| 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 | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 90 | static int lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, |
| 91 | struct lpfc_sli_ring *pring, |
| 92 | struct lpfc_iocbq *cmdiocb); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 93 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 94 | static IOCB_t * |
| 95 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 96 | { |
| 97 | return &iocbq->iocb; |
| 98 | } |
| 99 | |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 100 | #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN) |
| 101 | /** |
| 102 | * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function |
| 103 | * @srcp: Source memory pointer. |
| 104 | * @destp: Destination memory pointer. |
| 105 | * @cnt: Number of words required to be copied. |
| 106 | * Must be a multiple of sizeof(uint64_t) |
| 107 | * |
| 108 | * This function is used for copying data between driver memory |
| 109 | * and the SLI WQ. This function also changes the endianness |
| 110 | * of each word if native endianness is different from SLI |
| 111 | * endianness. This function can be called with or without |
| 112 | * lock. |
| 113 | **/ |
| 114 | void |
| 115 | lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 116 | { |
| 117 | uint64_t *src = srcp; |
| 118 | uint64_t *dest = destp; |
| 119 | int i; |
| 120 | |
| 121 | for (i = 0; i < (int)cnt; i += sizeof(uint64_t)) |
| 122 | *dest++ = *src++; |
| 123 | } |
| 124 | #else |
| 125 | #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c) |
| 126 | #endif |
| 127 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 128 | /** |
| 129 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 130 | * @q: The Work Queue to operate on. |
| 131 | * @wqe: The work Queue Entry to put on the Work queue. |
| 132 | * |
| 133 | * This routine will copy the contents of @wqe to the next available entry on |
| 134 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 135 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 136 | * successful. If no entries are available on @q then this function will return |
| 137 | * -ENOMEM. |
| 138 | * The caller is expected to hold the hbalock when calling this routine. |
| 139 | **/ |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 140 | static int |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 141 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 142 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 143 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 144 | struct lpfc_register doorbell; |
| 145 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 146 | uint32_t idx; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 147 | uint32_t i = 0; |
| 148 | uint8_t *tmp; |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 149 | u32 if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 150 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 151 | /* sanity check on queue memory */ |
| 152 | if (unlikely(!q)) |
| 153 | return -ENOMEM; |
| 154 | temp_wqe = q->qe[q->host_index].wqe; |
| 155 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 156 | /* 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] | 157 | idx = ((q->host_index + 1) % q->entry_count); |
| 158 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 159 | q->WQ_overflow++; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 160 | return -EBUSY; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 161 | } |
| 162 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 163 | /* set consumption flag every once in a while */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 164 | if (!((q->host_index + 1) % q->notify_interval)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 165 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | 04673e3 | 2018-01-30 15:58:45 -0800 | [diff] [blame] | 166 | else |
| 167 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 0); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 168 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 169 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 170 | lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 171 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 172 | /* write to DPP aperture taking advatage of Combined Writes */ |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 173 | tmp = (uint8_t *)temp_wqe; |
| 174 | #ifdef __raw_writeq |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 175 | for (i = 0; i < q->entry_size; i += sizeof(uint64_t)) |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 176 | __raw_writeq(*((uint64_t *)(tmp + i)), |
| 177 | q->dpp_regaddr + i); |
| 178 | #else |
| 179 | for (i = 0; i < q->entry_size; i += sizeof(uint32_t)) |
| 180 | __raw_writel(*((uint32_t *)(tmp + i)), |
| 181 | q->dpp_regaddr + i); |
| 182 | #endif |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 183 | } |
| 184 | /* ensure WQE bcopy and DPP flushed before doorbell write */ |
James Smart | 6b3b3bd | 2016-12-19 15:07:30 -0800 | [diff] [blame] | 185 | wmb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 186 | |
| 187 | /* Update the host index before invoking device */ |
| 188 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 189 | |
| 190 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 191 | |
| 192 | /* Ring Doorbell */ |
| 193 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 194 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 195 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 196 | bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1); |
| 197 | bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1); |
| 198 | bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell, |
| 199 | q->dpp_id); |
| 200 | bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell, |
| 201 | q->queue_id); |
| 202 | } else { |
| 203 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 204 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame] | 205 | |
| 206 | /* Leave bits <23:16> clear for if_type 6 dpp */ |
| 207 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 208 | &q->phba->sli4_hba.sli_intf); |
| 209 | if (if_type != LPFC_SLI_INTF_IF_TYPE_6) |
| 210 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, |
| 211 | host_index); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 212 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 213 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 214 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 215 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 216 | } else { |
| 217 | return -EINVAL; |
| 218 | } |
| 219 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 226 | * @q: The Work Queue to operate on. |
| 227 | * @index: The index to advance the hba index to. |
| 228 | * |
| 229 | * This routine will update the HBA index of a queue to reflect consumption of |
| 230 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 231 | * an entry the host calls this function to update the queue's internal |
| 232 | * pointers. This routine returns the number of entries that were consumed by |
| 233 | * the HBA. |
| 234 | **/ |
| 235 | static uint32_t |
| 236 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 237 | { |
| 238 | uint32_t released = 0; |
| 239 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 240 | /* sanity check on queue memory */ |
| 241 | if (unlikely(!q)) |
| 242 | return 0; |
| 243 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 244 | if (q->hba_index == index) |
| 245 | return 0; |
| 246 | do { |
| 247 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 248 | released++; |
| 249 | } while (q->hba_index != index); |
| 250 | return released; |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 255 | * @q: The Mailbox Queue to operate on. |
| 256 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 257 | * |
| 258 | * This routine will copy the contents of @mqe to the next available entry on |
| 259 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 260 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 261 | * successful. If no entries are available on @q then this function will return |
| 262 | * -ENOMEM. |
| 263 | * The caller is expected to hold the hbalock when calling this routine. |
| 264 | **/ |
| 265 | static uint32_t |
| 266 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 267 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 268 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 269 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 270 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 271 | /* sanity check on queue memory */ |
| 272 | if (unlikely(!q)) |
| 273 | return -ENOMEM; |
| 274 | temp_mqe = q->qe[q->host_index].mqe; |
| 275 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 276 | /* If the host has not yet processed the next entry then we are done */ |
| 277 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 278 | return -ENOMEM; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 279 | lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 280 | /* Save off the mailbox pointer for completion */ |
| 281 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 282 | |
| 283 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 284 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 285 | |
| 286 | /* Ring Doorbell */ |
| 287 | doorbell.word0 = 0; |
| 288 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 289 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 290 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 296 | * @q: The Mailbox Queue to operate on. |
| 297 | * |
| 298 | * This routine will update the HBA index of a queue to reflect consumption of |
| 299 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 300 | * an entry the host calls this function to update the queue's internal |
| 301 | * pointers. This routine returns the number of entries that were consumed by |
| 302 | * the HBA. |
| 303 | **/ |
| 304 | static uint32_t |
| 305 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 306 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 307 | /* sanity check on queue memory */ |
| 308 | if (unlikely(!q)) |
| 309 | return 0; |
| 310 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 311 | /* Clear the mailbox pointer for completion */ |
| 312 | q->phba->mbox = NULL; |
| 313 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 314 | return 1; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 319 | * @q: The Event Queue to get the first valid EQE from |
| 320 | * |
| 321 | * This routine will get the first valid Event Queue Entry from @q, update |
| 322 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 323 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 324 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 325 | **/ |
| 326 | static struct lpfc_eqe * |
| 327 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 328 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 329 | struct lpfc_eqe *eqe; |
| 330 | |
| 331 | /* sanity check on queue memory */ |
| 332 | if (unlikely(!q)) |
| 333 | return NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 334 | eqe = q->qe[q->host_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 335 | |
| 336 | /* If the next EQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 337 | if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 338 | return NULL; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 339 | |
| 340 | /* |
| 341 | * insert barrier for instruction interlock : data from the hardware |
| 342 | * 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] | 343 | * upon. Speculative instructions were allowing a bcopy at the start |
| 344 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 345 | * after our return, to copy data before the valid bit check above |
| 346 | * was done. As such, some of the copied data was stale. The barrier |
| 347 | * ensures the check is before any data is copied. |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 348 | */ |
| 349 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 350 | return eqe; |
| 351 | } |
| 352 | |
| 353 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 354 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 355 | * @q: The Event Queue to disable interrupts |
| 356 | * |
| 357 | **/ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 358 | inline void |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 359 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 360 | { |
| 361 | struct lpfc_register doorbell; |
| 362 | |
| 363 | doorbell.word0 = 0; |
| 364 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 365 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 366 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 367 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 368 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 369 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 373 | * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ |
| 374 | * @q: The Event Queue to disable interrupts |
| 375 | * |
| 376 | **/ |
| 377 | inline void |
| 378 | lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q) |
| 379 | { |
| 380 | struct lpfc_register doorbell; |
| 381 | |
| 382 | doorbell.word0 = 0; |
James Smart | aad59d5 | 2018-09-10 10:30:47 -0700 | [diff] [blame] | 383 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 384 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 385 | } |
| 386 | |
| 387 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 388 | * lpfc_sli4_write_eq_db - write EQ DB for eqe's consumed or arm state |
| 389 | * @phba: adapter with EQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 390 | * @q: The Event Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 391 | * @count: Number of elements that have been consumed |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 392 | * @arm: Indicates whether the host wants to arms this CQ. |
| 393 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 394 | * This routine will notify the HBA, by ringing the doorbell, that count |
| 395 | * number of EQEs have been processed. The @arm parameter indicates whether |
| 396 | * the queue should be rearmed when ringing the doorbell. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 397 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 398 | void |
| 399 | lpfc_sli4_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 400 | uint32_t count, bool arm) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 401 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 402 | struct lpfc_register doorbell; |
| 403 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 404 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 405 | if (unlikely(!q || (count == 0 && !arm))) |
| 406 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 407 | |
| 408 | /* ring doorbell for number popped */ |
| 409 | doorbell.word0 = 0; |
| 410 | if (arm) { |
| 411 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 412 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 413 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 414 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 415 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 416 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 417 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 418 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 419 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 420 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 421 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 422 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 426 | * lpfc_sli4_if6_write_eq_db - write EQ DB for eqe's consumed or arm state |
| 427 | * @phba: adapter with EQ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 428 | * @q: The Event Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 429 | * @count: Number of elements that have been consumed |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 430 | * @arm: Indicates whether the host wants to arms this CQ. |
| 431 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 432 | * This routine will notify the HBA, by ringing the doorbell, that count |
| 433 | * number of EQEs have been processed. The @arm parameter indicates whether |
| 434 | * the queue should be rearmed when ringing the doorbell. |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 435 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 436 | void |
| 437 | lpfc_sli4_if6_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 438 | uint32_t count, bool arm) |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 439 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 440 | struct lpfc_register doorbell; |
| 441 | |
| 442 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 443 | if (unlikely(!q || (count == 0 && !arm))) |
| 444 | return; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 445 | |
| 446 | /* ring doorbell for number popped */ |
| 447 | doorbell.word0 = 0; |
| 448 | if (arm) |
| 449 | bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 450 | bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, count); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 451 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
| 452 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 453 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 454 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 455 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | static void |
| 459 | __lpfc_sli4_consume_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 460 | struct lpfc_eqe *eqe) |
| 461 | { |
| 462 | if (!phba->sli4_hba.pc_sli4_params.eqav) |
| 463 | bf_set_le32(lpfc_eqe_valid, eqe, 0); |
| 464 | |
| 465 | eq->host_index = ((eq->host_index + 1) % eq->entry_count); |
| 466 | |
| 467 | /* if the index wrapped around, toggle the valid bit */ |
| 468 | if (phba->sli4_hba.pc_sli4_params.eqav && !eq->host_index) |
| 469 | eq->qe_valid = (eq->qe_valid) ? 0 : 1; |
| 470 | } |
| 471 | |
| 472 | static void |
| 473 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 474 | { |
| 475 | struct lpfc_eqe *eqe; |
| 476 | uint32_t count = 0; |
| 477 | |
| 478 | /* walk all the EQ entries and drop on the floor */ |
| 479 | eqe = lpfc_sli4_eq_get(eq); |
| 480 | while (eqe) { |
| 481 | __lpfc_sli4_consume_eqe(phba, eq, eqe); |
| 482 | count++; |
| 483 | eqe = lpfc_sli4_eq_get(eq); |
| 484 | } |
| 485 | |
| 486 | /* Clear and re-arm the EQ */ |
| 487 | phba->sli4_hba.sli4_write_eq_db(phba, eq, count, LPFC_QUEUE_REARM); |
| 488 | } |
| 489 | |
| 490 | static int |
| 491 | lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 492 | { |
| 493 | struct lpfc_eqe *eqe; |
| 494 | int count = 0, consumed = 0; |
| 495 | |
| 496 | if (cmpxchg(&eq->queue_claimed, 0, 1) != 0) |
| 497 | goto rearm_and_exit; |
| 498 | |
| 499 | eqe = lpfc_sli4_eq_get(eq); |
| 500 | while (eqe) { |
| 501 | lpfc_sli4_hba_handle_eqe(phba, eq, eqe); |
| 502 | __lpfc_sli4_consume_eqe(phba, eq, eqe); |
| 503 | |
| 504 | consumed++; |
| 505 | if (!(++count % eq->max_proc_limit)) |
| 506 | break; |
| 507 | |
| 508 | if (!(count % eq->notify_interval)) { |
| 509 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, |
| 510 | LPFC_QUEUE_NOARM); |
| 511 | consumed = 0; |
| 512 | } |
| 513 | |
| 514 | eqe = lpfc_sli4_eq_get(eq); |
| 515 | } |
| 516 | eq->EQ_processed += count; |
| 517 | |
| 518 | /* Track the max number of EQEs processed in 1 intr */ |
| 519 | if (count > eq->EQ_max_eqe) |
| 520 | eq->EQ_max_eqe = count; |
| 521 | |
| 522 | eq->queue_claimed = 0; |
| 523 | |
| 524 | rearm_and_exit: |
| 525 | /* Always clear and re-arm the EQ */ |
| 526 | phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, LPFC_QUEUE_REARM); |
| 527 | |
| 528 | return count; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 532 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 533 | * @q: The Completion Queue to get the first valid CQE from |
| 534 | * |
| 535 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 536 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 537 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 538 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 539 | **/ |
| 540 | static struct lpfc_cqe * |
| 541 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 542 | { |
| 543 | struct lpfc_cqe *cqe; |
| 544 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 545 | /* sanity check on queue memory */ |
| 546 | if (unlikely(!q)) |
| 547 | return NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 548 | cqe = q->qe[q->host_index].cqe; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 549 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 550 | /* If the next CQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 551 | if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 552 | return NULL; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 553 | |
| 554 | /* |
| 555 | * insert barrier for instruction interlock : data from the hardware |
| 556 | * 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] | 557 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 558 | * instructions allowing action on content before valid bit checked, |
| 559 | * add barrier here as well. May not be needed as "content" is a |
| 560 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 561 | */ |
| 562 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 563 | return cqe; |
| 564 | } |
| 565 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 566 | static void |
| 567 | __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 568 | struct lpfc_cqe *cqe) |
| 569 | { |
| 570 | if (!phba->sli4_hba.pc_sli4_params.cqav) |
| 571 | bf_set_le32(lpfc_cqe_valid, cqe, 0); |
| 572 | |
| 573 | cq->host_index = ((cq->host_index + 1) % cq->entry_count); |
| 574 | |
| 575 | /* if the index wrapped around, toggle the valid bit */ |
| 576 | if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index) |
| 577 | cq->qe_valid = (cq->qe_valid) ? 0 : 1; |
| 578 | } |
| 579 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 580 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 581 | * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state. |
| 582 | * @phba: the adapter with the CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 583 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 584 | * @count: the number of elements that were consumed |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 585 | * @arm: Indicates whether the host wants to arms this CQ. |
| 586 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 587 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 588 | * CQEs have been processed. The @arm parameter specifies whether the |
| 589 | * queue should be rearmed when ringing the doorbell. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 590 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 591 | void |
| 592 | lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 593 | uint32_t count, bool arm) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 594 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 595 | struct lpfc_register doorbell; |
| 596 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 597 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 598 | if (unlikely(!q || (count == 0 && !arm))) |
| 599 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 600 | |
| 601 | /* ring doorbell for number popped */ |
| 602 | doorbell.word0 = 0; |
| 603 | if (arm) |
| 604 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 605 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 606 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 607 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 608 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 609 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 610 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 614 | * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state. |
| 615 | * @phba: the adapter with the CQ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 616 | * @q: The Completion Queue that the host has completed processing for. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 617 | * @count: the number of elements that were consumed |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 618 | * @arm: Indicates whether the host wants to arms this CQ. |
| 619 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 620 | * This routine will notify the HBA, by ringing the doorbell, that the |
| 621 | * CQEs have been processed. The @arm parameter specifies whether the |
| 622 | * queue should be rearmed when ringing the doorbell. |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 623 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 624 | void |
| 625 | lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q, |
| 626 | uint32_t count, bool arm) |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 627 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 628 | struct lpfc_register doorbell; |
| 629 | |
| 630 | /* sanity check on queue memory */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 631 | if (unlikely(!q || (count == 0 && !arm))) |
| 632 | return; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 633 | |
| 634 | /* ring doorbell for number popped */ |
| 635 | doorbell.word0 = 0; |
| 636 | if (arm) |
| 637 | bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 638 | bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 639 | bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id); |
| 640 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 644 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 645 | * @q: The Header Receive Queue to operate on. |
| 646 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 647 | * |
| 648 | * This routine will copy the contents of @wqe to the next available entry on |
| 649 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 650 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 651 | * index that the rqe was copied to if successful. If no entries are available |
| 652 | * on @q then this function will return -ENOMEM. |
| 653 | * The caller is expected to hold the hbalock when calling this routine. |
| 654 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 655 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 656 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 657 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 658 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 659 | struct lpfc_rqe *temp_hrqe; |
| 660 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 661 | struct lpfc_register doorbell; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 662 | int hq_put_index; |
| 663 | int dq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 664 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 665 | /* sanity check on queue memory */ |
| 666 | if (unlikely(!hq) || unlikely(!dq)) |
| 667 | return -ENOMEM; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 668 | hq_put_index = hq->host_index; |
| 669 | dq_put_index = dq->host_index; |
| 670 | temp_hrqe = hq->qe[hq_put_index].rqe; |
| 671 | temp_drqe = dq->qe[dq_put_index].rqe; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 672 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 673 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 674 | return -EINVAL; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 675 | if (hq_put_index != dq_put_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 676 | return -EINVAL; |
| 677 | /* 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] | 678 | if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 679 | return -EBUSY; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 680 | lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 681 | lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 682 | |
| 683 | /* Update the host index to point to the next slot */ |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 684 | hq->host_index = ((hq_put_index + 1) % hq->entry_count); |
| 685 | dq->host_index = ((dq_put_index + 1) % dq->entry_count); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 686 | hq->RQ_buf_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 687 | |
| 688 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 689 | if (!(hq->host_index % hq->notify_interval)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 690 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 691 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 692 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 693 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 694 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 695 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 696 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 697 | hq->notify_interval); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 698 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 699 | hq->host_index); |
| 700 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 701 | } else { |
| 702 | return -EINVAL; |
| 703 | } |
| 704 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 705 | } |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 706 | return hq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | /** |
| 710 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 711 | * @q: The Header Receive Queue to operate on. |
| 712 | * |
| 713 | * This routine will update the HBA index of a queue to reflect consumption of |
| 714 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 715 | * consumed an entry the host calls this function to update the queue's |
| 716 | * internal pointers. This routine returns the number of entries that were |
| 717 | * consumed by the HBA. |
| 718 | **/ |
| 719 | static uint32_t |
| 720 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 721 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 722 | /* sanity check on queue memory */ |
| 723 | if (unlikely(!hq) || unlikely(!dq)) |
| 724 | return 0; |
| 725 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 726 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 727 | return 0; |
| 728 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 729 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 730 | return 1; |
| 731 | } |
| 732 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 733 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 734 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 735 | * @phba: Pointer to HBA context object. |
| 736 | * @pring: Pointer to driver SLI ring object. |
| 737 | * |
| 738 | * This function returns pointer to next command iocb entry |
| 739 | * in the command ring. The caller must hold hbalock to prevent |
| 740 | * other threads consume the next command iocb. |
| 741 | * SLI-2/SLI-3 provide different sized iocbs. |
| 742 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 743 | static inline IOCB_t * |
| 744 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 745 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 746 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 747 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 748 | } |
| 749 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 750 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 751 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 752 | * @phba: Pointer to HBA context object. |
| 753 | * @pring: Pointer to driver SLI ring object. |
| 754 | * |
| 755 | * This function returns pointer to next response iocb entry |
| 756 | * in the response ring. The caller must hold hbalock to make sure |
| 757 | * that no other thread consume the next response iocb. |
| 758 | * SLI-2/SLI-3 provide different sized iocbs. |
| 759 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 760 | static inline IOCB_t * |
| 761 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 762 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 763 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 764 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 765 | } |
| 766 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 767 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 768 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 769 | * @phba: Pointer to HBA context object. |
| 770 | * |
| 771 | * This function is called with hbalock held. This function |
| 772 | * allocates a new driver iocb object from the iocb pool. If the |
| 773 | * allocation is successful, it returns pointer to the newly |
| 774 | * allocated iocb object else it returns NULL. |
| 775 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 776 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 777 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 778 | { |
| 779 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 780 | struct lpfc_iocbq * iocbq = NULL; |
| 781 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 782 | lockdep_assert_held(&phba->hbalock); |
| 783 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 784 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 785 | if (iocbq) |
| 786 | phba->iocb_cnt++; |
| 787 | if (phba->iocb_cnt > phba->iocb_max) |
| 788 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 789 | return iocbq; |
| 790 | } |
| 791 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 792 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 793 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 794 | * @phba: Pointer to HBA context object. |
| 795 | * @xritag: XRI value. |
| 796 | * |
| 797 | * This function clears the sglq pointer from the array of acive |
| 798 | * sglq's. The xritag that is passed in is used to index into the |
| 799 | * array. Before the xritag can be used it needs to be adjusted |
| 800 | * by subtracting the xribase. |
| 801 | * |
| 802 | * Returns sglq ponter = success, NULL = Failure. |
| 803 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 804 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 805 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 806 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 807 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 808 | |
| 809 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 810 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 811 | return sglq; |
| 812 | } |
| 813 | |
| 814 | /** |
| 815 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 816 | * @phba: Pointer to HBA context object. |
| 817 | * @xritag: XRI value. |
| 818 | * |
| 819 | * This function returns the sglq pointer from the array of acive |
| 820 | * sglq's. The xritag that is passed in is used to index into the |
| 821 | * array. Before the xritag can be used it needs to be adjusted |
| 822 | * by subtracting the xribase. |
| 823 | * |
| 824 | * Returns sglq ponter = success, NULL = Failure. |
| 825 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 826 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 827 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 828 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 829 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 830 | |
| 831 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 832 | return sglq; |
| 833 | } |
| 834 | |
| 835 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 836 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 837 | * @phba: Pointer to HBA context object. |
| 838 | * @xritag: xri used in this exchange. |
| 839 | * @rrq: The RRQ to be cleared. |
| 840 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 841 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 842 | void |
| 843 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 844 | uint16_t xritag, |
| 845 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 846 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 847 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 848 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 849 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 850 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 851 | |
| 852 | /* The target DID could have been swapped (cable swap) |
| 853 | * we should use the ndlp from the findnode if it is |
| 854 | * available. |
| 855 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 856 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 857 | ndlp = rrq->ndlp; |
| 858 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 859 | if (!ndlp) |
| 860 | goto out; |
| 861 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 862 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 863 | rrq->send_rrq = 0; |
| 864 | rrq->xritag = 0; |
| 865 | rrq->rrq_stop_time = 0; |
| 866 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 867 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 868 | mempool_free(rrq, phba->rrq_pool); |
| 869 | } |
| 870 | |
| 871 | /** |
| 872 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 873 | * @phba: Pointer to HBA context object. |
| 874 | * |
| 875 | * This function is called with hbalock held. This function |
| 876 | * Checks if stop_time (ratov from setting rrq active) has |
| 877 | * been reached, if it has and the send_rrq flag is set then |
| 878 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 879 | * then it will just call the routine to clear the rrq and |
| 880 | * free the rrq resource. |
| 881 | * The timer is set to the next rrq that is going to expire before |
| 882 | * leaving the routine. |
| 883 | * |
| 884 | **/ |
| 885 | void |
| 886 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 887 | { |
| 888 | struct lpfc_node_rrq *rrq; |
| 889 | struct lpfc_node_rrq *nextrrq; |
| 890 | unsigned long next_time; |
| 891 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 892 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 893 | |
| 894 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 895 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 896 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 897 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 898 | &phba->active_rrq_list, list) { |
| 899 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 900 | list_move(&rrq->list, &send_rrq); |
| 901 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 902 | next_time = rrq->rrq_stop_time; |
| 903 | } |
| 904 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 905 | if ((!list_empty(&phba->active_rrq_list)) && |
| 906 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 907 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 908 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 909 | list_del(&rrq->list); |
| 910 | if (!rrq->send_rrq) |
| 911 | /* this call will free the rrq */ |
| 912 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 913 | else if (lpfc_send_rrq(phba, rrq)) { |
| 914 | /* if we send the rrq then the completion handler |
| 915 | * will clear the bit in the xribitmap. |
| 916 | */ |
| 917 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 918 | rrq); |
| 919 | } |
| 920 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | /** |
| 924 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 925 | * @vport: Pointer to vport context object. |
| 926 | * @xri: The xri used in the exchange. |
| 927 | * @did: The targets DID for this exchange. |
| 928 | * |
| 929 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 930 | * rrq = rrq for this xri and target. |
| 931 | **/ |
| 932 | struct lpfc_node_rrq * |
| 933 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 934 | { |
| 935 | struct lpfc_hba *phba = vport->phba; |
| 936 | struct lpfc_node_rrq *rrq; |
| 937 | struct lpfc_node_rrq *nextrrq; |
| 938 | unsigned long iflags; |
| 939 | |
| 940 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 941 | return NULL; |
| 942 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 943 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 944 | if (rrq->vport == vport && rrq->xritag == xri && |
| 945 | rrq->nlp_DID == did){ |
| 946 | list_del(&rrq->list); |
| 947 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 948 | return rrq; |
| 949 | } |
| 950 | } |
| 951 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 952 | return NULL; |
| 953 | } |
| 954 | |
| 955 | /** |
| 956 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 957 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 958 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 959 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 960 | * phba->active_rrq_list and clear the rrq. |
| 961 | * 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] | 962 | **/ |
| 963 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 964 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 965 | |
| 966 | { |
| 967 | struct lpfc_hba *phba = vport->phba; |
| 968 | struct lpfc_node_rrq *rrq; |
| 969 | struct lpfc_node_rrq *nextrrq; |
| 970 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 971 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 972 | |
| 973 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 974 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 975 | if (!ndlp) { |
| 976 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 977 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 978 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 979 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 980 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 981 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 982 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 983 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 984 | |
| 985 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 986 | list_del(&rrq->list); |
| 987 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 988 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 992 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 993 | * @phba: Pointer to HBA context object. |
| 994 | * @ndlp: Targets nodelist pointer for this exchange. |
| 995 | * @xritag the xri in the bitmap to test. |
| 996 | * |
| 997 | * This function is called with hbalock held. This function |
| 998 | * returns 0 = rrq not active for this xri |
| 999 | * 1 = rrq is valid for this xri. |
| 1000 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1001 | int |
| 1002 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1003 | uint16_t xritag) |
| 1004 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1005 | lockdep_assert_held(&phba->hbalock); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1006 | if (!ndlp) |
| 1007 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1008 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1009 | return 0; |
| 1010 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1011 | return 1; |
| 1012 | else |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | /** |
| 1017 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 1018 | * @phba: Pointer to HBA context object. |
| 1019 | * @ndlp: nodelist pointer for this target. |
| 1020 | * @xritag: xri used in this exchange. |
| 1021 | * @rxid: Remote Exchange ID. |
| 1022 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 1023 | * |
| 1024 | * This function takes the hbalock. |
| 1025 | * The active bit is always set in the active rrq xri_bitmap even |
| 1026 | * if there is no slot avaiable for the other rrq information. |
| 1027 | * |
| 1028 | * returns 0 rrq actived for this xri |
| 1029 | * < 0 No memory or invalid ndlp. |
| 1030 | **/ |
| 1031 | int |
| 1032 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1033 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1034 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1035 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1036 | struct lpfc_node_rrq *rrq; |
| 1037 | int empty; |
| 1038 | |
| 1039 | if (!ndlp) |
| 1040 | return -EINVAL; |
| 1041 | |
| 1042 | if (!phba->cfg_enable_rrq) |
| 1043 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1044 | |
| 1045 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1046 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1047 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 1048 | goto out; |
| 1049 | } |
| 1050 | |
| 1051 | /* |
| 1052 | * set the active bit even if there is no mem available. |
| 1053 | */ |
| 1054 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 1055 | goto out; |
| 1056 | |
| 1057 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 1058 | goto out; |
| 1059 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1060 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1061 | goto out; |
| 1062 | |
| 1063 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1064 | goto out; |
| 1065 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1066 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1067 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 1068 | if (!rrq) { |
| 1069 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1070 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 1071 | " DID:0x%x Send:%d\n", |
| 1072 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1073 | return -EINVAL; |
| 1074 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 1075 | if (phba->cfg_enable_rrq == 1) |
| 1076 | rrq->send_rrq = send_rrq; |
| 1077 | else |
| 1078 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1079 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1080 | rrq->rrq_stop_time = jiffies + |
| 1081 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1082 | rrq->ndlp = ndlp; |
| 1083 | rrq->nlp_DID = ndlp->nlp_DID; |
| 1084 | rrq->vport = ndlp->vport; |
| 1085 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1086 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1087 | empty = list_empty(&phba->active_rrq_list); |
| 1088 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 1089 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1090 | if (empty) |
| 1091 | lpfc_worker_wake_up(phba); |
| 1092 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1093 | return 0; |
| 1094 | out: |
| 1095 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1096 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1097 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 1098 | " DID:0x%x Send:%d\n", |
| 1099 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1100 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1104 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1105 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1106 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1107 | * |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1108 | * This function is called with the ring lock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1109 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1110 | * list is not empty then it is successful, it returns pointer to the newly |
| 1111 | * allocated sglq object else it returns NULL. |
| 1112 | **/ |
| 1113 | static struct lpfc_sglq * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1114 | __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] | 1115 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1116 | 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] | 1117 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1118 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1119 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1120 | struct lpfc_nodelist *ndlp; |
| 1121 | int found = 0; |
| 1122 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1123 | lockdep_assert_held(&phba->hbalock); |
| 1124 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1125 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1126 | lpfc_cmd = (struct lpfc_io_buf *) piocbq->context1; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1127 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 1128 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1129 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1130 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1131 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 1132 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 1133 | ndlp = NULL; |
| 1134 | else |
| 1135 | ndlp = piocbq->context_un.ndlp; |
| 1136 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1137 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1138 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1139 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1140 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 1141 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1142 | start_sglq = sglq; |
| 1143 | while (!found) { |
| 1144 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 1145 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1146 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 1147 | test_bit(sglq->sli4_lxritag, |
| 1148 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1149 | /* This xri has an rrq outstanding for this DID. |
| 1150 | * put it back in the list and get another xri. |
| 1151 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1152 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1153 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1154 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1155 | struct lpfc_sglq, list); |
| 1156 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 1157 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1158 | sglq = NULL; |
| 1159 | break; |
| 1160 | } else |
| 1161 | continue; |
| 1162 | } |
| 1163 | sglq->ndlp = ndlp; |
| 1164 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1165 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1166 | sglq->state = SGL_ALLOCATED; |
| 1167 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1168 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1169 | return sglq; |
| 1170 | } |
| 1171 | |
| 1172 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1173 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 1174 | * @phba: Pointer to HBA context object. |
| 1175 | * @piocb: Pointer to the iocbq. |
| 1176 | * |
| 1177 | * This function is called with the sgl_list lock held. This function |
| 1178 | * gets a new driver sglq object from the sglq list. If the |
| 1179 | * list is not empty then it is successful, it returns pointer to the newly |
| 1180 | * allocated sglq object else it returns NULL. |
| 1181 | **/ |
| 1182 | struct lpfc_sglq * |
| 1183 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 1184 | { |
| 1185 | struct list_head *lpfc_nvmet_sgl_list; |
| 1186 | struct lpfc_sglq *sglq = NULL; |
| 1187 | |
| 1188 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1189 | |
| 1190 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1191 | |
| 1192 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1193 | if (!sglq) |
| 1194 | return NULL; |
| 1195 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1196 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1197 | return sglq; |
| 1198 | } |
| 1199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1201 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1202 | * @phba: Pointer to HBA context object. |
| 1203 | * |
| 1204 | * This function is called with no lock held. This function |
| 1205 | * allocates a new driver iocb object from the iocb pool. If the |
| 1206 | * allocation is successful, it returns pointer to the newly |
| 1207 | * allocated iocb object else it returns NULL. |
| 1208 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1209 | struct lpfc_iocbq * |
| 1210 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1211 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1212 | struct lpfc_iocbq * iocbq = NULL; |
| 1213 | unsigned long iflags; |
| 1214 | |
| 1215 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1216 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1217 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1218 | return iocbq; |
| 1219 | } |
| 1220 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1221 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1222 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1223 | * @phba: Pointer to HBA context object. |
| 1224 | * @iocbq: Pointer to driver iocb object. |
| 1225 | * |
| 1226 | * This function is called with hbalock held to release driver |
| 1227 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1228 | * does not change for each use of the iocb object. This function |
| 1229 | * clears all other fields of the iocb object when it is freed. |
| 1230 | * The sqlq structure that holds the xritag and phys and virtual |
| 1231 | * mappings for the scatter gather list is retrieved from the |
| 1232 | * active array of sglq. The get of the sglq pointer also clears |
| 1233 | * the entry in the array. If the status of the IO indiactes that |
| 1234 | * this IO was aborted then the sglq entry it put on the |
| 1235 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1236 | * 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] | 1237 | * entry is added to the free list (lpfc_els_sgl_list). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1238 | **/ |
| 1239 | static void |
| 1240 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1241 | { |
| 1242 | struct lpfc_sglq *sglq; |
| 1243 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1244 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1245 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1246 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1247 | lockdep_assert_held(&phba->hbalock); |
| 1248 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1249 | if (iocbq->sli4_xritag == NO_XRI) |
| 1250 | sglq = NULL; |
| 1251 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1252 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1253 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1254 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1255 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1256 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1257 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1258 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1259 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1260 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1261 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1262 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1263 | spin_unlock_irqrestore( |
| 1264 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1265 | goto out; |
| 1266 | } |
| 1267 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1268 | pring = phba->sli4_hba.els_wq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1269 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1270 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1271 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1272 | iflag); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1273 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1274 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1275 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1276 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1277 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1278 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1279 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1280 | sglq->state = SGL_FREED; |
| 1281 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1282 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1283 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1284 | spin_unlock_irqrestore( |
| 1285 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1286 | |
| 1287 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1288 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1289 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1290 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1293 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1294 | /* |
| 1295 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1296 | */ |
| 1297 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1298 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1299 | iocbq->sli4_xritag = NO_XRI; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1300 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 1301 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1302 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1303 | } |
| 1304 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1305 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1306 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1307 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1308 | * @phba: Pointer to HBA context object. |
| 1309 | * @iocbq: Pointer to driver iocb object. |
| 1310 | * |
| 1311 | * This function is called with hbalock held to release driver |
| 1312 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1313 | * does not change for each use of the iocb object. This function |
| 1314 | * clears all other fields of the iocb object when it is freed. |
| 1315 | **/ |
| 1316 | static void |
| 1317 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1318 | { |
| 1319 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1320 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1321 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1322 | |
| 1323 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1324 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1325 | */ |
| 1326 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1327 | iocbq->sli4_xritag = NO_XRI; |
| 1328 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1329 | } |
| 1330 | |
| 1331 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1332 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1333 | * @phba: Pointer to HBA context object. |
| 1334 | * @iocbq: Pointer to driver iocb object. |
| 1335 | * |
| 1336 | * This function is called with hbalock held to release driver |
| 1337 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1338 | * does not change for each use of the iocb object. This function |
| 1339 | * clears all other fields of the iocb object when it is freed. |
| 1340 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1341 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1342 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1343 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1344 | lockdep_assert_held(&phba->hbalock); |
| 1345 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1346 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1347 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1348 | } |
| 1349 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1350 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1351 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1352 | * @phba: Pointer to HBA context object. |
| 1353 | * @iocbq: Pointer to driver iocb object. |
| 1354 | * |
| 1355 | * This function is called with no lock held to release the iocb to |
| 1356 | * iocb pool. |
| 1357 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1358 | void |
| 1359 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1360 | { |
| 1361 | unsigned long iflags; |
| 1362 | |
| 1363 | /* |
| 1364 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1365 | */ |
| 1366 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1367 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1368 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1369 | } |
| 1370 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1371 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1372 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1373 | * @phba: Pointer to HBA context object. |
| 1374 | * @iocblist: List of IOCBs. |
| 1375 | * @ulpstatus: ULP status in IOCB command field. |
| 1376 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1377 | * |
| 1378 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1379 | * on the list by invoking the complete callback function associated with the |
| 1380 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1381 | * fields. |
| 1382 | **/ |
| 1383 | void |
| 1384 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1385 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1386 | { |
| 1387 | struct lpfc_iocbq *piocb; |
| 1388 | |
| 1389 | while (!list_empty(iocblist)) { |
| 1390 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1391 | if (!piocb->iocb_cmpl) |
| 1392 | lpfc_sli_release_iocbq(phba, piocb); |
| 1393 | else { |
| 1394 | piocb->iocb.ulpStatus = ulpstatus; |
| 1395 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1396 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1397 | } |
| 1398 | } |
| 1399 | return; |
| 1400 | } |
| 1401 | |
| 1402 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1403 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1404 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1405 | * |
| 1406 | * This function is called by ring event handler function to get the iocb type. |
| 1407 | * This function translates the iocb command to an iocb command type used to |
| 1408 | * decide the final disposition of each completed IOCB. |
| 1409 | * The function returns |
| 1410 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1411 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1412 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1413 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1414 | * |
| 1415 | * The caller is not required to hold any lock. |
| 1416 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1417 | static lpfc_iocb_type |
| 1418 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1419 | { |
| 1420 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1421 | |
| 1422 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1423 | return 0; |
| 1424 | |
| 1425 | switch (iocb_cmnd) { |
| 1426 | case CMD_XMIT_SEQUENCE_CR: |
| 1427 | case CMD_XMIT_SEQUENCE_CX: |
| 1428 | case CMD_XMIT_BCAST_CN: |
| 1429 | case CMD_XMIT_BCAST_CX: |
| 1430 | case CMD_ELS_REQUEST_CR: |
| 1431 | case CMD_ELS_REQUEST_CX: |
| 1432 | case CMD_CREATE_XRI_CR: |
| 1433 | case CMD_CREATE_XRI_CX: |
| 1434 | case CMD_GET_RPI_CN: |
| 1435 | case CMD_XMIT_ELS_RSP_CX: |
| 1436 | case CMD_GET_RPI_CR: |
| 1437 | case CMD_FCP_IWRITE_CR: |
| 1438 | case CMD_FCP_IWRITE_CX: |
| 1439 | case CMD_FCP_IREAD_CR: |
| 1440 | case CMD_FCP_IREAD_CX: |
| 1441 | case CMD_FCP_ICMND_CR: |
| 1442 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1443 | case CMD_FCP_TSEND_CX: |
| 1444 | case CMD_FCP_TRSP_CX: |
| 1445 | case CMD_FCP_TRECEIVE_CX: |
| 1446 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1447 | case CMD_ADAPTER_MSG: |
| 1448 | case CMD_ADAPTER_DUMP: |
| 1449 | case CMD_XMIT_SEQUENCE64_CR: |
| 1450 | case CMD_XMIT_SEQUENCE64_CX: |
| 1451 | case CMD_XMIT_BCAST64_CN: |
| 1452 | case CMD_XMIT_BCAST64_CX: |
| 1453 | case CMD_ELS_REQUEST64_CR: |
| 1454 | case CMD_ELS_REQUEST64_CX: |
| 1455 | case CMD_FCP_IWRITE64_CR: |
| 1456 | case CMD_FCP_IWRITE64_CX: |
| 1457 | case CMD_FCP_IREAD64_CR: |
| 1458 | case CMD_FCP_IREAD64_CX: |
| 1459 | case CMD_FCP_ICMND64_CR: |
| 1460 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1461 | case CMD_FCP_TSEND64_CX: |
| 1462 | case CMD_FCP_TRSP64_CX: |
| 1463 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1464 | case CMD_GEN_REQUEST64_CR: |
| 1465 | case CMD_GEN_REQUEST64_CX: |
| 1466 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1467 | case DSSCMD_IWRITE64_CR: |
| 1468 | case DSSCMD_IWRITE64_CX: |
| 1469 | case DSSCMD_IREAD64_CR: |
| 1470 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | type = LPFC_SOL_IOCB; |
| 1472 | break; |
| 1473 | case CMD_ABORT_XRI_CN: |
| 1474 | case CMD_ABORT_XRI_CX: |
| 1475 | case CMD_CLOSE_XRI_CN: |
| 1476 | case CMD_CLOSE_XRI_CX: |
| 1477 | case CMD_XRI_ABORTED_CX: |
| 1478 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1479 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1480 | type = LPFC_ABORT_IOCB; |
| 1481 | break; |
| 1482 | case CMD_RCV_SEQUENCE_CX: |
| 1483 | case CMD_RCV_ELS_REQ_CX: |
| 1484 | case CMD_RCV_SEQUENCE64_CX: |
| 1485 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1486 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1487 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1488 | case CMD_IOCB_RCV_ELS64_CX: |
| 1489 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1490 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1491 | type = LPFC_UNSOL_IOCB; |
| 1492 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1493 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1494 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1495 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1496 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1497 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1498 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1499 | case CMD_IOCB_RET_HBQE64_CN: |
| 1500 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1501 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1502 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1503 | case CMD_IOCB_LOGENTRY_CN: |
| 1504 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1505 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1506 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1507 | type = LPFC_UNKNOWN_IOCB; |
| 1508 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1509 | default: |
| 1510 | type = LPFC_UNKNOWN_IOCB; |
| 1511 | break; |
| 1512 | } |
| 1513 | |
| 1514 | return type; |
| 1515 | } |
| 1516 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1517 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1518 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1519 | * @phba: Pointer to HBA context object. |
| 1520 | * |
| 1521 | * This function is called from SLI initialization code |
| 1522 | * to configure every ring of the HBA's SLI interface. The |
| 1523 | * caller is not required to hold any lock. This function issues |
| 1524 | * a config_ring mailbox command for each ring. |
| 1525 | * This function returns zero if successful else returns a negative |
| 1526 | * error code. |
| 1527 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1528 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1529 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1530 | { |
| 1531 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1532 | LPFC_MBOXQ_t *pmb; |
| 1533 | MAILBOX_t *pmbox; |
| 1534 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1535 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1536 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1537 | if (!pmb) |
| 1538 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1539 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1540 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1541 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | lpfc_config_ring(phba, i, pmb); |
| 1543 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1544 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1545 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1546 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1547 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1548 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1549 | rc, pmbox->mbxCommand, |
| 1550 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1551 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1552 | ret = -ENXIO; |
| 1553 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1554 | } |
| 1555 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1556 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1557 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1558 | } |
| 1559 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1560 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1561 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1562 | * @phba: Pointer to HBA context object. |
| 1563 | * @pring: Pointer to driver SLI ring object. |
| 1564 | * @piocb: Pointer to the driver iocb object. |
| 1565 | * |
| 1566 | * This function is called with hbalock held. The function adds the |
| 1567 | * new iocb to txcmplq of the given ring. This function always returns |
| 1568 | * 0. If this function is called for ELS ring, this function checks if |
| 1569 | * there is a vport associated with the ELS command. This function also |
| 1570 | * starts els_tmofunc timer if this is an ELS command. |
| 1571 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1572 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1573 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1574 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1575 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1576 | lockdep_assert_held(&phba->hbalock); |
| 1577 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1578 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1579 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1580 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1581 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1582 | pring->txcmplq_cnt++; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1583 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1584 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1585 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1586 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1587 | BUG_ON(!piocb->vport); |
| 1588 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1589 | mod_timer(&piocb->vport->els_tmofunc, |
| 1590 | jiffies + |
| 1591 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1592 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1593 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1594 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1595 | } |
| 1596 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1597 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1598 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1599 | * @phba: Pointer to HBA context object. |
| 1600 | * @pring: Pointer to driver SLI ring object. |
| 1601 | * |
| 1602 | * This function is called with hbalock held to get next |
| 1603 | * iocb in txq of the given ring. If there is any iocb in |
| 1604 | * the txq, the function returns first iocb in the list after |
| 1605 | * removing the iocb from the list, else it returns NULL. |
| 1606 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1607 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1608 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1609 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1610 | struct lpfc_iocbq *cmd_iocb; |
| 1611 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1612 | lockdep_assert_held(&phba->hbalock); |
| 1613 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1614 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1615 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1616 | } |
| 1617 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1618 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1619 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1620 | * @phba: Pointer to HBA context object. |
| 1621 | * @pring: Pointer to driver SLI ring object. |
| 1622 | * |
| 1623 | * This function is called with hbalock held and the caller must post the |
| 1624 | * iocb without releasing the lock. If the caller releases the lock, |
| 1625 | * iocb slot returned by the function is not guaranteed to be available. |
| 1626 | * The function returns pointer to the next available iocb slot if there |
| 1627 | * is available slot in the ring, else it returns NULL. |
| 1628 | * If the get index of the ring is ahead of the put index, the function |
| 1629 | * will post an error attention event to the worker thread to take the |
| 1630 | * HBA to offline state. |
| 1631 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1632 | static IOCB_t * |
| 1633 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1634 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1635 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1636 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1637 | |
| 1638 | lockdep_assert_held(&phba->hbalock); |
| 1639 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1640 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1641 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1642 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1643 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1644 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1645 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1646 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1647 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1648 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1649 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1650 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1651 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1652 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1653 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1654 | pring->sli.sli3.local_getidx, |
| 1655 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1656 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1657 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1658 | /* |
| 1659 | * All error attention handlers are posted to |
| 1660 | * worker thread |
| 1661 | */ |
| 1662 | phba->work_ha |= HA_ERATT; |
| 1663 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1664 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1665 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1666 | |
| 1667 | return NULL; |
| 1668 | } |
| 1669 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1670 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1671 | return NULL; |
| 1672 | } |
| 1673 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1674 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1675 | } |
| 1676 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1677 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1678 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1679 | * @phba: Pointer to HBA context object. |
| 1680 | * @iocbq: Pointer to driver iocb object. |
| 1681 | * |
| 1682 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1683 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1684 | * array and assigns a new iotag. |
| 1685 | * The function returns the allocated iotag if successful, else returns zero. |
| 1686 | * Zero is not a valid iotag. |
| 1687 | * The caller is not required to hold any lock. |
| 1688 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1689 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1690 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1692 | struct lpfc_iocbq **new_arr; |
| 1693 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1694 | size_t new_len; |
| 1695 | struct lpfc_sli *psli = &phba->sli; |
| 1696 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1697 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1698 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1699 | iotag = psli->last_iotag; |
| 1700 | if(++iotag < psli->iocbq_lookup_len) { |
| 1701 | psli->last_iotag = iotag; |
| 1702 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1703 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1704 | iocbq->iotag = iotag; |
| 1705 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1706 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1707 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1708 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1709 | spin_unlock_irq(&phba->hbalock); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1710 | new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1711 | GFP_KERNEL); |
| 1712 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1713 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1714 | old_arr = psli->iocbq_lookup; |
| 1715 | if (new_len <= psli->iocbq_lookup_len) { |
| 1716 | /* highly unprobable case */ |
| 1717 | kfree(new_arr); |
| 1718 | iotag = psli->last_iotag; |
| 1719 | if(++iotag < psli->iocbq_lookup_len) { |
| 1720 | psli->last_iotag = iotag; |
| 1721 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1722 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1723 | iocbq->iotag = iotag; |
| 1724 | return iotag; |
| 1725 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1726 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1727 | return 0; |
| 1728 | } |
| 1729 | if (psli->iocbq_lookup) |
| 1730 | memcpy(new_arr, old_arr, |
| 1731 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1732 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1733 | psli->iocbq_lookup = new_arr; |
| 1734 | psli->iocbq_lookup_len = new_len; |
| 1735 | psli->last_iotag = iotag; |
| 1736 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1737 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1738 | iocbq->iotag = iotag; |
| 1739 | kfree(old_arr); |
| 1740 | return iotag; |
| 1741 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1742 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1743 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1744 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1745 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1746 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1747 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1749 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | } |
| 1751 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1752 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1753 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1754 | * @phba: Pointer to HBA context object. |
| 1755 | * @pring: Pointer to driver SLI ring object. |
| 1756 | * @iocb: Pointer to iocb slot in the ring. |
| 1757 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1758 | * posted to firmware. |
| 1759 | * |
| 1760 | * This function is called with hbalock held to post a new iocb to |
| 1761 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1762 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1763 | * a completion call back for this iocb else the function will free the |
| 1764 | * iocb object. |
| 1765 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1766 | static void |
| 1767 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1768 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1769 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1770 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1771 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1772 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1773 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1774 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1775 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1776 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1777 | if (pring->ringno == LPFC_ELS_RING) { |
| 1778 | lpfc_debugfs_slow_ring_trc(phba, |
| 1779 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1780 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1781 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1782 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1783 | } |
| 1784 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1785 | /* |
| 1786 | * Issue iocb command to adapter |
| 1787 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1788 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1789 | wmb(); |
| 1790 | pring->stats.iocb_cmd++; |
| 1791 | |
| 1792 | /* |
| 1793 | * If there is no completion routine to call, we can release the |
| 1794 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1795 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1796 | */ |
| 1797 | if (nextiocb->iocb_cmpl) |
| 1798 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1799 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1800 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1801 | |
| 1802 | /* |
| 1803 | * Let the HBA know what IOCB slot will be the next one the |
| 1804 | * driver will put a command into. |
| 1805 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1806 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1807 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1808 | } |
| 1809 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1810 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1811 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1812 | * @phba: Pointer to HBA context object. |
| 1813 | * @pring: Pointer to driver SLI ring object. |
| 1814 | * |
| 1815 | * The caller is not required to hold any lock for calling this function. |
| 1816 | * This function updates the chip attention bits for the ring to inform firmware |
| 1817 | * that there are pending work to be done for this ring and requests an |
| 1818 | * interrupt when there is space available in the ring. This function is |
| 1819 | * called when the driver is unable to post more iocbs to the ring due |
| 1820 | * to unavailability of space in the ring. |
| 1821 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1822 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1823 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1824 | { |
| 1825 | int ringno = pring->ringno; |
| 1826 | |
| 1827 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1828 | |
| 1829 | wmb(); |
| 1830 | |
| 1831 | /* |
| 1832 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1833 | * The HBA will tell us when an IOCB entry is available. |
| 1834 | */ |
| 1835 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1836 | readl(phba->CAregaddr); /* flush */ |
| 1837 | |
| 1838 | pring->stats.iocb_cmd_full++; |
| 1839 | } |
| 1840 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1841 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1842 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1843 | * @phba: Pointer to HBA context object. |
| 1844 | * @pring: Pointer to driver SLI ring object. |
| 1845 | * |
| 1846 | * This function updates the chip attention register bit for the |
| 1847 | * given ring to inform HBA that there is more work to be done |
| 1848 | * in this ring. The caller is not required to hold any lock. |
| 1849 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1850 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1851 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1852 | { |
| 1853 | int ringno = pring->ringno; |
| 1854 | |
| 1855 | /* |
| 1856 | * Tell the HBA that there is work to do in this ring. |
| 1857 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1858 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1859 | wmb(); |
| 1860 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1861 | readl(phba->CAregaddr); /* flush */ |
| 1862 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1863 | } |
| 1864 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1865 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1866 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1867 | * @phba: Pointer to HBA context object. |
| 1868 | * @pring: Pointer to driver SLI ring object. |
| 1869 | * |
| 1870 | * This function is called with hbalock held to post pending iocbs |
| 1871 | * in the txq to the firmware. This function is called when driver |
| 1872 | * detects space available in the ring. |
| 1873 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1874 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1875 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1876 | { |
| 1877 | IOCB_t *iocb; |
| 1878 | struct lpfc_iocbq *nextiocb; |
| 1879 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1880 | lockdep_assert_held(&phba->hbalock); |
| 1881 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1882 | /* |
| 1883 | * Check to see if: |
| 1884 | * (a) there is anything on the txq to send |
| 1885 | * (b) link is up |
| 1886 | * (c) link attention events can be processed (fcp ring only) |
| 1887 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1888 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1889 | |
| 1890 | if (lpfc_is_link_up(phba) && |
| 1891 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1892 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1893 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1894 | |
| 1895 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1896 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1897 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1898 | |
| 1899 | if (iocb) |
| 1900 | lpfc_sli_update_ring(phba, pring); |
| 1901 | else |
| 1902 | lpfc_sli_update_full_ring(phba, pring); |
| 1903 | } |
| 1904 | |
| 1905 | return; |
| 1906 | } |
| 1907 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1908 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1909 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1910 | * @phba: Pointer to HBA context object. |
| 1911 | * @hbqno: HBQ number. |
| 1912 | * |
| 1913 | * This function is called with hbalock held to get the next |
| 1914 | * available slot for the given HBQ. If there is free slot |
| 1915 | * available for the HBQ it will return pointer to the next available |
| 1916 | * HBQ entry else it will return NULL. |
| 1917 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1918 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1919 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1920 | { |
| 1921 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1922 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1923 | lockdep_assert_held(&phba->hbalock); |
| 1924 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1925 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1926 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1927 | hbqp->next_hbqPutIdx = 0; |
| 1928 | |
| 1929 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1930 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1931 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1932 | |
| 1933 | hbqp->local_hbqGetIdx = getidx; |
| 1934 | |
| 1935 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1936 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1937 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1938 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1939 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1940 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1941 | hbqp->entry_count); |
| 1942 | |
| 1943 | phba->link_state = LPFC_HBA_ERROR; |
| 1944 | return NULL; |
| 1945 | } |
| 1946 | |
| 1947 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1948 | return NULL; |
| 1949 | } |
| 1950 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1951 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1952 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1953 | } |
| 1954 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1955 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1956 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1957 | * @phba: Pointer to HBA context object. |
| 1958 | * |
| 1959 | * This function is called with no lock held to free all the |
| 1960 | * hbq buffers while uninitializing the SLI interface. It also |
| 1961 | * frees the HBQ buffers returned by the firmware but not yet |
| 1962 | * processed by the upper layers. |
| 1963 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1964 | void |
| 1965 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1966 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1967 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1968 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1969 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1970 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1971 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1972 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1973 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1974 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1975 | for (i = 0; i < hbq_count; ++i) { |
| 1976 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1977 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1978 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1979 | list_del(&hbq_buf->dbuf.list); |
| 1980 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1981 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1982 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1983 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1984 | |
| 1985 | /* Mark the HBQs not in use */ |
| 1986 | phba->hbq_in_use = 0; |
| 1987 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1988 | } |
| 1989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1990 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1991 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1992 | * @phba: Pointer to HBA context object. |
| 1993 | * @hbqno: HBQ number. |
| 1994 | * @hbq_buf: Pointer to HBQ buffer. |
| 1995 | * |
| 1996 | * This function is called with the hbalock held to post a |
| 1997 | * hbq buffer to the firmware. If the function finds an empty |
| 1998 | * slot in the HBQ, it will post the buffer. The function will return |
| 1999 | * pointer to the hbq entry if it successfully post the buffer |
| 2000 | * else it will return NULL. |
| 2001 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2002 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2003 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2004 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2005 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2006 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2007 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 2008 | } |
| 2009 | |
| 2010 | /** |
| 2011 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 2012 | * @phba: Pointer to HBA context object. |
| 2013 | * @hbqno: HBQ number. |
| 2014 | * @hbq_buf: Pointer to HBQ buffer. |
| 2015 | * |
| 2016 | * This function is called with the hbalock held to post a hbq buffer to the |
| 2017 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 2018 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 2019 | * it successfully post the buffer else it will return an error. |
| 2020 | **/ |
| 2021 | static int |
| 2022 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 2023 | struct hbq_dmabuf *hbq_buf) |
| 2024 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2025 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2026 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2027 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2028 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2029 | /* Get next HBQ entry slot to use */ |
| 2030 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 2031 | if (hbqe) { |
| 2032 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2033 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2034 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 2035 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2036 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2037 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2038 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 2039 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 2040 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2041 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 2042 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2043 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2044 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2045 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2046 | return 0; |
| 2047 | } else |
| 2048 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2049 | } |
| 2050 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2051 | /** |
| 2052 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 2053 | * @phba: Pointer to HBA context object. |
| 2054 | * @hbqno: HBQ number. |
| 2055 | * @hbq_buf: Pointer to HBQ buffer. |
| 2056 | * |
| 2057 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 2058 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 2059 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 2060 | **/ |
| 2061 | static int |
| 2062 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 2063 | struct hbq_dmabuf *hbq_buf) |
| 2064 | { |
| 2065 | int rc; |
| 2066 | struct lpfc_rqe hrqe; |
| 2067 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2068 | struct lpfc_queue *hrq; |
| 2069 | struct lpfc_queue *drq; |
| 2070 | |
| 2071 | if (hbqno != LPFC_ELS_HBQ) |
| 2072 | return 1; |
| 2073 | hrq = phba->sli4_hba.hdr_rq; |
| 2074 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2075 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2076 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2077 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 2078 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 2079 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 2080 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2081 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2082 | if (rc < 0) |
| 2083 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2084 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2085 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 2086 | return 0; |
| 2087 | } |
| 2088 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2089 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2090 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 2091 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2092 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2093 | .mask_count = 0, |
| 2094 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2095 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2096 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2097 | .init_count = 40, |
| 2098 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2099 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2100 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2101 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2102 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2103 | &lpfc_els_hbq, |
| 2104 | }; |
| 2105 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2106 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2107 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2108 | * @phba: Pointer to HBA context object. |
| 2109 | * @hbqno: HBQ number. |
| 2110 | * @count: Number of HBQ buffers to be posted. |
| 2111 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2112 | * This function is called with no lock held to post more hbq buffers to the |
| 2113 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 2114 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2115 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2116 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2117 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 2118 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2119 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2120 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2121 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2122 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2123 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2124 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2125 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2126 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 2127 | lpfc_hbq_defs[hbqno]->entry_count) |
| 2128 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 2129 | phba->hbqs[hbqno].buffer_count; |
| 2130 | if (!count) |
| 2131 | return 0; |
| 2132 | /* Allocate HBQ entries */ |
| 2133 | for (i = 0; i < count; i++) { |
| 2134 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 2135 | if (!hbq_buffer) |
| 2136 | break; |
| 2137 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 2138 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2139 | /* Check whether HBQ is still in use */ |
| 2140 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2141 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2142 | goto err; |
| 2143 | while (!list_empty(&hbq_buf_list)) { |
| 2144 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2145 | dbuf.list); |
| 2146 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 2147 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2148 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2149 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2150 | posted++; |
| 2151 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2152 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2153 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2154 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2155 | return posted; |
| 2156 | err: |
| 2157 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2158 | while (!list_empty(&hbq_buf_list)) { |
| 2159 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2160 | dbuf.list); |
| 2161 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 2162 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2163 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2164 | } |
| 2165 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2166 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2167 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2168 | * @phba: Pointer to HBA context object. |
| 2169 | * @qno: HBQ number. |
| 2170 | * |
| 2171 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2172 | * is called with no lock held. The function returns the number of HBQ entries |
| 2173 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2174 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2175 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2176 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2177 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2178 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2179 | return 0; |
| 2180 | else |
| 2181 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2182 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2183 | } |
| 2184 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2185 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2186 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2187 | * @phba: Pointer to HBA context object. |
| 2188 | * @qno: HBQ queue number. |
| 2189 | * |
| 2190 | * This function is called from SLI initialization code path with |
| 2191 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2192 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2193 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2194 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2195 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2196 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2197 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2198 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2199 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2200 | else |
| 2201 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2202 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2203 | } |
| 2204 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2205 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2206 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 2207 | * @phba: Pointer to HBA context object. |
| 2208 | * @hbqno: HBQ number. |
| 2209 | * |
| 2210 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2211 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2212 | **/ |
| 2213 | static struct hbq_dmabuf * |
| 2214 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2215 | { |
| 2216 | struct lpfc_dmabuf *d_buf; |
| 2217 | |
| 2218 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2219 | if (!d_buf) |
| 2220 | return NULL; |
| 2221 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2222 | } |
| 2223 | |
| 2224 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2225 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2226 | * @phba: Pointer to HBA context object. |
| 2227 | * @hbqno: HBQ number. |
| 2228 | * |
| 2229 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2230 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2231 | **/ |
| 2232 | static struct rqb_dmabuf * |
| 2233 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2234 | { |
| 2235 | struct lpfc_dmabuf *h_buf; |
| 2236 | struct lpfc_rqb *rqbp; |
| 2237 | |
| 2238 | rqbp = hrq->rqbp; |
| 2239 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2240 | struct lpfc_dmabuf, list); |
| 2241 | if (!h_buf) |
| 2242 | return NULL; |
| 2243 | rqbp->buffer_count--; |
| 2244 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2245 | } |
| 2246 | |
| 2247 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2248 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2249 | * @phba: Pointer to HBA context object. |
| 2250 | * @tag: Tag of the hbq buffer. |
| 2251 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2252 | * This function searches for the hbq buffer associated with the given tag in |
| 2253 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2254 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2255 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2256 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2257 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2258 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2259 | struct lpfc_dmabuf *d_buf; |
| 2260 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2261 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2262 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2263 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2264 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2265 | return NULL; |
| 2266 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2267 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2268 | 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] | 2269 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2270 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2271 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2272 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2273 | } |
| 2274 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2275 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2276 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2277 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2278 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2279 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2280 | } |
| 2281 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2282 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2283 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2284 | * @phba: Pointer to HBA context object. |
| 2285 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2286 | * |
| 2287 | * This function is called with hbalock. This function gives back |
| 2288 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2289 | * post the buffer, it will free the buffer. |
| 2290 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2291 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2292 | 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] | 2293 | { |
| 2294 | uint32_t hbqno; |
| 2295 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2296 | if (hbq_buffer) { |
| 2297 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2298 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2299 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2303 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2304 | * 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] | 2305 | * @mbxCommand: mailbox command code. |
| 2306 | * |
| 2307 | * This function is called by the mailbox event handler function to verify |
| 2308 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2309 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2310 | * and the mailbox event handler will take the HBA offline. |
| 2311 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2312 | static int |
| 2313 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2314 | { |
| 2315 | uint8_t ret; |
| 2316 | |
| 2317 | switch (mbxCommand) { |
| 2318 | case MBX_LOAD_SM: |
| 2319 | case MBX_READ_NV: |
| 2320 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2321 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | case MBX_RUN_BIU_DIAG: |
| 2323 | case MBX_INIT_LINK: |
| 2324 | case MBX_DOWN_LINK: |
| 2325 | case MBX_CONFIG_LINK: |
| 2326 | case MBX_CONFIG_RING: |
| 2327 | case MBX_RESET_RING: |
| 2328 | case MBX_READ_CONFIG: |
| 2329 | case MBX_READ_RCONFIG: |
| 2330 | case MBX_READ_SPARM: |
| 2331 | case MBX_READ_STATUS: |
| 2332 | case MBX_READ_RPI: |
| 2333 | case MBX_READ_XRI: |
| 2334 | case MBX_READ_REV: |
| 2335 | case MBX_READ_LNK_STAT: |
| 2336 | case MBX_REG_LOGIN: |
| 2337 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2338 | case MBX_CLEAR_LA: |
| 2339 | case MBX_DUMP_MEMORY: |
| 2340 | case MBX_DUMP_CONTEXT: |
| 2341 | case MBX_RUN_DIAGS: |
| 2342 | case MBX_RESTART: |
| 2343 | case MBX_UPDATE_CFG: |
| 2344 | case MBX_DOWN_LOAD: |
| 2345 | case MBX_DEL_LD_ENTRY: |
| 2346 | case MBX_RUN_PROGRAM: |
| 2347 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2348 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2349 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2350 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2351 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2352 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2353 | case MBX_LOAD_AREA: |
| 2354 | case MBX_RUN_BIU_DIAG64: |
| 2355 | case MBX_CONFIG_PORT: |
| 2356 | case MBX_READ_SPARM64: |
| 2357 | case MBX_READ_RPI64: |
| 2358 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2359 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2360 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | case MBX_SET_DEBUG: |
| 2362 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2363 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2364 | case MBX_REG_VPI: |
| 2365 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2366 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2367 | case MBX_PORT_CAPABILITIES: |
| 2368 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2369 | case MBX_SLI4_CONFIG: |
| 2370 | case MBX_SLI4_REQ_FTRS: |
| 2371 | case MBX_REG_FCFI: |
| 2372 | case MBX_UNREG_FCFI: |
| 2373 | case MBX_REG_VFI: |
| 2374 | case MBX_UNREG_VFI: |
| 2375 | case MBX_INIT_VPI: |
| 2376 | case MBX_INIT_VFI: |
| 2377 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2378 | case MBX_READ_EVENT_LOG_STATUS: |
| 2379 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2380 | case MBX_SECURITY_MGMT: |
| 2381 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2382 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2383 | ret = mbxCommand; |
| 2384 | break; |
| 2385 | default: |
| 2386 | ret = MBX_SHUTDOWN; |
| 2387 | break; |
| 2388 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2389 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2390 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2391 | |
| 2392 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2393 | * 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] | 2394 | * @phba: Pointer to HBA context object. |
| 2395 | * @pmboxq: Pointer to mailbox command. |
| 2396 | * |
| 2397 | * This is completion handler function for mailbox commands issued from |
| 2398 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2399 | * mailbox event handler function with no lock held. This function |
| 2400 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2401 | * of the mailbox. |
| 2402 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2403 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2404 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2405 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2406 | unsigned long drvr_flag; |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2407 | struct completion *pmbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | |
| 2409 | /* |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2410 | * If pmbox_done is empty, the driver thread gave up waiting and |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2411 | * continued running. |
| 2412 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2413 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2414 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2415 | pmbox_done = (struct completion *)pmboxq->context3; |
| 2416 | if (pmbox_done) |
| 2417 | complete(pmbox_done); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2418 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2419 | return; |
| 2420 | } |
| 2421 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2422 | |
| 2423 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2424 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2425 | * @phba: Pointer to HBA context object. |
| 2426 | * @pmb: Pointer to mailbox object. |
| 2427 | * |
| 2428 | * This function is the default mailbox completion handler. It |
| 2429 | * frees the memory resources associated with the completed mailbox |
| 2430 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2431 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2432 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2433 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2434 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2436 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2438 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2439 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2440 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2441 | int rc; |
| 2442 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2443 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2444 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2445 | if (mp) { |
| 2446 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2447 | kfree(mp); |
| 2448 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2449 | |
| 2450 | /* |
| 2451 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2452 | * is in re-discovery driver need to cleanup the RPI. |
| 2453 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2454 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2455 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2456 | !pmb->u.mb.mbxStatus) { |
| 2457 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2458 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2459 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2460 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2461 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2462 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2463 | if (rc != MBX_NOT_FINISHED) |
| 2464 | return; |
| 2465 | } |
| 2466 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2467 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2468 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2469 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2470 | shost = lpfc_shost_from_vport(vport); |
| 2471 | spin_lock_irq(shost->host_lock); |
| 2472 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2473 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2474 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2475 | } |
| 2476 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2477 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2478 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2479 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2480 | pmb->ctx_buf = NULL; |
| 2481 | pmb->ctx_ndlp = NULL; |
| 2482 | } |
| 2483 | |
| 2484 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2485 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
| 2486 | |
| 2487 | /* Check to see if there are any deferred events to process */ |
| 2488 | if (ndlp) { |
| 2489 | lpfc_printf_vlog( |
| 2490 | vport, |
| 2491 | KERN_INFO, LOG_MBOX | LOG_DISCOVERY, |
| 2492 | "1438 UNREG cmpl deferred mbox x%x " |
| 2493 | "on NPort x%x Data: x%x x%x %p\n", |
| 2494 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2495 | ndlp->nlp_flag, ndlp->nlp_defer_did, ndlp); |
| 2496 | |
| 2497 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2498 | (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) { |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2499 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2500 | ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING; |
| 2501 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2502 | } else { |
| 2503 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2504 | } |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2505 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2506 | pmb->ctx_ndlp = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2507 | } |
| 2508 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2509 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2510 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2511 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2512 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2513 | "2860 SLI authentication is required " |
| 2514 | "for INIT_LINK but has not done yet\n"); |
| 2515 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2516 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2517 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2518 | else |
| 2519 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2520 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2521 | /** |
| 2522 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2523 | * @phba: Pointer to HBA context object. |
| 2524 | * @pmb: Pointer to mailbox object. |
| 2525 | * |
| 2526 | * This function is the unreg rpi mailbox completion handler. It |
| 2527 | * frees the memory resources associated with the completed mailbox |
| 2528 | * command. An additional refrenece is put on the ndlp to prevent |
| 2529 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2530 | * the unreg mailbox command completes, this routine puts the |
| 2531 | * reference back. |
| 2532 | * |
| 2533 | **/ |
| 2534 | void |
| 2535 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2536 | { |
| 2537 | struct lpfc_vport *vport = pmb->vport; |
| 2538 | struct lpfc_nodelist *ndlp; |
| 2539 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 2540 | ndlp = pmb->ctx_ndlp; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2541 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2542 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2543 | (bf_get(lpfc_sli_intf_if_type, |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2544 | &phba->sli4_hba.sli_intf) >= |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2545 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2546 | if (ndlp) { |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2547 | lpfc_printf_vlog( |
| 2548 | vport, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 2549 | "0010 UNREG_LOGIN vpi:%x " |
| 2550 | "rpi:%x DID:%x defer x%x flg x%x " |
| 2551 | "map:%x %p\n", |
| 2552 | vport->vpi, ndlp->nlp_rpi, |
| 2553 | ndlp->nlp_DID, ndlp->nlp_defer_did, |
| 2554 | ndlp->nlp_flag, |
| 2555 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2556 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2557 | lpfc_nlp_put(ndlp); |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2558 | |
| 2559 | /* Check to see if there are any deferred |
| 2560 | * events to process |
| 2561 | */ |
| 2562 | if ((ndlp->nlp_flag & NLP_UNREG_INP) && |
| 2563 | (ndlp->nlp_defer_did != |
| 2564 | NLP_EVT_NOTHING_PENDING)) { |
| 2565 | lpfc_printf_vlog( |
| 2566 | vport, KERN_INFO, LOG_DISCOVERY, |
| 2567 | "4111 UNREG cmpl deferred " |
| 2568 | "clr x%x on " |
| 2569 | "NPort x%x Data: x%x %p\n", |
| 2570 | ndlp->nlp_rpi, ndlp->nlp_DID, |
| 2571 | ndlp->nlp_defer_did, ndlp); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2572 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2573 | ndlp->nlp_defer_did = |
| 2574 | NLP_EVT_NOTHING_PENDING; |
| 2575 | lpfc_issue_els_plogi( |
| 2576 | vport, ndlp->nlp_DID, 0); |
James Smart | 00292e0 | 2018-12-13 15:17:55 -0800 | [diff] [blame] | 2577 | } else { |
| 2578 | ndlp->nlp_flag &= ~NLP_UNREG_INP; |
James Smart | dea16bd | 2018-11-29 16:09:30 -0800 | [diff] [blame] | 2579 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2580 | } |
| 2581 | } |
| 2582 | } |
| 2583 | |
| 2584 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2585 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2586 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2587 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2588 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2589 | * @phba: Pointer to HBA context object. |
| 2590 | * |
| 2591 | * This function is called with no lock held. This function processes all |
| 2592 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2593 | * service routine processes mailbox completion interrupt and adds completed |
| 2594 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2595 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2596 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2597 | * function returns the mailbox commands to the upper layer by calling the |
| 2598 | * completion handler function of each mailbox. |
| 2599 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2600 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2601 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2602 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2603 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2604 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2605 | int rc; |
| 2606 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2607 | |
| 2608 | phba->sli.slistat.mbox_event++; |
| 2609 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2610 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2611 | spin_lock_irq(&phba->hbalock); |
| 2612 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2613 | spin_unlock_irq(&phba->hbalock); |
| 2614 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2615 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2616 | do { |
| 2617 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2618 | if (pmb == NULL) |
| 2619 | break; |
| 2620 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2621 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2622 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2623 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2624 | if (pmb->vport) { |
| 2625 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2626 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2627 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2628 | (uint32_t)pmbox->mbxCommand, |
| 2629 | pmbox->un.varWords[0], |
| 2630 | pmbox->un.varWords[1]); |
| 2631 | } |
| 2632 | else { |
| 2633 | lpfc_debugfs_disc_trc(phba->pport, |
| 2634 | LPFC_DISC_TRC_MBOX, |
| 2635 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2636 | (uint32_t)pmbox->mbxCommand, |
| 2637 | pmbox->un.varWords[0], |
| 2638 | pmbox->un.varWords[1]); |
| 2639 | } |
| 2640 | } |
| 2641 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2642 | /* |
| 2643 | * It is a fatal error if unknown mbox command completion. |
| 2644 | */ |
| 2645 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2646 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2647 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2648 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2649 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2650 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2651 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2652 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2653 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2654 | pmb), |
| 2655 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2656 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2657 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | phba->work_hs = HS_FFER3; |
| 2659 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2660 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2661 | } |
| 2662 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | if (pmbox->mbxStatus) { |
| 2664 | phba->sli.slistat.mbox_stat_err++; |
| 2665 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2666 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2667 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2668 | LOG_MBOX | LOG_SLI, |
| 2669 | "(%d):0305 Mbox cmd cmpl " |
| 2670 | "error - RETRYing Data: x%x " |
| 2671 | "(x%x/x%x) x%x x%x x%x\n", |
| 2672 | pmb->vport ? pmb->vport->vpi : 0, |
| 2673 | pmbox->mbxCommand, |
| 2674 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2675 | pmb), |
| 2676 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2677 | pmb), |
| 2678 | pmbox->mbxStatus, |
| 2679 | pmbox->un.varWords[0], |
| 2680 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2681 | pmbox->mbxStatus = 0; |
| 2682 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2683 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2684 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2685 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2686 | } |
| 2687 | } |
| 2688 | |
| 2689 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2690 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2691 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2692 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2693 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2694 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2695 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2696 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2697 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2698 | pmb->mbox_cmpl, |
| 2699 | *((uint32_t *) pmbox), |
| 2700 | pmbox->un.varWords[0], |
| 2701 | pmbox->un.varWords[1], |
| 2702 | pmbox->un.varWords[2], |
| 2703 | pmbox->un.varWords[3], |
| 2704 | pmbox->un.varWords[4], |
| 2705 | pmbox->un.varWords[5], |
| 2706 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2707 | pmbox->un.varWords[7], |
| 2708 | pmbox->un.varWords[8], |
| 2709 | pmbox->un.varWords[9], |
| 2710 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2711 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2712 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2713 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2714 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2715 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2717 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2718 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2719 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2720 | * @phba: Pointer to HBA context object. |
| 2721 | * @pring: Pointer to driver SLI ring object. |
| 2722 | * @tag: buffer tag. |
| 2723 | * |
| 2724 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2725 | * is set in the tag the buffer is posted for a particular exchange, |
| 2726 | * the function will return the buffer without replacing the buffer. |
| 2727 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2728 | * returns the buffer and also posts another buffer to the firmware. |
| 2729 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2730 | static struct lpfc_dmabuf * |
| 2731 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2732 | struct lpfc_sli_ring *pring, |
| 2733 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2734 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2735 | struct hbq_dmabuf *hbq_entry; |
| 2736 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2737 | if (tag & QUE_BUFTAG_BIT) |
| 2738 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2739 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2740 | if (!hbq_entry) |
| 2741 | return NULL; |
| 2742 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2743 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2744 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2745 | /** |
| 2746 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2747 | * @phba: Pointer to HBA context object. |
| 2748 | * @pring: Pointer to driver SLI ring object. |
| 2749 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2750 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2751 | * @fch_type: the type for the first frame of the sequence. |
| 2752 | * |
| 2753 | * This function is called with no lock held. This function uses the r_ctl and |
| 2754 | * type of the received sequence to find the correct callback function to call |
| 2755 | * to process the sequence. |
| 2756 | **/ |
| 2757 | static int |
| 2758 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2759 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2760 | uint32_t fch_type) |
| 2761 | { |
| 2762 | int i; |
| 2763 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2764 | switch (fch_type) { |
| 2765 | case FC_TYPE_NVME: |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2766 | lpfc_nvmet_unsol_ls_event(phba, pring, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2767 | return 1; |
| 2768 | default: |
| 2769 | break; |
| 2770 | } |
| 2771 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2772 | /* unSolicited Responses */ |
| 2773 | if (pring->prt[0].profile) { |
| 2774 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2775 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2776 | saveq); |
| 2777 | return 1; |
| 2778 | } |
| 2779 | /* We must search, based on rctl / type |
| 2780 | for the right routine */ |
| 2781 | for (i = 0; i < pring->num_mask; i++) { |
| 2782 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2783 | (pring->prt[i].type == fch_type)) { |
| 2784 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2785 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2786 | (phba, pring, saveq); |
| 2787 | return 1; |
| 2788 | } |
| 2789 | } |
| 2790 | return 0; |
| 2791 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2792 | |
| 2793 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2794 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2795 | * @phba: Pointer to HBA context object. |
| 2796 | * @pring: Pointer to driver SLI ring object. |
| 2797 | * @saveq: Pointer to the unsolicited iocb. |
| 2798 | * |
| 2799 | * This function is called with no lock held by the ring event handler |
| 2800 | * when there is an unsolicited iocb posted to the response ring by the |
| 2801 | * firmware. This function gets the buffer associated with the iocbs |
| 2802 | * and calls the event handler for the ring. This function handles both |
| 2803 | * qring buffers and hbq buffers. |
| 2804 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2805 | * upper layer functions will free the iocb objects. |
| 2806 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2807 | static int |
| 2808 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2809 | struct lpfc_iocbq *saveq) |
| 2810 | { |
| 2811 | IOCB_t * irsp; |
| 2812 | WORD5 * w5p; |
| 2813 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2814 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2815 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2816 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2818 | |
| 2819 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2820 | if (pring->lpfc_sli_rcv_async_status) |
| 2821 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2822 | else |
| 2823 | lpfc_printf_log(phba, |
| 2824 | KERN_WARNING, |
| 2825 | LOG_SLI, |
| 2826 | "0316 Ring %d handler: unexpected " |
| 2827 | "ASYNC_STATUS iocb received evt_code " |
| 2828 | "0x%x\n", |
| 2829 | pring->ringno, |
| 2830 | irsp->un.asyncstat.evt_code); |
| 2831 | return 1; |
| 2832 | } |
| 2833 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2834 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2835 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2836 | if (irsp->ulpBdeCount > 0) { |
| 2837 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2838 | irsp->un.ulpWord[3]); |
| 2839 | lpfc_in_buf_free(phba, dmzbuf); |
| 2840 | } |
| 2841 | |
| 2842 | if (irsp->ulpBdeCount > 1) { |
| 2843 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2844 | irsp->unsli3.sli3Words[3]); |
| 2845 | lpfc_in_buf_free(phba, dmzbuf); |
| 2846 | } |
| 2847 | |
| 2848 | if (irsp->ulpBdeCount > 2) { |
| 2849 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2850 | irsp->unsli3.sli3Words[7]); |
| 2851 | lpfc_in_buf_free(phba, dmzbuf); |
| 2852 | } |
| 2853 | |
| 2854 | return 1; |
| 2855 | } |
| 2856 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2857 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2858 | if (irsp->ulpBdeCount != 0) { |
| 2859 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2860 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2861 | if (!saveq->context2) |
| 2862 | lpfc_printf_log(phba, |
| 2863 | KERN_ERR, |
| 2864 | LOG_SLI, |
| 2865 | "0341 Ring %d Cannot find buffer for " |
| 2866 | "an unsolicited iocb. tag 0x%x\n", |
| 2867 | pring->ringno, |
| 2868 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2869 | } |
| 2870 | if (irsp->ulpBdeCount == 2) { |
| 2871 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2872 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2873 | if (!saveq->context3) |
| 2874 | lpfc_printf_log(phba, |
| 2875 | KERN_ERR, |
| 2876 | LOG_SLI, |
| 2877 | "0342 Ring %d Cannot find buffer for an" |
| 2878 | " unsolicited iocb. tag 0x%x\n", |
| 2879 | pring->ringno, |
| 2880 | irsp->unsli3.sli3Words[7]); |
| 2881 | } |
| 2882 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2883 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2884 | if (irsp->ulpBdeCount != 0) { |
| 2885 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2886 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2887 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2888 | lpfc_printf_log(phba, |
| 2889 | KERN_ERR, |
| 2890 | LOG_SLI, |
| 2891 | "0343 Ring %d Cannot find " |
| 2892 | "buffer for an unsolicited iocb" |
| 2893 | ". tag 0x%x\n", pring->ringno, |
| 2894 | irsp->un.ulpWord[3]); |
| 2895 | } |
| 2896 | if (irsp->ulpBdeCount == 2) { |
| 2897 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2898 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2899 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2900 | lpfc_printf_log(phba, |
| 2901 | KERN_ERR, |
| 2902 | LOG_SLI, |
| 2903 | "0344 Ring %d Cannot find " |
| 2904 | "buffer for an unsolicited " |
| 2905 | "iocb. tag 0x%x\n", |
| 2906 | pring->ringno, |
| 2907 | irsp->unsli3.sli3Words[7]); |
| 2908 | } |
| 2909 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2910 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2911 | if (irsp->ulpBdeCount != 0 && |
| 2912 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2913 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2914 | int found = 0; |
| 2915 | |
| 2916 | /* search continue save q for same XRI */ |
| 2917 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2918 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2919 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2920 | list_add_tail(&saveq->list, &iocbq->list); |
| 2921 | found = 1; |
| 2922 | break; |
| 2923 | } |
| 2924 | } |
| 2925 | if (!found) |
| 2926 | list_add_tail(&saveq->clist, |
| 2927 | &pring->iocb_continue_saveq); |
| 2928 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2929 | list_del_init(&iocbq->clist); |
| 2930 | saveq = iocbq; |
| 2931 | irsp = &(saveq->iocb); |
| 2932 | } else |
| 2933 | return 0; |
| 2934 | } |
| 2935 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2936 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2937 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2938 | Rctl = FC_RCTL_ELS_REQ; |
| 2939 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2940 | } else { |
| 2941 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2942 | Rctl = w5p->hcsw.Rctl; |
| 2943 | Type = w5p->hcsw.Type; |
| 2944 | |
| 2945 | /* Firmware Workaround */ |
| 2946 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2947 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2948 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2949 | Rctl = FC_RCTL_ELS_REQ; |
| 2950 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2951 | w5p->hcsw.Rctl = Rctl; |
| 2952 | w5p->hcsw.Type = Type; |
| 2953 | } |
| 2954 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2955 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2956 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2957 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2958 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2959 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2960 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2961 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2962 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2963 | } |
| 2964 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2965 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2966 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2967 | * @phba: Pointer to HBA context object. |
| 2968 | * @pring: Pointer to driver SLI ring object. |
| 2969 | * @prspiocb: Pointer to response iocb object. |
| 2970 | * |
| 2971 | * This function looks up the iocb_lookup table to get the command iocb |
| 2972 | * corresponding to the given response iocb using the iotag of the |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 2973 | * response iocb. This function is called with the hbalock held |
| 2974 | * for sli3 devices or the ring_lock for sli4 devices. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2975 | * This function returns the command iocb object if it finds the command |
| 2976 | * iocb else returns NULL. |
| 2977 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2978 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2979 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2980 | struct lpfc_sli_ring *pring, |
| 2981 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2982 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2984 | uint16_t iotag; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2985 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2986 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2987 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2988 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2989 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2990 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2991 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2992 | /* remove from txcmpl queue list */ |
| 2993 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2994 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 2995 | pring->txcmplq_cnt--; |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2996 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2997 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2998 | } |
| 2999 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3001 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3002 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3003 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3004 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3005 | return NULL; |
| 3006 | } |
| 3007 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3008 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3009 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 3010 | * @phba: Pointer to HBA context object. |
| 3011 | * @pring: Pointer to driver SLI ring object. |
| 3012 | * @iotag: IOCB tag. |
| 3013 | * |
| 3014 | * This function looks up the iocb_lookup table to get the command iocb |
| 3015 | * corresponding to the given iotag. This function is called with the |
| 3016 | * hbalock held. |
| 3017 | * This function returns the command iocb object if it finds the command |
| 3018 | * iocb else returns NULL. |
| 3019 | **/ |
| 3020 | static struct lpfc_iocbq * |
| 3021 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 3022 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 3023 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3024 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3025 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 3026 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3027 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 3028 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3029 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 3030 | /* remove from txcmpl queue list */ |
| 3031 | list_del_init(&cmd_iocb->list); |
| 3032 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3033 | pring->txcmplq_cnt--; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3034 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3035 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3036 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3037 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3038 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3039 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 3040 | "iocb_flag x%x\n", |
| 3041 | iotag, phba->sli.last_iotag, |
| 3042 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3043 | return NULL; |
| 3044 | } |
| 3045 | |
| 3046 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3047 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3048 | * @phba: Pointer to HBA context object. |
| 3049 | * @pring: Pointer to driver SLI ring object. |
| 3050 | * @saveq: Pointer to the response iocb to be processed. |
| 3051 | * |
| 3052 | * This function is called by the ring event handler for non-fcp |
| 3053 | * rings when there is a new response iocb in the response ring. |
| 3054 | * The caller is not required to hold any locks. This function |
| 3055 | * gets the command iocb associated with the response iocb and |
| 3056 | * calls the completion handler for the command iocb. If there |
| 3057 | * is no completion handler, the function will free the resources |
| 3058 | * associated with command iocb. If the response iocb is for |
| 3059 | * an already aborted command iocb, the status of the completion |
| 3060 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 3061 | * This function always returns 1. |
| 3062 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3063 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3064 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | struct lpfc_iocbq *saveq) |
| 3066 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3067 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3068 | int rc = 1; |
| 3069 | unsigned long iflag; |
| 3070 | |
| 3071 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 3072 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3073 | spin_lock_irqsave(&pring->ring_lock, iflag); |
| 3074 | else |
| 3075 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3076 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 3077 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3078 | spin_unlock_irqrestore(&pring->ring_lock, iflag); |
| 3079 | else |
| 3080 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3081 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3082 | if (cmdiocbp) { |
| 3083 | if (cmdiocbp->iocb_cmpl) { |
| 3084 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3085 | * If an ELS command failed send an event to mgmt |
| 3086 | * application. |
| 3087 | */ |
| 3088 | if (saveq->iocb.ulpStatus && |
| 3089 | (pring->ringno == LPFC_ELS_RING) && |
| 3090 | (cmdiocbp->iocb.ulpCommand == |
| 3091 | CMD_ELS_REQUEST64_CR)) |
| 3092 | lpfc_send_els_failure_event(phba, |
| 3093 | cmdiocbp, saveq); |
| 3094 | |
| 3095 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3096 | * Post all ELS completions to the worker thread. |
| 3097 | * All other are passed to the completion callback. |
| 3098 | */ |
| 3099 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3100 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3101 | (cmdiocbp->iocb_flag & |
| 3102 | LPFC_DRIVER_ABORTED)) { |
| 3103 | spin_lock_irqsave(&phba->hbalock, |
| 3104 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3105 | cmdiocbp->iocb_flag &= |
| 3106 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3107 | spin_unlock_irqrestore(&phba->hbalock, |
| 3108 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3109 | saveq->iocb.ulpStatus = |
| 3110 | IOSTAT_LOCAL_REJECT; |
| 3111 | saveq->iocb.un.ulpWord[4] = |
| 3112 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3113 | |
| 3114 | /* Firmware could still be in progress |
| 3115 | * of DMAing payload, so don't free data |
| 3116 | * buffer till after a hbeat. |
| 3117 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3118 | spin_lock_irqsave(&phba->hbalock, |
| 3119 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3120 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3121 | spin_unlock_irqrestore(&phba->hbalock, |
| 3122 | iflag); |
| 3123 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3124 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3125 | if (saveq->iocb_flag & |
| 3126 | LPFC_EXCHANGE_BUSY) { |
| 3127 | /* Set cmdiocb flag for the |
| 3128 | * exchange busy so sgl (xri) |
| 3129 | * will not be released until |
| 3130 | * the abort xri is received |
| 3131 | * from hba. |
| 3132 | */ |
| 3133 | spin_lock_irqsave( |
| 3134 | &phba->hbalock, iflag); |
| 3135 | cmdiocbp->iocb_flag |= |
| 3136 | LPFC_EXCHANGE_BUSY; |
| 3137 | spin_unlock_irqrestore( |
| 3138 | &phba->hbalock, iflag); |
| 3139 | } |
| 3140 | if (cmdiocbp->iocb_flag & |
| 3141 | LPFC_DRIVER_ABORTED) { |
| 3142 | /* |
| 3143 | * Clear LPFC_DRIVER_ABORTED |
| 3144 | * bit in case it was driver |
| 3145 | * initiated abort. |
| 3146 | */ |
| 3147 | spin_lock_irqsave( |
| 3148 | &phba->hbalock, iflag); |
| 3149 | cmdiocbp->iocb_flag &= |
| 3150 | ~LPFC_DRIVER_ABORTED; |
| 3151 | spin_unlock_irqrestore( |
| 3152 | &phba->hbalock, iflag); |
| 3153 | cmdiocbp->iocb.ulpStatus = |
| 3154 | IOSTAT_LOCAL_REJECT; |
| 3155 | cmdiocbp->iocb.un.ulpWord[4] = |
| 3156 | IOERR_ABORT_REQUESTED; |
| 3157 | /* |
| 3158 | * For SLI4, irsiocb contains |
| 3159 | * NO_XRI in sli_xritag, it |
| 3160 | * shall not affect releasing |
| 3161 | * sgl (xri) process. |
| 3162 | */ |
| 3163 | saveq->iocb.ulpStatus = |
| 3164 | IOSTAT_LOCAL_REJECT; |
| 3165 | saveq->iocb.un.ulpWord[4] = |
| 3166 | IOERR_SLI_ABORTED; |
| 3167 | spin_lock_irqsave( |
| 3168 | &phba->hbalock, iflag); |
| 3169 | saveq->iocb_flag |= |
| 3170 | LPFC_DELAY_MEM_FREE; |
| 3171 | spin_unlock_irqrestore( |
| 3172 | &phba->hbalock, iflag); |
| 3173 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3174 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3175 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3176 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3177 | } else |
| 3178 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3179 | } else { |
| 3180 | /* |
| 3181 | * Unknown initiating command based on the response iotag. |
| 3182 | * This could be the case on the ELS ring because of |
| 3183 | * lpfc_els_abort(). |
| 3184 | */ |
| 3185 | if (pring->ringno != LPFC_ELS_RING) { |
| 3186 | /* |
| 3187 | * Ring <ringno> handler: unexpected completion IoTag |
| 3188 | * <IoTag> |
| 3189 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3190 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3191 | "0322 Ring %d handler: " |
| 3192 | "unexpected completion IoTag x%x " |
| 3193 | "Data: x%x x%x x%x x%x\n", |
| 3194 | pring->ringno, |
| 3195 | saveq->iocb.ulpIoTag, |
| 3196 | saveq->iocb.ulpStatus, |
| 3197 | saveq->iocb.un.ulpWord[4], |
| 3198 | saveq->iocb.ulpCommand, |
| 3199 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3200 | } |
| 3201 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3202 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | return rc; |
| 3204 | } |
| 3205 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3206 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3207 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3208 | * @phba: Pointer to HBA context object. |
| 3209 | * @pring: Pointer to driver SLI ring object. |
| 3210 | * |
| 3211 | * This function is called from the iocb ring event handlers when |
| 3212 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 3213 | * an error attention condition to the worker thread and the worker |
| 3214 | * thread will transition the HBA to offline state. |
| 3215 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3216 | static void |
| 3217 | 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] | 3218 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3219 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3220 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3221 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3222 | * rsp ring <portRspMax> |
| 3223 | */ |
| 3224 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3225 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3226 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3227 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3228 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3229 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3230 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3231 | |
| 3232 | /* |
| 3233 | * All error attention handlers are posted to |
| 3234 | * worker thread |
| 3235 | */ |
| 3236 | phba->work_ha |= HA_ERATT; |
| 3237 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3238 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3239 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3240 | |
| 3241 | return; |
| 3242 | } |
| 3243 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3244 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3245 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3246 | * @ptr: Pointer to address of HBA context object. |
| 3247 | * |
| 3248 | * This function is invoked by the Error Attention polling timer when the |
| 3249 | * timer times out. It will check the SLI Error Attention register for |
| 3250 | * possible attention events. If so, it will post an Error Attention event |
| 3251 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3252 | * Error Attention polling timer for the next poll. |
| 3253 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3254 | void lpfc_poll_eratt(struct timer_list *t) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3255 | { |
| 3256 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3257 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3258 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3259 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3260 | phba = from_timer(phba, t, eratt_poll); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3261 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3262 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3263 | sli_intr = phba->sli.slistat.sli_intr; |
| 3264 | |
| 3265 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3266 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3267 | sli_intr); |
| 3268 | else |
| 3269 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3270 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3271 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3272 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3273 | phba->sli.slistat.sli_ips = cnt; |
| 3274 | |
| 3275 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3276 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3277 | /* Check chip HA register for error event */ |
| 3278 | eratt = lpfc_sli_check_eratt(phba); |
| 3279 | |
| 3280 | if (eratt) |
| 3281 | /* Tell the worker thread there is work to do */ |
| 3282 | lpfc_worker_wake_up(phba); |
| 3283 | else |
| 3284 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3285 | mod_timer(&phba->eratt_poll, |
| 3286 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3287 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3288 | return; |
| 3289 | } |
| 3290 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3291 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3292 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3293 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3294 | * @phba: Pointer to HBA context object. |
| 3295 | * @pring: Pointer to driver SLI ring object. |
| 3296 | * @mask: Host attention register mask for this ring. |
| 3297 | * |
| 3298 | * This function is called from the interrupt context when there is a ring |
| 3299 | * event for the fcp ring. The caller does not hold any lock. |
| 3300 | * 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] | 3301 | * 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] | 3302 | * LE bit set. The function will call the completion handler of the command iocb |
| 3303 | * if the response iocb indicates a completion for a command iocb or it is |
| 3304 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3305 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3306 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3307 | * to check it explicitly. |
| 3308 | */ |
| 3309 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3310 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3311 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3312 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3313 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3314 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3315 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3316 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3317 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3318 | uint32_t status; |
| 3319 | uint32_t portRspPut, portRspMax; |
| 3320 | int rc = 1; |
| 3321 | lpfc_iocb_type type; |
| 3322 | unsigned long iflag; |
| 3323 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3324 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3325 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3326 | pring->stats.iocb_event++; |
| 3327 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3328 | /* |
| 3329 | * The next available response entry should never exceed the maximum |
| 3330 | * entries. If it does, treat it as an adapter hardware error. |
| 3331 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3332 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3333 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3334 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3335 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3336 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3337 | return 1; |
| 3338 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3339 | if (phba->fcp_ring_in_use) { |
| 3340 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3341 | return 1; |
| 3342 | } else |
| 3343 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3344 | |
| 3345 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3346 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3347 | /* |
| 3348 | * Fetch an entry off the ring and copy it into a local data |
| 3349 | * structure. The copy involves a byte-swap since the |
| 3350 | * network byte order and pci byte orders are different. |
| 3351 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3352 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3353 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3354 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3355 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3356 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3357 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3358 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3359 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3360 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3361 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3362 | irsp = &rspiocbq.iocb; |
| 3363 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3364 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3365 | pring->stats.iocb_rsp++; |
| 3366 | rsp_cmpl++; |
| 3367 | |
| 3368 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3369 | /* |
| 3370 | * If resource errors reported from HBA, reduce |
| 3371 | * queuedepths of the SCSI device. |
| 3372 | */ |
| 3373 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3374 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3375 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3376 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3377 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3378 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3379 | } |
| 3380 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3381 | /* Rsp ring <ringno> error: IOCB */ |
| 3382 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3383 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3384 | "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] | 3385 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3386 | irsp->un.ulpWord[0], |
| 3387 | irsp->un.ulpWord[1], |
| 3388 | irsp->un.ulpWord[2], |
| 3389 | irsp->un.ulpWord[3], |
| 3390 | irsp->un.ulpWord[4], |
| 3391 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3392 | *(uint32_t *)&irsp->un1, |
| 3393 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3394 | } |
| 3395 | |
| 3396 | switch (type) { |
| 3397 | case LPFC_ABORT_IOCB: |
| 3398 | case LPFC_SOL_IOCB: |
| 3399 | /* |
| 3400 | * Idle exchange closed via ABTS from port. No iocb |
| 3401 | * resources need to be recovered. |
| 3402 | */ |
| 3403 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3404 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3405 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3406 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3407 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3408 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | break; |
| 3410 | } |
| 3411 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3412 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3413 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3414 | if (unlikely(!cmdiocbq)) |
| 3415 | break; |
| 3416 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3417 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3418 | if (cmdiocbq->iocb_cmpl) { |
| 3419 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3420 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3421 | &rspiocbq); |
| 3422 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3423 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3425 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3426 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3427 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3428 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3429 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3430 | default: |
| 3431 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3432 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3433 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3434 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3435 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3436 | dev_warn(&((phba->pcidev)->dev), |
| 3437 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3438 | phba->brd_no, adaptermsg); |
| 3439 | } else { |
| 3440 | /* Unknown IOCB command */ |
| 3441 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3442 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3443 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3444 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3445 | irsp->ulpStatus, |
| 3446 | irsp->ulpIoTag, |
| 3447 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3448 | } |
| 3449 | break; |
| 3450 | } |
| 3451 | |
| 3452 | /* |
| 3453 | * The response IOCB has been processed. Update the ring |
| 3454 | * pointer in SLIM. If the port response put pointer has not |
| 3455 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3456 | * response put pointer. |
| 3457 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3458 | writel(pring->sli.sli3.rspidx, |
| 3459 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3461 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3463 | } |
| 3464 | |
| 3465 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3466 | pring->stats.iocb_rsp_full++; |
| 3467 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3468 | writel(status, phba->CAregaddr); |
| 3469 | readl(phba->CAregaddr); |
| 3470 | } |
| 3471 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3472 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3473 | pring->stats.iocb_cmd_empty++; |
| 3474 | |
| 3475 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3476 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | lpfc_sli_resume_iocb(phba, pring); |
| 3478 | |
| 3479 | if ((pring->lpfc_sli_cmd_available)) |
| 3480 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3481 | |
| 3482 | } |
| 3483 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3484 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3485 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3486 | return rc; |
| 3487 | } |
| 3488 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3489 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3490 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3491 | * @phba: Pointer to HBA context object. |
| 3492 | * @pring: Pointer to driver SLI ring object. |
| 3493 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3494 | * |
| 3495 | * This function is called from the worker thread when there is a slow-path |
| 3496 | * response IOCB to process. This function chains all the response iocbs until |
| 3497 | * seeing the iocb with the LE bit set. The function will call |
| 3498 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3499 | * completion of a command iocb. The function will call the |
| 3500 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3501 | * The function frees the resources or calls the completion handler if this |
| 3502 | * iocb is an abort completion. The function returns NULL when the response |
| 3503 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3504 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3505 | * response iocb passed in. |
| 3506 | **/ |
| 3507 | static struct lpfc_iocbq * |
| 3508 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3509 | struct lpfc_iocbq *rspiocbp) |
| 3510 | { |
| 3511 | struct lpfc_iocbq *saveq; |
| 3512 | struct lpfc_iocbq *cmdiocbp; |
| 3513 | struct lpfc_iocbq *next_iocb; |
| 3514 | IOCB_t *irsp = NULL; |
| 3515 | uint32_t free_saveq; |
| 3516 | uint8_t iocb_cmd_type; |
| 3517 | lpfc_iocb_type type; |
| 3518 | unsigned long iflag; |
| 3519 | int rc; |
| 3520 | |
| 3521 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3522 | /* First add the response iocb to the countinueq list */ |
| 3523 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3524 | pring->iocb_continueq_cnt++; |
| 3525 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3526 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3527 | irsp = &rspiocbp->iocb; |
| 3528 | if (irsp->ulpLe) { |
| 3529 | /* |
| 3530 | * By default, the driver expects to free all resources |
| 3531 | * associated with this iocb completion. |
| 3532 | */ |
| 3533 | free_saveq = 1; |
| 3534 | saveq = list_get_first(&pring->iocb_continueq, |
| 3535 | struct lpfc_iocbq, list); |
| 3536 | irsp = &(saveq->iocb); |
| 3537 | list_del_init(&pring->iocb_continueq); |
| 3538 | pring->iocb_continueq_cnt = 0; |
| 3539 | |
| 3540 | pring->stats.iocb_rsp++; |
| 3541 | |
| 3542 | /* |
| 3543 | * If resource errors reported from HBA, reduce |
| 3544 | * queuedepths of the SCSI device. |
| 3545 | */ |
| 3546 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3547 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3548 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3549 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3550 | phba->lpfc_rampdown_queue_depth(phba); |
| 3551 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3552 | } |
| 3553 | |
| 3554 | if (irsp->ulpStatus) { |
| 3555 | /* Rsp ring <ringno> error: IOCB */ |
| 3556 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3557 | "0328 Rsp Ring %d error: " |
| 3558 | "IOCB Data: " |
| 3559 | "x%x x%x x%x x%x " |
| 3560 | "x%x x%x x%x x%x " |
| 3561 | "x%x x%x x%x x%x " |
| 3562 | "x%x x%x x%x x%x\n", |
| 3563 | pring->ringno, |
| 3564 | irsp->un.ulpWord[0], |
| 3565 | irsp->un.ulpWord[1], |
| 3566 | irsp->un.ulpWord[2], |
| 3567 | irsp->un.ulpWord[3], |
| 3568 | irsp->un.ulpWord[4], |
| 3569 | irsp->un.ulpWord[5], |
| 3570 | *(((uint32_t *) irsp) + 6), |
| 3571 | *(((uint32_t *) irsp) + 7), |
| 3572 | *(((uint32_t *) irsp) + 8), |
| 3573 | *(((uint32_t *) irsp) + 9), |
| 3574 | *(((uint32_t *) irsp) + 10), |
| 3575 | *(((uint32_t *) irsp) + 11), |
| 3576 | *(((uint32_t *) irsp) + 12), |
| 3577 | *(((uint32_t *) irsp) + 13), |
| 3578 | *(((uint32_t *) irsp) + 14), |
| 3579 | *(((uint32_t *) irsp) + 15)); |
| 3580 | } |
| 3581 | |
| 3582 | /* |
| 3583 | * Fetch the IOCB command type and call the correct completion |
| 3584 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3585 | * get freed back to the lpfc_iocb_list by the discovery |
| 3586 | * kernel thread. |
| 3587 | */ |
| 3588 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3589 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3590 | switch (type) { |
| 3591 | case LPFC_SOL_IOCB: |
| 3592 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3593 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3594 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3595 | break; |
| 3596 | |
| 3597 | case LPFC_UNSOL_IOCB: |
| 3598 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3599 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3600 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3601 | if (!rc) |
| 3602 | free_saveq = 0; |
| 3603 | break; |
| 3604 | |
| 3605 | case LPFC_ABORT_IOCB: |
| 3606 | cmdiocbp = NULL; |
| 3607 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3608 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3609 | saveq); |
| 3610 | if (cmdiocbp) { |
| 3611 | /* Call the specified completion routine */ |
| 3612 | if (cmdiocbp->iocb_cmpl) { |
| 3613 | spin_unlock_irqrestore(&phba->hbalock, |
| 3614 | iflag); |
| 3615 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3616 | saveq); |
| 3617 | spin_lock_irqsave(&phba->hbalock, |
| 3618 | iflag); |
| 3619 | } else |
| 3620 | __lpfc_sli_release_iocbq(phba, |
| 3621 | cmdiocbp); |
| 3622 | } |
| 3623 | break; |
| 3624 | |
| 3625 | case LPFC_UNKNOWN_IOCB: |
| 3626 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3627 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3628 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3629 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3630 | MAX_MSG_DATA); |
| 3631 | dev_warn(&((phba->pcidev)->dev), |
| 3632 | "lpfc%d: %s\n", |
| 3633 | phba->brd_no, adaptermsg); |
| 3634 | } else { |
| 3635 | /* Unknown IOCB command */ |
| 3636 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3637 | "0335 Unknown IOCB " |
| 3638 | "command Data: x%x " |
| 3639 | "x%x x%x x%x\n", |
| 3640 | irsp->ulpCommand, |
| 3641 | irsp->ulpStatus, |
| 3642 | irsp->ulpIoTag, |
| 3643 | irsp->ulpContext); |
| 3644 | } |
| 3645 | break; |
| 3646 | } |
| 3647 | |
| 3648 | if (free_saveq) { |
| 3649 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3650 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3651 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3652 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3653 | } |
| 3654 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3655 | } |
| 3656 | rspiocbp = NULL; |
| 3657 | } |
| 3658 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3659 | return rspiocbp; |
| 3660 | } |
| 3661 | |
| 3662 | /** |
| 3663 | * 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] | 3664 | * @phba: Pointer to HBA context object. |
| 3665 | * @pring: Pointer to driver SLI ring object. |
| 3666 | * @mask: Host attention register mask for this ring. |
| 3667 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3668 | * This routine wraps the actual slow_ring event process routine from the |
| 3669 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3670 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3671 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3672 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3673 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3674 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3675 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3676 | } |
| 3677 | |
| 3678 | /** |
| 3679 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3680 | * @phba: Pointer to HBA context object. |
| 3681 | * @pring: Pointer to driver SLI ring object. |
| 3682 | * @mask: Host attention register mask for this ring. |
| 3683 | * |
| 3684 | * This function is called from the worker thread when there is a ring event |
| 3685 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3686 | * remove each response iocb in the response ring and calls the handle |
| 3687 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3688 | **/ |
| 3689 | static void |
| 3690 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3691 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3692 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3693 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3694 | IOCB_t *entry; |
| 3695 | IOCB_t *irsp = NULL; |
| 3696 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3697 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3698 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3699 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3700 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3701 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3702 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3703 | pring->stats.iocb_event++; |
| 3704 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3705 | /* |
| 3706 | * The next available response entry should never exceed the maximum |
| 3707 | * entries. If it does, treat it as an adapter hardware error. |
| 3708 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3709 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3710 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3711 | if (portRspPut >= portRspMax) { |
| 3712 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3713 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3714 | * rsp ring <portRspMax> |
| 3715 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3716 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3717 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3718 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3719 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3721 | phba->link_state = LPFC_HBA_ERROR; |
| 3722 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3723 | |
| 3724 | phba->work_hs = HS_FFER3; |
| 3725 | lpfc_handle_eratt(phba); |
| 3726 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3727 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3731 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3732 | /* |
| 3733 | * Build a completion list and call the appropriate handler. |
| 3734 | * The process is to get the next available response iocb, get |
| 3735 | * a free iocb from the list, copy the response data into the |
| 3736 | * free iocb, insert to the continuation list, and update the |
| 3737 | * next response index to slim. This process makes response |
| 3738 | * iocb's in the ring available to DMA as fast as possible but |
| 3739 | * pays a penalty for a copy operation. Since the iocb is |
| 3740 | * only 32 bytes, this penalty is considered small relative to |
| 3741 | * the PCI reads for register values and a slim write. When |
| 3742 | * the ulpLe field is set, the entire Command has been |
| 3743 | * received. |
| 3744 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3745 | entry = lpfc_resp_iocb(phba, pring); |
| 3746 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3747 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3748 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3749 | if (rspiocbp == NULL) { |
| 3750 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3751 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3752 | break; |
| 3753 | } |
| 3754 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3755 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3756 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3757 | irsp = &rspiocbp->iocb; |
| 3758 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3759 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3760 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3761 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3762 | if (pring->ringno == LPFC_ELS_RING) { |
| 3763 | lpfc_debugfs_slow_ring_trc(phba, |
| 3764 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3765 | *(((uint32_t *) irsp) + 4), |
| 3766 | *(((uint32_t *) irsp) + 6), |
| 3767 | *(((uint32_t *) irsp) + 7)); |
| 3768 | } |
| 3769 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3770 | writel(pring->sli.sli3.rspidx, |
| 3771 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3772 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3773 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3774 | /* Handle the response IOCB */ |
| 3775 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3776 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3777 | |
| 3778 | /* |
| 3779 | * If the port response put pointer has not been updated, sync |
| 3780 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3781 | * response put pointer. |
| 3782 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3783 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3784 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3785 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3786 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3787 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3788 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3789 | /* At least one response entry has been freed */ |
| 3790 | pring->stats.iocb_rsp_full++; |
| 3791 | /* SET RxRE_RSP in Chip Att register */ |
| 3792 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3793 | writel(status, phba->CAregaddr); |
| 3794 | readl(phba->CAregaddr); /* flush */ |
| 3795 | } |
| 3796 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3797 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3798 | pring->stats.iocb_cmd_empty++; |
| 3799 | |
| 3800 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3801 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3802 | lpfc_sli_resume_iocb(phba, pring); |
| 3803 | |
| 3804 | if ((pring->lpfc_sli_cmd_available)) |
| 3805 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3806 | |
| 3807 | } |
| 3808 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3809 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3810 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3811 | } |
| 3812 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3813 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3814 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3815 | * @phba: Pointer to HBA context object. |
| 3816 | * @pring: Pointer to driver SLI ring object. |
| 3817 | * @mask: Host attention register mask for this ring. |
| 3818 | * |
| 3819 | * This function is called from the worker thread when there is a pending |
| 3820 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3821 | * queue. The caller does not hold any lock. The function will remove each |
| 3822 | * response iocb from the response worker queue and calls the handle |
| 3823 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3824 | **/ |
| 3825 | static void |
| 3826 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3827 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3828 | { |
| 3829 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3830 | struct hbq_dmabuf *dmabuf; |
| 3831 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3832 | unsigned long iflag; |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3833 | int count = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3834 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3835 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3836 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3837 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3838 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3839 | /* Get the response iocb from the head of work queue */ |
| 3840 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3841 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3842 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3843 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3844 | |
| 3845 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3846 | case CQE_CODE_COMPL_WQE: |
| 3847 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3848 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3849 | /* Translate ELS WCQE to response IOCBQ */ |
| 3850 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3851 | irspiocbq); |
| 3852 | if (irspiocbq) |
| 3853 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3854 | irspiocbq); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3855 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3856 | break; |
| 3857 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3858 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3859 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3860 | cq_event); |
| 3861 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3862 | count++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3863 | break; |
| 3864 | default: |
| 3865 | break; |
| 3866 | } |
James Smart | 0ef01a2 | 2018-09-10 10:30:45 -0700 | [diff] [blame] | 3867 | |
| 3868 | /* Limit the number of events to 64 to avoid soft lockups */ |
| 3869 | if (count == 64) |
| 3870 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3871 | } |
| 3872 | } |
| 3873 | |
| 3874 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3875 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3876 | * @phba: Pointer to HBA context object. |
| 3877 | * @pring: Pointer to driver SLI ring object. |
| 3878 | * |
| 3879 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3880 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3881 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3882 | * the return of this function. The caller is not required to hold any locks. |
| 3883 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3884 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3885 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3886 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3887 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3888 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3890 | if (pring->ringno == LPFC_ELS_RING) { |
| 3891 | lpfc_fabric_abort_hba(phba); |
| 3892 | } |
| 3893 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3894 | /* Error everything on txq and txcmplq |
| 3895 | * First do the txq. |
| 3896 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3897 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3898 | spin_lock_irq(&pring->ring_lock); |
| 3899 | list_splice_init(&pring->txq, &completions); |
| 3900 | pring->txq_cnt = 0; |
| 3901 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3902 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3903 | spin_lock_irq(&phba->hbalock); |
| 3904 | /* Next issue ABTS for everything on the txcmplq */ |
| 3905 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3906 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3907 | spin_unlock_irq(&phba->hbalock); |
| 3908 | } else { |
| 3909 | spin_lock_irq(&phba->hbalock); |
| 3910 | list_splice_init(&pring->txq, &completions); |
| 3911 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3912 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3913 | /* Next issue ABTS for everything on the txcmplq */ |
| 3914 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3915 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3916 | spin_unlock_irq(&phba->hbalock); |
| 3917 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3918 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3919 | /* Cancel all the IOCBs from the completions list */ |
| 3920 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3921 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3922 | } |
| 3923 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3924 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3925 | * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring |
| 3926 | * @phba: Pointer to HBA context object. |
| 3927 | * @pring: Pointer to driver SLI ring object. |
| 3928 | * |
| 3929 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3930 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3931 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3932 | * the return of this function. The caller is not required to hold any locks. |
| 3933 | **/ |
| 3934 | void |
| 3935 | lpfc_sli_abort_wqe_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3936 | { |
| 3937 | LIST_HEAD(completions); |
| 3938 | struct lpfc_iocbq *iocb, *next_iocb; |
| 3939 | |
| 3940 | if (pring->ringno == LPFC_ELS_RING) |
| 3941 | lpfc_fabric_abort_hba(phba); |
| 3942 | |
| 3943 | spin_lock_irq(&phba->hbalock); |
| 3944 | /* Next issue ABTS for everything on the txcmplq */ |
| 3945 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3946 | lpfc_sli4_abort_nvme_io(phba, pring, iocb); |
| 3947 | spin_unlock_irq(&phba->hbalock); |
| 3948 | } |
| 3949 | |
| 3950 | |
| 3951 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3952 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3953 | * @phba: Pointer to HBA context object. |
| 3954 | * @pring: Pointer to driver SLI ring object. |
| 3955 | * |
| 3956 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 3957 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3958 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3959 | * the return of this function. The caller is not required to hold any locks. |
| 3960 | **/ |
| 3961 | void |
| 3962 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 3963 | { |
| 3964 | struct lpfc_sli *psli = &phba->sli; |
| 3965 | struct lpfc_sli_ring *pring; |
| 3966 | uint32_t i; |
| 3967 | |
| 3968 | /* Look on all the FCP Rings for the iotag */ |
| 3969 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 3970 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 3971 | pring = phba->sli4_hba.hdwq[i].fcp_wq->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3972 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3973 | } |
| 3974 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3975 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3976 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3977 | } |
| 3978 | } |
| 3979 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3980 | /** |
| 3981 | * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings |
| 3982 | * @phba: Pointer to HBA context object. |
| 3983 | * |
| 3984 | * This function aborts all wqes in NVME rings. This function issues an |
| 3985 | * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in |
| 3986 | * the txcmplq is not guaranteed to complete before the return of this |
| 3987 | * function. The caller is not required to hold any locks. |
| 3988 | **/ |
| 3989 | void |
| 3990 | lpfc_sli_abort_nvme_rings(struct lpfc_hba *phba) |
| 3991 | { |
| 3992 | struct lpfc_sli_ring *pring; |
| 3993 | uint32_t i; |
| 3994 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 3995 | if ((phba->sli_rev < LPFC_SLI_REV4) || |
| 3996 | !(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3997 | return; |
| 3998 | |
| 3999 | /* Abort all IO on each NVME ring. */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4000 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 4001 | pring = phba->sli4_hba.hdwq[i].nvme_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4002 | lpfc_sli_abort_wqe_ring(phba, pring); |
| 4003 | } |
| 4004 | } |
| 4005 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4006 | |
| 4007 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4008 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4009 | * @phba: Pointer to HBA context object. |
| 4010 | * |
| 4011 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 4012 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 4013 | * for all the iocb commands in txcmplq, they will just be returned with |
| 4014 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4015 | * slot has been permanently disabled. |
| 4016 | **/ |
| 4017 | void |
| 4018 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 4019 | { |
| 4020 | LIST_HEAD(txq); |
| 4021 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4022 | struct lpfc_sli *psli = &phba->sli; |
| 4023 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4024 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4025 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4026 | |
| 4027 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 4028 | /* Indicate the I/O queues are flushed */ |
| 4029 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4030 | spin_unlock_irq(&phba->hbalock); |
| 4031 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4032 | /* Look on all the FCP Rings for the iotag */ |
| 4033 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4034 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 4035 | pring = phba->sli4_hba.hdwq[i].fcp_wq->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4036 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4037 | spin_lock_irq(&pring->ring_lock); |
| 4038 | /* Retrieve everything on txq */ |
| 4039 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4040 | list_for_each_entry_safe(piocb, next_iocb, |
| 4041 | &pring->txcmplq, list) |
| 4042 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4043 | /* Retrieve everything on the txcmplq */ |
| 4044 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4045 | pring->txq_cnt = 0; |
| 4046 | pring->txcmplq_cnt = 0; |
| 4047 | spin_unlock_irq(&pring->ring_lock); |
| 4048 | |
| 4049 | /* Flush the txq */ |
| 4050 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 4051 | IOSTAT_LOCAL_REJECT, |
| 4052 | IOERR_SLI_DOWN); |
| 4053 | /* Flush the txcmpq */ |
| 4054 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4055 | IOSTAT_LOCAL_REJECT, |
| 4056 | IOERR_SLI_DOWN); |
| 4057 | } |
| 4058 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4059 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4060 | |
| 4061 | spin_lock_irq(&phba->hbalock); |
| 4062 | /* Retrieve everything on txq */ |
| 4063 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4064 | list_for_each_entry_safe(piocb, next_iocb, |
| 4065 | &pring->txcmplq, list) |
| 4066 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4067 | /* Retrieve everything on the txcmplq */ |
| 4068 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4069 | pring->txq_cnt = 0; |
| 4070 | pring->txcmplq_cnt = 0; |
| 4071 | spin_unlock_irq(&phba->hbalock); |
| 4072 | |
| 4073 | /* Flush the txq */ |
| 4074 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 4075 | IOERR_SLI_DOWN); |
| 4076 | /* Flush the txcmpq */ |
| 4077 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 4078 | IOERR_SLI_DOWN); |
| 4079 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4080 | } |
| 4081 | |
| 4082 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4083 | * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings |
| 4084 | * @phba: Pointer to HBA context object. |
| 4085 | * |
| 4086 | * This function flushes all wqes in the nvme rings and frees all resources |
| 4087 | * in the txcmplq. This function does not issue abort wqes for the IO |
| 4088 | * commands in txcmplq, they will just be returned with |
| 4089 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4090 | * slot has been permanently disabled. |
| 4091 | **/ |
| 4092 | void |
| 4093 | lpfc_sli_flush_nvme_rings(struct lpfc_hba *phba) |
| 4094 | { |
| 4095 | LIST_HEAD(txcmplq); |
| 4096 | struct lpfc_sli_ring *pring; |
| 4097 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4098 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4099 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4100 | if ((phba->sli_rev < LPFC_SLI_REV4) || |
| 4101 | !(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4102 | return; |
| 4103 | |
| 4104 | /* Hint to other driver operations that a flush is in progress. */ |
| 4105 | spin_lock_irq(&phba->hbalock); |
| 4106 | phba->hba_flag |= HBA_NVME_IOQ_FLUSH; |
| 4107 | spin_unlock_irq(&phba->hbalock); |
| 4108 | |
| 4109 | /* Cycle through all NVME rings and complete each IO with |
| 4110 | * a local driver reason code. This is a flush so no |
| 4111 | * abort exchange to FW. |
| 4112 | */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4113 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 4114 | pring = phba->sli4_hba.hdwq[i].nvme_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4115 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4116 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4117 | list_for_each_entry_safe(piocb, next_iocb, |
| 4118 | &pring->txcmplq, list) |
| 4119 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
| 4120 | /* Retrieve everything on the txcmplq */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4121 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4122 | pring->txcmplq_cnt = 0; |
| 4123 | spin_unlock_irq(&pring->ring_lock); |
| 4124 | |
| 4125 | /* Flush the txcmpq &&&PAE */ |
| 4126 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4127 | IOSTAT_LOCAL_REJECT, |
| 4128 | IOERR_SLI_DOWN); |
| 4129 | } |
| 4130 | } |
| 4131 | |
| 4132 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4133 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4134 | * @phba: Pointer to HBA context object. |
| 4135 | * @mask: Bit mask to be checked. |
| 4136 | * |
| 4137 | * This function reads the host status register and compares |
| 4138 | * with the provided bit mask to check if HBA completed |
| 4139 | * the restart. This function will wait in a loop for the |
| 4140 | * HBA to complete restart. If the HBA does not restart within |
| 4141 | * 15 iterations, the function will reset the HBA again. The |
| 4142 | * function returns 1 when HBA fail to restart otherwise returns |
| 4143 | * zero. |
| 4144 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4145 | static int |
| 4146 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4147 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4148 | uint32_t status; |
| 4149 | int i = 0; |
| 4150 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4151 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4152 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4153 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4154 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4155 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4156 | /* |
| 4157 | * Check status register every 100ms for 5 retries, then every |
| 4158 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 4159 | * every 2.5 sec for 4. |
| 4160 | * Break our of the loop if errors occurred during init. |
| 4161 | */ |
| 4162 | while (((status & mask) != mask) && |
| 4163 | !(status & HS_FFERM) && |
| 4164 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4165 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4166 | if (i <= 5) |
| 4167 | msleep(10); |
| 4168 | else if (i <= 10) |
| 4169 | msleep(500); |
| 4170 | else |
| 4171 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4172 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4173 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4174 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4175 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4176 | lpfc_sli_brdrestart(phba); |
| 4177 | } |
| 4178 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4179 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 4180 | retval = 1; |
| 4181 | break; |
| 4182 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4184 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4185 | /* Check to see if any errors occurred during init */ |
| 4186 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4187 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4188 | "2751 Adapter failed to restart, " |
| 4189 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 4190 | status, |
| 4191 | readl(phba->MBslimaddr + 0xa8), |
| 4192 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4193 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4194 | retval = 1; |
| 4195 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4196 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4197 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4198 | } |
| 4199 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4200 | /** |
| 4201 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 4202 | * @phba: Pointer to HBA context object. |
| 4203 | * @mask: Bit mask to be checked. |
| 4204 | * |
| 4205 | * This function checks the host status register to check if HBA is |
| 4206 | * ready. This function will wait in a loop for the HBA to be ready |
| 4207 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 4208 | * function again. The function returns 1 when HBA fail to be ready |
| 4209 | * otherwise returns zero. |
| 4210 | **/ |
| 4211 | static int |
| 4212 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 4213 | { |
| 4214 | uint32_t status; |
| 4215 | int retval = 0; |
| 4216 | |
| 4217 | /* Read the HBA Host Status Register */ |
| 4218 | status = lpfc_sli4_post_status_check(phba); |
| 4219 | |
| 4220 | if (status) { |
| 4221 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 4222 | lpfc_sli_brdrestart(phba); |
| 4223 | status = lpfc_sli4_post_status_check(phba); |
| 4224 | } |
| 4225 | |
| 4226 | /* Check to see if any errors occurred during init */ |
| 4227 | if (status) { |
| 4228 | phba->link_state = LPFC_HBA_ERROR; |
| 4229 | retval = 1; |
| 4230 | } else |
| 4231 | phba->sli4_hba.intr_enable = 0; |
| 4232 | |
| 4233 | return retval; |
| 4234 | } |
| 4235 | |
| 4236 | /** |
| 4237 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 4238 | * @phba: Pointer to HBA context object. |
| 4239 | * @mask: Bit mask to be checked. |
| 4240 | * |
| 4241 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 4242 | * from the API jump table function pointer from the lpfc_hba struct. |
| 4243 | **/ |
| 4244 | int |
| 4245 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 4246 | { |
| 4247 | return phba->lpfc_sli_brdready(phba, mask); |
| 4248 | } |
| 4249 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4250 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 4251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4252 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4253 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4254 | * @phba: Pointer to HBA context object. |
| 4255 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4256 | * This function is called before resetting an HBA. This function is called |
| 4257 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4258 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4259 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4260 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4261 | uint32_t __iomem *resp_buf; |
| 4262 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4263 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4264 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4265 | int i; |
| 4266 | uint8_t hdrtype; |
| 4267 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4268 | lockdep_assert_held(&phba->hbalock); |
| 4269 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4270 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4271 | if (hdrtype != 0x80 || |
| 4272 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4273 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4274 | return; |
| 4275 | |
| 4276 | /* |
| 4277 | * Tell the other part of the chip to suspend temporarily all |
| 4278 | * its DMA activity. |
| 4279 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4280 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4281 | |
| 4282 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4283 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4284 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4285 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4286 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4287 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4288 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4289 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4290 | return; |
| 4291 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4292 | /* Clear Chip error bit */ |
| 4293 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4294 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | mbox = 0; |
| 4298 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4299 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4300 | |
| 4301 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4302 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4303 | writel(mbox, mbox_buf); |
| 4304 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4305 | for (i = 0; i < 50; i++) { |
| 4306 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4307 | return; |
| 4308 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4309 | mdelay(1); |
| 4310 | else |
| 4311 | break; |
| 4312 | } |
| 4313 | resp_data = 0; |
| 4314 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4315 | return; |
| 4316 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4317 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4318 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4319 | goto restore_hc; |
| 4320 | else |
| 4321 | goto clear_errat; |
| 4322 | } |
| 4323 | |
| 4324 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4325 | resp_data = 0; |
| 4326 | for (i = 0; i < 500; i++) { |
| 4327 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4328 | return; |
| 4329 | if (resp_data != mbox) |
| 4330 | mdelay(1); |
| 4331 | else |
| 4332 | break; |
| 4333 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4334 | |
| 4335 | clear_errat: |
| 4336 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4337 | while (++i < 500) { |
| 4338 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4339 | return; |
| 4340 | if (!(ha_copy & HA_ERATT)) |
| 4341 | mdelay(1); |
| 4342 | else |
| 4343 | break; |
| 4344 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4345 | |
| 4346 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4347 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4348 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4352 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4353 | writel(hc_copy, phba->HCregaddr); |
| 4354 | readl(phba->HCregaddr); /* flush */ |
| 4355 | } |
| 4356 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4357 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4358 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4359 | * @phba: Pointer to HBA context object. |
| 4360 | * |
| 4361 | * This function issues a kill_board mailbox command and waits for |
| 4362 | * the error attention interrupt. This function is called for stopping |
| 4363 | * the firmware processing. The caller is not required to hold any |
| 4364 | * locks. This function calls lpfc_hba_down_post function to free |
| 4365 | * any pending commands after the kill. The function will return 1 when it |
| 4366 | * fails to kill the board else will return 0. |
| 4367 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4368 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4369 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4370 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4371 | struct lpfc_sli *psli; |
| 4372 | LPFC_MBOXQ_t *pmb; |
| 4373 | uint32_t status; |
| 4374 | uint32_t ha_copy; |
| 4375 | int retval; |
| 4376 | int i = 0; |
| 4377 | |
| 4378 | psli = &phba->sli; |
| 4379 | |
| 4380 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4381 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4382 | "0329 Kill HBA Data: x%x x%x\n", |
| 4383 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4384 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4385 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4386 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4387 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4388 | |
| 4389 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4390 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4391 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4392 | spin_unlock_irq(&phba->hbalock); |
| 4393 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4394 | return 1; |
| 4395 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4396 | status &= ~HC_ERINT_ENA; |
| 4397 | writel(status, phba->HCregaddr); |
| 4398 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4399 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4400 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4401 | |
| 4402 | lpfc_kill_board(phba, pmb); |
| 4403 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4404 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4405 | |
| 4406 | if (retval != MBX_SUCCESS) { |
| 4407 | if (retval != MBX_BUSY) |
| 4408 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4409 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4410 | "2752 KILL_BOARD command failed retval %d\n", |
| 4411 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4412 | spin_lock_irq(&phba->hbalock); |
| 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 | return 1; |
| 4416 | } |
| 4417 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4418 | spin_lock_irq(&phba->hbalock); |
| 4419 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4420 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4421 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4422 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4423 | |
| 4424 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4425 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4426 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4427 | * board is now undefined. |
| 4428 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4429 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4430 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4431 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4432 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4433 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4434 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4438 | if (ha_copy & HA_ERATT) { |
| 4439 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4440 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4441 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4442 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4443 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4444 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4445 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4446 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4447 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4448 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4449 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4450 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4451 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4452 | } |
| 4453 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4454 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4455 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4456 | * @phba: Pointer to HBA context object. |
| 4457 | * |
| 4458 | * This function resets the HBA by writing HC_INITFF to the control |
| 4459 | * register. After the HBA resets, this function resets all the iocb ring |
| 4460 | * indices. This function disables PCI layer parity checking during |
| 4461 | * the reset. |
| 4462 | * This function returns 0 always. |
| 4463 | * The caller is not required to hold any locks. |
| 4464 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4465 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4466 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4467 | { |
| 4468 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4469 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4470 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4471 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4472 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4473 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4474 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4475 | /* Reset HBA */ |
| 4476 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4477 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4478 | (phba->pport) ? phba->pport->port_state : 0, |
| 4479 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4480 | |
| 4481 | /* perform board reset */ |
| 4482 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4483 | phba->link_events = 0; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4484 | if (phba->pport) { |
| 4485 | phba->pport->fc_myDID = 0; |
| 4486 | phba->pport->fc_prevDID = 0; |
| 4487 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4488 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4489 | /* Turn off parity checking and serr during the physical reset */ |
| 4490 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4491 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4492 | (cfg_value & |
| 4493 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4494 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4495 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4496 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4497 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4498 | writel(HC_INITFF, phba->HCregaddr); |
| 4499 | mdelay(1); |
| 4500 | readl(phba->HCregaddr); /* flush */ |
| 4501 | writel(0, phba->HCregaddr); |
| 4502 | readl(phba->HCregaddr); /* flush */ |
| 4503 | |
| 4504 | /* Restore PCI cmd register */ |
| 4505 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4506 | |
| 4507 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4508 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4509 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4510 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4511 | pring->sli.sli3.rspidx = 0; |
| 4512 | pring->sli.sli3.next_cmdidx = 0; |
| 4513 | pring->sli.sli3.local_getidx = 0; |
| 4514 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4515 | pring->missbufcnt = 0; |
| 4516 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4517 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4518 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4519 | return 0; |
| 4520 | } |
| 4521 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4522 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4523 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4524 | * @phba: Pointer to HBA context object. |
| 4525 | * |
| 4526 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4527 | * checking during resets the device. The caller is not required to hold |
| 4528 | * any locks. |
| 4529 | * |
| 4530 | * This function returns 0 always. |
| 4531 | **/ |
| 4532 | int |
| 4533 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4534 | { |
| 4535 | struct lpfc_sli *psli = &phba->sli; |
| 4536 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4537 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4538 | |
| 4539 | /* Reset HBA */ |
| 4540 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4541 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4542 | phba->pport->port_state, psli->sli_flag, |
| 4543 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4544 | |
| 4545 | /* perform board reset */ |
| 4546 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4547 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4548 | phba->pport->fc_myDID = 0; |
| 4549 | phba->pport->fc_prevDID = 0; |
| 4550 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4551 | spin_lock_irq(&phba->hbalock); |
| 4552 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4553 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4554 | spin_unlock_irq(&phba->hbalock); |
| 4555 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4556 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4557 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4558 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4559 | return rc; |
| 4560 | } |
| 4561 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4562 | /* Now physically reset the device */ |
| 4563 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4564 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4565 | |
| 4566 | /* Turn off parity checking and serr during the physical reset */ |
| 4567 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4568 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4569 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4570 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4571 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4572 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4573 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4574 | /* Restore PCI cmd register */ |
| 4575 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4576 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4577 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4578 | } |
| 4579 | |
| 4580 | /** |
| 4581 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4582 | * @phba: Pointer to HBA context object. |
| 4583 | * |
| 4584 | * This function is called in the SLI initialization code path to |
| 4585 | * restart the HBA. The caller is not required to hold any lock. |
| 4586 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4587 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4588 | * function to free any pending commands. The function enables |
| 4589 | * POST only during the first initialization. The function returns zero. |
| 4590 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4591 | * command before the return of this function. |
| 4592 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4593 | static int |
| 4594 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4595 | { |
| 4596 | MAILBOX_t *mb; |
| 4597 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4598 | volatile uint32_t word0; |
| 4599 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4600 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4601 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4602 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4603 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4604 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4605 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4606 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4607 | psli = &phba->sli; |
| 4608 | |
| 4609 | /* Restart HBA */ |
| 4610 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4611 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4612 | (phba->pport) ? phba->pport->port_state : 0, |
| 4613 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4614 | |
| 4615 | word0 = 0; |
| 4616 | mb = (MAILBOX_t *) &word0; |
| 4617 | mb->mbxCommand = MBX_RESTART; |
| 4618 | mb->mbxHc = 1; |
| 4619 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4620 | lpfc_reset_barrier(phba); |
| 4621 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4622 | to_slim = phba->MBslimaddr; |
| 4623 | writel(*(uint32_t *) mb, to_slim); |
| 4624 | readl(to_slim); /* flush */ |
| 4625 | |
| 4626 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4627 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4628 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4629 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4630 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4631 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4632 | writel(*(uint32_t *) mb, to_slim); |
| 4633 | readl(to_slim); /* flush */ |
| 4634 | |
| 4635 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4636 | if (phba->pport) |
| 4637 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4638 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4639 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4640 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4641 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4642 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4643 | psli->stats_start = ktime_get_seconds(); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4644 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4645 | /* Give the INITFF and Post time to settle. */ |
| 4646 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4647 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4648 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4649 | if (hba_aer_enabled) |
| 4650 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4651 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4652 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4653 | |
| 4654 | return 0; |
| 4655 | } |
| 4656 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4657 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4658 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4659 | * @phba: Pointer to HBA context object. |
| 4660 | * |
| 4661 | * This function is called in the SLI initialization code path to restart |
| 4662 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4663 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4664 | * free any pending commands. |
| 4665 | **/ |
| 4666 | static int |
| 4667 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4668 | { |
| 4669 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4670 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4671 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4672 | |
| 4673 | /* Restart HBA */ |
| 4674 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4675 | "0296 Restart HBA Data: x%x x%x\n", |
| 4676 | phba->pport->port_state, psli->sli_flag); |
| 4677 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4678 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4679 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4680 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4681 | rc = lpfc_sli4_brdreset(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 4682 | if (rc) |
| 4683 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4684 | |
| 4685 | spin_lock_irq(&phba->hbalock); |
| 4686 | phba->pport->stopped = 0; |
| 4687 | phba->link_state = LPFC_INIT_START; |
| 4688 | phba->hba_flag = 0; |
| 4689 | spin_unlock_irq(&phba->hbalock); |
| 4690 | |
| 4691 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4692 | psli->stats_start = ktime_get_seconds(); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4693 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4694 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4695 | if (hba_aer_enabled) |
| 4696 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4697 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4698 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4699 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4700 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4701 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4702 | } |
| 4703 | |
| 4704 | /** |
| 4705 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4706 | * @phba: Pointer to HBA context object. |
| 4707 | * |
| 4708 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4709 | * API jump table function pointer from the lpfc_hba struct. |
| 4710 | **/ |
| 4711 | int |
| 4712 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4713 | { |
| 4714 | return phba->lpfc_sli_brdrestart(phba); |
| 4715 | } |
| 4716 | |
| 4717 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4718 | * 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] | 4719 | * @phba: Pointer to HBA context object. |
| 4720 | * |
| 4721 | * This function is called after a HBA restart to wait for successful |
| 4722 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4723 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4724 | * iteration, the function will restart the HBA again. The function returns |
| 4725 | * zero if HBA successfully restarted else returns negative error code. |
| 4726 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4727 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4728 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4729 | { |
| 4730 | uint32_t status, i = 0; |
| 4731 | |
| 4732 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4733 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4734 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4735 | |
| 4736 | /* Check status register to see what current state is */ |
| 4737 | i = 0; |
| 4738 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4739 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4740 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4741 | * retries, then every 1 sec for 50 retires for a total of |
| 4742 | * ~60 seconds before reset the board again and check every |
| 4743 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4744 | * board ready is required by the Falcon FIPS zeroization |
| 4745 | * complete, and any reset the board in between shall cause |
| 4746 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4747 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4748 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4749 | /* Adapter failed to init, timeout, status reg |
| 4750 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4751 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4752 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4753 | "timeout, status reg x%x, " |
| 4754 | "FW Data: A8 x%x AC x%x\n", status, |
| 4755 | readl(phba->MBslimaddr + 0xa8), |
| 4756 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4757 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4758 | return -ETIMEDOUT; |
| 4759 | } |
| 4760 | |
| 4761 | /* Check to see if any errors occurred during init */ |
| 4762 | if (status & HS_FFERM) { |
| 4763 | /* ERROR: During chipset initialization */ |
| 4764 | /* Adapter failed to init, chipset, status reg |
| 4765 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4766 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4767 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4768 | "chipset, status reg x%x, " |
| 4769 | "FW Data: A8 x%x AC x%x\n", status, |
| 4770 | readl(phba->MBslimaddr + 0xa8), |
| 4771 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4772 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4773 | return -EIO; |
| 4774 | } |
| 4775 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4776 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4777 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4778 | else if (i <= 100) |
| 4779 | msleep(100); |
| 4780 | else |
| 4781 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4782 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4783 | if (i == 150) { |
| 4784 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4785 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4786 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4787 | } |
| 4788 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4789 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4790 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | /* Check to see if any errors occurred during init */ |
| 4794 | if (status & HS_FFERM) { |
| 4795 | /* ERROR: During chipset initialization */ |
| 4796 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4797 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4798 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4799 | "status reg x%x, " |
| 4800 | "FW Data: A8 x%x AC x%x\n", status, |
| 4801 | readl(phba->MBslimaddr + 0xa8), |
| 4802 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4803 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4804 | return -EIO; |
| 4805 | } |
| 4806 | |
| 4807 | /* Clear all interrupt enable conditions */ |
| 4808 | writel(0, phba->HCregaddr); |
| 4809 | readl(phba->HCregaddr); /* flush */ |
| 4810 | |
| 4811 | /* setup host attn register */ |
| 4812 | writel(0xffffffff, phba->HAregaddr); |
| 4813 | readl(phba->HAregaddr); /* flush */ |
| 4814 | return 0; |
| 4815 | } |
| 4816 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4817 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4818 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4819 | * |
| 4820 | * This function calculates and returns the number of HBQs required to be |
| 4821 | * configured. |
| 4822 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4823 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4824 | lpfc_sli_hbq_count(void) |
| 4825 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4826 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4827 | } |
| 4828 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4829 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4830 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4831 | * |
| 4832 | * This function adds the number of hbq entries in every HBQ to get |
| 4833 | * the total number of hbq entries required for the HBA and returns |
| 4834 | * the total count. |
| 4835 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4836 | static int |
| 4837 | lpfc_sli_hbq_entry_count(void) |
| 4838 | { |
| 4839 | int hbq_count = lpfc_sli_hbq_count(); |
| 4840 | int count = 0; |
| 4841 | int i; |
| 4842 | |
| 4843 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4844 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4845 | return count; |
| 4846 | } |
| 4847 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4848 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4849 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4850 | * |
| 4851 | * This function calculates amount of memory required for all hbq entries |
| 4852 | * to be configured and returns the total memory required. |
| 4853 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4854 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4855 | lpfc_sli_hbq_size(void) |
| 4856 | { |
| 4857 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4858 | } |
| 4859 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4860 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4861 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4862 | * @phba: Pointer to HBA context object. |
| 4863 | * |
| 4864 | * This function is called during the SLI initialization to configure |
| 4865 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4866 | * required to hold any locks. This function will return zero if successful |
| 4867 | * else it will return negative error code. |
| 4868 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4869 | static int |
| 4870 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4871 | { |
| 4872 | int hbq_count = lpfc_sli_hbq_count(); |
| 4873 | LPFC_MBOXQ_t *pmb; |
| 4874 | MAILBOX_t *pmbox; |
| 4875 | uint32_t hbqno; |
| 4876 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4877 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4878 | /* Get a Mailbox buffer to setup mailbox |
| 4879 | * commands for HBA initialization |
| 4880 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4881 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4882 | |
| 4883 | if (!pmb) |
| 4884 | return -ENOMEM; |
| 4885 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4886 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4887 | |
| 4888 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4889 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4890 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4891 | |
| 4892 | hbq_entry_index = 0; |
| 4893 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4894 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4895 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4896 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4897 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4898 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4899 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4900 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4901 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4902 | |
| 4903 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4904 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4905 | mbxStatus <status>, ring <num> */ |
| 4906 | |
| 4907 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4908 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4909 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4910 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4911 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4912 | pmbox->mbxStatus, hbqno); |
| 4913 | |
| 4914 | phba->link_state = LPFC_HBA_ERROR; |
| 4915 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4916 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4917 | } |
| 4918 | } |
| 4919 | phba->hbq_count = hbq_count; |
| 4920 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4921 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4922 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4923 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4924 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4925 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4926 | return 0; |
| 4927 | } |
| 4928 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4929 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4930 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4931 | * @phba: Pointer to HBA context object. |
| 4932 | * |
| 4933 | * This function is called during the SLI initialization to configure |
| 4934 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4935 | * required to hold any locks. This function will return zero if successful |
| 4936 | * else it will return negative error code. |
| 4937 | **/ |
| 4938 | static int |
| 4939 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4940 | { |
| 4941 | phba->hbq_in_use = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4942 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 4943 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4944 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4945 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4946 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4947 | return 0; |
| 4948 | } |
| 4949 | |
| 4950 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4951 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4952 | * @phba: Pointer to HBA context object. |
| 4953 | * @sli_mode: sli mode - 2/3 |
| 4954 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4955 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4956 | * to issue config_port mailbox command. This function restarts the |
| 4957 | * HBA firmware and issues a config_port mailbox command to configure |
| 4958 | * the SLI interface in the sli mode specified by sli_mode |
| 4959 | * variable. The caller is not required to hold any locks. |
| 4960 | * The function returns 0 if successful, else returns negative error |
| 4961 | * code. |
| 4962 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4963 | int |
| 4964 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4965 | { |
| 4966 | LPFC_MBOXQ_t *pmb; |
| 4967 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4968 | |
| 4969 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4970 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4971 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4972 | return -ENOMEM; |
| 4973 | } |
| 4974 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4975 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4976 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4977 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4978 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4979 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4980 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4981 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4982 | rc = lpfc_sli_chipset_init(phba); |
| 4983 | if (rc) |
| 4984 | break; |
| 4985 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4986 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4987 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4988 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4989 | resetcount++; |
| 4990 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4991 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4992 | * value of 0 means the call was successful. Any other |
| 4993 | * nonzero value is a failure, but if ERESTART is returned, |
| 4994 | * the driver may reset the HBA and try again. |
| 4995 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4996 | rc = lpfc_config_port_prep(phba); |
| 4997 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4998 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4999 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5000 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5001 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5002 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5003 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5004 | lpfc_config_port(phba, pmb); |
| 5005 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5006 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 5007 | LPFC_SLI3_HBQ_ENABLED | |
| 5008 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5009 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5010 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5011 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5012 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5013 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5014 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5015 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5016 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5017 | spin_unlock_irq(&phba->hbalock); |
| 5018 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5019 | } else { |
| 5020 | /* Allow asynchronous mailbox command to go through */ |
| 5021 | spin_lock_irq(&phba->hbalock); |
| 5022 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 5023 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5024 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 5025 | |
| 5026 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 5027 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 5028 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5029 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5030 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5031 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5032 | if (!done) { |
| 5033 | rc = -EINVAL; |
| 5034 | goto do_prep_failed; |
| 5035 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5036 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 5037 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5038 | rc = -ENXIO; |
| 5039 | goto do_prep_failed; |
| 5040 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5041 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5042 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5043 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 5044 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 5045 | phba->max_vpi : phba->max_vports; |
| 5046 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5047 | } else |
| 5048 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5049 | phba->fips_level = 0; |
| 5050 | phba->fips_spec_rev = 0; |
| 5051 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5052 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5053 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 5054 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 5055 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5056 | "2850 Security Crypto Active. FIPS x%d " |
| 5057 | "(Spec Rev: x%d)", |
| 5058 | phba->fips_level, phba->fips_spec_rev); |
| 5059 | } |
| 5060 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 5061 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5062 | "2856 Config Port Security Crypto " |
| 5063 | "Error: x%x ", |
| 5064 | pmb->u.mb.un.varCfgPort.sec_err); |
| 5065 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5066 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5067 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5068 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5069 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5070 | |
| 5071 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 5072 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5073 | |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5074 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 5075 | if (pmb->u.mb.un.varCfgPort.gbg == 0) { |
| 5076 | phba->cfg_enable_bg = 0; |
| 5077 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5078 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5079 | "0443 Adapter did not grant " |
| 5080 | "BlockGuard\n"); |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5081 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5082 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5083 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 5084 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5085 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5086 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5087 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5088 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5089 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5090 | return rc; |
| 5091 | } |
| 5092 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5093 | |
| 5094 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5095 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5096 | * @phba: Pointer to HBA context object. |
| 5097 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5098 | * This function is the main SLI initialization function. This function |
| 5099 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5100 | * error attention handler code. Caller is not required to hold any |
| 5101 | * locks. This function issues config_port mailbox command to configure |
| 5102 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 5103 | * calls the config_port_post function to issue init_link mailbox |
| 5104 | * command and to start the discovery. The function will return zero |
| 5105 | * if successful, else it will return negative error code. |
| 5106 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5107 | int |
| 5108 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 5109 | { |
| 5110 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5111 | int mode = 3, i; |
| 5112 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5113 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5114 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5115 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 5116 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5117 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5118 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5119 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5120 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5121 | break; |
| 5122 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5123 | mode = 2; |
| 5124 | break; |
| 5125 | case 0: |
| 5126 | case 3: |
| 5127 | break; |
| 5128 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5129 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5130 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 5131 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5132 | |
| 5133 | break; |
| 5134 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 5135 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5136 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5137 | rc = lpfc_sli_config_port(phba, mode); |
| 5138 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5139 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5140 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5141 | "1820 Unable to select SLI-3. " |
| 5142 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5143 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5144 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 5145 | else if (rc && mode == 2) |
| 5146 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5147 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5148 | goto lpfc_sli_hba_setup_error; |
| 5149 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5150 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 5151 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 5152 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 5153 | if (!rc) { |
| 5154 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5155 | "2709 This device supports " |
| 5156 | "Advanced Error Reporting (AER)\n"); |
| 5157 | spin_lock_irq(&phba->hbalock); |
| 5158 | phba->hba_flag |= HBA_AER_ENABLED; |
| 5159 | spin_unlock_irq(&phba->hbalock); |
| 5160 | } else { |
| 5161 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5162 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 5163 | "Advanced Error Reporting (AER): %d\n", |
| 5164 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5165 | phba->cfg_aer_support = 0; |
| 5166 | } |
| 5167 | } |
| 5168 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5169 | if (phba->sli_rev == 3) { |
| 5170 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 5171 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5172 | } else { |
| 5173 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 5174 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5175 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5179 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 5180 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5181 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5182 | |
| 5183 | if (rc) |
| 5184 | goto lpfc_sli_hba_setup_error; |
| 5185 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5186 | /* Initialize VPIs. */ |
| 5187 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 5188 | /* |
| 5189 | * The VPI bitmask and physical ID array are allocated |
| 5190 | * and initialized once only - at driver load. A port |
| 5191 | * reset doesn't need to reinitialize this memory. |
| 5192 | */ |
| 5193 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 5194 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5195 | phba->vpi_bmask = kcalloc(longs, |
| 5196 | sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5197 | GFP_KERNEL); |
| 5198 | if (!phba->vpi_bmask) { |
| 5199 | rc = -ENOMEM; |
| 5200 | goto lpfc_sli_hba_setup_error; |
| 5201 | } |
| 5202 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5203 | phba->vpi_ids = kcalloc(phba->max_vpi + 1, |
| 5204 | sizeof(uint16_t), |
| 5205 | GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5206 | if (!phba->vpi_ids) { |
| 5207 | kfree(phba->vpi_bmask); |
| 5208 | rc = -ENOMEM; |
| 5209 | goto lpfc_sli_hba_setup_error; |
| 5210 | } |
| 5211 | for (i = 0; i < phba->max_vpi; i++) |
| 5212 | phba->vpi_ids[i] = i; |
| 5213 | } |
| 5214 | } |
| 5215 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5216 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5217 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 5218 | rc = lpfc_sli_hbq_setup(phba); |
| 5219 | if (rc) |
| 5220 | goto lpfc_sli_hba_setup_error; |
| 5221 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5222 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5223 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5224 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5225 | |
| 5226 | rc = lpfc_config_port_post(phba); |
| 5227 | if (rc) |
| 5228 | goto lpfc_sli_hba_setup_error; |
| 5229 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5230 | return rc; |
| 5231 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5232 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5233 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 5234 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5235 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5236 | return rc; |
| 5237 | } |
| 5238 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5239 | /** |
| 5240 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 5241 | * @phba: Pointer to HBA context object. |
| 5242 | * @mboxq: mailbox pointer. |
| 5243 | * This function issue a dump mailbox command to read config region |
| 5244 | * 23 and parse the records in the region and populate driver |
| 5245 | * data structure. |
| 5246 | **/ |
| 5247 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5248 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5249 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5250 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5251 | struct lpfc_dmabuf *mp; |
| 5252 | struct lpfc_mqe *mqe; |
| 5253 | uint32_t data_length; |
| 5254 | int rc; |
| 5255 | |
| 5256 | /* Program the default value of vlan_id and fc_map */ |
| 5257 | phba->valid_vlan = 0; |
| 5258 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5259 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5260 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5261 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5262 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5263 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5264 | return -ENOMEM; |
| 5265 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5266 | mqe = &mboxq->u.mqe; |
| 5267 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5268 | rc = -ENOMEM; |
| 5269 | goto out_free_mboxq; |
| 5270 | } |
| 5271 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 5272 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5273 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5274 | |
| 5275 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5276 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5277 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5278 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5279 | "CQ: x%x x%x x%x x%x\n", |
| 5280 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5281 | bf_get(lpfc_mqe_command, mqe), |
| 5282 | bf_get(lpfc_mqe_status, mqe), |
| 5283 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5284 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5285 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5286 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5287 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5288 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5289 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5290 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5291 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5292 | mboxq->mcqe.word0, |
| 5293 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5294 | mboxq->mcqe.trailer); |
| 5295 | |
| 5296 | if (rc) { |
| 5297 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5298 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5299 | rc = -EIO; |
| 5300 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5301 | } |
| 5302 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5303 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5304 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5305 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5306 | rc = -EIO; |
| 5307 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5308 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5309 | |
| 5310 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5311 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5312 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5313 | rc = 0; |
| 5314 | |
| 5315 | out_free_mboxq: |
| 5316 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5317 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | /** |
| 5321 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5322 | * @phba: pointer to lpfc hba data structure. |
| 5323 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5324 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5325 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5326 | * On output, the number of data bytes in @vpd. |
| 5327 | * |
| 5328 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5329 | * addition, this routine gets the port vpd data. |
| 5330 | * |
| 5331 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5332 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5333 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5334 | **/ |
| 5335 | static int |
| 5336 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5337 | uint8_t *vpd, uint32_t *vpd_size) |
| 5338 | { |
| 5339 | int rc = 0; |
| 5340 | uint32_t dma_size; |
| 5341 | struct lpfc_dmabuf *dmabuf; |
| 5342 | struct lpfc_mqe *mqe; |
| 5343 | |
| 5344 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5345 | if (!dmabuf) |
| 5346 | return -ENOMEM; |
| 5347 | |
| 5348 | /* |
| 5349 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5350 | * mailbox command. |
| 5351 | */ |
| 5352 | dma_size = *vpd_size; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 5353 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
| 5354 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5355 | if (!dmabuf->virt) { |
| 5356 | kfree(dmabuf); |
| 5357 | return -ENOMEM; |
| 5358 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5359 | |
| 5360 | /* |
| 5361 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5362 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5363 | * in SLI3. This code corrects the conflicts. |
| 5364 | */ |
| 5365 | lpfc_read_rev(phba, mboxq); |
| 5366 | mqe = &mboxq->u.mqe; |
| 5367 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5368 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5369 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5370 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5371 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5372 | |
| 5373 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5374 | if (rc) { |
| 5375 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5376 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5377 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5378 | return -EIO; |
| 5379 | } |
| 5380 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5381 | /* |
| 5382 | * The available vpd length cannot be bigger than the |
| 5383 | * DMA buffer passed to the port. Catch the less than |
| 5384 | * case and update the caller's size. |
| 5385 | */ |
| 5386 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5387 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5388 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5389 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5390 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5391 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5392 | dmabuf->virt, dmabuf->phys); |
| 5393 | kfree(dmabuf); |
| 5394 | return 0; |
| 5395 | } |
| 5396 | |
| 5397 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5398 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5399 | * @phba: pointer to lpfc hba data structure. |
| 5400 | * |
| 5401 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5402 | * is attached to. |
| 5403 | * |
| 5404 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5405 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5406 | * otherwise - failed to retrieve physical port name |
| 5407 | **/ |
| 5408 | static int |
| 5409 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5410 | { |
| 5411 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5412 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5413 | struct lpfc_controller_attribute *cntl_attr; |
| 5414 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5415 | void *virtaddr = NULL; |
| 5416 | uint32_t alloclen, reqlen; |
| 5417 | uint32_t shdr_status, shdr_add_status; |
| 5418 | union lpfc_sli4_cfg_shdr *shdr; |
| 5419 | char cport_name = 0; |
| 5420 | int rc; |
| 5421 | |
| 5422 | /* We assume nothing at this point */ |
| 5423 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5424 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5425 | |
| 5426 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5427 | if (!mboxq) |
| 5428 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5429 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5430 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5431 | lpfc_sli4_read_config(phba); |
| 5432 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5433 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5434 | |
| 5435 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5436 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5437 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5438 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5439 | LPFC_SLI4_MBX_NEMBED); |
| 5440 | if (alloclen < reqlen) { |
| 5441 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5442 | "3084 Allocated DMA memory size (%d) is " |
| 5443 | "less than the requested DMA memory size " |
| 5444 | "(%d)\n", alloclen, reqlen); |
| 5445 | rc = -ENOMEM; |
| 5446 | goto out_free_mboxq; |
| 5447 | } |
| 5448 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5449 | virtaddr = mboxq->sge_array->addr[0]; |
| 5450 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5451 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5452 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5453 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5454 | if (shdr_status || shdr_add_status || rc) { |
| 5455 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5456 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5457 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5458 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5459 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5460 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5461 | rc, shdr_status, shdr_add_status); |
| 5462 | rc = -ENXIO; |
| 5463 | goto out_free_mboxq; |
| 5464 | } |
| 5465 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5466 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5467 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5468 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5469 | phba->sli4_hba.lnk_info.lnk_no = |
| 5470 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 5471 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5472 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 5473 | phba->sli4_hba.lnk_info.lnk_tp, |
| 5474 | phba->sli4_hba.lnk_info.lnk_no); |
| 5475 | |
| 5476 | retrieve_ppname: |
| 5477 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5478 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5479 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5480 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5481 | LPFC_SLI4_MBX_EMBED); |
| 5482 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5483 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5484 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5485 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5486 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5487 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5488 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5489 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5490 | if (shdr_status || shdr_add_status || rc) { |
| 5491 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5492 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5493 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5494 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5495 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5496 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5497 | rc, shdr_status, shdr_add_status); |
| 5498 | rc = -ENXIO; |
| 5499 | goto out_free_mboxq; |
| 5500 | } |
| 5501 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5502 | case LPFC_LINK_NUMBER_0: |
| 5503 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5504 | &get_port_name->u.response); |
| 5505 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5506 | break; |
| 5507 | case LPFC_LINK_NUMBER_1: |
| 5508 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5509 | &get_port_name->u.response); |
| 5510 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5511 | break; |
| 5512 | case LPFC_LINK_NUMBER_2: |
| 5513 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5514 | &get_port_name->u.response); |
| 5515 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5516 | break; |
| 5517 | case LPFC_LINK_NUMBER_3: |
| 5518 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5519 | &get_port_name->u.response); |
| 5520 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5521 | break; |
| 5522 | default: |
| 5523 | break; |
| 5524 | } |
| 5525 | |
| 5526 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5527 | phba->Port[0] = cport_name; |
| 5528 | phba->Port[1] = '\0'; |
| 5529 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5530 | "3091 SLI get port name: %s\n", phba->Port); |
| 5531 | } |
| 5532 | |
| 5533 | out_free_mboxq: |
| 5534 | if (rc != MBX_TIMEOUT) { |
| 5535 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5536 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5537 | else |
| 5538 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5539 | } |
| 5540 | return rc; |
| 5541 | } |
| 5542 | |
| 5543 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5544 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5545 | * @phba: pointer to lpfc hba data structure. |
| 5546 | * |
| 5547 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5548 | * event queues |
| 5549 | **/ |
| 5550 | static void |
| 5551 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5552 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5553 | int qidx; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5554 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5555 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5556 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5557 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM); |
| 5558 | 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] | 5559 | if (sli4_hba->nvmels_cq) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5560 | sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0, |
| 5561 | LPFC_QUEUE_REARM); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5562 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5563 | qp = sli4_hba->hdwq; |
| 5564 | if (sli4_hba->hdwq) { |
| 5565 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5566 | sli4_hba->sli4_write_cq_db(phba, qp[qidx].fcp_cq, 0, |
| 5567 | LPFC_QUEUE_REARM); |
| 5568 | sli4_hba->sli4_write_cq_db(phba, qp[qidx].nvme_cq, 0, |
| 5569 | LPFC_QUEUE_REARM); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5570 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5571 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 5572 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5573 | sli4_hba->sli4_write_eq_db(phba, qp[qidx].hba_eq, |
| 5574 | 0, LPFC_QUEUE_REARM); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 5575 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5576 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5577 | if (phba->nvmet_support) { |
| 5578 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 5579 | sli4_hba->sli4_write_cq_db(phba, |
| 5580 | sli4_hba->nvmet_cqset[qidx], 0, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5581 | LPFC_QUEUE_REARM); |
| 5582 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5583 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5587 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5588 | * @phba: Pointer to HBA context object. |
| 5589 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5590 | * @extnt_count: buffer to hold port available extent count. |
| 5591 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5592 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5593 | * This function calls the port and retrievs the number of available |
| 5594 | * extents and their size for a particular extent type. |
| 5595 | * |
| 5596 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5597 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5598 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5599 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5600 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5601 | { |
| 5602 | int rc = 0; |
| 5603 | uint32_t length; |
| 5604 | uint32_t mbox_tmo; |
| 5605 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5606 | LPFC_MBOXQ_t *mbox; |
| 5607 | |
| 5608 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5609 | if (!mbox) |
| 5610 | return -ENOMEM; |
| 5611 | |
| 5612 | /* Find out how many extents are available for this resource type */ |
| 5613 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5614 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5615 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5616 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5617 | length, LPFC_SLI4_MBX_EMBED); |
| 5618 | |
| 5619 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5620 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5621 | LPFC_SLI4_MBX_EMBED); |
| 5622 | if (unlikely(rc)) { |
| 5623 | rc = -EIO; |
| 5624 | goto err_exit; |
| 5625 | } |
| 5626 | |
| 5627 | if (!phba->sli4_hba.intr_enable) |
| 5628 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5629 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5630 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5631 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5632 | } |
| 5633 | if (unlikely(rc)) { |
| 5634 | rc = -EIO; |
| 5635 | goto err_exit; |
| 5636 | } |
| 5637 | |
| 5638 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5639 | if (bf_get(lpfc_mbox_hdr_status, |
| 5640 | &rsrc_info->header.cfg_shdr.response)) { |
| 5641 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5642 | "2930 Failed to get resource extents " |
| 5643 | "Status 0x%x Add'l Status 0x%x\n", |
| 5644 | bf_get(lpfc_mbox_hdr_status, |
| 5645 | &rsrc_info->header.cfg_shdr.response), |
| 5646 | bf_get(lpfc_mbox_hdr_add_status, |
| 5647 | &rsrc_info->header.cfg_shdr.response)); |
| 5648 | rc = -EIO; |
| 5649 | goto err_exit; |
| 5650 | } |
| 5651 | |
| 5652 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5653 | &rsrc_info->u.rsp); |
| 5654 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5655 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5656 | |
| 5657 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5658 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5659 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5660 | |
| 5661 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5662 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5663 | return rc; |
| 5664 | } |
| 5665 | |
| 5666 | /** |
| 5667 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5668 | * @phba: Pointer to HBA context object. |
| 5669 | * @type: The extent type to check. |
| 5670 | * |
| 5671 | * This function reads the current available extents from the port and checks |
| 5672 | * if the extent count or extent size has changed since the last access. |
| 5673 | * Callers use this routine post port reset to understand if there is a |
| 5674 | * extent reprovisioning requirement. |
| 5675 | * |
| 5676 | * Returns: |
| 5677 | * -Error: error indicates problem. |
| 5678 | * 1: Extent count or size has changed. |
| 5679 | * 0: No changes. |
| 5680 | **/ |
| 5681 | static int |
| 5682 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5683 | { |
| 5684 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5685 | uint16_t size_diff, rsrc_ext_size; |
| 5686 | int rc = 0; |
| 5687 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5688 | struct list_head *rsrc_blk_list = NULL; |
| 5689 | |
| 5690 | size_diff = 0; |
| 5691 | curr_ext_cnt = 0; |
| 5692 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5693 | &rsrc_ext_cnt, |
| 5694 | &rsrc_ext_size); |
| 5695 | if (unlikely(rc)) |
| 5696 | return -EIO; |
| 5697 | |
| 5698 | switch (type) { |
| 5699 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5700 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5701 | break; |
| 5702 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5703 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5704 | break; |
| 5705 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5706 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5707 | break; |
| 5708 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5709 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5710 | break; |
| 5711 | default: |
| 5712 | break; |
| 5713 | } |
| 5714 | |
| 5715 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5716 | curr_ext_cnt++; |
| 5717 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5718 | size_diff++; |
| 5719 | } |
| 5720 | |
| 5721 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5722 | rc = 1; |
| 5723 | |
| 5724 | return rc; |
| 5725 | } |
| 5726 | |
| 5727 | /** |
| 5728 | * lpfc_sli4_cfg_post_extnts - |
| 5729 | * @phba: Pointer to HBA context object. |
| 5730 | * @extnt_cnt - number of available extents. |
| 5731 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5732 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5733 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5734 | * |
| 5735 | * This function executes the extents allocation request. It also |
| 5736 | * takes care of the amount of memory needed to allocate or get the |
| 5737 | * allocated extents. It is the caller's responsibility to evaluate |
| 5738 | * the response. |
| 5739 | * |
| 5740 | * Returns: |
| 5741 | * -Error: Error value describes the condition found. |
| 5742 | * 0: if successful |
| 5743 | **/ |
| 5744 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5745 | 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] | 5746 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5747 | { |
| 5748 | int rc = 0; |
| 5749 | uint32_t req_len; |
| 5750 | uint32_t emb_len; |
| 5751 | uint32_t alloc_len, mbox_tmo; |
| 5752 | |
| 5753 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5754 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5755 | |
| 5756 | /* |
| 5757 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5758 | * accounts for extents-specific word. |
| 5759 | */ |
| 5760 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5761 | sizeof(uint32_t); |
| 5762 | |
| 5763 | /* |
| 5764 | * Presume the allocation and response will fit into an embedded |
| 5765 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5766 | */ |
| 5767 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5768 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5769 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5770 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5771 | sizeof(uint32_t); |
| 5772 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5773 | } |
| 5774 | |
| 5775 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5776 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5777 | req_len, *emb); |
| 5778 | if (alloc_len < req_len) { |
| 5779 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5780 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5781 | "less than the requested DMA memory " |
| 5782 | "size (x%x)\n", alloc_len, req_len); |
| 5783 | return -ENOMEM; |
| 5784 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5785 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5786 | if (unlikely(rc)) |
| 5787 | return -EIO; |
| 5788 | |
| 5789 | if (!phba->sli4_hba.intr_enable) |
| 5790 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5791 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5792 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5793 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5794 | } |
| 5795 | |
| 5796 | if (unlikely(rc)) |
| 5797 | rc = -EIO; |
| 5798 | return rc; |
| 5799 | } |
| 5800 | |
| 5801 | /** |
| 5802 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5803 | * @phba: Pointer to HBA context object. |
| 5804 | * @type: The resource extent type to allocate. |
| 5805 | * |
| 5806 | * This function allocates the number of elements for the specified |
| 5807 | * resource type. |
| 5808 | **/ |
| 5809 | static int |
| 5810 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5811 | { |
| 5812 | bool emb = false; |
| 5813 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5814 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5815 | uint16_t *ids; |
| 5816 | int i, rc; |
| 5817 | unsigned long longs; |
| 5818 | unsigned long *bmask; |
| 5819 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5820 | LPFC_MBOXQ_t *mbox; |
| 5821 | uint32_t length; |
| 5822 | struct lpfc_id_range *id_array = NULL; |
| 5823 | void *virtaddr = NULL; |
| 5824 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5825 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5826 | struct list_head *ext_blk_list; |
| 5827 | |
| 5828 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5829 | &rsrc_cnt, |
| 5830 | &rsrc_size); |
| 5831 | if (unlikely(rc)) |
| 5832 | return -EIO; |
| 5833 | |
| 5834 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5835 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5836 | "3009 No available Resource Extents " |
| 5837 | "for resource type 0x%x: Count: 0x%x, " |
| 5838 | "Size 0x%x\n", type, rsrc_cnt, |
| 5839 | rsrc_size); |
| 5840 | return -ENOMEM; |
| 5841 | } |
| 5842 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5843 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5844 | "2903 Post resource extents type-0x%x: " |
| 5845 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5846 | |
| 5847 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5848 | if (!mbox) |
| 5849 | return -ENOMEM; |
| 5850 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5851 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5852 | if (unlikely(rc)) { |
| 5853 | rc = -EIO; |
| 5854 | goto err_exit; |
| 5855 | } |
| 5856 | |
| 5857 | /* |
| 5858 | * Figure out where the response is located. Then get local pointers |
| 5859 | * to the response data. The port does not guarantee to respond to |
| 5860 | * all extents counts request so update the local variable with the |
| 5861 | * allocated count from the port. |
| 5862 | */ |
| 5863 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5864 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5865 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5866 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5867 | } else { |
| 5868 | virtaddr = mbox->sge_array->addr[0]; |
| 5869 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5870 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5871 | id_array = &n_rsrc->id; |
| 5872 | } |
| 5873 | |
| 5874 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5875 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5876 | |
| 5877 | /* |
| 5878 | * Based on the resource size and count, correct the base and max |
| 5879 | * resource values. |
| 5880 | */ |
| 5881 | length = sizeof(struct lpfc_rsrc_blks); |
| 5882 | switch (type) { |
| 5883 | case LPFC_RSC_TYPE_FCOE_RPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5884 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5885 | sizeof(unsigned long), |
| 5886 | GFP_KERNEL); |
| 5887 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5888 | rc = -ENOMEM; |
| 5889 | goto err_exit; |
| 5890 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5891 | phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5892 | sizeof(uint16_t), |
| 5893 | GFP_KERNEL); |
| 5894 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5895 | kfree(phba->sli4_hba.rpi_bmask); |
| 5896 | rc = -ENOMEM; |
| 5897 | goto err_exit; |
| 5898 | } |
| 5899 | |
| 5900 | /* |
| 5901 | * The next_rpi was initialized with the maximum available |
| 5902 | * count but the port may allocate a smaller number. Catch |
| 5903 | * that case and update the next_rpi. |
| 5904 | */ |
| 5905 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5906 | |
| 5907 | /* Initialize local ptrs for common extent processing later. */ |
| 5908 | bmask = phba->sli4_hba.rpi_bmask; |
| 5909 | ids = phba->sli4_hba.rpi_ids; |
| 5910 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5911 | break; |
| 5912 | case LPFC_RSC_TYPE_FCOE_VPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5913 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5914 | GFP_KERNEL); |
| 5915 | if (unlikely(!phba->vpi_bmask)) { |
| 5916 | rc = -ENOMEM; |
| 5917 | goto err_exit; |
| 5918 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5919 | phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5920 | GFP_KERNEL); |
| 5921 | if (unlikely(!phba->vpi_ids)) { |
| 5922 | kfree(phba->vpi_bmask); |
| 5923 | rc = -ENOMEM; |
| 5924 | goto err_exit; |
| 5925 | } |
| 5926 | |
| 5927 | /* Initialize local ptrs for common extent processing later. */ |
| 5928 | bmask = phba->vpi_bmask; |
| 5929 | ids = phba->vpi_ids; |
| 5930 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5931 | break; |
| 5932 | case LPFC_RSC_TYPE_FCOE_XRI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5933 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5934 | sizeof(unsigned long), |
| 5935 | GFP_KERNEL); |
| 5936 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5937 | rc = -ENOMEM; |
| 5938 | goto err_exit; |
| 5939 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5940 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5941 | phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5942 | sizeof(uint16_t), |
| 5943 | GFP_KERNEL); |
| 5944 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5945 | kfree(phba->sli4_hba.xri_bmask); |
| 5946 | rc = -ENOMEM; |
| 5947 | goto err_exit; |
| 5948 | } |
| 5949 | |
| 5950 | /* Initialize local ptrs for common extent processing later. */ |
| 5951 | bmask = phba->sli4_hba.xri_bmask; |
| 5952 | ids = phba->sli4_hba.xri_ids; |
| 5953 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5954 | break; |
| 5955 | case LPFC_RSC_TYPE_FCOE_VFI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5956 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5957 | sizeof(unsigned long), |
| 5958 | GFP_KERNEL); |
| 5959 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5960 | rc = -ENOMEM; |
| 5961 | goto err_exit; |
| 5962 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5963 | phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5964 | sizeof(uint16_t), |
| 5965 | GFP_KERNEL); |
| 5966 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5967 | kfree(phba->sli4_hba.vfi_bmask); |
| 5968 | rc = -ENOMEM; |
| 5969 | goto err_exit; |
| 5970 | } |
| 5971 | |
| 5972 | /* Initialize local ptrs for common extent processing later. */ |
| 5973 | bmask = phba->sli4_hba.vfi_bmask; |
| 5974 | ids = phba->sli4_hba.vfi_ids; |
| 5975 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5976 | break; |
| 5977 | default: |
| 5978 | /* Unsupported Opcode. Fail call. */ |
| 5979 | id_array = NULL; |
| 5980 | bmask = NULL; |
| 5981 | ids = NULL; |
| 5982 | ext_blk_list = NULL; |
| 5983 | goto err_exit; |
| 5984 | } |
| 5985 | |
| 5986 | /* |
| 5987 | * Complete initializing the extent configuration with the |
| 5988 | * allocated ids assigned to this function. The bitmask serves |
| 5989 | * as an index into the array and manages the available ids. The |
| 5990 | * array just stores the ids communicated to the port via the wqes. |
| 5991 | */ |
| 5992 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5993 | if ((i % 2) == 0) |
| 5994 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5995 | &id_array[k]); |
| 5996 | else |
| 5997 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5998 | &id_array[k]); |
| 5999 | |
| 6000 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 6001 | if (unlikely(!rsrc_blks)) { |
| 6002 | rc = -ENOMEM; |
| 6003 | kfree(bmask); |
| 6004 | kfree(ids); |
| 6005 | goto err_exit; |
| 6006 | } |
| 6007 | rsrc_blks->rsrc_start = rsrc_id; |
| 6008 | rsrc_blks->rsrc_size = rsrc_size; |
| 6009 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 6010 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6011 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6012 | phba->sli4_hba.io_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6013 | lpfc_sli4_get_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6014 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6015 | |
| 6016 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 6017 | ids[j] = rsrc_id; |
| 6018 | rsrc_id++; |
| 6019 | j++; |
| 6020 | } |
| 6021 | /* Entire word processed. Get next word.*/ |
| 6022 | if ((i % 2) == 1) |
| 6023 | k++; |
| 6024 | } |
| 6025 | err_exit: |
| 6026 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6027 | return rc; |
| 6028 | } |
| 6029 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6030 | |
| 6031 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6032 | /** |
| 6033 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 6034 | * @phba: Pointer to HBA context object. |
| 6035 | * @type: the extent's type. |
| 6036 | * |
| 6037 | * This function deallocates all extents of a particular resource type. |
| 6038 | * SLI4 does not allow for deallocating a particular extent range. It |
| 6039 | * is the caller's responsibility to release all kernel memory resources. |
| 6040 | **/ |
| 6041 | static int |
| 6042 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6043 | { |
| 6044 | int rc; |
| 6045 | uint32_t length, mbox_tmo = 0; |
| 6046 | LPFC_MBOXQ_t *mbox; |
| 6047 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 6048 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 6049 | |
| 6050 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6051 | if (!mbox) |
| 6052 | return -ENOMEM; |
| 6053 | |
| 6054 | /* |
| 6055 | * This function sends an embedded mailbox because it only sends the |
| 6056 | * the resource type. All extents of this type are released by the |
| 6057 | * port. |
| 6058 | */ |
| 6059 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 6060 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6061 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6062 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 6063 | length, LPFC_SLI4_MBX_EMBED); |
| 6064 | |
| 6065 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 6066 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 6067 | LPFC_SLI4_MBX_EMBED); |
| 6068 | if (unlikely(rc)) { |
| 6069 | rc = -EIO; |
| 6070 | goto out_free_mbox; |
| 6071 | } |
| 6072 | if (!phba->sli4_hba.intr_enable) |
| 6073 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6074 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6075 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6076 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6077 | } |
| 6078 | if (unlikely(rc)) { |
| 6079 | rc = -EIO; |
| 6080 | goto out_free_mbox; |
| 6081 | } |
| 6082 | |
| 6083 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 6084 | if (bf_get(lpfc_mbox_hdr_status, |
| 6085 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 6086 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6087 | "2919 Failed to release resource extents " |
| 6088 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 6089 | "Resource memory not released.\n", |
| 6090 | type, |
| 6091 | bf_get(lpfc_mbox_hdr_status, |
| 6092 | &dealloc_rsrc->header.cfg_shdr.response), |
| 6093 | bf_get(lpfc_mbox_hdr_add_status, |
| 6094 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 6095 | rc = -EIO; |
| 6096 | goto out_free_mbox; |
| 6097 | } |
| 6098 | |
| 6099 | /* Release kernel memory resources for the specific type. */ |
| 6100 | switch (type) { |
| 6101 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6102 | kfree(phba->vpi_bmask); |
| 6103 | kfree(phba->vpi_ids); |
| 6104 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6105 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6106 | &phba->lpfc_vpi_blk_list, list) { |
| 6107 | list_del_init(&rsrc_blk->list); |
| 6108 | kfree(rsrc_blk); |
| 6109 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6110 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6111 | break; |
| 6112 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6113 | kfree(phba->sli4_hba.xri_bmask); |
| 6114 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6115 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6116 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 6117 | list_del_init(&rsrc_blk->list); |
| 6118 | kfree(rsrc_blk); |
| 6119 | } |
| 6120 | break; |
| 6121 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6122 | kfree(phba->sli4_hba.vfi_bmask); |
| 6123 | kfree(phba->sli4_hba.vfi_ids); |
| 6124 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6125 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6126 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 6127 | list_del_init(&rsrc_blk->list); |
| 6128 | kfree(rsrc_blk); |
| 6129 | } |
| 6130 | break; |
| 6131 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6132 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 6133 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6134 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 6135 | list_del_init(&rsrc_blk->list); |
| 6136 | kfree(rsrc_blk); |
| 6137 | } |
| 6138 | break; |
| 6139 | default: |
| 6140 | break; |
| 6141 | } |
| 6142 | |
| 6143 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6144 | |
| 6145 | out_free_mbox: |
| 6146 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6147 | return rc; |
| 6148 | } |
| 6149 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6150 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6151 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 6152 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6153 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6154 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6155 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6156 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 6157 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6158 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6159 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 6160 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6161 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6162 | switch (feature) { |
| 6163 | case LPFC_SET_UE_RECOVERY: |
| 6164 | bf_set(lpfc_mbx_set_feature_UER, |
| 6165 | &mbox->u.mqe.un.set_feature, 1); |
| 6166 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 6167 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6168 | break; |
| 6169 | case LPFC_SET_MDS_DIAGS: |
| 6170 | bf_set(lpfc_mbx_set_feature_mds, |
| 6171 | &mbox->u.mqe.un.set_feature, 1); |
| 6172 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 6173 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6174 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 6175 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6176 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6177 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6178 | |
| 6179 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6180 | } |
| 6181 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6182 | /** |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 6183 | * lpfc_ras_stop_fwlog: Disable FW logging by the adapter |
| 6184 | * @phba: Pointer to HBA context object. |
| 6185 | * |
| 6186 | * Disable FW logging into host memory on the adapter. To |
| 6187 | * be done before reading logs from the host memory. |
| 6188 | **/ |
| 6189 | void |
| 6190 | lpfc_ras_stop_fwlog(struct lpfc_hba *phba) |
| 6191 | { |
| 6192 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6193 | |
| 6194 | ras_fwlog->ras_active = false; |
| 6195 | |
| 6196 | /* Disable FW logging to host memory */ |
| 6197 | writel(LPFC_CTL_PDEV_CTL_DDL_RAS, |
| 6198 | phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); |
| 6199 | } |
| 6200 | |
| 6201 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6202 | * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging. |
| 6203 | * @phba: Pointer to HBA context object. |
| 6204 | * |
| 6205 | * This function is called to free memory allocated for RAS FW logging |
| 6206 | * support in the driver. |
| 6207 | **/ |
| 6208 | void |
| 6209 | lpfc_sli4_ras_dma_free(struct lpfc_hba *phba) |
| 6210 | { |
| 6211 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6212 | struct lpfc_dmabuf *dmabuf, *next; |
| 6213 | |
| 6214 | if (!list_empty(&ras_fwlog->fwlog_buff_list)) { |
| 6215 | list_for_each_entry_safe(dmabuf, next, |
| 6216 | &ras_fwlog->fwlog_buff_list, |
| 6217 | list) { |
| 6218 | list_del(&dmabuf->list); |
| 6219 | dma_free_coherent(&phba->pcidev->dev, |
| 6220 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6221 | dmabuf->virt, dmabuf->phys); |
| 6222 | kfree(dmabuf); |
| 6223 | } |
| 6224 | } |
| 6225 | |
| 6226 | if (ras_fwlog->lwpd.virt) { |
| 6227 | dma_free_coherent(&phba->pcidev->dev, |
| 6228 | sizeof(uint32_t) * 2, |
| 6229 | ras_fwlog->lwpd.virt, |
| 6230 | ras_fwlog->lwpd.phys); |
| 6231 | ras_fwlog->lwpd.virt = NULL; |
| 6232 | } |
| 6233 | |
| 6234 | ras_fwlog->ras_active = false; |
| 6235 | } |
| 6236 | |
| 6237 | /** |
| 6238 | * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support |
| 6239 | * @phba: Pointer to HBA context object. |
| 6240 | * @fwlog_buff_count: Count of buffers to be created. |
| 6241 | * |
| 6242 | * This routine DMA memory for Log Write Position Data[LPWD] and buffer |
| 6243 | * to update FW log is posted to the adapter. |
| 6244 | * Buffer count is calculated based on module param ras_fwlog_buffsize |
| 6245 | * Size of each buffer posted to FW is 64K. |
| 6246 | **/ |
| 6247 | |
| 6248 | static int |
| 6249 | lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba, |
| 6250 | uint32_t fwlog_buff_count) |
| 6251 | { |
| 6252 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6253 | struct lpfc_dmabuf *dmabuf; |
| 6254 | int rc = 0, i = 0; |
| 6255 | |
| 6256 | /* Initialize List */ |
| 6257 | INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list); |
| 6258 | |
| 6259 | /* Allocate memory for the LWPD */ |
| 6260 | ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 6261 | sizeof(uint32_t) * 2, |
| 6262 | &ras_fwlog->lwpd.phys, |
| 6263 | GFP_KERNEL); |
| 6264 | if (!ras_fwlog->lwpd.virt) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6265 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6266 | "6185 LWPD Memory Alloc Failed\n"); |
| 6267 | |
| 6268 | return -ENOMEM; |
| 6269 | } |
| 6270 | |
| 6271 | ras_fwlog->fw_buffcount = fwlog_buff_count; |
| 6272 | for (i = 0; i < ras_fwlog->fw_buffcount; i++) { |
| 6273 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 6274 | GFP_KERNEL); |
| 6275 | if (!dmabuf) { |
| 6276 | rc = -ENOMEM; |
| 6277 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6278 | "6186 Memory Alloc failed FW logging"); |
| 6279 | goto free_mem; |
| 6280 | } |
| 6281 | |
Sabyasachi Gupta | 359d0ac | 2018-11-18 20:08:48 +0530 | [diff] [blame] | 6282 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6283 | LPFC_RAS_MAX_ENTRY_SIZE, |
| 6284 | &dmabuf->phys, |
| 6285 | GFP_KERNEL); |
| 6286 | if (!dmabuf->virt) { |
| 6287 | kfree(dmabuf); |
| 6288 | rc = -ENOMEM; |
| 6289 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6290 | "6187 DMA Alloc Failed FW logging"); |
| 6291 | goto free_mem; |
| 6292 | } |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6293 | dmabuf->buffer_tag = i; |
| 6294 | list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list); |
| 6295 | } |
| 6296 | |
| 6297 | free_mem: |
| 6298 | if (rc) |
| 6299 | lpfc_sli4_ras_dma_free(phba); |
| 6300 | |
| 6301 | return rc; |
| 6302 | } |
| 6303 | |
| 6304 | /** |
| 6305 | * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command |
| 6306 | * @phba: pointer to lpfc hba data structure. |
| 6307 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 6308 | * |
| 6309 | * Completion handler for driver's RAS MBX command to the device. |
| 6310 | **/ |
| 6311 | static void |
| 6312 | lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 6313 | { |
| 6314 | MAILBOX_t *mb; |
| 6315 | union lpfc_sli4_cfg_shdr *shdr; |
| 6316 | uint32_t shdr_status, shdr_add_status; |
| 6317 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6318 | |
| 6319 | mb = &pmb->u.mb; |
| 6320 | |
| 6321 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 6322 | &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr; |
| 6323 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 6324 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 6325 | |
| 6326 | if (mb->mbxStatus != MBX_SUCCESS || shdr_status) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6327 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6328 | "6188 FW LOG mailbox " |
| 6329 | "completed with status x%x add_status x%x," |
| 6330 | " mbx status x%x\n", |
| 6331 | shdr_status, shdr_add_status, mb->mbxStatus); |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6332 | |
| 6333 | ras_fwlog->ras_hwsupport = false; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6334 | goto disable_ras; |
| 6335 | } |
| 6336 | |
| 6337 | ras_fwlog->ras_active = true; |
| 6338 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6339 | |
| 6340 | return; |
| 6341 | |
| 6342 | disable_ras: |
| 6343 | /* Free RAS DMA memory */ |
| 6344 | lpfc_sli4_ras_dma_free(phba); |
| 6345 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6346 | } |
| 6347 | |
| 6348 | /** |
| 6349 | * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command |
| 6350 | * @phba: pointer to lpfc hba data structure. |
| 6351 | * @fwlog_level: Logging verbosity level. |
| 6352 | * @fwlog_enable: Enable/Disable logging. |
| 6353 | * |
| 6354 | * Initialize memory and post mailbox command to enable FW logging in host |
| 6355 | * memory. |
| 6356 | **/ |
| 6357 | int |
| 6358 | lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba, |
| 6359 | uint32_t fwlog_level, |
| 6360 | uint32_t fwlog_enable) |
| 6361 | { |
| 6362 | struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog; |
| 6363 | struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL; |
| 6364 | struct lpfc_dmabuf *dmabuf; |
| 6365 | LPFC_MBOXQ_t *mbox; |
| 6366 | uint32_t len = 0, fwlog_buffsize, fwlog_entry_count; |
| 6367 | int rc = 0; |
| 6368 | |
| 6369 | fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE * |
| 6370 | phba->cfg_ras_fwlog_buffsize); |
| 6371 | fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE); |
| 6372 | |
| 6373 | /* |
| 6374 | * If re-enabling FW logging support use earlier allocated |
| 6375 | * DMA buffers while posting MBX command. |
| 6376 | **/ |
| 6377 | if (!ras_fwlog->lwpd.virt) { |
| 6378 | rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count); |
| 6379 | if (rc) { |
| 6380 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6381 | "6189 FW Log Memory Allocation Failed"); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6382 | return rc; |
| 6383 | } |
| 6384 | } |
| 6385 | |
| 6386 | /* Setup Mailbox command */ |
| 6387 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6388 | if (!mbox) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6389 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6390 | "6190 RAS MBX Alloc Failed"); |
| 6391 | rc = -ENOMEM; |
| 6392 | goto mem_free; |
| 6393 | } |
| 6394 | |
| 6395 | ras_fwlog->fw_loglevel = fwlog_level; |
| 6396 | len = (sizeof(struct lpfc_mbx_set_ras_fwlog) - |
| 6397 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6398 | |
| 6399 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL, |
| 6400 | LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION, |
| 6401 | len, LPFC_SLI4_MBX_EMBED); |
| 6402 | |
| 6403 | mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog; |
| 6404 | bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request, |
| 6405 | fwlog_enable); |
| 6406 | bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request, |
| 6407 | ras_fwlog->fw_loglevel); |
| 6408 | bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request, |
| 6409 | ras_fwlog->fw_buffcount); |
| 6410 | bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request, |
| 6411 | LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE); |
| 6412 | |
| 6413 | /* Update DMA buffer address */ |
| 6414 | list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) { |
| 6415 | memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE); |
| 6416 | |
| 6417 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo = |
| 6418 | putPaddrLow(dmabuf->phys); |
| 6419 | |
| 6420 | mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi = |
| 6421 | putPaddrHigh(dmabuf->phys); |
| 6422 | } |
| 6423 | |
| 6424 | /* Update LPWD address */ |
| 6425 | mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys); |
| 6426 | mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys); |
| 6427 | |
| 6428 | mbox->vport = phba->pport; |
| 6429 | mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl; |
| 6430 | |
| 6431 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 6432 | |
| 6433 | if (rc == MBX_NOT_FINISHED) { |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 6434 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6435 | "6191 FW-Log Mailbox failed. " |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6436 | "status %d mbxStatus : x%x", rc, |
| 6437 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); |
| 6438 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6439 | rc = -EIO; |
| 6440 | goto mem_free; |
| 6441 | } else |
| 6442 | rc = 0; |
| 6443 | mem_free: |
| 6444 | if (rc) |
| 6445 | lpfc_sli4_ras_dma_free(phba); |
| 6446 | |
| 6447 | return rc; |
| 6448 | } |
| 6449 | |
| 6450 | /** |
| 6451 | * lpfc_sli4_ras_setup - Check if RAS supported on the adapter |
| 6452 | * @phba: Pointer to HBA context object. |
| 6453 | * |
| 6454 | * Check if RAS is supported on the adapter and initialize it. |
| 6455 | **/ |
| 6456 | void |
| 6457 | lpfc_sli4_ras_setup(struct lpfc_hba *phba) |
| 6458 | { |
| 6459 | /* Check RAS FW Log needs to be enabled or not */ |
| 6460 | if (lpfc_check_fwlog_support(phba)) |
| 6461 | return; |
| 6462 | |
| 6463 | lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level, |
| 6464 | LPFC_RAS_ENABLE_LOGGING); |
| 6465 | } |
| 6466 | |
| 6467 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6468 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 6469 | * @phba: Pointer to HBA context object. |
| 6470 | * |
| 6471 | * This function allocates all SLI4 resource identifiers. |
| 6472 | **/ |
| 6473 | int |
| 6474 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 6475 | { |
| 6476 | int i, rc, error = 0; |
| 6477 | uint16_t count, base; |
| 6478 | unsigned long longs; |
| 6479 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6480 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6481 | 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] | 6482 | if (phba->sli4_hba.extents_in_use) { |
| 6483 | /* |
| 6484 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 6485 | * resource extent count must be read and allocated before |
| 6486 | * provisioning the resource id arrays. |
| 6487 | */ |
| 6488 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 6489 | LPFC_IDX_RSRC_RDY) { |
| 6490 | /* |
| 6491 | * Extent-based resources are set - the driver could |
| 6492 | * be in a port reset. Figure out if any corrective |
| 6493 | * actions need to be taken. |
| 6494 | */ |
| 6495 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6496 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6497 | if (rc != 0) |
| 6498 | error++; |
| 6499 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6500 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6501 | if (rc != 0) |
| 6502 | error++; |
| 6503 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6504 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6505 | if (rc != 0) |
| 6506 | error++; |
| 6507 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6508 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6509 | if (rc != 0) |
| 6510 | error++; |
| 6511 | |
| 6512 | /* |
| 6513 | * It's possible that the number of resources |
| 6514 | * provided to this port instance changed between |
| 6515 | * resets. Detect this condition and reallocate |
| 6516 | * resources. Otherwise, there is no action. |
| 6517 | */ |
| 6518 | if (error) { |
| 6519 | lpfc_printf_log(phba, KERN_INFO, |
| 6520 | LOG_MBOX | LOG_INIT, |
| 6521 | "2931 Detected extent resource " |
| 6522 | "change. Reallocating all " |
| 6523 | "extents.\n"); |
| 6524 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6525 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6526 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6527 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6528 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6529 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6530 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6531 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6532 | } else |
| 6533 | return 0; |
| 6534 | } |
| 6535 | |
| 6536 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6537 | if (unlikely(rc)) |
| 6538 | goto err_exit; |
| 6539 | |
| 6540 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6541 | if (unlikely(rc)) |
| 6542 | goto err_exit; |
| 6543 | |
| 6544 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6545 | if (unlikely(rc)) |
| 6546 | goto err_exit; |
| 6547 | |
| 6548 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6549 | if (unlikely(rc)) |
| 6550 | goto err_exit; |
| 6551 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6552 | LPFC_IDX_RSRC_RDY); |
| 6553 | return rc; |
| 6554 | } else { |
| 6555 | /* |
| 6556 | * The port does not support resource extents. The XRI, VPI, |
| 6557 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6558 | * Just allocate the bitmasks and provision the resource id |
| 6559 | * arrays. If a port reset is active, the resources don't |
| 6560 | * need any action - just exit. |
| 6561 | */ |
| 6562 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6563 | LPFC_IDX_RSRC_RDY) { |
| 6564 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6565 | lpfc_sli4_remove_rpis(phba); |
| 6566 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6567 | /* RPIs. */ |
| 6568 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6569 | if (count <= 0) { |
| 6570 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6571 | "3279 Invalid provisioning of " |
| 6572 | "rpi:%d\n", count); |
| 6573 | rc = -EINVAL; |
| 6574 | goto err_exit; |
| 6575 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6576 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6577 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6578 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6579 | sizeof(unsigned long), |
| 6580 | GFP_KERNEL); |
| 6581 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6582 | rc = -ENOMEM; |
| 6583 | goto err_exit; |
| 6584 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6585 | phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6586 | GFP_KERNEL); |
| 6587 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6588 | rc = -ENOMEM; |
| 6589 | goto free_rpi_bmask; |
| 6590 | } |
| 6591 | |
| 6592 | for (i = 0; i < count; i++) |
| 6593 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6594 | |
| 6595 | /* VPIs. */ |
| 6596 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6597 | if (count <= 0) { |
| 6598 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6599 | "3280 Invalid provisioning of " |
| 6600 | "vpi:%d\n", count); |
| 6601 | rc = -EINVAL; |
| 6602 | goto free_rpi_ids; |
| 6603 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6604 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6605 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6606 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6607 | GFP_KERNEL); |
| 6608 | if (unlikely(!phba->vpi_bmask)) { |
| 6609 | rc = -ENOMEM; |
| 6610 | goto free_rpi_ids; |
| 6611 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6612 | phba->vpi_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->vpi_ids)) { |
| 6615 | rc = -ENOMEM; |
| 6616 | goto free_vpi_bmask; |
| 6617 | } |
| 6618 | |
| 6619 | for (i = 0; i < count; i++) |
| 6620 | phba->vpi_ids[i] = base + i; |
| 6621 | |
| 6622 | /* XRIs. */ |
| 6623 | count = phba->sli4_hba.max_cfg_param.max_xri; |
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 | "3281 Invalid provisioning of " |
| 6627 | "xri:%d\n", count); |
| 6628 | rc = -EINVAL; |
| 6629 | goto free_vpi_ids; |
| 6630 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6631 | base = phba->sli4_hba.max_cfg_param.xri_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->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6634 | sizeof(unsigned long), |
| 6635 | GFP_KERNEL); |
| 6636 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6637 | rc = -ENOMEM; |
| 6638 | goto free_vpi_ids; |
| 6639 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6640 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6641 | phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6642 | GFP_KERNEL); |
| 6643 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6644 | rc = -ENOMEM; |
| 6645 | goto free_xri_bmask; |
| 6646 | } |
| 6647 | |
| 6648 | for (i = 0; i < count; i++) |
| 6649 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6650 | |
| 6651 | /* VFIs. */ |
| 6652 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6653 | if (count <= 0) { |
| 6654 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6655 | "3282 Invalid provisioning of " |
| 6656 | "vfi:%d\n", count); |
| 6657 | rc = -EINVAL; |
| 6658 | goto free_xri_ids; |
| 6659 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6660 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6661 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6662 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6663 | sizeof(unsigned long), |
| 6664 | GFP_KERNEL); |
| 6665 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6666 | rc = -ENOMEM; |
| 6667 | goto free_xri_ids; |
| 6668 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6669 | phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6670 | GFP_KERNEL); |
| 6671 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6672 | rc = -ENOMEM; |
| 6673 | goto free_vfi_bmask; |
| 6674 | } |
| 6675 | |
| 6676 | for (i = 0; i < count; i++) |
| 6677 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6678 | |
| 6679 | /* |
| 6680 | * Mark all resources ready. An HBA reset doesn't need |
| 6681 | * to reset the initialization. |
| 6682 | */ |
| 6683 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6684 | LPFC_IDX_RSRC_RDY); |
| 6685 | return 0; |
| 6686 | } |
| 6687 | |
| 6688 | free_vfi_bmask: |
| 6689 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6690 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6691 | free_xri_ids: |
| 6692 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6693 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6694 | free_xri_bmask: |
| 6695 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6696 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6697 | free_vpi_ids: |
| 6698 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6699 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6700 | free_vpi_bmask: |
| 6701 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6702 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6703 | free_rpi_ids: |
| 6704 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6705 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6706 | free_rpi_bmask: |
| 6707 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6708 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6709 | err_exit: |
| 6710 | return rc; |
| 6711 | } |
| 6712 | |
| 6713 | /** |
| 6714 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6715 | * @phba: Pointer to HBA context object. |
| 6716 | * |
| 6717 | * This function allocates the number of elements for the specified |
| 6718 | * resource type. |
| 6719 | **/ |
| 6720 | int |
| 6721 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 6722 | { |
| 6723 | if (phba->sli4_hba.extents_in_use) { |
| 6724 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6725 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6726 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6727 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6728 | } else { |
| 6729 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6730 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6731 | kfree(phba->vpi_ids); |
| 6732 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6733 | kfree(phba->sli4_hba.xri_bmask); |
| 6734 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6735 | kfree(phba->sli4_hba.vfi_bmask); |
| 6736 | kfree(phba->sli4_hba.vfi_ids); |
| 6737 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6738 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6739 | } |
| 6740 | |
| 6741 | return 0; |
| 6742 | } |
| 6743 | |
| 6744 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6745 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6746 | * @phba: Pointer to HBA context object. |
| 6747 | * @type: The resource extent type. |
| 6748 | * @extnt_count: buffer to hold port extent count response |
| 6749 | * @extnt_size: buffer to hold port extent size response. |
| 6750 | * |
| 6751 | * This function calls the port to read the host allocated extents |
| 6752 | * for a particular type. |
| 6753 | **/ |
| 6754 | int |
| 6755 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6756 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6757 | { |
| 6758 | bool emb; |
| 6759 | int rc = 0; |
| 6760 | uint16_t curr_blks = 0; |
| 6761 | uint32_t req_len, emb_len; |
| 6762 | uint32_t alloc_len, mbox_tmo; |
| 6763 | struct list_head *blk_list_head; |
| 6764 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6765 | LPFC_MBOXQ_t *mbox; |
| 6766 | void *virtaddr = NULL; |
| 6767 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6768 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6769 | union lpfc_sli4_cfg_shdr *shdr; |
| 6770 | |
| 6771 | switch (type) { |
| 6772 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6773 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6774 | break; |
| 6775 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6776 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6777 | break; |
| 6778 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6779 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6780 | break; |
| 6781 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6782 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6783 | break; |
| 6784 | default: |
| 6785 | return -EIO; |
| 6786 | } |
| 6787 | |
| 6788 | /* Count the number of extents currently allocatd for this type. */ |
| 6789 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6790 | if (curr_blks == 0) { |
| 6791 | /* |
| 6792 | * The GET_ALLOCATED mailbox does not return the size, |
| 6793 | * just the count. The size should be just the size |
| 6794 | * stored in the current allocated block and all sizes |
| 6795 | * for an extent type are the same so set the return |
| 6796 | * value now. |
| 6797 | */ |
| 6798 | *extnt_size = rsrc_blk->rsrc_size; |
| 6799 | } |
| 6800 | curr_blks++; |
| 6801 | } |
| 6802 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6803 | /* |
| 6804 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6805 | * accounts for extents-specific word. |
| 6806 | */ |
| 6807 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6808 | sizeof(uint32_t); |
| 6809 | |
| 6810 | /* |
| 6811 | * Presume the allocation and response will fit into an embedded |
| 6812 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6813 | */ |
| 6814 | emb = LPFC_SLI4_MBX_EMBED; |
| 6815 | req_len = emb_len; |
| 6816 | if (req_len > emb_len) { |
| 6817 | req_len = curr_blks * sizeof(uint16_t) + |
| 6818 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6819 | sizeof(uint32_t); |
| 6820 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6821 | } |
| 6822 | |
| 6823 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6824 | if (!mbox) |
| 6825 | return -ENOMEM; |
| 6826 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6827 | |
| 6828 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6829 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6830 | req_len, emb); |
| 6831 | if (alloc_len < req_len) { |
| 6832 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6833 | "2983 Allocated DMA memory size (x%x) is " |
| 6834 | "less than the requested DMA memory " |
| 6835 | "size (x%x)\n", alloc_len, req_len); |
| 6836 | rc = -ENOMEM; |
| 6837 | goto err_exit; |
| 6838 | } |
| 6839 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6840 | if (unlikely(rc)) { |
| 6841 | rc = -EIO; |
| 6842 | goto err_exit; |
| 6843 | } |
| 6844 | |
| 6845 | if (!phba->sli4_hba.intr_enable) |
| 6846 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6847 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6848 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6849 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6850 | } |
| 6851 | |
| 6852 | if (unlikely(rc)) { |
| 6853 | rc = -EIO; |
| 6854 | goto err_exit; |
| 6855 | } |
| 6856 | |
| 6857 | /* |
| 6858 | * Figure out where the response is located. Then get local pointers |
| 6859 | * to the response data. The port does not guarantee to respond to |
| 6860 | * all extents counts request so update the local variable with the |
| 6861 | * allocated count from the port. |
| 6862 | */ |
| 6863 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6864 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6865 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6866 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6867 | } else { |
| 6868 | virtaddr = mbox->sge_array->addr[0]; |
| 6869 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6870 | shdr = &n_rsrc->cfg_shdr; |
| 6871 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6872 | } |
| 6873 | |
| 6874 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6875 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6876 | "2984 Failed to read allocated resources " |
| 6877 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6878 | type, |
| 6879 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6880 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6881 | rc = -EIO; |
| 6882 | goto err_exit; |
| 6883 | } |
| 6884 | err_exit: |
| 6885 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6886 | return rc; |
| 6887 | } |
| 6888 | |
| 6889 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 6890 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6891 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6892 | * @pring: Pointer to driver SLI ring object. |
| 6893 | * @sgl_list: linked link of sgl buffers to post |
| 6894 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6895 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6896 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6897 | * repost them to the port by using SGL block post. This is needed after a |
| 6898 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6899 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 6900 | * 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] | 6901 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6902 | * mailbox command for posting. |
| 6903 | * |
| 6904 | * Returns: 0 = success, non-zero failure. |
| 6905 | **/ |
| 6906 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6907 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 6908 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6909 | { |
| 6910 | struct lpfc_sglq *sglq_entry = NULL; |
| 6911 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6912 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6913 | int status, total_cnt; |
| 6914 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6915 | int last_xritag = NO_XRI; |
| 6916 | LIST_HEAD(prep_sgl_list); |
| 6917 | LIST_HEAD(blck_sgl_list); |
| 6918 | LIST_HEAD(allc_sgl_list); |
| 6919 | LIST_HEAD(post_sgl_list); |
| 6920 | LIST_HEAD(free_sgl_list); |
| 6921 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6922 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6923 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6924 | list_splice_init(sgl_list, &allc_sgl_list); |
| 6925 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6926 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6927 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6928 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6929 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6930 | &allc_sgl_list, list) { |
| 6931 | list_del_init(&sglq_entry->list); |
| 6932 | block_cnt++; |
| 6933 | if ((last_xritag != NO_XRI) && |
| 6934 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6935 | /* a hole in xri block, form a sgl posting block */ |
| 6936 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6937 | post_cnt = block_cnt - 1; |
| 6938 | /* prepare list for next posting block */ |
| 6939 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6940 | block_cnt = 1; |
| 6941 | } else { |
| 6942 | /* prepare list for next posting block */ |
| 6943 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6944 | /* enough sgls for non-embed sgl mbox command */ |
| 6945 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6946 | list_splice_init(&prep_sgl_list, |
| 6947 | &blck_sgl_list); |
| 6948 | post_cnt = block_cnt; |
| 6949 | block_cnt = 0; |
| 6950 | } |
| 6951 | } |
| 6952 | num_posted++; |
| 6953 | |
| 6954 | /* keep track of last sgl's xritag */ |
| 6955 | last_xritag = sglq_entry->sli4_xritag; |
| 6956 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6957 | /* end of repost sgl list condition for buffers */ |
| 6958 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6959 | if (post_cnt == 0) { |
| 6960 | list_splice_init(&prep_sgl_list, |
| 6961 | &blck_sgl_list); |
| 6962 | post_cnt = block_cnt; |
| 6963 | } else if (block_cnt == 1) { |
| 6964 | status = lpfc_sli4_post_sgl(phba, |
| 6965 | sglq_entry->phys, 0, |
| 6966 | sglq_entry->sli4_xritag); |
| 6967 | if (!status) { |
| 6968 | /* successful, put sgl to posted list */ |
| 6969 | list_add_tail(&sglq_entry->list, |
| 6970 | &post_sgl_list); |
| 6971 | } else { |
| 6972 | /* Failure, put sgl to free list */ |
| 6973 | lpfc_printf_log(phba, KERN_WARNING, |
| 6974 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6975 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6976 | "sgl, xritag:x%x\n", |
| 6977 | sglq_entry->sli4_xritag); |
| 6978 | list_add_tail(&sglq_entry->list, |
| 6979 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6980 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6981 | } |
| 6982 | } |
| 6983 | } |
| 6984 | |
| 6985 | /* continue until a nembed page worth of sgls */ |
| 6986 | if (post_cnt == 0) |
| 6987 | continue; |
| 6988 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6989 | /* post the buffer list sgls as a block */ |
| 6990 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 6991 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6992 | |
| 6993 | if (!status) { |
| 6994 | /* success, put sgl list to posted sgl list */ |
| 6995 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6996 | } else { |
| 6997 | /* Failure, put sgl list to free sgl list */ |
| 6998 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6999 | struct lpfc_sglq, |
| 7000 | list); |
| 7001 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7002 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7003 | "xritag:x%x-x%x\n", |
| 7004 | sglq_entry_first->sli4_xritag, |
| 7005 | (sglq_entry_first->sli4_xritag + |
| 7006 | post_cnt - 1)); |
| 7007 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 7008 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7009 | } |
| 7010 | |
| 7011 | /* don't reset xirtag due to hole in xri block */ |
| 7012 | if (block_cnt == 0) |
| 7013 | last_xritag = NO_XRI; |
| 7014 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7015 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7016 | post_cnt = 0; |
| 7017 | } |
| 7018 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7019 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7020 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 7021 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7022 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7023 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7024 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7025 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7026 | list_splice_init(&post_sgl_list, sgl_list); |
| 7027 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 7028 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7029 | } else { |
| 7030 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7031 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7032 | return -EIO; |
| 7033 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7034 | |
| 7035 | /* return the number of XRIs actually posted */ |
| 7036 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7037 | } |
| 7038 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7039 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7040 | * 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] | 7041 | * @phba: pointer to lpfc hba data structure. |
| 7042 | * |
| 7043 | * This routine walks the list of nvme buffers that have been allocated and |
| 7044 | * repost them to the port by using SGL block post. This is needed after a |
| 7045 | * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine |
| 7046 | * 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] | 7047 | * 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] | 7048 | * |
| 7049 | * Returns: 0 = success, non-zero failure. |
| 7050 | **/ |
| 7051 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7052 | lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7053 | { |
| 7054 | LIST_HEAD(post_nblist); |
| 7055 | int num_posted, rc = 0; |
| 7056 | |
| 7057 | /* get all NVME buffers need to repost to a local list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7058 | lpfc_io_buf_flush(phba, &post_nblist); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7059 | |
| 7060 | /* post the list of nvme buffer sgls to port if available */ |
| 7061 | if (!list_empty(&post_nblist)) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7062 | num_posted = lpfc_sli4_post_io_sgl_list( |
| 7063 | phba, &post_nblist, phba->sli4_hba.io_xri_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7064 | /* failed to post any nvme buffer, return error */ |
| 7065 | if (num_posted == 0) |
| 7066 | rc = -EIO; |
| 7067 | } |
| 7068 | return rc; |
| 7069 | } |
| 7070 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7071 | void |
| 7072 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 7073 | { |
| 7074 | uint32_t len; |
| 7075 | |
| 7076 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 7077 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 7078 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7079 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 7080 | LPFC_SLI4_MBX_EMBED); |
| 7081 | |
| 7082 | 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] | 7083 | mbox->u.mqe.un.set_host_data.param_len = |
| 7084 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7085 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 7086 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 7087 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 7088 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 7089 | } |
| 7090 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7091 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7092 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7093 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7094 | { |
| 7095 | int rc, i; |
| 7096 | struct lpfc_rqe hrqe; |
| 7097 | struct lpfc_rqe drqe; |
| 7098 | struct lpfc_rqb *rqbp; |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7099 | unsigned long flags; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7100 | struct rqb_dmabuf *rqb_buffer; |
| 7101 | LIST_HEAD(rqb_buf_list); |
| 7102 | |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7103 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7104 | rqbp = hrq->rqbp; |
| 7105 | for (i = 0; i < count; i++) { |
| 7106 | /* IF RQ is already full, don't bother */ |
| 7107 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) |
| 7108 | break; |
| 7109 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 7110 | if (!rqb_buffer) |
| 7111 | break; |
| 7112 | rqb_buffer->hrq = hrq; |
| 7113 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7114 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7115 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 7116 | } |
| 7117 | while (!list_empty(&rqb_buf_list)) { |
| 7118 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 7119 | hbuf.list); |
| 7120 | |
| 7121 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 7122 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 7123 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 7124 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 7125 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 7126 | if (rc < 0) { |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7127 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7128 | "6421 Cannot post to HRQ %d: %x %x %x " |
| 7129 | "DRQ %x %x\n", |
| 7130 | hrq->queue_id, |
| 7131 | hrq->host_index, |
| 7132 | hrq->hba_index, |
| 7133 | hrq->entry_count, |
| 7134 | drq->host_index, |
| 7135 | drq->hba_index); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7136 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 7137 | } else { |
| 7138 | list_add_tail(&rqb_buffer->hbuf.list, |
| 7139 | &rqbp->rqb_buffer_list); |
| 7140 | rqbp->buffer_count++; |
| 7141 | } |
| 7142 | } |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 7143 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7144 | return 1; |
| 7145 | } |
| 7146 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7147 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7148 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7149 | * @phba: Pointer to HBA context object. |
| 7150 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 7151 | * This function is the main SLI4 device initialization PCI function. This |
| 7152 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7153 | * HBA error attention handler code. Caller is not required to hold any |
| 7154 | * locks. |
| 7155 | **/ |
| 7156 | int |
| 7157 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 7158 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7159 | int rc, i, cnt, len; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7160 | LPFC_MBOXQ_t *mboxq; |
| 7161 | struct lpfc_mqe *mqe; |
| 7162 | uint8_t *vpd; |
| 7163 | uint32_t vpd_size; |
| 7164 | uint32_t ftr_rsp = 0; |
| 7165 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 7166 | struct lpfc_vport *vport = phba->pport; |
| 7167 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7168 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7169 | |
| 7170 | /* Perform a PCI function reset to start from clean */ |
| 7171 | rc = lpfc_pci_function_reset(phba); |
| 7172 | if (unlikely(rc)) |
| 7173 | return -ENODEV; |
| 7174 | |
| 7175 | /* Check the HBA Host Status Register for readyness */ |
| 7176 | rc = lpfc_sli4_post_status_check(phba); |
| 7177 | if (unlikely(rc)) |
| 7178 | return -ENODEV; |
| 7179 | else { |
| 7180 | spin_lock_irq(&phba->hbalock); |
| 7181 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 7182 | spin_unlock_irq(&phba->hbalock); |
| 7183 | } |
| 7184 | |
| 7185 | /* |
| 7186 | * Allocate a single mailbox container for initializing the |
| 7187 | * port. |
| 7188 | */ |
| 7189 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7190 | if (!mboxq) |
| 7191 | return -ENOMEM; |
| 7192 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7193 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7194 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7195 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 7196 | if (!vpd) { |
| 7197 | rc = -ENOMEM; |
| 7198 | goto out_free_mbox; |
| 7199 | } |
| 7200 | |
| 7201 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7202 | if (unlikely(rc)) { |
| 7203 | kfree(vpd); |
| 7204 | goto out_free_mbox; |
| 7205 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7206 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7207 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7208 | 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] | 7209 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7210 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7211 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 7212 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7213 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 7214 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7215 | |
| 7216 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 7217 | LPFC_DCBX_CEE_MODE) |
| 7218 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 7219 | else |
| 7220 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 7221 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 7222 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 7223 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 7224 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7225 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7226 | "0376 READ_REV Error. SLI Level %d " |
| 7227 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7228 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7229 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7230 | kfree(vpd); |
| 7231 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7232 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7233 | |
| 7234 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7235 | * Continue initialization with default values even if driver failed |
| 7236 | * to read FCoE param config regions, only read parameters if the |
| 7237 | * board is FCoE |
| 7238 | */ |
| 7239 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 7240 | lpfc_sli4_read_fcoe_params(phba)) |
| 7241 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 7242 | "2570 Failed to read FCoE parameters\n"); |
| 7243 | |
| 7244 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 7245 | * Retrieve sli4 device physical port name, failure of doing it |
| 7246 | * is considered as non-fatal. |
| 7247 | */ |
| 7248 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 7249 | if (!rc) |
| 7250 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7251 | "3080 Successful retrieving SLI4 device " |
| 7252 | "physical port name: %s.\n", phba->Port); |
| 7253 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7254 | /* |
| 7255 | * Evaluate the read rev and vpd data. Populate the driver |
| 7256 | * state with the results. If this routine fails, the failure |
| 7257 | * is not fatal as the driver will use generic values. |
| 7258 | */ |
| 7259 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 7260 | if (unlikely(!rc)) { |
| 7261 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7262 | "0377 Error %d parsing vpd. " |
| 7263 | "Using defaults.\n", rc); |
| 7264 | rc = 0; |
| 7265 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7266 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7267 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7268 | /* Save information as VPD data */ |
| 7269 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 7270 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 7271 | |
| 7272 | /* |
| 7273 | * This is because first G7 ASIC doesn't support the standard |
| 7274 | * 0x5a NVME cmd descriptor type/subtype |
| 7275 | */ |
| 7276 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7277 | LPFC_SLI_INTF_IF_TYPE_6) && |
| 7278 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && |
| 7279 | (phba->vpd.rev.smRev == 0) && |
| 7280 | (phba->cfg_nvme_embed_cmd == 1)) |
| 7281 | phba->cfg_nvme_embed_cmd = 0; |
| 7282 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7283 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 7284 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 7285 | &mqe->un.read_rev); |
| 7286 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 7287 | &mqe->un.read_rev); |
| 7288 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 7289 | &mqe->un.read_rev); |
| 7290 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 7291 | &mqe->un.read_rev); |
| 7292 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 7293 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 7294 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 7295 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 7296 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 7297 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 7298 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 7299 | "(%d):0380 READ_REV Status x%x " |
| 7300 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 7301 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7302 | bf_get(lpfc_mqe_status, mqe), |
| 7303 | phba->vpd.rev.opFwName, |
| 7304 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 7305 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7306 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7307 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 7308 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 7309 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 7310 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7311 | "3362 LUN queue depth changed from %d to %d\n", |
| 7312 | phba->pport->cfg_lun_queue_depth, rc); |
| 7313 | phba->pport->cfg_lun_queue_depth = rc; |
| 7314 | } |
| 7315 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7316 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 7317 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 7318 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 7319 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7320 | if (rc == MBX_SUCCESS) { |
| 7321 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 7322 | /* Set 1Sec interval to detect UE */ |
| 7323 | phba->eratt_poll_interval = 1; |
| 7324 | phba->sli4_hba.ue_to_sr = bf_get( |
| 7325 | lpfc_mbx_set_feature_UESR, |
| 7326 | &mboxq->u.mqe.un.set_feature); |
| 7327 | phba->sli4_hba.ue_to_rp = bf_get( |
| 7328 | lpfc_mbx_set_feature_UERP, |
| 7329 | &mboxq->u.mqe.un.set_feature); |
| 7330 | } |
| 7331 | } |
| 7332 | |
| 7333 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 7334 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 7335 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 7336 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7337 | if (rc != MBX_SUCCESS) |
| 7338 | phba->mds_diags_support = 0; |
| 7339 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7340 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7341 | /* |
| 7342 | * Discover the port's supported feature set and match it against the |
| 7343 | * hosts requests. |
| 7344 | */ |
| 7345 | lpfc_request_features(phba, mboxq); |
| 7346 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7347 | if (unlikely(rc)) { |
| 7348 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7349 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7350 | } |
| 7351 | |
| 7352 | /* |
| 7353 | * The port must support FCP initiator mode as this is the |
| 7354 | * only mode running in the host. |
| 7355 | */ |
| 7356 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 7357 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7358 | "0378 No support for fcpi mode.\n"); |
| 7359 | ftr_rsp++; |
| 7360 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 7361 | |
| 7362 | /* Performance Hints are ONLY for FCoE */ |
| 7363 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 7364 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 7365 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 7366 | else |
| 7367 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
| 7368 | } |
| 7369 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7370 | /* |
| 7371 | * If the port cannot support the host's requested features |
| 7372 | * then turn off the global config parameters to disable the |
| 7373 | * feature in the driver. This is not a fatal error. |
| 7374 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7375 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 7376 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { |
| 7377 | phba->cfg_enable_bg = 0; |
| 7378 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7379 | ftr_rsp++; |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7380 | } |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7381 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7382 | |
| 7383 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 7384 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7385 | ftr_rsp++; |
| 7386 | |
| 7387 | if (ftr_rsp) { |
| 7388 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7389 | "0379 Feature Mismatch Data: x%08x %08x " |
| 7390 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 7391 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 7392 | phba->cfg_enable_npiv, phba->max_vpi); |
| 7393 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 7394 | phba->cfg_enable_bg = 0; |
| 7395 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7396 | phba->cfg_enable_npiv = 0; |
| 7397 | } |
| 7398 | |
| 7399 | /* These SLI3 features are assumed in SLI4 */ |
| 7400 | spin_lock_irq(&phba->hbalock); |
| 7401 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 7402 | spin_unlock_irq(&phba->hbalock); |
| 7403 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7404 | /* |
| 7405 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 7406 | * calls depends on these resources to complete port setup. |
| 7407 | */ |
| 7408 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 7409 | if (rc) { |
| 7410 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7411 | "2920 Failed to alloc Resource IDs " |
| 7412 | "rc = x%x\n", rc); |
| 7413 | goto out_free_mbox; |
| 7414 | } |
| 7415 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7416 | lpfc_set_host_data(phba, mboxq); |
| 7417 | |
| 7418 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7419 | if (rc) { |
| 7420 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7421 | "2134 Failed to set host os driver version %x", |
| 7422 | rc); |
| 7423 | } |
| 7424 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7425 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7426 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 7427 | if (rc) { |
| 7428 | phba->link_state = LPFC_HBA_ERROR; |
| 7429 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7430 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7431 | } |
| 7432 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7433 | mboxq->vport = vport; |
| 7434 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7435 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7436 | if (rc == MBX_SUCCESS) { |
| 7437 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 7438 | rc = 0; |
| 7439 | } |
| 7440 | |
| 7441 | /* |
| 7442 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 7443 | * it to the mbuf pool. |
| 7444 | */ |
| 7445 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 7446 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 7447 | mboxq->ctx_buf = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7448 | if (unlikely(rc)) { |
| 7449 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7450 | "0382 READ_SPARAM command failed " |
| 7451 | "status %d, mbxStatus x%x\n", |
| 7452 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 7453 | phba->link_state = LPFC_HBA_ERROR; |
| 7454 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7455 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7456 | } |
| 7457 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7458 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7459 | |
| 7460 | /* Update the fc_host data structures with new wwn. */ |
| 7461 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 7462 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 7463 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7464 | /* Create all the SLI4 queues */ |
| 7465 | rc = lpfc_sli4_queue_create(phba); |
| 7466 | if (rc) { |
| 7467 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7468 | "3089 Failed to allocate queues\n"); |
| 7469 | rc = -ENODEV; |
| 7470 | goto out_free_mbox; |
| 7471 | } |
| 7472 | /* Set up all the queues to the device */ |
| 7473 | rc = lpfc_sli4_queue_setup(phba); |
| 7474 | if (unlikely(rc)) { |
| 7475 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7476 | "0381 Error %d during queue setup.\n ", rc); |
| 7477 | goto out_stop_timers; |
| 7478 | } |
| 7479 | /* Initialize the driver internal SLI layer lists. */ |
| 7480 | lpfc_sli4_setup(phba); |
| 7481 | lpfc_sli4_queue_init(phba); |
| 7482 | |
| 7483 | /* update host els xri-sgl sizes and mappings */ |
| 7484 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7485 | if (unlikely(rc)) { |
| 7486 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7487 | "1400 Failed to update xri-sgl size and " |
| 7488 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7489 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7490 | } |
| 7491 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7492 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7493 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 7494 | phba->sli4_hba.els_xri_cnt); |
| 7495 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7496 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7497 | "0582 Error %d during els sgl post " |
| 7498 | "operation\n", rc); |
| 7499 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7500 | goto out_destroy_queue; |
| 7501 | } |
| 7502 | phba->sli4_hba.els_xri_cnt = rc; |
| 7503 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7504 | if (phba->nvmet_support) { |
| 7505 | /* update host nvmet xri-sgl sizes and mappings */ |
| 7506 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 7507 | if (unlikely(rc)) { |
| 7508 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7509 | "6308 Failed to update nvmet-sgl size " |
| 7510 | "and mapping: %d\n", rc); |
| 7511 | goto out_destroy_queue; |
| 7512 | } |
| 7513 | |
| 7514 | /* register the nvmet sgl pool to the port */ |
| 7515 | rc = lpfc_sli4_repost_sgl_list( |
| 7516 | phba, |
| 7517 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 7518 | phba->sli4_hba.nvmet_xri_cnt); |
| 7519 | if (unlikely(rc < 0)) { |
| 7520 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7521 | "3117 Error %d during nvmet " |
| 7522 | "sgl post\n", rc); |
| 7523 | rc = -ENODEV; |
| 7524 | goto out_destroy_queue; |
| 7525 | } |
| 7526 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7527 | |
| 7528 | cnt = phba->cfg_iocb_cnt * 1024; |
| 7529 | /* We need 1 iocbq for every SGL, for IO processing */ |
| 7530 | cnt += phba->sli4_hba.nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7531 | } else { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7532 | /* update host common xri-sgl sizes and mappings */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7533 | rc = lpfc_sli4_io_sgl_update(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7534 | if (unlikely(rc)) { |
| 7535 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7536 | "6082 Failed to update nvme-sgl size " |
| 7537 | "and mapping: %d\n", rc); |
| 7538 | goto out_destroy_queue; |
| 7539 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7540 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7541 | /* register the allocated common sgl pool to the port */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7542 | rc = lpfc_sli4_repost_io_sgl_list(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7543 | if (unlikely(rc)) { |
| 7544 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7545 | "6116 Error %d during nvme sgl post " |
| 7546 | "operation\n", rc); |
| 7547 | /* Some NVME buffers were moved to abort nvme list */ |
| 7548 | /* A pci function reset will repost them */ |
| 7549 | rc = -ENODEV; |
| 7550 | goto out_destroy_queue; |
| 7551 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7552 | cnt = phba->cfg_iocb_cnt * 1024; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7553 | } |
| 7554 | |
| 7555 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7556 | /* Initialize and populate the iocb list per host */ |
| 7557 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7558 | "2821 initialize iocb list %d total %d\n", |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7559 | phba->cfg_iocb_cnt, cnt); |
| 7560 | rc = lpfc_init_iocb_list(phba, cnt); |
| 7561 | if (rc) { |
| 7562 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7563 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7564 | goto out_destroy_queue; |
| 7565 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7566 | } |
| 7567 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7568 | if (phba->nvmet_support) |
| 7569 | lpfc_nvmet_create_targetport(phba); |
| 7570 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7571 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7572 | /* Post initial buffers to all RQs created */ |
| 7573 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 7574 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 7575 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 7576 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 7577 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 7578 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7579 | rqbp->buffer_count = 0; |
| 7580 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7581 | lpfc_post_rq_buffer( |
| 7582 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 7583 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | 2448e48 | 2018-04-09 14:24:24 -0700 | [diff] [blame] | 7584 | phba->cfg_nvmet_mrq_post, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7585 | } |
| 7586 | } |
| 7587 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7588 | /* Post the rpi header region to the device. */ |
| 7589 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7590 | if (unlikely(rc)) { |
| 7591 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7592 | "0393 Error %d during rpi post operation\n", |
| 7593 | rc); |
| 7594 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7595 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7596 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7597 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7598 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7599 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7600 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7601 | /* |
| 7602 | * The FC Port needs to register FCFI (index 0) |
| 7603 | */ |
| 7604 | lpfc_reg_fcfi(phba, mboxq); |
| 7605 | mboxq->vport = phba->pport; |
| 7606 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7607 | if (rc != MBX_SUCCESS) |
| 7608 | goto out_unset_queue; |
| 7609 | rc = 0; |
| 7610 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7611 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7612 | } else { |
| 7613 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7614 | |
| 7615 | /* First register the FCFI */ |
| 7616 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7617 | mboxq->vport = phba->pport; |
| 7618 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7619 | if (rc != MBX_SUCCESS) |
| 7620 | goto out_unset_queue; |
| 7621 | rc = 0; |
| 7622 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7623 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7624 | |
| 7625 | /* Next register the MRQs */ |
| 7626 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7627 | mboxq->vport = phba->pport; |
| 7628 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7629 | if (rc != MBX_SUCCESS) |
| 7630 | goto out_unset_queue; |
| 7631 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7632 | } |
| 7633 | /* Check if the port is configured to be disabled */ |
| 7634 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7635 | } |
| 7636 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7637 | /* Don't post more new bufs if repost already recovered |
| 7638 | * the nvme sgls. |
| 7639 | */ |
| 7640 | if (phba->nvmet_support == 0) { |
| 7641 | if (phba->sli4_hba.io_xri_cnt == 0) { |
| 7642 | len = lpfc_new_io_buf( |
| 7643 | phba, phba->sli4_hba.io_xri_max); |
| 7644 | if (len == 0) { |
| 7645 | rc = -ENOMEM; |
| 7646 | goto out_unset_queue; |
| 7647 | } |
| 7648 | |
| 7649 | if (phba->cfg_xri_rebalancing) |
| 7650 | lpfc_create_multixri_pools(phba); |
| 7651 | } |
| 7652 | } else { |
| 7653 | phba->cfg_xri_rebalancing = 0; |
| 7654 | } |
| 7655 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7656 | /* Arm the CQs and then EQs on device */ |
| 7657 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7658 | |
| 7659 | /* Indicate device interrupt mode */ |
| 7660 | phba->sli4_hba.intr_enable = 1; |
| 7661 | |
| 7662 | /* Allow asynchronous mailbox command to go through */ |
| 7663 | spin_lock_irq(&phba->hbalock); |
| 7664 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7665 | spin_unlock_irq(&phba->hbalock); |
| 7666 | |
| 7667 | /* Post receive buffers to the device */ |
| 7668 | lpfc_sli4_rb_setup(phba); |
| 7669 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7670 | /* Reset HBA FCF states after HBA reset */ |
| 7671 | phba->fcf.fcf_flag = 0; |
| 7672 | phba->fcf.current_rec.flag = 0; |
| 7673 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7674 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7675 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7676 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7677 | |
| 7678 | /* Start heart beat timer */ |
| 7679 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7680 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7681 | phba->hb_outstanding = 0; |
| 7682 | phba->last_completion_time = jiffies; |
| 7683 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7684 | /* start eq_delay heartbeat */ |
| 7685 | if (phba->cfg_auto_imax) |
| 7686 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 7687 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 7688 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7689 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7690 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7691 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7692 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7693 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7694 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7695 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7696 | if (!rc) { |
| 7697 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7698 | "2829 This device supports " |
| 7699 | "Advanced Error Reporting (AER)\n"); |
| 7700 | spin_lock_irq(&phba->hbalock); |
| 7701 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7702 | spin_unlock_irq(&phba->hbalock); |
| 7703 | } else { |
| 7704 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7705 | "2830 This device does not support " |
| 7706 | "Advanced Error Reporting (AER)\n"); |
| 7707 | phba->cfg_aer_support = 0; |
| 7708 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7709 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7710 | } |
| 7711 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7712 | /* |
| 7713 | * The port is ready, set the host's link state to LINK_DOWN |
| 7714 | * in preparation for link interrupts. |
| 7715 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7716 | spin_lock_irq(&phba->hbalock); |
| 7717 | phba->link_state = LPFC_LINK_DOWN; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7718 | |
| 7719 | /* Check if physical ports are trunked */ |
| 7720 | if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba)) |
| 7721 | phba->trunk_link.link0.state = LPFC_LINK_DOWN; |
| 7722 | if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba)) |
| 7723 | phba->trunk_link.link1.state = LPFC_LINK_DOWN; |
| 7724 | if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba)) |
| 7725 | phba->trunk_link.link2.state = LPFC_LINK_DOWN; |
| 7726 | if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba)) |
| 7727 | phba->trunk_link.link3.state = LPFC_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7728 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 7729 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7730 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7731 | (phba->hba_flag & LINK_DISABLED)) { |
| 7732 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7733 | "3103 Adapter Link is disabled.\n"); |
| 7734 | lpfc_down_link(phba, mboxq); |
| 7735 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7736 | if (rc != MBX_SUCCESS) { |
| 7737 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7738 | "3104 Adapter failed to issue " |
| 7739 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7740 | goto out_io_buff_free; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7741 | } |
| 7742 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7743 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7744 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7745 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7746 | if (rc) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7747 | goto out_io_buff_free; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7748 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7749 | } |
| 7750 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7751 | return rc; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 7752 | out_io_buff_free: |
| 7753 | /* Free allocated IO Buffers */ |
| 7754 | lpfc_io_free(phba); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7755 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7756 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7757 | lpfc_sli4_queue_unset(phba); |
| 7758 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7759 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7760 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7761 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7762 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7763 | out_free_mbox: |
| 7764 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7765 | return rc; |
| 7766 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7767 | |
| 7768 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7769 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7770 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7771 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7772 | * This is the callback function for mailbox timer. The mailbox |
| 7773 | * timer is armed when a new mailbox command is issued and the timer |
| 7774 | * is deleted when the mailbox complete. The function is called by |
| 7775 | * the kernel timer code when a mailbox does not complete within |
| 7776 | * expected time. This function wakes up the worker thread to |
| 7777 | * process the mailbox timeout and returns. All the processing is |
| 7778 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 7779 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7780 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7781 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7782 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7783 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7784 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7785 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7786 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7787 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7788 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7789 | if (!tmo_posted) |
| 7790 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 7791 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 7792 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7793 | if (!tmo_posted) |
| 7794 | lpfc_worker_wake_up(phba); |
| 7795 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7796 | } |
| 7797 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7798 | /** |
| 7799 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 7800 | * are pending |
| 7801 | * @phba: Pointer to HBA context object. |
| 7802 | * |
| 7803 | * This function checks if any mailbox completions are present on the mailbox |
| 7804 | * completion queue. |
| 7805 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 7806 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7807 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 7808 | { |
| 7809 | |
| 7810 | uint32_t idx; |
| 7811 | struct lpfc_queue *mcq; |
| 7812 | struct lpfc_mcqe *mcqe; |
| 7813 | bool pending_completions = false; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7814 | uint8_t qe_valid; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7815 | |
| 7816 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7817 | return false; |
| 7818 | |
| 7819 | /* Check for completions on mailbox completion queue */ |
| 7820 | |
| 7821 | mcq = phba->sli4_hba.mbx_cq; |
| 7822 | idx = mcq->hba_index; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7823 | qe_valid = mcq->qe_valid; |
| 7824 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe) == qe_valid) { |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7825 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 7826 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 7827 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 7828 | pending_completions = true; |
| 7829 | break; |
| 7830 | } |
| 7831 | idx = (idx + 1) % mcq->entry_count; |
| 7832 | if (mcq->hba_index == idx) |
| 7833 | break; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7834 | |
| 7835 | /* if the index wrapped around, toggle the valid bit */ |
| 7836 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) |
| 7837 | qe_valid = (qe_valid) ? 0 : 1; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7838 | } |
| 7839 | return pending_completions; |
| 7840 | |
| 7841 | } |
| 7842 | |
| 7843 | /** |
| 7844 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 7845 | * that were missed. |
| 7846 | * @phba: Pointer to HBA context object. |
| 7847 | * |
| 7848 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 7849 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 7850 | * checks to see if mbox completions are on the mailbox completion queue |
| 7851 | * and will process all the completions associated with the eq for the |
| 7852 | * mailbox completion queue. |
| 7853 | **/ |
| 7854 | bool |
| 7855 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 7856 | { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7857 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7858 | uint32_t eqidx; |
| 7859 | struct lpfc_queue *fpeq = NULL; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7860 | bool mbox_pending; |
| 7861 | |
| 7862 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7863 | return false; |
| 7864 | |
| 7865 | /* Find the eq associated with the mcq */ |
| 7866 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 7867 | if (sli4_hba->hdwq) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 7868 | for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 7869 | if (sli4_hba->hdwq[eqidx].hba_eq->queue_id == |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7870 | sli4_hba->mbx_cq->assoc_qid) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 7871 | fpeq = sli4_hba->hdwq[eqidx].hba_eq; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7872 | break; |
| 7873 | } |
| 7874 | if (!fpeq) |
| 7875 | return false; |
| 7876 | |
| 7877 | /* Turn off interrupts from this EQ */ |
| 7878 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7879 | sli4_hba->sli4_eq_clr_intr(fpeq); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7880 | |
| 7881 | /* Check to see if a mbox completion is pending */ |
| 7882 | |
| 7883 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 7884 | |
| 7885 | /* |
| 7886 | * If a mbox completion is pending, process all the events on EQ |
| 7887 | * associated with the mbox completion queue (this could include |
| 7888 | * mailbox commands, async events, els commands, receive queue data |
| 7889 | * and fcp commands) |
| 7890 | */ |
| 7891 | |
| 7892 | if (mbox_pending) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7893 | /* process and rearm the EQ */ |
| 7894 | lpfc_sli4_process_eq(phba, fpeq); |
| 7895 | else |
| 7896 | /* Always clear and re-arm the EQ */ |
| 7897 | sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7898 | |
| 7899 | return mbox_pending; |
| 7900 | |
| 7901 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7902 | |
| 7903 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7904 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7905 | * @phba: Pointer to HBA context object. |
| 7906 | * |
| 7907 | * This function is called from worker thread when a mailbox command times out. |
| 7908 | * The caller is not required to hold any locks. This function will reset the |
| 7909 | * HBA and recover all the pending commands. |
| 7910 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7911 | void |
| 7912 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 7913 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7914 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7915 | MAILBOX_t *mb = NULL; |
| 7916 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7917 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7918 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7919 | /* If the mailbox completed, process the completion and return */ |
| 7920 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 7921 | return; |
| 7922 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7923 | if (pmbox != NULL) |
| 7924 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7925 | /* Check the pmbox pointer first. There is a race condition |
| 7926 | * between the mbox timeout handler getting executed in the |
| 7927 | * worklist and the mailbox actually completing. When this |
| 7928 | * race condition occurs, the mbox_active will be NULL. |
| 7929 | */ |
| 7930 | spin_lock_irq(&phba->hbalock); |
| 7931 | if (pmbox == NULL) { |
| 7932 | lpfc_printf_log(phba, KERN_WARNING, |
| 7933 | LOG_MBOX | LOG_SLI, |
| 7934 | "0353 Active Mailbox cleared - mailbox timeout " |
| 7935 | "exiting\n"); |
| 7936 | spin_unlock_irq(&phba->hbalock); |
| 7937 | return; |
| 7938 | } |
| 7939 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7940 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7941 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7942 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7943 | mb->mbxCommand, |
| 7944 | phba->pport->port_state, |
| 7945 | phba->sli.sli_flag, |
| 7946 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7947 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7948 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7949 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 7950 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7951 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7952 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7953 | spin_lock_irq(&phba->pport->work_port_lock); |
| 7954 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 7955 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 7956 | spin_lock_irq(&phba->hbalock); |
| 7957 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 7958 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7959 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7960 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 7961 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7962 | |
| 7963 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 7964 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7965 | |
| 7966 | /* Reset the HBA device */ |
| 7967 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7968 | } |
| 7969 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7970 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7971 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7972 | * @phba: Pointer to HBA context object. |
| 7973 | * @pmbox: Pointer to mailbox object. |
| 7974 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7975 | * |
| 7976 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7977 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 7978 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7979 | * The mailbox command can be submitted in polling mode, in which case |
| 7980 | * this function will wait in a polling loop for the completion of the |
| 7981 | * mailbox. |
| 7982 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 7983 | * function will submit the command and returns immediately without waiting |
| 7984 | * for the mailbox completion. The no_wait is supported only when HBA |
| 7985 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 7986 | * The SLI interface allows only one mailbox pending at a time. If the |
| 7987 | * mailbox is issued in polling mode and there is already a mailbox |
| 7988 | * pending, then the function will return an error. If the mailbox is issued |
| 7989 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 7990 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 7991 | * The sli layer owns the mailbox object until the completion of mailbox |
| 7992 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 7993 | * return codes the caller owns the mailbox command after the return of |
| 7994 | * the function. |
| 7995 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7996 | static int |
| 7997 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 7998 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7999 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8000 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8001 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8002 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8003 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8004 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8005 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8006 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8007 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8008 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8009 | int processing_queue = 0; |
| 8010 | |
| 8011 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8012 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 8013 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8014 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8015 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8016 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8017 | return MBX_SUCCESS; |
| 8018 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8019 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8020 | pmbox = lpfc_mbox_get(phba); |
| 8021 | if (!pmbox) { |
| 8022 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8023 | return MBX_SUCCESS; |
| 8024 | } |
| 8025 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8026 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8027 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8028 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8029 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8030 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8031 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8032 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8033 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8034 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8035 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8036 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8037 | } |
| 8038 | } |
| 8039 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8040 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8041 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 8042 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8043 | goto out_not_finished; |
| 8044 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8045 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8046 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8047 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 8048 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8049 | goto out_not_finished; |
| 8050 | } |
| 8051 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8052 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8053 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8054 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8055 | status = MBX_SUCCESS; |
| 8056 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8057 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 8058 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8059 | |
| 8060 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8061 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8062 | "(%d):0311 Mailbox command x%x cannot " |
| 8063 | "issue Data: x%x x%x\n", |
| 8064 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8065 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8066 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8067 | } |
| 8068 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8069 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8070 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 8071 | !(hc_copy & HC_MBINT_ENA)) { |
| 8072 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8073 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8074 | "(%d):2528 Mailbox command x%x cannot " |
| 8075 | "issue Data: x%x x%x\n", |
| 8076 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8077 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8078 | goto out_not_finished; |
| 8079 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 8080 | } |
| 8081 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8082 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8083 | /* Polling for a mbox command when another one is already active |
| 8084 | * is not allowed in SLI. Also, the driver must have established |
| 8085 | * SLI2 mode to queue and process multiple mbox commands. |
| 8086 | */ |
| 8087 | |
| 8088 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8089 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8090 | |
| 8091 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8092 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8093 | "(%d):2529 Mailbox command x%x " |
| 8094 | "cannot issue Data: x%x x%x\n", |
| 8095 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8096 | pmbox->u.mb.mbxCommand, |
| 8097 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8098 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8099 | } |
| 8100 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8101 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8102 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8103 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8104 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8105 | "(%d):2530 Mailbox command x%x " |
| 8106 | "cannot issue Data: x%x x%x\n", |
| 8107 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8108 | pmbox->u.mb.mbxCommand, |
| 8109 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8110 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8111 | } |
| 8112 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8113 | /* Another mailbox command is still being processed, queue this |
| 8114 | * command to be processed later. |
| 8115 | */ |
| 8116 | lpfc_mbox_put(phba, pmbox); |
| 8117 | |
| 8118 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8119 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8120 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8121 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8122 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8123 | mbx->mbxCommand, |
| 8124 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8125 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8126 | |
| 8127 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8128 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8129 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8130 | if (pmbox->vport) { |
| 8131 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8132 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8133 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8134 | (uint32_t)mbx->mbxCommand, |
| 8135 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8136 | } |
| 8137 | else { |
| 8138 | lpfc_debugfs_disc_trc(phba->pport, |
| 8139 | LPFC_DISC_TRC_MBOX, |
| 8140 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8141 | (uint32_t)mbx->mbxCommand, |
| 8142 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8143 | } |
| 8144 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8145 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8146 | } |
| 8147 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8148 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8149 | |
| 8150 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 8151 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8152 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8153 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8154 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8155 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8156 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8157 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8158 | "(%d):2531 Mailbox command x%x " |
| 8159 | "cannot issue Data: x%x x%x\n", |
| 8160 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 8161 | pmbox->u.mb.mbxCommand, |
| 8162 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8163 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8164 | } |
| 8165 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8166 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8167 | 1000); |
| 8168 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8169 | } |
| 8170 | |
| 8171 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 8172 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8173 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8174 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8175 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 8176 | mbx->mbxCommand, |
| 8177 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8178 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8179 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8180 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8181 | if (pmbox->vport) { |
| 8182 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 8183 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8184 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8185 | (uint32_t)mbx->mbxCommand, |
| 8186 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8187 | } |
| 8188 | else { |
| 8189 | lpfc_debugfs_disc_trc(phba->pport, |
| 8190 | LPFC_DISC_TRC_MBOX, |
| 8191 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8192 | (uint32_t)mbx->mbxCommand, |
| 8193 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8194 | } |
| 8195 | } |
| 8196 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8197 | psli->slistat.mbox_cmd++; |
| 8198 | evtctr = psli->slistat.mbox_event; |
| 8199 | |
| 8200 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8201 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8202 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8203 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8204 | /* Populate mbox extension offset word. */ |
| 8205 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8206 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8207 | = (uint8_t *)phba->mbox_ext |
| 8208 | - (uint8_t *)phba->mbox; |
| 8209 | } |
| 8210 | |
| 8211 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8212 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) { |
| 8213 | lpfc_sli_pcimem_bcopy(pmbox->ctx_buf, |
| 8214 | (uint8_t *)phba->mbox_ext, |
| 8215 | pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8216 | } |
| 8217 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8218 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8219 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8220 | /* Populate mbox extension offset word. */ |
| 8221 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8222 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8223 | = MAILBOX_HBA_EXT_OFFSET; |
| 8224 | |
| 8225 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8226 | if (pmbox->in_ext_byte_len && pmbox->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8227 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 8228 | MAILBOX_HBA_EXT_OFFSET, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8229 | pmbox->ctx_buf, pmbox->in_ext_byte_len); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8230 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8231 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8232 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8233 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 8234 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8235 | |
| 8236 | /* First copy mbox command data to HBA SLIM, skip past first |
| 8237 | word */ |
| 8238 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8239 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8240 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 8241 | |
| 8242 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8243 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8244 | to_slim = phba->MBslimaddr; |
| 8245 | writel(ldata, to_slim); |
| 8246 | readl(to_slim); /* flush */ |
| 8247 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8248 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8249 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8250 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8251 | } |
| 8252 | |
| 8253 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8254 | |
| 8255 | switch (flag) { |
| 8256 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8257 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8258 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8259 | /* Interrupt board to do it */ |
| 8260 | writel(CA_MBATT, phba->CAregaddr); |
| 8261 | readl(phba->CAregaddr); /* flush */ |
| 8262 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8263 | break; |
| 8264 | |
| 8265 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8266 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8267 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8268 | /* Interrupt board to do it */ |
| 8269 | writel(CA_MBATT, phba->CAregaddr); |
| 8270 | readl(phba->CAregaddr); /* flush */ |
| 8271 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8272 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8273 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8274 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8275 | word0 = le32_to_cpu(word0); |
| 8276 | } else { |
| 8277 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8278 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 8279 | spin_unlock_irqrestore(&phba->hbalock, |
| 8280 | drvr_flag); |
| 8281 | goto out_not_finished; |
| 8282 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8283 | } |
| 8284 | |
| 8285 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8286 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8287 | spin_unlock_irqrestore(&phba->hbalock, |
| 8288 | drvr_flag); |
| 8289 | goto out_not_finished; |
| 8290 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8291 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 8292 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8293 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8294 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 8295 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 8296 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8297 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8298 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8299 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8300 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8301 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8302 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8303 | } |
| 8304 | |
| 8305 | /* Check if we took a mbox interrupt while we were |
| 8306 | polling */ |
| 8307 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 8308 | && (evtctr != psli->slistat.mbox_event)) |
| 8309 | break; |
| 8310 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 8311 | if (i++ > 10) { |
| 8312 | spin_unlock_irqrestore(&phba->hbalock, |
| 8313 | drvr_flag); |
| 8314 | msleep(1); |
| 8315 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 8316 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8317 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8318 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8319 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8320 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8321 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8322 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8323 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8324 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8325 | /* Check real SLIM for any errors */ |
| 8326 | slimword0 = readl(phba->MBslimaddr); |
| 8327 | slimmb = (MAILBOX_t *) & slimword0; |
| 8328 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 8329 | && slimmb->mbxStatus) { |
| 8330 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8331 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8332 | word0 = slimword0; |
| 8333 | } |
| 8334 | } |
| 8335 | } else { |
| 8336 | /* First copy command data */ |
| 8337 | word0 = readl(phba->MBslimaddr); |
| 8338 | } |
| 8339 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8340 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 8341 | spin_unlock_irqrestore(&phba->hbalock, |
| 8342 | drvr_flag); |
| 8343 | goto out_not_finished; |
| 8344 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8345 | } |
| 8346 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8347 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8348 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8349 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 8350 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8351 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8352 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8353 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8354 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8355 | pmbox->out_ext_byte_len); |
| 8356 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8357 | } else { |
| 8358 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8359 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8360 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8361 | /* Copy the mailbox extension data */ |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 8362 | if (pmbox->out_ext_byte_len && pmbox->ctx_buf) { |
| 8363 | lpfc_memcpy_from_slim( |
| 8364 | pmbox->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8365 | phba->MBslimaddr + |
| 8366 | MAILBOX_HBA_EXT_OFFSET, |
| 8367 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8368 | } |
| 8369 | } |
| 8370 | |
| 8371 | writel(HA_MBATT, phba->HAregaddr); |
| 8372 | readl(phba->HAregaddr); /* flush */ |
| 8373 | |
| 8374 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8375 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8376 | } |
| 8377 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8378 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8379 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8380 | |
| 8381 | out_not_finished: |
| 8382 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8383 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8384 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 8385 | } |
| 8386 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8387 | } |
| 8388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8389 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8390 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 8391 | * @phba: Pointer to HBA context object. |
| 8392 | * |
| 8393 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 8394 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 8395 | * possible outstanding mailbox command before return. |
| 8396 | * |
| 8397 | * Returns: |
| 8398 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 8399 | * the outstanding mailbox command timed out. |
| 8400 | **/ |
| 8401 | static int |
| 8402 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 8403 | { |
| 8404 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8405 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8406 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8407 | |
| 8408 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 8409 | spin_lock_irq(&phba->hbalock); |
| 8410 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8411 | /* Determine how long we might wait for the active mailbox |
| 8412 | * command to be gracefully completed by firmware. |
| 8413 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8414 | if (phba->sli.mbox_active) |
| 8415 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 8416 | phba->sli.mbox_active) * |
| 8417 | 1000) + jiffies; |
| 8418 | spin_unlock_irq(&phba->hbalock); |
| 8419 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8420 | /* Make sure the mailbox is really active */ |
| 8421 | if (timeout) |
| 8422 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8423 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8424 | /* Wait for the outstnading mailbox command to complete */ |
| 8425 | while (phba->sli.mbox_active) { |
| 8426 | /* Check active mailbox complete status every 2ms */ |
| 8427 | msleep(2); |
| 8428 | if (time_after(jiffies, timeout)) { |
| 8429 | /* Timeout, marked the outstanding cmd not complete */ |
| 8430 | rc = 1; |
| 8431 | break; |
| 8432 | } |
| 8433 | } |
| 8434 | |
| 8435 | /* Can not cleanly block async mailbox command, fails it */ |
| 8436 | if (rc) { |
| 8437 | spin_lock_irq(&phba->hbalock); |
| 8438 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8439 | spin_unlock_irq(&phba->hbalock); |
| 8440 | } |
| 8441 | return rc; |
| 8442 | } |
| 8443 | |
| 8444 | /** |
| 8445 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 8446 | * @phba: Pointer to HBA context object. |
| 8447 | * |
| 8448 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 8449 | * commands from the driver internal pending mailbox queue. It makes sure |
| 8450 | * that there is no outstanding mailbox command before resuming posting |
| 8451 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 8452 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 8453 | * mailbox command posting. |
| 8454 | **/ |
| 8455 | static void |
| 8456 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 8457 | { |
| 8458 | struct lpfc_sli *psli = &phba->sli; |
| 8459 | |
| 8460 | spin_lock_irq(&phba->hbalock); |
| 8461 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8462 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 8463 | spin_unlock_irq(&phba->hbalock); |
| 8464 | return; |
| 8465 | } |
| 8466 | |
| 8467 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 8468 | * successful or timeout, after timing-out the outstanding mailbox |
| 8469 | * command shall always be removed, so just unblock posting async |
| 8470 | * mailbox command and resume |
| 8471 | */ |
| 8472 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8473 | spin_unlock_irq(&phba->hbalock); |
| 8474 | |
| 8475 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 8476 | lpfc_worker_wake_up(phba); |
| 8477 | } |
| 8478 | |
| 8479 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8480 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 8481 | * @phba: Pointer to HBA context object. |
| 8482 | * @mboxq: Pointer to mailbox object. |
| 8483 | * |
| 8484 | * The function waits for the bootstrap mailbox register ready bit from |
| 8485 | * port for twice the regular mailbox command timeout value. |
| 8486 | * |
| 8487 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 8488 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 8489 | **/ |
| 8490 | static int |
| 8491 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8492 | { |
| 8493 | uint32_t db_ready; |
| 8494 | unsigned long timeout; |
| 8495 | struct lpfc_register bmbx_reg; |
| 8496 | |
| 8497 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 8498 | * 1000) + jiffies; |
| 8499 | |
| 8500 | do { |
| 8501 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 8502 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 8503 | if (!db_ready) |
| 8504 | msleep(2); |
| 8505 | |
| 8506 | if (time_after(jiffies, timeout)) |
| 8507 | return MBXERR_ERROR; |
| 8508 | } while (!db_ready); |
| 8509 | |
| 8510 | return 0; |
| 8511 | } |
| 8512 | |
| 8513 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8514 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 8515 | * @phba: Pointer to HBA context object. |
| 8516 | * @mboxq: Pointer to mailbox object. |
| 8517 | * |
| 8518 | * The function posts a mailbox to the port. The mailbox is expected |
| 8519 | * to be comletely filled in and ready for the port to operate on it. |
| 8520 | * This routine executes a synchronous completion operation on the |
| 8521 | * mailbox by polling for its completion. |
| 8522 | * |
| 8523 | * The caller must not be holding any locks when calling this routine. |
| 8524 | * |
| 8525 | * Returns: |
| 8526 | * MBX_SUCCESS - mailbox posted successfully |
| 8527 | * Any of the MBX error values. |
| 8528 | **/ |
| 8529 | static int |
| 8530 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8531 | { |
| 8532 | int rc = MBX_SUCCESS; |
| 8533 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8534 | uint32_t mcqe_status; |
| 8535 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8536 | struct lpfc_sli *psli = &phba->sli; |
| 8537 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 8538 | struct lpfc_bmbx_create *mbox_rgn; |
| 8539 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8540 | |
| 8541 | /* |
| 8542 | * Only one mailbox can be active to the bootstrap mailbox region |
| 8543 | * at a time and there is no queueing provided. |
| 8544 | */ |
| 8545 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8546 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8547 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8548 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8549 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8550 | "cannot issue Data: x%x x%x\n", |
| 8551 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8552 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8553 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8554 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8555 | psli->sli_flag, MBX_POLL); |
| 8556 | return MBXERR_ERROR; |
| 8557 | } |
| 8558 | /* The server grabs the token and owns it until release */ |
| 8559 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8560 | phba->sli.mbox_active = mboxq; |
| 8561 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8562 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8563 | /* wait for bootstrap mbox register for readyness */ |
| 8564 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8565 | if (rc) |
| 8566 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8567 | /* |
| 8568 | * Initialize the bootstrap memory region to avoid stale data areas |
| 8569 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 8570 | * the bmbx mailbox region. |
| 8571 | */ |
| 8572 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 8573 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8574 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 8575 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8576 | |
| 8577 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 8578 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8579 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 8580 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8581 | /* wait for bootstrap mbox register for hi-address write done */ |
| 8582 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8583 | if (rc) |
| 8584 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8585 | |
| 8586 | /* Post the low mailbox dma address to the port. */ |
| 8587 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8588 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8589 | /* wait for bootstrap mbox register for low address write done */ |
| 8590 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8591 | if (rc) |
| 8592 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8593 | |
| 8594 | /* |
| 8595 | * Read the CQ to ensure the mailbox has completed. |
| 8596 | * If so, update the mailbox status so that the upper layers |
| 8597 | * can complete the request normally. |
| 8598 | */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8599 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 8600 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8601 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8602 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 8603 | sizeof(struct lpfc_mcqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8604 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8605 | /* |
| 8606 | * When the CQE status indicates a failure and the mailbox status |
| 8607 | * indicates success then copy the CQE status into the mailbox status |
| 8608 | * (and prefix it with x4000). |
| 8609 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8610 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8611 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8612 | bf_set(lpfc_mqe_status, mb, |
| 8613 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8614 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8615 | } else |
| 8616 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8617 | |
| 8618 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8619 | "(%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] | 8620 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8621 | " 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] | 8622 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8623 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8624 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8625 | bf_get(lpfc_mqe_status, mb), |
| 8626 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8627 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8628 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8629 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8630 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8631 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8632 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8633 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8634 | mboxq->mcqe.trailer); |
| 8635 | exit: |
| 8636 | /* We are holding the token, no needed for lock when release */ |
| 8637 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8638 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8639 | phba->sli.mbox_active = NULL; |
| 8640 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8641 | return rc; |
| 8642 | } |
| 8643 | |
| 8644 | /** |
| 8645 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8646 | * @phba: Pointer to HBA context object. |
| 8647 | * @pmbox: Pointer to mailbox object. |
| 8648 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8649 | * |
| 8650 | * This function is called by discovery code and HBA management code to submit |
| 8651 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8652 | * |
| 8653 | * Return codes the caller owns the mailbox command after the return of the |
| 8654 | * function. |
| 8655 | **/ |
| 8656 | static int |
| 8657 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8658 | uint32_t flag) |
| 8659 | { |
| 8660 | struct lpfc_sli *psli = &phba->sli; |
| 8661 | unsigned long iflags; |
| 8662 | int rc; |
| 8663 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8664 | /* dump from issue mailbox command if setup */ |
| 8665 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8666 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8667 | rc = lpfc_mbox_dev_check(phba); |
| 8668 | if (unlikely(rc)) { |
| 8669 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8670 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8671 | "cannot issue Data: x%x x%x\n", |
| 8672 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8673 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8674 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8675 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8676 | psli->sli_flag, flag); |
| 8677 | goto out_not_finished; |
| 8678 | } |
| 8679 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8680 | /* Detect polling mode and jump to a handler */ |
| 8681 | if (!phba->sli4_hba.intr_enable) { |
| 8682 | if (flag == MBX_POLL) |
| 8683 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8684 | else |
| 8685 | rc = -EIO; |
| 8686 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8687 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8688 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8689 | "(x%x/x%x) failure: " |
| 8690 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8691 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8692 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8693 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8694 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8695 | mboxq), |
| 8696 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8697 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8698 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8699 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8700 | bf_get(lpfc_mcqe_ext_status, |
| 8701 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8702 | psli->sli_flag, flag); |
| 8703 | return rc; |
| 8704 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8705 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8706 | "(%d):2542 Try to issue mailbox command " |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8707 | "x%x (x%x/x%x) synchronously ahead of async " |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8708 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8709 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8710 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8711 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8712 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8713 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8714 | /* Try to block the asynchronous mailbox posting */ |
| 8715 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8716 | if (!rc) { |
| 8717 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8718 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8719 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8720 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8721 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8722 | "(%d):2597 Sync Mailbox command " |
| 8723 | "x%x (x%x/x%x) failure: " |
| 8724 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8725 | "Data: x%x x%x\n,", |
| 8726 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8727 | mboxq->u.mb.mbxCommand, |
| 8728 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8729 | mboxq), |
| 8730 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8731 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8732 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8733 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8734 | bf_get(lpfc_mcqe_ext_status, |
| 8735 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8736 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8737 | /* Unblock the async mailbox posting afterward */ |
| 8738 | lpfc_sli4_async_mbox_unblock(phba); |
| 8739 | } |
| 8740 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8741 | } |
| 8742 | |
| 8743 | /* Now, interrupt mode asynchrous mailbox command */ |
| 8744 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8745 | if (rc) { |
| 8746 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8747 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8748 | "cannot issue Data: x%x x%x\n", |
| 8749 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8750 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8751 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8752 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8753 | psli->sli_flag, flag); |
| 8754 | goto out_not_finished; |
| 8755 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8756 | |
| 8757 | /* Put the mailbox command to the driver internal FIFO */ |
| 8758 | psli->slistat.mbox_busy++; |
| 8759 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8760 | lpfc_mbox_put(phba, mboxq); |
| 8761 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8762 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8763 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8764 | "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] | 8765 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 8766 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8767 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8768 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8769 | phba->pport->port_state, |
| 8770 | psli->sli_flag, MBX_NOWAIT); |
| 8771 | /* Wake up worker thread to transport mailbox command from head */ |
| 8772 | lpfc_worker_wake_up(phba); |
| 8773 | |
| 8774 | return MBX_BUSY; |
| 8775 | |
| 8776 | out_not_finished: |
| 8777 | return MBX_NOT_FINISHED; |
| 8778 | } |
| 8779 | |
| 8780 | /** |
| 8781 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 8782 | * @phba: Pointer to HBA context object. |
| 8783 | * |
| 8784 | * This function is called by worker thread to send a mailbox command to |
| 8785 | * SLI4 HBA firmware. |
| 8786 | * |
| 8787 | **/ |
| 8788 | int |
| 8789 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 8790 | { |
| 8791 | struct lpfc_sli *psli = &phba->sli; |
| 8792 | LPFC_MBOXQ_t *mboxq; |
| 8793 | int rc = MBX_SUCCESS; |
| 8794 | unsigned long iflags; |
| 8795 | struct lpfc_mqe *mqe; |
| 8796 | uint32_t mbx_cmnd; |
| 8797 | |
| 8798 | /* Check interrupt mode before post async mailbox command */ |
| 8799 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 8800 | return MBX_NOT_FINISHED; |
| 8801 | |
| 8802 | /* Check for mailbox command service token */ |
| 8803 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8804 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8805 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8806 | return MBX_NOT_FINISHED; |
| 8807 | } |
| 8808 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8809 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8810 | return MBX_NOT_FINISHED; |
| 8811 | } |
| 8812 | if (unlikely(phba->sli.mbox_active)) { |
| 8813 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8814 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8815 | "0384 There is pending active mailbox cmd\n"); |
| 8816 | return MBX_NOT_FINISHED; |
| 8817 | } |
| 8818 | /* Take the mailbox command service token */ |
| 8819 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8820 | |
| 8821 | /* Get the next mailbox command from head of queue */ |
| 8822 | mboxq = lpfc_mbox_get(phba); |
| 8823 | |
| 8824 | /* If no more mailbox command waiting for post, we're done */ |
| 8825 | if (!mboxq) { |
| 8826 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8827 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8828 | return MBX_SUCCESS; |
| 8829 | } |
| 8830 | phba->sli.mbox_active = mboxq; |
| 8831 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8832 | |
| 8833 | /* Check device readiness for posting mailbox command */ |
| 8834 | rc = lpfc_mbox_dev_check(phba); |
| 8835 | if (unlikely(rc)) |
| 8836 | /* Driver clean routine will clean up pending mailbox */ |
| 8837 | goto out_not_finished; |
| 8838 | |
| 8839 | /* Prepare the mbox command to be posted */ |
| 8840 | mqe = &mboxq->u.mqe; |
| 8841 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 8842 | |
| 8843 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 8844 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8845 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8846 | |
| 8847 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8848 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8849 | "x%x x%x\n", |
| 8850 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8851 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8852 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8853 | phba->pport->port_state, psli->sli_flag); |
| 8854 | |
| 8855 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 8856 | if (mboxq->vport) { |
| 8857 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 8858 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8859 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 8860 | mbx_cmnd, mqe->un.mb_words[0], |
| 8861 | mqe->un.mb_words[1]); |
| 8862 | } else { |
| 8863 | lpfc_debugfs_disc_trc(phba->pport, |
| 8864 | LPFC_DISC_TRC_MBOX, |
| 8865 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 8866 | mbx_cmnd, mqe->un.mb_words[0], |
| 8867 | mqe->un.mb_words[1]); |
| 8868 | } |
| 8869 | } |
| 8870 | psli->slistat.mbox_cmd++; |
| 8871 | |
| 8872 | /* Post the mailbox command to the port */ |
| 8873 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 8874 | if (rc != MBX_SUCCESS) { |
| 8875 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8876 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8877 | "cannot issue Data: x%x x%x\n", |
| 8878 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8879 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8880 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8881 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8882 | psli->sli_flag, MBX_NOWAIT); |
| 8883 | goto out_not_finished; |
| 8884 | } |
| 8885 | |
| 8886 | return rc; |
| 8887 | |
| 8888 | out_not_finished: |
| 8889 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 8890 | if (phba->sli.mbox_active) { |
| 8891 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8892 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8893 | /* Release the token */ |
| 8894 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8895 | phba->sli.mbox_active = NULL; |
| 8896 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8897 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8898 | |
| 8899 | return MBX_NOT_FINISHED; |
| 8900 | } |
| 8901 | |
| 8902 | /** |
| 8903 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 8904 | * @phba: Pointer to HBA context object. |
| 8905 | * @pmbox: Pointer to mailbox object. |
| 8906 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8907 | * |
| 8908 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 8909 | * the API jump table function pointer from the lpfc_hba struct. |
| 8910 | * |
| 8911 | * Return codes the caller owns the mailbox command after the return of the |
| 8912 | * function. |
| 8913 | **/ |
| 8914 | int |
| 8915 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 8916 | { |
| 8917 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 8918 | } |
| 8919 | |
| 8920 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8921 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8922 | * @phba: The hba struct for which this call is being executed. |
| 8923 | * @dev_grp: The HBA PCI-Device group number. |
| 8924 | * |
| 8925 | * This routine sets up the mbox interface API function jump table in @phba |
| 8926 | * struct. |
| 8927 | * Returns: 0 - success, -ENODEV - failure. |
| 8928 | **/ |
| 8929 | int |
| 8930 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8931 | { |
| 8932 | |
| 8933 | switch (dev_grp) { |
| 8934 | case LPFC_PCI_DEV_LP: |
| 8935 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 8936 | phba->lpfc_sli_handle_slow_ring_event = |
| 8937 | lpfc_sli_handle_slow_ring_event_s3; |
| 8938 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 8939 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 8940 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 8941 | break; |
| 8942 | case LPFC_PCI_DEV_OC: |
| 8943 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 8944 | phba->lpfc_sli_handle_slow_ring_event = |
| 8945 | lpfc_sli_handle_slow_ring_event_s4; |
| 8946 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 8947 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 8948 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 8949 | break; |
| 8950 | default: |
| 8951 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8952 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 8953 | dev_grp); |
| 8954 | return -ENODEV; |
| 8955 | break; |
| 8956 | } |
| 8957 | return 0; |
| 8958 | } |
| 8959 | |
| 8960 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8961 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8962 | * @phba: Pointer to HBA context object. |
| 8963 | * @pring: Pointer to driver SLI ring object. |
| 8964 | * @piocb: Pointer to address of newly added command iocb. |
| 8965 | * |
| 8966 | * This function is called with hbalock held to add a command |
| 8967 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 8968 | * to the ring. |
| 8969 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8970 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8971 | __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] | 8972 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8973 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8974 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8975 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 8976 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8977 | } |
| 8978 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8979 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8980 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8981 | * @phba: Pointer to HBA context object. |
| 8982 | * @pring: Pointer to driver SLI ring object. |
| 8983 | * @piocb: Pointer to address of newly added command iocb. |
| 8984 | * |
| 8985 | * This function is called with hbalock held before a new |
| 8986 | * iocb is submitted to the firmware. This function checks |
| 8987 | * txq to flush the iocbs in txq to Firmware before |
| 8988 | * submitting new iocbs to the Firmware. |
| 8989 | * If there are iocbs in the txq which need to be submitted |
| 8990 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 8991 | * of the txq after dequeuing it from txq. |
| 8992 | * If there is no iocb in the txq then the function will return |
| 8993 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 8994 | * *piocb to find if there are more commands in the txq. |
| 8995 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8996 | static struct lpfc_iocbq * |
| 8997 | 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] | 8998 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8999 | { |
| 9000 | struct lpfc_iocbq * nextiocb; |
| 9001 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9002 | lockdep_assert_held(&phba->hbalock); |
| 9003 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9004 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 9005 | if (!nextiocb) { |
| 9006 | nextiocb = *piocb; |
| 9007 | *piocb = NULL; |
| 9008 | } |
| 9009 | |
| 9010 | return nextiocb; |
| 9011 | } |
| 9012 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9013 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9014 | * __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] | 9015 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9016 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9017 | * @piocb: Pointer to command iocb. |
| 9018 | * @flag: Flag indicating if this command can be put into txq. |
| 9019 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9020 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 9021 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 9022 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 9023 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 9024 | * this function allows only iocbs for posting buffers. This function finds |
| 9025 | * next available slot in the command ring and posts the command to the |
| 9026 | * available slot and writes the port attention register to request HBA start |
| 9027 | * processing new iocb. If there is no slot available in the ring and |
| 9028 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 9029 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9030 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9031 | * This function is called with hbalock held. The function will return success |
| 9032 | * after it successfully submit the iocb to firmware or after adding to the |
| 9033 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9034 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9035 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9036 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9037 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9038 | { |
| 9039 | struct lpfc_iocbq *nextiocb; |
| 9040 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9041 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9042 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9043 | lockdep_assert_held(&phba->hbalock); |
| 9044 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9045 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 9046 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 9047 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 9048 | lpfc_printf_log(phba, KERN_ERR, |
| 9049 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9050 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9051 | piocb->iocb.ulpCommand); |
| 9052 | dump_stack(); |
| 9053 | return IOCB_ERROR; |
| 9054 | } |
| 9055 | |
| 9056 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 9057 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 9058 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 9059 | return IOCB_ERROR; |
| 9060 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9061 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 9062 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 9063 | return IOCB_ERROR; |
| 9064 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9065 | /* |
| 9066 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 9067 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9068 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9069 | return IOCB_ERROR; |
| 9070 | |
| 9071 | /* |
| 9072 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9073 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9074 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 9075 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9076 | goto iocb_busy; |
| 9077 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9078 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9079 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9080 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9081 | * can be issued if the link is not up. |
| 9082 | */ |
| 9083 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9084 | case CMD_GEN_REQUEST64_CR: |
| 9085 | case CMD_GEN_REQUEST64_CX: |
| 9086 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 9087 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9088 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 9089 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 9090 | MENLO_TRANSPORT_TYPE)) |
| 9091 | |
| 9092 | goto iocb_busy; |
| 9093 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9094 | case CMD_QUE_RING_BUF_CN: |
| 9095 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9096 | /* |
| 9097 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 9098 | * completion, iocb_cmpl MUST be 0. |
| 9099 | */ |
| 9100 | if (piocb->iocb_cmpl) |
| 9101 | piocb->iocb_cmpl = NULL; |
| 9102 | /*FALLTHROUGH*/ |
| 9103 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 9104 | case CMD_CLOSE_XRI_CN: |
| 9105 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9106 | break; |
| 9107 | default: |
| 9108 | goto iocb_busy; |
| 9109 | } |
| 9110 | |
| 9111 | /* |
| 9112 | * For FCP commands, we must be in a state where we can process link |
| 9113 | * attention events. |
| 9114 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9115 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9116 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9117 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9118 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9119 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9120 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 9121 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 9122 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 9123 | |
| 9124 | if (iocb) |
| 9125 | lpfc_sli_update_ring(phba, pring); |
| 9126 | else |
| 9127 | lpfc_sli_update_full_ring(phba, pring); |
| 9128 | |
| 9129 | if (!piocb) |
| 9130 | return IOCB_SUCCESS; |
| 9131 | |
| 9132 | goto out_busy; |
| 9133 | |
| 9134 | iocb_busy: |
| 9135 | pring->stats.iocb_cmd_delay++; |
| 9136 | |
| 9137 | out_busy: |
| 9138 | |
| 9139 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9140 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9141 | return IOCB_SUCCESS; |
| 9142 | } |
| 9143 | |
| 9144 | return IOCB_BUSY; |
| 9145 | } |
| 9146 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9147 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9148 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 9149 | * @phba: Pointer to HBA context object. |
| 9150 | * @piocb: Pointer to command iocb. |
| 9151 | * @sglq: Pointer to the scatter gather queue object. |
| 9152 | * |
| 9153 | * This routine converts the bpl or bde that is in the IOCB |
| 9154 | * to a sgl list for the sli4 hardware. The physical address |
| 9155 | * of the bpl/bde is converted back to a virtual address. |
| 9156 | * If the IOCB contains a BPL then the list of BDE's is |
| 9157 | * converted to sli4_sge's. If the IOCB contains a single |
| 9158 | * BDE then it is converted to a single sli_sge. |
| 9159 | * The IOCB is still in cpu endianess so the contents of |
| 9160 | * the bpl can be used without byte swapping. |
| 9161 | * |
| 9162 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 9163 | **/ |
| 9164 | static uint16_t |
| 9165 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 9166 | struct lpfc_sglq *sglq) |
| 9167 | { |
| 9168 | uint16_t xritag = NO_XRI; |
| 9169 | struct ulp_bde64 *bpl = NULL; |
| 9170 | struct ulp_bde64 bde; |
| 9171 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9172 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9173 | IOCB_t *icmd; |
| 9174 | int numBdes = 0; |
| 9175 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9176 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 9177 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9178 | |
| 9179 | if (!piocbq || !sglq) |
| 9180 | return xritag; |
| 9181 | |
| 9182 | sgl = (struct sli4_sge *)sglq->sgl; |
| 9183 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9184 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 9185 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9186 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 9187 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 9188 | sizeof(struct ulp_bde64); |
| 9189 | /* The addrHigh and addrLow fields within the IOCB |
| 9190 | * have not been byteswapped yet so there is no |
| 9191 | * need to swap them back. |
| 9192 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9193 | if (piocbq->context3) |
| 9194 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 9195 | else |
| 9196 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9197 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9198 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9199 | if (!bpl) |
| 9200 | return xritag; |
| 9201 | |
| 9202 | for (i = 0; i < numBdes; i++) { |
| 9203 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9204 | sgl->addr_hi = bpl->addrHigh; |
| 9205 | sgl->addr_lo = bpl->addrLow; |
| 9206 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9207 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9208 | if ((i+1) == numBdes) |
| 9209 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9210 | else |
| 9211 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9212 | /* swap the size field back to the cpu so we |
| 9213 | * can assign it to the sgl. |
| 9214 | */ |
| 9215 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 9216 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9217 | /* The offsets in the sgl need to be accumulated |
| 9218 | * separately for the request and reply lists. |
| 9219 | * The request is always first, the reply follows. |
| 9220 | */ |
| 9221 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 9222 | /* add up the reply sg entries */ |
| 9223 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 9224 | inbound++; |
| 9225 | /* first inbound? reset the offset */ |
| 9226 | if (inbound == 1) |
| 9227 | offset = 0; |
| 9228 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 9229 | bf_set(lpfc_sli4_sge_type, sgl, |
| 9230 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9231 | offset += bde.tus.f.bdeSize; |
| 9232 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9233 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9234 | bpl++; |
| 9235 | sgl++; |
| 9236 | } |
| 9237 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 9238 | /* The addrHigh and addrLow fields of the BDE have not |
| 9239 | * been byteswapped yet so they need to be swapped |
| 9240 | * before putting them in the sgl. |
| 9241 | */ |
| 9242 | sgl->addr_hi = |
| 9243 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 9244 | sgl->addr_lo = |
| 9245 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9246 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9247 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 9248 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9249 | sgl->sge_len = |
| 9250 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9251 | } |
| 9252 | return sglq->sli4_xritag; |
| 9253 | } |
| 9254 | |
| 9255 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9256 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 9257 | * @phba: Pointer to HBA context object. |
| 9258 | * @piocb: Pointer to command iocb. |
| 9259 | * @wqe: Pointer to the work queue entry. |
| 9260 | * |
| 9261 | * This routine converts the iocb command to its Work Queue Entry |
| 9262 | * equivalent. The wqe pointer should not have any fields set when |
| 9263 | * this routine is called because it will memcpy over them. |
| 9264 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 9265 | * wqe. |
| 9266 | * |
| 9267 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 9268 | **/ |
| 9269 | static int |
| 9270 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9271 | union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9272 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9273 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9274 | uint8_t ct = 0; |
| 9275 | uint32_t fip; |
| 9276 | uint32_t abort_tag; |
| 9277 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 9278 | uint8_t cmnd; |
| 9279 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9280 | uint16_t abrt_iotag; |
| 9281 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9282 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9283 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9284 | int numBdes, i; |
| 9285 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9286 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9287 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9288 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9289 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 9290 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9291 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9292 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9293 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9294 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 9295 | command_type = ELS_COMMAND_FIP; |
| 9296 | else |
| 9297 | command_type = ELS_COMMAND_NON_FIP; |
| 9298 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9299 | if (phba->fcp_embed_io) |
| 9300 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9301 | /* Some of the fields are in the right position already */ |
| 9302 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9303 | if (iocbq->iocb.ulpCommand != CMD_SEND_FRAME) { |
| 9304 | /* The ct field has moved so reset */ |
| 9305 | wqe->generic.wqe_com.word7 = 0; |
| 9306 | wqe->generic.wqe_com.word10 = 0; |
| 9307 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9308 | |
| 9309 | abort_tag = (uint32_t) iocbq->iotag; |
| 9310 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9311 | /* words0-2 bpl convert bde */ |
| 9312 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9313 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9314 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9315 | bpl = (struct ulp_bde64 *) |
| 9316 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 9317 | if (!bpl) |
| 9318 | return IOCB_ERROR; |
| 9319 | |
| 9320 | /* Should already be byte swapped. */ |
| 9321 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 9322 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 9323 | /* swap the size field back to the cpu so we |
| 9324 | * can assign it to the sgl. |
| 9325 | */ |
| 9326 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9327 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 9328 | total_len = 0; |
| 9329 | for (i = 0; i < numBdes; i++) { |
| 9330 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 9331 | total_len += bde.tus.f.bdeSize; |
| 9332 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9333 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9334 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9335 | |
| 9336 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 9337 | cmnd = iocbq->iocb.ulpCommand; |
| 9338 | |
| 9339 | switch (iocbq->iocb.ulpCommand) { |
| 9340 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 9341 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 9342 | ndlp = iocbq->context_un.ndlp; |
| 9343 | else |
| 9344 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9345 | if (!iocbq->iocb.ulpLe) { |
| 9346 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9347 | "2007 Only Limited Edition cmd Format" |
| 9348 | " supported 0x%x\n", |
| 9349 | iocbq->iocb.ulpCommand); |
| 9350 | return IOCB_ERROR; |
| 9351 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9352 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9353 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9354 | /* Els_reguest64 has a TMO */ |
| 9355 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 9356 | iocbq->iocb.ulpTimeout); |
| 9357 | /* Need a VF for word 4 set the vf bit*/ |
| 9358 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 9359 | /* And a VFID for word 12 */ |
| 9360 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9361 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9362 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9363 | iocbq->iocb.ulpContext); |
| 9364 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 9365 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9366 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9367 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9368 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 9369 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9370 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9371 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9372 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9373 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9374 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9375 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9376 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9377 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 9378 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9379 | *pcmd == ELS_CMD_PLOGI)) { |
| 9380 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 9381 | bf_set(els_req64_sid, &wqe->els_req, |
| 9382 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9383 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 9384 | !(phba->fc_topology == |
| 9385 | LPFC_TOPOLOGY_LOOP)) |
| 9386 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9387 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 9388 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 9389 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 9390 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9391 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 9392 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9393 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 9394 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9395 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9396 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 9397 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9398 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 9399 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 9400 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9401 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 9402 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9403 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9404 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9405 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9406 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9407 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 9408 | iocbq->iocb.un.ulpWord[3]); |
| 9409 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9410 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9411 | /* The entire sequence is transmitted for this IOCB */ |
| 9412 | xmit_len = total_len; |
| 9413 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9414 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 9415 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9416 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9417 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 9418 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9419 | /* word4 relative_offset memcpy */ |
| 9420 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9421 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 9422 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 9423 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 9424 | LPFC_WQE_IOD_WRITE); |
| 9425 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 9426 | LPFC_WQE_LENLOC_WORD12); |
| 9427 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9428 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 9429 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9430 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9431 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9432 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 9433 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9434 | /* word4 iocb=rsvd wqe=rsvd */ |
| 9435 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 9436 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9437 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9438 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9439 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 9440 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9441 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 9442 | LPFC_WQE_LENLOC_WORD3); |
| 9443 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9444 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9445 | case CMD_FCP_IWRITE64_CR: |
| 9446 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9447 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9448 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9449 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 9450 | xmit_len + sizeof(struct fcp_rsp)); |
| 9451 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 9452 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9453 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9454 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9455 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 9456 | iocbq->iocb.ulpFCP2Rcvy); |
| 9457 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 9458 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9459 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9460 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 9461 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9462 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9463 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9464 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9465 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9466 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 9467 | if (iocbq->priority) { |
| 9468 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9469 | (iocbq->priority << 1)); |
| 9470 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9471 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9472 | (phba->cfg_XLanePriority << 1)); |
| 9473 | } |
| 9474 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9475 | /* Note, word 10 is already initialized to 0 */ |
| 9476 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9477 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9478 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9479 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
| 9480 | else |
| 9481 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 9482 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9483 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9484 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9485 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9486 | struct fcp_cmnd *fcp_cmnd; |
| 9487 | uint32_t *ptr; |
| 9488 | |
| 9489 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9490 | |
| 9491 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9492 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9493 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9494 | |
| 9495 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9496 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9497 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9498 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9499 | wqe->generic.bde.addrHigh = 0; |
| 9500 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9501 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9502 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 9503 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9504 | |
| 9505 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9506 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9507 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9508 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9509 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9510 | case CMD_FCP_IREAD64_CR: |
| 9511 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9512 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9513 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 9514 | xmit_len + sizeof(struct fcp_rsp)); |
| 9515 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 9516 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9517 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9518 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9519 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 9520 | iocbq->iocb.ulpFCP2Rcvy); |
| 9521 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9522 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9523 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 9524 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 9525 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9526 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9527 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9528 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9529 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9530 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 9531 | if (iocbq->priority) { |
| 9532 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9533 | (iocbq->priority << 1)); |
| 9534 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9535 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9536 | (phba->cfg_XLanePriority << 1)); |
| 9537 | } |
| 9538 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9539 | /* Note, word 10 is already initialized to 0 */ |
| 9540 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 9541 | /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */ |
| 9542 | if (phba->cfg_enable_pbde) |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9543 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
| 9544 | else |
| 9545 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 9546 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9547 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9548 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9549 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9550 | struct fcp_cmnd *fcp_cmnd; |
| 9551 | uint32_t *ptr; |
| 9552 | |
| 9553 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9554 | |
| 9555 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9556 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9557 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9558 | |
| 9559 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9560 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9561 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9562 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9563 | wqe->generic.bde.addrHigh = 0; |
| 9564 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9565 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9566 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 9567 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9568 | |
| 9569 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9570 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9571 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9572 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9573 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9574 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9575 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9576 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 9577 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 9578 | xmit_len + sizeof(struct fcp_rsp)); |
| 9579 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 9580 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9581 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9582 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9583 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9584 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 9585 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9586 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 9587 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 9588 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 9589 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 9590 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9591 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9592 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9593 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 9594 | if (iocbq->priority) { |
| 9595 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9596 | (iocbq->priority << 1)); |
| 9597 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9598 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9599 | (phba->cfg_XLanePriority << 1)); |
| 9600 | } |
| 9601 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9602 | /* Note, word 10 is already initialized to 0 */ |
| 9603 | |
| 9604 | if (phba->fcp_embed_io) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 9605 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9606 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9607 | struct fcp_cmnd *fcp_cmnd; |
| 9608 | uint32_t *ptr; |
| 9609 | |
| 9610 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9611 | |
| 9612 | lpfc_cmd = iocbq->context1; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 9613 | sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9614 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9615 | |
| 9616 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9617 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9618 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9619 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9620 | wqe->generic.bde.addrHigh = 0; |
| 9621 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9622 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9623 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 9624 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9625 | |
| 9626 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9627 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9628 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9629 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9630 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9631 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9632 | /* For this command calculate the xmit length of the |
| 9633 | * request bde. |
| 9634 | */ |
| 9635 | xmit_len = 0; |
| 9636 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9637 | sizeof(struct ulp_bde64); |
| 9638 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9639 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9640 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9641 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9642 | xmit_len += bde.tus.f.bdeSize; |
| 9643 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9644 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9645 | wqe->gen_req.request_payload_len = xmit_len; |
| 9646 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9647 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9648 | /* word6 context tag copied in memcpy */ |
| 9649 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9650 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9651 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9652 | "2015 Invalid CT %x command 0x%x\n", |
| 9653 | ct, iocbq->iocb.ulpCommand); |
| 9654 | return IOCB_ERROR; |
| 9655 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9656 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9657 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9658 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9659 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9660 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9661 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9662 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9663 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9664 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9665 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9666 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9667 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9668 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9669 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9670 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9671 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9672 | /* word4 */ |
| 9673 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9674 | /* word5 iocb=rsvd wge=did */ |
| 9675 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9676 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9677 | |
| 9678 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9679 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9680 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9681 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9682 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9683 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9684 | iocbq->vport->fc_myDID); |
| 9685 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9686 | bf_set(wqe_els_did, |
| 9687 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9688 | } |
| 9689 | } |
| 9690 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9691 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9692 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9693 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9694 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9695 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9696 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9697 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9698 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9699 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9700 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9701 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9702 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9703 | LPFC_WQE_LENLOC_WORD3); |
| 9704 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9705 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9706 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9707 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9708 | iocbq->context2)->virt); |
| 9709 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9710 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9711 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9712 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9713 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9714 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9715 | phba->vpi_ids[phba->pport->vpi]); |
| 9716 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9717 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9718 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9719 | case CMD_CLOSE_XRI_CN: |
| 9720 | case CMD_ABORT_XRI_CN: |
| 9721 | case CMD_ABORT_XRI_CX: |
| 9722 | /* words 0-2 memcpy should be 0 rserved */ |
| 9723 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9724 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9725 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9726 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9727 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9728 | } else |
| 9729 | fip = 0; |
| 9730 | |
| 9731 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9732 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9733 | * The link is down, or the command was ELS_FIP |
| 9734 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9735 | * on the wire. |
| 9736 | */ |
| 9737 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9738 | else |
| 9739 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9740 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9741 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9742 | wqe->abort_cmd.rsrvd5 = 0; |
| 9743 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9744 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9745 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9746 | /* |
| 9747 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9748 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9749 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9750 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 9751 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 9752 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 9753 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9754 | cmnd = CMD_ABORT_XRI_CX; |
| 9755 | command_type = OTHER_COMMAND; |
| 9756 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9757 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9758 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9759 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9760 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9761 | * we re-construct this WQE here based on information in |
| 9762 | * iocbq from scratch. |
| 9763 | */ |
| 9764 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9765 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9766 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9767 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 9768 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9769 | LPFC_ABTS_UNSOL_INT) { |
| 9770 | /* ABTS sent by initiator to CT exchange, the |
| 9771 | * RX_ID field will be filled with the newly |
| 9772 | * allocated responder XRI. |
| 9773 | */ |
| 9774 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 9775 | iocbq->sli4_xritag); |
| 9776 | } else { |
| 9777 | /* ABTS sent by responder to CT exchange, the |
| 9778 | * RX_ID field will be filled with the responder |
| 9779 | * RX_ID from ABTS. |
| 9780 | */ |
| 9781 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9782 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9783 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9784 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 9785 | 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] | 9786 | |
| 9787 | /* Use CT=VPI */ |
| 9788 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 9789 | ndlp->nlp_DID); |
| 9790 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 9791 | iocbq->iocb.ulpContext); |
| 9792 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9793 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9794 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9795 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 9796 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 9797 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9798 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 9799 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9800 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 9801 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 9802 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 9803 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 9804 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 9805 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 9806 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 9807 | } |
| 9808 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9809 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9810 | case CMD_SEND_FRAME: |
| 9811 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9812 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9813 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9814 | case CMD_XRI_ABORTED_CX: |
| 9815 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9816 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 9817 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 9818 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 9819 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 9820 | default: |
| 9821 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9822 | "2014 Invalid command 0x%x\n", |
| 9823 | iocbq->iocb.ulpCommand); |
| 9824 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9825 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9826 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9827 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 9828 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 9829 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 9830 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 9831 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 9832 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 9833 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 9834 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 9835 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9836 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9837 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9838 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 9839 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 9840 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 9841 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 9842 | 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] | 9843 | return 0; |
| 9844 | } |
| 9845 | |
| 9846 | /** |
| 9847 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 9848 | * @phba: Pointer to HBA context object. |
| 9849 | * @ring_number: SLI ring number to issue iocb on. |
| 9850 | * @piocb: Pointer to command iocb. |
| 9851 | * @flag: Flag indicating if this command can be put into txq. |
| 9852 | * |
| 9853 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 9854 | * an iocb command to an HBA with SLI-4 interface spec. |
| 9855 | * |
| 9856 | * This function is called with hbalock held. The function will return success |
| 9857 | * after it successfully submit the iocb to firmware or after adding to the |
| 9858 | * txq. |
| 9859 | **/ |
| 9860 | static int |
| 9861 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 9862 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9863 | { |
| 9864 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9865 | union lpfc_wqe128 wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9866 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9867 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9868 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9869 | /* Get the WQ */ |
| 9870 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 9871 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9872 | wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].fcp_wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9873 | } else { |
| 9874 | wq = phba->sli4_hba.els_wq; |
| 9875 | } |
| 9876 | |
| 9877 | /* Get corresponding ring */ |
| 9878 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9879 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9880 | /* |
| 9881 | * The WQE can be either 64 or 128 bytes, |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9882 | */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9883 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9884 | lockdep_assert_held(&phba->hbalock); |
| 9885 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9886 | if (piocb->sli4_xritag == NO_XRI) { |
| 9887 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9888 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9889 | sglq = NULL; |
| 9890 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9891 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9892 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9893 | __lpfc_sli_ringtx_put(phba, |
| 9894 | pring, piocb); |
| 9895 | return IOCB_SUCCESS; |
| 9896 | } else { |
| 9897 | return IOCB_BUSY; |
| 9898 | } |
| 9899 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9900 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9901 | if (!sglq) { |
| 9902 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9903 | __lpfc_sli_ringtx_put(phba, |
| 9904 | pring, |
| 9905 | piocb); |
| 9906 | return IOCB_SUCCESS; |
| 9907 | } else |
| 9908 | return IOCB_BUSY; |
| 9909 | } |
| 9910 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9911 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9912 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9913 | /* These IO's already have an XRI and a mapped sgl. */ |
| 9914 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9915 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9916 | /* |
| 9917 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9918 | * sglq is on the active list |
| 9919 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 9920 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9921 | if (!sglq) |
| 9922 | return IOCB_ERROR; |
| 9923 | } |
| 9924 | |
| 9925 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9926 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9927 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9928 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9929 | return IOCB_ERROR; |
| 9930 | } |
| 9931 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9932 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9933 | return IOCB_ERROR; |
| 9934 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9935 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9936 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9937 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 9938 | |
| 9939 | return 0; |
| 9940 | } |
| 9941 | |
| 9942 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9943 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 9944 | * |
| 9945 | * This routine wraps the actual lockless version for issusing IOCB function |
| 9946 | * pointer from the lpfc_hba struct. |
| 9947 | * |
| 9948 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9949 | * IOCB_ERROR - Error |
| 9950 | * IOCB_SUCCESS - Success |
| 9951 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9952 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9953 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9954 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 9955 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9956 | { |
| 9957 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9958 | } |
| 9959 | |
| 9960 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9961 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9962 | * @phba: The hba struct for which this call is being executed. |
| 9963 | * @dev_grp: The HBA PCI-Device group number. |
| 9964 | * |
| 9965 | * This routine sets up the SLI interface API function jump table in @phba |
| 9966 | * struct. |
| 9967 | * Returns: 0 - success, -ENODEV - failure. |
| 9968 | **/ |
| 9969 | int |
| 9970 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9971 | { |
| 9972 | |
| 9973 | switch (dev_grp) { |
| 9974 | case LPFC_PCI_DEV_LP: |
| 9975 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 9976 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 9977 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9978 | case LPFC_PCI_DEV_OC: |
| 9979 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 9980 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 9981 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9982 | default: |
| 9983 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9984 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 9985 | dev_grp); |
| 9986 | return -ENODEV; |
| 9987 | break; |
| 9988 | } |
| 9989 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 9990 | return 0; |
| 9991 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9992 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9993 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9994 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9995 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9996 | * @piocb: Pointer to command iocb. |
| 9997 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9998 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 9999 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10000 | * 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] | 10001 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 10002 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10003 | struct lpfc_sli_ring * |
| 10004 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10005 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10006 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10007 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10008 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10009 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 10010 | return NULL; |
| 10011 | /* |
| 10012 | * for abort iocb hba_wqidx should already |
| 10013 | * be setup based on what work queue we used. |
| 10014 | */ |
| 10015 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10016 | lpfc_cmd = (struct lpfc_io_buf *)piocb->context1; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 10017 | piocb->hba_wqidx = lpfc_cmd->hdwq_no; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10018 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10019 | return phba->sli4_hba.hdwq[piocb->hba_wqidx].fcp_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10020 | } else { |
| 10021 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 10022 | return NULL; |
| 10023 | piocb->hba_wqidx = 0; |
| 10024 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10025 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10026 | } |
| 10027 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10028 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10029 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10030 | * @phba: Pointer to HBA context object. |
| 10031 | * @pring: Pointer to driver SLI ring object. |
| 10032 | * @piocb: Pointer to command iocb. |
| 10033 | * @flag: Flag indicating if this command can be put into txq. |
| 10034 | * |
| 10035 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 10036 | * function. This function gets the hbalock and calls |
| 10037 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 10038 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 10039 | * functions which do not hold hbalock. |
| 10040 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10041 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10042 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10043 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 10044 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10045 | struct lpfc_sli_ring *pring; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10046 | unsigned long iflags; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10047 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10048 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10049 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10050 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 10051 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10052 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 10053 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10054 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10055 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10056 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10057 | } else { |
| 10058 | /* For now, SLI2/3 will still use hbalock */ |
| 10059 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10060 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 10061 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10062 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10063 | return rc; |
| 10064 | } |
| 10065 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10066 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10067 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10068 | * @phba: Pointer to HBA context object. |
| 10069 | * |
| 10070 | * This function is called while driver attaches with the |
| 10071 | * HBA to setup the extra ring. The extra ring is used |
| 10072 | * only when driver needs to support target mode functionality |
| 10073 | * or IP over FC functionalities. |
| 10074 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10075 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10076 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10077 | static int |
| 10078 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 10079 | { |
| 10080 | struct lpfc_sli *psli; |
| 10081 | struct lpfc_sli_ring *pring; |
| 10082 | |
| 10083 | psli = &phba->sli; |
| 10084 | |
| 10085 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10086 | |
| 10087 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10088 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10089 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10090 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10091 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10092 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10093 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10094 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10095 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10096 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10097 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10098 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10099 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10100 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10101 | |
| 10102 | /* Setup default profile for this ring */ |
| 10103 | pring->iotag_max = 4096; |
| 10104 | pring->num_mask = 1; |
| 10105 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10106 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 10107 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10108 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 10109 | return 0; |
| 10110 | } |
| 10111 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10112 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 10113 | * @phba: Pointer to HBA context object. |
| 10114 | * @iocbq: Pointer to iocb object. |
| 10115 | * |
| 10116 | * The async_event handler calls this routine when it receives |
| 10117 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 10118 | * this event when an Abort Sequence request to an rport fails |
| 10119 | * twice in succession. The abort could be originated by the |
| 10120 | * driver or by the port. The ABTS could have been for an ELS |
| 10121 | * or FCP IO. The port only generates this event when an ABTS |
| 10122 | * fails to complete after one retry. |
| 10123 | */ |
| 10124 | static void |
| 10125 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 10126 | struct lpfc_iocbq *iocbq) |
| 10127 | { |
| 10128 | struct lpfc_nodelist *ndlp = NULL; |
| 10129 | uint16_t rpi = 0, vpi = 0; |
| 10130 | struct lpfc_vport *vport = NULL; |
| 10131 | |
| 10132 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 10133 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 10134 | rpi = iocbq->iocb.ulpContext; |
| 10135 | |
| 10136 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10137 | "3092 Port generated ABTS async event " |
| 10138 | "on vpi %d rpi %d status 0x%x\n", |
| 10139 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 10140 | |
| 10141 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 10142 | if (!vport) |
| 10143 | goto err_exit; |
| 10144 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 10145 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 10146 | goto err_exit; |
| 10147 | |
| 10148 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 10149 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10150 | return; |
| 10151 | |
| 10152 | err_exit: |
| 10153 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10154 | "3095 Event Context not found, no " |
| 10155 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 10156 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 10157 | vpi, rpi); |
| 10158 | } |
| 10159 | |
| 10160 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 10161 | * @phba: pointer to HBA context object. |
| 10162 | * @ndlp: nodelist pointer for the impacted rport. |
| 10163 | * @axri: pointer to the wcqe containing the failed exchange. |
| 10164 | * |
| 10165 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 10166 | * port. The port generates this event when an abort exchange request to an |
| 10167 | * rport fails twice in succession with no reply. The abort could be originated |
| 10168 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 10169 | */ |
| 10170 | void |
| 10171 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 10172 | struct lpfc_nodelist *ndlp, |
| 10173 | struct sli4_wcqe_xri_aborted *axri) |
| 10174 | { |
| 10175 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10176 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10177 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10178 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10179 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10180 | "3115 Node Context not found, driver " |
| 10181 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 10182 | return; |
| 10183 | } |
| 10184 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10185 | vport = ndlp->vport; |
| 10186 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 10187 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10188 | "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] | 10189 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10190 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10191 | bf_get(lpfc_wcqe_xa_status, axri), |
| 10192 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10193 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10194 | /* |
| 10195 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 10196 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 10197 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 10198 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 10199 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 10200 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 10201 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10202 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 10203 | } |
| 10204 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10205 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10206 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10207 | * @phba: Pointer to HBA context object. |
| 10208 | * @pring: Pointer to driver SLI ring object. |
| 10209 | * @iocbq: Pointer to iocb object. |
| 10210 | * |
| 10211 | * This function is called by the slow ring event handler |
| 10212 | * function when there is an ASYNC event iocb in the ring. |
| 10213 | * This function is called with no lock held. |
| 10214 | * Currently this function handles only temperature related |
| 10215 | * ASYNC events. The function decodes the temperature sensor |
| 10216 | * event message and posts events for the management applications. |
| 10217 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 10218 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10219 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 10220 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 10221 | { |
| 10222 | IOCB_t *icmd; |
| 10223 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10224 | struct temp_event temp_event_data; |
| 10225 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10226 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10227 | |
| 10228 | icmd = &iocbq->iocb; |
| 10229 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10230 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10231 | switch (evt_code) { |
| 10232 | case ASYNC_TEMP_WARN: |
| 10233 | case ASYNC_TEMP_SAFE: |
| 10234 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 10235 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 10236 | if (evt_code == ASYNC_TEMP_WARN) { |
| 10237 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 10238 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10239 | "0347 Adapter is very hot, please take " |
| 10240 | "corrective action. temperature : %d Celsius\n", |
| 10241 | (uint32_t) icmd->ulpContext); |
| 10242 | } else { |
| 10243 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 10244 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 10245 | "0340 Adapter temperature is OK now. " |
| 10246 | "temperature : %d Celsius\n", |
| 10247 | (uint32_t) icmd->ulpContext); |
| 10248 | } |
| 10249 | |
| 10250 | /* Send temperature change event to applications */ |
| 10251 | shost = lpfc_shost_from_vport(phba->pport); |
| 10252 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 10253 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 10254 | LPFC_NL_VENDOR_ID); |
| 10255 | break; |
| 10256 | case ASYNC_STATUS_CN: |
| 10257 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 10258 | break; |
| 10259 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10260 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10261 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10262 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 10263 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10264 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 10265 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 10266 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 10267 | "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] | 10268 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10269 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 10270 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 10271 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 10272 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 10273 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10274 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10275 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10276 | } |
| 10277 | |
| 10278 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10279 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10280 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10281 | * @phba: Pointer to HBA context object. |
| 10282 | * |
| 10283 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10284 | * number of iocbs per ring and iotags. This function is |
| 10285 | * called while driver attach to the HBA and before the |
| 10286 | * interrupts are enabled. So there is no need for locking. |
| 10287 | * |
| 10288 | * This function always returns 0. |
| 10289 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10290 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10291 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 10292 | { |
| 10293 | struct lpfc_sli_ring *pring; |
| 10294 | |
| 10295 | pring = phba->sli4_hba.els_wq->pring; |
| 10296 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 10297 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 10298 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10299 | pring->prt[0].type = FC_TYPE_ELS; |
| 10300 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 10301 | lpfc_els_unsol_event; |
| 10302 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 10303 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10304 | pring->prt[1].type = FC_TYPE_ELS; |
| 10305 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 10306 | lpfc_els_unsol_event; |
| 10307 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10308 | /* NameServer Inquiry */ |
| 10309 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 10310 | /* NameServer */ |
| 10311 | pring->prt[2].type = FC_TYPE_CT; |
| 10312 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 10313 | lpfc_ct_unsol_event; |
| 10314 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10315 | /* NameServer response */ |
| 10316 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 10317 | /* NameServer */ |
| 10318 | pring->prt[3].type = FC_TYPE_CT; |
| 10319 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 10320 | lpfc_ct_unsol_event; |
| 10321 | return 0; |
| 10322 | } |
| 10323 | |
| 10324 | /** |
| 10325 | * lpfc_sli_setup - SLI ring setup function |
| 10326 | * @phba: Pointer to HBA context object. |
| 10327 | * |
| 10328 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10329 | * number of iocbs per ring and iotags. This function is |
| 10330 | * called while driver attach to the HBA and before the |
| 10331 | * interrupts are enabled. So there is no need for locking. |
| 10332 | * |
| 10333 | * This function always returns 0. SLI3 only. |
| 10334 | **/ |
| 10335 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10336 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 10337 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10338 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10339 | struct lpfc_sli *psli = &phba->sli; |
| 10340 | struct lpfc_sli_ring *pring; |
| 10341 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10342 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10343 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10344 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10345 | psli->iocbq_lookup = NULL; |
| 10346 | psli->iocbq_lookup_len = 0; |
| 10347 | psli->last_iotag = 0; |
| 10348 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10349 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10350 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10351 | switch (i) { |
| 10352 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 10353 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10354 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 10355 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 10356 | pring->sli.sli3.numCiocb += |
| 10357 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10358 | pring->sli.sli3.numRiocb += |
| 10359 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10360 | pring->sli.sli3.numCiocb += |
| 10361 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10362 | pring->sli.sli3.numRiocb += |
| 10363 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 10364 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10365 | SLI3_IOCB_CMD_SIZE : |
| 10366 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10367 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10368 | SLI3_IOCB_RSP_SIZE : |
| 10369 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10370 | pring->iotag_ctr = 0; |
| 10371 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10372 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10373 | pring->fast_iotag = pring->iotag_max; |
| 10374 | pring->num_mask = 0; |
| 10375 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10376 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10377 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10378 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 10379 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 10380 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10381 | SLI3_IOCB_CMD_SIZE : |
| 10382 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10383 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10384 | SLI3_IOCB_RSP_SIZE : |
| 10385 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10386 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10387 | pring->num_mask = 0; |
| 10388 | break; |
| 10389 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 10390 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10391 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 10392 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 10393 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10394 | SLI3_IOCB_CMD_SIZE : |
| 10395 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10396 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10397 | SLI3_IOCB_RSP_SIZE : |
| 10398 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10399 | pring->fast_iotag = 0; |
| 10400 | pring->iotag_ctr = 0; |
| 10401 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10402 | pring->lpfc_sli_rcv_async_status = |
| 10403 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10404 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10405 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10406 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10407 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10408 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10409 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10410 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10411 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10412 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10413 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10414 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10415 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10416 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10417 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10418 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10419 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10420 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10421 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10422 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10423 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10424 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10425 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10426 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10427 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10428 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10429 | break; |
| 10430 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10431 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 10432 | pring->sli.sli3.sizeCiocb) + |
| 10433 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10434 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10435 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10436 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10437 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 10438 | "SLI2 SLIM Data: x%x x%lx\n", |
| 10439 | phba->brd_no, totiocbsize, |
| 10440 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10441 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10442 | if (phba->cfg_multi_ring_support == 2) |
| 10443 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10444 | |
| 10445 | return 0; |
| 10446 | } |
| 10447 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10448 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10449 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10450 | * @phba: Pointer to HBA context object. |
| 10451 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10452 | * 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] | 10453 | * ring. This function also initializes ring indices of each ring. |
| 10454 | * This function is called during the initialization of the SLI |
| 10455 | * interface of an HBA. |
| 10456 | * This function is called with no lock held and always returns |
| 10457 | * 1. |
| 10458 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10459 | void |
| 10460 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 10461 | { |
| 10462 | struct lpfc_sli *psli; |
| 10463 | struct lpfc_sli_ring *pring; |
| 10464 | int i; |
| 10465 | |
| 10466 | psli = &phba->sli; |
| 10467 | spin_lock_irq(&phba->hbalock); |
| 10468 | INIT_LIST_HEAD(&psli->mboxq); |
| 10469 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 10470 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10471 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 10472 | pring = phba->sli4_hba.hdwq[i].fcp_wq->pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10473 | pring->flag = 0; |
| 10474 | pring->ringno = LPFC_FCP_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10475 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10476 | INIT_LIST_HEAD(&pring->txq); |
| 10477 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10478 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10479 | spin_lock_init(&pring->ring_lock); |
| 10480 | } |
| 10481 | pring = phba->sli4_hba.els_wq->pring; |
| 10482 | pring->flag = 0; |
| 10483 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10484 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10485 | INIT_LIST_HEAD(&pring->txq); |
| 10486 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10487 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10488 | spin_lock_init(&pring->ring_lock); |
| 10489 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10490 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 10491 | for (i = 0; i < phba->cfg_hdw_queue; i++) { |
| 10492 | pring = phba->sli4_hba.hdwq[i].nvme_wq->pring; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10493 | pring->flag = 0; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10494 | pring->ringno = LPFC_FCP_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10495 | pring->txcmplq_cnt = 0; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10496 | INIT_LIST_HEAD(&pring->txq); |
| 10497 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10498 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10499 | spin_lock_init(&pring->ring_lock); |
| 10500 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10501 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 10502 | pring->flag = 0; |
| 10503 | pring->ringno = LPFC_ELS_RING; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 10504 | pring->txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10505 | INIT_LIST_HEAD(&pring->txq); |
| 10506 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10507 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10508 | spin_lock_init(&pring->ring_lock); |
| 10509 | } |
| 10510 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10511 | spin_unlock_irq(&phba->hbalock); |
| 10512 | } |
| 10513 | |
| 10514 | /** |
| 10515 | * lpfc_sli_queue_init - Queue initialization function |
| 10516 | * @phba: Pointer to HBA context object. |
| 10517 | * |
| 10518 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 10519 | * ring. This function also initializes ring indices of each ring. |
| 10520 | * This function is called during the initialization of the SLI |
| 10521 | * interface of an HBA. |
| 10522 | * This function is called with no lock held and always returns |
| 10523 | * 1. |
| 10524 | **/ |
| 10525 | void |
| 10526 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10527 | { |
| 10528 | struct lpfc_sli *psli; |
| 10529 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10530 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10531 | |
| 10532 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10533 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10534 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10535 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10536 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10537 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10538 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10539 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10540 | pring->sli.sli3.next_cmdidx = 0; |
| 10541 | pring->sli.sli3.local_getidx = 0; |
| 10542 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10543 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 10544 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10545 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10546 | pring->flag = 0; |
| 10547 | INIT_LIST_HEAD(&pring->txq); |
| 10548 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10549 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10550 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10551 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10552 | } |
| 10553 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10554 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10555 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 10556 | * @phba: Pointer to HBA context object. |
| 10557 | * |
| 10558 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 10559 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 10560 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 10561 | * command; and completed mailbox command queue. It is caller's responsibility |
| 10562 | * to make sure that the driver is in the proper state to flush the mailbox |
| 10563 | * command sub-system. Namely, the posting of mailbox commands into the |
| 10564 | * pending mailbox command queue from the various clients must be stopped; |
| 10565 | * either the HBA is in a state that it will never works on the outstanding |
| 10566 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 10567 | * mailbox command has been completed. |
| 10568 | **/ |
| 10569 | static void |
| 10570 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10571 | { |
| 10572 | LIST_HEAD(completions); |
| 10573 | struct lpfc_sli *psli = &phba->sli; |
| 10574 | LPFC_MBOXQ_t *pmb; |
| 10575 | unsigned long iflag; |
| 10576 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10577 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10578 | local_bh_disable(); |
| 10579 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10580 | /* Flush all the mailbox commands in the mbox system */ |
| 10581 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10582 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10583 | /* The pending mailbox command queue */ |
| 10584 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10585 | /* The outstanding active mailbox command */ |
| 10586 | if (psli->mbox_active) { |
| 10587 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10588 | psli->mbox_active = NULL; |
| 10589 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10590 | } |
| 10591 | /* The completed mailbox command queue */ |
| 10592 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10593 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10594 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10595 | /* Enable softirqs again, done with phba->hbalock */ |
| 10596 | local_bh_enable(); |
| 10597 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10598 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10599 | while (!list_empty(&completions)) { |
| 10600 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10601 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10602 | if (pmb->mbox_cmpl) |
| 10603 | pmb->mbox_cmpl(phba, pmb); |
| 10604 | } |
| 10605 | } |
| 10606 | |
| 10607 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10608 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10609 | * @vport: Pointer to virtual port object. |
| 10610 | * |
| 10611 | * lpfc_sli_host_down is called to clean up the resources |
| 10612 | * associated with a vport before destroying virtual |
| 10613 | * port data structures. |
| 10614 | * This function does following operations: |
| 10615 | * - Free discovery resources associated with this virtual |
| 10616 | * port. |
| 10617 | * - Free iocbs associated with this virtual port in |
| 10618 | * the txq. |
| 10619 | * - Send abort for all iocb commands associated with this |
| 10620 | * vport in txcmplq. |
| 10621 | * |
| 10622 | * This function is called with no lock held and always returns 1. |
| 10623 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10624 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10625 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10626 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10627 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10628 | struct lpfc_hba *phba = vport->phba; |
| 10629 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10630 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10631 | struct lpfc_sli_ring *pring; |
| 10632 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10633 | int i; |
| 10634 | unsigned long flags = 0; |
| 10635 | uint16_t prev_pring_flag; |
| 10636 | |
| 10637 | lpfc_cleanup_discovery_resources(vport); |
| 10638 | |
| 10639 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10640 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10641 | /* |
| 10642 | * Error everything on the txq since these iocbs |
| 10643 | * have not been given to the FW yet. |
| 10644 | * Also issue ABTS for everything on the txcmplq |
| 10645 | */ |
| 10646 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10647 | for (i = 0; i < psli->num_rings; i++) { |
| 10648 | pring = &psli->sli3_ring[i]; |
| 10649 | prev_pring_flag = pring->flag; |
| 10650 | /* Only slow rings */ |
| 10651 | if (pring->ringno == LPFC_ELS_RING) { |
| 10652 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10653 | /* Set the lpfc data pending flag */ |
| 10654 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10655 | } |
| 10656 | list_for_each_entry_safe(iocb, next_iocb, |
| 10657 | &pring->txq, list) { |
| 10658 | if (iocb->vport != vport) |
| 10659 | continue; |
| 10660 | list_move_tail(&iocb->list, &completions); |
| 10661 | } |
| 10662 | list_for_each_entry_safe(iocb, next_iocb, |
| 10663 | &pring->txcmplq, list) { |
| 10664 | if (iocb->vport != vport) |
| 10665 | continue; |
| 10666 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10667 | } |
| 10668 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10669 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10670 | } else { |
| 10671 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10672 | pring = qp->pring; |
| 10673 | if (!pring) |
| 10674 | continue; |
| 10675 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10676 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10677 | /* Set the lpfc data pending flag */ |
| 10678 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10679 | } |
| 10680 | prev_pring_flag = pring->flag; |
| 10681 | spin_lock_irq(&pring->ring_lock); |
| 10682 | list_for_each_entry_safe(iocb, next_iocb, |
| 10683 | &pring->txq, list) { |
| 10684 | if (iocb->vport != vport) |
| 10685 | continue; |
| 10686 | list_move_tail(&iocb->list, &completions); |
| 10687 | } |
| 10688 | spin_unlock_irq(&pring->ring_lock); |
| 10689 | list_for_each_entry_safe(iocb, next_iocb, |
| 10690 | &pring->txcmplq, list) { |
| 10691 | if (iocb->vport != vport) |
| 10692 | continue; |
| 10693 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10694 | } |
| 10695 | pring->flag = prev_pring_flag; |
| 10696 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10697 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10698 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10699 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10700 | /* Cancel all the IOCBs from the completions list */ |
| 10701 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10702 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10703 | return 1; |
| 10704 | } |
| 10705 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10706 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10707 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10708 | * @phba: Pointer to HBA context object. |
| 10709 | * |
| 10710 | * This function cleans up all iocb, buffers, mailbox commands |
| 10711 | * while shutting down the HBA. This function is called with no |
| 10712 | * lock held and always returns 1. |
| 10713 | * This function does the following to cleanup driver resources: |
| 10714 | * - Free discovery resources for each virtual port |
| 10715 | * - Cleanup any pending fabric iocbs |
| 10716 | * - Iterate through the iocb txq and free each entry |
| 10717 | * in the list. |
| 10718 | * - Free up any buffer posted to the HBA |
| 10719 | * - Free mailbox commands in the mailbox queue. |
| 10720 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10721 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10722 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10723 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10724 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10725 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10726 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10727 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10728 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10729 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10730 | int i; |
| 10731 | |
| 10732 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10733 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10734 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10735 | lpfc_hba_down_prep(phba); |
| 10736 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10737 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 10738 | local_bh_disable(); |
| 10739 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10740 | lpfc_fabric_abort_hba(phba); |
| 10741 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10742 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10743 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10744 | /* |
| 10745 | * Error everything on the txq since these iocbs |
| 10746 | * have not been given to the FW yet. |
| 10747 | */ |
| 10748 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10749 | for (i = 0; i < psli->num_rings; i++) { |
| 10750 | pring = &psli->sli3_ring[i]; |
| 10751 | /* Only slow rings */ |
| 10752 | if (pring->ringno == LPFC_ELS_RING) { |
| 10753 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10754 | /* Set the lpfc data pending flag */ |
| 10755 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10756 | } |
| 10757 | list_splice_init(&pring->txq, &completions); |
| 10758 | } |
| 10759 | } else { |
| 10760 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10761 | pring = qp->pring; |
| 10762 | if (!pring) |
| 10763 | continue; |
| 10764 | spin_lock_irq(&pring->ring_lock); |
| 10765 | list_splice_init(&pring->txq, &completions); |
| 10766 | spin_unlock_irq(&pring->ring_lock); |
| 10767 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10768 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10769 | /* Set the lpfc data pending flag */ |
| 10770 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10771 | } |
| 10772 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10773 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10774 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10775 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10776 | /* Cancel all the IOCBs from the completions list */ |
| 10777 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10778 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10779 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10780 | spin_lock_irqsave(&phba->hbalock, flags); |
| 10781 | list_splice_init(&phba->elsbuf, &completions); |
| 10782 | phba->elsbuf_cnt = 0; |
| 10783 | phba->elsbuf_prev_cnt = 0; |
| 10784 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10785 | |
| 10786 | while (!list_empty(&completions)) { |
| 10787 | list_remove_head(&completions, buf_ptr, |
| 10788 | struct lpfc_dmabuf, list); |
| 10789 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 10790 | kfree(buf_ptr); |
| 10791 | } |
| 10792 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 10793 | /* Enable softirqs again, done with phba->hbalock */ |
| 10794 | local_bh_enable(); |
| 10795 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10796 | /* Return any active mbox cmds */ |
| 10797 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10798 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10799 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10800 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10801 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10802 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10803 | return 1; |
| 10804 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10805 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10806 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10807 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10808 | * @srcp: Source memory pointer. |
| 10809 | * @destp: Destination memory pointer. |
| 10810 | * @cnt: Number of words required to be copied. |
| 10811 | * |
| 10812 | * This function is used for copying data between driver memory |
| 10813 | * and the SLI memory. This function also changes the endianness |
| 10814 | * of each word if native endianness is different from SLI |
| 10815 | * endianness. This function can be called with or without |
| 10816 | * lock. |
| 10817 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10818 | void |
| 10819 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10820 | { |
| 10821 | uint32_t *src = srcp; |
| 10822 | uint32_t *dest = destp; |
| 10823 | uint32_t ldata; |
| 10824 | int i; |
| 10825 | |
| 10826 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 10827 | ldata = *src; |
| 10828 | ldata = le32_to_cpu(ldata); |
| 10829 | *dest = ldata; |
| 10830 | src++; |
| 10831 | dest++; |
| 10832 | } |
| 10833 | } |
| 10834 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10835 | |
| 10836 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 10837 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 10838 | * @srcp: Source memory pointer. |
| 10839 | * @destp: Destination memory pointer. |
| 10840 | * @cnt: Number of words required to be copied. |
| 10841 | * |
| 10842 | * This function is used for copying data between a data structure |
| 10843 | * with big endian representation to local endianness. |
| 10844 | * This function can be called with or without lock. |
| 10845 | **/ |
| 10846 | void |
| 10847 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10848 | { |
| 10849 | uint32_t *src = srcp; |
| 10850 | uint32_t *dest = destp; |
| 10851 | uint32_t ldata; |
| 10852 | int i; |
| 10853 | |
| 10854 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 10855 | ldata = *src; |
| 10856 | ldata = be32_to_cpu(ldata); |
| 10857 | *dest = ldata; |
| 10858 | src++; |
| 10859 | dest++; |
| 10860 | } |
| 10861 | } |
| 10862 | |
| 10863 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10864 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10865 | * @phba: Pointer to HBA context object. |
| 10866 | * @pring: Pointer to driver SLI ring object. |
| 10867 | * @mp: Pointer to driver buffer object. |
| 10868 | * |
| 10869 | * This function is called with no lock held. |
| 10870 | * It always return zero after adding the buffer to the postbufq |
| 10871 | * buffer list. |
| 10872 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10873 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10874 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10875 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10876 | { |
| 10877 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 10878 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10879 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10880 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10881 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10882 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10883 | return 0; |
| 10884 | } |
| 10885 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10886 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10887 | * 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] | 10888 | * @phba: Pointer to HBA context object. |
| 10889 | * |
| 10890 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 10891 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 10892 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 10893 | * does not conflict with tags of buffer posted for unsolicited events. |
| 10894 | * The function returns the allocated tag. The function is called with |
| 10895 | * no locks held. |
| 10896 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10897 | uint32_t |
| 10898 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 10899 | { |
| 10900 | spin_lock_irq(&phba->hbalock); |
| 10901 | phba->buffer_tag_count++; |
| 10902 | /* |
| 10903 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 10904 | * a tag assigned by HBQ. |
| 10905 | */ |
| 10906 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 10907 | spin_unlock_irq(&phba->hbalock); |
| 10908 | return phba->buffer_tag_count; |
| 10909 | } |
| 10910 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10911 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10912 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10913 | * @phba: Pointer to HBA context object. |
| 10914 | * @pring: Pointer to driver SLI ring object. |
| 10915 | * @tag: Buffer tag. |
| 10916 | * |
| 10917 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 10918 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 10919 | * iocb is posted to the response ring with the tag of the buffer. |
| 10920 | * This function searches the pring->postbufq list using the tag |
| 10921 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 10922 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 10923 | * buffer is returned to the caller else NULL is returned. |
| 10924 | * This function is called with no lock held. |
| 10925 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10926 | struct lpfc_dmabuf * |
| 10927 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10928 | uint32_t tag) |
| 10929 | { |
| 10930 | struct lpfc_dmabuf *mp, *next_mp; |
| 10931 | struct list_head *slp = &pring->postbufq; |
| 10932 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10933 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10934 | spin_lock_irq(&phba->hbalock); |
| 10935 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10936 | if (mp->buffer_tag == tag) { |
| 10937 | list_del_init(&mp->list); |
| 10938 | pring->postbufq_cnt--; |
| 10939 | spin_unlock_irq(&phba->hbalock); |
| 10940 | return mp; |
| 10941 | } |
| 10942 | } |
| 10943 | |
| 10944 | spin_unlock_irq(&phba->hbalock); |
| 10945 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10946 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10947 | "ring %d Data x%lx x%p x%p x%x\n", |
| 10948 | pring->ringno, (unsigned long) tag, |
| 10949 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10950 | |
| 10951 | return NULL; |
| 10952 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10953 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10954 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10955 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10956 | * @phba: Pointer to HBA context object. |
| 10957 | * @pring: Pointer to driver SLI ring object. |
| 10958 | * @phys: DMA address of the buffer. |
| 10959 | * |
| 10960 | * This function searches the buffer list using the dma_address |
| 10961 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 10962 | * corresponding to the dma_address. The function returns the |
| 10963 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 10964 | * This function is called by the ct and els unsolicited event |
| 10965 | * handlers to get the buffer associated with the unsolicited |
| 10966 | * event. |
| 10967 | * |
| 10968 | * This function is called with no lock held. |
| 10969 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10970 | struct lpfc_dmabuf * |
| 10971 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10972 | dma_addr_t phys) |
| 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 phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10978 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10979 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10980 | if (mp->phys == phys) { |
| 10981 | list_del_init(&mp->list); |
| 10982 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10983 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10984 | return mp; |
| 10985 | } |
| 10986 | } |
| 10987 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10988 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10989 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10990 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10991 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10992 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10993 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10994 | return NULL; |
| 10995 | } |
| 10996 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10997 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10998 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10999 | * @phba: Pointer to HBA context object. |
| 11000 | * @cmdiocb: Pointer to driver command iocb object. |
| 11001 | * @rspiocb: Pointer to driver response iocb object. |
| 11002 | * |
| 11003 | * This function is the completion handler for the abort iocbs for |
| 11004 | * ELS commands. This function is called from the ELS ring event |
| 11005 | * handler with no lock held. This function frees memory resources |
| 11006 | * associated with the abort iocb. |
| 11007 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11008 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11009 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11010 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11011 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11012 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11013 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11014 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11015 | |
| 11016 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11017 | |
| 11018 | /* |
| 11019 | * Assume that the port already completed and returned, or |
| 11020 | * will return the iocb. Just Log the message. |
| 11021 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11022 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 11023 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 11024 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11025 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11026 | if (phba->sli_rev < LPFC_SLI_REV4) { |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11027 | if (irsp->ulpCommand == CMD_ABORT_XRI_CX && |
| 11028 | irsp->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 11029 | irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) { |
| 11030 | spin_unlock_irq(&phba->hbalock); |
| 11031 | goto release_iocb; |
| 11032 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11033 | if (abort_iotag != 0 && |
| 11034 | abort_iotag <= phba->sli.last_iotag) |
| 11035 | abort_iocb = |
| 11036 | phba->sli.iocbq_lookup[abort_iotag]; |
| 11037 | } else |
| 11038 | /* For sli4 the abort_tag is the XRI, |
| 11039 | * so the abort routine puts the iotag of the iocb |
| 11040 | * being aborted in the context field of the abort |
| 11041 | * IOCB. |
| 11042 | */ |
| 11043 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11044 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11045 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 11046 | "0327 Cannot abort els iocb %p " |
| 11047 | "with tag %x context %x, abort status %x, " |
| 11048 | "abort code %x\n", |
| 11049 | abort_iocb, abort_iotag, abort_context, |
| 11050 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11051 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 11052 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 11053 | } |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11054 | release_iocb: |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11055 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11056 | return; |
| 11057 | } |
| 11058 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11059 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11060 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11061 | * @phba: Pointer to HBA context object. |
| 11062 | * @cmdiocb: Pointer to driver command iocb object. |
| 11063 | * @rspiocb: Pointer to driver response iocb object. |
| 11064 | * |
| 11065 | * The function is called from SLI ring event handler with no |
| 11066 | * lock held. This function is the completion handler for ELS commands |
| 11067 | * which are aborted. The function frees memory resources used for |
| 11068 | * the aborted ELS commands. |
| 11069 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11070 | static void |
| 11071 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11072 | struct lpfc_iocbq *rspiocb) |
| 11073 | { |
| 11074 | IOCB_t *irsp = &rspiocb->iocb; |
| 11075 | |
| 11076 | /* ELS cmd tag <ulpIoTag> completes */ |
| 11077 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11078 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11079 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11080 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11081 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11082 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 11083 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 11084 | else |
| 11085 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11086 | return; |
| 11087 | } |
| 11088 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11089 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11090 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11091 | * @phba: Pointer to HBA context object. |
| 11092 | * @pring: Pointer to driver SLI ring object. |
| 11093 | * @cmdiocb: Pointer to driver command iocb object. |
| 11094 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11095 | * This function issues an abort iocb for the provided command iocb down to |
| 11096 | * the port. Other than the case the outstanding command iocb is an abort |
| 11097 | * request, this function issues abort out unconditionally. This function is |
| 11098 | * called with hbalock held. The function returns 0 when it fails due to |
| 11099 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11100 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11101 | static int |
| 11102 | 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] | 11103 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11104 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11105 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11106 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11107 | IOCB_t *icmd = NULL; |
| 11108 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11109 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11110 | unsigned long iflags; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11111 | struct lpfc_nodelist *ndlp; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11112 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11113 | lockdep_assert_held(&phba->hbalock); |
| 11114 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11115 | /* |
| 11116 | * There are certain command types we don't want to abort. And we |
| 11117 | * don't want to abort commands that are already in the process of |
| 11118 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11119 | */ |
| 11120 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11121 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11122 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11123 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11124 | return 0; |
| 11125 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11126 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11127 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11128 | if (abtsiocbp == NULL) |
| 11129 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11130 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11131 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11132 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11133 | */ |
| 11134 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11135 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11136 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11137 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11138 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11139 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11140 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 11141 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11142 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11143 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
James Smart | faa832e | 2018-07-31 17:23:18 -0700 | [diff] [blame] | 11144 | if (pring->ringno == LPFC_ELS_RING) { |
| 11145 | ndlp = (struct lpfc_nodelist *)(cmdiocb->context1); |
| 11146 | iabt->un.acxri.abortContextTag = ndlp->nlp_rpi; |
| 11147 | } |
| 11148 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11149 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11150 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11151 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11152 | /* 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] | 11153 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11154 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 11155 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11156 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 11157 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11158 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11159 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11160 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 11161 | else |
| 11162 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 11163 | |
| 11164 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 11165 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 11166 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11167 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 11168 | "0339 Abort xri x%x, original iotag x%x, " |
| 11169 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11170 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11171 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11172 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11173 | |
| 11174 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11175 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 11176 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11177 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 11178 | /* Note: both hbalock and ring_lock need to be set here */ |
| 11179 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 11180 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11181 | abtsiocbp, 0); |
| 11182 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 11183 | } else { |
| 11184 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11185 | abtsiocbp, 0); |
| 11186 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11187 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11188 | if (retval) |
| 11189 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11190 | |
| 11191 | /* |
| 11192 | * Caller to this routine should check for IOCB_ERROR |
| 11193 | * and handle it properly. This routine no longer removes |
| 11194 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 11195 | */ |
| 11196 | return retval; |
| 11197 | } |
| 11198 | |
| 11199 | /** |
| 11200 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 11201 | * @phba: Pointer to HBA context object. |
| 11202 | * @pring: Pointer to driver SLI ring object. |
| 11203 | * @cmdiocb: Pointer to driver command iocb object. |
| 11204 | * |
| 11205 | * This function issues an abort iocb for the provided command iocb. In case |
| 11206 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 11207 | * ring. Instead, the callback function shall be changed to those commands |
| 11208 | * so that nothing happens when them finishes. This function is called with |
| 11209 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 11210 | * request. |
| 11211 | **/ |
| 11212 | int |
| 11213 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11214 | struct lpfc_iocbq *cmdiocb) |
| 11215 | { |
| 11216 | struct lpfc_vport *vport = cmdiocb->vport; |
| 11217 | int retval = IOCB_ERROR; |
| 11218 | IOCB_t *icmd = NULL; |
| 11219 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 11220 | lockdep_assert_held(&phba->hbalock); |
| 11221 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11222 | /* |
| 11223 | * There are certain command types we don't want to abort. And we |
| 11224 | * don't want to abort commands that are already in the process of |
| 11225 | * being aborted. |
| 11226 | */ |
| 11227 | icmd = &cmdiocb->iocb; |
| 11228 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 11229 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 11230 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 11231 | return 0; |
| 11232 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 11233 | if (!pring) { |
| 11234 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11235 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11236 | else |
| 11237 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11238 | goto abort_iotag_exit; |
| 11239 | } |
| 11240 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11241 | /* |
| 11242 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 11243 | * the callback so that nothing happens when it finishes. |
| 11244 | */ |
| 11245 | if ((vport->load_flag & FC_UNLOADING) && |
| 11246 | (pring->ringno == LPFC_ELS_RING)) { |
| 11247 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 11248 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11249 | else |
| 11250 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 11251 | goto abort_iotag_exit; |
| 11252 | } |
| 11253 | |
| 11254 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 11255 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 11256 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11257 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11258 | /* |
| 11259 | * Caller to this routine should check for IOCB_ERROR |
| 11260 | * and handle it properly. This routine no longer removes |
| 11261 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 11262 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11263 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11264 | } |
| 11265 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11266 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11267 | * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb |
| 11268 | * @phba: Pointer to HBA context object. |
| 11269 | * @pring: Pointer to driver SLI ring object. |
| 11270 | * @cmdiocb: Pointer to driver command iocb object. |
| 11271 | * |
| 11272 | * This function issues an abort iocb for the provided command iocb down to |
| 11273 | * the port. Other than the case the outstanding command iocb is an abort |
| 11274 | * request, this function issues abort out unconditionally. This function is |
| 11275 | * called with hbalock held. The function returns 0 when it fails due to |
| 11276 | * memory allocation failure or when the command iocb is an abort request. |
| 11277 | **/ |
| 11278 | static int |
| 11279 | lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 11280 | struct lpfc_iocbq *cmdiocb) |
| 11281 | { |
| 11282 | struct lpfc_vport *vport = cmdiocb->vport; |
| 11283 | struct lpfc_iocbq *abtsiocbp; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 11284 | union lpfc_wqe128 *abts_wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11285 | int retval; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 11286 | int idx = cmdiocb->hba_wqidx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11287 | |
| 11288 | /* |
| 11289 | * There are certain command types we don't want to abort. And we |
| 11290 | * don't want to abort commands that are already in the process of |
| 11291 | * being aborted. |
| 11292 | */ |
| 11293 | if (cmdiocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 11294 | cmdiocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN || |
| 11295 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 11296 | return 0; |
| 11297 | |
| 11298 | /* issue ABTS for this io based on iotag */ |
| 11299 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| 11300 | if (abtsiocbp == NULL) |
| 11301 | return 0; |
| 11302 | |
| 11303 | /* This signals the response to set the correct status |
| 11304 | * before calling the completion handler |
| 11305 | */ |
| 11306 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11307 | |
| 11308 | /* Complete prepping the abort wqe and issue to the FW. */ |
| 11309 | abts_wqe = &abtsiocbp->wqe; |
James Smart | 1c36833 | 2018-11-29 16:09:37 -0800 | [diff] [blame] | 11310 | |
| 11311 | /* Clear any stale WQE contents */ |
| 11312 | memset(abts_wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11313 | bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); |
| 11314 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11315 | /* word 7 */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11316 | bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 11317 | bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com, |
| 11318 | cmdiocb->iocb.ulpClass); |
| 11319 | |
| 11320 | /* word 8 - tell the FW to abort the IO associated with this |
| 11321 | * outstanding exchange ID. |
| 11322 | */ |
| 11323 | abts_wqe->abort_cmd.wqe_com.abort_tag = cmdiocb->sli4_xritag; |
| 11324 | |
| 11325 | /* word 9 - this is the iotag for the abts_wqe completion. */ |
| 11326 | bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, |
| 11327 | abtsiocbp->iotag); |
| 11328 | |
| 11329 | /* word 10 */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11330 | bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); |
| 11331 | bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 11332 | |
| 11333 | /* word 11 */ |
| 11334 | bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); |
| 11335 | bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); |
| 11336 | bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
| 11337 | |
| 11338 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 11339 | abtsiocbp->iocb_flag |= LPFC_IO_NVME; |
| 11340 | abtsiocbp->vport = vport; |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11341 | abtsiocbp->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 11342 | retval = lpfc_sli4_issue_wqe(phba, &phba->sli4_hba.hdwq[idx], |
| 11343 | abtsiocbp); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 11344 | if (retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11345 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 11346 | "6147 Failed abts issue_wqe with status x%x " |
| 11347 | "for oxid x%x\n", |
| 11348 | retval, cmdiocb->sli4_xritag); |
| 11349 | lpfc_sli_release_iocbq(phba, abtsiocbp); |
| 11350 | return retval; |
| 11351 | } |
| 11352 | |
| 11353 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 11354 | "6148 Drv Abort NVME Request Issued for " |
| 11355 | "ox_id x%x on reqtag x%x\n", |
| 11356 | cmdiocb->sli4_xritag, |
| 11357 | abtsiocbp->iotag); |
| 11358 | |
| 11359 | return retval; |
| 11360 | } |
| 11361 | |
| 11362 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11363 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 11364 | * @phba: pointer to lpfc HBA data structure. |
| 11365 | * |
| 11366 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 11367 | **/ |
| 11368 | void |
| 11369 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 11370 | { |
| 11371 | struct lpfc_sli *psli = &phba->sli; |
| 11372 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11373 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11374 | int i; |
| 11375 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11376 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11377 | for (i = 0; i < psli->num_rings; i++) { |
| 11378 | pring = &psli->sli3_ring[i]; |
| 11379 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 11380 | } |
| 11381 | return; |
| 11382 | } |
| 11383 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11384 | pring = qp->pring; |
| 11385 | if (!pring) |
| 11386 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11387 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11388 | } |
| 11389 | } |
| 11390 | |
| 11391 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11392 | * 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] | 11393 | * @iocbq: Pointer to driver iocb object. |
| 11394 | * @vport: Pointer to driver virtual port object. |
| 11395 | * @tgt_id: SCSI ID of the target. |
| 11396 | * @lun_id: LUN ID of the scsi device. |
| 11397 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 11398 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11399 | * 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] | 11400 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 11401 | * 0 if the filtering criteria is met for the given iocb and will return |
| 11402 | * 1 if the filtering criteria is not met. |
| 11403 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 11404 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 11405 | * lun_id parameter. |
| 11406 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 11407 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 11408 | * parameters. |
| 11409 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 11410 | * given iocb is for the SCSI host associated with the given vport. |
| 11411 | * This function is called with no locks held. |
| 11412 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11413 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11414 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 11415 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11416 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11417 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11418 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11419 | int rc = 1; |
| 11420 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11421 | if (iocbq->vport != vport) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11422 | return rc; |
| 11423 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11424 | if (!(iocbq->iocb_flag & LPFC_IO_FCP) || |
| 11425 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11426 | return rc; |
| 11427 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11428 | 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] | 11429 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11430 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11431 | return rc; |
| 11432 | |
| 11433 | switch (ctx_cmd) { |
| 11434 | case LPFC_CTX_LUN: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11435 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11436 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 11437 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11438 | rc = 0; |
| 11439 | break; |
| 11440 | case LPFC_CTX_TGT: |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11441 | if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) && |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11442 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11443 | rc = 0; |
| 11444 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11445 | case LPFC_CTX_HOST: |
| 11446 | rc = 0; |
| 11447 | break; |
| 11448 | default: |
| 11449 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 11450 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11451 | break; |
| 11452 | } |
| 11453 | |
| 11454 | return rc; |
| 11455 | } |
| 11456 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11457 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11458 | * 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] | 11459 | * @vport: Pointer to virtual port. |
| 11460 | * @tgt_id: SCSI ID of the target. |
| 11461 | * @lun_id: LUN ID of the scsi device. |
| 11462 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11463 | * |
| 11464 | * This function returns number of FCP commands pending for the vport. |
| 11465 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 11466 | * commands pending on the vport associated with SCSI device specified |
| 11467 | * by tgt_id and lun_id parameters. |
| 11468 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 11469 | * commands pending on the vport associated with SCSI target specified |
| 11470 | * by tgt_id parameter. |
| 11471 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 11472 | * commands pending on the vport. |
| 11473 | * This function returns the number of iocbs which satisfy the filter. |
| 11474 | * This function is called without any lock held. |
| 11475 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11476 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11477 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 11478 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11479 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11480 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11481 | struct lpfc_iocbq *iocbq; |
| 11482 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11483 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11484 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11485 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 11486 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11487 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11488 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 11489 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11490 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11491 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11492 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11493 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11494 | return sum; |
| 11495 | } |
| 11496 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11497 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11498 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11499 | * @phba: Pointer to HBA context object |
| 11500 | * @cmdiocb: Pointer to command iocb object. |
| 11501 | * @rspiocb: Pointer to response iocb object. |
| 11502 | * |
| 11503 | * This function is called when an aborted FCP iocb completes. This |
| 11504 | * function is called by the ring event handler with no lock held. |
| 11505 | * This function frees the iocb. |
| 11506 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11507 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11508 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11509 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11510 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11511 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 11512 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11513 | "original iotag x%x, abort cmd iotag x%x " |
| 11514 | "status 0x%x, reason 0x%x\n", |
| 11515 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 11516 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 11517 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 11518 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11519 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11520 | return; |
| 11521 | } |
| 11522 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11523 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11524 | * 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] | 11525 | * @vport: Pointer to virtual port. |
| 11526 | * @pring: Pointer to driver SLI ring object. |
| 11527 | * @tgt_id: SCSI ID of the target. |
| 11528 | * @lun_id: LUN ID of the scsi device. |
| 11529 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11530 | * |
| 11531 | * This function sends an abort command for every SCSI command |
| 11532 | * associated with the given virtual port pending on the ring |
| 11533 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11534 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11535 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11536 | * parameters |
| 11537 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11538 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11539 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11540 | * FCP iocbs associated with virtual port. |
| 11541 | * This function returns number of iocbs it failed to abort. |
| 11542 | * This function is called with no locks held. |
| 11543 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11544 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11545 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11546 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11547 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11548 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11549 | struct lpfc_iocbq *iocbq; |
| 11550 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11551 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11552 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11553 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11554 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11555 | |
James Smart | b0e8301 | 2018-06-26 08:24:29 -0700 | [diff] [blame] | 11556 | /* all I/Os are in process of being flushed */ |
| 11557 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) |
| 11558 | return errcnt; |
| 11559 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11560 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11561 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11562 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11563 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11564 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11565 | continue; |
| 11566 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11567 | /* |
| 11568 | * If the iocbq is already being aborted, don't take a second |
| 11569 | * action, but do count it. |
| 11570 | */ |
| 11571 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11572 | continue; |
| 11573 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11574 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11575 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11576 | if (abtsiocb == NULL) { |
| 11577 | errcnt++; |
| 11578 | continue; |
| 11579 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11580 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11581 | /* indicate the IO is being aborted by the driver. */ |
| 11582 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11583 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11584 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11585 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11586 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11587 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11588 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 11589 | else |
| 11590 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11591 | abtsiocb->iocb.ulpLe = 1; |
| 11592 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11593 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11594 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11595 | /* 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] | 11596 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11597 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11598 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11599 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11600 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11601 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11602 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11603 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11604 | else |
| 11605 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11606 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11607 | /* Setup callback routine and issue the command. */ |
| 11608 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11609 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11610 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11611 | if (!pring_s4) |
| 11612 | continue; |
| 11613 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11614 | abtsiocb, 0); |
| 11615 | } else |
| 11616 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11617 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11618 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11619 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11620 | errcnt++; |
| 11621 | continue; |
| 11622 | } |
| 11623 | } |
| 11624 | |
| 11625 | return errcnt; |
| 11626 | } |
| 11627 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11628 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11629 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11630 | * @vport: Pointer to virtual port. |
| 11631 | * @pring: Pointer to driver SLI ring object. |
| 11632 | * @tgt_id: SCSI ID of the target. |
| 11633 | * @lun_id: LUN ID of the scsi device. |
| 11634 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11635 | * |
| 11636 | * This function sends an abort command for every SCSI command |
| 11637 | * associated with the given virtual port pending on the ring |
| 11638 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11639 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11640 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11641 | * parameters |
| 11642 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11643 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11644 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11645 | * FCP iocbs associated with virtual port. |
| 11646 | * This function returns number of iocbs it aborted . |
| 11647 | * This function is called with no locks held right after a taskmgmt |
| 11648 | * command is sent. |
| 11649 | **/ |
| 11650 | int |
| 11651 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11652 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11653 | { |
| 11654 | struct lpfc_hba *phba = vport->phba; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11655 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11656 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11657 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11658 | struct lpfc_iocbq *iocbq; |
| 11659 | IOCB_t *icmd; |
| 11660 | int sum, i, ret_val; |
| 11661 | unsigned long iflags; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11662 | struct lpfc_sli_ring *pring_s4 = NULL; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11663 | |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11664 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11665 | |
| 11666 | /* all I/Os are in process of being flushed */ |
| 11667 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11668 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11669 | return 0; |
| 11670 | } |
| 11671 | sum = 0; |
| 11672 | |
| 11673 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11674 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11675 | |
| 11676 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11677 | cmd) != 0) |
| 11678 | continue; |
| 11679 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11680 | /* Guard against IO completion being called at same time */ |
| 11681 | lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq); |
| 11682 | spin_lock(&lpfc_cmd->buf_lock); |
| 11683 | |
| 11684 | if (!lpfc_cmd->pCmd) { |
| 11685 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11686 | continue; |
| 11687 | } |
| 11688 | |
| 11689 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11690 | pring_s4 = |
| 11691 | phba->sli4_hba.hdwq[iocbq->hba_wqidx].fcp_wq->pring; |
| 11692 | if (!pring_s4) { |
| 11693 | spin_unlock(&lpfc_cmd->buf_lock); |
| 11694 | continue; |
| 11695 | } |
| 11696 | /* Note: both hbalock and ring_lock must be set here */ |
| 11697 | spin_lock(&pring_s4->ring_lock); |
| 11698 | } |
| 11699 | |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11700 | /* |
| 11701 | * If the iocbq is already being aborted, don't take a second |
| 11702 | * action, but do count it. |
| 11703 | */ |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11704 | if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) || |
| 11705 | !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) { |
| 11706 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11707 | spin_unlock(&pring_s4->ring_lock); |
| 11708 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11709 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11710 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11711 | |
| 11712 | /* issue ABTS for this IOCB based on iotag */ |
| 11713 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11714 | if (!abtsiocbq) { |
| 11715 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11716 | spin_unlock(&pring_s4->ring_lock); |
| 11717 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11718 | continue; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11719 | } |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11720 | |
| 11721 | icmd = &iocbq->iocb; |
| 11722 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11723 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11724 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11725 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11726 | iocbq->sli4_xritag; |
| 11727 | else |
| 11728 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11729 | abtsiocbq->iocb.ulpLe = 1; |
| 11730 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11731 | abtsiocbq->vport = vport; |
| 11732 | |
| 11733 | /* 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] | 11734 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11735 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11736 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11737 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11738 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11739 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11740 | ndlp = lpfc_cmd->rdata->pnode; |
| 11741 | |
| 11742 | if (lpfc_is_link_up(phba) && |
| 11743 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11744 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11745 | else |
| 11746 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11747 | |
| 11748 | /* Setup callback routine and issue the command. */ |
| 11749 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11750 | |
| 11751 | /* |
| 11752 | * Indicate the IO is being aborted by the driver and set |
| 11753 | * the caller's flag into the aborted IO. |
| 11754 | */ |
| 11755 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11756 | |
| 11757 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11758 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11759 | abtsiocbq, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11760 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11761 | } else { |
| 11762 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11763 | abtsiocbq, 0); |
| 11764 | } |
| 11765 | |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 11766 | spin_unlock(&lpfc_cmd->buf_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11767 | |
| 11768 | if (ret_val == IOCB_ERROR) |
| 11769 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11770 | else |
| 11771 | sum++; |
| 11772 | } |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11773 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11774 | return sum; |
| 11775 | } |
| 11776 | |
| 11777 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11778 | * 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] | 11779 | * @phba: Pointer to HBA context object. |
| 11780 | * @cmdiocbq: Pointer to command iocb. |
| 11781 | * @rspiocbq: Pointer to response iocb. |
| 11782 | * |
| 11783 | * This function is the completion handler for iocbs issued using |
| 11784 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11785 | * ring event handler function without any lock held. This function |
| 11786 | * can be called from both worker thread context and interrupt |
| 11787 | * context. This function also can be called from other thread which |
| 11788 | * cleans up the SLI layer objects. |
| 11789 | * This function copy the contents of the response iocb to the |
| 11790 | * response iocb memory object provided by the caller of |
| 11791 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11792 | * sleeps for the iocb completion. |
| 11793 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11794 | static void |
| 11795 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11796 | struct lpfc_iocbq *cmdiocbq, |
| 11797 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11798 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11799 | wait_queue_head_t *pdone_q; |
| 11800 | unsigned long iflags; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11801 | struct lpfc_io_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11802 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11803 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11804 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11805 | |
| 11806 | /* |
| 11807 | * A time out has occurred for the iocb. If a time out |
| 11808 | * completion handler has been supplied, call it. Otherwise, |
| 11809 | * just free the iocbq. |
| 11810 | */ |
| 11811 | |
| 11812 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11813 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11814 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11815 | if (cmdiocbq->iocb_cmpl) |
| 11816 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11817 | else |
| 11818 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11819 | return; |
| 11820 | } |
| 11821 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11822 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11823 | if (cmdiocbq->context2 && rspiocbq) |
| 11824 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11825 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11826 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11827 | /* Set the exchange busy flag for task management commands */ |
| 11828 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11829 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 11830 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf, |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11831 | cur_iocbq); |
| 11832 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 11833 | } |
| 11834 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11835 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11836 | if (pdone_q) |
| 11837 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11838 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11839 | return; |
| 11840 | } |
| 11841 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11842 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11843 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 11844 | * @phba: Pointer to HBA context object.. |
| 11845 | * @piocbq: Pointer to command iocb. |
| 11846 | * @flag: Flag to test. |
| 11847 | * |
| 11848 | * This routine grabs the hbalock and then test the iocb_flag to |
| 11849 | * see if the passed in flag is set. |
| 11850 | * Returns: |
| 11851 | * 1 if flag is set. |
| 11852 | * 0 if flag is not set. |
| 11853 | **/ |
| 11854 | static int |
| 11855 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 11856 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 11857 | { |
| 11858 | unsigned long iflags; |
| 11859 | int ret; |
| 11860 | |
| 11861 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11862 | ret = piocbq->iocb_flag & flag; |
| 11863 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11864 | return ret; |
| 11865 | |
| 11866 | } |
| 11867 | |
| 11868 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11869 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11870 | * @phba: Pointer to HBA context object.. |
| 11871 | * @pring: Pointer to sli ring. |
| 11872 | * @piocb: Pointer to command iocb. |
| 11873 | * @prspiocbq: Pointer to response iocb. |
| 11874 | * @timeout: Timeout in number of seconds. |
| 11875 | * |
| 11876 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11877 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 11878 | * to handle iocbs which time out. If the field is NULL, the |
| 11879 | * function shall free the iocbq structure. If more clean up is |
| 11880 | * needed, the caller is expected to provide a completion function |
| 11881 | * that will provide the needed clean up. If the iocb command is |
| 11882 | * not completed within timeout seconds, the function will either |
| 11883 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 11884 | * completion function set in the iocb_cmpl field and then return |
| 11885 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 11886 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11887 | * The function waits for the iocb completion using an |
| 11888 | * non-interruptible wait. |
| 11889 | * This function will sleep while waiting for iocb completion. |
| 11890 | * So, this function should not be called from any context which |
| 11891 | * does not allow sleeping. Due to the same reason, this function |
| 11892 | * cannot be called with interrupt disabled. |
| 11893 | * This function assumes that the iocb completions occur while |
| 11894 | * this function sleep. So, this function cannot be called from |
| 11895 | * the thread which process iocb completion for this ring. |
| 11896 | * This function clears the iocb_flag of the iocb object before |
| 11897 | * issuing the iocb and the iocb completion handler sets this |
| 11898 | * flag and wakes this thread when the iocb completes. |
| 11899 | * The contents of the response iocb will be copied to prspiocbq |
| 11900 | * by the completion handler when the command completes. |
| 11901 | * This function returns IOCB_SUCCESS when success. |
| 11902 | * This function is called with no lock held. |
| 11903 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11904 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11905 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11906 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11907 | struct lpfc_iocbq *piocb, |
| 11908 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11909 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11910 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11911 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11912 | long timeleft, timeout_req = 0; |
| 11913 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11914 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11915 | struct lpfc_iocbq *iocb; |
| 11916 | int txq_cnt = 0; |
| 11917 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11918 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11919 | unsigned long iflags; |
| 11920 | bool iocb_completed = true; |
| 11921 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11922 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 11923 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 11924 | else |
| 11925 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11926 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11927 | * If the caller has provided a response iocbq buffer, then context2 |
| 11928 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11929 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11930 | if (prspiocbq) { |
| 11931 | if (piocb->context2) |
| 11932 | return IOCB_ERROR; |
| 11933 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11934 | } |
| 11935 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11936 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11937 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 11938 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11939 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11940 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11941 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11942 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11943 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11944 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 11945 | writel(creg_val, phba->HCregaddr); |
| 11946 | readl(phba->HCregaddr); /* flush */ |
| 11947 | } |
| 11948 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11949 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 11950 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11951 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11952 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11953 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11954 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11955 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11956 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11957 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11958 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11959 | /* |
| 11960 | * IOCB timed out. Inform the wake iocb wait |
| 11961 | * completion function and set local status |
| 11962 | */ |
| 11963 | |
| 11964 | iocb_completed = false; |
| 11965 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 11966 | } |
| 11967 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11968 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11969 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11970 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 11971 | /* Note: we are not indicating if the IOCB has a success |
| 11972 | * status or not - that's for the caller to check. |
| 11973 | * IOCB_SUCCESS means just that the command was sent and |
| 11974 | * completed. Not that it completed successfully. |
| 11975 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11976 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11977 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11978 | "0338 IOCB wait timeout error - no " |
| 11979 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11980 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11981 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11982 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11983 | "0330 IOCB wake NOT set, " |
| 11984 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11985 | timeout, (timeleft / jiffies)); |
| 11986 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11987 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11988 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11989 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 11990 | list_for_each_entry(iocb, &pring->txq, list) { |
| 11991 | txq_cnt++; |
| 11992 | } |
| 11993 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 11994 | txcmplq_cnt++; |
| 11995 | } |
| 11996 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11997 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 11998 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 11999 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12000 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12001 | } else { |
| 12002 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12003 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12004 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12005 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12006 | } |
| 12007 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12008 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12009 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 12010 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 12011 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 12012 | writel(creg_val, phba->HCregaddr); |
| 12013 | readl(phba->HCregaddr); /* flush */ |
| 12014 | } |
| 12015 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12016 | if (prspiocbq) |
| 12017 | piocb->context2 = NULL; |
| 12018 | |
| 12019 | piocb->context_un.wait_queue = NULL; |
| 12020 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12021 | return retval; |
| 12022 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 12023 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12024 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12025 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12026 | * @phba: Pointer to HBA context object. |
| 12027 | * @pmboxq: Pointer to driver mailbox object. |
| 12028 | * @timeout: Timeout in number of seconds. |
| 12029 | * |
| 12030 | * This function issues the mailbox to firmware and waits for the |
| 12031 | * mailbox command to complete. If the mailbox command is not |
| 12032 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 12033 | * The function waits for the mailbox completion using an |
| 12034 | * interruptible wait. If the thread is woken up due to a |
| 12035 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 12036 | * should not free the mailbox resources, if this function returns |
| 12037 | * MBX_TIMEOUT. |
| 12038 | * This function will sleep while waiting for mailbox completion. |
| 12039 | * So, this function should not be called from any context which |
| 12040 | * does not allow sleeping. Due to the same reason, this function |
| 12041 | * cannot be called with interrupt disabled. |
| 12042 | * This function assumes that the mailbox completion occurs while |
| 12043 | * this function sleep. So, this function cannot be called from |
| 12044 | * the worker thread which processes mailbox completion. |
| 12045 | * This function is called in the context of HBA management |
| 12046 | * applications. |
| 12047 | * This function returns MBX_SUCCESS when successful. |
| 12048 | * This function is called with no lock held. |
| 12049 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12050 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12051 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12052 | uint32_t timeout) |
| 12053 | { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12054 | struct completion mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12055 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12056 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12057 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 12058 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12059 | /* setup wake call as IOCB callback */ |
| 12060 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12061 | |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12062 | /* setup context3 field to pass wait_queue pointer to wake function */ |
| 12063 | init_completion(&mbox_done); |
| 12064 | pmboxq->context3 = &mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12065 | /* now issue the command */ |
| 12066 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12067 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12068 | wait_for_completion_timeout(&mbox_done, |
| 12069 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12070 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12071 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 12072 | pmboxq->context3 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12073 | /* |
| 12074 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 12075 | * else do not free the resources. |
| 12076 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12077 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12078 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 12079 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 12080 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12081 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 12082 | } |
| 12083 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12084 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12085 | return retval; |
| 12086 | } |
| 12087 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12088 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12089 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12090 | * @phba: Pointer to HBA context. |
| 12091 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12092 | * This function is called to shutdown the driver's mailbox sub-system. |
| 12093 | * It first marks the mailbox sub-system is in a block state to prevent |
| 12094 | * the asynchronous mailbox command from issued off the pending mailbox |
| 12095 | * command queue. If the mailbox command sub-system shutdown is due to |
| 12096 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 12097 | * the mailbox sub-system flush routine to forcefully bring down the |
| 12098 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 12099 | * as with offline or HBA function reset), this routine will wait for the |
| 12100 | * outstanding mailbox command to complete before invoking the mailbox |
| 12101 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12102 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12103 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12104 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12105 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12106 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12107 | unsigned long timeout; |
| 12108 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12109 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 12110 | /* delay 100ms for port state */ |
| 12111 | msleep(100); |
| 12112 | lpfc_sli_mbox_sys_flush(phba); |
| 12113 | return; |
| 12114 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12115 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12116 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12117 | /* Disable softirqs, including timers from obtaining phba->hbalock */ |
| 12118 | local_bh_disable(); |
| 12119 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12120 | spin_lock_irq(&phba->hbalock); |
| 12121 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12122 | |
| 12123 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12124 | /* Determine how long we might wait for the active mailbox |
| 12125 | * command to be gracefully completed by firmware. |
| 12126 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12127 | if (phba->sli.mbox_active) |
| 12128 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 12129 | phba->sli.mbox_active) * |
| 12130 | 1000) + jiffies; |
| 12131 | spin_unlock_irq(&phba->hbalock); |
| 12132 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12133 | /* Enable softirqs again, done with phba->hbalock */ |
| 12134 | local_bh_enable(); |
| 12135 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12136 | while (phba->sli.mbox_active) { |
| 12137 | /* Check active mailbox complete status every 2ms */ |
| 12138 | msleep(2); |
| 12139 | if (time_after(jiffies, timeout)) |
| 12140 | /* Timeout, let the mailbox flush routine to |
| 12141 | * forcefully release active mailbox command |
| 12142 | */ |
| 12143 | break; |
| 12144 | } |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12145 | } else { |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 12146 | spin_unlock_irq(&phba->hbalock); |
| 12147 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12148 | /* Enable softirqs again, done with phba->hbalock */ |
| 12149 | local_bh_enable(); |
| 12150 | } |
| 12151 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12152 | lpfc_sli_mbox_sys_flush(phba); |
| 12153 | } |
| 12154 | |
| 12155 | /** |
| 12156 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 12157 | * @phba: Pointer to HBA context. |
| 12158 | * |
| 12159 | * This function is called to read the SLI3 device error attention registers |
| 12160 | * for possible error attention events. The caller must hold the hostlock |
| 12161 | * with spin_lock_irq(). |
| 12162 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12163 | * 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] | 12164 | * Register and returns 0 otherwise. |
| 12165 | **/ |
| 12166 | static int |
| 12167 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 12168 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12169 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12170 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12171 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12172 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12173 | goto unplug_err; |
| 12174 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12175 | if (ha_copy & HA_ERATT) { |
| 12176 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12177 | if (lpfc_sli_read_hs(phba)) |
| 12178 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12179 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12180 | /* Check if there is a deferred error condition is active */ |
| 12181 | if ((HS_FFER1 & phba->work_hs) && |
| 12182 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12183 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12184 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12185 | /* Clear all interrupt enable conditions */ |
| 12186 | writel(0, phba->HCregaddr); |
| 12187 | readl(phba->HCregaddr); |
| 12188 | } |
| 12189 | |
| 12190 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12191 | phba->work_ha |= HA_ERATT; |
| 12192 | /* Indicate polling handles this ERATT */ |
| 12193 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12194 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12195 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12196 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12197 | |
| 12198 | unplug_err: |
| 12199 | /* Set the driver HS work bitmap */ |
| 12200 | phba->work_hs |= UNPLUG_ERR; |
| 12201 | /* Set the driver HA work bitmap */ |
| 12202 | phba->work_ha |= HA_ERATT; |
| 12203 | /* Indicate polling handles this ERATT */ |
| 12204 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12205 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 12206 | } |
| 12207 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12208 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12209 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 12210 | * @phba: Pointer to HBA context. |
| 12211 | * |
| 12212 | * This function is called to read the SLI4 device error attention registers |
| 12213 | * for possible error attention events. The caller must hold the hostlock |
| 12214 | * with spin_lock_irq(). |
| 12215 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12216 | * 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] | 12217 | * Register and returns 0 otherwise. |
| 12218 | **/ |
| 12219 | static int |
| 12220 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 12221 | { |
| 12222 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12223 | uint32_t if_type, portsmphr; |
| 12224 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12225 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12226 | /* |
| 12227 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12228 | * registers for error attention. This can be changed later. |
| 12229 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12230 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 12231 | switch (if_type) { |
| 12232 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12233 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 12234 | &uerr_sta_lo) || |
| 12235 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 12236 | &uerr_sta_hi)) { |
| 12237 | phba->work_hs |= UNPLUG_ERR; |
| 12238 | phba->work_ha |= HA_ERATT; |
| 12239 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12240 | return 1; |
| 12241 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12242 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 12243 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 12244 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12245 | "1423 HBA Unrecoverable error: " |
| 12246 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 12247 | "ue_mask_lo_reg=0x%x, " |
| 12248 | "ue_mask_hi_reg=0x%x\n", |
| 12249 | uerr_sta_lo, uerr_sta_hi, |
| 12250 | phba->sli4_hba.ue_mask_lo, |
| 12251 | phba->sli4_hba.ue_mask_hi); |
| 12252 | phba->work_status[0] = uerr_sta_lo; |
| 12253 | phba->work_status[1] = uerr_sta_hi; |
| 12254 | phba->work_ha |= HA_ERATT; |
| 12255 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12256 | return 1; |
| 12257 | } |
| 12258 | break; |
| 12259 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 12260 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12261 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 12262 | &portstat_reg.word0) || |
| 12263 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 12264 | &portsmphr)){ |
| 12265 | phba->work_hs |= UNPLUG_ERR; |
| 12266 | phba->work_ha |= HA_ERATT; |
| 12267 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12268 | return 1; |
| 12269 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12270 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 12271 | phba->work_status[0] = |
| 12272 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 12273 | phba->work_status[1] = |
| 12274 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 12275 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12276 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12277 | "port status reg 0x%x, " |
| 12278 | "port smphr reg 0x%x, " |
| 12279 | "error 1=0x%x, error 2=0x%x\n", |
| 12280 | portstat_reg.word0, |
| 12281 | portsmphr, |
| 12282 | phba->work_status[0], |
| 12283 | phba->work_status[1]); |
| 12284 | phba->work_ha |= HA_ERATT; |
| 12285 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12286 | return 1; |
| 12287 | } |
| 12288 | break; |
| 12289 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 12290 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12291 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12292 | "2886 HBA Error Attention on unsupported " |
| 12293 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12294 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12295 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12296 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12297 | return 0; |
| 12298 | } |
| 12299 | |
| 12300 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12301 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12302 | * @phba: Pointer to HBA context. |
| 12303 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12304 | * 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] | 12305 | * error attention register bit for error attention events. |
| 12306 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12307 | * 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] | 12308 | * Register and returns 0 otherwise. |
| 12309 | **/ |
| 12310 | int |
| 12311 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 12312 | { |
| 12313 | uint32_t ha_copy; |
| 12314 | |
| 12315 | /* If somebody is waiting to handle an eratt, don't process it |
| 12316 | * here. The brdkill function will do this. |
| 12317 | */ |
| 12318 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12319 | return 0; |
| 12320 | |
| 12321 | /* Check if interrupt handler handles this ERATT */ |
| 12322 | spin_lock_irq(&phba->hbalock); |
| 12323 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 12324 | /* Interrupt handler has handled ERATT */ |
| 12325 | spin_unlock_irq(&phba->hbalock); |
| 12326 | return 0; |
| 12327 | } |
| 12328 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12329 | /* |
| 12330 | * If there is deferred error attention, do not check for error |
| 12331 | * attention |
| 12332 | */ |
| 12333 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 12334 | spin_unlock_irq(&phba->hbalock); |
| 12335 | return 0; |
| 12336 | } |
| 12337 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12338 | /* If PCI channel is offline, don't process it */ |
| 12339 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12340 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12341 | return 0; |
| 12342 | } |
| 12343 | |
| 12344 | switch (phba->sli_rev) { |
| 12345 | case LPFC_SLI_REV2: |
| 12346 | case LPFC_SLI_REV3: |
| 12347 | /* Read chip Host Attention (HA) register */ |
| 12348 | ha_copy = lpfc_sli_eratt_read(phba); |
| 12349 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12350 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 12351 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12352 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 12353 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12354 | default: |
| 12355 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12356 | "0299 Invalid SLI revision (%d)\n", |
| 12357 | phba->sli_rev); |
| 12358 | ha_copy = 0; |
| 12359 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12360 | } |
| 12361 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12362 | |
| 12363 | return ha_copy; |
| 12364 | } |
| 12365 | |
| 12366 | /** |
| 12367 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 12368 | * @phba: Pointer to HBA context. |
| 12369 | * |
| 12370 | * This inline routine checks whether a device or its PCI slot is in a state |
| 12371 | * that the interrupt should be handled. |
| 12372 | * |
| 12373 | * This function returns 0 if the device or the PCI slot is in a state that |
| 12374 | * interrupt should be handled, otherwise -EIO. |
| 12375 | */ |
| 12376 | static inline int |
| 12377 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 12378 | { |
| 12379 | /* If the pci channel is offline, ignore all the interrupts */ |
| 12380 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 12381 | return -EIO; |
| 12382 | |
| 12383 | /* Update device level interrupt statistics */ |
| 12384 | phba->sli.slistat.sli_intr++; |
| 12385 | |
| 12386 | /* Ignore all interrupts during initialization. */ |
| 12387 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 12388 | return -EIO; |
| 12389 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12390 | return 0; |
| 12391 | } |
| 12392 | |
| 12393 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12394 | * 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] | 12395 | * @irq: Interrupt number. |
| 12396 | * @dev_id: The device context pointer. |
| 12397 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12398 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12399 | * service routine when device with SLI-3 interface spec is enabled with |
| 12400 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 12401 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 12402 | * interrupt mode, this function is called as part of the device-level |
| 12403 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 12404 | * is undergoing initialization, the interrupt handler will not process |
| 12405 | * the interrupt. The link attention and ELS ring attention events are |
| 12406 | * handled by the worker thread. The interrupt handler signals the worker |
| 12407 | * thread and returns for these events. This function is called without |
| 12408 | * 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] | 12409 | * structures. |
| 12410 | * |
| 12411 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12412 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12413 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12414 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12415 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12416 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12417 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12418 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12419 | uint32_t work_ha_copy; |
| 12420 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12421 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12422 | uint32_t control; |
| 12423 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12424 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12425 | struct lpfc_vport *vport; |
| 12426 | struct lpfc_nodelist *ndlp; |
| 12427 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12428 | LPFC_MBOXQ_t *pmb; |
| 12429 | int rc; |
| 12430 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12431 | /* |
| 12432 | * Get the driver's phba structure from the dev_id and |
| 12433 | * assume the HBA is not interrupting. |
| 12434 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12435 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12436 | |
| 12437 | if (unlikely(!phba)) |
| 12438 | return IRQ_NONE; |
| 12439 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12440 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12441 | * Stuff needs to be attented to when this function is invoked as an |
| 12442 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12443 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12444 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12445 | /* Check device state for handling interrupt */ |
| 12446 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12447 | return IRQ_NONE; |
| 12448 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12449 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12450 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12451 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12452 | /* If somebody is waiting to handle an eratt don't process it |
| 12453 | * here. The brdkill function will do this. |
| 12454 | */ |
| 12455 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12456 | ha_copy &= ~HA_ERATT; |
| 12457 | /* Check the need for handling ERATT in interrupt handler */ |
| 12458 | if (ha_copy & HA_ERATT) { |
| 12459 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12460 | /* ERATT polling has handled ERATT */ |
| 12461 | ha_copy &= ~HA_ERATT; |
| 12462 | else |
| 12463 | /* Indicate interrupt handler handles ERATT */ |
| 12464 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12465 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12466 | |
| 12467 | /* |
| 12468 | * If there is deferred error attention, do not check for any |
| 12469 | * interrupt. |
| 12470 | */ |
| 12471 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12472 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12473 | return IRQ_NONE; |
| 12474 | } |
| 12475 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12476 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12477 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 12478 | goto unplug_error; |
| 12479 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12480 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 12481 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12482 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12483 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 12484 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12485 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12486 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12487 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12488 | } else |
| 12489 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12490 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12491 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 12492 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12493 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12494 | if (work_ha_copy & HA_LATT) { |
| 12495 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 12496 | /* |
| 12497 | * Turn off Link Attention interrupts |
| 12498 | * until CLEAR_LA done |
| 12499 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12500 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12501 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12502 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12503 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12504 | control &= ~HC_LAINT_ENA; |
| 12505 | writel(control, phba->HCregaddr); |
| 12506 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12507 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12508 | } |
| 12509 | else |
| 12510 | work_ha_copy &= ~HA_LATT; |
| 12511 | } |
| 12512 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12513 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12514 | /* |
| 12515 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 12516 | * the only slow ring. |
| 12517 | */ |
| 12518 | status = (work_ha_copy & |
| 12519 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12520 | status >>= (4*LPFC_ELS_RING); |
| 12521 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12522 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12523 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12524 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12525 | |
| 12526 | lpfc_debugfs_slow_ring_trc(phba, |
| 12527 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 12528 | control, status, |
| 12529 | (uint32_t)phba->sli.slistat.sli_intr); |
| 12530 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12531 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12532 | lpfc_debugfs_slow_ring_trc(phba, |
| 12533 | "ISR Disable ring:" |
| 12534 | "pwork:x%x hawork:x%x wait:x%x", |
| 12535 | phba->work_ha, work_ha_copy, |
| 12536 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12537 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12538 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12539 | control &= |
| 12540 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12541 | writel(control, phba->HCregaddr); |
| 12542 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12543 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12544 | else { |
| 12545 | lpfc_debugfs_slow_ring_trc(phba, |
| 12546 | "ISR slow ring: pwork:" |
| 12547 | "x%x hawork:x%x wait:x%x", |
| 12548 | phba->work_ha, work_ha_copy, |
| 12549 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12550 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12551 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12552 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12553 | } |
| 12554 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12555 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12556 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12557 | if (lpfc_sli_read_hs(phba)) |
| 12558 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12559 | /* |
| 12560 | * Check if there is a deferred error condition |
| 12561 | * is active |
| 12562 | */ |
| 12563 | if ((HS_FFER1 & phba->work_hs) && |
| 12564 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12565 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 12566 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12567 | phba->hba_flag |= DEFER_ERATT; |
| 12568 | /* Clear all interrupt enable conditions */ |
| 12569 | writel(0, phba->HCregaddr); |
| 12570 | readl(phba->HCregaddr); |
| 12571 | } |
| 12572 | } |
| 12573 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12574 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12575 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12576 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12577 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12578 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12579 | |
| 12580 | /* First check out the status word */ |
| 12581 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 12582 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12583 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12584 | /* |
| 12585 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 12586 | * mbxStatus <status> |
| 12587 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12588 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12589 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12590 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12591 | "Interrupt mbxCommand x%x " |
| 12592 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12593 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12594 | pmbox->mbxCommand, |
| 12595 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12596 | /* clear mailbox attention bit */ |
| 12597 | work_ha_copy &= ~HA_MBATT; |
| 12598 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12599 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12600 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12601 | phba->last_completion_time = jiffies; |
| 12602 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12603 | if (pmb->mbox_cmpl) { |
| 12604 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 12605 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12606 | if (pmb->out_ext_byte_len && |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12607 | pmb->ctx_buf) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12608 | lpfc_sli_pcimem_bcopy( |
| 12609 | phba->mbox_ext, |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12610 | pmb->ctx_buf, |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12611 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12612 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12613 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12614 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12615 | |
| 12616 | lpfc_debugfs_disc_trc(vport, |
| 12617 | LPFC_DISC_TRC_MBOX_VPORT, |
| 12618 | "MBOX dflt rpi: : " |
| 12619 | "status:x%x rpi:x%x", |
| 12620 | (uint32_t)pmbox->mbxStatus, |
| 12621 | pmbox->un.varWords[0], 0); |
| 12622 | |
| 12623 | if (!pmbox->mbxStatus) { |
| 12624 | mp = (struct lpfc_dmabuf *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12625 | (pmb->ctx_buf); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12626 | ndlp = (struct lpfc_nodelist *) |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12627 | pmb->ctx_ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12628 | |
| 12629 | /* Reg_LOGIN of dflt RPI was |
| 12630 | * successful. new lets get |
| 12631 | * rid of the RPI using the |
| 12632 | * same mbox buffer. |
| 12633 | */ |
| 12634 | lpfc_unreg_login(phba, |
| 12635 | vport->vpi, |
| 12636 | pmbox->un.varWords[0], |
| 12637 | pmb); |
| 12638 | pmb->mbox_cmpl = |
| 12639 | lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 12640 | pmb->ctx_buf = mp; |
| 12641 | pmb->ctx_ndlp = ndlp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12642 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12643 | rc = lpfc_sli_issue_mbox(phba, |
| 12644 | pmb, |
| 12645 | MBX_NOWAIT); |
| 12646 | if (rc != MBX_BUSY) |
| 12647 | lpfc_printf_log(phba, |
| 12648 | KERN_ERR, |
| 12649 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12650 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12651 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12652 | if (rc != MBX_NOT_FINISHED) |
| 12653 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12654 | } |
| 12655 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12656 | spin_lock_irqsave( |
| 12657 | &phba->pport->work_port_lock, |
| 12658 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12659 | phba->pport->work_port_events &= |
| 12660 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12661 | spin_unlock_irqrestore( |
| 12662 | &phba->pport->work_port_lock, |
| 12663 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12664 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12665 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12666 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12667 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12668 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12669 | if ((work_ha_copy & HA_MBATT) && |
| 12670 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12671 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12672 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12673 | do { |
| 12674 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12675 | MBX_NOWAIT); |
| 12676 | } while (rc == MBX_NOT_FINISHED); |
| 12677 | if (rc != MBX_SUCCESS) |
| 12678 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12679 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12680 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12681 | } |
| 12682 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12683 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12684 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12685 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12686 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12687 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12688 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12689 | unplug_error: |
| 12690 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12691 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12692 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12693 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12694 | |
| 12695 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12696 | * 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] | 12697 | * @irq: Interrupt number. |
| 12698 | * @dev_id: The device context pointer. |
| 12699 | * |
| 12700 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12701 | * service routine when device with SLI-3 interface spec is enabled with |
| 12702 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12703 | * ring event in the HBA. However, when the device is enabled with either |
| 12704 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12705 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12706 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12707 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12708 | * the intrrupt context. This function is called without any lock held. |
| 12709 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12710 | * |
| 12711 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12712 | * returns IRQ_NONE. |
| 12713 | **/ |
| 12714 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12715 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12716 | { |
| 12717 | struct lpfc_hba *phba; |
| 12718 | uint32_t ha_copy; |
| 12719 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12720 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12721 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12722 | |
| 12723 | /* Get the driver's phba structure from the dev_id and |
| 12724 | * assume the HBA is not interrupting. |
| 12725 | */ |
| 12726 | phba = (struct lpfc_hba *) dev_id; |
| 12727 | |
| 12728 | if (unlikely(!phba)) |
| 12729 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12730 | |
| 12731 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12732 | * Stuff needs to be attented to when this function is invoked as an |
| 12733 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12734 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12735 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12736 | /* Check device state for handling interrupt */ |
| 12737 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12738 | return IRQ_NONE; |
| 12739 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12740 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12741 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12742 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12743 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12744 | /* |
| 12745 | * If there is deferred error attention, do not check for |
| 12746 | * any interrupt. |
| 12747 | */ |
| 12748 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12749 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12750 | return IRQ_NONE; |
| 12751 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12752 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12753 | phba->HAregaddr); |
| 12754 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12755 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12756 | } else |
| 12757 | ha_copy = phba->ha_copy; |
| 12758 | |
| 12759 | /* |
| 12760 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12761 | */ |
| 12762 | ha_copy &= ~(phba->work_ha_mask); |
| 12763 | |
| 12764 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12765 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12766 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12767 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12768 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12769 | |
| 12770 | if (phba->cfg_multi_ring_support == 2) { |
| 12771 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12772 | * Process all events on extra ring. Take the optimized path |
| 12773 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12774 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12775 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12776 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12777 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12778 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12779 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12780 | status); |
| 12781 | } |
| 12782 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12783 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12784 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12785 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12786 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12787 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12788 | * @irq: Interrupt number. |
| 12789 | * @dev_id: The device context pointer. |
| 12790 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12791 | * This function is the HBA device-level interrupt handler to device with |
| 12792 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12793 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12794 | * requires driver attention. This function invokes the slow-path interrupt |
| 12795 | * attention handling function and fast-path interrupt attention handling |
| 12796 | * function in turn to process the relevant HBA attention events. This |
| 12797 | * function is called without any lock held. It gets the hbalock to access |
| 12798 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12799 | * |
| 12800 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12801 | * returns IRQ_NONE. |
| 12802 | **/ |
| 12803 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12804 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12805 | { |
| 12806 | struct lpfc_hba *phba; |
| 12807 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12808 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12809 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12810 | |
| 12811 | /* |
| 12812 | * Get the driver's phba structure from the dev_id and |
| 12813 | * assume the HBA is not interrupting. |
| 12814 | */ |
| 12815 | phba = (struct lpfc_hba *) dev_id; |
| 12816 | |
| 12817 | if (unlikely(!phba)) |
| 12818 | return IRQ_NONE; |
| 12819 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12820 | /* Check device state for handling interrupt */ |
| 12821 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12822 | return IRQ_NONE; |
| 12823 | |
| 12824 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12825 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12826 | spin_unlock(&phba->hbalock); |
| 12827 | return IRQ_HANDLED; |
| 12828 | } |
| 12829 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12830 | if (unlikely(!phba->ha_copy)) { |
| 12831 | spin_unlock(&phba->hbalock); |
| 12832 | return IRQ_NONE; |
| 12833 | } else if (phba->ha_copy & HA_ERATT) { |
| 12834 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12835 | /* ERATT polling has handled ERATT */ |
| 12836 | phba->ha_copy &= ~HA_ERATT; |
| 12837 | else |
| 12838 | /* Indicate interrupt handler handles ERATT */ |
| 12839 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12840 | } |
| 12841 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12842 | /* |
| 12843 | * If there is deferred error attention, do not check for any interrupt. |
| 12844 | */ |
| 12845 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 12846 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12847 | return IRQ_NONE; |
| 12848 | } |
| 12849 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12850 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12851 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 12852 | spin_unlock(&phba->hbalock); |
| 12853 | return IRQ_HANDLED; |
| 12854 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12855 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 12856 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12857 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12858 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12859 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12860 | readl(phba->HAregaddr); /* flush */ |
| 12861 | spin_unlock(&phba->hbalock); |
| 12862 | |
| 12863 | /* |
| 12864 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12865 | */ |
| 12866 | |
| 12867 | /* status of events with mailbox and link attention */ |
| 12868 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 12869 | |
| 12870 | /* status of events with ELS ring */ |
| 12871 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12872 | status2 >>= (4*LPFC_ELS_RING); |
| 12873 | |
| 12874 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12875 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12876 | else |
| 12877 | sp_irq_rc = IRQ_NONE; |
| 12878 | |
| 12879 | /* |
| 12880 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12881 | */ |
| 12882 | |
| 12883 | /* status of events with FCP ring */ |
| 12884 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 12885 | status1 >>= (4*LPFC_FCP_RING); |
| 12886 | |
| 12887 | /* status of events with extra ring */ |
| 12888 | if (phba->cfg_multi_ring_support == 2) { |
| 12889 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 12890 | status2 >>= (4*LPFC_EXTRA_RING); |
| 12891 | } else |
| 12892 | status2 = 0; |
| 12893 | |
| 12894 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12895 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12896 | else |
| 12897 | fp_irq_rc = IRQ_NONE; |
| 12898 | |
| 12899 | /* Return device-level interrupt handling status */ |
| 12900 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12901 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12902 | |
| 12903 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12904 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 12905 | * @phba: pointer to lpfc hba data structure. |
| 12906 | * |
| 12907 | * This routine is invoked by the worker thread to process all the pending |
| 12908 | * SLI4 els abort xri events. |
| 12909 | **/ |
| 12910 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12911 | { |
| 12912 | struct lpfc_cq_event *cq_event; |
| 12913 | |
| 12914 | /* First, declare the els xri abort event has been handled */ |
| 12915 | spin_lock_irq(&phba->hbalock); |
| 12916 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 12917 | spin_unlock_irq(&phba->hbalock); |
| 12918 | /* Now, handle all the els xri abort events */ |
| 12919 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 12920 | /* Get the first event from the head of the event queue */ |
| 12921 | spin_lock_irq(&phba->hbalock); |
| 12922 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 12923 | cq_event, struct lpfc_cq_event, list); |
| 12924 | spin_unlock_irq(&phba->hbalock); |
| 12925 | /* Notify aborted XRI for ELS work queue */ |
| 12926 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12927 | /* Free the event processed back to the free pool */ |
| 12928 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12929 | } |
| 12930 | } |
| 12931 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12932 | /** |
| 12933 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 12934 | * @phba: pointer to lpfc hba data structure |
| 12935 | * @pIocbIn: pointer to the rspiocbq |
| 12936 | * @pIocbOut: pointer to the cmdiocbq |
| 12937 | * @wcqe: pointer to the complete wcqe |
| 12938 | * |
| 12939 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 12940 | * by copying all the IOCB fields from command iocbq and transferring the |
| 12941 | * completion status information from the complete wcqe. |
| 12942 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12943 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12944 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 12945 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12946 | struct lpfc_iocbq *pIocbOut, |
| 12947 | struct lpfc_wcqe_complete *wcqe) |
| 12948 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12949 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12950 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12951 | uint32_t status, max_response; |
| 12952 | struct lpfc_dmabuf *dmabuf; |
| 12953 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12954 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 12955 | |
| 12956 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 12957 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12958 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12959 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 12960 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12961 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 12962 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 12963 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 12964 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 12965 | wcqe->total_data_placed; |
| 12966 | else |
| 12967 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12968 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12969 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12970 | switch (pIocbOut->iocb.ulpCommand) { |
| 12971 | case CMD_ELS_REQUEST64_CR: |
| 12972 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12973 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12974 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 12975 | max_response = bde.tus.f.bdeSize; |
| 12976 | break; |
| 12977 | case CMD_GEN_REQUEST64_CR: |
| 12978 | max_response = 0; |
| 12979 | if (!pIocbOut->context3) |
| 12980 | break; |
| 12981 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 12982 | sizeof(struct ulp_bde64); |
| 12983 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12984 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12985 | for (i = 0; i < numBdes; i++) { |
| 12986 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 12987 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 12988 | max_response += bde.tus.f.bdeSize; |
| 12989 | } |
| 12990 | break; |
| 12991 | default: |
| 12992 | max_response = wcqe->total_data_placed; |
| 12993 | break; |
| 12994 | } |
| 12995 | if (max_response < wcqe->total_data_placed) |
| 12996 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 12997 | else |
| 12998 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 12999 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 13000 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13001 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 13002 | /* Convert BG errors for completion status */ |
| 13003 | if (status == CQE_STATUS_DI_ERROR) { |
| 13004 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 13005 | |
| 13006 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 13007 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 13008 | else |
| 13009 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 13010 | |
| 13011 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 13012 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 13013 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13014 | BGS_GUARD_ERR_MASK; |
| 13015 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 13016 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13017 | BGS_APPTAG_ERR_MASK; |
| 13018 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 13019 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13020 | BGS_REFTAG_ERR_MASK; |
| 13021 | |
| 13022 | /* Check to see if there was any good data before the error */ |
| 13023 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 13024 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13025 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 13026 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 13027 | wcqe->total_data_placed; |
| 13028 | } |
| 13029 | |
| 13030 | /* |
| 13031 | * Set ALL the error bits to indicate we don't know what |
| 13032 | * type of error it is. |
| 13033 | */ |
| 13034 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 13035 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 13036 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 13037 | BGS_GUARD_ERR_MASK); |
| 13038 | } |
| 13039 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13040 | /* Pick up HBA exchange busy condition */ |
| 13041 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 13042 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13043 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 13044 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13045 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13046 | } |
| 13047 | |
| 13048 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13049 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 13050 | * @phba: Pointer to HBA context object. |
| 13051 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13052 | * |
| 13053 | * This routine handles an ELS work-queue completion event and construct |
| 13054 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 13055 | * discovery engine to handle. |
| 13056 | * |
| 13057 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 13058 | **/ |
| 13059 | static struct lpfc_iocbq * |
| 13060 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 13061 | struct lpfc_iocbq *irspiocbq) |
| 13062 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13063 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13064 | struct lpfc_iocbq *cmdiocbq; |
| 13065 | struct lpfc_wcqe_complete *wcqe; |
| 13066 | unsigned long iflags; |
| 13067 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13068 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 13069 | if (unlikely(!pring)) |
| 13070 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13071 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13072 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13073 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13074 | pring->stats.iocb_event++; |
| 13075 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 13076 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13077 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13078 | if (unlikely(!cmdiocbq)) { |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13079 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13080 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13081 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13082 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 13083 | wcqe->word0, wcqe->total_data_placed, |
| 13084 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13085 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 13086 | return NULL; |
| 13087 | } |
| 13088 | |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 13089 | /* Put the iocb back on the txcmplq */ |
| 13090 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 13091 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 13092 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13093 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13094 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13095 | |
| 13096 | return irspiocbq; |
| 13097 | } |
| 13098 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13099 | inline struct lpfc_cq_event * |
| 13100 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 13101 | { |
| 13102 | struct lpfc_cq_event *cq_event; |
| 13103 | |
| 13104 | /* Allocate a new internal CQ_EVENT entry */ |
| 13105 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 13106 | if (!cq_event) { |
| 13107 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13108 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 13109 | return NULL; |
| 13110 | } |
| 13111 | |
| 13112 | /* Move the CQE into the event */ |
| 13113 | memcpy(&cq_event->cqe, entry, size); |
| 13114 | return cq_event; |
| 13115 | } |
| 13116 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13117 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13118 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 13119 | * @phba: Pointer to HBA context object. |
| 13120 | * @cqe: Pointer to mailbox completion queue entry. |
| 13121 | * |
| 13122 | * This routine process a mailbox completion queue entry with asynchrous |
| 13123 | * event. |
| 13124 | * |
| 13125 | * Return: true if work posted to worker thread, otherwise false. |
| 13126 | **/ |
| 13127 | static bool |
| 13128 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13129 | { |
| 13130 | struct lpfc_cq_event *cq_event; |
| 13131 | unsigned long iflags; |
| 13132 | |
| 13133 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13134 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 13135 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 13136 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 13137 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13138 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 13139 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13140 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13141 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13142 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 13143 | /* Set the async event flag */ |
| 13144 | phba->hba_flag |= ASYNC_EVENT; |
| 13145 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13146 | |
| 13147 | return true; |
| 13148 | } |
| 13149 | |
| 13150 | /** |
| 13151 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 13152 | * @phba: Pointer to HBA context object. |
| 13153 | * @cqe: Pointer to mailbox completion queue entry. |
| 13154 | * |
| 13155 | * This routine process a mailbox completion queue entry with mailbox |
| 13156 | * completion event. |
| 13157 | * |
| 13158 | * Return: true if work posted to worker thread, otherwise false. |
| 13159 | **/ |
| 13160 | static bool |
| 13161 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 13162 | { |
| 13163 | uint32_t mcqe_status; |
| 13164 | MAILBOX_t *mbox, *pmbox; |
| 13165 | struct lpfc_mqe *mqe; |
| 13166 | struct lpfc_vport *vport; |
| 13167 | struct lpfc_nodelist *ndlp; |
| 13168 | struct lpfc_dmabuf *mp; |
| 13169 | unsigned long iflags; |
| 13170 | LPFC_MBOXQ_t *pmb; |
| 13171 | bool workposted = false; |
| 13172 | int rc; |
| 13173 | |
| 13174 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 13175 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 13176 | goto out_no_mqe_complete; |
| 13177 | |
| 13178 | /* Get the reference to the active mbox command */ |
| 13179 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13180 | pmb = phba->sli.mbox_active; |
| 13181 | if (unlikely(!pmb)) { |
| 13182 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 13183 | "1832 No pending MBOX command to handle\n"); |
| 13184 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13185 | goto out_no_mqe_complete; |
| 13186 | } |
| 13187 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13188 | mqe = &pmb->u.mqe; |
| 13189 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 13190 | mbox = phba->mbox; |
| 13191 | vport = pmb->vport; |
| 13192 | |
| 13193 | /* Reset heartbeat timer */ |
| 13194 | phba->last_completion_time = jiffies; |
| 13195 | del_timer(&phba->sli.mbox_tmo); |
| 13196 | |
| 13197 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 13198 | if (pmb->mbox_cmpl && mbox) |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13199 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13200 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 13201 | /* |
| 13202 | * For mcqe errors, conditionally move a modified error code to |
| 13203 | * the mbox so that the error will not be missed. |
| 13204 | */ |
| 13205 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 13206 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 13207 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 13208 | bf_set(lpfc_mqe_status, mqe, |
| 13209 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 13210 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13211 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 13212 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 13213 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 13214 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 13215 | mcqe_status, |
| 13216 | pmbox->un.varWords[0], 0); |
| 13217 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13218 | mp = (struct lpfc_dmabuf *)(pmb->ctx_buf); |
| 13219 | ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13220 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 13221 | * RID of the PPI using the same mbox buffer. |
| 13222 | */ |
| 13223 | lpfc_unreg_login(phba, vport->vpi, |
| 13224 | pmbox->un.varWords[0], pmb); |
| 13225 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 13226 | pmb->ctx_buf = mp; |
| 13227 | pmb->ctx_ndlp = ndlp; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13228 | pmb->vport = vport; |
| 13229 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 13230 | if (rc != MBX_BUSY) |
| 13231 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 13232 | LOG_SLI, "0385 rc should " |
| 13233 | "have been MBX_BUSY\n"); |
| 13234 | if (rc != MBX_NOT_FINISHED) |
| 13235 | goto send_current_mbox; |
| 13236 | } |
| 13237 | } |
| 13238 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 13239 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 13240 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 13241 | |
| 13242 | /* There is mailbox completion work to do */ |
| 13243 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13244 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 13245 | phba->work_ha |= HA_MBATT; |
| 13246 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13247 | workposted = true; |
| 13248 | |
| 13249 | send_current_mbox: |
| 13250 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13251 | /* Release the mailbox command posting token */ |
| 13252 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 13253 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 13254 | phba->sli.mbox_active = NULL; |
| 13255 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13256 | /* Wake up worker thread to post the next pending mailbox command */ |
| 13257 | lpfc_worker_wake_up(phba); |
| 13258 | out_no_mqe_complete: |
| 13259 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 13260 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 13261 | return workposted; |
| 13262 | } |
| 13263 | |
| 13264 | /** |
| 13265 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 13266 | * @phba: Pointer to HBA context object. |
| 13267 | * @cqe: Pointer to mailbox completion queue entry. |
| 13268 | * |
| 13269 | * This routine process a mailbox completion queue entry, it invokes the |
| 13270 | * proper mailbox complete handling or asynchrous event handling routine |
| 13271 | * according to the MCQE's async bit. |
| 13272 | * |
| 13273 | * Return: true if work posted to worker thread, otherwise false. |
| 13274 | **/ |
| 13275 | static bool |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13276 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13277 | struct lpfc_cqe *cqe) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13278 | { |
| 13279 | struct lpfc_mcqe mcqe; |
| 13280 | bool workposted; |
| 13281 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13282 | cq->CQ_mbox++; |
| 13283 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13284 | /* Copy the mailbox MCQE and convert endian order as needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13285 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 13286 | |
| 13287 | /* Invoke the proper event handling routine */ |
| 13288 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 13289 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 13290 | else |
| 13291 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 13292 | return workposted; |
| 13293 | } |
| 13294 | |
| 13295 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13296 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 13297 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13298 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13299 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13300 | * |
| 13301 | * This routine handles an ELS work-queue completion event. |
| 13302 | * |
| 13303 | * Return: true if work posted to worker thread, otherwise false. |
| 13304 | **/ |
| 13305 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13306 | 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] | 13307 | struct lpfc_wcqe_complete *wcqe) |
| 13308 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13309 | struct lpfc_iocbq *irspiocbq; |
| 13310 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13311 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13312 | int txq_cnt = 0; |
| 13313 | int txcmplq_cnt = 0; |
| 13314 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13315 | |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13316 | /* Check for response status */ |
| 13317 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13318 | /* Log the error status */ |
| 13319 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13320 | "0357 ELS CQE error: status=x%x: " |
| 13321 | "CQE: %08x %08x %08x %08x\n", |
| 13322 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13323 | wcqe->word0, wcqe->total_data_placed, |
| 13324 | wcqe->parameter, wcqe->word3); |
| 13325 | } |
| 13326 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13327 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13328 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 13329 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13330 | if (!list_empty(&pring->txq)) |
| 13331 | txq_cnt++; |
| 13332 | if (!list_empty(&pring->txcmplq)) |
| 13333 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13334 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 13335 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 13336 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 13337 | txq_cnt, phba->iocb_cnt, |
| 13338 | fcp_txcmplq_cnt, |
| 13339 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13340 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13341 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13342 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13343 | /* Save off the slow-path queue event for work thread to process */ |
| 13344 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13345 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13346 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13347 | &phba->sli4_hba.sp_queue_event); |
| 13348 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13349 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13350 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13351 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13352 | } |
| 13353 | |
| 13354 | /** |
| 13355 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 13356 | * @phba: Pointer to HBA context object. |
| 13357 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13358 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13359 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13360 | * proper WQ release routine to the slow-path WQ. |
| 13361 | **/ |
| 13362 | static void |
| 13363 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 13364 | struct lpfc_wcqe_release *wcqe) |
| 13365 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13366 | /* sanity check on queue memory */ |
| 13367 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 13368 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13369 | /* Check for the slow-path ELS work queue */ |
| 13370 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 13371 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 13372 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13373 | else |
| 13374 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13375 | "2579 Slow-path wqe consume event carries " |
| 13376 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 13377 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 13378 | phba->sli4_hba.els_wq->queue_id); |
| 13379 | } |
| 13380 | |
| 13381 | /** |
| 13382 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 13383 | * @phba: Pointer to HBA context object. |
| 13384 | * @cq: Pointer to a WQ completion queue. |
| 13385 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13386 | * |
| 13387 | * This routine handles an XRI abort event. |
| 13388 | * |
| 13389 | * Return: true if work posted to worker thread, otherwise false. |
| 13390 | **/ |
| 13391 | static bool |
| 13392 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 13393 | struct lpfc_queue *cq, |
| 13394 | struct sli4_wcqe_xri_aborted *wcqe) |
| 13395 | { |
| 13396 | bool workposted = false; |
| 13397 | struct lpfc_cq_event *cq_event; |
| 13398 | unsigned long iflags; |
| 13399 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13400 | switch (cq->subtype) { |
| 13401 | case LPFC_FCP: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13402 | lpfc_sli4_fcp_xri_aborted(phba, wcqe, cq->hdwq); |
| 13403 | workposted = false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13404 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 13405 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13406 | case LPFC_ELS: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13407 | cq_event = lpfc_cq_event_setup( |
| 13408 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 13409 | if (!cq_event) |
| 13410 | return false; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13411 | cq_event->hdwq = cq->hdwq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13412 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13413 | list_add_tail(&cq_event->list, |
| 13414 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 13415 | /* Set the els xri abort event flag */ |
| 13416 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 13417 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13418 | workposted = true; |
| 13419 | break; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13420 | case LPFC_NVME: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13421 | /* Notify aborted XRI for NVME work queue */ |
| 13422 | if (phba->nvmet_support) |
| 13423 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 13424 | else |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13425 | lpfc_sli4_nvme_xri_aborted(phba, wcqe, cq->hdwq); |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13426 | |
| 13427 | workposted = false; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13428 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13429 | default: |
| 13430 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13431 | "0603 Invalid CQ subtype %d: " |
| 13432 | "%08x %08x %08x %08x\n", |
| 13433 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 13434 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13435 | workposted = false; |
| 13436 | break; |
| 13437 | } |
| 13438 | return workposted; |
| 13439 | } |
| 13440 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13441 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 13442 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13443 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13444 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13445 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13446 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13447 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13448 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13449 | * |
| 13450 | * Return: true if work posted to worker thread, otherwise false. |
| 13451 | **/ |
| 13452 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13453 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 13454 | { |
| 13455 | bool workposted = false; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13456 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13457 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 13458 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13459 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13460 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13461 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13462 | unsigned long iflags; |
| 13463 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13464 | /* sanity check on queue memory */ |
| 13465 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13466 | return workposted; |
| 13467 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13468 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13469 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13470 | else |
| 13471 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13472 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13473 | goto out; |
| 13474 | |
| 13475 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13476 | switch (status) { |
| 13477 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13478 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13479 | "2537 Receive Frame Truncated!!\n"); |
| 13480 | case FC_STATUS_RQ_SUCCESS: |
| 13481 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13482 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13483 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 13484 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13485 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13486 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13487 | goto out; |
| 13488 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13489 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13490 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13491 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13492 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 13493 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13494 | |
| 13495 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 13496 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 13497 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13498 | /* Handle MDS Loopback frames */ |
| 13499 | lpfc_sli4_handle_mds_loopback(phba->pport, dma_buf); |
| 13500 | break; |
| 13501 | } |
| 13502 | |
| 13503 | /* save off the frame for the work thread to process */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13504 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13505 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13506 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13507 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13508 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13509 | workposted = true; |
| 13510 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13511 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13512 | if (phba->nvmet_support) { |
| 13513 | tgtp = phba->targetport->private; |
| 13514 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13515 | "6402 RQE Error x%x, posted %d err_cnt " |
| 13516 | "%d: %x %x %x\n", |
| 13517 | status, hrq->RQ_buf_posted, |
| 13518 | hrq->RQ_no_posted_buf, |
| 13519 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13520 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13521 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13522 | } |
| 13523 | /* fallthrough */ |
| 13524 | |
| 13525 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13526 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13527 | /* Post more buffers if possible */ |
| 13528 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13529 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 13530 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13531 | workposted = true; |
| 13532 | break; |
| 13533 | } |
| 13534 | out: |
| 13535 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13536 | } |
| 13537 | |
| 13538 | /** |
| 13539 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 13540 | * @phba: Pointer to HBA context object. |
| 13541 | * @cq: Pointer to the completion queue. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13542 | * @cqe: Pointer to a completion queue entry. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13543 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13544 | * 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] | 13545 | * entry. |
| 13546 | * |
| 13547 | * Return: true if work posted to worker thread, otherwise false. |
| 13548 | **/ |
| 13549 | static bool |
| 13550 | 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] | 13551 | struct lpfc_cqe *cqe) |
| 13552 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13553 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13554 | bool workposted = false; |
| 13555 | |
| 13556 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13557 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13558 | |
| 13559 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13560 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13561 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13562 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13563 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13564 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13565 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13566 | break; |
| 13567 | case CQE_CODE_RELEASE_WQE: |
| 13568 | /* Process the WQ release event */ |
| 13569 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13570 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13571 | break; |
| 13572 | case CQE_CODE_XRI_ABORTED: |
| 13573 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13574 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13575 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13576 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13577 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13578 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13579 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13580 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13581 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13582 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13583 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13584 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13585 | default: |
| 13586 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13587 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13588 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13589 | break; |
| 13590 | } |
| 13591 | return workposted; |
| 13592 | } |
| 13593 | |
| 13594 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13595 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13596 | * @phba: Pointer to HBA context object. |
| 13597 | * @eqe: Pointer to fast-path event queue entry. |
| 13598 | * |
| 13599 | * This routine process a event queue entry from the slow-path event queue. |
| 13600 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13601 | * completion event on a completion queue, if not, an error shall be logged |
| 13602 | * and just return. Otherwise, it will get to the corresponding completion |
| 13603 | * queue and process all the entries on that completion queue, rearm the |
| 13604 | * completion queue, and then return. |
| 13605 | * |
| 13606 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13607 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13608 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13609 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13610 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13611 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13612 | uint16_t cqid; |
| 13613 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13614 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13615 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13616 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13617 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13618 | if (childq->queue_id == cqid) { |
| 13619 | cq = childq; |
| 13620 | break; |
| 13621 | } |
| 13622 | } |
| 13623 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13624 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13625 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13626 | "0365 Slow-path CQ identifier " |
| 13627 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13628 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13629 | } |
| 13630 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13631 | /* Save EQ associated with this CQ */ |
| 13632 | cq->assoc_qp = speq; |
| 13633 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13634 | if (!queue_work_on(cq->chann, phba->wq, &cq->spwork)) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13635 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13636 | "0390 Cannot schedule soft IRQ " |
| 13637 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13638 | cqid, cq->queue_id, smp_processor_id()); |
| 13639 | } |
| 13640 | |
| 13641 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13642 | * __lpfc_sli4_process_cq - Process elements of a CQ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13643 | * @phba: Pointer to HBA context object. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13644 | * @cq: Pointer to CQ to be processed |
| 13645 | * @handler: Routine to process each cqe |
| 13646 | * @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] | 13647 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13648 | * This routine processes completion queue entries in a CQ. While a valid |
| 13649 | * queue element is found, the handler is called. During processing checks |
| 13650 | * are made for periodic doorbell writes to let the hardware know of |
| 13651 | * element consumption. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13652 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13653 | * If the max limit on cqes to process is hit, or there are no more valid |
| 13654 | * entries, the loop stops. If we processed a sufficient number of elements, |
| 13655 | * meaning there is sufficient load, rather than rearming and generating |
| 13656 | * another interrupt, a cq rescheduling delay will be set. A delay of 0 |
| 13657 | * indicates no rescheduling. |
| 13658 | * |
| 13659 | * Returns True if work scheduled, False otherwise. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13660 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13661 | static bool |
| 13662 | __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13663 | bool (*handler)(struct lpfc_hba *, struct lpfc_queue *, |
| 13664 | struct lpfc_cqe *), unsigned long *delay) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13665 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13666 | struct lpfc_cqe *cqe; |
| 13667 | bool workposted = false; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13668 | int count = 0, consumed = 0; |
| 13669 | bool arm = true; |
| 13670 | |
| 13671 | /* default - no reschedule */ |
| 13672 | *delay = 0; |
| 13673 | |
| 13674 | if (cmpxchg(&cq->queue_claimed, 0, 1) != 0) |
| 13675 | goto rearm_and_exit; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13676 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13677 | /* Process all the entries to the CQ */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13678 | cqe = lpfc_sli4_cq_get(cq); |
| 13679 | while (cqe) { |
| 13680 | #if defined(CONFIG_SCSI_LPFC_DEBUG_FS) && defined(BUILD_NVME) |
| 13681 | if (phba->ktime_on) |
| 13682 | cq->isr_timestamp = ktime_get_ns(); |
| 13683 | else |
| 13684 | cq->isr_timestamp = 0; |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13685 | #endif |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13686 | workposted |= handler(phba, cq, cqe); |
| 13687 | __lpfc_sli4_consume_cqe(phba, cq, cqe); |
| 13688 | |
| 13689 | consumed++; |
| 13690 | if (!(++count % cq->max_proc_limit)) |
| 13691 | break; |
| 13692 | |
| 13693 | if (!(count % cq->notify_interval)) { |
| 13694 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13695 | LPFC_QUEUE_NOARM); |
| 13696 | consumed = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13697 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13698 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13699 | cqe = lpfc_sli4_cq_get(cq); |
| 13700 | } |
| 13701 | if (count >= phba->cfg_cq_poll_threshold) { |
| 13702 | *delay = 1; |
| 13703 | arm = false; |
| 13704 | } |
| 13705 | |
| 13706 | /* Track the max number of CQEs processed in 1 EQ */ |
| 13707 | if (count > cq->CQ_max_cqe) |
| 13708 | cq->CQ_max_cqe = count; |
| 13709 | |
| 13710 | cq->assoc_qp->EQ_cqe_cnt += count; |
| 13711 | |
| 13712 | /* Catch the no cq entry condition */ |
| 13713 | if (unlikely(count == 0)) |
| 13714 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13715 | "0369 No entry from completion queue " |
| 13716 | "qid=%d\n", cq->queue_id); |
| 13717 | |
| 13718 | cq->queue_claimed = 0; |
| 13719 | |
| 13720 | rearm_and_exit: |
| 13721 | phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed, |
| 13722 | arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM); |
| 13723 | |
| 13724 | return workposted; |
| 13725 | } |
| 13726 | |
| 13727 | /** |
| 13728 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
| 13729 | * @cq: pointer to CQ to process |
| 13730 | * |
| 13731 | * This routine calls the cq processing routine with a handler specific |
| 13732 | * to the type of queue bound to it. |
| 13733 | * |
| 13734 | * The CQ routine returns two values: the first is the calling status, |
| 13735 | * which indicates whether work was queued to the background discovery |
| 13736 | * thread. If true, the routine should wakeup the discovery thread; |
| 13737 | * the second is the delay parameter. If non-zero, rather than rearming |
| 13738 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 13739 | * that it is processed in a subsequent polling action. The value of |
| 13740 | * the delay indicates when to reschedule it. |
| 13741 | **/ |
| 13742 | static void |
| 13743 | __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq) |
| 13744 | { |
| 13745 | struct lpfc_hba *phba = cq->phba; |
| 13746 | unsigned long delay; |
| 13747 | bool workposted = false; |
| 13748 | |
| 13749 | /* Process and rearm the CQ */ |
| 13750 | switch (cq->type) { |
| 13751 | case LPFC_MCQ: |
| 13752 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13753 | lpfc_sli4_sp_handle_mcqe, |
| 13754 | &delay); |
| 13755 | break; |
| 13756 | case LPFC_WCQ: |
| 13757 | if (cq->subtype == LPFC_FCP || cq->subtype == LPFC_NVME) |
| 13758 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13759 | lpfc_sli4_fp_handle_cqe, |
| 13760 | &delay); |
| 13761 | else |
| 13762 | workposted |= __lpfc_sli4_process_cq(phba, cq, |
| 13763 | lpfc_sli4_sp_handle_cqe, |
| 13764 | &delay); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13765 | break; |
| 13766 | default: |
| 13767 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13768 | "0370 Invalid completion queue type (%d)\n", |
| 13769 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13770 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13771 | } |
| 13772 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13773 | if (delay) { |
| 13774 | if (!queue_delayed_work_on(cq->chann, phba->wq, |
| 13775 | &cq->sched_spwork, delay)) |
| 13776 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13777 | "0394 Cannot schedule soft IRQ " |
| 13778 | "for cqid=%d on CPU %d\n", |
| 13779 | cq->queue_id, cq->chann); |
| 13780 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13781 | |
| 13782 | /* wake up worker thread if there are works to be done */ |
| 13783 | if (workposted) |
| 13784 | lpfc_worker_wake_up(phba); |
| 13785 | } |
| 13786 | |
| 13787 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 13788 | * lpfc_sli4_sp_process_cq - slow-path work handler when started by |
| 13789 | * interrupt |
| 13790 | * @work: pointer to work element |
| 13791 | * |
| 13792 | * translates from the work handler and calls the slow-path handler. |
| 13793 | **/ |
| 13794 | static void |
| 13795 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 13796 | { |
| 13797 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork); |
| 13798 | |
| 13799 | __lpfc_sli4_sp_process_cq(cq); |
| 13800 | } |
| 13801 | |
| 13802 | /** |
| 13803 | * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer |
| 13804 | * @work: pointer to work element |
| 13805 | * |
| 13806 | * translates from the work handler and calls the slow-path handler. |
| 13807 | **/ |
| 13808 | static void |
| 13809 | lpfc_sli4_dly_sp_process_cq(struct work_struct *work) |
| 13810 | { |
| 13811 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 13812 | struct lpfc_queue, sched_spwork); |
| 13813 | |
| 13814 | __lpfc_sli4_sp_process_cq(cq); |
| 13815 | } |
| 13816 | |
| 13817 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13818 | * 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] | 13819 | * @phba: Pointer to HBA context object. |
| 13820 | * @cq: Pointer to associated CQ |
| 13821 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13822 | * |
| 13823 | * This routine process a fast-path work queue completion entry from fast-path |
| 13824 | * event queue for FCP command response completion. |
| 13825 | **/ |
| 13826 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13827 | 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] | 13828 | struct lpfc_wcqe_complete *wcqe) |
| 13829 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13830 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13831 | struct lpfc_iocbq *cmdiocbq; |
| 13832 | struct lpfc_iocbq irspiocbq; |
| 13833 | unsigned long iflags; |
| 13834 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13835 | /* Check for response status */ |
| 13836 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13837 | /* If resource errors reported from HBA, reduce queue |
| 13838 | * depth of the SCSI device. |
| 13839 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13840 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 13841 | IOSTAT_LOCAL_REJECT)) && |
| 13842 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 13843 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13844 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13845 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13846 | /* Log the error status */ |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13847 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13848 | "0373 FCP CQE error: status=x%x: " |
| 13849 | "CQE: %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13850 | bf_get(lpfc_wcqe_c_status, wcqe), |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13851 | wcqe->word0, wcqe->total_data_placed, |
| 13852 | wcqe->parameter, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13853 | } |
| 13854 | |
| 13855 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13856 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 13857 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13858 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13859 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13860 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13861 | if (unlikely(!cmdiocbq)) { |
| 13862 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13863 | "0374 FCP complete with no corresponding " |
| 13864 | "cmdiocb: iotag (%d)\n", |
| 13865 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13866 | return; |
| 13867 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13868 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13869 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 13870 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13871 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 13872 | if (cmdiocbq->wqe_cmpl) { |
| 13873 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13874 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13875 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13876 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13877 | } |
| 13878 | |
| 13879 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 13880 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 13881 | return; |
| 13882 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13883 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13884 | "0375 FCP cmdiocb not callback function " |
| 13885 | "iotag: (%d)\n", |
| 13886 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13887 | return; |
| 13888 | } |
| 13889 | |
| 13890 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13891 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13892 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 13893 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13894 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13895 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13896 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13897 | } |
| 13898 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13899 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 13900 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 13901 | } |
| 13902 | |
| 13903 | /** |
| 13904 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 13905 | * @phba: Pointer to HBA context object. |
| 13906 | * @cq: Pointer to completion queue. |
| 13907 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13908 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13909 | * 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] | 13910 | * proper WQ release routine to the slow-path WQ. |
| 13911 | **/ |
| 13912 | static void |
| 13913 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13914 | struct lpfc_wcqe_release *wcqe) |
| 13915 | { |
| 13916 | struct lpfc_queue *childwq; |
| 13917 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13918 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13919 | |
| 13920 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13921 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13922 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13923 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13924 | lpfc_sli4_wq_release(childwq, |
| 13925 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 13926 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 13927 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13928 | wqid_matched = true; |
| 13929 | break; |
| 13930 | } |
| 13931 | } |
| 13932 | /* Report warning log message if no match found */ |
| 13933 | if (wqid_matched != true) |
| 13934 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13935 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13936 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13937 | } |
| 13938 | |
| 13939 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13940 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 13941 | * @phba: Pointer to HBA context object. |
| 13942 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 13943 | * |
| 13944 | * This routine process a receive-queue completion queue entry. |
| 13945 | * |
| 13946 | * Return: true if work posted to worker thread, otherwise false. |
| 13947 | **/ |
| 13948 | static bool |
| 13949 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13950 | struct lpfc_rcqe *rcqe) |
| 13951 | { |
| 13952 | bool workposted = false; |
| 13953 | struct lpfc_queue *hrq; |
| 13954 | struct lpfc_queue *drq; |
| 13955 | struct rqb_dmabuf *dma_buf; |
| 13956 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13957 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13958 | uint32_t status, rq_id; |
| 13959 | unsigned long iflags; |
| 13960 | uint32_t fctl, idx; |
| 13961 | |
| 13962 | if ((phba->nvmet_support == 0) || |
| 13963 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 13964 | return workposted; |
| 13965 | |
| 13966 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13967 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 13968 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 13969 | |
| 13970 | /* sanity check on queue memory */ |
| 13971 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13972 | return workposted; |
| 13973 | |
| 13974 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13975 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13976 | else |
| 13977 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13978 | |
| 13979 | if ((phba->nvmet_support == 0) || |
| 13980 | (rq_id != hrq->queue_id)) |
| 13981 | return workposted; |
| 13982 | |
| 13983 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13984 | switch (status) { |
| 13985 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13986 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13987 | "6126 Receive Frame Truncated!!\n"); |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 13988 | /* Drop thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13989 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13990 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13991 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13992 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 13993 | if (!dma_buf) { |
| 13994 | hrq->RQ_no_buf_found++; |
| 13995 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13996 | goto out; |
| 13997 | } |
| 13998 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13999 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14000 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14001 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 14002 | |
| 14003 | /* Just some basic sanity checks on FCP Command frame */ |
| 14004 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 14005 | fc_hdr->fh_f_ctl[1] << 8 | |
| 14006 | fc_hdr->fh_f_ctl[2]); |
| 14007 | if (((fctl & |
| 14008 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 14009 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 14010 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 14011 | goto drop; |
| 14012 | |
| 14013 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
| 14014 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 14015 | lpfc_nvmet_unsol_fcp_event( |
Dick Kennedy | 66d7ce9 | 2017-08-23 16:55:42 -0700 | [diff] [blame] | 14016 | phba, idx, dma_buf, |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 14017 | cq->isr_timestamp); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14018 | return false; |
| 14019 | } |
| 14020 | drop: |
| 14021 | lpfc_in_buf_free(phba, &dma_buf->dbuf); |
| 14022 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14023 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 14024 | if (phba->nvmet_support) { |
| 14025 | tgtp = phba->targetport->private; |
| 14026 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 14027 | "6401 RQE Error x%x, posted %d err_cnt " |
| 14028 | "%d: %x %x %x\n", |
| 14029 | status, hrq->RQ_buf_posted, |
| 14030 | hrq->RQ_no_posted_buf, |
| 14031 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 14032 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 14033 | atomic_read(&tgtp->xmt_fcp_release)); |
| 14034 | } |
| 14035 | /* fallthrough */ |
| 14036 | |
| 14037 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14038 | hrq->RQ_no_posted_buf++; |
| 14039 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14040 | break; |
| 14041 | } |
| 14042 | out: |
| 14043 | return workposted; |
| 14044 | } |
| 14045 | |
| 14046 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14047 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14048 | * @phba: adapter with cq |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14049 | * @cq: Pointer to the completion queue. |
| 14050 | * @eqe: Pointer to fast-path completion queue entry. |
| 14051 | * |
| 14052 | * This routine process a fast-path work queue completion entry from fast-path |
| 14053 | * event queue for FCP command response completion. |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14054 | * |
| 14055 | * Return: true if work posted to worker thread, otherwise false. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14056 | **/ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14057 | static bool |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14058 | 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] | 14059 | struct lpfc_cqe *cqe) |
| 14060 | { |
| 14061 | struct lpfc_wcqe_release wcqe; |
| 14062 | bool workposted = false; |
| 14063 | |
| 14064 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 14065 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14066 | |
| 14067 | /* Check and process for different type of WCQE and dispatch */ |
| 14068 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 14069 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14070 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14071 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14072 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 14073 | phba->last_completion_time = jiffies; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14074 | if ((cq->subtype == LPFC_FCP) || (cq->subtype == LPFC_NVME)) |
| 14075 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
| 14076 | (struct lpfc_wcqe_complete *)&wcqe); |
| 14077 | if (cq->subtype == LPFC_NVME_LS) |
| 14078 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14079 | (struct lpfc_wcqe_complete *)&wcqe); |
| 14080 | break; |
| 14081 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14082 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14083 | /* Process the WQ release event */ |
| 14084 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 14085 | (struct lpfc_wcqe_release *)&wcqe); |
| 14086 | break; |
| 14087 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14088 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14089 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 14090 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14091 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 14092 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 14093 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14094 | case CQE_CODE_RECEIVE_V1: |
| 14095 | case CQE_CODE_RECEIVE: |
| 14096 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14097 | if (cq->subtype == LPFC_NVMET) { |
| 14098 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 14099 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 14100 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14101 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14102 | default: |
| 14103 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14104 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14105 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 14106 | break; |
| 14107 | } |
| 14108 | return workposted; |
| 14109 | } |
| 14110 | |
| 14111 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14112 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14113 | * @phba: Pointer to HBA context object. |
| 14114 | * @eqe: Pointer to fast-path event queue entry. |
| 14115 | * |
| 14116 | * This routine process a event queue entry from the fast-path event queue. |
| 14117 | * It will check the MajorCode and MinorCode to determine this is for a |
| 14118 | * completion event on a completion queue, if not, an error shall be logged |
| 14119 | * and just return. Otherwise, it will get to the corresponding completion |
| 14120 | * queue and process all the entries on the completion queue, rearm the |
| 14121 | * completion queue, and then return. |
| 14122 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14123 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14124 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 14125 | struct lpfc_eqe *eqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14126 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14127 | struct lpfc_queue *cq = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14128 | uint32_t qidx = eq->hdwq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14129 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14130 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14131 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14132 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14133 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14134 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14135 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 14136 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14137 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14138 | } |
| 14139 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14140 | /* Get the reference to the corresponding CQ */ |
| 14141 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 14142 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14143 | /* Use the fast lookup method first */ |
| 14144 | if (cqid <= phba->sli4_hba.cq_max) { |
| 14145 | cq = phba->sli4_hba.cq_lookup[cqid]; |
| 14146 | if (cq) |
| 14147 | goto work_cq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14148 | } |
| 14149 | |
| 14150 | /* Next check for NVMET completion */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14151 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 14152 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 14153 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 14154 | /* Process NVMET unsol rcv */ |
| 14155 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 14156 | goto process_cq; |
| 14157 | } |
| 14158 | } |
| 14159 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14160 | if (phba->sli4_hba.nvmels_cq && |
| 14161 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 14162 | /* Process NVME unsol rcv */ |
| 14163 | cq = phba->sli4_hba.nvmels_cq; |
| 14164 | } |
| 14165 | |
| 14166 | /* Otherwise this is a Slow path event */ |
| 14167 | if (cq == NULL) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14168 | lpfc_sli4_sp_handle_eqe(phba, eqe, |
| 14169 | phba->sli4_hba.hdwq[qidx].hba_eq); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14170 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14171 | } |
| 14172 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14173 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14174 | if (unlikely(cqid != cq->queue_id)) { |
| 14175 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14176 | "0368 Miss-matched fast-path completion " |
| 14177 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 14178 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14179 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14180 | } |
| 14181 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14182 | work_cq: |
James Smart | 45aa312 | 2019-01-28 11:14:29 -0800 | [diff] [blame] | 14183 | if (!queue_work_on(cq->chann, phba->wq, &cq->irqwork)) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14184 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14185 | "0363 Cannot schedule soft IRQ " |
| 14186 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 14187 | cqid, cq->queue_id, smp_processor_id()); |
| 14188 | } |
| 14189 | |
| 14190 | /** |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14191 | * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 14192 | * @cq: Pointer to CQ to be processed |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14193 | * |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14194 | * This routine calls the cq processing routine with the handler for |
| 14195 | * fast path CQEs. |
| 14196 | * |
| 14197 | * The CQ routine returns two values: the first is the calling status, |
| 14198 | * which indicates whether work was queued to the background discovery |
| 14199 | * thread. If true, the routine should wakeup the discovery thread; |
| 14200 | * the second is the delay parameter. If non-zero, rather than rearming |
| 14201 | * the CQ and yet another interrupt, the CQ handler should be queued so |
| 14202 | * that it is processed in a subsequent polling action. The value of |
| 14203 | * the delay indicates when to reschedule it. |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14204 | **/ |
| 14205 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14206 | __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq) |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14207 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14208 | struct lpfc_hba *phba = cq->phba; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14209 | unsigned long delay; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14210 | bool workposted = false; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14211 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14212 | /* process and rearm the CQ */ |
| 14213 | workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe, |
| 14214 | &delay); |
| 14215 | |
| 14216 | if (delay) { |
| 14217 | if (!queue_delayed_work_on(cq->chann, phba->wq, |
| 14218 | &cq->sched_irqwork, delay)) |
| 14219 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14220 | "0367 Cannot schedule soft IRQ " |
| 14221 | "for cqid=%d on CPU %d\n", |
| 14222 | cq->queue_id, cq->chann); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14223 | } |
| 14224 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14225 | /* wake up worker thread if there are works to be done */ |
| 14226 | if (workposted) |
| 14227 | lpfc_worker_wake_up(phba); |
| 14228 | } |
| 14229 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14230 | /** |
| 14231 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by |
| 14232 | * interrupt |
| 14233 | * @work: pointer to work element |
| 14234 | * |
| 14235 | * translates from the work handler and calls the fast-path handler. |
| 14236 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14237 | static void |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14238 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14239 | { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14240 | struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14241 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14242 | __lpfc_sli4_hba_process_cq(cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14243 | } |
| 14244 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14245 | /** |
| 14246 | * lpfc_sli4_hba_process_cq - fast-path work handler when started by timer |
| 14247 | * @work: pointer to work element |
| 14248 | * |
| 14249 | * translates from the work handler and calls the fast-path handler. |
| 14250 | **/ |
| 14251 | static void |
| 14252 | lpfc_sli4_dly_hba_process_cq(struct work_struct *work) |
| 14253 | { |
| 14254 | struct lpfc_queue *cq = container_of(to_delayed_work(work), |
| 14255 | struct lpfc_queue, sched_irqwork); |
| 14256 | |
| 14257 | __lpfc_sli4_hba_process_cq(cq); |
| 14258 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14259 | |
| 14260 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14261 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14262 | * @irq: Interrupt number. |
| 14263 | * @dev_id: The device context pointer. |
| 14264 | * |
| 14265 | * This function is directly called from the PCI layer as an interrupt |
| 14266 | * service routine when device with SLI-4 interface spec is enabled with |
| 14267 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 14268 | * ring event in the HBA. However, when the device is enabled with either |
| 14269 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 14270 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 14271 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 14272 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 14273 | * the intrrupt context. This function is called without any lock held. |
| 14274 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 14275 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 14276 | * equal to that of FCP CQ index. |
| 14277 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14278 | * The link attention and ELS ring attention events are handled |
| 14279 | * by the worker thread. The interrupt handler signals the worker thread |
| 14280 | * and returns for these events. This function is called without any lock |
| 14281 | * held. It gets the hbalock to access and update SLI data structures. |
| 14282 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14283 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 14284 | * returns IRQ_NONE. |
| 14285 | **/ |
| 14286 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14287 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14288 | { |
| 14289 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14290 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14291 | struct lpfc_queue *fpeq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14292 | unsigned long iflag; |
| 14293 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14294 | int hba_eqidx; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14295 | struct lpfc_eq_intr_info *eqi; |
| 14296 | uint32_t icnt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14297 | |
| 14298 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14299 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 14300 | phba = hba_eq_hdl->phba; |
| 14301 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14302 | |
| 14303 | if (unlikely(!phba)) |
| 14304 | return IRQ_NONE; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14305 | if (unlikely(!phba->sli4_hba.hdwq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 14306 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14307 | |
| 14308 | /* Get to the EQ struct associated with this vector */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14309 | fpeq = phba->sli4_hba.hdwq[hba_eqidx].hba_eq; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14310 | if (unlikely(!fpeq)) |
| 14311 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14312 | |
| 14313 | /* Check device state for handling interrupt */ |
| 14314 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 14315 | /* Check again for link_state with lock held */ |
| 14316 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 14317 | if (phba->link_state < LPFC_LINK_DOWN) |
| 14318 | /* Flush, clear interrupt, and rearm the EQ */ |
| 14319 | lpfc_sli4_eq_flush(phba, fpeq); |
| 14320 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 14321 | return IRQ_NONE; |
| 14322 | } |
| 14323 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14324 | eqi = phba->sli4_hba.eq_info; |
| 14325 | icnt = this_cpu_inc_return(eqi->icnt); |
| 14326 | fpeq->last_cpu = smp_processor_id(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14327 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14328 | if (icnt > LPFC_EQD_ISR_TRIGGER && |
| 14329 | phba->cfg_irq_chann == 1 && |
| 14330 | phba->cfg_auto_imax && |
| 14331 | fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY && |
| 14332 | phba->sli.sli_flag & LPFC_SLI_USE_EQDR) |
| 14333 | lpfc_sli4_mod_hba_eq_delay(phba, fpeq, LPFC_MAX_AUTO_EQ_DELAY); |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14334 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14335 | /* process and rearm the EQ */ |
| 14336 | ecount = lpfc_sli4_process_eq(phba, fpeq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14337 | |
| 14338 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14339 | fpeq->EQ_no_entry++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14340 | if (phba->intr_type == MSIX) |
| 14341 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 14342 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14343 | "0358 MSI-X interrupt with no EQE\n"); |
| 14344 | else |
| 14345 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 14346 | return IRQ_NONE; |
| 14347 | } |
| 14348 | |
| 14349 | return IRQ_HANDLED; |
| 14350 | } /* lpfc_sli4_fp_intr_handler */ |
| 14351 | |
| 14352 | /** |
| 14353 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 14354 | * @irq: Interrupt number. |
| 14355 | * @dev_id: The device context pointer. |
| 14356 | * |
| 14357 | * This function is the device-level interrupt handler to device with SLI-4 |
| 14358 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 14359 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 14360 | * driver attention. This function invokes the slow-path interrupt attention |
| 14361 | * handling function and fast-path interrupt attention handling function in |
| 14362 | * turn to process the relevant HBA attention events. This function is called |
| 14363 | * without any lock held. It gets the hbalock to access and update SLI data |
| 14364 | * structures. |
| 14365 | * |
| 14366 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 14367 | * returns IRQ_NONE. |
| 14368 | **/ |
| 14369 | irqreturn_t |
| 14370 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 14371 | { |
| 14372 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14373 | irqreturn_t hba_irq_rc; |
| 14374 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14375 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14376 | |
| 14377 | /* Get the driver's phba structure from the dev_id */ |
| 14378 | phba = (struct lpfc_hba *)dev_id; |
| 14379 | |
| 14380 | if (unlikely(!phba)) |
| 14381 | return IRQ_NONE; |
| 14382 | |
| 14383 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14384 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 14385 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14386 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14387 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14388 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14389 | if (hba_irq_rc == IRQ_HANDLED) |
| 14390 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14391 | } |
| 14392 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14393 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14394 | } /* lpfc_sli4_intr_handler */ |
| 14395 | |
| 14396 | /** |
| 14397 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 14398 | * @queue: The queue structure to free. |
| 14399 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 14400 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14401 | * the host resident queue. This function must be called after destroying the |
| 14402 | * queue on the HBA. |
| 14403 | **/ |
| 14404 | void |
| 14405 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 14406 | { |
| 14407 | struct lpfc_dmabuf *dmabuf; |
| 14408 | |
| 14409 | if (!queue) |
| 14410 | return; |
| 14411 | |
| 14412 | while (!list_empty(&queue->page_list)) { |
| 14413 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 14414 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14415 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14416 | dmabuf->virt, dmabuf->phys); |
| 14417 | kfree(dmabuf); |
| 14418 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14419 | if (queue->rqbp) { |
| 14420 | lpfc_free_rq_buffer(queue->phba, queue); |
| 14421 | kfree(queue->rqbp); |
| 14422 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 14423 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14424 | if (!list_empty(&queue->cpu_list)) |
| 14425 | list_del(&queue->cpu_list); |
| 14426 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 14427 | if (!list_empty(&queue->wq_list)) |
| 14428 | list_del(&queue->wq_list); |
| 14429 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14430 | kfree(queue); |
| 14431 | return; |
| 14432 | } |
| 14433 | |
| 14434 | /** |
| 14435 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 14436 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14437 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14438 | * @entry_size: The size of each queue entry for this queue. |
| 14439 | * @entry count: The number of entries that this queue will handle. |
| 14440 | * |
| 14441 | * This function allocates a queue structure and the DMAable memory used for |
| 14442 | * the host resident queue. This function must be called before creating the |
| 14443 | * queue on the HBA. |
| 14444 | **/ |
| 14445 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14446 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
| 14447 | uint32_t entry_size, uint32_t entry_count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14448 | { |
| 14449 | struct lpfc_queue *queue; |
| 14450 | struct lpfc_dmabuf *dmabuf; |
| 14451 | int x, total_qe_count; |
| 14452 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14453 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14454 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14455 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14456 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14457 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14458 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 14459 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 14460 | if (!queue) |
| 14461 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14462 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 14463 | hw_page_size))/hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14464 | |
| 14465 | /* If needed, Adjust page count to match the max the adapter supports */ |
Ewan D. Milne | 4e87eb2 | 2018-12-13 15:25:16 -0500 | [diff] [blame] | 14466 | if (phba->sli4_hba.pc_sli4_params.wqpcnt && |
| 14467 | (queue->page_count > phba->sli4_hba.pc_sli4_params.wqpcnt)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14468 | queue->page_count = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 14469 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14470 | INIT_LIST_HEAD(&queue->list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14471 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14472 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14473 | INIT_LIST_HEAD(&queue->page_list); |
| 14474 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14475 | INIT_LIST_HEAD(&queue->cpu_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14476 | |
| 14477 | /* Set queue parameters now. If the system cannot provide memory |
| 14478 | * resources, the free routine needs to know what was allocated. |
| 14479 | */ |
| 14480 | queue->entry_size = entry_size; |
| 14481 | queue->entry_count = entry_count; |
| 14482 | queue->page_size = hw_page_size; |
| 14483 | queue->phba = phba; |
| 14484 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14485 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 14486 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 14487 | if (!dmabuf) |
| 14488 | goto out_fail; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 14489 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 14490 | hw_page_size, &dmabuf->phys, |
| 14491 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14492 | if (!dmabuf->virt) { |
| 14493 | kfree(dmabuf); |
| 14494 | goto out_fail; |
| 14495 | } |
| 14496 | dmabuf->buffer_tag = x; |
| 14497 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 14498 | /* initialize queue's entry array */ |
| 14499 | dma_pointer = dmabuf->virt; |
| 14500 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14501 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14502 | total_qe_count++, dma_pointer += entry_size) { |
| 14503 | queue->qe[total_qe_count].address = dma_pointer; |
| 14504 | } |
| 14505 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14506 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 14507 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14508 | INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq); |
| 14509 | INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14510 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14511 | /* notify_interval will be set during q creation */ |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14512 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14513 | return queue; |
| 14514 | out_fail: |
| 14515 | lpfc_sli4_queue_free(queue); |
| 14516 | return NULL; |
| 14517 | } |
| 14518 | |
| 14519 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14520 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 14521 | * @phba: HBA structure that indicates port to create a queue on. |
| 14522 | * @pci_barset: PCI BAR set flag. |
| 14523 | * |
| 14524 | * This function shall perform iomap of the specified PCI BAR address to host |
| 14525 | * memory address if not already done so and return it. The returned host |
| 14526 | * memory address can be NULL. |
| 14527 | */ |
| 14528 | static void __iomem * |
| 14529 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 14530 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14531 | if (!phba->pcidev) |
| 14532 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14533 | |
| 14534 | switch (pci_barset) { |
| 14535 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14536 | return phba->pci_bar0_memmap_p; |
| 14537 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14538 | return phba->pci_bar2_memmap_p; |
| 14539 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14540 | return phba->pci_bar4_memmap_p; |
| 14541 | default: |
| 14542 | break; |
| 14543 | } |
| 14544 | return NULL; |
| 14545 | } |
| 14546 | |
| 14547 | /** |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14548 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs |
| 14549 | * @phba: HBA structure that EQs are on. |
| 14550 | * @startq: The starting EQ index to modify |
| 14551 | * @numq: The number of EQs (consecutive indexes) to modify |
| 14552 | * @usdelay: amount of delay |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14553 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14554 | * This function revises the EQ delay on 1 or more EQs. The EQ delay |
| 14555 | * is set either by writing to a register (if supported by the SLI Port) |
| 14556 | * or by mailbox command. The mailbox command allows several EQs to be |
| 14557 | * updated at once. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14558 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14559 | * The @phba struct is used to send a mailbox command to HBA. The @startq |
| 14560 | * is used to get the starting EQ index to change. The @numq value is |
| 14561 | * used to specify how many consecutive EQ indexes, starting at EQ index, |
| 14562 | * are to be changed. This function is asynchronous and will wait for any |
| 14563 | * mailbox commands to finish before returning. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14564 | * |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14565 | * On success this function will return a zero. If unable to allocate |
| 14566 | * enough memory this function will return -ENOMEM. If a mailbox command |
| 14567 | * fails this function will return -ENXIO. Note: on ENXIO, some EQs may |
| 14568 | * have had their delay multipler changed. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14569 | **/ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14570 | void |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14571 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14572 | uint32_t numq, uint32_t usdelay) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14573 | { |
| 14574 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14575 | LPFC_MBOXQ_t *mbox; |
| 14576 | struct lpfc_queue *eq; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14577 | int cnt = 0, rc, length; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14578 | uint32_t shdr_status, shdr_add_status; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14579 | uint32_t dmult; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14580 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14581 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14582 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14583 | if (startq >= phba->cfg_irq_chann) |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14584 | return; |
| 14585 | |
| 14586 | if (usdelay > 0xFFFF) { |
| 14587 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14588 | "6429 usdelay %d too large. Scaled down to " |
| 14589 | "0xFFFF.\n", usdelay); |
| 14590 | usdelay = 0xFFFF; |
| 14591 | } |
| 14592 | |
| 14593 | /* set values by EQ_DELAY register if supported */ |
| 14594 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14595 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
| 14596 | eq = phba->sli4_hba.hdwq[qidx].hba_eq; |
| 14597 | if (!eq) |
| 14598 | continue; |
| 14599 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14600 | lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14601 | |
| 14602 | if (++cnt >= numq) |
| 14603 | break; |
| 14604 | } |
| 14605 | |
| 14606 | return; |
| 14607 | } |
| 14608 | |
| 14609 | /* Otherwise, set values by mailbox cmd */ |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14610 | |
| 14611 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14612 | if (!mbox) { |
| 14613 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_FCP | LOG_NVME, |
| 14614 | "6428 Failed allocating mailbox cmd buffer." |
| 14615 | " EQ delay was not set.\n"); |
| 14616 | return; |
| 14617 | } |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14618 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14619 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14620 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14621 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14622 | length, LPFC_SLI4_MBX_EMBED); |
| 14623 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14624 | |
| 14625 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14626 | dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC; |
| 14627 | if (dmult) |
| 14628 | dmult--; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14629 | if (dmult > LPFC_DMULT_MAX) |
| 14630 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14631 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14632 | for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14633 | eq = phba->sli4_hba.hdwq[qidx].hba_eq; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14634 | if (!eq) |
| 14635 | continue; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14636 | eq->q_mode = usdelay; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14637 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14638 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14639 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14640 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14641 | if (++cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14642 | break; |
| 14643 | } |
| 14644 | eq_delay->u.request.num_eq = cnt; |
| 14645 | |
| 14646 | mbox->vport = phba->pport; |
| 14647 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14648 | mbox->ctx_buf = NULL; |
| 14649 | mbox->ctx_ndlp = NULL; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14650 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14651 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 14652 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14653 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14654 | if (shdr_status || shdr_add_status || rc) { |
| 14655 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14656 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 14657 | "status x%x add_status x%x, mbx status x%x\n", |
| 14658 | shdr_status, shdr_add_status, rc); |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14659 | } |
| 14660 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 14661 | return; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14662 | } |
| 14663 | |
| 14664 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14665 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 14666 | * @phba: HBA structure that indicates port to create a queue on. |
| 14667 | * @eq: The queue structure to use to create the event queue. |
| 14668 | * @imax: The maximum interrupt per second limit. |
| 14669 | * |
| 14670 | * This function creates an event queue, as detailed in @eq, on a port, |
| 14671 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 14672 | * |
| 14673 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 14674 | * is used to get the entry count and entry size that are necessary to |
| 14675 | * determine the number of pages to allocate and use for this queue. This |
| 14676 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 14677 | * event queue. This function is asynchronous and will wait for the mailbox |
| 14678 | * command to finish before continuing. |
| 14679 | * |
| 14680 | * 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] | 14681 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14682 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14683 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14684 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14685 | 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] | 14686 | { |
| 14687 | struct lpfc_mbx_eq_create *eq_create; |
| 14688 | LPFC_MBOXQ_t *mbox; |
| 14689 | int rc, length, status = 0; |
| 14690 | struct lpfc_dmabuf *dmabuf; |
| 14691 | uint32_t shdr_status, shdr_add_status; |
| 14692 | union lpfc_sli4_cfg_shdr *shdr; |
| 14693 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14694 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14695 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14696 | /* sanity check on queue memory */ |
| 14697 | if (!eq) |
| 14698 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14699 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14700 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14701 | |
| 14702 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14703 | if (!mbox) |
| 14704 | return -ENOMEM; |
| 14705 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 14706 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14707 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14708 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 14709 | length, LPFC_SLI4_MBX_EMBED); |
| 14710 | eq_create = &mbox->u.mqe.un.eq_create; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14711 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14712 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 14713 | eq->page_count); |
| 14714 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 14715 | LPFC_EQE_SIZE); |
| 14716 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14717 | |
| 14718 | /* Use version 2 of CREATE_EQ if eqav is set */ |
| 14719 | if (phba->sli4_hba.pc_sli4_params.eqav) { |
| 14720 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14721 | LPFC_Q_CREATE_VERSION_2); |
| 14722 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, |
| 14723 | phba->sli4_hba.pc_sli4_params.eqav); |
| 14724 | } |
| 14725 | |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 14726 | /* don't setup delay multiplier using EQ_CREATE */ |
| 14727 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14728 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 14729 | dmult); |
| 14730 | switch (eq->entry_count) { |
| 14731 | default: |
| 14732 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14733 | "0360 Unsupported EQ count. (%d)\n", |
| 14734 | eq->entry_count); |
| 14735 | if (eq->entry_count < 256) |
| 14736 | return -EINVAL; |
| 14737 | /* otherwise default to smallest count (drop through) */ |
| 14738 | case 256: |
| 14739 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14740 | LPFC_EQ_CNT_256); |
| 14741 | break; |
| 14742 | case 512: |
| 14743 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14744 | LPFC_EQ_CNT_512); |
| 14745 | break; |
| 14746 | case 1024: |
| 14747 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14748 | LPFC_EQ_CNT_1024); |
| 14749 | break; |
| 14750 | case 2048: |
| 14751 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14752 | LPFC_EQ_CNT_2048); |
| 14753 | break; |
| 14754 | case 4096: |
| 14755 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14756 | LPFC_EQ_CNT_4096); |
| 14757 | break; |
| 14758 | } |
| 14759 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14760 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14761 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14762 | putPaddrLow(dmabuf->phys); |
| 14763 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14764 | putPaddrHigh(dmabuf->phys); |
| 14765 | } |
| 14766 | mbox->vport = phba->pport; |
| 14767 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 14768 | mbox->ctx_buf = NULL; |
| 14769 | mbox->ctx_ndlp = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14770 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14771 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14772 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14773 | if (shdr_status || shdr_add_status || rc) { |
| 14774 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14775 | "2500 EQ_CREATE mailbox failed with " |
| 14776 | "status x%x add_status x%x, mbx status x%x\n", |
| 14777 | shdr_status, shdr_add_status, rc); |
| 14778 | status = -ENXIO; |
| 14779 | } |
| 14780 | eq->type = LPFC_EQ; |
| 14781 | eq->subtype = LPFC_NONE; |
| 14782 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 14783 | if (eq->queue_id == 0xFFFF) |
| 14784 | status = -ENXIO; |
| 14785 | eq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14786 | eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL; |
| 14787 | eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14788 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14789 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14790 | return status; |
| 14791 | } |
| 14792 | |
| 14793 | /** |
| 14794 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 14795 | * @phba: HBA structure that indicates port to create a queue on. |
| 14796 | * @cq: The queue structure to use to create the completion queue. |
| 14797 | * @eq: The event queue to bind this completion queue to. |
| 14798 | * |
| 14799 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 14800 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 14801 | * |
| 14802 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14803 | * is used to get the entry count and entry size that are necessary to |
| 14804 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14805 | * is used to indicate which event queue to bind this completion queue to. This |
| 14806 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 14807 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14808 | * command to finish before continuing. |
| 14809 | * |
| 14810 | * 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] | 14811 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14812 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14813 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14814 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14815 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14816 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 14817 | { |
| 14818 | struct lpfc_mbx_cq_create *cq_create; |
| 14819 | struct lpfc_dmabuf *dmabuf; |
| 14820 | LPFC_MBOXQ_t *mbox; |
| 14821 | int rc, length, status = 0; |
| 14822 | uint32_t shdr_status, shdr_add_status; |
| 14823 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14824 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14825 | /* sanity check on queue memory */ |
| 14826 | if (!cq || !eq) |
| 14827 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14828 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14829 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14830 | if (!mbox) |
| 14831 | return -ENOMEM; |
| 14832 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 14833 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14834 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14835 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 14836 | length, LPFC_SLI4_MBX_EMBED); |
| 14837 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14838 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14839 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 14840 | cq->page_count); |
| 14841 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 14842 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14843 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14844 | phba->sli4_hba.pc_sli4_params.cqv); |
| 14845 | 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] | 14846 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 14847 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14848 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 14849 | eq->queue_id); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14850 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
| 14851 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14852 | } else { |
| 14853 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 14854 | eq->queue_id); |
| 14855 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14856 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14857 | case 2048: |
| 14858 | case 4096: |
| 14859 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14860 | LPFC_Q_CREATE_VERSION_2) { |
| 14861 | cq_create->u.request.context.lpfc_cq_context_count = |
| 14862 | cq->entry_count; |
| 14863 | bf_set(lpfc_cq_context_count, |
| 14864 | &cq_create->u.request.context, |
| 14865 | LPFC_CQ_CNT_WORD7); |
| 14866 | break; |
| 14867 | } |
| 14868 | /* Fall Thru */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14869 | default: |
| 14870 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14871 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14872 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14873 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14874 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14875 | if (cq->entry_count < 256) { |
| 14876 | status = -EINVAL; |
| 14877 | goto out; |
| 14878 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14879 | /* otherwise default to smallest count (drop through) */ |
| 14880 | case 256: |
| 14881 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14882 | LPFC_CQ_CNT_256); |
| 14883 | break; |
| 14884 | case 512: |
| 14885 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14886 | LPFC_CQ_CNT_512); |
| 14887 | break; |
| 14888 | case 1024: |
| 14889 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14890 | LPFC_CQ_CNT_1024); |
| 14891 | break; |
| 14892 | } |
| 14893 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14894 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14895 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14896 | putPaddrLow(dmabuf->phys); |
| 14897 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14898 | putPaddrHigh(dmabuf->phys); |
| 14899 | } |
| 14900 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14901 | |
| 14902 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14903 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14904 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14905 | if (shdr_status || shdr_add_status || rc) { |
| 14906 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14907 | "2501 CQ_CREATE mailbox failed with " |
| 14908 | "status x%x add_status x%x, mbx status x%x\n", |
| 14909 | shdr_status, shdr_add_status, rc); |
| 14910 | status = -ENXIO; |
| 14911 | goto out; |
| 14912 | } |
| 14913 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 14914 | if (cq->queue_id == 0xFFFF) { |
| 14915 | status = -ENXIO; |
| 14916 | goto out; |
| 14917 | } |
| 14918 | /* link the cq onto the parent eq child list */ |
| 14919 | list_add_tail(&cq->list, &eq->child_list); |
| 14920 | /* Set up completion queue's type and subtype */ |
| 14921 | cq->type = type; |
| 14922 | cq->subtype = subtype; |
| 14923 | 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] | 14924 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14925 | cq->assoc_qp = eq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14926 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 14927 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 14928 | 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] | 14929 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14930 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 14931 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14932 | out: |
| 14933 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14934 | return status; |
| 14935 | } |
| 14936 | |
| 14937 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14938 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 14939 | * @phba: HBA structure that indicates port to create a queue on. |
| 14940 | * @cqp: The queue structure array to use to create the completion queues. |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14941 | * @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] | 14942 | * |
| 14943 | * This function creates a set of completion queue, s to support MRQ |
| 14944 | * as detailed in @cqp, on a port, |
| 14945 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 14946 | * |
| 14947 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14948 | * is used to get the entry count and entry size that are necessary to |
| 14949 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14950 | * is used to indicate which event queue to bind this completion queue to. This |
| 14951 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 14952 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14953 | * command to finish before continuing. |
| 14954 | * |
| 14955 | * On success this function will return a zero. If unable to allocate enough |
| 14956 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14957 | * fails this function will return -ENXIO. |
| 14958 | **/ |
| 14959 | int |
| 14960 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14961 | struct lpfc_sli4_hdw_queue *hdwq, uint32_t type, |
| 14962 | uint32_t subtype) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14963 | { |
| 14964 | struct lpfc_queue *cq; |
| 14965 | struct lpfc_queue *eq; |
| 14966 | struct lpfc_mbx_cq_create_set *cq_set; |
| 14967 | struct lpfc_dmabuf *dmabuf; |
| 14968 | LPFC_MBOXQ_t *mbox; |
| 14969 | int rc, length, alloclen, status = 0; |
| 14970 | int cnt, idx, numcq, page_idx = 0; |
| 14971 | uint32_t shdr_status, shdr_add_status; |
| 14972 | union lpfc_sli4_cfg_shdr *shdr; |
| 14973 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14974 | |
| 14975 | /* sanity check on queue memory */ |
| 14976 | numcq = phba->cfg_nvmet_mrq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14977 | if (!cqp || !hdwq || !numcq) |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14978 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14979 | |
| 14980 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14981 | if (!mbox) |
| 14982 | return -ENOMEM; |
| 14983 | |
| 14984 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 14985 | length += ((numcq * cqp[0]->page_count) * |
| 14986 | sizeof(struct dma_address)); |
| 14987 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14988 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 14989 | LPFC_SLI4_MBX_NEMBED); |
| 14990 | if (alloclen < length) { |
| 14991 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14992 | "3098 Allocated DMA memory size (%d) is " |
| 14993 | "less than the requested DMA memory size " |
| 14994 | "(%d)\n", alloclen, length); |
| 14995 | status = -ENOMEM; |
| 14996 | goto out; |
| 14997 | } |
| 14998 | cq_set = mbox->sge_array->addr[0]; |
| 14999 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 15000 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 15001 | |
| 15002 | for (idx = 0; idx < numcq; idx++) { |
| 15003 | cq = cqp[idx]; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 15004 | eq = hdwq[idx].hba_eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15005 | if (!cq || !eq) { |
| 15006 | status = -ENOMEM; |
| 15007 | goto out; |
| 15008 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15009 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15010 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15011 | |
| 15012 | switch (idx) { |
| 15013 | case 0: |
| 15014 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 15015 | &cq_set->u.request, |
| 15016 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 15017 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 15018 | &cq_set->u.request, cq->page_count); |
| 15019 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 15020 | &cq_set->u.request, 1); |
| 15021 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 15022 | &cq_set->u.request, 1); |
| 15023 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 15024 | &cq_set->u.request, 0); |
| 15025 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 15026 | &cq_set->u.request, numcq); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 15027 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
| 15028 | &cq_set->u.request, |
| 15029 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15030 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15031 | case 2048: |
| 15032 | case 4096: |
| 15033 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 15034 | LPFC_Q_CREATE_VERSION_2) { |
| 15035 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15036 | &cq_set->u.request, |
| 15037 | cq->entry_count); |
| 15038 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15039 | &cq_set->u.request, |
| 15040 | LPFC_CQ_CNT_WORD7); |
| 15041 | break; |
| 15042 | } |
| 15043 | /* Fall Thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15044 | default: |
| 15045 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15046 | "3118 Bad CQ count. (%d)\n", |
| 15047 | cq->entry_count); |
| 15048 | if (cq->entry_count < 256) { |
| 15049 | status = -EINVAL; |
| 15050 | goto out; |
| 15051 | } |
| 15052 | /* otherwise default to smallest (drop thru) */ |
| 15053 | case 256: |
| 15054 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15055 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 15056 | break; |
| 15057 | case 512: |
| 15058 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15059 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 15060 | break; |
| 15061 | case 1024: |
| 15062 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 15063 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 15064 | break; |
| 15065 | } |
| 15066 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 15067 | &cq_set->u.request, eq->queue_id); |
| 15068 | break; |
| 15069 | case 1: |
| 15070 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 15071 | &cq_set->u.request, eq->queue_id); |
| 15072 | break; |
| 15073 | case 2: |
| 15074 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 15075 | &cq_set->u.request, eq->queue_id); |
| 15076 | break; |
| 15077 | case 3: |
| 15078 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 15079 | &cq_set->u.request, eq->queue_id); |
| 15080 | break; |
| 15081 | case 4: |
| 15082 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 15083 | &cq_set->u.request, eq->queue_id); |
| 15084 | break; |
| 15085 | case 5: |
| 15086 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 15087 | &cq_set->u.request, eq->queue_id); |
| 15088 | break; |
| 15089 | case 6: |
| 15090 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 15091 | &cq_set->u.request, eq->queue_id); |
| 15092 | break; |
| 15093 | case 7: |
| 15094 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 15095 | &cq_set->u.request, eq->queue_id); |
| 15096 | break; |
| 15097 | case 8: |
| 15098 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 15099 | &cq_set->u.request, eq->queue_id); |
| 15100 | break; |
| 15101 | case 9: |
| 15102 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 15103 | &cq_set->u.request, eq->queue_id); |
| 15104 | break; |
| 15105 | case 10: |
| 15106 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 15107 | &cq_set->u.request, eq->queue_id); |
| 15108 | break; |
| 15109 | case 11: |
| 15110 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 15111 | &cq_set->u.request, eq->queue_id); |
| 15112 | break; |
| 15113 | case 12: |
| 15114 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 15115 | &cq_set->u.request, eq->queue_id); |
| 15116 | break; |
| 15117 | case 13: |
| 15118 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 15119 | &cq_set->u.request, eq->queue_id); |
| 15120 | break; |
| 15121 | case 14: |
| 15122 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 15123 | &cq_set->u.request, eq->queue_id); |
| 15124 | break; |
| 15125 | case 15: |
| 15126 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 15127 | &cq_set->u.request, eq->queue_id); |
| 15128 | break; |
| 15129 | } |
| 15130 | |
| 15131 | /* link the cq onto the parent eq child list */ |
| 15132 | list_add_tail(&cq->list, &eq->child_list); |
| 15133 | /* Set up completion queue's type and subtype */ |
| 15134 | cq->type = type; |
| 15135 | cq->subtype = subtype; |
| 15136 | cq->assoc_qid = eq->queue_id; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15137 | cq->assoc_qp = eq; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15138 | cq->host_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15139 | cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL; |
| 15140 | cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, |
| 15141 | cq->entry_count); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15142 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15143 | |
| 15144 | rc = 0; |
| 15145 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 15146 | memset(dmabuf->virt, 0, hw_page_size); |
| 15147 | cnt = page_idx + dmabuf->buffer_tag; |
| 15148 | cq_set->u.request.page[cnt].addr_lo = |
| 15149 | putPaddrLow(dmabuf->phys); |
| 15150 | cq_set->u.request.page[cnt].addr_hi = |
| 15151 | putPaddrHigh(dmabuf->phys); |
| 15152 | rc++; |
| 15153 | } |
| 15154 | page_idx += rc; |
| 15155 | } |
| 15156 | |
| 15157 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15158 | |
| 15159 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15160 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15161 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15162 | if (shdr_status || shdr_add_status || rc) { |
| 15163 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15164 | "3119 CQ_CREATE_SET mailbox failed with " |
| 15165 | "status x%x add_status x%x, mbx status x%x\n", |
| 15166 | shdr_status, shdr_add_status, rc); |
| 15167 | status = -ENXIO; |
| 15168 | goto out; |
| 15169 | } |
| 15170 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 15171 | if (rc == 0xFFFF) { |
| 15172 | status = -ENXIO; |
| 15173 | goto out; |
| 15174 | } |
| 15175 | |
| 15176 | for (idx = 0; idx < numcq; idx++) { |
| 15177 | cq = cqp[idx]; |
| 15178 | cq->queue_id = rc + idx; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 15179 | if (cq->queue_id > phba->sli4_hba.cq_max) |
| 15180 | phba->sli4_hba.cq_max = cq->queue_id; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15181 | } |
| 15182 | |
| 15183 | out: |
| 15184 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15185 | return status; |
| 15186 | } |
| 15187 | |
| 15188 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15189 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15190 | * @phba: HBA structure that indicates port to create a queue on. |
| 15191 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15192 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 15193 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15194 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15195 | * This function provides failback (fb) functionality when the |
| 15196 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 15197 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15198 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15199 | * This routine cannot fail as all attributes were previously accessed and |
| 15200 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15201 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15202 | static void |
| 15203 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15204 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15205 | { |
| 15206 | struct lpfc_mbx_mq_create *mq_create; |
| 15207 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15208 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15209 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15210 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 15211 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15212 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15213 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 15214 | length, LPFC_SLI4_MBX_EMBED); |
| 15215 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15216 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15217 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15218 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15219 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15220 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 15221 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15222 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15223 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15224 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15225 | break; |
| 15226 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15227 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15228 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15229 | break; |
| 15230 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15231 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15232 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15233 | break; |
| 15234 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15235 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 15236 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15237 | break; |
| 15238 | } |
| 15239 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 15240 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15241 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15242 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15243 | putPaddrHigh(dmabuf->phys); |
| 15244 | } |
| 15245 | } |
| 15246 | |
| 15247 | /** |
| 15248 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 15249 | * @phba: HBA structure that indicates port to create a queue on. |
| 15250 | * @mq: The queue structure to use to create the mailbox queue. |
| 15251 | * @cq: The completion queue to associate with this cq. |
| 15252 | * @subtype: The queue's subtype. |
| 15253 | * |
| 15254 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 15255 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 15256 | * |
| 15257 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 15258 | * is used to get the entry count and entry size that are necessary to |
| 15259 | * determine the number of pages to allocate and use for this queue. This |
| 15260 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 15261 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 15262 | * command to finish before continuing. |
| 15263 | * |
| 15264 | * 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] | 15265 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15266 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15267 | **/ |
| 15268 | int32_t |
| 15269 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 15270 | struct lpfc_queue *cq, uint32_t subtype) |
| 15271 | { |
| 15272 | struct lpfc_mbx_mq_create *mq_create; |
| 15273 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 15274 | struct lpfc_dmabuf *dmabuf; |
| 15275 | LPFC_MBOXQ_t *mbox; |
| 15276 | int rc, length, status = 0; |
| 15277 | uint32_t shdr_status, shdr_add_status; |
| 15278 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15279 | 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] | 15280 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15281 | /* sanity check on queue memory */ |
| 15282 | if (!mq || !cq) |
| 15283 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15284 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15285 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15286 | |
| 15287 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15288 | if (!mbox) |
| 15289 | return -ENOMEM; |
| 15290 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 15291 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15292 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15293 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 15294 | length, LPFC_SLI4_MBX_EMBED); |
| 15295 | |
| 15296 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15297 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15298 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 15299 | &mq_create_ext->u.request, mq->page_count); |
| 15300 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 15301 | &mq_create_ext->u.request, 1); |
| 15302 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15303 | &mq_create_ext->u.request, 1); |
| 15304 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 15305 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15306 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 15307 | &mq_create_ext->u.request, 1); |
| 15308 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 15309 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15310 | 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] | 15311 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15312 | phba->sli4_hba.pc_sli4_params.mqv); |
| 15313 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 15314 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 15315 | cq->queue_id); |
| 15316 | else |
| 15317 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 15318 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15319 | switch (mq->entry_count) { |
| 15320 | default: |
| 15321 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15322 | "0362 Unsupported MQ count. (%d)\n", |
| 15323 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15324 | if (mq->entry_count < 16) { |
| 15325 | status = -EINVAL; |
| 15326 | goto out; |
| 15327 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15328 | /* otherwise default to smallest count (drop through) */ |
| 15329 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15330 | bf_set(lpfc_mq_context_ring_size, |
| 15331 | &mq_create_ext->u.request.context, |
| 15332 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15333 | break; |
| 15334 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15335 | bf_set(lpfc_mq_context_ring_size, |
| 15336 | &mq_create_ext->u.request.context, |
| 15337 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15338 | break; |
| 15339 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15340 | bf_set(lpfc_mq_context_ring_size, |
| 15341 | &mq_create_ext->u.request.context, |
| 15342 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15343 | break; |
| 15344 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15345 | bf_set(lpfc_mq_context_ring_size, |
| 15346 | &mq_create_ext->u.request.context, |
| 15347 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15348 | break; |
| 15349 | } |
| 15350 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15351 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15352 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15353 | putPaddrLow(dmabuf->phys); |
| 15354 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15355 | putPaddrHigh(dmabuf->phys); |
| 15356 | } |
| 15357 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15358 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15359 | &mq_create_ext->u.response); |
| 15360 | if (rc != MBX_SUCCESS) { |
| 15361 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15362 | "2795 MQ_CREATE_EXT failed with " |
| 15363 | "status x%x. Failback to MQ_CREATE.\n", |
| 15364 | rc); |
| 15365 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 15366 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15367 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15368 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 15369 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15370 | &mq_create->u.response); |
| 15371 | } |
| 15372 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15373 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15374 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15375 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15376 | if (shdr_status || shdr_add_status || rc) { |
| 15377 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15378 | "2502 MQ_CREATE mailbox failed with " |
| 15379 | "status x%x add_status x%x, mbx status x%x\n", |
| 15380 | shdr_status, shdr_add_status, rc); |
| 15381 | status = -ENXIO; |
| 15382 | goto out; |
| 15383 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15384 | if (mq->queue_id == 0xFFFF) { |
| 15385 | status = -ENXIO; |
| 15386 | goto out; |
| 15387 | } |
| 15388 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15389 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15390 | mq->subtype = subtype; |
| 15391 | mq->host_index = 0; |
| 15392 | mq->hba_index = 0; |
| 15393 | |
| 15394 | /* link the mq onto the parent cq child list */ |
| 15395 | list_add_tail(&mq->list, &cq->child_list); |
| 15396 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15397 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15398 | return status; |
| 15399 | } |
| 15400 | |
| 15401 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15402 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 15403 | * @phba: HBA structure that indicates port to create a queue on. |
| 15404 | * @wq: The queue structure to use to create the work queue. |
| 15405 | * @cq: The completion queue to bind this work queue to. |
| 15406 | * @subtype: The subtype of the work queue indicating its functionality. |
| 15407 | * |
| 15408 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 15409 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 15410 | * |
| 15411 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 15412 | * is used to get the entry count and entry size that are necessary to |
| 15413 | * determine the number of pages to allocate and use for this queue. The @cq |
| 15414 | * is used to indicate which completion queue to bind this work queue to. This |
| 15415 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 15416 | * work queue. This function is asynchronous and will wait for the mailbox |
| 15417 | * command to finish before continuing. |
| 15418 | * |
| 15419 | * 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] | 15420 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15421 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15422 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15423 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15424 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 15425 | struct lpfc_queue *cq, uint32_t subtype) |
| 15426 | { |
| 15427 | struct lpfc_mbx_wq_create *wq_create; |
| 15428 | struct lpfc_dmabuf *dmabuf; |
| 15429 | LPFC_MBOXQ_t *mbox; |
| 15430 | int rc, length, status = 0; |
| 15431 | uint32_t shdr_status, shdr_add_status; |
| 15432 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15433 | 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] | 15434 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15435 | void __iomem *bar_memmap_p; |
| 15436 | uint32_t db_offset; |
| 15437 | uint16_t pci_barset; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15438 | uint8_t dpp_barset; |
| 15439 | uint32_t dpp_offset; |
| 15440 | unsigned long pg_addr; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15441 | uint8_t wq_create_version; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15442 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15443 | /* sanity check on queue memory */ |
| 15444 | if (!wq || !cq) |
| 15445 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15446 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15447 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15448 | |
| 15449 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15450 | if (!mbox) |
| 15451 | return -ENOMEM; |
| 15452 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 15453 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15454 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15455 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 15456 | length, LPFC_SLI4_MBX_EMBED); |
| 15457 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15458 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15459 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 15460 | wq->page_count); |
| 15461 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 15462 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15463 | |
| 15464 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15465 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15466 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15467 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 15468 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 15469 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15470 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15471 | else |
| 15472 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15473 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15474 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15475 | if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) |
| 15476 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15477 | else |
| 15478 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15479 | |
| 15480 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15481 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15482 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 15483 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 15484 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15485 | LPFC_Q_CREATE_VERSION_1); |
| 15486 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15487 | switch (wq->entry_size) { |
| 15488 | default: |
| 15489 | case 64: |
| 15490 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15491 | &wq_create->u.request_1, |
| 15492 | LPFC_WQ_WQE_SIZE_64); |
| 15493 | break; |
| 15494 | case 128: |
| 15495 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15496 | &wq_create->u.request_1, |
| 15497 | LPFC_WQ_WQE_SIZE_128); |
| 15498 | break; |
| 15499 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15500 | /* Request DPP by default */ |
| 15501 | 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] | 15502 | bf_set(lpfc_mbx_wq_create_page_size, |
| 15503 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15504 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15505 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15506 | break; |
| 15507 | default: |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15508 | page = wq_create->u.request.page; |
| 15509 | break; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15510 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15511 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15512 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15513 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15514 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 15515 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15516 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15517 | |
| 15518 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15519 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 15520 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15521 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15522 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15523 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15524 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15525 | if (shdr_status || shdr_add_status || rc) { |
| 15526 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15527 | "2503 WQ_CREATE mailbox failed with " |
| 15528 | "status x%x add_status x%x, mbx status x%x\n", |
| 15529 | shdr_status, shdr_add_status, rc); |
| 15530 | status = -ENXIO; |
| 15531 | goto out; |
| 15532 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15533 | |
| 15534 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) |
| 15535 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, |
| 15536 | &wq_create->u.response); |
| 15537 | else |
| 15538 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, |
| 15539 | &wq_create->u.response_1); |
| 15540 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15541 | if (wq->queue_id == 0xFFFF) { |
| 15542 | status = -ENXIO; |
| 15543 | goto out; |
| 15544 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15545 | |
| 15546 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15547 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { |
| 15548 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15549 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 15550 | &wq_create->u.response); |
| 15551 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15552 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15554 | "3265 WQ[%d] doorbell format " |
| 15555 | "not supported: x%x\n", |
| 15556 | wq->queue_id, wq->db_format); |
| 15557 | status = -EINVAL; |
| 15558 | goto out; |
| 15559 | } |
| 15560 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 15561 | &wq_create->u.response); |
| 15562 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15563 | pci_barset); |
| 15564 | if (!bar_memmap_p) { |
| 15565 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15566 | "3263 WQ[%d] failed to memmap " |
| 15567 | "pci barset:x%x\n", |
| 15568 | wq->queue_id, pci_barset); |
| 15569 | status = -ENOMEM; |
| 15570 | goto out; |
| 15571 | } |
| 15572 | db_offset = wq_create->u.response.doorbell_offset; |
| 15573 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 15574 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 15575 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15576 | "3252 WQ[%d] doorbell offset " |
| 15577 | "not supported: x%x\n", |
| 15578 | wq->queue_id, db_offset); |
| 15579 | status = -EINVAL; |
| 15580 | goto out; |
| 15581 | } |
| 15582 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15583 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15584 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15585 | "format:x%x\n", wq->queue_id, |
| 15586 | pci_barset, db_offset, wq->db_format); |
| 15587 | } else |
| 15588 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15589 | } else { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15590 | /* Check if DPP was honored by the firmware */ |
| 15591 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, |
| 15592 | &wq_create->u.response_1); |
| 15593 | if (wq->dpp_enable) { |
| 15594 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, |
| 15595 | &wq_create->u.response_1); |
| 15596 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15597 | pci_barset); |
| 15598 | if (!bar_memmap_p) { |
| 15599 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15600 | "3267 WQ[%d] failed to memmap " |
| 15601 | "pci barset:x%x\n", |
| 15602 | wq->queue_id, pci_barset); |
| 15603 | status = -ENOMEM; |
| 15604 | goto out; |
| 15605 | } |
| 15606 | db_offset = wq_create->u.response_1.doorbell_offset; |
| 15607 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15608 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, |
| 15609 | &wq_create->u.response_1); |
| 15610 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, |
| 15611 | &wq_create->u.response_1); |
| 15612 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15613 | dpp_barset); |
| 15614 | if (!bar_memmap_p) { |
| 15615 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15616 | "3268 WQ[%d] failed to memmap " |
| 15617 | "pci barset:x%x\n", |
| 15618 | wq->queue_id, dpp_barset); |
| 15619 | status = -ENOMEM; |
| 15620 | goto out; |
| 15621 | } |
| 15622 | dpp_offset = wq_create->u.response_1.dpp_offset; |
| 15623 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; |
| 15624 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15625 | "3271 WQ[%d]: barset:x%x, offset:x%x, " |
| 15626 | "dpp_id:x%x dpp_barset:x%x " |
| 15627 | "dpp_offset:x%x\n", |
| 15628 | wq->queue_id, pci_barset, db_offset, |
| 15629 | wq->dpp_id, dpp_barset, dpp_offset); |
| 15630 | |
| 15631 | /* Enable combined writes for DPP aperture */ |
| 15632 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; |
| 15633 | #ifdef CONFIG_X86 |
| 15634 | rc = set_memory_wc(pg_addr, 1); |
| 15635 | if (rc) { |
| 15636 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15637 | "3272 Cannot setup Combined " |
| 15638 | "Write on WQ[%d] - disable DPP\n", |
| 15639 | wq->queue_id); |
| 15640 | phba->cfg_enable_dpp = 0; |
| 15641 | } |
| 15642 | #else |
| 15643 | phba->cfg_enable_dpp = 0; |
| 15644 | #endif |
| 15645 | } else |
| 15646 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15647 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15648 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 15649 | if (wq->pring == NULL) { |
| 15650 | status = -ENOMEM; |
| 15651 | goto out; |
| 15652 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15653 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15654 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15655 | wq->subtype = subtype; |
| 15656 | wq->host_index = 0; |
| 15657 | wq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15658 | wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15659 | |
| 15660 | /* link the wq onto the parent cq child list */ |
| 15661 | list_add_tail(&wq->list, &cq->child_list); |
| 15662 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15663 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15664 | return status; |
| 15665 | } |
| 15666 | |
| 15667 | /** |
| 15668 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 15669 | * @phba: HBA structure that indicates port to create a queue on. |
| 15670 | * @hrq: The queue structure to use to create the header receive queue. |
| 15671 | * @drq: The queue structure to use to create the data receive queue. |
| 15672 | * @cq: The completion queue to bind this work queue to. |
| 15673 | * |
| 15674 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15675 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15676 | * to the HBA. |
| 15677 | * |
| 15678 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15679 | * struct is used to get the entry count that is necessary to determine the |
| 15680 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15681 | * completion queue to bind received buffers that are posted to these queues to. |
| 15682 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15683 | * receive queue pair. This function is asynchronous and will wait for the |
| 15684 | * mailbox command to finish before continuing. |
| 15685 | * |
| 15686 | * 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] | 15687 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15688 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15689 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15690 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15691 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15692 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 15693 | { |
| 15694 | struct lpfc_mbx_rq_create *rq_create; |
| 15695 | struct lpfc_dmabuf *dmabuf; |
| 15696 | LPFC_MBOXQ_t *mbox; |
| 15697 | int rc, length, status = 0; |
| 15698 | uint32_t shdr_status, shdr_add_status; |
| 15699 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15700 | 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] | 15701 | void __iomem *bar_memmap_p; |
| 15702 | uint32_t db_offset; |
| 15703 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15704 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15705 | /* sanity check on queue memory */ |
| 15706 | if (!hrq || !drq || !cq) |
| 15707 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15708 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15709 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15710 | |
| 15711 | if (hrq->entry_count != drq->entry_count) |
| 15712 | return -EINVAL; |
| 15713 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15714 | if (!mbox) |
| 15715 | return -ENOMEM; |
| 15716 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 15717 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15718 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15719 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15720 | length, LPFC_SLI4_MBX_EMBED); |
| 15721 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15722 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15723 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15724 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15725 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15726 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15727 | &rq_create->u.request.context, |
| 15728 | hrq->entry_count); |
| 15729 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15730 | bf_set(lpfc_rq_context_rqe_size, |
| 15731 | &rq_create->u.request.context, |
| 15732 | LPFC_RQE_SIZE_8); |
| 15733 | bf_set(lpfc_rq_context_page_size, |
| 15734 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15735 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15736 | } else { |
| 15737 | switch (hrq->entry_count) { |
| 15738 | default: |
| 15739 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15740 | "2535 Unsupported RQ count. (%d)\n", |
| 15741 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15742 | if (hrq->entry_count < 512) { |
| 15743 | status = -EINVAL; |
| 15744 | goto out; |
| 15745 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15746 | /* otherwise default to smallest count (drop through) */ |
| 15747 | case 512: |
| 15748 | bf_set(lpfc_rq_context_rqe_count, |
| 15749 | &rq_create->u.request.context, |
| 15750 | LPFC_RQ_RING_SIZE_512); |
| 15751 | break; |
| 15752 | case 1024: |
| 15753 | bf_set(lpfc_rq_context_rqe_count, |
| 15754 | &rq_create->u.request.context, |
| 15755 | LPFC_RQ_RING_SIZE_1024); |
| 15756 | break; |
| 15757 | case 2048: |
| 15758 | bf_set(lpfc_rq_context_rqe_count, |
| 15759 | &rq_create->u.request.context, |
| 15760 | LPFC_RQ_RING_SIZE_2048); |
| 15761 | break; |
| 15762 | case 4096: |
| 15763 | bf_set(lpfc_rq_context_rqe_count, |
| 15764 | &rq_create->u.request.context, |
| 15765 | LPFC_RQ_RING_SIZE_4096); |
| 15766 | break; |
| 15767 | } |
| 15768 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 15769 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15770 | } |
| 15771 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15772 | cq->queue_id); |
| 15773 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15774 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15775 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15776 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15777 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15778 | putPaddrLow(dmabuf->phys); |
| 15779 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15780 | putPaddrHigh(dmabuf->phys); |
| 15781 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15782 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15783 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 15784 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15785 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15786 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15787 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15788 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15789 | if (shdr_status || shdr_add_status || rc) { |
| 15790 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15791 | "2504 RQ_CREATE mailbox failed with " |
| 15792 | "status x%x add_status x%x, mbx status x%x\n", |
| 15793 | shdr_status, shdr_add_status, rc); |
| 15794 | status = -ENXIO; |
| 15795 | goto out; |
| 15796 | } |
| 15797 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15798 | if (hrq->queue_id == 0xFFFF) { |
| 15799 | status = -ENXIO; |
| 15800 | goto out; |
| 15801 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15802 | |
| 15803 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15804 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 15805 | &rq_create->u.response); |
| 15806 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15807 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15808 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15809 | "3262 RQ [%d] doorbell format not " |
| 15810 | "supported: x%x\n", hrq->queue_id, |
| 15811 | hrq->db_format); |
| 15812 | status = -EINVAL; |
| 15813 | goto out; |
| 15814 | } |
| 15815 | |
| 15816 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 15817 | &rq_create->u.response); |
| 15818 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15819 | if (!bar_memmap_p) { |
| 15820 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15821 | "3269 RQ[%d] failed to memmap pci " |
| 15822 | "barset:x%x\n", hrq->queue_id, |
| 15823 | pci_barset); |
| 15824 | status = -ENOMEM; |
| 15825 | goto out; |
| 15826 | } |
| 15827 | |
| 15828 | db_offset = rq_create->u.response.doorbell_offset; |
| 15829 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 15830 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 15831 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15832 | "3270 RQ[%d] doorbell offset not " |
| 15833 | "supported: x%x\n", hrq->queue_id, |
| 15834 | db_offset); |
| 15835 | status = -EINVAL; |
| 15836 | goto out; |
| 15837 | } |
| 15838 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 15839 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15840 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 15841 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 15842 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15843 | } else { |
| 15844 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15845 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15846 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15847 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15848 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15849 | hrq->subtype = subtype; |
| 15850 | hrq->host_index = 0; |
| 15851 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15852 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15853 | |
| 15854 | /* now create the data queue */ |
| 15855 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15856 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15857 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15858 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15859 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15860 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15861 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15862 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15863 | if (subtype == LPFC_NVMET) |
| 15864 | rq_create->u.request.context.buffer_size = |
| 15865 | LPFC_NVMET_DATA_BUF_SIZE; |
| 15866 | else |
| 15867 | rq_create->u.request.context.buffer_size = |
| 15868 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15869 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 15870 | LPFC_RQE_SIZE_8); |
| 15871 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 15872 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15873 | } else { |
| 15874 | switch (drq->entry_count) { |
| 15875 | default: |
| 15876 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15877 | "2536 Unsupported RQ count. (%d)\n", |
| 15878 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15879 | if (drq->entry_count < 512) { |
| 15880 | status = -EINVAL; |
| 15881 | goto out; |
| 15882 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15883 | /* otherwise default to smallest count (drop through) */ |
| 15884 | case 512: |
| 15885 | bf_set(lpfc_rq_context_rqe_count, |
| 15886 | &rq_create->u.request.context, |
| 15887 | LPFC_RQ_RING_SIZE_512); |
| 15888 | break; |
| 15889 | case 1024: |
| 15890 | bf_set(lpfc_rq_context_rqe_count, |
| 15891 | &rq_create->u.request.context, |
| 15892 | LPFC_RQ_RING_SIZE_1024); |
| 15893 | break; |
| 15894 | case 2048: |
| 15895 | bf_set(lpfc_rq_context_rqe_count, |
| 15896 | &rq_create->u.request.context, |
| 15897 | LPFC_RQ_RING_SIZE_2048); |
| 15898 | break; |
| 15899 | case 4096: |
| 15900 | bf_set(lpfc_rq_context_rqe_count, |
| 15901 | &rq_create->u.request.context, |
| 15902 | LPFC_RQ_RING_SIZE_4096); |
| 15903 | break; |
| 15904 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15905 | if (subtype == LPFC_NVMET) |
| 15906 | bf_set(lpfc_rq_context_buf_size, |
| 15907 | &rq_create->u.request.context, |
| 15908 | LPFC_NVMET_DATA_BUF_SIZE); |
| 15909 | else |
| 15910 | bf_set(lpfc_rq_context_buf_size, |
| 15911 | &rq_create->u.request.context, |
| 15912 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15913 | } |
| 15914 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15915 | cq->queue_id); |
| 15916 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15917 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15918 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15919 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15920 | putPaddrLow(dmabuf->phys); |
| 15921 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15922 | putPaddrHigh(dmabuf->phys); |
| 15923 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15924 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15925 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15926 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15927 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15928 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15929 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15930 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15931 | if (shdr_status || shdr_add_status || rc) { |
| 15932 | status = -ENXIO; |
| 15933 | goto out; |
| 15934 | } |
| 15935 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15936 | if (drq->queue_id == 0xFFFF) { |
| 15937 | status = -ENXIO; |
| 15938 | goto out; |
| 15939 | } |
| 15940 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15941 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15942 | drq->subtype = subtype; |
| 15943 | drq->host_index = 0; |
| 15944 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 15945 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15946 | |
| 15947 | /* link the header and data RQs onto the parent cq child list */ |
| 15948 | list_add_tail(&hrq->list, &cq->child_list); |
| 15949 | list_add_tail(&drq->list, &cq->child_list); |
| 15950 | |
| 15951 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15952 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15953 | return status; |
| 15954 | } |
| 15955 | |
| 15956 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15957 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 15958 | * @phba: HBA structure that indicates port to create a queue on. |
| 15959 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 15960 | * @drqp: The queue structure array to use to create the data receive queues. |
| 15961 | * @cqp: The completion queue array to bind these receive queues to. |
| 15962 | * |
| 15963 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15964 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15965 | * to the HBA. |
| 15966 | * |
| 15967 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15968 | * struct is used to get the entry count that is necessary to determine the |
| 15969 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15970 | * completion queue to bind received buffers that are posted to these queues to. |
| 15971 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15972 | * receive queue pair. This function is asynchronous and will wait for the |
| 15973 | * mailbox command to finish before continuing. |
| 15974 | * |
| 15975 | * On success this function will return a zero. If unable to allocate enough |
| 15976 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15977 | * fails this function will return -ENXIO. |
| 15978 | **/ |
| 15979 | int |
| 15980 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 15981 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 15982 | uint32_t subtype) |
| 15983 | { |
| 15984 | struct lpfc_queue *hrq, *drq, *cq; |
| 15985 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 15986 | struct lpfc_dmabuf *dmabuf; |
| 15987 | LPFC_MBOXQ_t *mbox; |
| 15988 | int rc, length, alloclen, status = 0; |
| 15989 | int cnt, idx, numrq, page_idx = 0; |
| 15990 | uint32_t shdr_status, shdr_add_status; |
| 15991 | union lpfc_sli4_cfg_shdr *shdr; |
| 15992 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15993 | |
| 15994 | numrq = phba->cfg_nvmet_mrq; |
| 15995 | /* sanity check on array memory */ |
| 15996 | if (!hrqp || !drqp || !cqp || !numrq) |
| 15997 | return -ENODEV; |
| 15998 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15999 | hw_page_size = SLI4_PAGE_SIZE; |
| 16000 | |
| 16001 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16002 | if (!mbox) |
| 16003 | return -ENOMEM; |
| 16004 | |
| 16005 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 16006 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 16007 | sizeof(struct dma_address)); |
| 16008 | |
| 16009 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16010 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 16011 | LPFC_SLI4_MBX_NEMBED); |
| 16012 | if (alloclen < length) { |
| 16013 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16014 | "3099 Allocated DMA memory size (%d) is " |
| 16015 | "less than the requested DMA memory size " |
| 16016 | "(%d)\n", alloclen, length); |
| 16017 | status = -ENOMEM; |
| 16018 | goto out; |
| 16019 | } |
| 16020 | |
| 16021 | |
| 16022 | |
| 16023 | rq_create = mbox->sge_array->addr[0]; |
| 16024 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 16025 | |
| 16026 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 16027 | cnt = 0; |
| 16028 | |
| 16029 | for (idx = 0; idx < numrq; idx++) { |
| 16030 | hrq = hrqp[idx]; |
| 16031 | drq = drqp[idx]; |
| 16032 | cq = cqp[idx]; |
| 16033 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16034 | /* sanity check on queue memory */ |
| 16035 | if (!hrq || !drq || !cq) { |
| 16036 | status = -ENODEV; |
| 16037 | goto out; |
| 16038 | } |
| 16039 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 16040 | if (hrq->entry_count != drq->entry_count) { |
| 16041 | status = -EINVAL; |
| 16042 | goto out; |
| 16043 | } |
| 16044 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16045 | if (idx == 0) { |
| 16046 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 16047 | &rq_create->u.request, |
| 16048 | hrq->page_count); |
| 16049 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 16050 | &rq_create->u.request, (numrq * 2)); |
| 16051 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 16052 | 1); |
| 16053 | bf_set(lpfc_rq_context_base_cq, |
| 16054 | &rq_create->u.request.context, |
| 16055 | cq->queue_id); |
| 16056 | bf_set(lpfc_rq_context_data_size, |
| 16057 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 16058 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16059 | bf_set(lpfc_rq_context_hdr_size, |
| 16060 | &rq_create->u.request.context, |
| 16061 | LPFC_HDR_BUF_SIZE); |
| 16062 | bf_set(lpfc_rq_context_rqe_count_1, |
| 16063 | &rq_create->u.request.context, |
| 16064 | hrq->entry_count); |
| 16065 | bf_set(lpfc_rq_context_rqe_size, |
| 16066 | &rq_create->u.request.context, |
| 16067 | LPFC_RQE_SIZE_8); |
| 16068 | bf_set(lpfc_rq_context_page_size, |
| 16069 | &rq_create->u.request.context, |
| 16070 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 16071 | } |
| 16072 | rc = 0; |
| 16073 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 16074 | memset(dmabuf->virt, 0, hw_page_size); |
| 16075 | cnt = page_idx + dmabuf->buffer_tag; |
| 16076 | rq_create->u.request.page[cnt].addr_lo = |
| 16077 | putPaddrLow(dmabuf->phys); |
| 16078 | rq_create->u.request.page[cnt].addr_hi = |
| 16079 | putPaddrHigh(dmabuf->phys); |
| 16080 | rc++; |
| 16081 | } |
| 16082 | page_idx += rc; |
| 16083 | |
| 16084 | rc = 0; |
| 16085 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 16086 | memset(dmabuf->virt, 0, hw_page_size); |
| 16087 | cnt = page_idx + dmabuf->buffer_tag; |
| 16088 | rq_create->u.request.page[cnt].addr_lo = |
| 16089 | putPaddrLow(dmabuf->phys); |
| 16090 | rq_create->u.request.page[cnt].addr_hi = |
| 16091 | putPaddrHigh(dmabuf->phys); |
| 16092 | rc++; |
| 16093 | } |
| 16094 | page_idx += rc; |
| 16095 | |
| 16096 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 16097 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16098 | hrq->type = LPFC_HRQ; |
| 16099 | hrq->assoc_qid = cq->queue_id; |
| 16100 | hrq->subtype = subtype; |
| 16101 | hrq->host_index = 0; |
| 16102 | hrq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16103 | hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16104 | |
| 16105 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 16106 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 16107 | drq->type = LPFC_DRQ; |
| 16108 | drq->assoc_qid = cq->queue_id; |
| 16109 | drq->subtype = subtype; |
| 16110 | drq->host_index = 0; |
| 16111 | drq->hba_index = 0; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16112 | drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 16113 | |
| 16114 | list_add_tail(&hrq->list, &cq->child_list); |
| 16115 | list_add_tail(&drq->list, &cq->child_list); |
| 16116 | } |
| 16117 | |
| 16118 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16119 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16120 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16121 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16122 | if (shdr_status || shdr_add_status || rc) { |
| 16123 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16124 | "3120 RQ_CREATE mailbox failed with " |
| 16125 | "status x%x add_status x%x, mbx status x%x\n", |
| 16126 | shdr_status, shdr_add_status, rc); |
| 16127 | status = -ENXIO; |
| 16128 | goto out; |
| 16129 | } |
| 16130 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 16131 | if (rc == 0xFFFF) { |
| 16132 | status = -ENXIO; |
| 16133 | goto out; |
| 16134 | } |
| 16135 | |
| 16136 | /* Initialize all RQs with associated queue id */ |
| 16137 | for (idx = 0; idx < numrq; idx++) { |
| 16138 | hrq = hrqp[idx]; |
| 16139 | hrq->queue_id = rc + (2 * idx); |
| 16140 | drq = drqp[idx]; |
| 16141 | drq->queue_id = rc + (2 * idx) + 1; |
| 16142 | } |
| 16143 | |
| 16144 | out: |
| 16145 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16146 | return status; |
| 16147 | } |
| 16148 | |
| 16149 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16150 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 16151 | * @eq: The queue structure associated with the queue to destroy. |
| 16152 | * |
| 16153 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 16154 | * command, specific to the type of queue, to the HBA. |
| 16155 | * |
| 16156 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 16157 | * |
| 16158 | * 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] | 16159 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16160 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16161 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16162 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 16163 | { |
| 16164 | LPFC_MBOXQ_t *mbox; |
| 16165 | int rc, length, status = 0; |
| 16166 | uint32_t shdr_status, shdr_add_status; |
| 16167 | union lpfc_sli4_cfg_shdr *shdr; |
| 16168 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16169 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16170 | if (!eq) |
| 16171 | return -ENODEV; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 16172 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16173 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16174 | if (!mbox) |
| 16175 | return -ENOMEM; |
| 16176 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 16177 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16178 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16179 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 16180 | length, LPFC_SLI4_MBX_EMBED); |
| 16181 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 16182 | eq->queue_id); |
| 16183 | mbox->vport = eq->phba->pport; |
| 16184 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16185 | |
| 16186 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 16187 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16188 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16189 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 16190 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16191 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16192 | if (shdr_status || shdr_add_status || rc) { |
| 16193 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16194 | "2505 EQ_DESTROY mailbox failed with " |
| 16195 | "status x%x add_status x%x, mbx status x%x\n", |
| 16196 | shdr_status, shdr_add_status, rc); |
| 16197 | status = -ENXIO; |
| 16198 | } |
| 16199 | |
| 16200 | /* Remove eq from any list */ |
| 16201 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16202 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16203 | return status; |
| 16204 | } |
| 16205 | |
| 16206 | /** |
| 16207 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 16208 | * @cq: The queue structure associated with the queue to destroy. |
| 16209 | * |
| 16210 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 16211 | * command, specific to the type of queue, to the HBA. |
| 16212 | * |
| 16213 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 16214 | * |
| 16215 | * 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] | 16216 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16217 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16218 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16219 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 16220 | { |
| 16221 | LPFC_MBOXQ_t *mbox; |
| 16222 | int rc, length, status = 0; |
| 16223 | uint32_t shdr_status, shdr_add_status; |
| 16224 | union lpfc_sli4_cfg_shdr *shdr; |
| 16225 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16226 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16227 | if (!cq) |
| 16228 | return -ENODEV; |
| 16229 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16230 | if (!mbox) |
| 16231 | return -ENOMEM; |
| 16232 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 16233 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16234 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16235 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 16236 | length, LPFC_SLI4_MBX_EMBED); |
| 16237 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 16238 | cq->queue_id); |
| 16239 | mbox->vport = cq->phba->pport; |
| 16240 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16241 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 16242 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16243 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16244 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 16245 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16246 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16247 | if (shdr_status || shdr_add_status || rc) { |
| 16248 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16249 | "2506 CQ_DESTROY mailbox failed with " |
| 16250 | "status x%x add_status x%x, mbx status x%x\n", |
| 16251 | shdr_status, shdr_add_status, rc); |
| 16252 | status = -ENXIO; |
| 16253 | } |
| 16254 | /* Remove cq from any list */ |
| 16255 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16256 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16257 | return status; |
| 16258 | } |
| 16259 | |
| 16260 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16261 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 16262 | * @qm: The queue structure associated with the queue to destroy. |
| 16263 | * |
| 16264 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 16265 | * command, specific to the type of queue, to the HBA. |
| 16266 | * |
| 16267 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 16268 | * |
| 16269 | * 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] | 16270 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16271 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16272 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16273 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 16274 | { |
| 16275 | LPFC_MBOXQ_t *mbox; |
| 16276 | int rc, length, status = 0; |
| 16277 | uint32_t shdr_status, shdr_add_status; |
| 16278 | union lpfc_sli4_cfg_shdr *shdr; |
| 16279 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16280 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16281 | if (!mq) |
| 16282 | return -ENODEV; |
| 16283 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16284 | if (!mbox) |
| 16285 | return -ENOMEM; |
| 16286 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 16287 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16288 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16289 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 16290 | length, LPFC_SLI4_MBX_EMBED); |
| 16291 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 16292 | mq->queue_id); |
| 16293 | mbox->vport = mq->phba->pport; |
| 16294 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16295 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 16296 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16297 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16298 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 16299 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16300 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16301 | if (shdr_status || shdr_add_status || rc) { |
| 16302 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16303 | "2507 MQ_DESTROY mailbox failed with " |
| 16304 | "status x%x add_status x%x, mbx status x%x\n", |
| 16305 | shdr_status, shdr_add_status, rc); |
| 16306 | status = -ENXIO; |
| 16307 | } |
| 16308 | /* Remove mq from any list */ |
| 16309 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16310 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16311 | return status; |
| 16312 | } |
| 16313 | |
| 16314 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16315 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 16316 | * @wq: The queue structure associated with the queue to destroy. |
| 16317 | * |
| 16318 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 16319 | * command, specific to the type of queue, to the HBA. |
| 16320 | * |
| 16321 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 16322 | * |
| 16323 | * 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] | 16324 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16325 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16326 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16327 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 16328 | { |
| 16329 | LPFC_MBOXQ_t *mbox; |
| 16330 | int rc, length, status = 0; |
| 16331 | uint32_t shdr_status, shdr_add_status; |
| 16332 | union lpfc_sli4_cfg_shdr *shdr; |
| 16333 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16334 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16335 | if (!wq) |
| 16336 | return -ENODEV; |
| 16337 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16338 | if (!mbox) |
| 16339 | return -ENOMEM; |
| 16340 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 16341 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16342 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16343 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 16344 | length, LPFC_SLI4_MBX_EMBED); |
| 16345 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 16346 | wq->queue_id); |
| 16347 | mbox->vport = wq->phba->pport; |
| 16348 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16349 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 16350 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16351 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 16352 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16353 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16354 | if (shdr_status || shdr_add_status || rc) { |
| 16355 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16356 | "2508 WQ_DESTROY mailbox failed with " |
| 16357 | "status x%x add_status x%x, mbx status x%x\n", |
| 16358 | shdr_status, shdr_add_status, rc); |
| 16359 | status = -ENXIO; |
| 16360 | } |
| 16361 | /* Remove wq from any list */ |
| 16362 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 16363 | kfree(wq->pring); |
| 16364 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16365 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16366 | return status; |
| 16367 | } |
| 16368 | |
| 16369 | /** |
| 16370 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 16371 | * @rq: The queue structure associated with the queue to destroy. |
| 16372 | * |
| 16373 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 16374 | * command, specific to the type of queue, to the HBA. |
| 16375 | * |
| 16376 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 16377 | * |
| 16378 | * On success this function will return a zero. If the queue destroy mailbox |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 16379 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16380 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16381 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16382 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 16383 | struct lpfc_queue *drq) |
| 16384 | { |
| 16385 | LPFC_MBOXQ_t *mbox; |
| 16386 | int rc, length, status = 0; |
| 16387 | uint32_t shdr_status, shdr_add_status; |
| 16388 | union lpfc_sli4_cfg_shdr *shdr; |
| 16389 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16390 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16391 | if (!hrq || !drq) |
| 16392 | return -ENODEV; |
| 16393 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16394 | if (!mbox) |
| 16395 | return -ENOMEM; |
| 16396 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16397 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16398 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16399 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 16400 | length, LPFC_SLI4_MBX_EMBED); |
| 16401 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16402 | hrq->queue_id); |
| 16403 | mbox->vport = hrq->phba->pport; |
| 16404 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16405 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 16406 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16407 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16408 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16409 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16410 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16411 | if (shdr_status || shdr_add_status || rc) { |
| 16412 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16413 | "2509 RQ_DESTROY mailbox failed with " |
| 16414 | "status x%x add_status x%x, mbx status x%x\n", |
| 16415 | shdr_status, shdr_add_status, rc); |
| 16416 | if (rc != MBX_TIMEOUT) |
| 16417 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 16418 | return -ENXIO; |
| 16419 | } |
| 16420 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16421 | drq->queue_id); |
| 16422 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 16423 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16424 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16425 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16426 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16427 | if (shdr_status || shdr_add_status || rc) { |
| 16428 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16429 | "2510 RQ_DESTROY mailbox failed with " |
| 16430 | "status x%x add_status x%x, mbx status x%x\n", |
| 16431 | shdr_status, shdr_add_status, rc); |
| 16432 | status = -ENXIO; |
| 16433 | } |
| 16434 | list_del_init(&hrq->list); |
| 16435 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16436 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16437 | return status; |
| 16438 | } |
| 16439 | |
| 16440 | /** |
| 16441 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 16442 | * @phba: The virtual port for which this call being executed. |
| 16443 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 16444 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 16445 | * @xritag: the xritag that ties this io to the SGL pages. |
| 16446 | * |
| 16447 | * This routine will post the sgl pages for the IO that has the xritag |
| 16448 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 16449 | * creation and persists for as long as the driver is loaded. |
| 16450 | * if the caller has fewer than 256 scatter gather segments to map then |
| 16451 | * pdma_phys_addr1 should be 0. |
| 16452 | * If the caller needs to map more than 256 scatter gather segment then |
| 16453 | * pdma_phys_addr1 should be a valid physical address. |
| 16454 | * physical address for SGLs must be 64 byte aligned. |
| 16455 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 16456 | * the second sgl can have between 1 and 256 entries. |
| 16457 | * |
| 16458 | * Return codes: |
| 16459 | * 0 - Success |
| 16460 | * -ENXIO, -ENOMEM - Failure |
| 16461 | **/ |
| 16462 | int |
| 16463 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 16464 | dma_addr_t pdma_phys_addr0, |
| 16465 | dma_addr_t pdma_phys_addr1, |
| 16466 | uint16_t xritag) |
| 16467 | { |
| 16468 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 16469 | LPFC_MBOXQ_t *mbox; |
| 16470 | int rc; |
| 16471 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16472 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16473 | union lpfc_sli4_cfg_shdr *shdr; |
| 16474 | |
| 16475 | if (xritag == NO_XRI) { |
| 16476 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16477 | "0364 Invalid param:\n"); |
| 16478 | return -EINVAL; |
| 16479 | } |
| 16480 | |
| 16481 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16482 | if (!mbox) |
| 16483 | return -ENOMEM; |
| 16484 | |
| 16485 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16486 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16487 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16488 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16489 | |
| 16490 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 16491 | &mbox->u.mqe.un.post_sgl_pages; |
| 16492 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 16493 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 16494 | |
| 16495 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 16496 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 16497 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 16498 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 16499 | |
| 16500 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 16501 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 16502 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 16503 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 16504 | if (!phba->sli4_hba.intr_enable) |
| 16505 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16506 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16507 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16508 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16509 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16510 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16511 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 16512 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16513 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16514 | if (rc != MBX_TIMEOUT) |
| 16515 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16516 | if (shdr_status || shdr_add_status || rc) { |
| 16517 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16518 | "2511 POST_SGL mailbox failed with " |
| 16519 | "status x%x add_status x%x, mbx status x%x\n", |
| 16520 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16521 | } |
| 16522 | return 0; |
| 16523 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16524 | |
| 16525 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16526 | * 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] | 16527 | * @phba: pointer to lpfc hba data structure. |
| 16528 | * |
| 16529 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16530 | * HBA consistent with the SLI-4 interface spec. This routine |
| 16531 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 16532 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16533 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16534 | * Returns |
| 16535 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 16536 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 16537 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16538 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16539 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 16540 | { |
| 16541 | unsigned long xri; |
| 16542 | |
| 16543 | /* |
| 16544 | * Fetch the next logical xri. Because this index is logical, |
| 16545 | * the driver starts at 0 each time. |
| 16546 | */ |
| 16547 | spin_lock_irq(&phba->hbalock); |
| 16548 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 16549 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 16550 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 16551 | spin_unlock_irq(&phba->hbalock); |
| 16552 | return NO_XRI; |
| 16553 | } else { |
| 16554 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 16555 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16556 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16557 | spin_unlock_irq(&phba->hbalock); |
| 16558 | return xri; |
| 16559 | } |
| 16560 | |
| 16561 | /** |
| 16562 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16563 | * @phba: pointer to lpfc hba data structure. |
| 16564 | * |
| 16565 | * This routine is invoked to release an xri to the pool of |
| 16566 | * available rpis maintained by the driver. |
| 16567 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16568 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16569 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16570 | { |
| 16571 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16572 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 16573 | } |
| 16574 | } |
| 16575 | |
| 16576 | /** |
| 16577 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16578 | * @phba: pointer to lpfc hba data structure. |
| 16579 | * |
| 16580 | * This routine is invoked to release an xri to the pool of |
| 16581 | * available rpis maintained by the driver. |
| 16582 | **/ |
| 16583 | void |
| 16584 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16585 | { |
| 16586 | spin_lock_irq(&phba->hbalock); |
| 16587 | __lpfc_sli4_free_xri(phba, xri); |
| 16588 | spin_unlock_irq(&phba->hbalock); |
| 16589 | } |
| 16590 | |
| 16591 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16592 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 16593 | * @phba: Pointer to HBA context object. |
| 16594 | * |
| 16595 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 16596 | * it will return 0xffff. |
| 16597 | * The function returns the allocated xritag if successful, else returns zero. |
| 16598 | * Zero is not a valid xritag. |
| 16599 | * The caller is not required to hold any lock. |
| 16600 | **/ |
| 16601 | uint16_t |
| 16602 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 16603 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16604 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16605 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16606 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 16607 | if (xri_index == NO_XRI) |
| 16608 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 16609 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 16610 | " Max XRI is %d, Used XRI is %d\n", |
| 16611 | xri_index, |
| 16612 | phba->sli4_hba.max_cfg_param.max_xri, |
| 16613 | phba->sli4_hba.max_cfg_param.xri_used); |
| 16614 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16615 | } |
| 16616 | |
| 16617 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16618 | * 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] | 16619 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16620 | * @post_sgl_list: pointer to els sgl entry list. |
| 16621 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16622 | * |
| 16623 | * This routine is invoked to post a block of driver's sgl pages to the |
| 16624 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 16625 | * is only called when the driver is loading and after all IO has been |
| 16626 | * stopped. |
| 16627 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16628 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16629 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16630 | struct list_head *post_sgl_list, |
| 16631 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16632 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16633 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16634 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16635 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16636 | void *viraddr; |
| 16637 | LPFC_MBOXQ_t *mbox; |
| 16638 | uint32_t reqlen, alloclen, pg_pairs; |
| 16639 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16640 | uint16_t xritag_start = 0; |
| 16641 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16642 | uint32_t shdr_status, shdr_add_status; |
| 16643 | union lpfc_sli4_cfg_shdr *shdr; |
| 16644 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16645 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16646 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16647 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16648 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16649 | "2559 Block sgl registration required DMA " |
| 16650 | "size (%d) great than a page\n", reqlen); |
| 16651 | return -ENOMEM; |
| 16652 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16653 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16654 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16655 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16656 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16657 | |
| 16658 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16659 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16660 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16661 | LPFC_SLI4_MBX_NEMBED); |
| 16662 | |
| 16663 | if (alloclen < reqlen) { |
| 16664 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16665 | "0285 Allocated DMA memory size (%d) is " |
| 16666 | "less than the requested DMA memory " |
| 16667 | "size (%d)\n", alloclen, reqlen); |
| 16668 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16669 | return -ENOMEM; |
| 16670 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16671 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16672 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16673 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16674 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16675 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16676 | pg_pairs = 0; |
| 16677 | 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] | 16678 | /* Set up the sge entry */ |
| 16679 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16680 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 16681 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16682 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 16683 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16684 | cpu_to_le32(putPaddrLow(0)); |
| 16685 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16686 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16687 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16688 | /* Keep the first xritag on the list */ |
| 16689 | if (pg_pairs == 0) |
| 16690 | xritag_start = sglq_entry->sli4_xritag; |
| 16691 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16692 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16693 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16694 | |
| 16695 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16696 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16697 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16698 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16699 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16700 | if (!phba->sli4_hba.intr_enable) |
| 16701 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16702 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16703 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16704 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16705 | } |
| 16706 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16707 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16708 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16709 | if (rc != MBX_TIMEOUT) |
| 16710 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16711 | if (shdr_status || shdr_add_status || rc) { |
| 16712 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16713 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 16714 | "status x%x add_status x%x mbx status x%x\n", |
| 16715 | shdr_status, shdr_add_status, rc); |
| 16716 | rc = -ENXIO; |
| 16717 | } |
| 16718 | return rc; |
| 16719 | } |
| 16720 | |
| 16721 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16722 | * 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] | 16723 | * @phba: pointer to lpfc hba data structure. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16724 | * @nblist: pointer to nvme buffer list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16725 | * @count: number of scsi buffers on the list. |
| 16726 | * |
| 16727 | * 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] | 16728 | * SCSI buffer list @nblist to the HBA using non-embedded mailbox command. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16729 | * No Lock is held. |
| 16730 | * |
| 16731 | **/ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16732 | static int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16733 | lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist, |
| 16734 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16735 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16736 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16737 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16738 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16739 | void *viraddr; |
| 16740 | LPFC_MBOXQ_t *mbox; |
| 16741 | uint32_t reqlen, alloclen, pg_pairs; |
| 16742 | uint32_t mbox_tmo; |
| 16743 | uint16_t xritag_start = 0; |
| 16744 | int rc = 0; |
| 16745 | uint32_t shdr_status, shdr_add_status; |
| 16746 | dma_addr_t pdma_phys_bpl1; |
| 16747 | union lpfc_sli4_cfg_shdr *shdr; |
| 16748 | |
| 16749 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16750 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16751 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16752 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16753 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16754 | "6118 Block sgl registration required DMA " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16755 | "size (%d) great than a page\n", reqlen); |
| 16756 | return -ENOMEM; |
| 16757 | } |
| 16758 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16759 | if (!mbox) { |
| 16760 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16761 | "6119 Failed to allocate mbox cmd memory\n"); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16762 | return -ENOMEM; |
| 16763 | } |
| 16764 | |
| 16765 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16766 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16767 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16768 | reqlen, LPFC_SLI4_MBX_NEMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16769 | |
| 16770 | if (alloclen < reqlen) { |
| 16771 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16772 | "6120 Allocated DMA memory size (%d) is " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16773 | "less than the requested DMA memory " |
| 16774 | "size (%d)\n", alloclen, reqlen); |
| 16775 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16776 | return -ENOMEM; |
| 16777 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16778 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16779 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16780 | viraddr = mbox->sge_array->addr[0]; |
| 16781 | |
| 16782 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 16783 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16784 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16785 | |
| 16786 | pg_pairs = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16787 | list_for_each_entry(lpfc_ncmd, nblist, list) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16788 | /* Set up the sge entry */ |
| 16789 | sgl_pg_pairs->sgl_pg0_addr_lo = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16790 | cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16791 | sgl_pg_pairs->sgl_pg0_addr_hi = |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16792 | cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16793 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16794 | pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl + |
| 16795 | SGL_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16796 | else |
| 16797 | pdma_phys_bpl1 = 0; |
| 16798 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16799 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 16800 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16801 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 16802 | /* Keep the first xritag on the list */ |
| 16803 | if (pg_pairs == 0) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16804 | xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16805 | sgl_pg_pairs++; |
| 16806 | pg_pairs++; |
| 16807 | } |
| 16808 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 16809 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 16810 | /* Perform endian conversion if necessary */ |
| 16811 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 16812 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16813 | if (!phba->sli4_hba.intr_enable) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16814 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16815 | } else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16816 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16817 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16818 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16819 | shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16820 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16821 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16822 | if (rc != MBX_TIMEOUT) |
| 16823 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16824 | if (shdr_status || shdr_add_status || rc) { |
| 16825 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16826 | "6125 POST_SGL_BLOCK mailbox command failed " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16827 | "status x%x add_status x%x mbx status x%x\n", |
| 16828 | shdr_status, shdr_add_status, rc); |
| 16829 | rc = -ENXIO; |
| 16830 | } |
| 16831 | return rc; |
| 16832 | } |
| 16833 | |
| 16834 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16835 | * 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] | 16836 | * @phba: pointer to lpfc hba data structure. |
| 16837 | * @post_nblist: pointer to the nvme buffer list. |
| 16838 | * |
| 16839 | * This routine walks a list of nvme buffers that was passed in. It attempts |
| 16840 | * to construct blocks of nvme buffer sgls which contains contiguous xris and |
| 16841 | * uses the non-embedded SGL block post mailbox commands to post to the port. |
| 16842 | * For single NVME buffer sgl with non-contiguous xri, if any, it shall use |
| 16843 | * embedded SGL post mailbox command for posting. The @post_nblist passed in |
| 16844 | * must be local list, thus no lock is needed when manipulate the list. |
| 16845 | * |
| 16846 | * Returns: 0 = failure, non-zero number of successfully posted buffers. |
| 16847 | **/ |
| 16848 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16849 | lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba, |
| 16850 | struct list_head *post_nblist, int sb_count) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16851 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16852 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16853 | int status, sgl_size; |
| 16854 | int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0; |
| 16855 | dma_addr_t pdma_phys_sgl1; |
| 16856 | int last_xritag = NO_XRI; |
| 16857 | int cur_xritag; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16858 | LIST_HEAD(prep_nblist); |
| 16859 | LIST_HEAD(blck_nblist); |
| 16860 | LIST_HEAD(nvme_nblist); |
| 16861 | |
| 16862 | /* sanity check */ |
| 16863 | if (sb_count <= 0) |
| 16864 | return -EINVAL; |
| 16865 | |
| 16866 | sgl_size = phba->cfg_sg_dma_buf_size; |
| 16867 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) { |
| 16868 | list_del_init(&lpfc_ncmd->list); |
| 16869 | block_cnt++; |
| 16870 | if ((last_xritag != NO_XRI) && |
| 16871 | (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) { |
| 16872 | /* a hole in xri block, form a sgl posting block */ |
| 16873 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16874 | post_cnt = block_cnt - 1; |
| 16875 | /* prepare list for next posting block */ |
| 16876 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 16877 | block_cnt = 1; |
| 16878 | } else { |
| 16879 | /* prepare list for next posting block */ |
| 16880 | list_add_tail(&lpfc_ncmd->list, &prep_nblist); |
| 16881 | /* enough sgls for non-embed sgl mbox command */ |
| 16882 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 16883 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16884 | post_cnt = block_cnt; |
| 16885 | block_cnt = 0; |
| 16886 | } |
| 16887 | } |
| 16888 | num_posting++; |
| 16889 | last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 16890 | |
| 16891 | /* end of repost sgl list condition for NVME buffers */ |
| 16892 | if (num_posting == sb_count) { |
| 16893 | if (post_cnt == 0) { |
| 16894 | /* last sgl posting block */ |
| 16895 | list_splice_init(&prep_nblist, &blck_nblist); |
| 16896 | post_cnt = block_cnt; |
| 16897 | } else if (block_cnt == 1) { |
| 16898 | /* last single sgl with non-contiguous xri */ |
| 16899 | if (sgl_size > SGL_PAGE_SIZE) |
| 16900 | pdma_phys_sgl1 = |
| 16901 | lpfc_ncmd->dma_phys_sgl + |
| 16902 | SGL_PAGE_SIZE; |
| 16903 | else |
| 16904 | pdma_phys_sgl1 = 0; |
| 16905 | cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag; |
| 16906 | status = lpfc_sli4_post_sgl( |
| 16907 | phba, lpfc_ncmd->dma_phys_sgl, |
| 16908 | pdma_phys_sgl1, cur_xritag); |
| 16909 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16910 | /* Post error. Buffer unavailable. */ |
| 16911 | lpfc_ncmd->flags |= |
| 16912 | LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16913 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16914 | /* Post success. Bffer available. */ |
| 16915 | lpfc_ncmd->flags &= |
| 16916 | ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16917 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 16918 | num_posted++; |
| 16919 | } |
| 16920 | /* success, put on NVME buffer sgl list */ |
| 16921 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 16922 | } |
| 16923 | } |
| 16924 | |
| 16925 | /* continue until a nembed page worth of sgls */ |
| 16926 | if (post_cnt == 0) |
| 16927 | continue; |
| 16928 | |
| 16929 | /* post block of NVME buffer list sgls */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16930 | status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist, |
| 16931 | post_cnt); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16932 | |
| 16933 | /* don't reset xirtag due to hole in xri block */ |
| 16934 | if (block_cnt == 0) |
| 16935 | last_xritag = NO_XRI; |
| 16936 | |
| 16937 | /* reset NVME buffer post count for next round of posting */ |
| 16938 | post_cnt = 0; |
| 16939 | |
| 16940 | /* put posted NVME buffer-sgl posted on NVME buffer sgl list */ |
| 16941 | while (!list_empty(&blck_nblist)) { |
| 16942 | list_remove_head(&blck_nblist, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16943 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16944 | if (status) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16945 | /* Post error. Mark buffer unavailable. */ |
| 16946 | lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16947 | } else { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 16948 | /* Post success, Mark buffer available. */ |
| 16949 | lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16950 | lpfc_ncmd->status = IOSTAT_SUCCESS; |
| 16951 | num_posted++; |
| 16952 | } |
| 16953 | list_add_tail(&lpfc_ncmd->list, &nvme_nblist); |
| 16954 | } |
| 16955 | } |
| 16956 | /* Push NVME buffers with sgl posted to the available list */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 16957 | lpfc_io_buf_replenish(phba, &nvme_nblist); |
| 16958 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 16959 | return num_posted; |
| 16960 | } |
| 16961 | |
| 16962 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16963 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 16964 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 16965 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16966 | * |
| 16967 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 16968 | * valid type of frame that the LPFC driver will handle. This function will |
| 16969 | * return a zero if the frame is a valid frame or a non zero value when the |
| 16970 | * frame does not pass the check. |
| 16971 | **/ |
| 16972 | static int |
| 16973 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 16974 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 16975 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16976 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16977 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16978 | |
| 16979 | switch (fc_hdr->fh_r_ctl) { |
| 16980 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 16981 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 16982 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 16983 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 16984 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 16985 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 16986 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 16987 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 16988 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 16989 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 16990 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 16991 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 16992 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 16993 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 16994 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 16995 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 16996 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 16997 | case FC_RCTL_BA_PRMT: |
| 16998 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 16999 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 17000 | case FC_RCTL_P_RJT: /* port reject */ |
| 17001 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 17002 | case FC_RCTL_P_BSY: /* port busy */ |
| 17003 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 17004 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 17005 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17006 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17007 | case FC_RCTL_END: /* end */ |
| 17008 | break; |
| 17009 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 17010 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17011 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 17012 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 17013 | default: |
| 17014 | goto drop; |
| 17015 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17016 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17017 | switch (fc_hdr->fh_type) { |
| 17018 | case FC_TYPE_BLS: |
| 17019 | case FC_TYPE_ELS: |
| 17020 | case FC_TYPE_FCP: |
| 17021 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17022 | case FC_TYPE_NVME: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17023 | break; |
| 17024 | case FC_TYPE_IP: |
| 17025 | case FC_TYPE_ILS: |
| 17026 | default: |
| 17027 | goto drop; |
| 17028 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17029 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17030 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17031 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 17032 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17033 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 17034 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 17035 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 17036 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 17037 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17038 | return 0; |
| 17039 | drop: |
| 17040 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 17041 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 17042 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17043 | return 1; |
| 17044 | } |
| 17045 | |
| 17046 | /** |
| 17047 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 17048 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17049 | * |
| 17050 | * This function processes the FC header to retrieve the VFI from the VF |
| 17051 | * header, if one exists. This function will return the VFI if one exists |
| 17052 | * or 0 if no VSAN Header exists. |
| 17053 | **/ |
| 17054 | static uint32_t |
| 17055 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 17056 | { |
| 17057 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 17058 | |
| 17059 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 17060 | return 0; |
| 17061 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 17062 | } |
| 17063 | |
| 17064 | /** |
| 17065 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 17066 | * @phba: Pointer to the HBA structure to search for the vport on |
| 17067 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 17068 | * @fcfi: The FC Fabric ID that the frame came from |
| 17069 | * |
| 17070 | * This function searches the @phba for a vport that matches the content of the |
| 17071 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 17072 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 17073 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 17074 | * vport. |
| 17075 | **/ |
| 17076 | static struct lpfc_vport * |
| 17077 | 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] | 17078 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17079 | { |
| 17080 | struct lpfc_vport **vports; |
| 17081 | struct lpfc_vport *vport = NULL; |
| 17082 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17083 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 17084 | if (did == Fabric_DID) |
| 17085 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17086 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 17087 | !(phba->link_state == LPFC_HBA_READY)) |
| 17088 | return phba->pport; |
| 17089 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17090 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17091 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17092 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 17093 | if (phba->fcf.fcfi == fcfi && |
| 17094 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 17095 | vports[i]->fc_myDID == did) { |
| 17096 | vport = vports[i]; |
| 17097 | break; |
| 17098 | } |
| 17099 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17100 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17101 | lpfc_destroy_vport_work_array(phba, vports); |
| 17102 | return vport; |
| 17103 | } |
| 17104 | |
| 17105 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17106 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 17107 | * @vport: The vport to work on. |
| 17108 | * |
| 17109 | * This function updates the receive sequence time stamp for this vport. The |
| 17110 | * receive sequence time stamp indicates the time that the last frame of the |
| 17111 | * the sequence that has been idle for the longest amount of time was received. |
| 17112 | * the driver uses this time stamp to indicate if any received sequences have |
| 17113 | * timed out. |
| 17114 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17115 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17116 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 17117 | { |
| 17118 | struct lpfc_dmabuf *h_buf; |
| 17119 | struct hbq_dmabuf *dmabuf = NULL; |
| 17120 | |
| 17121 | /* get the oldest sequence on the rcv list */ |
| 17122 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 17123 | struct lpfc_dmabuf, list); |
| 17124 | if (!h_buf) |
| 17125 | return; |
| 17126 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17127 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 17128 | } |
| 17129 | |
| 17130 | /** |
| 17131 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 17132 | * @vport: The vport that the received sequences were sent to. |
| 17133 | * |
| 17134 | * This function cleans up all outstanding received sequences. This is called |
| 17135 | * by the driver when a link event or user action invalidates all the received |
| 17136 | * sequences. |
| 17137 | **/ |
| 17138 | void |
| 17139 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 17140 | { |
| 17141 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17142 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17143 | struct hbq_dmabuf *dmabuf = NULL; |
| 17144 | |
| 17145 | /* start with the oldest sequence on the rcv list */ |
| 17146 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17147 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17148 | list_del_init(&dmabuf->hbuf.list); |
| 17149 | list_for_each_entry_safe(d_buf, dnext, |
| 17150 | &dmabuf->dbuf.list, list) { |
| 17151 | list_del_init(&d_buf->list); |
| 17152 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17153 | } |
| 17154 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17155 | } |
| 17156 | } |
| 17157 | |
| 17158 | /** |
| 17159 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 17160 | * @vport: The vport that the received sequences were sent to. |
| 17161 | * |
| 17162 | * This function determines whether any received sequences have timed out by |
| 17163 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 17164 | * indicates that there is at least one timed out sequence this routine will |
| 17165 | * go through the received sequences one at a time from most inactive to most |
| 17166 | * active to determine which ones need to be cleaned up. Once it has determined |
| 17167 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 17168 | * without sending an abort. |
| 17169 | **/ |
| 17170 | void |
| 17171 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 17172 | { |
| 17173 | struct lpfc_dmabuf *h_buf, *hnext; |
| 17174 | struct lpfc_dmabuf *d_buf, *dnext; |
| 17175 | struct hbq_dmabuf *dmabuf = NULL; |
| 17176 | unsigned long timeout; |
| 17177 | int abort_count = 0; |
| 17178 | |
| 17179 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17180 | vport->rcv_buffer_time_stamp); |
| 17181 | if (list_empty(&vport->rcv_buffer_list) || |
| 17182 | time_before(jiffies, timeout)) |
| 17183 | return; |
| 17184 | /* start with the oldest sequence on the rcv list */ |
| 17185 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 17186 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17187 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 17188 | dmabuf->time_stamp); |
| 17189 | if (time_before(jiffies, timeout)) |
| 17190 | break; |
| 17191 | abort_count++; |
| 17192 | list_del_init(&dmabuf->hbuf.list); |
| 17193 | list_for_each_entry_safe(d_buf, dnext, |
| 17194 | &dmabuf->dbuf.list, list) { |
| 17195 | list_del_init(&d_buf->list); |
| 17196 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17197 | } |
| 17198 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 17199 | } |
| 17200 | if (abort_count) |
| 17201 | lpfc_update_rcv_time_stamp(vport); |
| 17202 | } |
| 17203 | |
| 17204 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17205 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 17206 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 17207 | * |
| 17208 | * This function searches through the existing incomplete sequences that have |
| 17209 | * been sent to this @vport. If the frame matches one of the incomplete |
| 17210 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 17211 | * make up that sequence. If no sequence is found that matches this frame then |
| 17212 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 17213 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 17214 | * the frame was linked to. |
| 17215 | **/ |
| 17216 | static struct hbq_dmabuf * |
| 17217 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17218 | { |
| 17219 | struct fc_frame_header *new_hdr; |
| 17220 | struct fc_frame_header *temp_hdr; |
| 17221 | struct lpfc_dmabuf *d_buf; |
| 17222 | struct lpfc_dmabuf *h_buf; |
| 17223 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17224 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17225 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17226 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17227 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17228 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17229 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17230 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17231 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 17232 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17233 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17234 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17235 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17236 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17237 | continue; |
| 17238 | /* found a pending sequence that matches this frame */ |
| 17239 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17240 | break; |
| 17241 | } |
| 17242 | if (!seq_dmabuf) { |
| 17243 | /* |
| 17244 | * This indicates first frame received for this sequence. |
| 17245 | * Queue the buffer on the vport's rcv_buffer_list. |
| 17246 | */ |
| 17247 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17248 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17249 | return dmabuf; |
| 17250 | } |
| 17251 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17252 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 17253 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17254 | list_del_init(&seq_dmabuf->hbuf.list); |
| 17255 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17256 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17257 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17258 | return dmabuf; |
| 17259 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17260 | /* move this sequence to the tail to indicate a young sequence */ |
| 17261 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 17262 | seq_dmabuf->time_stamp = jiffies; |
| 17263 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17264 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 17265 | temp_hdr = dmabuf->hbuf.virt; |
| 17266 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 17267 | return seq_dmabuf; |
| 17268 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17269 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17270 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 17271 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17272 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17273 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 17274 | /* |
| 17275 | * If the frame's sequence count is greater than the frame on |
| 17276 | * the list then insert the frame right after this frame |
| 17277 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17278 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 17279 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17280 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17281 | found = 1; |
| 17282 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17283 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17284 | |
| 17285 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 17286 | break; |
| 17287 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17288 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 17289 | |
| 17290 | if (found) |
| 17291 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17292 | return NULL; |
| 17293 | } |
| 17294 | |
| 17295 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17296 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 17297 | * @vport: pointer to a vitural port |
| 17298 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17299 | * |
| 17300 | * This function tries to abort from the partially assembed sequence, described |
| 17301 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 17302 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 17303 | * the frames from the partially assembled sequence. |
| 17304 | * |
| 17305 | * Return |
| 17306 | * true -- if there is matching partially assembled sequence present and all |
| 17307 | * the frames freed with the sequence; |
| 17308 | * false -- if there is no matching partially assembled sequence present so |
| 17309 | * nothing got aborted in the lower layer driver |
| 17310 | **/ |
| 17311 | static bool |
| 17312 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 17313 | struct hbq_dmabuf *dmabuf) |
| 17314 | { |
| 17315 | struct fc_frame_header *new_hdr; |
| 17316 | struct fc_frame_header *temp_hdr; |
| 17317 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 17318 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 17319 | |
| 17320 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 17321 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 17322 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 17323 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17324 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 17325 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 17326 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 17327 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 17328 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 17329 | continue; |
| 17330 | /* found a pending sequence that matches this frame */ |
| 17331 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 17332 | break; |
| 17333 | } |
| 17334 | |
| 17335 | /* Free up all the frames from the partially assembled sequence */ |
| 17336 | if (seq_dmabuf) { |
| 17337 | list_for_each_entry_safe(d_buf, n_buf, |
| 17338 | &seq_dmabuf->dbuf.list, list) { |
| 17339 | list_del_init(&d_buf->list); |
| 17340 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17341 | } |
| 17342 | return true; |
| 17343 | } |
| 17344 | return false; |
| 17345 | } |
| 17346 | |
| 17347 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17348 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 17349 | * @vport: pointer to a vitural port |
| 17350 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17351 | * |
| 17352 | * This function tries to abort from the assembed sequence from upper level |
| 17353 | * protocol, described by the information from basic abbort @dmabuf. It |
| 17354 | * checks to see whether such pending context exists at upper level protocol. |
| 17355 | * If so, it shall clean up the pending context. |
| 17356 | * |
| 17357 | * Return |
| 17358 | * true -- if there is matching pending context of the sequence cleaned |
| 17359 | * at ulp; |
| 17360 | * false -- if there is no matching pending context of the sequence present |
| 17361 | * at ulp. |
| 17362 | **/ |
| 17363 | static bool |
| 17364 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 17365 | { |
| 17366 | struct lpfc_hba *phba = vport->phba; |
| 17367 | int handled; |
| 17368 | |
| 17369 | /* Accepting abort at ulp with SLI4 only */ |
| 17370 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 17371 | return false; |
| 17372 | |
| 17373 | /* Register all caring upper level protocols to attend abort */ |
| 17374 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 17375 | if (handled) |
| 17376 | return true; |
| 17377 | |
| 17378 | return false; |
| 17379 | } |
| 17380 | |
| 17381 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17382 | * 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] | 17383 | * @phba: Pointer to HBA context object. |
| 17384 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 17385 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 17386 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17387 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17388 | * event. It properly releases the memory allocated to the sequence abort |
| 17389 | * accept iocb. |
| 17390 | **/ |
| 17391 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17392 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17393 | struct lpfc_iocbq *cmd_iocbq, |
| 17394 | struct lpfc_iocbq *rsp_iocbq) |
| 17395 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17396 | struct lpfc_nodelist *ndlp; |
| 17397 | |
| 17398 | if (cmd_iocbq) { |
| 17399 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 17400 | lpfc_nlp_put(ndlp); |
| 17401 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17402 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17403 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17404 | |
| 17405 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 17406 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 17407 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17408 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 17409 | rsp_iocbq->iocb.ulpStatus, |
| 17410 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17411 | } |
| 17412 | |
| 17413 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17414 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 17415 | * @phba: Pointer to HBA context object. |
| 17416 | * @xri: xri id in transaction. |
| 17417 | * |
| 17418 | * This function validates the xri maps to the known range of XRIs allocated an |
| 17419 | * used by the driver. |
| 17420 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17421 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17422 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 17423 | uint16_t xri) |
| 17424 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17425 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17426 | |
| 17427 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 17428 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 17429 | return i; |
| 17430 | } |
| 17431 | return NO_XRI; |
| 17432 | } |
| 17433 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17434 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17435 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17436 | * @phba: Pointer to HBA context object. |
| 17437 | * @fc_hdr: pointer to a FC frame header. |
| 17438 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17439 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17440 | * event after aborting the sequence handling. |
| 17441 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17442 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17443 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 17444 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17445 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17446 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17447 | struct lpfc_iocbq *ctiocb = NULL; |
| 17448 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17449 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17450 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17451 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17452 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17453 | |
| 17454 | if (!lpfc_is_link_up(phba)) |
| 17455 | return; |
| 17456 | |
| 17457 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 17458 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17459 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17460 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17461 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17462 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 17463 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17464 | if (!ndlp) { |
| 17465 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17466 | "1268 Failed to allocate ndlp for " |
| 17467 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 17468 | return; |
| 17469 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17470 | /* Put ndlp onto pport node list */ |
| 17471 | lpfc_enqueue_node(vport, ndlp); |
| 17472 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 17473 | /* re-setup ndlp without removing from node list */ |
| 17474 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 17475 | if (!ndlp) { |
| 17476 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17477 | "3275 Failed to active ndlp found " |
| 17478 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 17479 | return; |
| 17480 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17481 | } |
| 17482 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17483 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17484 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 17485 | if (!ctiocb) |
| 17486 | return; |
| 17487 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17488 | /* Extract the F_CTL field from FC_HDR */ |
| 17489 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 17490 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17491 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17492 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17493 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17494 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 17495 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 17496 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 17497 | |
| 17498 | /* Fill in the rest of iocb fields */ |
| 17499 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 17500 | icmd->ulpBdeCount = 0; |
| 17501 | icmd->ulpLe = 1; |
| 17502 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17503 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17504 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17505 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17506 | ctiocb->iocb_cmpl = NULL; |
| 17507 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17508 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17509 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17510 | ctiocb->sli4_xritag = NO_XRI; |
| 17511 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17512 | if (fctl & FC_FC_EX_CTX) |
| 17513 | /* Exchange responder sent the abort so we |
| 17514 | * own the oxid. |
| 17515 | */ |
| 17516 | xri = oxid; |
| 17517 | else |
| 17518 | xri = rxid; |
| 17519 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 17520 | if (lxri != NO_XRI) |
| 17521 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 17522 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17523 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 17524 | * the oxid maps to the FCP XRI range, the port no longer has |
| 17525 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 17526 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17527 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17528 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17529 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17530 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17531 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17532 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17533 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17534 | } |
| 17535 | |
| 17536 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 17537 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 17538 | * the IOCB for a BA_RJT. |
| 17539 | */ |
| 17540 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17541 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17542 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17543 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17544 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17545 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17546 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17547 | if (fctl & FC_FC_EX_CTX) { |
| 17548 | /* ABTS sent by responder to CT exchange, construction |
| 17549 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 17550 | * field and RX_ID from ABTS for RX_ID field. |
| 17551 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17552 | 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] | 17553 | } else { |
| 17554 | /* ABTS sent by initiator to CT exchange, construction |
| 17555 | * 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] | 17556 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17557 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17558 | 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] | 17559 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 17560 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17561 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17562 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17563 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17564 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 17565 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 17566 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17567 | |
| 17568 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 17569 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17570 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 17571 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 17572 | "xri x%x, Data x%x\n", |
| 17573 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 17574 | phba->link_state); |
| 17575 | lpfc_nlp_put(ndlp); |
| 17576 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17577 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 17578 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17579 | } |
| 17580 | |
| 17581 | /** |
| 17582 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 17583 | * @vport: Pointer to the vport on which this sequence was received |
| 17584 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17585 | * |
| 17586 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 17587 | * receive sequence is only partially assembed by the driver, it shall abort |
| 17588 | * the partially assembled frames for the sequence. Otherwise, if the |
| 17589 | * unsolicited receive sequence has been completely assembled and passed to |
| 17590 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 17591 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 17592 | * accept to accept the abort. |
| 17593 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17594 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17595 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 17596 | struct hbq_dmabuf *dmabuf) |
| 17597 | { |
| 17598 | struct lpfc_hba *phba = vport->phba; |
| 17599 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17600 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17601 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17602 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17603 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 17604 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17605 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17606 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17607 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17608 | /* ABTS by responder to exchange, no cleanup needed */ |
| 17609 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17610 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17611 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 17612 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 17613 | if (aborted == false) |
| 17614 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17615 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17616 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17617 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17618 | if (phba->nvmet_support) { |
| 17619 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 17620 | return; |
| 17621 | } |
| 17622 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17623 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 17624 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17625 | } |
| 17626 | |
| 17627 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17628 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 17629 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17630 | * |
| 17631 | * This function checks the sequence, starting with the frame described by |
| 17632 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 17633 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 17634 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 17635 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 17636 | * set. 3) That there are no holes in the sequence count. The function will |
| 17637 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 17638 | **/ |
| 17639 | static int |
| 17640 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 17641 | { |
| 17642 | struct fc_frame_header *hdr; |
| 17643 | struct lpfc_dmabuf *d_buf; |
| 17644 | struct hbq_dmabuf *seq_dmabuf; |
| 17645 | uint32_t fctl; |
| 17646 | int seq_count = 0; |
| 17647 | |
| 17648 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17649 | /* make sure first fame of sequence has a sequence count of zero */ |
| 17650 | if (hdr->fh_seq_cnt != seq_count) |
| 17651 | return 0; |
| 17652 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17653 | hdr->fh_f_ctl[1] << 8 | |
| 17654 | hdr->fh_f_ctl[2]); |
| 17655 | /* If last frame of sequence we can return success. */ |
| 17656 | if (fctl & FC_FC_END_SEQ) |
| 17657 | return 1; |
| 17658 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 17659 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17660 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17661 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17662 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17663 | return 0; |
| 17664 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17665 | hdr->fh_f_ctl[1] << 8 | |
| 17666 | hdr->fh_f_ctl[2]); |
| 17667 | /* If last frame of sequence we can return success. */ |
| 17668 | if (fctl & FC_FC_END_SEQ) |
| 17669 | return 1; |
| 17670 | } |
| 17671 | return 0; |
| 17672 | } |
| 17673 | |
| 17674 | /** |
| 17675 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 17676 | * @vport: Pointer to the vport on which this sequence was received |
| 17677 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17678 | * |
| 17679 | * This function takes a sequence, described by a list of frames, and creates |
| 17680 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 17681 | * used to issue to the generic unsolicited sequence handler. This routine |
| 17682 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 17683 | * to allocate an iocbq then it throw out the received frames that were not |
| 17684 | * able to be described and return a pointer to the first iocbq. If unable to |
| 17685 | * allocate any iocbqs (including the first) this function will return NULL. |
| 17686 | **/ |
| 17687 | static struct lpfc_iocbq * |
| 17688 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 17689 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17690 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17691 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 17692 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 17693 | struct fc_frame_header *fc_hdr; |
| 17694 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17695 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17696 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17697 | |
| 17698 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17699 | /* remove from receive buffer list */ |
| 17700 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17701 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17702 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17703 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17704 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17705 | /* Get an iocbq struct to fill in. */ |
| 17706 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17707 | if (first_iocbq) { |
| 17708 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17709 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17710 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17711 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17712 | |
| 17713 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 17714 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 17715 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 17716 | first_iocbq->iocb.un.rcvels.parmRo = |
| 17717 | sli4_did_from_fc_hdr(fc_hdr); |
| 17718 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 17719 | } else |
| 17720 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17721 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 17722 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 17723 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 17724 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 17725 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 17726 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17727 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17728 | tot_len = bf_get(lpfc_rcqe_length, |
| 17729 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17730 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17731 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 17732 | first_iocbq->context3 = NULL; |
| 17733 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17734 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 17735 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17736 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17737 | else |
| 17738 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 17739 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17740 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17741 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17742 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17743 | } |
| 17744 | iocbq = first_iocbq; |
| 17745 | /* |
| 17746 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 17747 | * of buffers for this sequence and save two buffers in each IOCBq |
| 17748 | */ |
| 17749 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 17750 | if (!iocbq) { |
| 17751 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17752 | continue; |
| 17753 | } |
| 17754 | if (!iocbq->context3) { |
| 17755 | iocbq->context3 = d_buf; |
| 17756 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17757 | /* We need to get the size out of the right CQE */ |
| 17758 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17759 | len = bf_get(lpfc_rcqe_length, |
| 17760 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17761 | pbde = (struct ulp_bde64 *) |
| 17762 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 17763 | if (len > LPFC_DATA_BUF_SIZE) |
| 17764 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 17765 | else |
| 17766 | pbde->tus.f.bdeSize = len; |
| 17767 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17768 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 17769 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17770 | } else { |
| 17771 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17772 | if (!iocbq) { |
| 17773 | if (first_iocbq) { |
| 17774 | first_iocbq->iocb.ulpStatus = |
| 17775 | IOSTAT_FCP_RSP_ERROR; |
| 17776 | first_iocbq->iocb.un.ulpWord[4] = |
| 17777 | IOERR_NO_RESOURCES; |
| 17778 | } |
| 17779 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17780 | continue; |
| 17781 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17782 | /* We need to get the size out of the right CQE */ |
| 17783 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17784 | len = bf_get(lpfc_rcqe_length, |
| 17785 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17786 | iocbq->context2 = d_buf; |
| 17787 | iocbq->context3 = NULL; |
| 17788 | iocbq->iocb.ulpBdeCount = 1; |
| 17789 | if (len > LPFC_DATA_BUF_SIZE) |
| 17790 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 17791 | LPFC_DATA_BUF_SIZE; |
| 17792 | else |
| 17793 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 17794 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17795 | tot_len += len; |
| 17796 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 17797 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17798 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 17799 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 17800 | } |
| 17801 | } |
| 17802 | return first_iocbq; |
| 17803 | } |
| 17804 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17805 | static void |
| 17806 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 17807 | struct hbq_dmabuf *seq_dmabuf) |
| 17808 | { |
| 17809 | struct fc_frame_header *fc_hdr; |
| 17810 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 17811 | struct lpfc_hba *phba = vport->phba; |
| 17812 | |
| 17813 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17814 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 17815 | if (!iocbq) { |
| 17816 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17817 | "2707 Ring %d handler: Failed to allocate " |
| 17818 | "iocb Rctl x%x Type x%x received\n", |
| 17819 | LPFC_ELS_RING, |
| 17820 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17821 | return; |
| 17822 | } |
| 17823 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17824 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17825 | iocbq, fc_hdr->fh_r_ctl, |
| 17826 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17827 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17828 | "2540 Ring %d handler: unexpected Rctl " |
| 17829 | "x%x Type x%x received\n", |
| 17830 | LPFC_ELS_RING, |
| 17831 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17832 | |
| 17833 | /* Free iocb created in lpfc_prep_seq */ |
| 17834 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 17835 | &iocbq->list, list) { |
| 17836 | list_del_init(&curr_iocb->list); |
| 17837 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 17838 | } |
| 17839 | lpfc_sli_release_iocbq(phba, iocbq); |
| 17840 | } |
| 17841 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17842 | static void |
| 17843 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 17844 | struct lpfc_iocbq *rspiocb) |
| 17845 | { |
| 17846 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 17847 | |
| 17848 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17849 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17850 | kfree(pcmd); |
| 17851 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17852 | lpfc_drain_txq(phba); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17853 | } |
| 17854 | |
| 17855 | static void |
| 17856 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 17857 | struct hbq_dmabuf *dmabuf) |
| 17858 | { |
| 17859 | struct fc_frame_header *fc_hdr; |
| 17860 | struct lpfc_hba *phba = vport->phba; |
| 17861 | struct lpfc_iocbq *iocbq = NULL; |
| 17862 | union lpfc_wqe *wqe; |
| 17863 | struct lpfc_dmabuf *pcmd = NULL; |
| 17864 | uint32_t frame_len; |
| 17865 | int rc; |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17866 | unsigned long iflags; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17867 | |
| 17868 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17869 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17870 | |
| 17871 | /* Send the received frame back */ |
| 17872 | iocbq = lpfc_sli_get_iocbq(phba); |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17873 | if (!iocbq) { |
| 17874 | /* Queue cq event and wakeup worker thread to process it */ |
| 17875 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 17876 | list_add_tail(&dmabuf->cq_event.list, |
| 17877 | &phba->sli4_hba.sp_queue_event); |
| 17878 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
| 17879 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 17880 | lpfc_worker_wake_up(phba); |
| 17881 | return; |
| 17882 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17883 | |
| 17884 | /* Allocate buffer for command payload */ |
| 17885 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 17886 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17887 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17888 | &pcmd->phys); |
| 17889 | if (!pcmd || !pcmd->virt) |
| 17890 | goto exit; |
| 17891 | |
| 17892 | INIT_LIST_HEAD(&pcmd->list); |
| 17893 | |
| 17894 | /* copyin the payload */ |
| 17895 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 17896 | |
| 17897 | /* fill in BDE's for command */ |
| 17898 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 17899 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 17900 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 17901 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 17902 | |
| 17903 | iocbq->context2 = pcmd; |
| 17904 | iocbq->vport = vport; |
| 17905 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 17906 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 17907 | |
| 17908 | /* |
| 17909 | * Setup rest of the iocb as though it were a WQE |
| 17910 | * Build the SEND_FRAME WQE |
| 17911 | */ |
| 17912 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 17913 | |
| 17914 | wqe->send_frame.frame_len = frame_len; |
| 17915 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 17916 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 17917 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 17918 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 17919 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 17920 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 17921 | |
| 17922 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 17923 | iocbq->iocb.ulpLe = 1; |
| 17924 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 17925 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 17926 | if (rc == IOCB_ERROR) |
| 17927 | goto exit; |
| 17928 | |
| 17929 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17930 | return; |
| 17931 | |
| 17932 | exit: |
| 17933 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 17934 | "2023 Unable to process MDS loopback frame\n"); |
| 17935 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17936 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17937 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 17938 | if (iocbq) |
| 17939 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17940 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17941 | } |
| 17942 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17943 | /** |
| 17944 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 17945 | * @phba: Pointer to HBA context object. |
| 17946 | * |
| 17947 | * This function is called with no lock held. This function processes all |
| 17948 | * the received buffers and gives it to upper layers when a received buffer |
| 17949 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17950 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17951 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 17952 | * appropriate receive function when the final frame in a sequence is received. |
| 17953 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17954 | void |
| 17955 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 17956 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17957 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17958 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17959 | struct fc_frame_header *fc_hdr; |
| 17960 | struct lpfc_vport *vport; |
| 17961 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17962 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17963 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17964 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17965 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17966 | |
James Smart | e817e5d | 2018-12-13 15:17:53 -0800 | [diff] [blame] | 17967 | if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS || |
| 17968 | fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) { |
| 17969 | vport = phba->pport; |
| 17970 | /* Handle MDS Loopback frames */ |
| 17971 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 17972 | return; |
| 17973 | } |
| 17974 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17975 | /* check to see if this a valid type of frame */ |
| 17976 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 17977 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17978 | return; |
| 17979 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17980 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17981 | if ((bf_get(lpfc_cqe_code, |
| 17982 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 17983 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 17984 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17985 | else |
| 17986 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 17987 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17988 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17989 | /* d_id this frame is directed to */ |
| 17990 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 17991 | |
| 17992 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17993 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17994 | /* throw out the frame */ |
| 17995 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17996 | return; |
| 17997 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17998 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17999 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 18000 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 18001 | (did != Fabric_DID)) { |
| 18002 | /* |
| 18003 | * Throw out the frame if we are not pt2pt. |
| 18004 | * The pt2pt protocol allows for discovery frames |
| 18005 | * to be received without a registered VPI. |
| 18006 | */ |
| 18007 | if (!(vport->fc_flag & FC_PT2PT) || |
| 18008 | (phba->link_state == LPFC_HBA_READY)) { |
| 18009 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18010 | return; |
| 18011 | } |
| 18012 | } |
| 18013 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18014 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 18015 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 18016 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 18017 | return; |
| 18018 | } |
| 18019 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18020 | /* Link this frame */ |
| 18021 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 18022 | if (!seq_dmabuf) { |
| 18023 | /* unable to add frame to vport - throw it out */ |
| 18024 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 18025 | return; |
| 18026 | } |
| 18027 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18028 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18029 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 18030 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 18031 | /* Send the complete sequence to the upper layer protocol */ |
| 18032 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 18033 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18034 | |
| 18035 | /** |
| 18036 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 18037 | * @phba: pointer to lpfc hba data structure. |
| 18038 | * |
| 18039 | * This routine is invoked to post rpi header templates to the |
| 18040 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18041 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18042 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18043 | * |
| 18044 | * This routine does not require any locks. It's usage is expected |
| 18045 | * to be driver load or reset recovery when the driver is |
| 18046 | * sequential. |
| 18047 | * |
| 18048 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18049 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18050 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18051 | * When this error occurs, the driver is not guaranteed |
| 18052 | * to have any rpi regions posted to the device and |
| 18053 | * must either attempt to repost the regions or take a |
| 18054 | * fatal error. |
| 18055 | **/ |
| 18056 | int |
| 18057 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 18058 | { |
| 18059 | struct lpfc_rpi_hdr *rpi_page; |
| 18060 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18061 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18062 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18063 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18064 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18065 | goto exit; |
| 18066 | if (phba->sli4_hba.extents_in_use) |
| 18067 | return -EIO; |
| 18068 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18069 | 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] | 18070 | /* |
| 18071 | * Assign the rpi headers a physical rpi only if the driver |
| 18072 | * has not initialized those resources. A port reset only |
| 18073 | * needs the headers posted. |
| 18074 | */ |
| 18075 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 18076 | LPFC_RPI_RSRC_RDY) |
| 18077 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 18078 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18079 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 18080 | if (rc != MBX_SUCCESS) { |
| 18081 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18082 | "2008 Error %d posting all rpi " |
| 18083 | "headers\n", rc); |
| 18084 | rc = -EIO; |
| 18085 | break; |
| 18086 | } |
| 18087 | } |
| 18088 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18089 | exit: |
| 18090 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 18091 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18092 | return rc; |
| 18093 | } |
| 18094 | |
| 18095 | /** |
| 18096 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 18097 | * @phba: pointer to lpfc hba data structure. |
| 18098 | * @rpi_page: pointer to the rpi memory region. |
| 18099 | * |
| 18100 | * This routine is invoked to post a single rpi header to the |
| 18101 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 18102 | * maps up to 64 rpi context regions. |
| 18103 | * |
| 18104 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18105 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18106 | * -ENOMEM - No available memory |
| 18107 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18108 | **/ |
| 18109 | int |
| 18110 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 18111 | { |
| 18112 | LPFC_MBOXQ_t *mboxq; |
| 18113 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 18114 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18115 | uint32_t shdr_status, shdr_add_status; |
| 18116 | union lpfc_sli4_cfg_shdr *shdr; |
| 18117 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18118 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 18119 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 18120 | return rc; |
| 18121 | if (phba->sli4_hba.extents_in_use) |
| 18122 | return -EIO; |
| 18123 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18124 | /* The port is notified of the header region via a mailbox command. */ |
| 18125 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18126 | if (!mboxq) { |
| 18127 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18128 | "2001 Unable to allocate memory for issuing " |
| 18129 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 18130 | return -ENOMEM; |
| 18131 | } |
| 18132 | |
| 18133 | /* Post all rpi memory regions to the port. */ |
| 18134 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18135 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18136 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 18137 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 18138 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 18139 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18140 | |
| 18141 | |
| 18142 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18143 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 18144 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18145 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 18146 | hdr_tmpl, rpi_page->page_count); |
| 18147 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18148 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 18149 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 18150 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18151 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 18152 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18153 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18154 | if (rc != MBX_TIMEOUT) |
| 18155 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18156 | if (shdr_status || shdr_add_status || rc) { |
| 18157 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18158 | "2514 POST_RPI_HDR mailbox failed with " |
| 18159 | "status x%x add_status x%x, mbx status x%x\n", |
| 18160 | shdr_status, shdr_add_status, rc); |
| 18161 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 18162 | } else { |
| 18163 | /* |
| 18164 | * The next_rpi stores the next logical module-64 rpi value used |
| 18165 | * to post physical rpis in subsequent rpi postings. |
| 18166 | */ |
| 18167 | spin_lock_irq(&phba->hbalock); |
| 18168 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 18169 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18170 | } |
| 18171 | return rc; |
| 18172 | } |
| 18173 | |
| 18174 | /** |
| 18175 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 18176 | * @phba: pointer to lpfc hba data structure. |
| 18177 | * |
| 18178 | * This routine is invoked to post rpi header templates to the |
| 18179 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 18180 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 18181 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18182 | * |
| 18183 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 18184 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18185 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 18186 | **/ |
| 18187 | int |
| 18188 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 18189 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18190 | unsigned long rpi; |
| 18191 | uint16_t max_rpi, rpi_limit; |
| 18192 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18193 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18194 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18195 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18196 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18197 | * Fetch the next logical rpi. Because this index is logical, |
| 18198 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18199 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18200 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18201 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 18202 | rpi_limit = phba->sli4_hba.next_rpi; |
| 18203 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18204 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 18205 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18206 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 18207 | else { |
| 18208 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 18209 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 18210 | phba->sli4_hba.rpi_count++; |
| 18211 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 18212 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 18213 | "0001 rpi:%x max:%x lim:%x\n", |
| 18214 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18215 | |
| 18216 | /* |
| 18217 | * 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] | 18218 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18219 | */ |
| 18220 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 18221 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18222 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18223 | return rpi; |
| 18224 | } |
| 18225 | |
| 18226 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18227 | * RPI header postings are not required for SLI4 ports capable of |
| 18228 | * extents. |
| 18229 | */ |
| 18230 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18231 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18232 | return rpi; |
| 18233 | } |
| 18234 | |
| 18235 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18236 | * If the driver is running low on rpi resources, allocate another |
| 18237 | * page now. Note that the next_rpi value is used because |
| 18238 | * it represents how many are actually in use whereas max_rpi notes |
| 18239 | * how many are supported max by the device. |
| 18240 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18241 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 18242 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18243 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 18244 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 18245 | if (!rpi_hdr) { |
| 18246 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18247 | "2002 Error Could not grow rpi " |
| 18248 | "count\n"); |
| 18249 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18250 | lrpi = rpi_hdr->start_rpi; |
| 18251 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18252 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 18253 | } |
| 18254 | } |
| 18255 | |
| 18256 | return rpi; |
| 18257 | } |
| 18258 | |
| 18259 | /** |
| 18260 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18261 | * @phba: pointer to lpfc hba data structure. |
| 18262 | * |
| 18263 | * This routine is invoked to release an rpi to the pool of |
| 18264 | * available rpis maintained by the driver. |
| 18265 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18266 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18267 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18268 | { |
| 18269 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 18270 | phba->sli4_hba.rpi_count--; |
| 18271 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 18272 | } |
| 18273 | } |
| 18274 | |
| 18275 | /** |
| 18276 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 18277 | * @phba: pointer to lpfc hba data structure. |
| 18278 | * |
| 18279 | * This routine is invoked to release an rpi to the pool of |
| 18280 | * available rpis maintained by the driver. |
| 18281 | **/ |
| 18282 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18283 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 18284 | { |
| 18285 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 18286 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18287 | spin_unlock_irq(&phba->hbalock); |
| 18288 | } |
| 18289 | |
| 18290 | /** |
| 18291 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 18292 | * @phba: pointer to lpfc hba data structure. |
| 18293 | * |
| 18294 | * This routine is invoked to remove the memory region that |
| 18295 | * provided rpi via a bitmask. |
| 18296 | **/ |
| 18297 | void |
| 18298 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 18299 | { |
| 18300 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18301 | kfree(phba->sli4_hba.rpi_ids); |
| 18302 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18303 | } |
| 18304 | |
| 18305 | /** |
| 18306 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 18307 | * @phba: pointer to lpfc hba data structure. |
| 18308 | * |
| 18309 | * This routine is invoked to remove the memory region that |
| 18310 | * provided rpi via a bitmask. |
| 18311 | **/ |
| 18312 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18313 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 18314 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18315 | { |
| 18316 | LPFC_MBOXQ_t *mboxq; |
| 18317 | struct lpfc_hba *phba = ndlp->phba; |
| 18318 | int rc; |
| 18319 | |
| 18320 | /* The port is notified of the header region via a mailbox command. */ |
| 18321 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18322 | if (!mboxq) |
| 18323 | return -ENOMEM; |
| 18324 | |
| 18325 | /* Post all rpi memory regions to the port. */ |
| 18326 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18327 | if (cmpl) { |
| 18328 | mboxq->mbox_cmpl = cmpl; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 18329 | mboxq->ctx_buf = arg; |
| 18330 | mboxq->ctx_ndlp = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 18331 | } else |
| 18332 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 18333 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18334 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18335 | if (rc == MBX_NOT_FINISHED) { |
| 18336 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18337 | "2010 Resume RPI Mailbox failed " |
| 18338 | "status %d, mbxStatus x%x\n", rc, |
| 18339 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 18340 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18341 | return -EIO; |
| 18342 | } |
| 18343 | return 0; |
| 18344 | } |
| 18345 | |
| 18346 | /** |
| 18347 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18348 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18349 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18350 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18351 | * |
| 18352 | * Returns: |
| 18353 | * 0 success |
| 18354 | * -Evalue otherwise |
| 18355 | **/ |
| 18356 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18357 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18358 | { |
| 18359 | LPFC_MBOXQ_t *mboxq; |
| 18360 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18361 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18362 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18363 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18364 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18365 | if (!mboxq) |
| 18366 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18367 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18368 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18369 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18370 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18371 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18372 | "2022 INIT VPI Mailbox failed " |
| 18373 | "status %d, mbxStatus x%x\n", rc, |
| 18374 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18375 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18376 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18377 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 18378 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 18379 | |
| 18380 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18381 | } |
| 18382 | |
| 18383 | /** |
| 18384 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 18385 | * @phba: pointer to lpfc hba data structure. |
| 18386 | * @mboxq: Pointer to mailbox object. |
| 18387 | * |
| 18388 | * This routine is invoked to manually add a single FCF record. The caller |
| 18389 | * must pass a completely initialized FCF_Record. This routine takes |
| 18390 | * care of the nonembedded mailbox operations. |
| 18391 | **/ |
| 18392 | static void |
| 18393 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 18394 | { |
| 18395 | void *virt_addr; |
| 18396 | union lpfc_sli4_cfg_shdr *shdr; |
| 18397 | uint32_t shdr_status, shdr_add_status; |
| 18398 | |
| 18399 | virt_addr = mboxq->sge_array->addr[0]; |
| 18400 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18401 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 18402 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18403 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18404 | |
| 18405 | if ((shdr_status || shdr_add_status) && |
| 18406 | (shdr_status != STATUS_FCF_IN_USE)) |
| 18407 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18408 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 18409 | "status x%x add_status x%x\n", |
| 18410 | shdr_status, shdr_add_status); |
| 18411 | |
| 18412 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18413 | } |
| 18414 | |
| 18415 | /** |
| 18416 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 18417 | * @phba: pointer to lpfc hba data structure. |
| 18418 | * @fcf_record: pointer to the initialized fcf record to add. |
| 18419 | * |
| 18420 | * This routine is invoked to manually add a single FCF record. The caller |
| 18421 | * must pass a completely initialized FCF_Record. This routine takes |
| 18422 | * care of the nonembedded mailbox operations. |
| 18423 | **/ |
| 18424 | int |
| 18425 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 18426 | { |
| 18427 | int rc = 0; |
| 18428 | LPFC_MBOXQ_t *mboxq; |
| 18429 | uint8_t *bytep; |
| 18430 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18431 | struct lpfc_mbx_sge sge; |
| 18432 | uint32_t alloc_len, req_len; |
| 18433 | uint32_t fcfindex; |
| 18434 | |
| 18435 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18436 | if (!mboxq) { |
| 18437 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18438 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 18439 | return -ENOMEM; |
| 18440 | } |
| 18441 | |
| 18442 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 18443 | sizeof(uint32_t); |
| 18444 | |
| 18445 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 18446 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18447 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 18448 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 18449 | if (alloc_len < req_len) { |
| 18450 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18451 | "2523 Allocated DMA memory size (x%x) is " |
| 18452 | "less than the requested DMA memory " |
| 18453 | "size (x%x)\n", alloc_len, req_len); |
| 18454 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18455 | return -ENOMEM; |
| 18456 | } |
| 18457 | |
| 18458 | /* |
| 18459 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 18460 | * routine only uses a single SGE. |
| 18461 | */ |
| 18462 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18463 | virt_addr = mboxq->sge_array->addr[0]; |
| 18464 | /* |
| 18465 | * Configure the FCF record for FCFI 0. This is the driver's |
| 18466 | * hardcoded default and gets used in nonFIP mode. |
| 18467 | */ |
| 18468 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 18469 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 18470 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 18471 | |
| 18472 | /* |
| 18473 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 18474 | * the FCoE header plus word10. The data copy needs to be endian |
| 18475 | * correct. |
| 18476 | */ |
| 18477 | bytep += sizeof(uint32_t); |
| 18478 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 18479 | mboxq->vport = phba->pport; |
| 18480 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 18481 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18482 | if (rc == MBX_NOT_FINISHED) { |
| 18483 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18484 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 18485 | "status 0x%x\n", rc); |
| 18486 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18487 | rc = -EIO; |
| 18488 | } else |
| 18489 | rc = 0; |
| 18490 | |
| 18491 | return rc; |
| 18492 | } |
| 18493 | |
| 18494 | /** |
| 18495 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 18496 | * @phba: pointer to lpfc hba data structure. |
| 18497 | * @fcf_record: pointer to the fcf record to write the default data. |
| 18498 | * @fcf_index: FCF table entry index. |
| 18499 | * |
| 18500 | * This routine is invoked to build the driver's default FCF record. The |
| 18501 | * values used are hardcoded. This routine handles memory initialization. |
| 18502 | * |
| 18503 | **/ |
| 18504 | void |
| 18505 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 18506 | struct fcf_record *fcf_record, |
| 18507 | uint16_t fcf_index) |
| 18508 | { |
| 18509 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 18510 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 18511 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 18512 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 18513 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 18514 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 18515 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 18516 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 18517 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 18518 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 18519 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 18520 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 18521 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 18522 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 18523 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18524 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 18525 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 18526 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 18527 | /* Set the VLAN bit map */ |
| 18528 | if (phba->valid_vlan) { |
| 18529 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 18530 | = 1 << (phba->vlan_id % 8); |
| 18531 | } |
| 18532 | } |
| 18533 | |
| 18534 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18535 | * 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] | 18536 | * @phba: pointer to lpfc hba data structure. |
| 18537 | * @fcf_index: FCF table entry offset. |
| 18538 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18539 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 18540 | * record and processing it one at a time starting from the @fcf_index |
| 18541 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 18542 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18543 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18544 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18545 | **/ |
| 18546 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18547 | 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] | 18548 | { |
| 18549 | int rc = 0, error; |
| 18550 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18551 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18552 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 18553 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18554 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18555 | if (!mboxq) { |
| 18556 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18557 | "2000 Failed to allocate mbox for " |
| 18558 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18559 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18560 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18561 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18562 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18563 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18564 | if (rc) { |
| 18565 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18566 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18567 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18568 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18569 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18570 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18571 | |
| 18572 | spin_lock_irq(&phba->hbalock); |
| 18573 | phba->hba_flag |= FCF_TS_INPROG; |
| 18574 | spin_unlock_irq(&phba->hbalock); |
| 18575 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18576 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18577 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18578 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18579 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 18580 | /* Reset eligible FCF count for new scan */ |
| 18581 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 18582 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18583 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18584 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18585 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18586 | if (error) { |
| 18587 | if (mboxq) |
| 18588 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18589 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18590 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18591 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18592 | spin_unlock_irq(&phba->hbalock); |
| 18593 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18594 | return error; |
| 18595 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18596 | |
| 18597 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18598 | * 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] | 18599 | * @phba: pointer to lpfc hba data structure. |
| 18600 | * @fcf_index: FCF table entry offset. |
| 18601 | * |
| 18602 | * 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] | 18603 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18604 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18605 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18606 | * otherwise. |
| 18607 | **/ |
| 18608 | int |
| 18609 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18610 | { |
| 18611 | int rc = 0, error; |
| 18612 | LPFC_MBOXQ_t *mboxq; |
| 18613 | |
| 18614 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18615 | if (!mboxq) { |
| 18616 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18617 | "2763 Failed to allocate mbox for " |
| 18618 | "READ_FCF cmd\n"); |
| 18619 | error = -ENOMEM; |
| 18620 | goto fail_fcf_read; |
| 18621 | } |
| 18622 | /* Construct the read FCF record mailbox command */ |
| 18623 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18624 | if (rc) { |
| 18625 | error = -EINVAL; |
| 18626 | goto fail_fcf_read; |
| 18627 | } |
| 18628 | /* Issue the mailbox command asynchronously */ |
| 18629 | mboxq->vport = phba->pport; |
| 18630 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 18631 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18632 | if (rc == MBX_NOT_FINISHED) |
| 18633 | error = -EIO; |
| 18634 | else |
| 18635 | error = 0; |
| 18636 | |
| 18637 | fail_fcf_read: |
| 18638 | if (error && mboxq) |
| 18639 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18640 | return error; |
| 18641 | } |
| 18642 | |
| 18643 | /** |
| 18644 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 18645 | * @phba: pointer to lpfc hba data structure. |
| 18646 | * @fcf_index: FCF table entry offset. |
| 18647 | * |
| 18648 | * 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] | 18649 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18650 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18651 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18652 | * otherwise. |
| 18653 | **/ |
| 18654 | int |
| 18655 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18656 | { |
| 18657 | int rc = 0, error; |
| 18658 | LPFC_MBOXQ_t *mboxq; |
| 18659 | |
| 18660 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18661 | if (!mboxq) { |
| 18662 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18663 | "2758 Failed to allocate mbox for " |
| 18664 | "READ_FCF cmd\n"); |
| 18665 | error = -ENOMEM; |
| 18666 | goto fail_fcf_read; |
| 18667 | } |
| 18668 | /* Construct the read FCF record mailbox command */ |
| 18669 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18670 | if (rc) { |
| 18671 | error = -EINVAL; |
| 18672 | goto fail_fcf_read; |
| 18673 | } |
| 18674 | /* Issue the mailbox command asynchronously */ |
| 18675 | mboxq->vport = phba->pport; |
| 18676 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 18677 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18678 | if (rc == MBX_NOT_FINISHED) |
| 18679 | error = -EIO; |
| 18680 | else |
| 18681 | error = 0; |
| 18682 | |
| 18683 | fail_fcf_read: |
| 18684 | if (error && mboxq) |
| 18685 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18686 | return error; |
| 18687 | } |
| 18688 | |
| 18689 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18690 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18691 | * phba pointer to the lpfc_hba struct for this port. |
| 18692 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 18693 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 18694 | * rr_bmask based on their priority level. Starting from the highest priority |
| 18695 | * to the lowest. The most likely FCF candidate will be in the highest |
| 18696 | * priority group. When this routine is called it searches the fcf_pri list for |
| 18697 | * next lowest priority group and repopulates the rr_bmask with only those |
| 18698 | * fcf_indexes. |
| 18699 | * returns: |
| 18700 | * 1=success 0=failure |
| 18701 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18702 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18703 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 18704 | { |
| 18705 | uint16_t next_fcf_pri; |
| 18706 | uint16_t last_index; |
| 18707 | struct lpfc_fcf_pri *fcf_pri; |
| 18708 | int rc; |
| 18709 | int ret = 0; |
| 18710 | |
| 18711 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 18712 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18713 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 18714 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18715 | |
| 18716 | /* Verify the priority list has 2 or more entries */ |
| 18717 | spin_lock_irq(&phba->hbalock); |
| 18718 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 18719 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 18720 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18721 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 18722 | "3061 Last IDX %d\n", last_index); |
| 18723 | return 0; /* Empty rr list */ |
| 18724 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18725 | spin_unlock_irq(&phba->hbalock); |
| 18726 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18727 | next_fcf_pri = 0; |
| 18728 | /* |
| 18729 | * Clear the rr_bmask and set all of the bits that are at this |
| 18730 | * priority. |
| 18731 | */ |
| 18732 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 18733 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 18734 | spin_lock_irq(&phba->hbalock); |
| 18735 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18736 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 18737 | continue; |
| 18738 | /* |
| 18739 | * the 1st priority that has not FLOGI failed |
| 18740 | * will be the highest. |
| 18741 | */ |
| 18742 | if (!next_fcf_pri) |
| 18743 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18744 | spin_unlock_irq(&phba->hbalock); |
| 18745 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18746 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18747 | fcf_pri->fcf_rec.fcf_index); |
| 18748 | if (rc) |
| 18749 | return 0; |
| 18750 | } |
| 18751 | spin_lock_irq(&phba->hbalock); |
| 18752 | } |
| 18753 | /* |
| 18754 | * if next_fcf_pri was not set above and the list is not empty then |
| 18755 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 18756 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18757 | */ |
| 18758 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 18759 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18760 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 18761 | /* |
| 18762 | * the 1st priority that has not FLOGI failed |
| 18763 | * will be the highest. |
| 18764 | */ |
| 18765 | if (!next_fcf_pri) |
| 18766 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18767 | spin_unlock_irq(&phba->hbalock); |
| 18768 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18769 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18770 | fcf_pri->fcf_rec.fcf_index); |
| 18771 | if (rc) |
| 18772 | return 0; |
| 18773 | } |
| 18774 | spin_lock_irq(&phba->hbalock); |
| 18775 | } |
| 18776 | } else |
| 18777 | ret = 1; |
| 18778 | spin_unlock_irq(&phba->hbalock); |
| 18779 | |
| 18780 | return ret; |
| 18781 | } |
| 18782 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18783 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 18784 | * @phba: pointer to lpfc hba data structure. |
| 18785 | * |
| 18786 | * This routine is to get the next eligible FCF record index in a round |
| 18787 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18788 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18789 | * shall be returned, otherwise, the next eligible FCF record's index |
| 18790 | * shall be returned. |
| 18791 | **/ |
| 18792 | uint16_t |
| 18793 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 18794 | { |
| 18795 | uint16_t next_fcf_index; |
| 18796 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18797 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18798 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18799 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 18800 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18801 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18802 | /* Determine the next fcf index to check */ |
| 18803 | 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] | 18804 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18805 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18806 | next_fcf_index); |
| 18807 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18808 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18809 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18810 | /* |
| 18811 | * If we have wrapped then we need to clear the bits that |
| 18812 | * have been tested so that we can detect when we should |
| 18813 | * change the priority level. |
| 18814 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18815 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18816 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18817 | } |
| 18818 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18819 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18820 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18821 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 18822 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 18823 | /* |
| 18824 | * If next fcf index is not found check if there are lower |
| 18825 | * Priority level fcf's in the fcf_priority list. |
| 18826 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 18827 | * at that level and continue the selection process. |
| 18828 | */ |
| 18829 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18830 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18831 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18832 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 18833 | |
| 18834 | return LPFC_FCOE_FCF_NEXT_NONE; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18835 | } |
| 18836 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18837 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 18838 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18839 | LPFC_FCF_FLOGI_FAILED) { |
| 18840 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 18841 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18842 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18843 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18844 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18845 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18846 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18847 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 18848 | next_fcf_index); |
| 18849 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18850 | return next_fcf_index; |
| 18851 | } |
| 18852 | |
| 18853 | /** |
| 18854 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 18855 | * @phba: pointer to lpfc hba data structure. |
| 18856 | * |
| 18857 | * 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] | 18858 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18859 | * does not go beyond the range of the driver allocated bmask dimension |
| 18860 | * before setting the bit. |
| 18861 | * |
| 18862 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 18863 | * -EINVAL. |
| 18864 | **/ |
| 18865 | int |
| 18866 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18867 | { |
| 18868 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18869 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18870 | "2610 FCF (x%x) reached driver's book " |
| 18871 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18872 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18873 | return -EINVAL; |
| 18874 | } |
| 18875 | /* Set the eligible FCF record index bmask */ |
| 18876 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 18877 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18878 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18879 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18880 | "bmask\n", fcf_index); |
| 18881 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18882 | return 0; |
| 18883 | } |
| 18884 | |
| 18885 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18886 | * 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] | 18887 | * @phba: pointer to lpfc hba data structure. |
| 18888 | * |
| 18889 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18890 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18891 | * does not go beyond the range of the driver allocated bmask dimension |
| 18892 | * before clearing the bit. |
| 18893 | **/ |
| 18894 | void |
| 18895 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18896 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18897 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18898 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18899 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18900 | "2762 FCF (x%x) reached driver's book " |
| 18901 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18902 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18903 | return; |
| 18904 | } |
| 18905 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18906 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18907 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 18908 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18909 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 18910 | list_del_init(&fcf_pri->list); |
| 18911 | break; |
| 18912 | } |
| 18913 | } |
| 18914 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18915 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18916 | |
| 18917 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18918 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18919 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18920 | } |
| 18921 | |
| 18922 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18923 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 18924 | * @phba: pointer to lpfc hba data structure. |
| 18925 | * |
| 18926 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 18927 | * command. If the mailbox command returned failure, it will try to stop the |
| 18928 | * FCF rediscover wait timer. |
| 18929 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18930 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18931 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 18932 | { |
| 18933 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18934 | uint32_t shdr_status, shdr_add_status; |
| 18935 | |
| 18936 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18937 | |
| 18938 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 18939 | &redisc_fcf->header.cfg_shdr.response); |
| 18940 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 18941 | &redisc_fcf->header.cfg_shdr.response); |
| 18942 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18943 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18944 | "2746 Requesting for FCF rediscovery failed " |
| 18945 | "status x%x add_status x%x\n", |
| 18946 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18947 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18948 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18949 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18950 | spin_unlock_irq(&phba->hbalock); |
| 18951 | /* |
| 18952 | * CVL event triggered FCF rediscover request failed, |
| 18953 | * last resort to re-try current registered FCF entry. |
| 18954 | */ |
| 18955 | lpfc_retry_pport_discovery(phba); |
| 18956 | } else { |
| 18957 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18958 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18959 | spin_unlock_irq(&phba->hbalock); |
| 18960 | /* |
| 18961 | * DEAD FCF event triggered FCF rediscover request |
| 18962 | * failed, last resort to fail over as a link down |
| 18963 | * to FCF registration. |
| 18964 | */ |
| 18965 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 18966 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18967 | } else { |
| 18968 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18969 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18970 | /* |
| 18971 | * Start FCF rediscovery wait timer for pending FCF |
| 18972 | * before rescan FCF record table. |
| 18973 | */ |
| 18974 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18975 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18976 | |
| 18977 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18978 | } |
| 18979 | |
| 18980 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18981 | * 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] | 18982 | * @phba: pointer to lpfc hba data structure. |
| 18983 | * |
| 18984 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 18985 | * by the port. |
| 18986 | **/ |
| 18987 | int |
| 18988 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 18989 | { |
| 18990 | LPFC_MBOXQ_t *mbox; |
| 18991 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18992 | int rc, length; |
| 18993 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18994 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 18995 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 18996 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18997 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18998 | if (!mbox) { |
| 18999 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19000 | "2745 Failed to allocate mbox for " |
| 19001 | "requesting FCF rediscover.\n"); |
| 19002 | return -ENOMEM; |
| 19003 | } |
| 19004 | |
| 19005 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 19006 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 19007 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 19008 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 19009 | length, LPFC_SLI4_MBX_EMBED); |
| 19010 | |
| 19011 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 19012 | /* Set count to 0 for invalidating the entire FCF database */ |
| 19013 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 19014 | |
| 19015 | /* Issue the mailbox command asynchronously */ |
| 19016 | mbox->vport = phba->pport; |
| 19017 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 19018 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 19019 | |
| 19020 | if (rc == MBX_NOT_FINISHED) { |
| 19021 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19022 | return -EIO; |
| 19023 | } |
| 19024 | return 0; |
| 19025 | } |
| 19026 | |
| 19027 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 19028 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 19029 | * @phba: pointer to lpfc hba data structure. |
| 19030 | * |
| 19031 | * This function is the failover routine as a last resort to the FCF DEAD |
| 19032 | * event when driver failed to perform fast FCF failover. |
| 19033 | **/ |
| 19034 | void |
| 19035 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 19036 | { |
| 19037 | uint32_t link_state; |
| 19038 | |
| 19039 | /* |
| 19040 | * Last resort as FCF DEAD event failover will treat this as |
| 19041 | * a link down, but save the link state because we don't want |
| 19042 | * it to be changed to Link Down unless it is already down. |
| 19043 | */ |
| 19044 | link_state = phba->link_state; |
| 19045 | lpfc_linkdown(phba); |
| 19046 | phba->link_state = link_state; |
| 19047 | |
| 19048 | /* Unregister FCF if no devices connected to it */ |
| 19049 | lpfc_unregister_unused_fcf(phba); |
| 19050 | } |
| 19051 | |
| 19052 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19053 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19054 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19055 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19056 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19057 | * This function gets SLI3 port configure region 23 data through memory dump |
| 19058 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19059 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19060 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19061 | static uint32_t |
| 19062 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19063 | { |
| 19064 | LPFC_MBOXQ_t *pmb = NULL; |
| 19065 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19066 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19067 | int rc; |
| 19068 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19069 | if (!rgn23_data) |
| 19070 | return 0; |
| 19071 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19072 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19073 | if (!pmb) { |
| 19074 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19075 | "2600 failed to allocate mailbox memory\n"); |
| 19076 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19077 | } |
| 19078 | mb = &pmb->u.mb; |
| 19079 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19080 | do { |
| 19081 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 19082 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 19083 | |
| 19084 | if (rc != MBX_SUCCESS) { |
| 19085 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19086 | "2601 failed to read config " |
| 19087 | "region 23, rc 0x%x Status 0x%x\n", |
| 19088 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19089 | mb->un.varDmp.word_cnt = 0; |
| 19090 | } |
| 19091 | /* |
| 19092 | * dump mem may return a zero when finished or we got a |
| 19093 | * mailbox error, either way we are done. |
| 19094 | */ |
| 19095 | if (mb->un.varDmp.word_cnt == 0) |
| 19096 | break; |
| 19097 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 19098 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 19099 | |
| 19100 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19101 | rgn23_data + offset, |
| 19102 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19103 | offset += mb->un.varDmp.word_cnt; |
| 19104 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 19105 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19106 | mempool_free(pmb, phba->mbox_mem_pool); |
| 19107 | return offset; |
| 19108 | } |
| 19109 | |
| 19110 | /** |
| 19111 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 19112 | * @phba: pointer to lpfc hba data structure. |
| 19113 | * @rgn23_data: pointer to configure region 23 data. |
| 19114 | * |
| 19115 | * This function gets SLI4 port configure region 23 data through memory dump |
| 19116 | * mailbox command. When it successfully retrieves data, the size of the data |
| 19117 | * will be returned, otherwise, 0 will be returned. |
| 19118 | **/ |
| 19119 | static uint32_t |
| 19120 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 19121 | { |
| 19122 | LPFC_MBOXQ_t *mboxq = NULL; |
| 19123 | struct lpfc_dmabuf *mp = NULL; |
| 19124 | struct lpfc_mqe *mqe; |
| 19125 | uint32_t data_length = 0; |
| 19126 | int rc; |
| 19127 | |
| 19128 | if (!rgn23_data) |
| 19129 | return 0; |
| 19130 | |
| 19131 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19132 | if (!mboxq) { |
| 19133 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19134 | "3105 failed to allocate mailbox memory\n"); |
| 19135 | return 0; |
| 19136 | } |
| 19137 | |
| 19138 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 19139 | goto out; |
| 19140 | mqe = &mboxq->u.mqe; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19141 | mp = (struct lpfc_dmabuf *)mboxq->ctx_buf; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19142 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 19143 | if (rc) |
| 19144 | goto out; |
| 19145 | data_length = mqe->un.mb_words[5]; |
| 19146 | if (data_length == 0) |
| 19147 | goto out; |
| 19148 | if (data_length > DMP_RGN23_SIZE) { |
| 19149 | data_length = 0; |
| 19150 | goto out; |
| 19151 | } |
| 19152 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 19153 | out: |
| 19154 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 19155 | if (mp) { |
| 19156 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19157 | kfree(mp); |
| 19158 | } |
| 19159 | return data_length; |
| 19160 | } |
| 19161 | |
| 19162 | /** |
| 19163 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 19164 | * @phba: pointer to lpfc hba data structure. |
| 19165 | * |
| 19166 | * This function read region 23 and parse TLV for port status to |
| 19167 | * decide if the user disaled the port. If the TLV indicates the |
| 19168 | * port is disabled, the hba_flag is set accordingly. |
| 19169 | **/ |
| 19170 | void |
| 19171 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 19172 | { |
| 19173 | uint8_t *rgn23_data = NULL; |
| 19174 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 19175 | uint32_t offset = 0; |
| 19176 | |
| 19177 | /* Get adapter Region 23 data */ |
| 19178 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 19179 | if (!rgn23_data) |
| 19180 | goto out; |
| 19181 | |
| 19182 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 19183 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 19184 | else { |
| 19185 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 19186 | &phba->sli4_hba.sli_intf); |
| 19187 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 19188 | goto out; |
| 19189 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 19190 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19191 | |
| 19192 | if (!data_size) |
| 19193 | goto out; |
| 19194 | |
| 19195 | /* Check the region signature first */ |
| 19196 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 19197 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19198 | "2619 Config region 23 has bad signature\n"); |
| 19199 | goto out; |
| 19200 | } |
| 19201 | offset += 4; |
| 19202 | |
| 19203 | /* Check the data structure version */ |
| 19204 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 19205 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19206 | "2620 Config region 23 has bad version\n"); |
| 19207 | goto out; |
| 19208 | } |
| 19209 | offset += 4; |
| 19210 | |
| 19211 | /* Parse TLV entries in the region */ |
| 19212 | while (offset < data_size) { |
| 19213 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 19214 | break; |
| 19215 | /* |
| 19216 | * If the TLV is not driver specific TLV or driver id is |
| 19217 | * not linux driver id, skip the record. |
| 19218 | */ |
| 19219 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 19220 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 19221 | (rgn23_data[offset + 3] != 0)) { |
| 19222 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19223 | continue; |
| 19224 | } |
| 19225 | |
| 19226 | /* Driver found a driver specific TLV in the config region */ |
| 19227 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 19228 | offset += 4; |
| 19229 | tlv_offset = 0; |
| 19230 | |
| 19231 | /* |
| 19232 | * Search for configured port state sub-TLV. |
| 19233 | */ |
| 19234 | while ((offset < data_size) && |
| 19235 | (tlv_offset < sub_tlv_len)) { |
| 19236 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 19237 | offset += 4; |
| 19238 | tlv_offset += 4; |
| 19239 | break; |
| 19240 | } |
| 19241 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 19242 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 19243 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 19244 | continue; |
| 19245 | } |
| 19246 | |
| 19247 | /* This HBA contains PORT_STE configured */ |
| 19248 | if (!rgn23_data[offset + 2]) |
| 19249 | phba->hba_flag |= LINK_DISABLED; |
| 19250 | |
| 19251 | goto out; |
| 19252 | } |
| 19253 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 19254 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19255 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 19256 | kfree(rgn23_data); |
| 19257 | return; |
| 19258 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19259 | |
| 19260 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19261 | * lpfc_wr_object - write an object to the firmware |
| 19262 | * @phba: HBA structure that indicates port to create a queue on. |
| 19263 | * @dmabuf_list: list of dmabufs to write to the port. |
| 19264 | * @size: the total byte value of the objects to write to the port. |
| 19265 | * @offset: the current offset to be used to start the transfer. |
| 19266 | * |
| 19267 | * This routine will create a wr_object mailbox command to send to the port. |
| 19268 | * the mailbox command will be constructed using the dma buffers described in |
| 19269 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 19270 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 19271 | * used to indicate the starting offset of the transfer and will also return |
| 19272 | * the offset after the write object mailbox has completed. @size is used to |
| 19273 | * determine the end of the object and whether the eof bit should be set. |
| 19274 | * |
| 19275 | * Return 0 is successful and offset will contain the the new offset to use |
| 19276 | * for the next write. |
| 19277 | * Return negative value for error cases. |
| 19278 | **/ |
| 19279 | int |
| 19280 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 19281 | uint32_t size, uint32_t *offset) |
| 19282 | { |
| 19283 | struct lpfc_mbx_wr_object *wr_object; |
| 19284 | LPFC_MBOXQ_t *mbox; |
| 19285 | int rc = 0, i = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19286 | uint32_t shdr_status, shdr_add_status, shdr_change_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19287 | uint32_t mbox_tmo; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19288 | struct lpfc_dmabuf *dmabuf; |
| 19289 | uint32_t written = 0; |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19290 | bool check_change_status = false; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19291 | |
| 19292 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 19293 | if (!mbox) |
| 19294 | return -ENOMEM; |
| 19295 | |
| 19296 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 19297 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 19298 | sizeof(struct lpfc_mbx_wr_object) - |
| 19299 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 19300 | |
| 19301 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 19302 | wr_object->u.request.write_offset = *offset; |
| 19303 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 19304 | wr_object->u.request.object_name[0] = |
| 19305 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 19306 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 19307 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 19308 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 19309 | break; |
| 19310 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 19311 | wr_object->u.request.bde[i].addrHigh = |
| 19312 | putPaddrHigh(dmabuf->phys); |
| 19313 | if (written + SLI4_PAGE_SIZE >= size) { |
| 19314 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19315 | (size - written); |
| 19316 | written += (size - written); |
| 19317 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19318 | bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1); |
| 19319 | check_change_status = true; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19320 | } else { |
| 19321 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 19322 | SLI4_PAGE_SIZE; |
| 19323 | written += SLI4_PAGE_SIZE; |
| 19324 | } |
| 19325 | i++; |
| 19326 | } |
| 19327 | wr_object->u.request.bde_count = i; |
| 19328 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 19329 | if (!phba->sli4_hba.intr_enable) |
| 19330 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 19331 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 19332 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19333 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 19334 | } |
| 19335 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 5021267 | 2018-12-13 15:17:57 -0800 | [diff] [blame] | 19336 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 19337 | &wr_object->header.cfg_shdr.response); |
| 19338 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 19339 | &wr_object->header.cfg_shdr.response); |
| 19340 | if (check_change_status) { |
| 19341 | shdr_change_status = bf_get(lpfc_wr_object_change_status, |
| 19342 | &wr_object->u.response); |
| 19343 | switch (shdr_change_status) { |
| 19344 | case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET): |
| 19345 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19346 | "3198 Firmware write complete: System " |
| 19347 | "reboot required to instantiate\n"); |
| 19348 | break; |
| 19349 | case (LPFC_CHANGE_STATUS_FW_RESET): |
| 19350 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19351 | "3199 Firmware write complete: Firmware" |
| 19352 | " reset required to instantiate\n"); |
| 19353 | break; |
| 19354 | case (LPFC_CHANGE_STATUS_PORT_MIGRATION): |
| 19355 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19356 | "3200 Firmware write complete: Port " |
| 19357 | "Migration or PCI Reset required to " |
| 19358 | "instantiate\n"); |
| 19359 | break; |
| 19360 | case (LPFC_CHANGE_STATUS_PCI_RESET): |
| 19361 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 19362 | "3201 Firmware write complete: PCI " |
| 19363 | "Reset required to instantiate\n"); |
| 19364 | break; |
| 19365 | default: |
| 19366 | break; |
| 19367 | } |
| 19368 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19369 | if (rc != MBX_TIMEOUT) |
| 19370 | mempool_free(mbox, phba->mbox_mem_pool); |
| 19371 | if (shdr_status || shdr_add_status || rc) { |
| 19372 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 19373 | "3025 Write Object mailbox failed with " |
| 19374 | "status x%x add_status x%x, mbx status x%x\n", |
| 19375 | shdr_status, shdr_add_status, rc); |
| 19376 | rc = -ENXIO; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 19377 | *offset = shdr_add_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 19378 | } else |
| 19379 | *offset += wr_object->u.response.actual_write_length; |
| 19380 | return rc; |
| 19381 | } |
| 19382 | |
| 19383 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19384 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 19385 | * @vport: pointer to vport data structure. |
| 19386 | * |
| 19387 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 19388 | * and REG_VPI mailbox commands associated with the vport. This function |
| 19389 | * is called when driver want to restart discovery of the vport due to |
| 19390 | * a Clear Virtual Link event. |
| 19391 | **/ |
| 19392 | void |
| 19393 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 19394 | { |
| 19395 | struct lpfc_hba *phba = vport->phba; |
| 19396 | LPFC_MBOXQ_t *mb, *nextmb; |
| 19397 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19398 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19399 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19400 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19401 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19402 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19403 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19404 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19405 | spin_lock_irq(&phba->hbalock); |
| 19406 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 19407 | if (mb->vport != vport) |
| 19408 | continue; |
| 19409 | |
| 19410 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19411 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19412 | continue; |
| 19413 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19414 | list_del(&mb->list); |
| 19415 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 19416 | } |
| 19417 | /* Clean up active mailbox command with the vport */ |
| 19418 | mb = phba->sli.mbox_active; |
| 19419 | if (mb && (mb->vport == vport)) { |
| 19420 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 19421 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 19422 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19423 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19424 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19425 | /* Put reference count for delayed processing */ |
| 19426 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 19427 | /* Unregister the RPI when mailbox complete */ |
| 19428 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19429 | } |
| 19430 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19431 | /* Cleanup any mailbox completions which are not yet processed */ |
| 19432 | do { |
| 19433 | restart_loop = 0; |
| 19434 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 19435 | /* |
| 19436 | * If this mailox is already processed or it is |
| 19437 | * for another vport ignore it. |
| 19438 | */ |
| 19439 | if ((mb->vport != vport) || |
| 19440 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 19441 | continue; |
| 19442 | |
| 19443 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19444 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19445 | continue; |
| 19446 | |
| 19447 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19448 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19449 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 19450 | /* Unregister the RPI when mailbox complete */ |
| 19451 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19452 | restart_loop = 1; |
| 19453 | spin_unlock_irq(&phba->hbalock); |
| 19454 | spin_lock(shost->host_lock); |
| 19455 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19456 | spin_unlock(shost->host_lock); |
| 19457 | spin_lock_irq(&phba->hbalock); |
| 19458 | break; |
| 19459 | } |
| 19460 | } |
| 19461 | } while (restart_loop); |
| 19462 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19463 | spin_unlock_irq(&phba->hbalock); |
| 19464 | |
| 19465 | /* Release the cleaned-up mailbox commands */ |
| 19466 | while (!list_empty(&mbox_cmd_list)) { |
| 19467 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19468 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19469 | mp = (struct lpfc_dmabuf *)(mb->ctx_buf); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19470 | if (mp) { |
| 19471 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19472 | kfree(mp); |
| 19473 | } |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 19474 | mb->ctx_buf = NULL; |
| 19475 | ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp; |
| 19476 | mb->ctx_ndlp = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19477 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19478 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19479 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19480 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19481 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19482 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19483 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19484 | mempool_free(mb, phba->mbox_mem_pool); |
| 19485 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19486 | |
| 19487 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 19488 | if (act_mbx_ndlp) { |
| 19489 | spin_lock(shost->host_lock); |
| 19490 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19491 | spin_unlock(shost->host_lock); |
| 19492 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19493 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19494 | } |
| 19495 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19496 | /** |
| 19497 | * lpfc_drain_txq - Drain the txq |
| 19498 | * @phba: Pointer to HBA context object. |
| 19499 | * |
| 19500 | * This function attempt to submit IOCBs on the txq |
| 19501 | * to the adapter. For SLI4 adapters, the txq contains |
| 19502 | * ELS IOCBs that have been deferred because the there |
| 19503 | * are no SGLs. This congestion can occur with large |
| 19504 | * vport counts during node discovery. |
| 19505 | **/ |
| 19506 | |
| 19507 | uint32_t |
| 19508 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 19509 | { |
| 19510 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19511 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 19512 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19513 | unsigned long iflags = 0; |
| 19514 | char *fail_msg = NULL; |
| 19515 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19516 | union lpfc_wqe128 wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 19517 | uint32_t txq_cnt = 0; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19518 | struct lpfc_queue *wq; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19519 | |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19520 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
| 19521 | /* MDS WQE are posted only to first WQ*/ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 19522 | wq = phba->sli4_hba.hdwq[0].fcp_wq; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19523 | if (unlikely(!wq)) |
| 19524 | return 0; |
| 19525 | pring = wq->pring; |
| 19526 | } else { |
| 19527 | wq = phba->sli4_hba.els_wq; |
| 19528 | if (unlikely(!wq)) |
| 19529 | return 0; |
| 19530 | pring = lpfc_phba_elsring(phba); |
| 19531 | } |
| 19532 | |
| 19533 | if (unlikely(!pring) || list_empty(&pring->txq)) |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 19534 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19535 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19536 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19537 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 19538 | txq_cnt++; |
| 19539 | } |
| 19540 | |
| 19541 | if (txq_cnt > pring->txq_max) |
| 19542 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19543 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19544 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19545 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19546 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19547 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19548 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19549 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19550 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19551 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19552 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19553 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19554 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19555 | break; |
| 19556 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19557 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19558 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19559 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19560 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19561 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19562 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19563 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19564 | |
| 19565 | /* The xri and iocb resources secured, |
| 19566 | * attempt to issue request |
| 19567 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19568 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19569 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 19570 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 19571 | fail_msg = "to convert bpl to sgl"; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19572 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19573 | fail_msg = "to convert iocb to wqe"; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19574 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19575 | fail_msg = " - Wq is full"; |
| 19576 | else |
| 19577 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 19578 | |
| 19579 | if (fail_msg) { |
| 19580 | /* Failed means we can't issue and need to cancel */ |
| 19581 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19582 | "2822 IOCB failed %s iotag 0x%x " |
| 19583 | "xri 0x%x\n", |
| 19584 | fail_msg, |
| 19585 | piocbq->iotag, piocbq->sli4_xritag); |
| 19586 | list_add_tail(&piocbq->list, &completions); |
| 19587 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19588 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19589 | } |
| 19590 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19591 | /* Cancel all the IOCBs that cannot be issued */ |
| 19592 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 19593 | IOERR_SLI_ABORTED); |
| 19594 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19595 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19596 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19597 | |
| 19598 | /** |
| 19599 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 19600 | * @phba: Pointer to HBA context object. |
| 19601 | * @pwqe: Pointer to command WQE. |
| 19602 | * @sglq: Pointer to the scatter gather queue object. |
| 19603 | * |
| 19604 | * This routine converts the bpl or bde that is in the WQE |
| 19605 | * to a sgl list for the sli4 hardware. The physical address |
| 19606 | * of the bpl/bde is converted back to a virtual address. |
| 19607 | * If the WQE contains a BPL then the list of BDE's is |
| 19608 | * converted to sli4_sge's. If the WQE contains a single |
| 19609 | * BDE then it is converted to a single sli_sge. |
| 19610 | * The WQE is still in cpu endianness so the contents of |
| 19611 | * the bpl can be used without byte swapping. |
| 19612 | * |
| 19613 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 19614 | */ |
| 19615 | static uint16_t |
| 19616 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 19617 | struct lpfc_sglq *sglq) |
| 19618 | { |
| 19619 | uint16_t xritag = NO_XRI; |
| 19620 | struct ulp_bde64 *bpl = NULL; |
| 19621 | struct ulp_bde64 bde; |
| 19622 | struct sli4_sge *sgl = NULL; |
| 19623 | struct lpfc_dmabuf *dmabuf; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19624 | union lpfc_wqe128 *wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19625 | int numBdes = 0; |
| 19626 | int i = 0; |
| 19627 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 19628 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 19629 | uint32_t cmd; |
| 19630 | |
| 19631 | if (!pwqeq || !sglq) |
| 19632 | return xritag; |
| 19633 | |
| 19634 | sgl = (struct sli4_sge *)sglq->sgl; |
| 19635 | wqe = &pwqeq->wqe; |
| 19636 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 19637 | |
| 19638 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 19639 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 19640 | return sglq->sli4_xritag; |
| 19641 | numBdes = pwqeq->rsvd2; |
| 19642 | if (numBdes) { |
| 19643 | /* The addrHigh and addrLow fields within the WQE |
| 19644 | * have not been byteswapped yet so there is no |
| 19645 | * need to swap them back. |
| 19646 | */ |
| 19647 | if (pwqeq->context3) |
| 19648 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 19649 | else |
| 19650 | return xritag; |
| 19651 | |
| 19652 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 19653 | if (!bpl) |
| 19654 | return xritag; |
| 19655 | |
| 19656 | for (i = 0; i < numBdes; i++) { |
| 19657 | /* Should already be byte swapped. */ |
| 19658 | sgl->addr_hi = bpl->addrHigh; |
| 19659 | sgl->addr_lo = bpl->addrLow; |
| 19660 | |
| 19661 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19662 | if ((i+1) == numBdes) |
| 19663 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19664 | else |
| 19665 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 19666 | /* swap the size field back to the cpu so we |
| 19667 | * can assign it to the sgl. |
| 19668 | */ |
| 19669 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 19670 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 19671 | /* The offsets in the sgl need to be accumulated |
| 19672 | * separately for the request and reply lists. |
| 19673 | * The request is always first, the reply follows. |
| 19674 | */ |
| 19675 | switch (cmd) { |
| 19676 | case CMD_GEN_REQUEST64_WQE: |
| 19677 | /* add up the reply sg entries */ |
| 19678 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 19679 | inbound++; |
| 19680 | /* first inbound? reset the offset */ |
| 19681 | if (inbound == 1) |
| 19682 | offset = 0; |
| 19683 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19684 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19685 | LPFC_SGE_TYPE_DATA); |
| 19686 | offset += bde.tus.f.bdeSize; |
| 19687 | break; |
| 19688 | case CMD_FCP_TRSP64_WQE: |
| 19689 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 19690 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19691 | LPFC_SGE_TYPE_DATA); |
| 19692 | break; |
| 19693 | case CMD_FCP_TSEND64_WQE: |
| 19694 | case CMD_FCP_TRECEIVE64_WQE: |
| 19695 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19696 | bpl->tus.f.bdeFlags); |
| 19697 | if (i < 3) |
| 19698 | offset = 0; |
| 19699 | else |
| 19700 | offset += bde.tus.f.bdeSize; |
| 19701 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19702 | break; |
| 19703 | } |
| 19704 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19705 | bpl++; |
| 19706 | sgl++; |
| 19707 | } |
| 19708 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 19709 | /* The addrHigh and addrLow fields of the BDE have not |
| 19710 | * been byteswapped yet so they need to be swapped |
| 19711 | * before putting them in the sgl. |
| 19712 | */ |
| 19713 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 19714 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 19715 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19716 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19717 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19718 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 19719 | } |
| 19720 | return sglq->sli4_xritag; |
| 19721 | } |
| 19722 | |
| 19723 | /** |
| 19724 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 19725 | * @phba: Pointer to HBA context object. |
| 19726 | * @ring_number: Base sli ring number |
| 19727 | * @pwqe: Pointer to command WQE. |
| 19728 | **/ |
| 19729 | int |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19730 | 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] | 19731 | struct lpfc_iocbq *pwqe) |
| 19732 | { |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19733 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19734 | struct lpfc_nvmet_rcv_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19735 | struct lpfc_queue *wq; |
| 19736 | struct lpfc_sglq *sglq; |
| 19737 | struct lpfc_sli_ring *pring; |
| 19738 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19739 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19740 | |
| 19741 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 19742 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 19743 | pring = phba->sli4_hba.nvmels_wq->pring; |
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); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19746 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 19747 | if (!sglq) { |
| 19748 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19749 | return WQE_BUSY; |
| 19750 | } |
| 19751 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19752 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19753 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 19754 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19755 | return WQE_ERROR; |
| 19756 | } |
| 19757 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19758 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19759 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 19760 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19761 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19762 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19763 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19764 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19765 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19766 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19767 | return 0; |
| 19768 | } |
| 19769 | |
| 19770 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 19771 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 19772 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19773 | wq = qp->nvme_wq; |
| 19774 | pring = wq->pring; |
| 19775 | |
| 19776 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->nvme_cq_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19777 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19778 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19779 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19780 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19781 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19782 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19783 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19784 | } |
| 19785 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19786 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19787 | return 0; |
| 19788 | } |
| 19789 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19790 | /* NVMET requests */ |
| 19791 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 19792 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19793 | wq = qp->nvme_wq; |
| 19794 | pring = wq->pring; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19795 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19796 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 19797 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19798 | if (pwqe->sli4_xritag == NO_XRI) { |
| 19799 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19800 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19801 | } |
| 19802 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19803 | pwqe->sli4_xritag); |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 19804 | bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->nvme_cq_map); |
| 19805 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19806 | lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags, |
| 19807 | qp, wq_access); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19808 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19809 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19810 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19811 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19812 | } |
| 19813 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19814 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19815 | return 0; |
| 19816 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19817 | return WQE_ERROR; |
| 19818 | } |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19819 | |
| 19820 | #ifdef LPFC_MXP_STAT |
| 19821 | /** |
| 19822 | * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count |
| 19823 | * @phba: pointer to lpfc hba data structure. |
| 19824 | * @hwqid: belong to which HWQ. |
| 19825 | * |
| 19826 | * The purpose of this routine is to take a snapshot of pbl, pvt and busy count |
| 19827 | * 15 seconds after a test case is running. |
| 19828 | * |
| 19829 | * The user should call lpfc_debugfs_multixripools_write before running a test |
| 19830 | * case to clear stat_snapshot_taken. Then the user starts a test case. During |
| 19831 | * test case is running, stat_snapshot_taken is incremented by 1 every time when |
| 19832 | * this routine is called from heartbeat timer. When stat_snapshot_taken is |
| 19833 | * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken. |
| 19834 | **/ |
| 19835 | void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid) |
| 19836 | { |
| 19837 | struct lpfc_sli4_hdw_queue *qp; |
| 19838 | struct lpfc_multixri_pool *multixri_pool; |
| 19839 | struct lpfc_pvt_pool *pvt_pool; |
| 19840 | struct lpfc_pbl_pool *pbl_pool; |
| 19841 | u32 txcmplq_cnt; |
| 19842 | |
| 19843 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19844 | multixri_pool = qp->p_multixri_pool; |
| 19845 | if (!multixri_pool) |
| 19846 | return; |
| 19847 | |
| 19848 | if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) { |
| 19849 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 19850 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 19851 | txcmplq_cnt = qp->fcp_wq->pring->txcmplq_cnt; |
| 19852 | if (qp->nvme_wq) |
| 19853 | txcmplq_cnt += qp->nvme_wq->pring->txcmplq_cnt; |
| 19854 | |
| 19855 | multixri_pool->stat_pbl_count = pbl_pool->count; |
| 19856 | multixri_pool->stat_pvt_count = pvt_pool->count; |
| 19857 | multixri_pool->stat_busy_count = txcmplq_cnt; |
| 19858 | } |
| 19859 | |
| 19860 | multixri_pool->stat_snapshot_taken++; |
| 19861 | } |
| 19862 | #endif |
| 19863 | |
| 19864 | /** |
| 19865 | * lpfc_adjust_pvt_pool_count - Adjust private pool count |
| 19866 | * @phba: pointer to lpfc hba data structure. |
| 19867 | * @hwqid: belong to which HWQ. |
| 19868 | * |
| 19869 | * This routine moves some XRIs from private to public pool when private pool |
| 19870 | * is not busy. |
| 19871 | **/ |
| 19872 | void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid) |
| 19873 | { |
| 19874 | struct lpfc_multixri_pool *multixri_pool; |
| 19875 | u32 io_req_count; |
| 19876 | u32 prev_io_req_count; |
| 19877 | |
| 19878 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 19879 | if (!multixri_pool) |
| 19880 | return; |
| 19881 | io_req_count = multixri_pool->io_req_count; |
| 19882 | prev_io_req_count = multixri_pool->prev_io_req_count; |
| 19883 | |
| 19884 | if (prev_io_req_count != io_req_count) { |
| 19885 | /* Private pool is busy */ |
| 19886 | multixri_pool->prev_io_req_count = io_req_count; |
| 19887 | } else { |
| 19888 | /* Private pool is not busy. |
| 19889 | * Move XRIs from private to public pool. |
| 19890 | */ |
| 19891 | lpfc_move_xri_pvt_to_pbl(phba, hwqid); |
| 19892 | } |
| 19893 | } |
| 19894 | |
| 19895 | /** |
| 19896 | * lpfc_adjust_high_watermark - Adjust high watermark |
| 19897 | * @phba: pointer to lpfc hba data structure. |
| 19898 | * @hwqid: belong to which HWQ. |
| 19899 | * |
| 19900 | * This routine sets high watermark as number of outstanding XRIs, |
| 19901 | * but make sure the new value is between xri_limit/2 and xri_limit. |
| 19902 | **/ |
| 19903 | void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid) |
| 19904 | { |
| 19905 | u32 new_watermark; |
| 19906 | u32 watermark_max; |
| 19907 | u32 watermark_min; |
| 19908 | u32 xri_limit; |
| 19909 | u32 txcmplq_cnt; |
| 19910 | u32 abts_io_bufs; |
| 19911 | struct lpfc_multixri_pool *multixri_pool; |
| 19912 | struct lpfc_sli4_hdw_queue *qp; |
| 19913 | |
| 19914 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19915 | multixri_pool = qp->p_multixri_pool; |
| 19916 | if (!multixri_pool) |
| 19917 | return; |
| 19918 | xri_limit = multixri_pool->xri_limit; |
| 19919 | |
| 19920 | watermark_max = xri_limit; |
| 19921 | watermark_min = xri_limit / 2; |
| 19922 | |
| 19923 | txcmplq_cnt = qp->fcp_wq->pring->txcmplq_cnt; |
| 19924 | abts_io_bufs = qp->abts_scsi_io_bufs; |
| 19925 | if (qp->nvme_wq) { |
| 19926 | txcmplq_cnt += qp->nvme_wq->pring->txcmplq_cnt; |
| 19927 | abts_io_bufs += qp->abts_nvme_io_bufs; |
| 19928 | } |
| 19929 | |
| 19930 | new_watermark = txcmplq_cnt + abts_io_bufs; |
| 19931 | new_watermark = min(watermark_max, new_watermark); |
| 19932 | new_watermark = max(watermark_min, new_watermark); |
| 19933 | multixri_pool->pvt_pool.high_watermark = new_watermark; |
| 19934 | |
| 19935 | #ifdef LPFC_MXP_STAT |
| 19936 | multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm, |
| 19937 | new_watermark); |
| 19938 | #endif |
| 19939 | } |
| 19940 | |
| 19941 | /** |
| 19942 | * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool |
| 19943 | * @phba: pointer to lpfc hba data structure. |
| 19944 | * @hwqid: belong to which HWQ. |
| 19945 | * |
| 19946 | * This routine is called from hearbeat timer when pvt_pool is idle. |
| 19947 | * All free XRIs are moved from private to public pool on hwqid with 2 steps. |
| 19948 | * The first step moves (all - low_watermark) amount of XRIs. |
| 19949 | * The second step moves the rest of XRIs. |
| 19950 | **/ |
| 19951 | void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid) |
| 19952 | { |
| 19953 | struct lpfc_pbl_pool *pbl_pool; |
| 19954 | struct lpfc_pvt_pool *pvt_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19955 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19956 | struct lpfc_io_buf *lpfc_ncmd; |
| 19957 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 19958 | unsigned long iflag; |
| 19959 | struct list_head tmp_list; |
| 19960 | u32 tmp_count; |
| 19961 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19962 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 19963 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 19964 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19965 | tmp_count = 0; |
| 19966 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 19967 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool); |
| 19968 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 19969 | |
| 19970 | if (pvt_pool->count > pvt_pool->low_watermark) { |
| 19971 | /* Step 1: move (all - low_watermark) from pvt_pool |
| 19972 | * to pbl_pool |
| 19973 | */ |
| 19974 | |
| 19975 | /* Move low watermark of bufs from pvt_pool to tmp_list */ |
| 19976 | INIT_LIST_HEAD(&tmp_list); |
| 19977 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 19978 | &pvt_pool->list, list) { |
| 19979 | list_move_tail(&lpfc_ncmd->list, &tmp_list); |
| 19980 | tmp_count++; |
| 19981 | if (tmp_count >= pvt_pool->low_watermark) |
| 19982 | break; |
| 19983 | } |
| 19984 | |
| 19985 | /* Move all bufs from pvt_pool to pbl_pool */ |
| 19986 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 19987 | |
| 19988 | /* Move all bufs from tmp_list to pvt_pool */ |
| 19989 | list_splice(&tmp_list, &pvt_pool->list); |
| 19990 | |
| 19991 | pbl_pool->count += (pvt_pool->count - tmp_count); |
| 19992 | pvt_pool->count = tmp_count; |
| 19993 | } else { |
| 19994 | /* Step 2: move the rest from pvt_pool to pbl_pool */ |
| 19995 | list_splice_init(&pvt_pool->list, &pbl_pool->list); |
| 19996 | pbl_pool->count += pvt_pool->count; |
| 19997 | pvt_pool->count = 0; |
| 19998 | } |
| 19999 | |
| 20000 | spin_unlock(&pvt_pool->lock); |
| 20001 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20002 | } |
| 20003 | |
| 20004 | /** |
| 20005 | * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 20006 | * @phba: pointer to lpfc hba data structure |
| 20007 | * @pbl_pool: specified public free XRI pool |
| 20008 | * @pvt_pool: specified private free XRI pool |
| 20009 | * @count: number of XRIs to move |
| 20010 | * |
| 20011 | * This routine tries to move some free common bufs from the specified pbl_pool |
| 20012 | * to the specified pvt_pool. It might move less than count XRIs if there's not |
| 20013 | * enough in public pool. |
| 20014 | * |
| 20015 | * Return: |
| 20016 | * true - if XRIs are successfully moved from the specified pbl_pool to the |
| 20017 | * specified pvt_pool |
| 20018 | * false - if the specified pbl_pool is empty or locked by someone else |
| 20019 | **/ |
| 20020 | static bool |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20021 | _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp, |
| 20022 | struct lpfc_pbl_pool *pbl_pool, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20023 | struct lpfc_pvt_pool *pvt_pool, u32 count) |
| 20024 | { |
| 20025 | struct lpfc_io_buf *lpfc_ncmd; |
| 20026 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20027 | unsigned long iflag; |
| 20028 | int ret; |
| 20029 | |
| 20030 | ret = spin_trylock_irqsave(&pbl_pool->lock, iflag); |
| 20031 | if (ret) { |
| 20032 | if (pbl_pool->count) { |
| 20033 | /* Move a batch of XRIs from public to private pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20034 | lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20035 | list_for_each_entry_safe(lpfc_ncmd, |
| 20036 | lpfc_ncmd_next, |
| 20037 | &pbl_pool->list, |
| 20038 | list) { |
| 20039 | list_move_tail(&lpfc_ncmd->list, |
| 20040 | &pvt_pool->list); |
| 20041 | pvt_pool->count++; |
| 20042 | pbl_pool->count--; |
| 20043 | count--; |
| 20044 | if (count == 0) |
| 20045 | break; |
| 20046 | } |
| 20047 | |
| 20048 | spin_unlock(&pvt_pool->lock); |
| 20049 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20050 | return true; |
| 20051 | } |
| 20052 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20053 | } |
| 20054 | |
| 20055 | return false; |
| 20056 | } |
| 20057 | |
| 20058 | /** |
| 20059 | * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool |
| 20060 | * @phba: pointer to lpfc hba data structure. |
| 20061 | * @hwqid: belong to which HWQ. |
| 20062 | * @count: number of XRIs to move |
| 20063 | * |
| 20064 | * This routine tries to find some free common bufs in one of public pools with |
| 20065 | * Round Robin method. The search always starts from local hwqid, then the next |
| 20066 | * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found, |
| 20067 | * a batch of free common bufs are moved to private pool on hwqid. |
| 20068 | * It might move less than count XRIs if there's not enough in public pool. |
| 20069 | **/ |
| 20070 | void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count) |
| 20071 | { |
| 20072 | struct lpfc_multixri_pool *multixri_pool; |
| 20073 | struct lpfc_multixri_pool *next_multixri_pool; |
| 20074 | struct lpfc_pvt_pool *pvt_pool; |
| 20075 | struct lpfc_pbl_pool *pbl_pool; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20076 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20077 | u32 next_hwqid; |
| 20078 | u32 hwq_count; |
| 20079 | int ret; |
| 20080 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20081 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20082 | multixri_pool = qp->p_multixri_pool; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20083 | pvt_pool = &multixri_pool->pvt_pool; |
| 20084 | pbl_pool = &multixri_pool->pbl_pool; |
| 20085 | |
| 20086 | /* Check if local pbl_pool is available */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20087 | 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] | 20088 | if (ret) { |
| 20089 | #ifdef LPFC_MXP_STAT |
| 20090 | multixri_pool->local_pbl_hit_count++; |
| 20091 | #endif |
| 20092 | return; |
| 20093 | } |
| 20094 | |
| 20095 | hwq_count = phba->cfg_hdw_queue; |
| 20096 | |
| 20097 | /* Get the next hwqid which was found last time */ |
| 20098 | next_hwqid = multixri_pool->rrb_next_hwqid; |
| 20099 | |
| 20100 | do { |
| 20101 | /* Go to next hwq */ |
| 20102 | next_hwqid = (next_hwqid + 1) % hwq_count; |
| 20103 | |
| 20104 | next_multixri_pool = |
| 20105 | phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool; |
| 20106 | pbl_pool = &next_multixri_pool->pbl_pool; |
| 20107 | |
| 20108 | /* Check if the public free xri pool is available */ |
| 20109 | ret = _lpfc_move_xri_pbl_to_pvt( |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20110 | phba, qp, pbl_pool, pvt_pool, count); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20111 | |
| 20112 | /* Exit while-loop if success or all hwqid are checked */ |
| 20113 | } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid); |
| 20114 | |
| 20115 | /* Starting point for the next time */ |
| 20116 | multixri_pool->rrb_next_hwqid = next_hwqid; |
| 20117 | |
| 20118 | if (!ret) { |
| 20119 | /* stats: all public pools are empty*/ |
| 20120 | multixri_pool->pbl_empty_count++; |
| 20121 | } |
| 20122 | |
| 20123 | #ifdef LPFC_MXP_STAT |
| 20124 | if (ret) { |
| 20125 | if (next_hwqid == hwqid) |
| 20126 | multixri_pool->local_pbl_hit_count++; |
| 20127 | else |
| 20128 | multixri_pool->other_pbl_hit_count++; |
| 20129 | } |
| 20130 | #endif |
| 20131 | } |
| 20132 | |
| 20133 | /** |
| 20134 | * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark |
| 20135 | * @phba: pointer to lpfc hba data structure. |
| 20136 | * @qp: belong to which HWQ. |
| 20137 | * |
| 20138 | * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than |
| 20139 | * low watermark. |
| 20140 | **/ |
| 20141 | void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid) |
| 20142 | { |
| 20143 | struct lpfc_multixri_pool *multixri_pool; |
| 20144 | struct lpfc_pvt_pool *pvt_pool; |
| 20145 | |
| 20146 | multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool; |
| 20147 | pvt_pool = &multixri_pool->pvt_pool; |
| 20148 | |
| 20149 | if (pvt_pool->count < pvt_pool->low_watermark) |
| 20150 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20151 | } |
| 20152 | |
| 20153 | /** |
| 20154 | * lpfc_release_io_buf - Return one IO buf back to free pool |
| 20155 | * @phba: pointer to lpfc hba data structure. |
| 20156 | * @lpfc_ncmd: IO buf to be returned. |
| 20157 | * @qp: belong to which HWQ. |
| 20158 | * |
| 20159 | * This routine returns one IO buf back to free pool. If this is an urgent IO, |
| 20160 | * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1, |
| 20161 | * the IO buf is returned to pbl_pool or pvt_pool based on watermark and |
| 20162 | * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to |
| 20163 | * lpfc_io_buf_list_put. |
| 20164 | **/ |
| 20165 | void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd, |
| 20166 | struct lpfc_sli4_hdw_queue *qp) |
| 20167 | { |
| 20168 | unsigned long iflag; |
| 20169 | struct lpfc_pbl_pool *pbl_pool; |
| 20170 | struct lpfc_pvt_pool *pvt_pool; |
| 20171 | struct lpfc_epd_pool *epd_pool; |
| 20172 | u32 txcmplq_cnt; |
| 20173 | u32 xri_owned; |
| 20174 | u32 xri_limit; |
| 20175 | u32 abts_io_bufs; |
| 20176 | |
| 20177 | /* MUST zero fields if buffer is reused by another protocol */ |
| 20178 | lpfc_ncmd->nvmeCmd = NULL; |
| 20179 | lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL; |
| 20180 | lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL; |
| 20181 | |
| 20182 | if (phba->cfg_xri_rebalancing) { |
| 20183 | if (lpfc_ncmd->expedite) { |
| 20184 | /* Return to expedite pool */ |
| 20185 | epd_pool = &phba->epd_pool; |
| 20186 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20187 | list_add_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 20188 | epd_pool->count++; |
| 20189 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20190 | return; |
| 20191 | } |
| 20192 | |
| 20193 | /* Avoid invalid access if an IO sneaks in and is being rejected |
| 20194 | * just _after_ xri pools are destroyed in lpfc_offline. |
| 20195 | * Nothing much can be done at this point. |
| 20196 | */ |
| 20197 | if (!qp->p_multixri_pool) |
| 20198 | return; |
| 20199 | |
| 20200 | pbl_pool = &qp->p_multixri_pool->pbl_pool; |
| 20201 | pvt_pool = &qp->p_multixri_pool->pvt_pool; |
| 20202 | |
| 20203 | txcmplq_cnt = qp->fcp_wq->pring->txcmplq_cnt; |
| 20204 | abts_io_bufs = qp->abts_scsi_io_bufs; |
| 20205 | if (qp->nvme_wq) { |
| 20206 | txcmplq_cnt += qp->nvme_wq->pring->txcmplq_cnt; |
| 20207 | abts_io_bufs += qp->abts_nvme_io_bufs; |
| 20208 | } |
| 20209 | |
| 20210 | xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs; |
| 20211 | xri_limit = qp->p_multixri_pool->xri_limit; |
| 20212 | |
| 20213 | #ifdef LPFC_MXP_STAT |
| 20214 | if (xri_owned <= xri_limit) |
| 20215 | qp->p_multixri_pool->below_limit_count++; |
| 20216 | else |
| 20217 | qp->p_multixri_pool->above_limit_count++; |
| 20218 | #endif |
| 20219 | |
| 20220 | /* XRI goes to either public or private free xri pool |
| 20221 | * based on watermark and xri_limit |
| 20222 | */ |
| 20223 | if ((pvt_pool->count < pvt_pool->low_watermark) || |
| 20224 | (xri_owned < xri_limit && |
| 20225 | pvt_pool->count < pvt_pool->high_watermark)) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20226 | lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, |
| 20227 | qp, free_pvt_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20228 | list_add_tail(&lpfc_ncmd->list, |
| 20229 | &pvt_pool->list); |
| 20230 | pvt_pool->count++; |
| 20231 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20232 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20233 | lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, |
| 20234 | qp, free_pub_pool); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20235 | list_add_tail(&lpfc_ncmd->list, |
| 20236 | &pbl_pool->list); |
| 20237 | pbl_pool->count++; |
| 20238 | spin_unlock_irqrestore(&pbl_pool->lock, iflag); |
| 20239 | } |
| 20240 | } else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20241 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag, |
| 20242 | qp, free_xri); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20243 | list_add_tail(&lpfc_ncmd->list, |
| 20244 | &qp->lpfc_io_buf_list_put); |
| 20245 | qp->put_io_bufs++; |
| 20246 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, |
| 20247 | iflag); |
| 20248 | } |
| 20249 | } |
| 20250 | |
| 20251 | /** |
| 20252 | * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool |
| 20253 | * @phba: pointer to lpfc hba data structure. |
| 20254 | * @pvt_pool: pointer to private pool data structure. |
| 20255 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20256 | * |
| 20257 | * This routine tries to get one free IO buf from private pool. |
| 20258 | * |
| 20259 | * Return: |
| 20260 | * pointer to one free IO buf - if private pool is not empty |
| 20261 | * NULL - if private pool is empty |
| 20262 | **/ |
| 20263 | static struct lpfc_io_buf * |
| 20264 | lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20265 | struct lpfc_sli4_hdw_queue *qp, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20266 | struct lpfc_pvt_pool *pvt_pool, |
| 20267 | struct lpfc_nodelist *ndlp) |
| 20268 | { |
| 20269 | struct lpfc_io_buf *lpfc_ncmd; |
| 20270 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20271 | unsigned long iflag; |
| 20272 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20273 | 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] | 20274 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20275 | &pvt_pool->list, list) { |
| 20276 | if (lpfc_test_rrq_active( |
| 20277 | phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag)) |
| 20278 | continue; |
| 20279 | list_del(&lpfc_ncmd->list); |
| 20280 | pvt_pool->count--; |
| 20281 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20282 | return lpfc_ncmd; |
| 20283 | } |
| 20284 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 20285 | |
| 20286 | return NULL; |
| 20287 | } |
| 20288 | |
| 20289 | /** |
| 20290 | * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool |
| 20291 | * @phba: pointer to lpfc hba data structure. |
| 20292 | * |
| 20293 | * This routine tries to get one free IO buf from expedite pool. |
| 20294 | * |
| 20295 | * Return: |
| 20296 | * pointer to one free IO buf - if expedite pool is not empty |
| 20297 | * NULL - if expedite pool is empty |
| 20298 | **/ |
| 20299 | static struct lpfc_io_buf * |
| 20300 | lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba) |
| 20301 | { |
| 20302 | struct lpfc_io_buf *lpfc_ncmd; |
| 20303 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 20304 | unsigned long iflag; |
| 20305 | struct lpfc_epd_pool *epd_pool; |
| 20306 | |
| 20307 | epd_pool = &phba->epd_pool; |
| 20308 | lpfc_ncmd = NULL; |
| 20309 | |
| 20310 | spin_lock_irqsave(&epd_pool->lock, iflag); |
| 20311 | if (epd_pool->count > 0) { |
| 20312 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 20313 | &epd_pool->list, list) { |
| 20314 | list_del(&lpfc_ncmd->list); |
| 20315 | epd_pool->count--; |
| 20316 | break; |
| 20317 | } |
| 20318 | } |
| 20319 | spin_unlock_irqrestore(&epd_pool->lock, iflag); |
| 20320 | |
| 20321 | return lpfc_ncmd; |
| 20322 | } |
| 20323 | |
| 20324 | /** |
| 20325 | * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs |
| 20326 | * @phba: pointer to lpfc hba data structure. |
| 20327 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20328 | * @hwqid: belong to which HWQ |
| 20329 | * @expedite: 1 means this request is urgent. |
| 20330 | * |
| 20331 | * This routine will do the following actions and then return a pointer to |
| 20332 | * one free IO buf. |
| 20333 | * |
| 20334 | * 1. If private free xri count is empty, move some XRIs from public to |
| 20335 | * private pool. |
| 20336 | * 2. Get one XRI from private free xri pool. |
| 20337 | * 3. If we fail to get one from pvt_pool and this is an expedite request, |
| 20338 | * get one free xri from expedite pool. |
| 20339 | * |
| 20340 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20341 | * The caller should pass NULL for ndlp on NVME side. |
| 20342 | * |
| 20343 | * Return: |
| 20344 | * pointer to one free IO buf - if private pool is not empty |
| 20345 | * NULL - if private pool is empty |
| 20346 | **/ |
| 20347 | static struct lpfc_io_buf * |
| 20348 | lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba, |
| 20349 | struct lpfc_nodelist *ndlp, |
| 20350 | int hwqid, int expedite) |
| 20351 | { |
| 20352 | struct lpfc_sli4_hdw_queue *qp; |
| 20353 | struct lpfc_multixri_pool *multixri_pool; |
| 20354 | struct lpfc_pvt_pool *pvt_pool; |
| 20355 | struct lpfc_io_buf *lpfc_ncmd; |
| 20356 | |
| 20357 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20358 | lpfc_ncmd = NULL; |
| 20359 | multixri_pool = qp->p_multixri_pool; |
| 20360 | pvt_pool = &multixri_pool->pvt_pool; |
| 20361 | multixri_pool->io_req_count++; |
| 20362 | |
| 20363 | /* If pvt_pool is empty, move some XRIs from public to private pool */ |
| 20364 | if (pvt_pool->count == 0) |
| 20365 | lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH); |
| 20366 | |
| 20367 | /* Get one XRI from private free xri pool */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20368 | 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] | 20369 | |
| 20370 | if (lpfc_ncmd) { |
| 20371 | lpfc_ncmd->hdwq = qp; |
| 20372 | lpfc_ncmd->hdwq_no = hwqid; |
| 20373 | } else if (expedite) { |
| 20374 | /* If we fail to get one from pvt_pool and this is an expedite |
| 20375 | * request, get one free xri from expedite pool. |
| 20376 | */ |
| 20377 | lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba); |
| 20378 | } |
| 20379 | |
| 20380 | return lpfc_ncmd; |
| 20381 | } |
| 20382 | |
| 20383 | static inline struct lpfc_io_buf * |
| 20384 | lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx) |
| 20385 | { |
| 20386 | struct lpfc_sli4_hdw_queue *qp; |
| 20387 | struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next; |
| 20388 | |
| 20389 | qp = &phba->sli4_hba.hdwq[idx]; |
| 20390 | list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next, |
| 20391 | &qp->lpfc_io_buf_list_get, list) { |
| 20392 | if (lpfc_test_rrq_active(phba, ndlp, |
| 20393 | lpfc_cmd->cur_iocbq.sli4_lxritag)) |
| 20394 | continue; |
| 20395 | |
| 20396 | if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED) |
| 20397 | continue; |
| 20398 | |
| 20399 | list_del_init(&lpfc_cmd->list); |
| 20400 | qp->get_io_bufs--; |
| 20401 | lpfc_cmd->hdwq = qp; |
| 20402 | lpfc_cmd->hdwq_no = idx; |
| 20403 | return lpfc_cmd; |
| 20404 | } |
| 20405 | return NULL; |
| 20406 | } |
| 20407 | |
| 20408 | /** |
| 20409 | * lpfc_get_io_buf - Get one IO buffer from free pool |
| 20410 | * @phba: The HBA for which this call is being executed. |
| 20411 | * @ndlp: pointer to lpfc nodelist data structure. |
| 20412 | * @hwqid: belong to which HWQ |
| 20413 | * @expedite: 1 means this request is urgent. |
| 20414 | * |
| 20415 | * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1, |
| 20416 | * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes |
| 20417 | * a IO buffer from head of @hdwq io_buf_list and returns to caller. |
| 20418 | * |
| 20419 | * Note: ndlp is only used on SCSI side for RRQ testing. |
| 20420 | * The caller should pass NULL for ndlp on NVME side. |
| 20421 | * |
| 20422 | * Return codes: |
| 20423 | * NULL - Error |
| 20424 | * Pointer to lpfc_io_buf - Success |
| 20425 | **/ |
| 20426 | struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba, |
| 20427 | struct lpfc_nodelist *ndlp, |
| 20428 | u32 hwqid, int expedite) |
| 20429 | { |
| 20430 | struct lpfc_sli4_hdw_queue *qp; |
| 20431 | unsigned long iflag; |
| 20432 | struct lpfc_io_buf *lpfc_cmd; |
| 20433 | |
| 20434 | qp = &phba->sli4_hba.hdwq[hwqid]; |
| 20435 | lpfc_cmd = NULL; |
| 20436 | |
| 20437 | if (phba->cfg_xri_rebalancing) |
| 20438 | lpfc_cmd = lpfc_get_io_buf_from_multixri_pools( |
| 20439 | phba, ndlp, hwqid, expedite); |
| 20440 | else { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20441 | lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag, |
| 20442 | qp, alloc_xri_get); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20443 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite) |
| 20444 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20445 | if (!lpfc_cmd) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 20446 | lpfc_qp_spin_lock(&qp->io_buf_list_put_lock, |
| 20447 | qp, alloc_xri_put); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 20448 | list_splice(&qp->lpfc_io_buf_list_put, |
| 20449 | &qp->lpfc_io_buf_list_get); |
| 20450 | qp->get_io_bufs += qp->put_io_bufs; |
| 20451 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 20452 | qp->put_io_bufs = 0; |
| 20453 | spin_unlock(&qp->io_buf_list_put_lock); |
| 20454 | if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || |
| 20455 | expedite) |
| 20456 | lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid); |
| 20457 | } |
| 20458 | spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag); |
| 20459 | } |
| 20460 | |
| 20461 | return lpfc_cmd; |
| 20462 | } |