| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 128bdda | 2018-01-30 15:59:03 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term * |
James Smart | 3e21d1c | 2018-05-04 20:37:59 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| 23 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 29 | #include <linux/lockdep.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 31 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | #include <scsi/scsi_cmnd.h> |
| 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 35 | #include <scsi/scsi_transport_fc.h> |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 36 | #include <scsi/fc/fc_fs.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 37 | #include <linux/aer.h> |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 38 | #ifdef CONFIG_X86 |
| 39 | #include <asm/set_memory.h> |
| 40 | #endif |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 42 | #include <linux/nvme-fc-driver.h> |
| 43 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 44 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | #include "lpfc_hw.h" |
| 46 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 47 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 48 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 51 | #include "lpfc_scsi.h" |
| 52 | #include "lpfc_nvme.h" |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 53 | #include "lpfc_nvmet.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | #include "lpfc_crtn.h" |
| 55 | #include "lpfc_logmsg.h" |
| 56 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 57 | #include "lpfc_debugfs.h" |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 58 | #include "lpfc_vport.h" |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 59 | #include "lpfc_version.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 60 | |
| 61 | /* There are only four IOCB completion types. */ |
| 62 | typedef enum _lpfc_iocb_type { |
| 63 | LPFC_UNKNOWN_IOCB, |
| 64 | LPFC_UNSOL_IOCB, |
| 65 | LPFC_SOL_IOCB, |
| 66 | LPFC_ABORT_IOCB |
| 67 | } lpfc_iocb_type; |
| 68 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 69 | |
| 70 | /* Provide function prototypes local to this module. */ |
| 71 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 72 | uint32_t); |
| 73 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 74 | uint8_t *, uint32_t *); |
| 75 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 76 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 77 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 78 | struct hbq_dmabuf *); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 79 | static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 80 | struct hbq_dmabuf *dmabuf); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 81 | static int lpfc_sli4_fp_handle_cqe(struct lpfc_hba *, struct lpfc_queue *, |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 82 | struct lpfc_cqe *); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 83 | static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 84 | int); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 85 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, |
| 86 | struct lpfc_eqe *eqe, uint32_t qidx); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 87 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 88 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 89 | static int lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, |
| 90 | struct lpfc_sli_ring *pring, |
| 91 | struct lpfc_iocbq *cmdiocb); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 92 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 93 | static IOCB_t * |
| 94 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 95 | { |
| 96 | return &iocbq->iocb; |
| 97 | } |
| 98 | |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 99 | #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN) |
| 100 | /** |
| 101 | * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function |
| 102 | * @srcp: Source memory pointer. |
| 103 | * @destp: Destination memory pointer. |
| 104 | * @cnt: Number of words required to be copied. |
| 105 | * Must be a multiple of sizeof(uint64_t) |
| 106 | * |
| 107 | * This function is used for copying data between driver memory |
| 108 | * and the SLI WQ. This function also changes the endianness |
| 109 | * of each word if native endianness is different from SLI |
| 110 | * endianness. This function can be called with or without |
| 111 | * lock. |
| 112 | **/ |
| 113 | void |
| 114 | lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 115 | { |
| 116 | uint64_t *src = srcp; |
| 117 | uint64_t *dest = destp; |
| 118 | int i; |
| 119 | |
| 120 | for (i = 0; i < (int)cnt; i += sizeof(uint64_t)) |
| 121 | *dest++ = *src++; |
| 122 | } |
| 123 | #else |
| 124 | #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c) |
| 125 | #endif |
| 126 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 127 | /** |
| 128 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 129 | * @q: The Work Queue to operate on. |
| 130 | * @wqe: The work Queue Entry to put on the Work queue. |
| 131 | * |
| 132 | * This routine will copy the contents of @wqe to the next available entry on |
| 133 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 134 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 135 | * successful. If no entries are available on @q then this function will return |
| 136 | * -ENOMEM. |
| 137 | * The caller is expected to hold the hbalock when calling this routine. |
| 138 | **/ |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 139 | static int |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 140 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 141 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 142 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 143 | struct lpfc_register doorbell; |
| 144 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 145 | uint32_t idx; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 146 | uint32_t i = 0; |
| 147 | uint8_t *tmp; |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame^] | 148 | u32 if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 149 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 150 | /* sanity check on queue memory */ |
| 151 | if (unlikely(!q)) |
| 152 | return -ENOMEM; |
| 153 | temp_wqe = q->qe[q->host_index].wqe; |
| 154 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 155 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 156 | idx = ((q->host_index + 1) % q->entry_count); |
| 157 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 158 | q->WQ_overflow++; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 159 | return -EBUSY; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 160 | } |
| 161 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 162 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 163 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 164 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | 04673e3 | 2018-01-30 15:58:45 -0800 | [diff] [blame] | 165 | else |
| 166 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 0); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 167 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 168 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 169 | lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 170 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 171 | /* write to DPP aperture taking advatage of Combined Writes */ |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 172 | tmp = (uint8_t *)temp_wqe; |
| 173 | #ifdef __raw_writeq |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 174 | for (i = 0; i < q->entry_size; i += sizeof(uint64_t)) |
James Smart | 4c06619 | 2018-03-05 10:29:03 -0800 | [diff] [blame] | 175 | __raw_writeq(*((uint64_t *)(tmp + i)), |
| 176 | q->dpp_regaddr + i); |
| 177 | #else |
| 178 | for (i = 0; i < q->entry_size; i += sizeof(uint32_t)) |
| 179 | __raw_writel(*((uint32_t *)(tmp + i)), |
| 180 | q->dpp_regaddr + i); |
| 181 | #endif |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 182 | } |
| 183 | /* ensure WQE bcopy and DPP flushed before doorbell write */ |
James Smart | 6b3b3bd | 2016-12-19 15:07:30 -0800 | [diff] [blame] | 184 | wmb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 185 | |
| 186 | /* Update the host index before invoking device */ |
| 187 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 188 | |
| 189 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 190 | |
| 191 | /* Ring Doorbell */ |
| 192 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 193 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 194 | if (q->dpp_enable && q->phba->cfg_enable_dpp) { |
| 195 | bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1); |
| 196 | bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1); |
| 197 | bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell, |
| 198 | q->dpp_id); |
| 199 | bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell, |
| 200 | q->queue_id); |
| 201 | } else { |
| 202 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 203 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
James Smart | 5cc167d | 2018-06-26 08:24:23 -0700 | [diff] [blame^] | 204 | |
| 205 | /* Leave bits <23:16> clear for if_type 6 dpp */ |
| 206 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 207 | &q->phba->sli4_hba.sli_intf); |
| 208 | if (if_type != LPFC_SLI_INTF_IF_TYPE_6) |
| 209 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, |
| 210 | host_index); |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 211 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 212 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 213 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 214 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 215 | } else { |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 225 | * @q: The Work Queue to operate on. |
| 226 | * @index: The index to advance the hba index to. |
| 227 | * |
| 228 | * This routine will update the HBA index of a queue to reflect consumption of |
| 229 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 230 | * an entry the host calls this function to update the queue's internal |
| 231 | * pointers. This routine returns the number of entries that were consumed by |
| 232 | * the HBA. |
| 233 | **/ |
| 234 | static uint32_t |
| 235 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 236 | { |
| 237 | uint32_t released = 0; |
| 238 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 239 | /* sanity check on queue memory */ |
| 240 | if (unlikely(!q)) |
| 241 | return 0; |
| 242 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 243 | if (q->hba_index == index) |
| 244 | return 0; |
| 245 | do { |
| 246 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 247 | released++; |
| 248 | } while (q->hba_index != index); |
| 249 | return released; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 254 | * @q: The Mailbox Queue to operate on. |
| 255 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 256 | * |
| 257 | * This routine will copy the contents of @mqe to the next available entry on |
| 258 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 259 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 260 | * successful. If no entries are available on @q then this function will return |
| 261 | * -ENOMEM. |
| 262 | * The caller is expected to hold the hbalock when calling this routine. |
| 263 | **/ |
| 264 | static uint32_t |
| 265 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 266 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 267 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 268 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 269 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 270 | /* sanity check on queue memory */ |
| 271 | if (unlikely(!q)) |
| 272 | return -ENOMEM; |
| 273 | temp_mqe = q->qe[q->host_index].mqe; |
| 274 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 275 | /* If the host has not yet processed the next entry then we are done */ |
| 276 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 277 | return -ENOMEM; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 278 | lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 279 | /* Save off the mailbox pointer for completion */ |
| 280 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 281 | |
| 282 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 283 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 284 | |
| 285 | /* Ring Doorbell */ |
| 286 | doorbell.word0 = 0; |
| 287 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 288 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 289 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 295 | * @q: The Mailbox Queue to operate on. |
| 296 | * |
| 297 | * This routine will update the HBA index of a queue to reflect consumption of |
| 298 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 299 | * an entry the host calls this function to update the queue's internal |
| 300 | * pointers. This routine returns the number of entries that were consumed by |
| 301 | * the HBA. |
| 302 | **/ |
| 303 | static uint32_t |
| 304 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 305 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 306 | /* sanity check on queue memory */ |
| 307 | if (unlikely(!q)) |
| 308 | return 0; |
| 309 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 310 | /* Clear the mailbox pointer for completion */ |
| 311 | q->phba->mbox = NULL; |
| 312 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 313 | return 1; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 318 | * @q: The Event Queue to get the first valid EQE from |
| 319 | * |
| 320 | * This routine will get the first valid Event Queue Entry from @q, update |
| 321 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 322 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 323 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 324 | **/ |
| 325 | static struct lpfc_eqe * |
| 326 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 327 | { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 328 | struct lpfc_hba *phba; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 329 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 330 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 331 | |
| 332 | /* sanity check on queue memory */ |
| 333 | if (unlikely(!q)) |
| 334 | return NULL; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 335 | phba = q->phba; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 336 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 337 | |
| 338 | /* If the next EQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 339 | if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 340 | return NULL; |
| 341 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 342 | idx = ((q->hba_index + 1) % q->entry_count); |
| 343 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 344 | return NULL; |
| 345 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 346 | q->hba_index = idx; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 347 | /* if the index wrapped around, toggle the valid bit */ |
| 348 | if (phba->sli4_hba.pc_sli4_params.eqav && !q->hba_index) |
| 349 | q->qe_valid = (q->qe_valid) ? 0 : 1; |
| 350 | |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 351 | |
| 352 | /* |
| 353 | * insert barrier for instruction interlock : data from the hardware |
| 354 | * must have the valid bit checked before it can be copied and acted |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 355 | * upon. Speculative instructions were allowing a bcopy at the start |
| 356 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 357 | * after our return, to copy data before the valid bit check above |
| 358 | * was done. As such, some of the copied data was stale. The barrier |
| 359 | * ensures the check is before any data is copied. |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 360 | */ |
| 361 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 362 | return eqe; |
| 363 | } |
| 364 | |
| 365 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 366 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 367 | * @q: The Event Queue to disable interrupts |
| 368 | * |
| 369 | **/ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 370 | inline void |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 371 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 372 | { |
| 373 | struct lpfc_register doorbell; |
| 374 | |
| 375 | doorbell.word0 = 0; |
| 376 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 377 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 378 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 379 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 380 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 381 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 385 | * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ |
| 386 | * @q: The Event Queue to disable interrupts |
| 387 | * |
| 388 | **/ |
| 389 | inline void |
| 390 | lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q) |
| 391 | { |
| 392 | struct lpfc_register doorbell; |
| 393 | |
| 394 | doorbell.word0 = 0; |
| 395 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 396 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 397 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 398 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 399 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
| 400 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 401 | } |
| 402 | |
| 403 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 404 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 405 | * @q: The Event Queue that the host has completed processing for. |
| 406 | * @arm: Indicates whether the host wants to arms this CQ. |
| 407 | * |
| 408 | * This routine will mark all Event Queue Entries on @q, from the last |
| 409 | * known completed entry to the last entry that was processed, as completed |
| 410 | * by clearing the valid bit for each completion queue entry. Then it will |
| 411 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 412 | * The internal host index in the @q will be updated by this routine to indicate |
| 413 | * that the host has finished processing the entries. The @arm parameter |
| 414 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 415 | * |
| 416 | * This function will return the number of EQEs that were popped. |
| 417 | **/ |
| 418 | uint32_t |
| 419 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 420 | { |
| 421 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 422 | struct lpfc_hba *phba; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 423 | struct lpfc_eqe *temp_eqe; |
| 424 | struct lpfc_register doorbell; |
| 425 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 426 | /* sanity check on queue memory */ |
| 427 | if (unlikely(!q)) |
| 428 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 429 | phba = q->phba; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 430 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 431 | /* while there are valid entries */ |
| 432 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 433 | if (!phba->sli4_hba.pc_sli4_params.eqav) { |
| 434 | temp_eqe = q->qe[q->host_index].eqe; |
| 435 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
| 436 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 437 | released++; |
| 438 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 439 | } |
| 440 | if (unlikely(released == 0 && !arm)) |
| 441 | return 0; |
| 442 | |
| 443 | /* ring doorbell for number popped */ |
| 444 | doorbell.word0 = 0; |
| 445 | if (arm) { |
| 446 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 447 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 448 | } |
| 449 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 450 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 451 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 452 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 453 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 454 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 455 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 456 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 457 | readl(q->phba->sli4_hba.EQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 458 | return released; |
| 459 | } |
| 460 | |
| 461 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 462 | * lpfc_sli4_if6_eq_release - Indicates the host has finished processing an EQ |
| 463 | * @q: The Event Queue that the host has completed processing for. |
| 464 | * @arm: Indicates whether the host wants to arms this CQ. |
| 465 | * |
| 466 | * This routine will mark all Event Queue Entries on @q, from the last |
| 467 | * known completed entry to the last entry that was processed, as completed |
| 468 | * by clearing the valid bit for each completion queue entry. Then it will |
| 469 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 470 | * The internal host index in the @q will be updated by this routine to indicate |
| 471 | * that the host has finished processing the entries. The @arm parameter |
| 472 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 473 | * |
| 474 | * This function will return the number of EQEs that were popped. |
| 475 | **/ |
| 476 | uint32_t |
| 477 | lpfc_sli4_if6_eq_release(struct lpfc_queue *q, bool arm) |
| 478 | { |
| 479 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 480 | struct lpfc_hba *phba; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 481 | struct lpfc_eqe *temp_eqe; |
| 482 | struct lpfc_register doorbell; |
| 483 | |
| 484 | /* sanity check on queue memory */ |
| 485 | if (unlikely(!q)) |
| 486 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 487 | phba = q->phba; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 488 | |
| 489 | /* while there are valid entries */ |
| 490 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 491 | if (!phba->sli4_hba.pc_sli4_params.eqav) { |
| 492 | temp_eqe = q->qe[q->host_index].eqe; |
| 493 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
| 494 | } |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 495 | released++; |
| 496 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 497 | } |
| 498 | if (unlikely(released == 0 && !arm)) |
| 499 | return 0; |
| 500 | |
| 501 | /* ring doorbell for number popped */ |
| 502 | doorbell.word0 = 0; |
| 503 | if (arm) |
| 504 | bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1); |
| 505 | bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, released); |
| 506 | bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id); |
| 507 | writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr); |
| 508 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 509 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 510 | readl(q->phba->sli4_hba.EQDBregaddr); |
| 511 | return released; |
| 512 | } |
| 513 | |
| 514 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 515 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 516 | * @q: The Completion Queue to get the first valid CQE from |
| 517 | * |
| 518 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 519 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 520 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 521 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 522 | **/ |
| 523 | static struct lpfc_cqe * |
| 524 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 525 | { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 526 | struct lpfc_hba *phba; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 527 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 528 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 529 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 530 | /* sanity check on queue memory */ |
| 531 | if (unlikely(!q)) |
| 532 | return NULL; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 533 | phba = q->phba; |
| 534 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 535 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 536 | /* If the next CQE is not valid then we are done */ |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 537 | if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 538 | return NULL; |
| 539 | /* 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] | 540 | idx = ((q->hba_index + 1) % q->entry_count); |
| 541 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 542 | return NULL; |
| 543 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 544 | q->hba_index = idx; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 545 | /* if the index wrapped around, toggle the valid bit */ |
| 546 | if (phba->sli4_hba.pc_sli4_params.cqav && !q->hba_index) |
| 547 | q->qe_valid = (q->qe_valid) ? 0 : 1; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 548 | |
| 549 | /* |
| 550 | * insert barrier for instruction interlock : data from the hardware |
| 551 | * 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] | 552 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 553 | * instructions allowing action on content before valid bit checked, |
| 554 | * add barrier here as well. May not be needed as "content" is a |
| 555 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 556 | */ |
| 557 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 558 | return cqe; |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 563 | * @q: The Completion Queue that the host has completed processing for. |
| 564 | * @arm: Indicates whether the host wants to arms this CQ. |
| 565 | * |
| 566 | * This routine will mark all Completion queue entries on @q, from the last |
| 567 | * known completed entry to the last entry that was processed, as completed |
| 568 | * by clearing the valid bit for each completion queue entry. Then it will |
| 569 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 570 | * The internal host index in the @q will be updated by this routine to indicate |
| 571 | * that the host has finished processing the entries. The @arm parameter |
| 572 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 573 | * |
| 574 | * This function will return the number of CQEs that were released. |
| 575 | **/ |
| 576 | uint32_t |
| 577 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 578 | { |
| 579 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 580 | struct lpfc_hba *phba; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 581 | struct lpfc_cqe *temp_qe; |
| 582 | struct lpfc_register doorbell; |
| 583 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 584 | /* sanity check on queue memory */ |
| 585 | if (unlikely(!q)) |
| 586 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 587 | phba = q->phba; |
| 588 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 589 | /* while there are valid entries */ |
| 590 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 591 | if (!phba->sli4_hba.pc_sli4_params.cqav) { |
| 592 | temp_qe = q->qe[q->host_index].cqe; |
| 593 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
| 594 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 595 | released++; |
| 596 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 597 | } |
| 598 | if (unlikely(released == 0 && !arm)) |
| 599 | return 0; |
| 600 | |
| 601 | /* ring doorbell for number popped */ |
| 602 | doorbell.word0 = 0; |
| 603 | if (arm) |
| 604 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 605 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 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 | return released; |
| 612 | } |
| 613 | |
| 614 | /** |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 615 | * lpfc_sli4_if6_cq_release - Indicates the host has finished processing a CQ |
| 616 | * @q: The Completion Queue that the host has completed processing for. |
| 617 | * @arm: Indicates whether the host wants to arms this CQ. |
| 618 | * |
| 619 | * This routine will mark all Completion queue entries on @q, from the last |
| 620 | * known completed entry to the last entry that was processed, as completed |
| 621 | * by clearing the valid bit for each completion queue entry. Then it will |
| 622 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 623 | * The internal host index in the @q will be updated by this routine to indicate |
| 624 | * that the host has finished processing the entries. The @arm parameter |
| 625 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 626 | * |
| 627 | * This function will return the number of CQEs that were released. |
| 628 | **/ |
| 629 | uint32_t |
| 630 | lpfc_sli4_if6_cq_release(struct lpfc_queue *q, bool arm) |
| 631 | { |
| 632 | uint32_t released = 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 633 | struct lpfc_hba *phba; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 634 | struct lpfc_cqe *temp_qe; |
| 635 | struct lpfc_register doorbell; |
| 636 | |
| 637 | /* sanity check on queue memory */ |
| 638 | if (unlikely(!q)) |
| 639 | return 0; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 640 | phba = q->phba; |
| 641 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 642 | /* while there are valid entries */ |
| 643 | while (q->hba_index != q->host_index) { |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 644 | if (!phba->sli4_hba.pc_sli4_params.cqav) { |
| 645 | temp_qe = q->qe[q->host_index].cqe; |
| 646 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
| 647 | } |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 648 | released++; |
| 649 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 650 | } |
| 651 | if (unlikely(released == 0 && !arm)) |
| 652 | return 0; |
| 653 | |
| 654 | /* ring doorbell for number popped */ |
| 655 | doorbell.word0 = 0; |
| 656 | if (arm) |
| 657 | bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1); |
| 658 | bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, released); |
| 659 | bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id); |
| 660 | writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr); |
| 661 | return released; |
| 662 | } |
| 663 | |
| 664 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 665 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 666 | * @q: The Header Receive Queue to operate on. |
| 667 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 668 | * |
| 669 | * This routine will copy the contents of @wqe to the next available entry on |
| 670 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 671 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 672 | * index that the rqe was copied to if successful. If no entries are available |
| 673 | * on @q then this function will return -ENOMEM. |
| 674 | * The caller is expected to hold the hbalock when calling this routine. |
| 675 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 676 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 677 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 678 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 679 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 680 | struct lpfc_rqe *temp_hrqe; |
| 681 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 682 | struct lpfc_register doorbell; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 683 | int hq_put_index; |
| 684 | int dq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 685 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 686 | /* sanity check on queue memory */ |
| 687 | if (unlikely(!hq) || unlikely(!dq)) |
| 688 | return -ENOMEM; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 689 | hq_put_index = hq->host_index; |
| 690 | dq_put_index = dq->host_index; |
| 691 | temp_hrqe = hq->qe[hq_put_index].rqe; |
| 692 | temp_drqe = dq->qe[dq_put_index].rqe; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 693 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 694 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 695 | return -EINVAL; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 696 | if (hq_put_index != dq_put_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 697 | return -EINVAL; |
| 698 | /* 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] | 699 | if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 700 | return -EBUSY; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 701 | lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 702 | lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 703 | |
| 704 | /* Update the host index to point to the next slot */ |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 705 | hq->host_index = ((hq_put_index + 1) % hq->entry_count); |
| 706 | dq->host_index = ((dq_put_index + 1) % dq->entry_count); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 707 | hq->RQ_buf_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 708 | |
| 709 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 710 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 711 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 712 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 713 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
| 714 | hq->entry_repost); |
| 715 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 716 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 717 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
| 718 | hq->entry_repost); |
| 719 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 720 | hq->host_index); |
| 721 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 722 | } else { |
| 723 | return -EINVAL; |
| 724 | } |
| 725 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 726 | } |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 727 | return hq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | /** |
| 731 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 732 | * @q: The Header Receive Queue to operate on. |
| 733 | * |
| 734 | * This routine will update the HBA index of a queue to reflect consumption of |
| 735 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 736 | * consumed an entry the host calls this function to update the queue's |
| 737 | * internal pointers. This routine returns the number of entries that were |
| 738 | * consumed by the HBA. |
| 739 | **/ |
| 740 | static uint32_t |
| 741 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 742 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 743 | /* sanity check on queue memory */ |
| 744 | if (unlikely(!hq) || unlikely(!dq)) |
| 745 | return 0; |
| 746 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 747 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 748 | return 0; |
| 749 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 750 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 751 | return 1; |
| 752 | } |
| 753 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 754 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 755 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 756 | * @phba: Pointer to HBA context object. |
| 757 | * @pring: Pointer to driver SLI ring object. |
| 758 | * |
| 759 | * This function returns pointer to next command iocb entry |
| 760 | * in the command ring. The caller must hold hbalock to prevent |
| 761 | * other threads consume the next command iocb. |
| 762 | * SLI-2/SLI-3 provide different sized iocbs. |
| 763 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 764 | static inline IOCB_t * |
| 765 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 766 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 767 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 768 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 769 | } |
| 770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 771 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 772 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 773 | * @phba: Pointer to HBA context object. |
| 774 | * @pring: Pointer to driver SLI ring object. |
| 775 | * |
| 776 | * This function returns pointer to next response iocb entry |
| 777 | * in the response ring. The caller must hold hbalock to make sure |
| 778 | * that no other thread consume the next response iocb. |
| 779 | * SLI-2/SLI-3 provide different sized iocbs. |
| 780 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 781 | static inline IOCB_t * |
| 782 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 783 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 784 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 785 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 786 | } |
| 787 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 788 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 789 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 790 | * @phba: Pointer to HBA context object. |
| 791 | * |
| 792 | * This function is called with hbalock held. This function |
| 793 | * allocates a new driver iocb object from the iocb pool. If the |
| 794 | * allocation is successful, it returns pointer to the newly |
| 795 | * allocated iocb object else it returns NULL. |
| 796 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 797 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 798 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 799 | { |
| 800 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 801 | struct lpfc_iocbq * iocbq = NULL; |
| 802 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 803 | lockdep_assert_held(&phba->hbalock); |
| 804 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 805 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 806 | if (iocbq) |
| 807 | phba->iocb_cnt++; |
| 808 | if (phba->iocb_cnt > phba->iocb_max) |
| 809 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 810 | return iocbq; |
| 811 | } |
| 812 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 813 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 814 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 815 | * @phba: Pointer to HBA context object. |
| 816 | * @xritag: XRI value. |
| 817 | * |
| 818 | * This function clears the sglq pointer from the array of acive |
| 819 | * sglq's. The xritag that is passed in is used to index into the |
| 820 | * array. Before the xritag can be used it needs to be adjusted |
| 821 | * by subtracting the xribase. |
| 822 | * |
| 823 | * Returns sglq ponter = success, NULL = Failure. |
| 824 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 825 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 826 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 827 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 828 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 829 | |
| 830 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 831 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 832 | return sglq; |
| 833 | } |
| 834 | |
| 835 | /** |
| 836 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 837 | * @phba: Pointer to HBA context object. |
| 838 | * @xritag: XRI value. |
| 839 | * |
| 840 | * This function returns the sglq pointer from the array of acive |
| 841 | * sglq's. The xritag that is passed in is used to index into the |
| 842 | * array. Before the xritag can be used it needs to be adjusted |
| 843 | * by subtracting the xribase. |
| 844 | * |
| 845 | * Returns sglq ponter = success, NULL = Failure. |
| 846 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 847 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 848 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 849 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 850 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 851 | |
| 852 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 853 | return sglq; |
| 854 | } |
| 855 | |
| 856 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 857 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 858 | * @phba: Pointer to HBA context object. |
| 859 | * @xritag: xri used in this exchange. |
| 860 | * @rrq: The RRQ to be cleared. |
| 861 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 862 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 863 | void |
| 864 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 865 | uint16_t xritag, |
| 866 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 867 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 868 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 869 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 870 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 871 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 872 | |
| 873 | /* The target DID could have been swapped (cable swap) |
| 874 | * we should use the ndlp from the findnode if it is |
| 875 | * available. |
| 876 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 877 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 878 | ndlp = rrq->ndlp; |
| 879 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 880 | if (!ndlp) |
| 881 | goto out; |
| 882 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 883 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 884 | rrq->send_rrq = 0; |
| 885 | rrq->xritag = 0; |
| 886 | rrq->rrq_stop_time = 0; |
| 887 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 888 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 889 | mempool_free(rrq, phba->rrq_pool); |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 894 | * @phba: Pointer to HBA context object. |
| 895 | * |
| 896 | * This function is called with hbalock held. This function |
| 897 | * Checks if stop_time (ratov from setting rrq active) has |
| 898 | * been reached, if it has and the send_rrq flag is set then |
| 899 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 900 | * then it will just call the routine to clear the rrq and |
| 901 | * free the rrq resource. |
| 902 | * The timer is set to the next rrq that is going to expire before |
| 903 | * leaving the routine. |
| 904 | * |
| 905 | **/ |
| 906 | void |
| 907 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 908 | { |
| 909 | struct lpfc_node_rrq *rrq; |
| 910 | struct lpfc_node_rrq *nextrrq; |
| 911 | unsigned long next_time; |
| 912 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 913 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 914 | |
| 915 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 916 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 917 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 918 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 919 | &phba->active_rrq_list, list) { |
| 920 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 921 | list_move(&rrq->list, &send_rrq); |
| 922 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 923 | next_time = rrq->rrq_stop_time; |
| 924 | } |
| 925 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 926 | if ((!list_empty(&phba->active_rrq_list)) && |
| 927 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 928 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 929 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 930 | list_del(&rrq->list); |
| 931 | if (!rrq->send_rrq) |
| 932 | /* this call will free the rrq */ |
| 933 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 934 | else if (lpfc_send_rrq(phba, rrq)) { |
| 935 | /* if we send the rrq then the completion handler |
| 936 | * will clear the bit in the xribitmap. |
| 937 | */ |
| 938 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 939 | rrq); |
| 940 | } |
| 941 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | /** |
| 945 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 946 | * @vport: Pointer to vport context object. |
| 947 | * @xri: The xri used in the exchange. |
| 948 | * @did: The targets DID for this exchange. |
| 949 | * |
| 950 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 951 | * rrq = rrq for this xri and target. |
| 952 | **/ |
| 953 | struct lpfc_node_rrq * |
| 954 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 955 | { |
| 956 | struct lpfc_hba *phba = vport->phba; |
| 957 | struct lpfc_node_rrq *rrq; |
| 958 | struct lpfc_node_rrq *nextrrq; |
| 959 | unsigned long iflags; |
| 960 | |
| 961 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 962 | return NULL; |
| 963 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 964 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 965 | if (rrq->vport == vport && rrq->xritag == xri && |
| 966 | rrq->nlp_DID == did){ |
| 967 | list_del(&rrq->list); |
| 968 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 969 | return rrq; |
| 970 | } |
| 971 | } |
| 972 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 973 | return NULL; |
| 974 | } |
| 975 | |
| 976 | /** |
| 977 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 978 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 979 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 980 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 981 | * phba->active_rrq_list and clear the rrq. |
| 982 | * 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] | 983 | **/ |
| 984 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 985 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 986 | |
| 987 | { |
| 988 | struct lpfc_hba *phba = vport->phba; |
| 989 | struct lpfc_node_rrq *rrq; |
| 990 | struct lpfc_node_rrq *nextrrq; |
| 991 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 992 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 993 | |
| 994 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 995 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 996 | if (!ndlp) { |
| 997 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 998 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 999 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1000 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1001 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 1002 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 1003 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1004 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1005 | |
| 1006 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 1007 | list_del(&rrq->list); |
| 1008 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 1009 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1013 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1014 | * @phba: Pointer to HBA context object. |
| 1015 | * @ndlp: Targets nodelist pointer for this exchange. |
| 1016 | * @xritag the xri in the bitmap to test. |
| 1017 | * |
| 1018 | * This function is called with hbalock held. This function |
| 1019 | * returns 0 = rrq not active for this xri |
| 1020 | * 1 = rrq is valid for this xri. |
| 1021 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 1022 | int |
| 1023 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1024 | uint16_t xritag) |
| 1025 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1026 | lockdep_assert_held(&phba->hbalock); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1027 | if (!ndlp) |
| 1028 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1029 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1030 | return 0; |
| 1031 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1032 | return 1; |
| 1033 | else |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
| 1037 | /** |
| 1038 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 1039 | * @phba: Pointer to HBA context object. |
| 1040 | * @ndlp: nodelist pointer for this target. |
| 1041 | * @xritag: xri used in this exchange. |
| 1042 | * @rxid: Remote Exchange ID. |
| 1043 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 1044 | * |
| 1045 | * This function takes the hbalock. |
| 1046 | * The active bit is always set in the active rrq xri_bitmap even |
| 1047 | * if there is no slot avaiable for the other rrq information. |
| 1048 | * |
| 1049 | * returns 0 rrq actived for this xri |
| 1050 | * < 0 No memory or invalid ndlp. |
| 1051 | **/ |
| 1052 | int |
| 1053 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1054 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1055 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1056 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1057 | struct lpfc_node_rrq *rrq; |
| 1058 | int empty; |
| 1059 | |
| 1060 | if (!ndlp) |
| 1061 | return -EINVAL; |
| 1062 | |
| 1063 | if (!phba->cfg_enable_rrq) |
| 1064 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1065 | |
| 1066 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1067 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1068 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 1069 | goto out; |
| 1070 | } |
| 1071 | |
| 1072 | /* |
| 1073 | * set the active bit even if there is no mem available. |
| 1074 | */ |
| 1075 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 1076 | goto out; |
| 1077 | |
| 1078 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 1079 | goto out; |
| 1080 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 1081 | if (!ndlp->active_rrqs_xri_bitmap) |
| 1082 | goto out; |
| 1083 | |
| 1084 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1085 | goto out; |
| 1086 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1087 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1088 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 1089 | if (!rrq) { |
| 1090 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1091 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 1092 | " DID:0x%x Send:%d\n", |
| 1093 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1094 | return -EINVAL; |
| 1095 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 1096 | if (phba->cfg_enable_rrq == 1) |
| 1097 | rrq->send_rrq = send_rrq; |
| 1098 | else |
| 1099 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1100 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1101 | rrq->rrq_stop_time = jiffies + |
| 1102 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1103 | rrq->ndlp = ndlp; |
| 1104 | rrq->nlp_DID = ndlp->nlp_DID; |
| 1105 | rrq->vport = ndlp->vport; |
| 1106 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 1107 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1108 | empty = list_empty(&phba->active_rrq_list); |
| 1109 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 1110 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1111 | if (empty) |
| 1112 | lpfc_worker_wake_up(phba); |
| 1113 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1114 | return 0; |
| 1115 | out: |
| 1116 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1117 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 1118 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 1119 | " DID:0x%x Send:%d\n", |
| 1120 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 1121 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1125 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1126 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1127 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1128 | * |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 1129 | * This function is called with the ring lock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1130 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1131 | * list is not empty then it is successful, it returns pointer to the newly |
| 1132 | * allocated sglq object else it returns NULL. |
| 1133 | **/ |
| 1134 | static struct lpfc_sglq * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1135 | __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] | 1136 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1137 | 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] | 1138 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1139 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1140 | struct lpfc_scsi_buf *lpfc_cmd; |
| 1141 | struct lpfc_nodelist *ndlp; |
| 1142 | int found = 0; |
| 1143 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1144 | lockdep_assert_held(&phba->hbalock); |
| 1145 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1146 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 1147 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 1148 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 1149 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1150 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1151 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1152 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 1153 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 1154 | ndlp = NULL; |
| 1155 | else |
| 1156 | ndlp = piocbq->context_un.ndlp; |
| 1157 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1158 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 1159 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1160 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1161 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 1162 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1163 | start_sglq = sglq; |
| 1164 | while (!found) { |
| 1165 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 1166 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1167 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 1168 | test_bit(sglq->sli4_lxritag, |
| 1169 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1170 | /* This xri has an rrq outstanding for this DID. |
| 1171 | * put it back in the list and get another xri. |
| 1172 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1173 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1174 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1175 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1176 | struct lpfc_sglq, list); |
| 1177 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 1178 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1179 | sglq = NULL; |
| 1180 | break; |
| 1181 | } else |
| 1182 | continue; |
| 1183 | } |
| 1184 | sglq->ndlp = ndlp; |
| 1185 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1186 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1187 | sglq->state = SGL_ALLOCATED; |
| 1188 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1189 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1190 | return sglq; |
| 1191 | } |
| 1192 | |
| 1193 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1194 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 1195 | * @phba: Pointer to HBA context object. |
| 1196 | * @piocb: Pointer to the iocbq. |
| 1197 | * |
| 1198 | * This function is called with the sgl_list lock held. This function |
| 1199 | * gets a new driver sglq object from the sglq list. If the |
| 1200 | * list is not empty then it is successful, it returns pointer to the newly |
| 1201 | * allocated sglq object else it returns NULL. |
| 1202 | **/ |
| 1203 | struct lpfc_sglq * |
| 1204 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 1205 | { |
| 1206 | struct list_head *lpfc_nvmet_sgl_list; |
| 1207 | struct lpfc_sglq *sglq = NULL; |
| 1208 | |
| 1209 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1210 | |
| 1211 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1212 | |
| 1213 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1214 | if (!sglq) |
| 1215 | return NULL; |
| 1216 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1217 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1218 | return sglq; |
| 1219 | } |
| 1220 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1221 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1222 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1223 | * @phba: Pointer to HBA context object. |
| 1224 | * |
| 1225 | * This function is called with no lock held. This function |
| 1226 | * allocates a new driver iocb object from the iocb pool. If the |
| 1227 | * allocation is successful, it returns pointer to the newly |
| 1228 | * allocated iocb object else it returns NULL. |
| 1229 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1230 | struct lpfc_iocbq * |
| 1231 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1232 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1233 | struct lpfc_iocbq * iocbq = NULL; |
| 1234 | unsigned long iflags; |
| 1235 | |
| 1236 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1237 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1238 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1239 | return iocbq; |
| 1240 | } |
| 1241 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1242 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1243 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1244 | * @phba: Pointer to HBA context object. |
| 1245 | * @iocbq: Pointer to driver iocb object. |
| 1246 | * |
| 1247 | * This function is called with hbalock held to release driver |
| 1248 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1249 | * does not change for each use of the iocb object. This function |
| 1250 | * clears all other fields of the iocb object when it is freed. |
| 1251 | * The sqlq structure that holds the xritag and phys and virtual |
| 1252 | * mappings for the scatter gather list is retrieved from the |
| 1253 | * active array of sglq. The get of the sglq pointer also clears |
| 1254 | * the entry in the array. If the status of the IO indiactes that |
| 1255 | * this IO was aborted then the sglq entry it put on the |
| 1256 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1257 | * 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] | 1258 | * entry is added to the free list (lpfc_els_sgl_list). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1259 | **/ |
| 1260 | static void |
| 1261 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1262 | { |
| 1263 | struct lpfc_sglq *sglq; |
| 1264 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1265 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1266 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1267 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1268 | lockdep_assert_held(&phba->hbalock); |
| 1269 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1270 | if (iocbq->sli4_xritag == NO_XRI) |
| 1271 | sglq = NULL; |
| 1272 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1273 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1274 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1275 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1276 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1277 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1278 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1279 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1280 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1281 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1282 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1283 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1284 | spin_unlock_irqrestore( |
| 1285 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1286 | goto out; |
| 1287 | } |
| 1288 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1289 | pring = phba->sli4_hba.els_wq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1290 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1291 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1292 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1293 | iflag); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1294 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1295 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1296 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1297 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1298 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1299 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1300 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1301 | sglq->state = SGL_FREED; |
| 1302 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1303 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1304 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1305 | spin_unlock_irqrestore( |
| 1306 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1307 | |
| 1308 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1309 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1310 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1311 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1312 | } |
| 1313 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1314 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1315 | /* |
| 1316 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1317 | */ |
| 1318 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1319 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1320 | iocbq->sli4_xritag = NO_XRI; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1321 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 1322 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1323 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1324 | } |
| 1325 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1326 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1327 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1328 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1329 | * @phba: Pointer to HBA context object. |
| 1330 | * @iocbq: Pointer to driver iocb object. |
| 1331 | * |
| 1332 | * This function is called with hbalock held to release driver |
| 1333 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1334 | * does not change for each use of the iocb object. This function |
| 1335 | * clears all other fields of the iocb object when it is freed. |
| 1336 | **/ |
| 1337 | static void |
| 1338 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1339 | { |
| 1340 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1341 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1342 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1343 | |
| 1344 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1345 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1346 | */ |
| 1347 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1348 | iocbq->sli4_xritag = NO_XRI; |
| 1349 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1350 | } |
| 1351 | |
| 1352 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1353 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1354 | * @phba: Pointer to HBA context object. |
| 1355 | * @iocbq: Pointer to driver iocb object. |
| 1356 | * |
| 1357 | * This function is called with hbalock held to release driver |
| 1358 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1359 | * does not change for each use of the iocb object. This function |
| 1360 | * clears all other fields of the iocb object when it is freed. |
| 1361 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1362 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1363 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1364 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1365 | lockdep_assert_held(&phba->hbalock); |
| 1366 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1367 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1368 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1369 | } |
| 1370 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1371 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1372 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1373 | * @phba: Pointer to HBA context object. |
| 1374 | * @iocbq: Pointer to driver iocb object. |
| 1375 | * |
| 1376 | * This function is called with no lock held to release the iocb to |
| 1377 | * iocb pool. |
| 1378 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1379 | void |
| 1380 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1381 | { |
| 1382 | unsigned long iflags; |
| 1383 | |
| 1384 | /* |
| 1385 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1386 | */ |
| 1387 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1388 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1389 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1390 | } |
| 1391 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1392 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1393 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1394 | * @phba: Pointer to HBA context object. |
| 1395 | * @iocblist: List of IOCBs. |
| 1396 | * @ulpstatus: ULP status in IOCB command field. |
| 1397 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1398 | * |
| 1399 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1400 | * on the list by invoking the complete callback function associated with the |
| 1401 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1402 | * fields. |
| 1403 | **/ |
| 1404 | void |
| 1405 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1406 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1407 | { |
| 1408 | struct lpfc_iocbq *piocb; |
| 1409 | |
| 1410 | while (!list_empty(iocblist)) { |
| 1411 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1412 | if (!piocb->iocb_cmpl) |
| 1413 | lpfc_sli_release_iocbq(phba, piocb); |
| 1414 | else { |
| 1415 | piocb->iocb.ulpStatus = ulpstatus; |
| 1416 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1417 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1418 | } |
| 1419 | } |
| 1420 | return; |
| 1421 | } |
| 1422 | |
| 1423 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1424 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1425 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1426 | * |
| 1427 | * This function is called by ring event handler function to get the iocb type. |
| 1428 | * This function translates the iocb command to an iocb command type used to |
| 1429 | * decide the final disposition of each completed IOCB. |
| 1430 | * The function returns |
| 1431 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1432 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1433 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1434 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1435 | * |
| 1436 | * The caller is not required to hold any lock. |
| 1437 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1438 | static lpfc_iocb_type |
| 1439 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1440 | { |
| 1441 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1442 | |
| 1443 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1444 | return 0; |
| 1445 | |
| 1446 | switch (iocb_cmnd) { |
| 1447 | case CMD_XMIT_SEQUENCE_CR: |
| 1448 | case CMD_XMIT_SEQUENCE_CX: |
| 1449 | case CMD_XMIT_BCAST_CN: |
| 1450 | case CMD_XMIT_BCAST_CX: |
| 1451 | case CMD_ELS_REQUEST_CR: |
| 1452 | case CMD_ELS_REQUEST_CX: |
| 1453 | case CMD_CREATE_XRI_CR: |
| 1454 | case CMD_CREATE_XRI_CX: |
| 1455 | case CMD_GET_RPI_CN: |
| 1456 | case CMD_XMIT_ELS_RSP_CX: |
| 1457 | case CMD_GET_RPI_CR: |
| 1458 | case CMD_FCP_IWRITE_CR: |
| 1459 | case CMD_FCP_IWRITE_CX: |
| 1460 | case CMD_FCP_IREAD_CR: |
| 1461 | case CMD_FCP_IREAD_CX: |
| 1462 | case CMD_FCP_ICMND_CR: |
| 1463 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1464 | case CMD_FCP_TSEND_CX: |
| 1465 | case CMD_FCP_TRSP_CX: |
| 1466 | case CMD_FCP_TRECEIVE_CX: |
| 1467 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1468 | case CMD_ADAPTER_MSG: |
| 1469 | case CMD_ADAPTER_DUMP: |
| 1470 | case CMD_XMIT_SEQUENCE64_CR: |
| 1471 | case CMD_XMIT_SEQUENCE64_CX: |
| 1472 | case CMD_XMIT_BCAST64_CN: |
| 1473 | case CMD_XMIT_BCAST64_CX: |
| 1474 | case CMD_ELS_REQUEST64_CR: |
| 1475 | case CMD_ELS_REQUEST64_CX: |
| 1476 | case CMD_FCP_IWRITE64_CR: |
| 1477 | case CMD_FCP_IWRITE64_CX: |
| 1478 | case CMD_FCP_IREAD64_CR: |
| 1479 | case CMD_FCP_IREAD64_CX: |
| 1480 | case CMD_FCP_ICMND64_CR: |
| 1481 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1482 | case CMD_FCP_TSEND64_CX: |
| 1483 | case CMD_FCP_TRSP64_CX: |
| 1484 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | case CMD_GEN_REQUEST64_CR: |
| 1486 | case CMD_GEN_REQUEST64_CX: |
| 1487 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1488 | case DSSCMD_IWRITE64_CR: |
| 1489 | case DSSCMD_IWRITE64_CX: |
| 1490 | case DSSCMD_IREAD64_CR: |
| 1491 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1492 | type = LPFC_SOL_IOCB; |
| 1493 | break; |
| 1494 | case CMD_ABORT_XRI_CN: |
| 1495 | case CMD_ABORT_XRI_CX: |
| 1496 | case CMD_CLOSE_XRI_CN: |
| 1497 | case CMD_CLOSE_XRI_CX: |
| 1498 | case CMD_XRI_ABORTED_CX: |
| 1499 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1500 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | type = LPFC_ABORT_IOCB; |
| 1502 | break; |
| 1503 | case CMD_RCV_SEQUENCE_CX: |
| 1504 | case CMD_RCV_ELS_REQ_CX: |
| 1505 | case CMD_RCV_SEQUENCE64_CX: |
| 1506 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1507 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1508 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1509 | case CMD_IOCB_RCV_ELS64_CX: |
| 1510 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1511 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | type = LPFC_UNSOL_IOCB; |
| 1513 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1514 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1515 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1516 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1517 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1518 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1519 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1520 | case CMD_IOCB_RET_HBQE64_CN: |
| 1521 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1522 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1523 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1524 | case CMD_IOCB_LOGENTRY_CN: |
| 1525 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1526 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1527 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1528 | type = LPFC_UNKNOWN_IOCB; |
| 1529 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1530 | default: |
| 1531 | type = LPFC_UNKNOWN_IOCB; |
| 1532 | break; |
| 1533 | } |
| 1534 | |
| 1535 | return type; |
| 1536 | } |
| 1537 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1538 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1539 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1540 | * @phba: Pointer to HBA context object. |
| 1541 | * |
| 1542 | * This function is called from SLI initialization code |
| 1543 | * to configure every ring of the HBA's SLI interface. The |
| 1544 | * caller is not required to hold any lock. This function issues |
| 1545 | * a config_ring mailbox command for each ring. |
| 1546 | * This function returns zero if successful else returns a negative |
| 1547 | * error code. |
| 1548 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1550 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1551 | { |
| 1552 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1553 | LPFC_MBOXQ_t *pmb; |
| 1554 | MAILBOX_t *pmbox; |
| 1555 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1556 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1557 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1558 | if (!pmb) |
| 1559 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1560 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1561 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1562 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1563 | lpfc_config_ring(phba, i, pmb); |
| 1564 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1565 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1566 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1567 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1568 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1569 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1570 | rc, pmbox->mbxCommand, |
| 1571 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1572 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1573 | ret = -ENXIO; |
| 1574 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1575 | } |
| 1576 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1577 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1578 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1579 | } |
| 1580 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1581 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1582 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1583 | * @phba: Pointer to HBA context object. |
| 1584 | * @pring: Pointer to driver SLI ring object. |
| 1585 | * @piocb: Pointer to the driver iocb object. |
| 1586 | * |
| 1587 | * This function is called with hbalock held. The function adds the |
| 1588 | * new iocb to txcmplq of the given ring. This function always returns |
| 1589 | * 0. If this function is called for ELS ring, this function checks if |
| 1590 | * there is a vport associated with the ELS command. This function also |
| 1591 | * starts els_tmofunc timer if this is an ELS command. |
| 1592 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1593 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1594 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1595 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1596 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1597 | lockdep_assert_held(&phba->hbalock); |
| 1598 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1599 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1600 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1601 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1602 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1603 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1604 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1605 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1606 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1607 | BUG_ON(!piocb->vport); |
| 1608 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1609 | mod_timer(&piocb->vport->els_tmofunc, |
| 1610 | jiffies + |
| 1611 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1612 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1613 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1614 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1615 | } |
| 1616 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1617 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1618 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1619 | * @phba: Pointer to HBA context object. |
| 1620 | * @pring: Pointer to driver SLI ring object. |
| 1621 | * |
| 1622 | * This function is called with hbalock held to get next |
| 1623 | * iocb in txq of the given ring. If there is any iocb in |
| 1624 | * the txq, the function returns first iocb in the list after |
| 1625 | * removing the iocb from the list, else it returns NULL. |
| 1626 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1627 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1628 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1629 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1630 | struct lpfc_iocbq *cmd_iocb; |
| 1631 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1632 | lockdep_assert_held(&phba->hbalock); |
| 1633 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1634 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1635 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1636 | } |
| 1637 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1638 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1639 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1640 | * @phba: Pointer to HBA context object. |
| 1641 | * @pring: Pointer to driver SLI ring object. |
| 1642 | * |
| 1643 | * This function is called with hbalock held and the caller must post the |
| 1644 | * iocb without releasing the lock. If the caller releases the lock, |
| 1645 | * iocb slot returned by the function is not guaranteed to be available. |
| 1646 | * The function returns pointer to the next available iocb slot if there |
| 1647 | * is available slot in the ring, else it returns NULL. |
| 1648 | * If the get index of the ring is ahead of the put index, the function |
| 1649 | * will post an error attention event to the worker thread to take the |
| 1650 | * HBA to offline state. |
| 1651 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | static IOCB_t * |
| 1653 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1654 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1655 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1656 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1657 | |
| 1658 | lockdep_assert_held(&phba->hbalock); |
| 1659 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1660 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1661 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1662 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1663 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1664 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1665 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1666 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1667 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1668 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1669 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1670 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1671 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1672 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1673 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1674 | pring->sli.sli3.local_getidx, |
| 1675 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1676 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1677 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1678 | /* |
| 1679 | * All error attention handlers are posted to |
| 1680 | * worker thread |
| 1681 | */ |
| 1682 | phba->work_ha |= HA_ERATT; |
| 1683 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1684 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1685 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1686 | |
| 1687 | return NULL; |
| 1688 | } |
| 1689 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1690 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1691 | return NULL; |
| 1692 | } |
| 1693 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1694 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1695 | } |
| 1696 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1697 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1698 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1699 | * @phba: Pointer to HBA context object. |
| 1700 | * @iocbq: Pointer to driver iocb object. |
| 1701 | * |
| 1702 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1703 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1704 | * array and assigns a new iotag. |
| 1705 | * The function returns the allocated iotag if successful, else returns zero. |
| 1706 | * Zero is not a valid iotag. |
| 1707 | * The caller is not required to hold any lock. |
| 1708 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1709 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1710 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1711 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1712 | struct lpfc_iocbq **new_arr; |
| 1713 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1714 | size_t new_len; |
| 1715 | struct lpfc_sli *psli = &phba->sli; |
| 1716 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1717 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1718 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1719 | iotag = psli->last_iotag; |
| 1720 | if(++iotag < psli->iocbq_lookup_len) { |
| 1721 | psli->last_iotag = iotag; |
| 1722 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1723 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1724 | iocbq->iotag = iotag; |
| 1725 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1726 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1727 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1728 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1729 | spin_unlock_irq(&phba->hbalock); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1730 | new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1731 | GFP_KERNEL); |
| 1732 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1733 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1734 | old_arr = psli->iocbq_lookup; |
| 1735 | if (new_len <= psli->iocbq_lookup_len) { |
| 1736 | /* highly unprobable case */ |
| 1737 | kfree(new_arr); |
| 1738 | iotag = psli->last_iotag; |
| 1739 | if(++iotag < psli->iocbq_lookup_len) { |
| 1740 | psli->last_iotag = iotag; |
| 1741 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1742 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1743 | iocbq->iotag = iotag; |
| 1744 | return iotag; |
| 1745 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1746 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1747 | return 0; |
| 1748 | } |
| 1749 | if (psli->iocbq_lookup) |
| 1750 | memcpy(new_arr, old_arr, |
| 1751 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1752 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1753 | psli->iocbq_lookup = new_arr; |
| 1754 | psli->iocbq_lookup_len = new_len; |
| 1755 | psli->last_iotag = iotag; |
| 1756 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1757 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1758 | iocbq->iotag = iotag; |
| 1759 | kfree(old_arr); |
| 1760 | return iotag; |
| 1761 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1762 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1763 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1764 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1765 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1766 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1767 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1768 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1769 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1770 | } |
| 1771 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1772 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1773 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1774 | * @phba: Pointer to HBA context object. |
| 1775 | * @pring: Pointer to driver SLI ring object. |
| 1776 | * @iocb: Pointer to iocb slot in the ring. |
| 1777 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1778 | * posted to firmware. |
| 1779 | * |
| 1780 | * This function is called with hbalock held to post a new iocb to |
| 1781 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1782 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1783 | * a completion call back for this iocb else the function will free the |
| 1784 | * iocb object. |
| 1785 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1786 | static void |
| 1787 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1788 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1789 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1790 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1791 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1792 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1793 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1794 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1795 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1796 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1797 | if (pring->ringno == LPFC_ELS_RING) { |
| 1798 | lpfc_debugfs_slow_ring_trc(phba, |
| 1799 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1800 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1801 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1802 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1803 | } |
| 1804 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1805 | /* |
| 1806 | * Issue iocb command to adapter |
| 1807 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1808 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1809 | wmb(); |
| 1810 | pring->stats.iocb_cmd++; |
| 1811 | |
| 1812 | /* |
| 1813 | * If there is no completion routine to call, we can release the |
| 1814 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1815 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1816 | */ |
| 1817 | if (nextiocb->iocb_cmpl) |
| 1818 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1819 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1820 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1821 | |
| 1822 | /* |
| 1823 | * Let the HBA know what IOCB slot will be the next one the |
| 1824 | * driver will put a command into. |
| 1825 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1826 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1827 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1828 | } |
| 1829 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1830 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1831 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1832 | * @phba: Pointer to HBA context object. |
| 1833 | * @pring: Pointer to driver SLI ring object. |
| 1834 | * |
| 1835 | * The caller is not required to hold any lock for calling this function. |
| 1836 | * This function updates the chip attention bits for the ring to inform firmware |
| 1837 | * that there are pending work to be done for this ring and requests an |
| 1838 | * interrupt when there is space available in the ring. This function is |
| 1839 | * called when the driver is unable to post more iocbs to the ring due |
| 1840 | * to unavailability of space in the ring. |
| 1841 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1842 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1843 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1844 | { |
| 1845 | int ringno = pring->ringno; |
| 1846 | |
| 1847 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1848 | |
| 1849 | wmb(); |
| 1850 | |
| 1851 | /* |
| 1852 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1853 | * The HBA will tell us when an IOCB entry is available. |
| 1854 | */ |
| 1855 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1856 | readl(phba->CAregaddr); /* flush */ |
| 1857 | |
| 1858 | pring->stats.iocb_cmd_full++; |
| 1859 | } |
| 1860 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1861 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1862 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1863 | * @phba: Pointer to HBA context object. |
| 1864 | * @pring: Pointer to driver SLI ring object. |
| 1865 | * |
| 1866 | * This function updates the chip attention register bit for the |
| 1867 | * given ring to inform HBA that there is more work to be done |
| 1868 | * in this ring. The caller is not required to hold any lock. |
| 1869 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1870 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1871 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1872 | { |
| 1873 | int ringno = pring->ringno; |
| 1874 | |
| 1875 | /* |
| 1876 | * Tell the HBA that there is work to do in this ring. |
| 1877 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1878 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1879 | wmb(); |
| 1880 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1881 | readl(phba->CAregaddr); /* flush */ |
| 1882 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1883 | } |
| 1884 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1885 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1886 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1887 | * @phba: Pointer to HBA context object. |
| 1888 | * @pring: Pointer to driver SLI ring object. |
| 1889 | * |
| 1890 | * This function is called with hbalock held to post pending iocbs |
| 1891 | * in the txq to the firmware. This function is called when driver |
| 1892 | * detects space available in the ring. |
| 1893 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1894 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1895 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1896 | { |
| 1897 | IOCB_t *iocb; |
| 1898 | struct lpfc_iocbq *nextiocb; |
| 1899 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1900 | lockdep_assert_held(&phba->hbalock); |
| 1901 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1902 | /* |
| 1903 | * Check to see if: |
| 1904 | * (a) there is anything on the txq to send |
| 1905 | * (b) link is up |
| 1906 | * (c) link attention events can be processed (fcp ring only) |
| 1907 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1908 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1909 | |
| 1910 | if (lpfc_is_link_up(phba) && |
| 1911 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1912 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1913 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1914 | |
| 1915 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1916 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1917 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1918 | |
| 1919 | if (iocb) |
| 1920 | lpfc_sli_update_ring(phba, pring); |
| 1921 | else |
| 1922 | lpfc_sli_update_full_ring(phba, pring); |
| 1923 | } |
| 1924 | |
| 1925 | return; |
| 1926 | } |
| 1927 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1928 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1929 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1930 | * @phba: Pointer to HBA context object. |
| 1931 | * @hbqno: HBQ number. |
| 1932 | * |
| 1933 | * This function is called with hbalock held to get the next |
| 1934 | * available slot for the given HBQ. If there is free slot |
| 1935 | * available for the HBQ it will return pointer to the next available |
| 1936 | * HBQ entry else it will return NULL. |
| 1937 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1938 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1939 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1940 | { |
| 1941 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1942 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1943 | lockdep_assert_held(&phba->hbalock); |
| 1944 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1945 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1946 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1947 | hbqp->next_hbqPutIdx = 0; |
| 1948 | |
| 1949 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1950 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1951 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1952 | |
| 1953 | hbqp->local_hbqGetIdx = getidx; |
| 1954 | |
| 1955 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1956 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1957 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1958 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1959 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1960 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1961 | hbqp->entry_count); |
| 1962 | |
| 1963 | phba->link_state = LPFC_HBA_ERROR; |
| 1964 | return NULL; |
| 1965 | } |
| 1966 | |
| 1967 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1968 | return NULL; |
| 1969 | } |
| 1970 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1971 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1972 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1973 | } |
| 1974 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1975 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1976 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1977 | * @phba: Pointer to HBA context object. |
| 1978 | * |
| 1979 | * This function is called with no lock held to free all the |
| 1980 | * hbq buffers while uninitializing the SLI interface. It also |
| 1981 | * frees the HBQ buffers returned by the firmware but not yet |
| 1982 | * processed by the upper layers. |
| 1983 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1984 | void |
| 1985 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1986 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1987 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1988 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1989 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1990 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1991 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1992 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1993 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1994 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1995 | for (i = 0; i < hbq_count; ++i) { |
| 1996 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1997 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1998 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1999 | list_del(&hbq_buf->dbuf.list); |
| 2000 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 2001 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2002 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2003 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2004 | |
| 2005 | /* Mark the HBQs not in use */ |
| 2006 | phba->hbq_in_use = 0; |
| 2007 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2008 | } |
| 2009 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2010 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2011 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 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 |
| 2017 | * hbq buffer to the firmware. If the function finds an empty |
| 2018 | * slot in the HBQ, it will post the buffer. The function will return |
| 2019 | * pointer to the hbq entry if it successfully post the buffer |
| 2020 | * else it will return NULL. |
| 2021 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2022 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2023 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2024 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2025 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2026 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2027 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 2028 | } |
| 2029 | |
| 2030 | /** |
| 2031 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 2032 | * @phba: Pointer to HBA context object. |
| 2033 | * @hbqno: HBQ number. |
| 2034 | * @hbq_buf: Pointer to HBQ buffer. |
| 2035 | * |
| 2036 | * This function is called with the hbalock held to post a hbq buffer to the |
| 2037 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 2038 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 2039 | * it successfully post the buffer else it will return an error. |
| 2040 | **/ |
| 2041 | static int |
| 2042 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 2043 | struct hbq_dmabuf *hbq_buf) |
| 2044 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2045 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2046 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2047 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2048 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2049 | /* Get next HBQ entry slot to use */ |
| 2050 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 2051 | if (hbqe) { |
| 2052 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 2053 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2054 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 2055 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2056 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2057 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2058 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 2059 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 2060 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2061 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 2062 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2063 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2064 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2065 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2066 | return 0; |
| 2067 | } else |
| 2068 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2069 | } |
| 2070 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2071 | /** |
| 2072 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 2073 | * @phba: Pointer to HBA context object. |
| 2074 | * @hbqno: HBQ number. |
| 2075 | * @hbq_buf: Pointer to HBQ buffer. |
| 2076 | * |
| 2077 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 2078 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 2079 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 2080 | **/ |
| 2081 | static int |
| 2082 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 2083 | struct hbq_dmabuf *hbq_buf) |
| 2084 | { |
| 2085 | int rc; |
| 2086 | struct lpfc_rqe hrqe; |
| 2087 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2088 | struct lpfc_queue *hrq; |
| 2089 | struct lpfc_queue *drq; |
| 2090 | |
| 2091 | if (hbqno != LPFC_ELS_HBQ) |
| 2092 | return 1; |
| 2093 | hrq = phba->sli4_hba.hdr_rq; |
| 2094 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2095 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2096 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2097 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 2098 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 2099 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 2100 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2101 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2102 | if (rc < 0) |
| 2103 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2104 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 2105 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 2106 | return 0; |
| 2107 | } |
| 2108 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2109 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2110 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 2111 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2112 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2113 | .mask_count = 0, |
| 2114 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2115 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2116 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2117 | .init_count = 40, |
| 2118 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2119 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2120 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2121 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2122 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2123 | &lpfc_els_hbq, |
| 2124 | }; |
| 2125 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2126 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2127 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2128 | * @phba: Pointer to HBA context object. |
| 2129 | * @hbqno: HBQ number. |
| 2130 | * @count: Number of HBQ buffers to be posted. |
| 2131 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2132 | * This function is called with no lock held to post more hbq buffers to the |
| 2133 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 2134 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2135 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 2136 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2137 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 2138 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2139 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2140 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2141 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2142 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2143 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2144 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2145 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2146 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 2147 | lpfc_hbq_defs[hbqno]->entry_count) |
| 2148 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 2149 | phba->hbqs[hbqno].buffer_count; |
| 2150 | if (!count) |
| 2151 | return 0; |
| 2152 | /* Allocate HBQ entries */ |
| 2153 | for (i = 0; i < count; i++) { |
| 2154 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 2155 | if (!hbq_buffer) |
| 2156 | break; |
| 2157 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 2158 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2159 | /* Check whether HBQ is still in use */ |
| 2160 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 2161 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2162 | goto err; |
| 2163 | while (!list_empty(&hbq_buf_list)) { |
| 2164 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2165 | dbuf.list); |
| 2166 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 2167 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2168 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2169 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2170 | posted++; |
| 2171 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2172 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2173 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2174 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2175 | return posted; |
| 2176 | err: |
| 2177 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 2178 | while (!list_empty(&hbq_buf_list)) { |
| 2179 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 2180 | dbuf.list); |
| 2181 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 2182 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2183 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2184 | } |
| 2185 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2186 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2187 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2188 | * @phba: Pointer to HBA context object. |
| 2189 | * @qno: HBQ number. |
| 2190 | * |
| 2191 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2192 | * is called with no lock held. The function returns the number of HBQ entries |
| 2193 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2194 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2195 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2196 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2197 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2198 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2199 | return 0; |
| 2200 | else |
| 2201 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2202 | lpfc_hbq_defs[qno]->add_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 | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2206 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2207 | * @phba: Pointer to HBA context object. |
| 2208 | * @qno: HBQ queue number. |
| 2209 | * |
| 2210 | * This function is called from SLI initialization code path with |
| 2211 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2212 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2213 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2214 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2215 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2216 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2217 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2218 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2219 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2220 | else |
| 2221 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2222 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2223 | } |
| 2224 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2225 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2226 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 2227 | * @phba: Pointer to HBA context object. |
| 2228 | * @hbqno: HBQ number. |
| 2229 | * |
| 2230 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2231 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2232 | **/ |
| 2233 | static struct hbq_dmabuf * |
| 2234 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2235 | { |
| 2236 | struct lpfc_dmabuf *d_buf; |
| 2237 | |
| 2238 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2239 | if (!d_buf) |
| 2240 | return NULL; |
| 2241 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2242 | } |
| 2243 | |
| 2244 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2245 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2246 | * @phba: Pointer to HBA context object. |
| 2247 | * @hbqno: HBQ number. |
| 2248 | * |
| 2249 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2250 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2251 | **/ |
| 2252 | static struct rqb_dmabuf * |
| 2253 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2254 | { |
| 2255 | struct lpfc_dmabuf *h_buf; |
| 2256 | struct lpfc_rqb *rqbp; |
| 2257 | |
| 2258 | rqbp = hrq->rqbp; |
| 2259 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2260 | struct lpfc_dmabuf, list); |
| 2261 | if (!h_buf) |
| 2262 | return NULL; |
| 2263 | rqbp->buffer_count--; |
| 2264 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2265 | } |
| 2266 | |
| 2267 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2268 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2269 | * @phba: Pointer to HBA context object. |
| 2270 | * @tag: Tag of the hbq buffer. |
| 2271 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2272 | * This function searches for the hbq buffer associated with the given tag in |
| 2273 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2274 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2275 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2276 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2277 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2278 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2279 | struct lpfc_dmabuf *d_buf; |
| 2280 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2281 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2282 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2283 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2284 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2285 | return NULL; |
| 2286 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2287 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2288 | 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] | 2289 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2290 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2291 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2292 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2293 | } |
| 2294 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2295 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2296 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2297 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2298 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2299 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2300 | } |
| 2301 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2302 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2303 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2304 | * @phba: Pointer to HBA context object. |
| 2305 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2306 | * |
| 2307 | * This function is called with hbalock. This function gives back |
| 2308 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2309 | * post the buffer, it will free the buffer. |
| 2310 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2311 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2312 | 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] | 2313 | { |
| 2314 | uint32_t hbqno; |
| 2315 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2316 | if (hbq_buffer) { |
| 2317 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2318 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2319 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2320 | } |
| 2321 | } |
| 2322 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2323 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2324 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2325 | * @mbxCommand: mailbox command code. |
| 2326 | * |
| 2327 | * This function is called by the mailbox event handler function to verify |
| 2328 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2329 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2330 | * and the mailbox event handler will take the HBA offline. |
| 2331 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2332 | static int |
| 2333 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2334 | { |
| 2335 | uint8_t ret; |
| 2336 | |
| 2337 | switch (mbxCommand) { |
| 2338 | case MBX_LOAD_SM: |
| 2339 | case MBX_READ_NV: |
| 2340 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2341 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2342 | case MBX_RUN_BIU_DIAG: |
| 2343 | case MBX_INIT_LINK: |
| 2344 | case MBX_DOWN_LINK: |
| 2345 | case MBX_CONFIG_LINK: |
| 2346 | case MBX_CONFIG_RING: |
| 2347 | case MBX_RESET_RING: |
| 2348 | case MBX_READ_CONFIG: |
| 2349 | case MBX_READ_RCONFIG: |
| 2350 | case MBX_READ_SPARM: |
| 2351 | case MBX_READ_STATUS: |
| 2352 | case MBX_READ_RPI: |
| 2353 | case MBX_READ_XRI: |
| 2354 | case MBX_READ_REV: |
| 2355 | case MBX_READ_LNK_STAT: |
| 2356 | case MBX_REG_LOGIN: |
| 2357 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2358 | case MBX_CLEAR_LA: |
| 2359 | case MBX_DUMP_MEMORY: |
| 2360 | case MBX_DUMP_CONTEXT: |
| 2361 | case MBX_RUN_DIAGS: |
| 2362 | case MBX_RESTART: |
| 2363 | case MBX_UPDATE_CFG: |
| 2364 | case MBX_DOWN_LOAD: |
| 2365 | case MBX_DEL_LD_ENTRY: |
| 2366 | case MBX_RUN_PROGRAM: |
| 2367 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2368 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2370 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2372 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2373 | case MBX_LOAD_AREA: |
| 2374 | case MBX_RUN_BIU_DIAG64: |
| 2375 | case MBX_CONFIG_PORT: |
| 2376 | case MBX_READ_SPARM64: |
| 2377 | case MBX_READ_RPI64: |
| 2378 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2379 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2380 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2381 | case MBX_SET_DEBUG: |
| 2382 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2383 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2384 | case MBX_REG_VPI: |
| 2385 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2386 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2387 | case MBX_PORT_CAPABILITIES: |
| 2388 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2389 | case MBX_SLI4_CONFIG: |
| 2390 | case MBX_SLI4_REQ_FTRS: |
| 2391 | case MBX_REG_FCFI: |
| 2392 | case MBX_UNREG_FCFI: |
| 2393 | case MBX_REG_VFI: |
| 2394 | case MBX_UNREG_VFI: |
| 2395 | case MBX_INIT_VPI: |
| 2396 | case MBX_INIT_VFI: |
| 2397 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2398 | case MBX_READ_EVENT_LOG_STATUS: |
| 2399 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2400 | case MBX_SECURITY_MGMT: |
| 2401 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2402 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2403 | ret = mbxCommand; |
| 2404 | break; |
| 2405 | default: |
| 2406 | ret = MBX_SHUTDOWN; |
| 2407 | break; |
| 2408 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2409 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2410 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2411 | |
| 2412 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2413 | * 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] | 2414 | * @phba: Pointer to HBA context object. |
| 2415 | * @pmboxq: Pointer to mailbox command. |
| 2416 | * |
| 2417 | * This is completion handler function for mailbox commands issued from |
| 2418 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2419 | * mailbox event handler function with no lock held. This function |
| 2420 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2421 | * of the mailbox. |
| 2422 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2423 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2424 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2426 | unsigned long drvr_flag; |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2427 | struct completion *pmbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2428 | |
| 2429 | /* |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2430 | * If pmbox_done is empty, the driver thread gave up waiting and |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2431 | * continued running. |
| 2432 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2433 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2434 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 2435 | pmbox_done = (struct completion *)pmboxq->context3; |
| 2436 | if (pmbox_done) |
| 2437 | complete(pmbox_done); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2438 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | return; |
| 2440 | } |
| 2441 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2442 | |
| 2443 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2444 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2445 | * @phba: Pointer to HBA context object. |
| 2446 | * @pmb: Pointer to mailbox object. |
| 2447 | * |
| 2448 | * This function is the default mailbox completion handler. It |
| 2449 | * frees the memory resources associated with the completed mailbox |
| 2450 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2451 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2452 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2453 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2454 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2456 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2457 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2458 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2459 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2460 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2461 | int rc; |
| 2462 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2463 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2464 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2465 | if (mp) { |
| 2466 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2467 | kfree(mp); |
| 2468 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2469 | |
| 2470 | /* |
| 2471 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2472 | * is in re-discovery driver need to cleanup the RPI. |
| 2473 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2474 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2475 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2476 | !pmb->u.mb.mbxStatus) { |
| 2477 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2478 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2479 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2480 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2481 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2482 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2483 | if (rc != MBX_NOT_FINISHED) |
| 2484 | return; |
| 2485 | } |
| 2486 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2487 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2488 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2489 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2490 | shost = lpfc_shost_from_vport(vport); |
| 2491 | spin_lock_irq(shost->host_lock); |
| 2492 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2493 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2494 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2495 | } |
| 2496 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2497 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2498 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2499 | lpfc_nlp_put(ndlp); |
| 2500 | pmb->context2 = NULL; |
| 2501 | } |
| 2502 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2503 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2504 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2505 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2506 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2507 | "2860 SLI authentication is required " |
| 2508 | "for INIT_LINK but has not done yet\n"); |
| 2509 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2510 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2511 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2512 | else |
| 2513 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2514 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2515 | /** |
| 2516 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2517 | * @phba: Pointer to HBA context object. |
| 2518 | * @pmb: Pointer to mailbox object. |
| 2519 | * |
| 2520 | * This function is the unreg rpi mailbox completion handler. It |
| 2521 | * frees the memory resources associated with the completed mailbox |
| 2522 | * command. An additional refrenece is put on the ndlp to prevent |
| 2523 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2524 | * the unreg mailbox command completes, this routine puts the |
| 2525 | * reference back. |
| 2526 | * |
| 2527 | **/ |
| 2528 | void |
| 2529 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2530 | { |
| 2531 | struct lpfc_vport *vport = pmb->vport; |
| 2532 | struct lpfc_nodelist *ndlp; |
| 2533 | |
| 2534 | ndlp = pmb->context1; |
| 2535 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2536 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2537 | (bf_get(lpfc_sli_intf_if_type, |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2538 | &phba->sli4_hba.sli_intf) >= |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2539 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2540 | if (ndlp) { |
| 2541 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 2542 | "0010 UNREG_LOGIN vpi:%x " |
| 2543 | "rpi:%x DID:%x map:%x %p\n", |
| 2544 | vport->vpi, ndlp->nlp_rpi, |
| 2545 | ndlp->nlp_DID, |
| 2546 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2547 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2548 | lpfc_nlp_put(ndlp); |
| 2549 | } |
| 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2554 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2555 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2556 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2557 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2558 | * @phba: Pointer to HBA context object. |
| 2559 | * |
| 2560 | * This function is called with no lock held. This function processes all |
| 2561 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2562 | * service routine processes mailbox completion interrupt and adds completed |
| 2563 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2564 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2565 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2566 | * function returns the mailbox commands to the upper layer by calling the |
| 2567 | * completion handler function of each mailbox. |
| 2568 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2570 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2571 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2572 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2573 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2574 | int rc; |
| 2575 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2576 | |
| 2577 | phba->sli.slistat.mbox_event++; |
| 2578 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2579 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2580 | spin_lock_irq(&phba->hbalock); |
| 2581 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2582 | spin_unlock_irq(&phba->hbalock); |
| 2583 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2584 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2585 | do { |
| 2586 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2587 | if (pmb == NULL) |
| 2588 | break; |
| 2589 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2590 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2591 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2592 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2593 | if (pmb->vport) { |
| 2594 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2595 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2596 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2597 | (uint32_t)pmbox->mbxCommand, |
| 2598 | pmbox->un.varWords[0], |
| 2599 | pmbox->un.varWords[1]); |
| 2600 | } |
| 2601 | else { |
| 2602 | lpfc_debugfs_disc_trc(phba->pport, |
| 2603 | LPFC_DISC_TRC_MBOX, |
| 2604 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2605 | (uint32_t)pmbox->mbxCommand, |
| 2606 | pmbox->un.varWords[0], |
| 2607 | pmbox->un.varWords[1]); |
| 2608 | } |
| 2609 | } |
| 2610 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2611 | /* |
| 2612 | * It is a fatal error if unknown mbox command completion. |
| 2613 | */ |
| 2614 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2615 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2616 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2617 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2618 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2619 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2620 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2621 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2622 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2623 | pmb), |
| 2624 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2625 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2626 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2627 | phba->work_hs = HS_FFER3; |
| 2628 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2629 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2630 | } |
| 2631 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2632 | if (pmbox->mbxStatus) { |
| 2633 | phba->sli.slistat.mbox_stat_err++; |
| 2634 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2635 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2636 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2637 | LOG_MBOX | LOG_SLI, |
| 2638 | "(%d):0305 Mbox cmd cmpl " |
| 2639 | "error - RETRYing Data: x%x " |
| 2640 | "(x%x/x%x) x%x x%x x%x\n", |
| 2641 | pmb->vport ? pmb->vport->vpi : 0, |
| 2642 | pmbox->mbxCommand, |
| 2643 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2644 | pmb), |
| 2645 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2646 | pmb), |
| 2647 | pmbox->mbxStatus, |
| 2648 | pmbox->un.varWords[0], |
| 2649 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2650 | pmbox->mbxStatus = 0; |
| 2651 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2652 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2653 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2654 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2655 | } |
| 2656 | } |
| 2657 | |
| 2658 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2659 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2660 | "(%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] | 2661 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2662 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2663 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2664 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2665 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2666 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2667 | pmb->mbox_cmpl, |
| 2668 | *((uint32_t *) pmbox), |
| 2669 | pmbox->un.varWords[0], |
| 2670 | pmbox->un.varWords[1], |
| 2671 | pmbox->un.varWords[2], |
| 2672 | pmbox->un.varWords[3], |
| 2673 | pmbox->un.varWords[4], |
| 2674 | pmbox->un.varWords[5], |
| 2675 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2676 | pmbox->un.varWords[7], |
| 2677 | pmbox->un.varWords[8], |
| 2678 | pmbox->un.varWords[9], |
| 2679 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2680 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2681 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2683 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2684 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2685 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2686 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2687 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2688 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2689 | * @phba: Pointer to HBA context object. |
| 2690 | * @pring: Pointer to driver SLI ring object. |
| 2691 | * @tag: buffer tag. |
| 2692 | * |
| 2693 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2694 | * is set in the tag the buffer is posted for a particular exchange, |
| 2695 | * the function will return the buffer without replacing the buffer. |
| 2696 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2697 | * returns the buffer and also posts another buffer to the firmware. |
| 2698 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2699 | static struct lpfc_dmabuf * |
| 2700 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2701 | struct lpfc_sli_ring *pring, |
| 2702 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2703 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2704 | struct hbq_dmabuf *hbq_entry; |
| 2705 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2706 | if (tag & QUE_BUFTAG_BIT) |
| 2707 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2708 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2709 | if (!hbq_entry) |
| 2710 | return NULL; |
| 2711 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2712 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2713 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2714 | /** |
| 2715 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2716 | * @phba: Pointer to HBA context object. |
| 2717 | * @pring: Pointer to driver SLI ring object. |
| 2718 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2719 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2720 | * @fch_type: the type for the first frame of the sequence. |
| 2721 | * |
| 2722 | * This function is called with no lock held. This function uses the r_ctl and |
| 2723 | * type of the received sequence to find the correct callback function to call |
| 2724 | * to process the sequence. |
| 2725 | **/ |
| 2726 | static int |
| 2727 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2728 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2729 | uint32_t fch_type) |
| 2730 | { |
| 2731 | int i; |
| 2732 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2733 | switch (fch_type) { |
| 2734 | case FC_TYPE_NVME: |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2735 | lpfc_nvmet_unsol_ls_event(phba, pring, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2736 | return 1; |
| 2737 | default: |
| 2738 | break; |
| 2739 | } |
| 2740 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2741 | /* unSolicited Responses */ |
| 2742 | if (pring->prt[0].profile) { |
| 2743 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2744 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2745 | saveq); |
| 2746 | return 1; |
| 2747 | } |
| 2748 | /* We must search, based on rctl / type |
| 2749 | for the right routine */ |
| 2750 | for (i = 0; i < pring->num_mask; i++) { |
| 2751 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2752 | (pring->prt[i].type == fch_type)) { |
| 2753 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2754 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2755 | (phba, pring, saveq); |
| 2756 | return 1; |
| 2757 | } |
| 2758 | } |
| 2759 | return 0; |
| 2760 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2761 | |
| 2762 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2763 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2764 | * @phba: Pointer to HBA context object. |
| 2765 | * @pring: Pointer to driver SLI ring object. |
| 2766 | * @saveq: Pointer to the unsolicited iocb. |
| 2767 | * |
| 2768 | * This function is called with no lock held by the ring event handler |
| 2769 | * when there is an unsolicited iocb posted to the response ring by the |
| 2770 | * firmware. This function gets the buffer associated with the iocbs |
| 2771 | * and calls the event handler for the ring. This function handles both |
| 2772 | * qring buffers and hbq buffers. |
| 2773 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2774 | * upper layer functions will free the iocb objects. |
| 2775 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2776 | static int |
| 2777 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2778 | struct lpfc_iocbq *saveq) |
| 2779 | { |
| 2780 | IOCB_t * irsp; |
| 2781 | WORD5 * w5p; |
| 2782 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2783 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2784 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2785 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2786 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2787 | |
| 2788 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2789 | if (pring->lpfc_sli_rcv_async_status) |
| 2790 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2791 | else |
| 2792 | lpfc_printf_log(phba, |
| 2793 | KERN_WARNING, |
| 2794 | LOG_SLI, |
| 2795 | "0316 Ring %d handler: unexpected " |
| 2796 | "ASYNC_STATUS iocb received evt_code " |
| 2797 | "0x%x\n", |
| 2798 | pring->ringno, |
| 2799 | irsp->un.asyncstat.evt_code); |
| 2800 | return 1; |
| 2801 | } |
| 2802 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2803 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2804 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2805 | if (irsp->ulpBdeCount > 0) { |
| 2806 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2807 | irsp->un.ulpWord[3]); |
| 2808 | lpfc_in_buf_free(phba, dmzbuf); |
| 2809 | } |
| 2810 | |
| 2811 | if (irsp->ulpBdeCount > 1) { |
| 2812 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2813 | irsp->unsli3.sli3Words[3]); |
| 2814 | lpfc_in_buf_free(phba, dmzbuf); |
| 2815 | } |
| 2816 | |
| 2817 | if (irsp->ulpBdeCount > 2) { |
| 2818 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2819 | irsp->unsli3.sli3Words[7]); |
| 2820 | lpfc_in_buf_free(phba, dmzbuf); |
| 2821 | } |
| 2822 | |
| 2823 | return 1; |
| 2824 | } |
| 2825 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2826 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2827 | if (irsp->ulpBdeCount != 0) { |
| 2828 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2829 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2830 | if (!saveq->context2) |
| 2831 | lpfc_printf_log(phba, |
| 2832 | KERN_ERR, |
| 2833 | LOG_SLI, |
| 2834 | "0341 Ring %d Cannot find buffer for " |
| 2835 | "an unsolicited iocb. tag 0x%x\n", |
| 2836 | pring->ringno, |
| 2837 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2838 | } |
| 2839 | if (irsp->ulpBdeCount == 2) { |
| 2840 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2841 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2842 | if (!saveq->context3) |
| 2843 | lpfc_printf_log(phba, |
| 2844 | KERN_ERR, |
| 2845 | LOG_SLI, |
| 2846 | "0342 Ring %d Cannot find buffer for an" |
| 2847 | " unsolicited iocb. tag 0x%x\n", |
| 2848 | pring->ringno, |
| 2849 | irsp->unsli3.sli3Words[7]); |
| 2850 | } |
| 2851 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2852 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2853 | if (irsp->ulpBdeCount != 0) { |
| 2854 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2855 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2856 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2857 | lpfc_printf_log(phba, |
| 2858 | KERN_ERR, |
| 2859 | LOG_SLI, |
| 2860 | "0343 Ring %d Cannot find " |
| 2861 | "buffer for an unsolicited iocb" |
| 2862 | ". tag 0x%x\n", pring->ringno, |
| 2863 | irsp->un.ulpWord[3]); |
| 2864 | } |
| 2865 | if (irsp->ulpBdeCount == 2) { |
| 2866 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2867 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2868 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2869 | lpfc_printf_log(phba, |
| 2870 | KERN_ERR, |
| 2871 | LOG_SLI, |
| 2872 | "0344 Ring %d Cannot find " |
| 2873 | "buffer for an unsolicited " |
| 2874 | "iocb. tag 0x%x\n", |
| 2875 | pring->ringno, |
| 2876 | irsp->unsli3.sli3Words[7]); |
| 2877 | } |
| 2878 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2879 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2880 | if (irsp->ulpBdeCount != 0 && |
| 2881 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2882 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2883 | int found = 0; |
| 2884 | |
| 2885 | /* search continue save q for same XRI */ |
| 2886 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2887 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2888 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2889 | list_add_tail(&saveq->list, &iocbq->list); |
| 2890 | found = 1; |
| 2891 | break; |
| 2892 | } |
| 2893 | } |
| 2894 | if (!found) |
| 2895 | list_add_tail(&saveq->clist, |
| 2896 | &pring->iocb_continue_saveq); |
| 2897 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2898 | list_del_init(&iocbq->clist); |
| 2899 | saveq = iocbq; |
| 2900 | irsp = &(saveq->iocb); |
| 2901 | } else |
| 2902 | return 0; |
| 2903 | } |
| 2904 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2905 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2906 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2907 | Rctl = FC_RCTL_ELS_REQ; |
| 2908 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2909 | } else { |
| 2910 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2911 | Rctl = w5p->hcsw.Rctl; |
| 2912 | Type = w5p->hcsw.Type; |
| 2913 | |
| 2914 | /* Firmware Workaround */ |
| 2915 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2916 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2917 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2918 | Rctl = FC_RCTL_ELS_REQ; |
| 2919 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2920 | w5p->hcsw.Rctl = Rctl; |
| 2921 | w5p->hcsw.Type = Type; |
| 2922 | } |
| 2923 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2924 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2925 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2926 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2927 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2928 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2929 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2930 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2931 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2932 | } |
| 2933 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2934 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2935 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2936 | * @phba: Pointer to HBA context object. |
| 2937 | * @pring: Pointer to driver SLI ring object. |
| 2938 | * @prspiocb: Pointer to response iocb object. |
| 2939 | * |
| 2940 | * This function looks up the iocb_lookup table to get the command iocb |
| 2941 | * corresponding to the given response iocb using the iotag of the |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 2942 | * response iocb. This function is called with the hbalock held |
| 2943 | * for sli3 devices or the ring_lock for sli4 devices. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2944 | * This function returns the command iocb object if it finds the command |
| 2945 | * iocb else returns NULL. |
| 2946 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2947 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2948 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2949 | struct lpfc_sli_ring *pring, |
| 2950 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2951 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2952 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2953 | uint16_t iotag; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2954 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2955 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2956 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2957 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2958 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2959 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2960 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2961 | /* remove from txcmpl queue list */ |
| 2962 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2963 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2964 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2965 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2966 | } |
| 2967 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2968 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2969 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2970 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2971 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2972 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2973 | return NULL; |
| 2974 | } |
| 2975 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2976 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2977 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2978 | * @phba: Pointer to HBA context object. |
| 2979 | * @pring: Pointer to driver SLI ring object. |
| 2980 | * @iotag: IOCB tag. |
| 2981 | * |
| 2982 | * This function looks up the iocb_lookup table to get the command iocb |
| 2983 | * corresponding to the given iotag. This function is called with the |
| 2984 | * hbalock held. |
| 2985 | * This function returns the command iocb object if it finds the command |
| 2986 | * iocb else returns NULL. |
| 2987 | **/ |
| 2988 | static struct lpfc_iocbq * |
| 2989 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2990 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2991 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2992 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2993 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2994 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2995 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2996 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2997 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2998 | /* remove from txcmpl queue list */ |
| 2999 | list_del_init(&cmd_iocb->list); |
| 3000 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3001 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 3002 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3003 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 3004 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3005 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3006 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 3007 | "iocb_flag x%x\n", |
| 3008 | iotag, phba->sli.last_iotag, |
| 3009 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3010 | return NULL; |
| 3011 | } |
| 3012 | |
| 3013 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3014 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3015 | * @phba: Pointer to HBA context object. |
| 3016 | * @pring: Pointer to driver SLI ring object. |
| 3017 | * @saveq: Pointer to the response iocb to be processed. |
| 3018 | * |
| 3019 | * This function is called by the ring event handler for non-fcp |
| 3020 | * rings when there is a new response iocb in the response ring. |
| 3021 | * The caller is not required to hold any locks. This function |
| 3022 | * gets the command iocb associated with the response iocb and |
| 3023 | * calls the completion handler for the command iocb. If there |
| 3024 | * is no completion handler, the function will free the resources |
| 3025 | * associated with command iocb. If the response iocb is for |
| 3026 | * an already aborted command iocb, the status of the completion |
| 3027 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 3028 | * This function always returns 1. |
| 3029 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3030 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3031 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3032 | struct lpfc_iocbq *saveq) |
| 3033 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3034 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3035 | int rc = 1; |
| 3036 | unsigned long iflag; |
| 3037 | |
| 3038 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 3039 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3040 | spin_lock_irqsave(&pring->ring_lock, iflag); |
| 3041 | else |
| 3042 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3043 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 3044 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3045 | spin_unlock_irqrestore(&pring->ring_lock, iflag); |
| 3046 | else |
| 3047 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3048 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3049 | if (cmdiocbp) { |
| 3050 | if (cmdiocbp->iocb_cmpl) { |
| 3051 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 3052 | * If an ELS command failed send an event to mgmt |
| 3053 | * application. |
| 3054 | */ |
| 3055 | if (saveq->iocb.ulpStatus && |
| 3056 | (pring->ringno == LPFC_ELS_RING) && |
| 3057 | (cmdiocbp->iocb.ulpCommand == |
| 3058 | CMD_ELS_REQUEST64_CR)) |
| 3059 | lpfc_send_els_failure_event(phba, |
| 3060 | cmdiocbp, saveq); |
| 3061 | |
| 3062 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3063 | * Post all ELS completions to the worker thread. |
| 3064 | * All other are passed to the completion callback. |
| 3065 | */ |
| 3066 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3067 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3068 | (cmdiocbp->iocb_flag & |
| 3069 | LPFC_DRIVER_ABORTED)) { |
| 3070 | spin_lock_irqsave(&phba->hbalock, |
| 3071 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3072 | cmdiocbp->iocb_flag &= |
| 3073 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3074 | spin_unlock_irqrestore(&phba->hbalock, |
| 3075 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3076 | saveq->iocb.ulpStatus = |
| 3077 | IOSTAT_LOCAL_REJECT; |
| 3078 | saveq->iocb.un.ulpWord[4] = |
| 3079 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3080 | |
| 3081 | /* Firmware could still be in progress |
| 3082 | * of DMAing payload, so don't free data |
| 3083 | * buffer till after a hbeat. |
| 3084 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3085 | spin_lock_irqsave(&phba->hbalock, |
| 3086 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3087 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 3088 | spin_unlock_irqrestore(&phba->hbalock, |
| 3089 | iflag); |
| 3090 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3091 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3092 | if (saveq->iocb_flag & |
| 3093 | LPFC_EXCHANGE_BUSY) { |
| 3094 | /* Set cmdiocb flag for the |
| 3095 | * exchange busy so sgl (xri) |
| 3096 | * will not be released until |
| 3097 | * the abort xri is received |
| 3098 | * from hba. |
| 3099 | */ |
| 3100 | spin_lock_irqsave( |
| 3101 | &phba->hbalock, iflag); |
| 3102 | cmdiocbp->iocb_flag |= |
| 3103 | LPFC_EXCHANGE_BUSY; |
| 3104 | spin_unlock_irqrestore( |
| 3105 | &phba->hbalock, iflag); |
| 3106 | } |
| 3107 | if (cmdiocbp->iocb_flag & |
| 3108 | LPFC_DRIVER_ABORTED) { |
| 3109 | /* |
| 3110 | * Clear LPFC_DRIVER_ABORTED |
| 3111 | * bit in case it was driver |
| 3112 | * initiated abort. |
| 3113 | */ |
| 3114 | spin_lock_irqsave( |
| 3115 | &phba->hbalock, iflag); |
| 3116 | cmdiocbp->iocb_flag &= |
| 3117 | ~LPFC_DRIVER_ABORTED; |
| 3118 | spin_unlock_irqrestore( |
| 3119 | &phba->hbalock, iflag); |
| 3120 | cmdiocbp->iocb.ulpStatus = |
| 3121 | IOSTAT_LOCAL_REJECT; |
| 3122 | cmdiocbp->iocb.un.ulpWord[4] = |
| 3123 | IOERR_ABORT_REQUESTED; |
| 3124 | /* |
| 3125 | * For SLI4, irsiocb contains |
| 3126 | * NO_XRI in sli_xritag, it |
| 3127 | * shall not affect releasing |
| 3128 | * sgl (xri) process. |
| 3129 | */ |
| 3130 | saveq->iocb.ulpStatus = |
| 3131 | IOSTAT_LOCAL_REJECT; |
| 3132 | saveq->iocb.un.ulpWord[4] = |
| 3133 | IOERR_SLI_ABORTED; |
| 3134 | spin_lock_irqsave( |
| 3135 | &phba->hbalock, iflag); |
| 3136 | saveq->iocb_flag |= |
| 3137 | LPFC_DELAY_MEM_FREE; |
| 3138 | spin_unlock_irqrestore( |
| 3139 | &phba->hbalock, iflag); |
| 3140 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3141 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3142 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3143 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3144 | } else |
| 3145 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3146 | } else { |
| 3147 | /* |
| 3148 | * Unknown initiating command based on the response iotag. |
| 3149 | * This could be the case on the ELS ring because of |
| 3150 | * lpfc_els_abort(). |
| 3151 | */ |
| 3152 | if (pring->ringno != LPFC_ELS_RING) { |
| 3153 | /* |
| 3154 | * Ring <ringno> handler: unexpected completion IoTag |
| 3155 | * <IoTag> |
| 3156 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3157 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3158 | "0322 Ring %d handler: " |
| 3159 | "unexpected completion IoTag x%x " |
| 3160 | "Data: x%x x%x x%x x%x\n", |
| 3161 | pring->ringno, |
| 3162 | saveq->iocb.ulpIoTag, |
| 3163 | saveq->iocb.ulpStatus, |
| 3164 | saveq->iocb.un.ulpWord[4], |
| 3165 | saveq->iocb.ulpCommand, |
| 3166 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3167 | } |
| 3168 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 3169 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3170 | return rc; |
| 3171 | } |
| 3172 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3173 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3174 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3175 | * @phba: Pointer to HBA context object. |
| 3176 | * @pring: Pointer to driver SLI ring object. |
| 3177 | * |
| 3178 | * This function is called from the iocb ring event handlers when |
| 3179 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 3180 | * an error attention condition to the worker thread and the worker |
| 3181 | * thread will transition the HBA to offline state. |
| 3182 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3183 | static void |
| 3184 | 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] | 3185 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3186 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3187 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3188 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3189 | * rsp ring <portRspMax> |
| 3190 | */ |
| 3191 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3192 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3193 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3194 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3195 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3196 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3197 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3198 | |
| 3199 | /* |
| 3200 | * All error attention handlers are posted to |
| 3201 | * worker thread |
| 3202 | */ |
| 3203 | phba->work_ha |= HA_ERATT; |
| 3204 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3205 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3206 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3207 | |
| 3208 | return; |
| 3209 | } |
| 3210 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3211 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3212 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3213 | * @ptr: Pointer to address of HBA context object. |
| 3214 | * |
| 3215 | * This function is invoked by the Error Attention polling timer when the |
| 3216 | * timer times out. It will check the SLI Error Attention register for |
| 3217 | * possible attention events. If so, it will post an Error Attention event |
| 3218 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3219 | * Error Attention polling timer for the next poll. |
| 3220 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3221 | void lpfc_poll_eratt(struct timer_list *t) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3222 | { |
| 3223 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3224 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3225 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3226 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3227 | phba = from_timer(phba, t, eratt_poll); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3228 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3229 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3230 | sli_intr = phba->sli.slistat.sli_intr; |
| 3231 | |
| 3232 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3233 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3234 | sli_intr); |
| 3235 | else |
| 3236 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3237 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3238 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3239 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3240 | phba->sli.slistat.sli_ips = cnt; |
| 3241 | |
| 3242 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3243 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3244 | /* Check chip HA register for error event */ |
| 3245 | eratt = lpfc_sli_check_eratt(phba); |
| 3246 | |
| 3247 | if (eratt) |
| 3248 | /* Tell the worker thread there is work to do */ |
| 3249 | lpfc_worker_wake_up(phba); |
| 3250 | else |
| 3251 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3252 | mod_timer(&phba->eratt_poll, |
| 3253 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3254 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3255 | return; |
| 3256 | } |
| 3257 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3258 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3259 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3260 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3261 | * @phba: Pointer to HBA context object. |
| 3262 | * @pring: Pointer to driver SLI ring object. |
| 3263 | * @mask: Host attention register mask for this ring. |
| 3264 | * |
| 3265 | * This function is called from the interrupt context when there is a ring |
| 3266 | * event for the fcp ring. The caller does not hold any lock. |
| 3267 | * 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] | 3268 | * 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] | 3269 | * LE bit set. The function will call the completion handler of the command iocb |
| 3270 | * if the response iocb indicates a completion for a command iocb or it is |
| 3271 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3272 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3274 | * to check it explicitly. |
| 3275 | */ |
| 3276 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3277 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3278 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3279 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3280 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3281 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3282 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3283 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3284 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3285 | uint32_t status; |
| 3286 | uint32_t portRspPut, portRspMax; |
| 3287 | int rc = 1; |
| 3288 | lpfc_iocb_type type; |
| 3289 | unsigned long iflag; |
| 3290 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3291 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3292 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3293 | pring->stats.iocb_event++; |
| 3294 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3295 | /* |
| 3296 | * The next available response entry should never exceed the maximum |
| 3297 | * entries. If it does, treat it as an adapter hardware error. |
| 3298 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3299 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3300 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3301 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3302 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3303 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | return 1; |
| 3305 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3306 | if (phba->fcp_ring_in_use) { |
| 3307 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3308 | return 1; |
| 3309 | } else |
| 3310 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3311 | |
| 3312 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3313 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3314 | /* |
| 3315 | * Fetch an entry off the ring and copy it into a local data |
| 3316 | * structure. The copy involves a byte-swap since the |
| 3317 | * network byte order and pci byte orders are different. |
| 3318 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3319 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3320 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3321 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3322 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3323 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3324 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3325 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3326 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3327 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3328 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3329 | irsp = &rspiocbq.iocb; |
| 3330 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3331 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3332 | pring->stats.iocb_rsp++; |
| 3333 | rsp_cmpl++; |
| 3334 | |
| 3335 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3336 | /* |
| 3337 | * If resource errors reported from HBA, reduce |
| 3338 | * queuedepths of the SCSI device. |
| 3339 | */ |
| 3340 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3341 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3342 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3343 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3344 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3345 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3346 | } |
| 3347 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3348 | /* Rsp ring <ringno> error: IOCB */ |
| 3349 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3350 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3351 | "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] | 3352 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3353 | irsp->un.ulpWord[0], |
| 3354 | irsp->un.ulpWord[1], |
| 3355 | irsp->un.ulpWord[2], |
| 3356 | irsp->un.ulpWord[3], |
| 3357 | irsp->un.ulpWord[4], |
| 3358 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3359 | *(uint32_t *)&irsp->un1, |
| 3360 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | switch (type) { |
| 3364 | case LPFC_ABORT_IOCB: |
| 3365 | case LPFC_SOL_IOCB: |
| 3366 | /* |
| 3367 | * Idle exchange closed via ABTS from port. No iocb |
| 3368 | * resources need to be recovered. |
| 3369 | */ |
| 3370 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3371 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3372 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3373 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3374 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3375 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3376 | break; |
| 3377 | } |
| 3378 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3379 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3380 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3381 | if (unlikely(!cmdiocbq)) |
| 3382 | break; |
| 3383 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3384 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3385 | if (cmdiocbq->iocb_cmpl) { |
| 3386 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3387 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3388 | &rspiocbq); |
| 3389 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3390 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3391 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3392 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3393 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3394 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3395 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3396 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | default: |
| 3398 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3399 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3400 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3401 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3402 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3403 | dev_warn(&((phba->pcidev)->dev), |
| 3404 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3405 | phba->brd_no, adaptermsg); |
| 3406 | } else { |
| 3407 | /* Unknown IOCB command */ |
| 3408 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3409 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3410 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3411 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3412 | irsp->ulpStatus, |
| 3413 | irsp->ulpIoTag, |
| 3414 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | } |
| 3416 | break; |
| 3417 | } |
| 3418 | |
| 3419 | /* |
| 3420 | * The response IOCB has been processed. Update the ring |
| 3421 | * pointer in SLIM. If the port response put pointer has not |
| 3422 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3423 | * response put pointer. |
| 3424 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3425 | writel(pring->sli.sli3.rspidx, |
| 3426 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3427 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3428 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3429 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3430 | } |
| 3431 | |
| 3432 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3433 | pring->stats.iocb_rsp_full++; |
| 3434 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3435 | writel(status, phba->CAregaddr); |
| 3436 | readl(phba->CAregaddr); |
| 3437 | } |
| 3438 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3439 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3440 | pring->stats.iocb_cmd_empty++; |
| 3441 | |
| 3442 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3443 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3444 | lpfc_sli_resume_iocb(phba, pring); |
| 3445 | |
| 3446 | if ((pring->lpfc_sli_cmd_available)) |
| 3447 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3448 | |
| 3449 | } |
| 3450 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3451 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3452 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | return rc; |
| 3454 | } |
| 3455 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3456 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3457 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3458 | * @phba: Pointer to HBA context object. |
| 3459 | * @pring: Pointer to driver SLI ring object. |
| 3460 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3461 | * |
| 3462 | * This function is called from the worker thread when there is a slow-path |
| 3463 | * response IOCB to process. This function chains all the response iocbs until |
| 3464 | * seeing the iocb with the LE bit set. The function will call |
| 3465 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3466 | * completion of a command iocb. The function will call the |
| 3467 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3468 | * The function frees the resources or calls the completion handler if this |
| 3469 | * iocb is an abort completion. The function returns NULL when the response |
| 3470 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3471 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3472 | * response iocb passed in. |
| 3473 | **/ |
| 3474 | static struct lpfc_iocbq * |
| 3475 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3476 | struct lpfc_iocbq *rspiocbp) |
| 3477 | { |
| 3478 | struct lpfc_iocbq *saveq; |
| 3479 | struct lpfc_iocbq *cmdiocbp; |
| 3480 | struct lpfc_iocbq *next_iocb; |
| 3481 | IOCB_t *irsp = NULL; |
| 3482 | uint32_t free_saveq; |
| 3483 | uint8_t iocb_cmd_type; |
| 3484 | lpfc_iocb_type type; |
| 3485 | unsigned long iflag; |
| 3486 | int rc; |
| 3487 | |
| 3488 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3489 | /* First add the response iocb to the countinueq list */ |
| 3490 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3491 | pring->iocb_continueq_cnt++; |
| 3492 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3493 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3494 | irsp = &rspiocbp->iocb; |
| 3495 | if (irsp->ulpLe) { |
| 3496 | /* |
| 3497 | * By default, the driver expects to free all resources |
| 3498 | * associated with this iocb completion. |
| 3499 | */ |
| 3500 | free_saveq = 1; |
| 3501 | saveq = list_get_first(&pring->iocb_continueq, |
| 3502 | struct lpfc_iocbq, list); |
| 3503 | irsp = &(saveq->iocb); |
| 3504 | list_del_init(&pring->iocb_continueq); |
| 3505 | pring->iocb_continueq_cnt = 0; |
| 3506 | |
| 3507 | pring->stats.iocb_rsp++; |
| 3508 | |
| 3509 | /* |
| 3510 | * If resource errors reported from HBA, reduce |
| 3511 | * queuedepths of the SCSI device. |
| 3512 | */ |
| 3513 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3514 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3515 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3516 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3517 | phba->lpfc_rampdown_queue_depth(phba); |
| 3518 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3519 | } |
| 3520 | |
| 3521 | if (irsp->ulpStatus) { |
| 3522 | /* Rsp ring <ringno> error: IOCB */ |
| 3523 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3524 | "0328 Rsp Ring %d error: " |
| 3525 | "IOCB Data: " |
| 3526 | "x%x x%x x%x x%x " |
| 3527 | "x%x x%x x%x x%x " |
| 3528 | "x%x x%x x%x x%x " |
| 3529 | "x%x x%x x%x x%x\n", |
| 3530 | pring->ringno, |
| 3531 | irsp->un.ulpWord[0], |
| 3532 | irsp->un.ulpWord[1], |
| 3533 | irsp->un.ulpWord[2], |
| 3534 | irsp->un.ulpWord[3], |
| 3535 | irsp->un.ulpWord[4], |
| 3536 | irsp->un.ulpWord[5], |
| 3537 | *(((uint32_t *) irsp) + 6), |
| 3538 | *(((uint32_t *) irsp) + 7), |
| 3539 | *(((uint32_t *) irsp) + 8), |
| 3540 | *(((uint32_t *) irsp) + 9), |
| 3541 | *(((uint32_t *) irsp) + 10), |
| 3542 | *(((uint32_t *) irsp) + 11), |
| 3543 | *(((uint32_t *) irsp) + 12), |
| 3544 | *(((uint32_t *) irsp) + 13), |
| 3545 | *(((uint32_t *) irsp) + 14), |
| 3546 | *(((uint32_t *) irsp) + 15)); |
| 3547 | } |
| 3548 | |
| 3549 | /* |
| 3550 | * Fetch the IOCB command type and call the correct completion |
| 3551 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3552 | * get freed back to the lpfc_iocb_list by the discovery |
| 3553 | * kernel thread. |
| 3554 | */ |
| 3555 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3556 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3557 | switch (type) { |
| 3558 | case LPFC_SOL_IOCB: |
| 3559 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3560 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3561 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3562 | break; |
| 3563 | |
| 3564 | case LPFC_UNSOL_IOCB: |
| 3565 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3566 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3567 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3568 | if (!rc) |
| 3569 | free_saveq = 0; |
| 3570 | break; |
| 3571 | |
| 3572 | case LPFC_ABORT_IOCB: |
| 3573 | cmdiocbp = NULL; |
| 3574 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3575 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3576 | saveq); |
| 3577 | if (cmdiocbp) { |
| 3578 | /* Call the specified completion routine */ |
| 3579 | if (cmdiocbp->iocb_cmpl) { |
| 3580 | spin_unlock_irqrestore(&phba->hbalock, |
| 3581 | iflag); |
| 3582 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3583 | saveq); |
| 3584 | spin_lock_irqsave(&phba->hbalock, |
| 3585 | iflag); |
| 3586 | } else |
| 3587 | __lpfc_sli_release_iocbq(phba, |
| 3588 | cmdiocbp); |
| 3589 | } |
| 3590 | break; |
| 3591 | |
| 3592 | case LPFC_UNKNOWN_IOCB: |
| 3593 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3594 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3595 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3596 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3597 | MAX_MSG_DATA); |
| 3598 | dev_warn(&((phba->pcidev)->dev), |
| 3599 | "lpfc%d: %s\n", |
| 3600 | phba->brd_no, adaptermsg); |
| 3601 | } else { |
| 3602 | /* Unknown IOCB command */ |
| 3603 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3604 | "0335 Unknown IOCB " |
| 3605 | "command Data: x%x " |
| 3606 | "x%x x%x x%x\n", |
| 3607 | irsp->ulpCommand, |
| 3608 | irsp->ulpStatus, |
| 3609 | irsp->ulpIoTag, |
| 3610 | irsp->ulpContext); |
| 3611 | } |
| 3612 | break; |
| 3613 | } |
| 3614 | |
| 3615 | if (free_saveq) { |
| 3616 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3617 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3618 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3619 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3620 | } |
| 3621 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3622 | } |
| 3623 | rspiocbp = NULL; |
| 3624 | } |
| 3625 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3626 | return rspiocbp; |
| 3627 | } |
| 3628 | |
| 3629 | /** |
| 3630 | * 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] | 3631 | * @phba: Pointer to HBA context object. |
| 3632 | * @pring: Pointer to driver SLI ring object. |
| 3633 | * @mask: Host attention register mask for this ring. |
| 3634 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3635 | * This routine wraps the actual slow_ring event process routine from the |
| 3636 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3637 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3638 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3639 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3640 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3641 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3642 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3643 | } |
| 3644 | |
| 3645 | /** |
| 3646 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3647 | * @phba: Pointer to HBA context object. |
| 3648 | * @pring: Pointer to driver SLI ring object. |
| 3649 | * @mask: Host attention register mask for this ring. |
| 3650 | * |
| 3651 | * This function is called from the worker thread when there is a ring event |
| 3652 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3653 | * remove each response iocb in the response ring and calls the handle |
| 3654 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3655 | **/ |
| 3656 | static void |
| 3657 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3658 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3659 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3660 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3661 | IOCB_t *entry; |
| 3662 | IOCB_t *irsp = NULL; |
| 3663 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3664 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3665 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3666 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3667 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3668 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3669 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3670 | pring->stats.iocb_event++; |
| 3671 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3672 | /* |
| 3673 | * The next available response entry should never exceed the maximum |
| 3674 | * entries. If it does, treat it as an adapter hardware error. |
| 3675 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3676 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3677 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3678 | if (portRspPut >= portRspMax) { |
| 3679 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3680 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3681 | * rsp ring <portRspMax> |
| 3682 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3683 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3684 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3685 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3686 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3687 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3688 | phba->link_state = LPFC_HBA_ERROR; |
| 3689 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3690 | |
| 3691 | phba->work_hs = HS_FFER3; |
| 3692 | lpfc_handle_eratt(phba); |
| 3693 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3694 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3698 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3699 | /* |
| 3700 | * Build a completion list and call the appropriate handler. |
| 3701 | * The process is to get the next available response iocb, get |
| 3702 | * a free iocb from the list, copy the response data into the |
| 3703 | * free iocb, insert to the continuation list, and update the |
| 3704 | * next response index to slim. This process makes response |
| 3705 | * iocb's in the ring available to DMA as fast as possible but |
| 3706 | * pays a penalty for a copy operation. Since the iocb is |
| 3707 | * only 32 bytes, this penalty is considered small relative to |
| 3708 | * the PCI reads for register values and a slim write. When |
| 3709 | * the ulpLe field is set, the entire Command has been |
| 3710 | * received. |
| 3711 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3712 | entry = lpfc_resp_iocb(phba, pring); |
| 3713 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3714 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3715 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3716 | if (rspiocbp == NULL) { |
| 3717 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3718 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3719 | break; |
| 3720 | } |
| 3721 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3722 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3723 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3724 | irsp = &rspiocbp->iocb; |
| 3725 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3726 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3727 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3728 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3729 | if (pring->ringno == LPFC_ELS_RING) { |
| 3730 | lpfc_debugfs_slow_ring_trc(phba, |
| 3731 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3732 | *(((uint32_t *) irsp) + 4), |
| 3733 | *(((uint32_t *) irsp) + 6), |
| 3734 | *(((uint32_t *) irsp) + 7)); |
| 3735 | } |
| 3736 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3737 | writel(pring->sli.sli3.rspidx, |
| 3738 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3739 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3740 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3741 | /* Handle the response IOCB */ |
| 3742 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3743 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3744 | |
| 3745 | /* |
| 3746 | * If the port response put pointer has not been updated, sync |
| 3747 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3748 | * response put pointer. |
| 3749 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3750 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3751 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3752 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3753 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3754 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3755 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3756 | /* At least one response entry has been freed */ |
| 3757 | pring->stats.iocb_rsp_full++; |
| 3758 | /* SET RxRE_RSP in Chip Att register */ |
| 3759 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3760 | writel(status, phba->CAregaddr); |
| 3761 | readl(phba->CAregaddr); /* flush */ |
| 3762 | } |
| 3763 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3764 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3765 | pring->stats.iocb_cmd_empty++; |
| 3766 | |
| 3767 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3768 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3769 | lpfc_sli_resume_iocb(phba, pring); |
| 3770 | |
| 3771 | if ((pring->lpfc_sli_cmd_available)) |
| 3772 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3773 | |
| 3774 | } |
| 3775 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3776 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3777 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3778 | } |
| 3779 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3780 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3781 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3782 | * @phba: Pointer to HBA context object. |
| 3783 | * @pring: Pointer to driver SLI ring object. |
| 3784 | * @mask: Host attention register mask for this ring. |
| 3785 | * |
| 3786 | * This function is called from the worker thread when there is a pending |
| 3787 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3788 | * queue. The caller does not hold any lock. The function will remove each |
| 3789 | * response iocb from the response worker queue and calls the handle |
| 3790 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3791 | **/ |
| 3792 | static void |
| 3793 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3794 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3795 | { |
| 3796 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3797 | struct hbq_dmabuf *dmabuf; |
| 3798 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3799 | unsigned long iflag; |
| 3800 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3801 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3802 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3803 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3804 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3805 | /* Get the response iocb from the head of work queue */ |
| 3806 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3807 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3808 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3809 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3810 | |
| 3811 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3812 | case CQE_CODE_COMPL_WQE: |
| 3813 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3814 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3815 | /* Translate ELS WCQE to response IOCBQ */ |
| 3816 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3817 | irspiocbq); |
| 3818 | if (irspiocbq) |
| 3819 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3820 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3821 | break; |
| 3822 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3823 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3824 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3825 | cq_event); |
| 3826 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3827 | break; |
| 3828 | default: |
| 3829 | break; |
| 3830 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3831 | } |
| 3832 | } |
| 3833 | |
| 3834 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3835 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3836 | * @phba: Pointer to HBA context object. |
| 3837 | * @pring: Pointer to driver SLI ring object. |
| 3838 | * |
| 3839 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3840 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3841 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3842 | * the return of this function. The caller is not required to hold any locks. |
| 3843 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3844 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3845 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3846 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3847 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3848 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3849 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3850 | if (pring->ringno == LPFC_ELS_RING) { |
| 3851 | lpfc_fabric_abort_hba(phba); |
| 3852 | } |
| 3853 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3854 | /* Error everything on txq and txcmplq |
| 3855 | * First do the txq. |
| 3856 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3857 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3858 | spin_lock_irq(&pring->ring_lock); |
| 3859 | list_splice_init(&pring->txq, &completions); |
| 3860 | pring->txq_cnt = 0; |
| 3861 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3862 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3863 | spin_lock_irq(&phba->hbalock); |
| 3864 | /* Next issue ABTS for everything on the txcmplq */ |
| 3865 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3866 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3867 | spin_unlock_irq(&phba->hbalock); |
| 3868 | } else { |
| 3869 | spin_lock_irq(&phba->hbalock); |
| 3870 | list_splice_init(&pring->txq, &completions); |
| 3871 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3872 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3873 | /* Next issue ABTS for everything on the txcmplq */ |
| 3874 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3875 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3876 | spin_unlock_irq(&phba->hbalock); |
| 3877 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3878 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3879 | /* Cancel all the IOCBs from the completions list */ |
| 3880 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3881 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3882 | } |
| 3883 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3884 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3885 | * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring |
| 3886 | * @phba: Pointer to HBA context object. |
| 3887 | * @pring: Pointer to driver SLI ring object. |
| 3888 | * |
| 3889 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3890 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3891 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3892 | * the return of this function. The caller is not required to hold any locks. |
| 3893 | **/ |
| 3894 | void |
| 3895 | lpfc_sli_abort_wqe_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3896 | { |
| 3897 | LIST_HEAD(completions); |
| 3898 | struct lpfc_iocbq *iocb, *next_iocb; |
| 3899 | |
| 3900 | if (pring->ringno == LPFC_ELS_RING) |
| 3901 | lpfc_fabric_abort_hba(phba); |
| 3902 | |
| 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_sli4_abort_nvme_io(phba, pring, iocb); |
| 3907 | spin_unlock_irq(&phba->hbalock); |
| 3908 | } |
| 3909 | |
| 3910 | |
| 3911 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3912 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3913 | * @phba: Pointer to HBA context object. |
| 3914 | * @pring: Pointer to driver SLI ring object. |
| 3915 | * |
| 3916 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 3917 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3918 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3919 | * the return of this function. The caller is not required to hold any locks. |
| 3920 | **/ |
| 3921 | void |
| 3922 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 3923 | { |
| 3924 | struct lpfc_sli *psli = &phba->sli; |
| 3925 | struct lpfc_sli_ring *pring; |
| 3926 | uint32_t i; |
| 3927 | |
| 3928 | /* Look on all the FCP Rings for the iotag */ |
| 3929 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3930 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3931 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3932 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3933 | } |
| 3934 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3935 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3936 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3937 | } |
| 3938 | } |
| 3939 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3940 | /** |
| 3941 | * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings |
| 3942 | * @phba: Pointer to HBA context object. |
| 3943 | * |
| 3944 | * This function aborts all wqes in NVME rings. This function issues an |
| 3945 | * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in |
| 3946 | * the txcmplq is not guaranteed to complete before the return of this |
| 3947 | * function. The caller is not required to hold any locks. |
| 3948 | **/ |
| 3949 | void |
| 3950 | lpfc_sli_abort_nvme_rings(struct lpfc_hba *phba) |
| 3951 | { |
| 3952 | struct lpfc_sli_ring *pring; |
| 3953 | uint32_t i; |
| 3954 | |
| 3955 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3956 | return; |
| 3957 | |
| 3958 | /* Abort all IO on each NVME ring. */ |
| 3959 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 3960 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 3961 | lpfc_sli_abort_wqe_ring(phba, pring); |
| 3962 | } |
| 3963 | } |
| 3964 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3965 | |
| 3966 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3967 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3968 | * @phba: Pointer to HBA context object. |
| 3969 | * |
| 3970 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3971 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3972 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3973 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3974 | * slot has been permanently disabled. |
| 3975 | **/ |
| 3976 | void |
| 3977 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3978 | { |
| 3979 | LIST_HEAD(txq); |
| 3980 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3981 | struct lpfc_sli *psli = &phba->sli; |
| 3982 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3983 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 3984 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3985 | |
| 3986 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3987 | /* Indicate the I/O queues are flushed */ |
| 3988 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3989 | spin_unlock_irq(&phba->hbalock); |
| 3990 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3991 | /* Look on all the FCP Rings for the iotag */ |
| 3992 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3993 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3994 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3995 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3996 | spin_lock_irq(&pring->ring_lock); |
| 3997 | /* Retrieve everything on txq */ |
| 3998 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 3999 | list_for_each_entry_safe(piocb, next_iocb, |
| 4000 | &pring->txcmplq, list) |
| 4001 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4002 | /* Retrieve everything on the txcmplq */ |
| 4003 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4004 | pring->txq_cnt = 0; |
| 4005 | pring->txcmplq_cnt = 0; |
| 4006 | spin_unlock_irq(&pring->ring_lock); |
| 4007 | |
| 4008 | /* Flush the txq */ |
| 4009 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 4010 | IOSTAT_LOCAL_REJECT, |
| 4011 | IOERR_SLI_DOWN); |
| 4012 | /* Flush the txcmpq */ |
| 4013 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4014 | IOSTAT_LOCAL_REJECT, |
| 4015 | IOERR_SLI_DOWN); |
| 4016 | } |
| 4017 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4018 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4019 | |
| 4020 | spin_lock_irq(&phba->hbalock); |
| 4021 | /* Retrieve everything on txq */ |
| 4022 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4023 | list_for_each_entry_safe(piocb, next_iocb, |
| 4024 | &pring->txcmplq, list) |
| 4025 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 4026 | /* Retrieve everything on the txcmplq */ |
| 4027 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4028 | pring->txq_cnt = 0; |
| 4029 | pring->txcmplq_cnt = 0; |
| 4030 | spin_unlock_irq(&phba->hbalock); |
| 4031 | |
| 4032 | /* Flush the txq */ |
| 4033 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 4034 | IOERR_SLI_DOWN); |
| 4035 | /* Flush the txcmpq */ |
| 4036 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 4037 | IOERR_SLI_DOWN); |
| 4038 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4042 | * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings |
| 4043 | * @phba: Pointer to HBA context object. |
| 4044 | * |
| 4045 | * This function flushes all wqes in the nvme rings and frees all resources |
| 4046 | * in the txcmplq. This function does not issue abort wqes for the IO |
| 4047 | * commands in txcmplq, they will just be returned with |
| 4048 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 4049 | * slot has been permanently disabled. |
| 4050 | **/ |
| 4051 | void |
| 4052 | lpfc_sli_flush_nvme_rings(struct lpfc_hba *phba) |
| 4053 | { |
| 4054 | LIST_HEAD(txcmplq); |
| 4055 | struct lpfc_sli_ring *pring; |
| 4056 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4057 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4058 | |
| 4059 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4060 | return; |
| 4061 | |
| 4062 | /* Hint to other driver operations that a flush is in progress. */ |
| 4063 | spin_lock_irq(&phba->hbalock); |
| 4064 | phba->hba_flag |= HBA_NVME_IOQ_FLUSH; |
| 4065 | spin_unlock_irq(&phba->hbalock); |
| 4066 | |
| 4067 | /* Cycle through all NVME rings and complete each IO with |
| 4068 | * a local driver reason code. This is a flush so no |
| 4069 | * abort exchange to FW. |
| 4070 | */ |
| 4071 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 4072 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 4073 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4074 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 4075 | list_for_each_entry_safe(piocb, next_iocb, |
| 4076 | &pring->txcmplq, list) |
| 4077 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
| 4078 | /* Retrieve everything on the txcmplq */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4079 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 4080 | pring->txcmplq_cnt = 0; |
| 4081 | spin_unlock_irq(&pring->ring_lock); |
| 4082 | |
| 4083 | /* Flush the txcmpq &&&PAE */ |
| 4084 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 4085 | IOSTAT_LOCAL_REJECT, |
| 4086 | IOERR_SLI_DOWN); |
| 4087 | } |
| 4088 | } |
| 4089 | |
| 4090 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4091 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4092 | * @phba: Pointer to HBA context object. |
| 4093 | * @mask: Bit mask to be checked. |
| 4094 | * |
| 4095 | * This function reads the host status register and compares |
| 4096 | * with the provided bit mask to check if HBA completed |
| 4097 | * the restart. This function will wait in a loop for the |
| 4098 | * HBA to complete restart. If the HBA does not restart within |
| 4099 | * 15 iterations, the function will reset the HBA again. The |
| 4100 | * function returns 1 when HBA fail to restart otherwise returns |
| 4101 | * zero. |
| 4102 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4103 | static int |
| 4104 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4105 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4106 | uint32_t status; |
| 4107 | int i = 0; |
| 4108 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4109 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4110 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4111 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4112 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4113 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4114 | /* |
| 4115 | * Check status register every 100ms for 5 retries, then every |
| 4116 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 4117 | * every 2.5 sec for 4. |
| 4118 | * Break our of the loop if errors occurred during init. |
| 4119 | */ |
| 4120 | while (((status & mask) != mask) && |
| 4121 | !(status & HS_FFERM) && |
| 4122 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4123 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4124 | if (i <= 5) |
| 4125 | msleep(10); |
| 4126 | else if (i <= 10) |
| 4127 | msleep(500); |
| 4128 | else |
| 4129 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4130 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4131 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4132 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4133 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4134 | lpfc_sli_brdrestart(phba); |
| 4135 | } |
| 4136 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4137 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 4138 | retval = 1; |
| 4139 | break; |
| 4140 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4141 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4142 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4143 | /* Check to see if any errors occurred during init */ |
| 4144 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4145 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4146 | "2751 Adapter failed to restart, " |
| 4147 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 4148 | status, |
| 4149 | readl(phba->MBslimaddr + 0xa8), |
| 4150 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4151 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4152 | retval = 1; |
| 4153 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4154 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4155 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4156 | } |
| 4157 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4158 | /** |
| 4159 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 4160 | * @phba: Pointer to HBA context object. |
| 4161 | * @mask: Bit mask to be checked. |
| 4162 | * |
| 4163 | * This function checks the host status register to check if HBA is |
| 4164 | * ready. This function will wait in a loop for the HBA to be ready |
| 4165 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 4166 | * function again. The function returns 1 when HBA fail to be ready |
| 4167 | * otherwise returns zero. |
| 4168 | **/ |
| 4169 | static int |
| 4170 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 4171 | { |
| 4172 | uint32_t status; |
| 4173 | int retval = 0; |
| 4174 | |
| 4175 | /* Read the HBA Host Status Register */ |
| 4176 | status = lpfc_sli4_post_status_check(phba); |
| 4177 | |
| 4178 | if (status) { |
| 4179 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 4180 | lpfc_sli_brdrestart(phba); |
| 4181 | status = lpfc_sli4_post_status_check(phba); |
| 4182 | } |
| 4183 | |
| 4184 | /* Check to see if any errors occurred during init */ |
| 4185 | if (status) { |
| 4186 | phba->link_state = LPFC_HBA_ERROR; |
| 4187 | retval = 1; |
| 4188 | } else |
| 4189 | phba->sli4_hba.intr_enable = 0; |
| 4190 | |
| 4191 | return retval; |
| 4192 | } |
| 4193 | |
| 4194 | /** |
| 4195 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 4196 | * @phba: Pointer to HBA context object. |
| 4197 | * @mask: Bit mask to be checked. |
| 4198 | * |
| 4199 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 4200 | * from the API jump table function pointer from the lpfc_hba struct. |
| 4201 | **/ |
| 4202 | int |
| 4203 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 4204 | { |
| 4205 | return phba->lpfc_sli_brdready(phba, mask); |
| 4206 | } |
| 4207 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4208 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 4209 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4210 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4211 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4212 | * @phba: Pointer to HBA context object. |
| 4213 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4214 | * This function is called before resetting an HBA. This function is called |
| 4215 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4216 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4217 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4218 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4219 | uint32_t __iomem *resp_buf; |
| 4220 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4221 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4222 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4223 | int i; |
| 4224 | uint8_t hdrtype; |
| 4225 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4226 | lockdep_assert_held(&phba->hbalock); |
| 4227 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4228 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4229 | if (hdrtype != 0x80 || |
| 4230 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4231 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4232 | return; |
| 4233 | |
| 4234 | /* |
| 4235 | * Tell the other part of the chip to suspend temporarily all |
| 4236 | * its DMA activity. |
| 4237 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4238 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4239 | |
| 4240 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4241 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4242 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4243 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4244 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4245 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4246 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4247 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4248 | return; |
| 4249 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4250 | /* Clear Chip error bit */ |
| 4251 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4252 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | mbox = 0; |
| 4256 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4257 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4258 | |
| 4259 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4260 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4261 | writel(mbox, mbox_buf); |
| 4262 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4263 | for (i = 0; i < 50; i++) { |
| 4264 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4265 | return; |
| 4266 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4267 | mdelay(1); |
| 4268 | else |
| 4269 | break; |
| 4270 | } |
| 4271 | resp_data = 0; |
| 4272 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4273 | return; |
| 4274 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4275 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4276 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4277 | goto restore_hc; |
| 4278 | else |
| 4279 | goto clear_errat; |
| 4280 | } |
| 4281 | |
| 4282 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4283 | resp_data = 0; |
| 4284 | for (i = 0; i < 500; i++) { |
| 4285 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4286 | return; |
| 4287 | if (resp_data != mbox) |
| 4288 | mdelay(1); |
| 4289 | else |
| 4290 | break; |
| 4291 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4292 | |
| 4293 | clear_errat: |
| 4294 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4295 | while (++i < 500) { |
| 4296 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4297 | return; |
| 4298 | if (!(ha_copy & HA_ERATT)) |
| 4299 | mdelay(1); |
| 4300 | else |
| 4301 | break; |
| 4302 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4303 | |
| 4304 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4305 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4306 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4307 | } |
| 4308 | |
| 4309 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4310 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4311 | writel(hc_copy, phba->HCregaddr); |
| 4312 | readl(phba->HCregaddr); /* flush */ |
| 4313 | } |
| 4314 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4315 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4316 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4317 | * @phba: Pointer to HBA context object. |
| 4318 | * |
| 4319 | * This function issues a kill_board mailbox command and waits for |
| 4320 | * the error attention interrupt. This function is called for stopping |
| 4321 | * the firmware processing. The caller is not required to hold any |
| 4322 | * locks. This function calls lpfc_hba_down_post function to free |
| 4323 | * any pending commands after the kill. The function will return 1 when it |
| 4324 | * fails to kill the board else will return 0. |
| 4325 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4326 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4327 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4328 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4329 | struct lpfc_sli *psli; |
| 4330 | LPFC_MBOXQ_t *pmb; |
| 4331 | uint32_t status; |
| 4332 | uint32_t ha_copy; |
| 4333 | int retval; |
| 4334 | int i = 0; |
| 4335 | |
| 4336 | psli = &phba->sli; |
| 4337 | |
| 4338 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4339 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4340 | "0329 Kill HBA Data: x%x x%x\n", |
| 4341 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4342 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4343 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4344 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4345 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4346 | |
| 4347 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4348 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4349 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4350 | spin_unlock_irq(&phba->hbalock); |
| 4351 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4352 | return 1; |
| 4353 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4354 | status &= ~HC_ERINT_ENA; |
| 4355 | writel(status, phba->HCregaddr); |
| 4356 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4357 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4358 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4359 | |
| 4360 | lpfc_kill_board(phba, pmb); |
| 4361 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4362 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4363 | |
| 4364 | if (retval != MBX_SUCCESS) { |
| 4365 | if (retval != MBX_BUSY) |
| 4366 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4367 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4368 | "2752 KILL_BOARD command failed retval %d\n", |
| 4369 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4370 | spin_lock_irq(&phba->hbalock); |
| 4371 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4372 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4373 | return 1; |
| 4374 | } |
| 4375 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4376 | spin_lock_irq(&phba->hbalock); |
| 4377 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4378 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4379 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4380 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4381 | |
| 4382 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4383 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4384 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4385 | * board is now undefined. |
| 4386 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4387 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4388 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4389 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4390 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4391 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4392 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4396 | if (ha_copy & HA_ERATT) { |
| 4397 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4398 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4399 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4400 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4401 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4402 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4403 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4404 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4405 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4406 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4407 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4408 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4409 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4410 | } |
| 4411 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4412 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4413 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4414 | * @phba: Pointer to HBA context object. |
| 4415 | * |
| 4416 | * This function resets the HBA by writing HC_INITFF to the control |
| 4417 | * register. After the HBA resets, this function resets all the iocb ring |
| 4418 | * indices. This function disables PCI layer parity checking during |
| 4419 | * the reset. |
| 4420 | * This function returns 0 always. |
| 4421 | * The caller is not required to hold any locks. |
| 4422 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4423 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4424 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4425 | { |
| 4426 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4427 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4428 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4429 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4430 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4431 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4432 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4433 | /* Reset HBA */ |
| 4434 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4435 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4436 | (phba->pport) ? phba->pport->port_state : 0, |
| 4437 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4438 | |
| 4439 | /* perform board reset */ |
| 4440 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4441 | phba->link_events = 0; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4442 | if (phba->pport) { |
| 4443 | phba->pport->fc_myDID = 0; |
| 4444 | phba->pport->fc_prevDID = 0; |
| 4445 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4446 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4447 | /* Turn off parity checking and serr during the physical reset */ |
| 4448 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4449 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4450 | (cfg_value & |
| 4451 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4452 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4453 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4454 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4455 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4456 | writel(HC_INITFF, phba->HCregaddr); |
| 4457 | mdelay(1); |
| 4458 | readl(phba->HCregaddr); /* flush */ |
| 4459 | writel(0, phba->HCregaddr); |
| 4460 | readl(phba->HCregaddr); /* flush */ |
| 4461 | |
| 4462 | /* Restore PCI cmd register */ |
| 4463 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4464 | |
| 4465 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4466 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4467 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4468 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4469 | pring->sli.sli3.rspidx = 0; |
| 4470 | pring->sli.sli3.next_cmdidx = 0; |
| 4471 | pring->sli.sli3.local_getidx = 0; |
| 4472 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4473 | pring->missbufcnt = 0; |
| 4474 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4475 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4476 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4477 | return 0; |
| 4478 | } |
| 4479 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4480 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4481 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4482 | * @phba: Pointer to HBA context object. |
| 4483 | * |
| 4484 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4485 | * checking during resets the device. The caller is not required to hold |
| 4486 | * any locks. |
| 4487 | * |
| 4488 | * This function returns 0 always. |
| 4489 | **/ |
| 4490 | int |
| 4491 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4492 | { |
| 4493 | struct lpfc_sli *psli = &phba->sli; |
| 4494 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4495 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4496 | |
| 4497 | /* Reset HBA */ |
| 4498 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4499 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4500 | phba->pport->port_state, psli->sli_flag, |
| 4501 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4502 | |
| 4503 | /* perform board reset */ |
| 4504 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4505 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4506 | phba->pport->fc_myDID = 0; |
| 4507 | phba->pport->fc_prevDID = 0; |
| 4508 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4509 | spin_lock_irq(&phba->hbalock); |
| 4510 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4511 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4512 | spin_unlock_irq(&phba->hbalock); |
| 4513 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4514 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4515 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4516 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4517 | return rc; |
| 4518 | } |
| 4519 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4520 | /* Now physically reset the device */ |
| 4521 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4522 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4523 | |
| 4524 | /* Turn off parity checking and serr during the physical reset */ |
| 4525 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4526 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4527 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4528 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4529 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4530 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4531 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4532 | /* Restore PCI cmd register */ |
| 4533 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4534 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4535 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | /** |
| 4539 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4540 | * @phba: Pointer to HBA context object. |
| 4541 | * |
| 4542 | * This function is called in the SLI initialization code path to |
| 4543 | * restart the HBA. The caller is not required to hold any lock. |
| 4544 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4545 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4546 | * function to free any pending commands. The function enables |
| 4547 | * POST only during the first initialization. The function returns zero. |
| 4548 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4549 | * command before the return of this function. |
| 4550 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4551 | static int |
| 4552 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4553 | { |
| 4554 | MAILBOX_t *mb; |
| 4555 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4556 | volatile uint32_t word0; |
| 4557 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4558 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4559 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4560 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4561 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4562 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4563 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4564 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4565 | psli = &phba->sli; |
| 4566 | |
| 4567 | /* Restart HBA */ |
| 4568 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4569 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4570 | (phba->pport) ? phba->pport->port_state : 0, |
| 4571 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4572 | |
| 4573 | word0 = 0; |
| 4574 | mb = (MAILBOX_t *) &word0; |
| 4575 | mb->mbxCommand = MBX_RESTART; |
| 4576 | mb->mbxHc = 1; |
| 4577 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4578 | lpfc_reset_barrier(phba); |
| 4579 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4580 | to_slim = phba->MBslimaddr; |
| 4581 | writel(*(uint32_t *) mb, to_slim); |
| 4582 | readl(to_slim); /* flush */ |
| 4583 | |
| 4584 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4585 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4586 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4587 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4588 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4589 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4590 | writel(*(uint32_t *) mb, to_slim); |
| 4591 | readl(to_slim); /* flush */ |
| 4592 | |
| 4593 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4594 | if (phba->pport) |
| 4595 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4596 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4597 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4598 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4599 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4600 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4601 | psli->stats_start = ktime_get_seconds(); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4602 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4603 | /* Give the INITFF and Post time to settle. */ |
| 4604 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4605 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4606 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4607 | if (hba_aer_enabled) |
| 4608 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4609 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4610 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4611 | |
| 4612 | return 0; |
| 4613 | } |
| 4614 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4615 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4616 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4617 | * @phba: Pointer to HBA context object. |
| 4618 | * |
| 4619 | * This function is called in the SLI initialization code path to restart |
| 4620 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4621 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4622 | * free any pending commands. |
| 4623 | **/ |
| 4624 | static int |
| 4625 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4626 | { |
| 4627 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4628 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4629 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4630 | |
| 4631 | /* Restart HBA */ |
| 4632 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4633 | "0296 Restart HBA Data: x%x x%x\n", |
| 4634 | phba->pport->port_state, psli->sli_flag); |
| 4635 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4636 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4637 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4638 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4639 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4640 | |
| 4641 | spin_lock_irq(&phba->hbalock); |
| 4642 | phba->pport->stopped = 0; |
| 4643 | phba->link_state = LPFC_INIT_START; |
| 4644 | phba->hba_flag = 0; |
| 4645 | spin_unlock_irq(&phba->hbalock); |
| 4646 | |
| 4647 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
Arnd Bergmann | c4d6204d | 2018-06-18 17:28:23 +0200 | [diff] [blame] | 4648 | psli->stats_start = ktime_get_seconds(); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4649 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4650 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4651 | if (hba_aer_enabled) |
| 4652 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4653 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4654 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4655 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4656 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4657 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | /** |
| 4661 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4662 | * @phba: Pointer to HBA context object. |
| 4663 | * |
| 4664 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4665 | * API jump table function pointer from the lpfc_hba struct. |
| 4666 | **/ |
| 4667 | int |
| 4668 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4669 | { |
| 4670 | return phba->lpfc_sli_brdrestart(phba); |
| 4671 | } |
| 4672 | |
| 4673 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4674 | * 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] | 4675 | * @phba: Pointer to HBA context object. |
| 4676 | * |
| 4677 | * This function is called after a HBA restart to wait for successful |
| 4678 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4679 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4680 | * iteration, the function will restart the HBA again. The function returns |
| 4681 | * zero if HBA successfully restarted else returns negative error code. |
| 4682 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4683 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4684 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4685 | { |
| 4686 | uint32_t status, i = 0; |
| 4687 | |
| 4688 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4689 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4690 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4691 | |
| 4692 | /* Check status register to see what current state is */ |
| 4693 | i = 0; |
| 4694 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4695 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4696 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4697 | * retries, then every 1 sec for 50 retires for a total of |
| 4698 | * ~60 seconds before reset the board again and check every |
| 4699 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4700 | * board ready is required by the Falcon FIPS zeroization |
| 4701 | * complete, and any reset the board in between shall cause |
| 4702 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4703 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4704 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4705 | /* Adapter failed to init, timeout, status reg |
| 4706 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4707 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4708 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4709 | "timeout, status reg x%x, " |
| 4710 | "FW Data: A8 x%x AC x%x\n", status, |
| 4711 | readl(phba->MBslimaddr + 0xa8), |
| 4712 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4713 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4714 | return -ETIMEDOUT; |
| 4715 | } |
| 4716 | |
| 4717 | /* Check to see if any errors occurred during init */ |
| 4718 | if (status & HS_FFERM) { |
| 4719 | /* ERROR: During chipset initialization */ |
| 4720 | /* Adapter failed to init, chipset, status reg |
| 4721 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4722 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4723 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4724 | "chipset, status reg x%x, " |
| 4725 | "FW Data: A8 x%x AC x%x\n", status, |
| 4726 | readl(phba->MBslimaddr + 0xa8), |
| 4727 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4728 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4729 | return -EIO; |
| 4730 | } |
| 4731 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4732 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4733 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4734 | else if (i <= 100) |
| 4735 | msleep(100); |
| 4736 | else |
| 4737 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4738 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4739 | if (i == 150) { |
| 4740 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4741 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4742 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4743 | } |
| 4744 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4745 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4746 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | /* Check to see if any errors occurred during init */ |
| 4750 | if (status & HS_FFERM) { |
| 4751 | /* ERROR: During chipset initialization */ |
| 4752 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4753 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4754 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4755 | "status reg x%x, " |
| 4756 | "FW Data: A8 x%x AC x%x\n", status, |
| 4757 | readl(phba->MBslimaddr + 0xa8), |
| 4758 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4759 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4760 | return -EIO; |
| 4761 | } |
| 4762 | |
| 4763 | /* Clear all interrupt enable conditions */ |
| 4764 | writel(0, phba->HCregaddr); |
| 4765 | readl(phba->HCregaddr); /* flush */ |
| 4766 | |
| 4767 | /* setup host attn register */ |
| 4768 | writel(0xffffffff, phba->HAregaddr); |
| 4769 | readl(phba->HAregaddr); /* flush */ |
| 4770 | return 0; |
| 4771 | } |
| 4772 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4773 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4774 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4775 | * |
| 4776 | * This function calculates and returns the number of HBQs required to be |
| 4777 | * configured. |
| 4778 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4779 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4780 | lpfc_sli_hbq_count(void) |
| 4781 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4782 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4783 | } |
| 4784 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4785 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4786 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4787 | * |
| 4788 | * This function adds the number of hbq entries in every HBQ to get |
| 4789 | * the total number of hbq entries required for the HBA and returns |
| 4790 | * the total count. |
| 4791 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4792 | static int |
| 4793 | lpfc_sli_hbq_entry_count(void) |
| 4794 | { |
| 4795 | int hbq_count = lpfc_sli_hbq_count(); |
| 4796 | int count = 0; |
| 4797 | int i; |
| 4798 | |
| 4799 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4800 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4801 | return count; |
| 4802 | } |
| 4803 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4804 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4805 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4806 | * |
| 4807 | * This function calculates amount of memory required for all hbq entries |
| 4808 | * to be configured and returns the total memory required. |
| 4809 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4810 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4811 | lpfc_sli_hbq_size(void) |
| 4812 | { |
| 4813 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4814 | } |
| 4815 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4816 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4817 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4818 | * @phba: Pointer to HBA context object. |
| 4819 | * |
| 4820 | * This function is called during the SLI initialization to configure |
| 4821 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4822 | * required to hold any locks. This function will return zero if successful |
| 4823 | * else it will return negative error code. |
| 4824 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4825 | static int |
| 4826 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4827 | { |
| 4828 | int hbq_count = lpfc_sli_hbq_count(); |
| 4829 | LPFC_MBOXQ_t *pmb; |
| 4830 | MAILBOX_t *pmbox; |
| 4831 | uint32_t hbqno; |
| 4832 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4833 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4834 | /* Get a Mailbox buffer to setup mailbox |
| 4835 | * commands for HBA initialization |
| 4836 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4837 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4838 | |
| 4839 | if (!pmb) |
| 4840 | return -ENOMEM; |
| 4841 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4842 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4843 | |
| 4844 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4845 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4846 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4847 | |
| 4848 | hbq_entry_index = 0; |
| 4849 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4850 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4851 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4852 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4853 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4854 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4855 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4856 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4857 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4858 | |
| 4859 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4860 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4861 | mbxStatus <status>, ring <num> */ |
| 4862 | |
| 4863 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4864 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4865 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4866 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4867 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4868 | pmbox->mbxStatus, hbqno); |
| 4869 | |
| 4870 | phba->link_state = LPFC_HBA_ERROR; |
| 4871 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4872 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4873 | } |
| 4874 | } |
| 4875 | phba->hbq_count = hbq_count; |
| 4876 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4877 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4878 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4879 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4880 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4881 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4882 | return 0; |
| 4883 | } |
| 4884 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4885 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4886 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4887 | * @phba: Pointer to HBA context object. |
| 4888 | * |
| 4889 | * This function is called during the SLI initialization to configure |
| 4890 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4891 | * required to hold any locks. This function will return zero if successful |
| 4892 | * else it will return negative error code. |
| 4893 | **/ |
| 4894 | static int |
| 4895 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4896 | { |
| 4897 | phba->hbq_in_use = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4898 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 4899 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4900 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4901 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4902 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4903 | return 0; |
| 4904 | } |
| 4905 | |
| 4906 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4907 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4908 | * @phba: Pointer to HBA context object. |
| 4909 | * @sli_mode: sli mode - 2/3 |
| 4910 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4911 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4912 | * to issue config_port mailbox command. This function restarts the |
| 4913 | * HBA firmware and issues a config_port mailbox command to configure |
| 4914 | * the SLI interface in the sli mode specified by sli_mode |
| 4915 | * variable. The caller is not required to hold any locks. |
| 4916 | * The function returns 0 if successful, else returns negative error |
| 4917 | * code. |
| 4918 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4919 | int |
| 4920 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4921 | { |
| 4922 | LPFC_MBOXQ_t *pmb; |
| 4923 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4924 | |
| 4925 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4926 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4927 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4928 | return -ENOMEM; |
| 4929 | } |
| 4930 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4931 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4932 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4933 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4934 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4935 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4936 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4937 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4938 | rc = lpfc_sli_chipset_init(phba); |
| 4939 | if (rc) |
| 4940 | break; |
| 4941 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4942 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4943 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4944 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4945 | resetcount++; |
| 4946 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4947 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4948 | * value of 0 means the call was successful. Any other |
| 4949 | * nonzero value is a failure, but if ERESTART is returned, |
| 4950 | * the driver may reset the HBA and try again. |
| 4951 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4952 | rc = lpfc_config_port_prep(phba); |
| 4953 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4954 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4955 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4956 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4957 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4958 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4959 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4960 | lpfc_config_port(phba, pmb); |
| 4961 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4962 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4963 | LPFC_SLI3_HBQ_ENABLED | |
| 4964 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4965 | LPFC_SLI3_BG_ENABLED | |
| 4966 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4967 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4968 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4969 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4970 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4971 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4972 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4973 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4974 | spin_unlock_irq(&phba->hbalock); |
| 4975 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4976 | } else { |
| 4977 | /* Allow asynchronous mailbox command to go through */ |
| 4978 | spin_lock_irq(&phba->hbalock); |
| 4979 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4980 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4981 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4982 | |
| 4983 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4984 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4985 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4986 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4987 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4988 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4989 | if (!done) { |
| 4990 | rc = -EINVAL; |
| 4991 | goto do_prep_failed; |
| 4992 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4993 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4994 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4995 | rc = -ENXIO; |
| 4996 | goto do_prep_failed; |
| 4997 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4998 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4999 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5000 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 5001 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 5002 | phba->max_vpi : phba->max_vports; |
| 5003 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5004 | } else |
| 5005 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5006 | phba->fips_level = 0; |
| 5007 | phba->fips_spec_rev = 0; |
| 5008 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5009 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 5010 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 5011 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 5012 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5013 | "2850 Security Crypto Active. FIPS x%d " |
| 5014 | "(Spec Rev: x%d)", |
| 5015 | phba->fips_level, phba->fips_spec_rev); |
| 5016 | } |
| 5017 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 5018 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5019 | "2856 Config Port Security Crypto " |
| 5020 | "Error: x%x ", |
| 5021 | pmb->u.mb.un.varCfgPort.sec_err); |
| 5022 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5023 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5024 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5025 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5026 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 5027 | |
| 5028 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 5029 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5030 | |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5031 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 5032 | if (pmb->u.mb.un.varCfgPort.gbg == 0) { |
| 5033 | phba->cfg_enable_bg = 0; |
| 5034 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5035 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5036 | "0443 Adapter did not grant " |
| 5037 | "BlockGuard\n"); |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5038 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 5039 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5040 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 5041 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 5042 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 5043 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5044 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5045 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5046 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5047 | return rc; |
| 5048 | } |
| 5049 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5050 | |
| 5051 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5052 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5053 | * @phba: Pointer to HBA context object. |
| 5054 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 5055 | * This function is the main SLI initialization function. This function |
| 5056 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5057 | * error attention handler code. Caller is not required to hold any |
| 5058 | * locks. This function issues config_port mailbox command to configure |
| 5059 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 5060 | * calls the config_port_post function to issue init_link mailbox |
| 5061 | * command and to start the discovery. The function will return zero |
| 5062 | * if successful, else it will return negative error code. |
| 5063 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5064 | int |
| 5065 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 5066 | { |
| 5067 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5068 | int mode = 3, i; |
| 5069 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5070 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5071 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5072 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 5073 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5074 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5075 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5076 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5077 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5078 | break; |
| 5079 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5080 | mode = 2; |
| 5081 | break; |
| 5082 | case 0: |
| 5083 | case 3: |
| 5084 | break; |
| 5085 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5086 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5087 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 5088 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5089 | |
| 5090 | break; |
| 5091 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 5092 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5093 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5094 | rc = lpfc_sli_config_port(phba, mode); |
| 5095 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 5096 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5097 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5098 | "1820 Unable to select SLI-3. " |
| 5099 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5100 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5101 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 5102 | else if (rc && mode == 2) |
| 5103 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5104 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5105 | goto lpfc_sli_hba_setup_error; |
| 5106 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5107 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 5108 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 5109 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 5110 | if (!rc) { |
| 5111 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5112 | "2709 This device supports " |
| 5113 | "Advanced Error Reporting (AER)\n"); |
| 5114 | spin_lock_irq(&phba->hbalock); |
| 5115 | phba->hba_flag |= HBA_AER_ENABLED; |
| 5116 | spin_unlock_irq(&phba->hbalock); |
| 5117 | } else { |
| 5118 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5119 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 5120 | "Advanced Error Reporting (AER): %d\n", |
| 5121 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 5122 | phba->cfg_aer_support = 0; |
| 5123 | } |
| 5124 | } |
| 5125 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5126 | if (phba->sli_rev == 3) { |
| 5127 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 5128 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5129 | } else { |
| 5130 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 5131 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5132 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5133 | } |
| 5134 | |
| 5135 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5136 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 5137 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5138 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5139 | |
| 5140 | if (rc) |
| 5141 | goto lpfc_sli_hba_setup_error; |
| 5142 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5143 | /* Initialize VPIs. */ |
| 5144 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 5145 | /* |
| 5146 | * The VPI bitmask and physical ID array are allocated |
| 5147 | * and initialized once only - at driver load. A port |
| 5148 | * reset doesn't need to reinitialize this memory. |
| 5149 | */ |
| 5150 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 5151 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5152 | phba->vpi_bmask = kcalloc(longs, |
| 5153 | sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5154 | GFP_KERNEL); |
| 5155 | if (!phba->vpi_bmask) { |
| 5156 | rc = -ENOMEM; |
| 5157 | goto lpfc_sli_hba_setup_error; |
| 5158 | } |
| 5159 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5160 | phba->vpi_ids = kcalloc(phba->max_vpi + 1, |
| 5161 | sizeof(uint16_t), |
| 5162 | GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5163 | if (!phba->vpi_ids) { |
| 5164 | kfree(phba->vpi_bmask); |
| 5165 | rc = -ENOMEM; |
| 5166 | goto lpfc_sli_hba_setup_error; |
| 5167 | } |
| 5168 | for (i = 0; i < phba->max_vpi; i++) |
| 5169 | phba->vpi_ids[i] = i; |
| 5170 | } |
| 5171 | } |
| 5172 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 5173 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5174 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 5175 | rc = lpfc_sli_hbq_setup(phba); |
| 5176 | if (rc) |
| 5177 | goto lpfc_sli_hba_setup_error; |
| 5178 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5179 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5180 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 5181 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5182 | |
| 5183 | rc = lpfc_config_port_post(phba); |
| 5184 | if (rc) |
| 5185 | goto lpfc_sli_hba_setup_error; |
| 5186 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 5187 | return rc; |
| 5188 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5189 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 5190 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 5191 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 5192 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5193 | return rc; |
| 5194 | } |
| 5195 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5196 | /** |
| 5197 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 5198 | * @phba: Pointer to HBA context object. |
| 5199 | * @mboxq: mailbox pointer. |
| 5200 | * This function issue a dump mailbox command to read config region |
| 5201 | * 23 and parse the records in the region and populate driver |
| 5202 | * data structure. |
| 5203 | **/ |
| 5204 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5205 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5206 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5207 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5208 | struct lpfc_dmabuf *mp; |
| 5209 | struct lpfc_mqe *mqe; |
| 5210 | uint32_t data_length; |
| 5211 | int rc; |
| 5212 | |
| 5213 | /* Program the default value of vlan_id and fc_map */ |
| 5214 | phba->valid_vlan = 0; |
| 5215 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5216 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5217 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5218 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5219 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5220 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5221 | return -ENOMEM; |
| 5222 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5223 | mqe = &mboxq->u.mqe; |
| 5224 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5225 | rc = -ENOMEM; |
| 5226 | goto out_free_mboxq; |
| 5227 | } |
| 5228 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5229 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 5230 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5231 | |
| 5232 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5233 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5234 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5235 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5236 | "CQ: x%x x%x x%x x%x\n", |
| 5237 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5238 | bf_get(lpfc_mqe_command, mqe), |
| 5239 | bf_get(lpfc_mqe_status, mqe), |
| 5240 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5241 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5242 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5243 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5244 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5245 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5246 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5247 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5248 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5249 | mboxq->mcqe.word0, |
| 5250 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5251 | mboxq->mcqe.trailer); |
| 5252 | |
| 5253 | if (rc) { |
| 5254 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5255 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5256 | rc = -EIO; |
| 5257 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5258 | } |
| 5259 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5260 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5261 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5262 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5263 | rc = -EIO; |
| 5264 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5265 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5266 | |
| 5267 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5268 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5269 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5270 | rc = 0; |
| 5271 | |
| 5272 | out_free_mboxq: |
| 5273 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5274 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5275 | } |
| 5276 | |
| 5277 | /** |
| 5278 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5279 | * @phba: pointer to lpfc hba data structure. |
| 5280 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5281 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5282 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5283 | * On output, the number of data bytes in @vpd. |
| 5284 | * |
| 5285 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5286 | * addition, this routine gets the port vpd data. |
| 5287 | * |
| 5288 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5289 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5290 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5291 | **/ |
| 5292 | static int |
| 5293 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5294 | uint8_t *vpd, uint32_t *vpd_size) |
| 5295 | { |
| 5296 | int rc = 0; |
| 5297 | uint32_t dma_size; |
| 5298 | struct lpfc_dmabuf *dmabuf; |
| 5299 | struct lpfc_mqe *mqe; |
| 5300 | |
| 5301 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5302 | if (!dmabuf) |
| 5303 | return -ENOMEM; |
| 5304 | |
| 5305 | /* |
| 5306 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5307 | * mailbox command. |
| 5308 | */ |
| 5309 | dma_size = *vpd_size; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 5310 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
| 5311 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5312 | if (!dmabuf->virt) { |
| 5313 | kfree(dmabuf); |
| 5314 | return -ENOMEM; |
| 5315 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5316 | |
| 5317 | /* |
| 5318 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5319 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5320 | * in SLI3. This code corrects the conflicts. |
| 5321 | */ |
| 5322 | lpfc_read_rev(phba, mboxq); |
| 5323 | mqe = &mboxq->u.mqe; |
| 5324 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5325 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5326 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5327 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5328 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5329 | |
| 5330 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5331 | if (rc) { |
| 5332 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5333 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5334 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5335 | return -EIO; |
| 5336 | } |
| 5337 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5338 | /* |
| 5339 | * The available vpd length cannot be bigger than the |
| 5340 | * DMA buffer passed to the port. Catch the less than |
| 5341 | * case and update the caller's size. |
| 5342 | */ |
| 5343 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5344 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5345 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5346 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5347 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5348 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5349 | dmabuf->virt, dmabuf->phys); |
| 5350 | kfree(dmabuf); |
| 5351 | return 0; |
| 5352 | } |
| 5353 | |
| 5354 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5355 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5356 | * @phba: pointer to lpfc hba data structure. |
| 5357 | * |
| 5358 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5359 | * is attached to. |
| 5360 | * |
| 5361 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5362 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5363 | * otherwise - failed to retrieve physical port name |
| 5364 | **/ |
| 5365 | static int |
| 5366 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5367 | { |
| 5368 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5369 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5370 | struct lpfc_controller_attribute *cntl_attr; |
| 5371 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5372 | void *virtaddr = NULL; |
| 5373 | uint32_t alloclen, reqlen; |
| 5374 | uint32_t shdr_status, shdr_add_status; |
| 5375 | union lpfc_sli4_cfg_shdr *shdr; |
| 5376 | char cport_name = 0; |
| 5377 | int rc; |
| 5378 | |
| 5379 | /* We assume nothing at this point */ |
| 5380 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5381 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5382 | |
| 5383 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5384 | if (!mboxq) |
| 5385 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5386 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5387 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5388 | lpfc_sli4_read_config(phba); |
| 5389 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5390 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5391 | |
| 5392 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5393 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5394 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5395 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5396 | LPFC_SLI4_MBX_NEMBED); |
| 5397 | if (alloclen < reqlen) { |
| 5398 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5399 | "3084 Allocated DMA memory size (%d) is " |
| 5400 | "less than the requested DMA memory size " |
| 5401 | "(%d)\n", alloclen, reqlen); |
| 5402 | rc = -ENOMEM; |
| 5403 | goto out_free_mboxq; |
| 5404 | } |
| 5405 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5406 | virtaddr = mboxq->sge_array->addr[0]; |
| 5407 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5408 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5409 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5410 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5411 | if (shdr_status || shdr_add_status || rc) { |
| 5412 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5413 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5414 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5415 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5416 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5417 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5418 | rc, shdr_status, shdr_add_status); |
| 5419 | rc = -ENXIO; |
| 5420 | goto out_free_mboxq; |
| 5421 | } |
| 5422 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5423 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5424 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5425 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5426 | phba->sli4_hba.lnk_info.lnk_no = |
| 5427 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 5428 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5429 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 5430 | phba->sli4_hba.lnk_info.lnk_tp, |
| 5431 | phba->sli4_hba.lnk_info.lnk_no); |
| 5432 | |
| 5433 | retrieve_ppname: |
| 5434 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5435 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5436 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5437 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5438 | LPFC_SLI4_MBX_EMBED); |
| 5439 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5440 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5441 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5442 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5443 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5444 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5445 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5446 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5447 | if (shdr_status || shdr_add_status || rc) { |
| 5448 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5449 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5450 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5451 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5452 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5453 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5454 | rc, shdr_status, shdr_add_status); |
| 5455 | rc = -ENXIO; |
| 5456 | goto out_free_mboxq; |
| 5457 | } |
| 5458 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5459 | case LPFC_LINK_NUMBER_0: |
| 5460 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5461 | &get_port_name->u.response); |
| 5462 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5463 | break; |
| 5464 | case LPFC_LINK_NUMBER_1: |
| 5465 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5466 | &get_port_name->u.response); |
| 5467 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5468 | break; |
| 5469 | case LPFC_LINK_NUMBER_2: |
| 5470 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5471 | &get_port_name->u.response); |
| 5472 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5473 | break; |
| 5474 | case LPFC_LINK_NUMBER_3: |
| 5475 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5476 | &get_port_name->u.response); |
| 5477 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5478 | break; |
| 5479 | default: |
| 5480 | break; |
| 5481 | } |
| 5482 | |
| 5483 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5484 | phba->Port[0] = cport_name; |
| 5485 | phba->Port[1] = '\0'; |
| 5486 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5487 | "3091 SLI get port name: %s\n", phba->Port); |
| 5488 | } |
| 5489 | |
| 5490 | out_free_mboxq: |
| 5491 | if (rc != MBX_TIMEOUT) { |
| 5492 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5493 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5494 | else |
| 5495 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5496 | } |
| 5497 | return rc; |
| 5498 | } |
| 5499 | |
| 5500 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5501 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5502 | * @phba: pointer to lpfc hba data structure. |
| 5503 | * |
| 5504 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5505 | * event queues |
| 5506 | **/ |
| 5507 | static void |
| 5508 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5509 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5510 | int qidx; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5511 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5512 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5513 | sli4_hba->sli4_cq_release(sli4_hba->mbx_cq, LPFC_QUEUE_REARM); |
| 5514 | sli4_hba->sli4_cq_release(sli4_hba->els_cq, LPFC_QUEUE_REARM); |
| 5515 | if (sli4_hba->nvmels_cq) |
| 5516 | sli4_hba->sli4_cq_release(sli4_hba->nvmels_cq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5517 | LPFC_QUEUE_REARM); |
| 5518 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5519 | if (sli4_hba->fcp_cq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5520 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5521 | sli4_hba->sli4_cq_release(sli4_hba->fcp_cq[qidx], |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5522 | LPFC_QUEUE_REARM); |
| 5523 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5524 | if (sli4_hba->nvme_cq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5525 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5526 | sli4_hba->sli4_cq_release(sli4_hba->nvme_cq[qidx], |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5527 | LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5528 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5529 | if (phba->cfg_fof) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5530 | sli4_hba->sli4_cq_release(sli4_hba->oas_cq, LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5531 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5532 | if (sli4_hba->hba_eq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5533 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5534 | sli4_hba->sli4_eq_release(sli4_hba->hba_eq[qidx], |
| 5535 | LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5536 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5537 | if (phba->nvmet_support) { |
| 5538 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5539 | sli4_hba->sli4_cq_release( |
| 5540 | sli4_hba->nvmet_cqset[qidx], |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5541 | LPFC_QUEUE_REARM); |
| 5542 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5543 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5544 | |
| 5545 | if (phba->cfg_fof) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 5546 | sli4_hba->sli4_eq_release(sli4_hba->fof_eq, LPFC_QUEUE_REARM); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5547 | } |
| 5548 | |
| 5549 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5550 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5551 | * @phba: Pointer to HBA context object. |
| 5552 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5553 | * @extnt_count: buffer to hold port available extent count. |
| 5554 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5555 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5556 | * This function calls the port and retrievs the number of available |
| 5557 | * extents and their size for a particular extent type. |
| 5558 | * |
| 5559 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5560 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5561 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5562 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5563 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5564 | { |
| 5565 | int rc = 0; |
| 5566 | uint32_t length; |
| 5567 | uint32_t mbox_tmo; |
| 5568 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5569 | LPFC_MBOXQ_t *mbox; |
| 5570 | |
| 5571 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5572 | if (!mbox) |
| 5573 | return -ENOMEM; |
| 5574 | |
| 5575 | /* Find out how many extents are available for this resource type */ |
| 5576 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5577 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5578 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5579 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5580 | length, LPFC_SLI4_MBX_EMBED); |
| 5581 | |
| 5582 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5583 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5584 | LPFC_SLI4_MBX_EMBED); |
| 5585 | if (unlikely(rc)) { |
| 5586 | rc = -EIO; |
| 5587 | goto err_exit; |
| 5588 | } |
| 5589 | |
| 5590 | if (!phba->sli4_hba.intr_enable) |
| 5591 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5592 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5593 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5594 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5595 | } |
| 5596 | if (unlikely(rc)) { |
| 5597 | rc = -EIO; |
| 5598 | goto err_exit; |
| 5599 | } |
| 5600 | |
| 5601 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5602 | if (bf_get(lpfc_mbox_hdr_status, |
| 5603 | &rsrc_info->header.cfg_shdr.response)) { |
| 5604 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5605 | "2930 Failed to get resource extents " |
| 5606 | "Status 0x%x Add'l Status 0x%x\n", |
| 5607 | bf_get(lpfc_mbox_hdr_status, |
| 5608 | &rsrc_info->header.cfg_shdr.response), |
| 5609 | bf_get(lpfc_mbox_hdr_add_status, |
| 5610 | &rsrc_info->header.cfg_shdr.response)); |
| 5611 | rc = -EIO; |
| 5612 | goto err_exit; |
| 5613 | } |
| 5614 | |
| 5615 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5616 | &rsrc_info->u.rsp); |
| 5617 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5618 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5619 | |
| 5620 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5621 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5622 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5623 | |
| 5624 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5625 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5626 | return rc; |
| 5627 | } |
| 5628 | |
| 5629 | /** |
| 5630 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5631 | * @phba: Pointer to HBA context object. |
| 5632 | * @type: The extent type to check. |
| 5633 | * |
| 5634 | * This function reads the current available extents from the port and checks |
| 5635 | * if the extent count or extent size has changed since the last access. |
| 5636 | * Callers use this routine post port reset to understand if there is a |
| 5637 | * extent reprovisioning requirement. |
| 5638 | * |
| 5639 | * Returns: |
| 5640 | * -Error: error indicates problem. |
| 5641 | * 1: Extent count or size has changed. |
| 5642 | * 0: No changes. |
| 5643 | **/ |
| 5644 | static int |
| 5645 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5646 | { |
| 5647 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5648 | uint16_t size_diff, rsrc_ext_size; |
| 5649 | int rc = 0; |
| 5650 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5651 | struct list_head *rsrc_blk_list = NULL; |
| 5652 | |
| 5653 | size_diff = 0; |
| 5654 | curr_ext_cnt = 0; |
| 5655 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5656 | &rsrc_ext_cnt, |
| 5657 | &rsrc_ext_size); |
| 5658 | if (unlikely(rc)) |
| 5659 | return -EIO; |
| 5660 | |
| 5661 | switch (type) { |
| 5662 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5663 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5664 | break; |
| 5665 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5666 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5667 | break; |
| 5668 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5669 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5670 | break; |
| 5671 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5672 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5673 | break; |
| 5674 | default: |
| 5675 | break; |
| 5676 | } |
| 5677 | |
| 5678 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5679 | curr_ext_cnt++; |
| 5680 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5681 | size_diff++; |
| 5682 | } |
| 5683 | |
| 5684 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5685 | rc = 1; |
| 5686 | |
| 5687 | return rc; |
| 5688 | } |
| 5689 | |
| 5690 | /** |
| 5691 | * lpfc_sli4_cfg_post_extnts - |
| 5692 | * @phba: Pointer to HBA context object. |
| 5693 | * @extnt_cnt - number of available extents. |
| 5694 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5695 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5696 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5697 | * |
| 5698 | * This function executes the extents allocation request. It also |
| 5699 | * takes care of the amount of memory needed to allocate or get the |
| 5700 | * allocated extents. It is the caller's responsibility to evaluate |
| 5701 | * the response. |
| 5702 | * |
| 5703 | * Returns: |
| 5704 | * -Error: Error value describes the condition found. |
| 5705 | * 0: if successful |
| 5706 | **/ |
| 5707 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5708 | 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] | 5709 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5710 | { |
| 5711 | int rc = 0; |
| 5712 | uint32_t req_len; |
| 5713 | uint32_t emb_len; |
| 5714 | uint32_t alloc_len, mbox_tmo; |
| 5715 | |
| 5716 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5717 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5718 | |
| 5719 | /* |
| 5720 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5721 | * accounts for extents-specific word. |
| 5722 | */ |
| 5723 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5724 | sizeof(uint32_t); |
| 5725 | |
| 5726 | /* |
| 5727 | * Presume the allocation and response will fit into an embedded |
| 5728 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5729 | */ |
| 5730 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5731 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5732 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5733 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5734 | sizeof(uint32_t); |
| 5735 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5736 | } |
| 5737 | |
| 5738 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5739 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5740 | req_len, *emb); |
| 5741 | if (alloc_len < req_len) { |
| 5742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5743 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5744 | "less than the requested DMA memory " |
| 5745 | "size (x%x)\n", alloc_len, req_len); |
| 5746 | return -ENOMEM; |
| 5747 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5748 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5749 | if (unlikely(rc)) |
| 5750 | return -EIO; |
| 5751 | |
| 5752 | if (!phba->sli4_hba.intr_enable) |
| 5753 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5754 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5755 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5756 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5757 | } |
| 5758 | |
| 5759 | if (unlikely(rc)) |
| 5760 | rc = -EIO; |
| 5761 | return rc; |
| 5762 | } |
| 5763 | |
| 5764 | /** |
| 5765 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5766 | * @phba: Pointer to HBA context object. |
| 5767 | * @type: The resource extent type to allocate. |
| 5768 | * |
| 5769 | * This function allocates the number of elements for the specified |
| 5770 | * resource type. |
| 5771 | **/ |
| 5772 | static int |
| 5773 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5774 | { |
| 5775 | bool emb = false; |
| 5776 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5777 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5778 | uint16_t *ids; |
| 5779 | int i, rc; |
| 5780 | unsigned long longs; |
| 5781 | unsigned long *bmask; |
| 5782 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5783 | LPFC_MBOXQ_t *mbox; |
| 5784 | uint32_t length; |
| 5785 | struct lpfc_id_range *id_array = NULL; |
| 5786 | void *virtaddr = NULL; |
| 5787 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5788 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5789 | struct list_head *ext_blk_list; |
| 5790 | |
| 5791 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5792 | &rsrc_cnt, |
| 5793 | &rsrc_size); |
| 5794 | if (unlikely(rc)) |
| 5795 | return -EIO; |
| 5796 | |
| 5797 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5798 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5799 | "3009 No available Resource Extents " |
| 5800 | "for resource type 0x%x: Count: 0x%x, " |
| 5801 | "Size 0x%x\n", type, rsrc_cnt, |
| 5802 | rsrc_size); |
| 5803 | return -ENOMEM; |
| 5804 | } |
| 5805 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5806 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5807 | "2903 Post resource extents type-0x%x: " |
| 5808 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5809 | |
| 5810 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5811 | if (!mbox) |
| 5812 | return -ENOMEM; |
| 5813 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5814 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5815 | if (unlikely(rc)) { |
| 5816 | rc = -EIO; |
| 5817 | goto err_exit; |
| 5818 | } |
| 5819 | |
| 5820 | /* |
| 5821 | * Figure out where the response is located. Then get local pointers |
| 5822 | * to the response data. The port does not guarantee to respond to |
| 5823 | * all extents counts request so update the local variable with the |
| 5824 | * allocated count from the port. |
| 5825 | */ |
| 5826 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5827 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5828 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5829 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5830 | } else { |
| 5831 | virtaddr = mbox->sge_array->addr[0]; |
| 5832 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5833 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5834 | id_array = &n_rsrc->id; |
| 5835 | } |
| 5836 | |
| 5837 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5838 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5839 | |
| 5840 | /* |
| 5841 | * Based on the resource size and count, correct the base and max |
| 5842 | * resource values. |
| 5843 | */ |
| 5844 | length = sizeof(struct lpfc_rsrc_blks); |
| 5845 | switch (type) { |
| 5846 | case LPFC_RSC_TYPE_FCOE_RPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5847 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5848 | sizeof(unsigned long), |
| 5849 | GFP_KERNEL); |
| 5850 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5851 | rc = -ENOMEM; |
| 5852 | goto err_exit; |
| 5853 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5854 | phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5855 | sizeof(uint16_t), |
| 5856 | GFP_KERNEL); |
| 5857 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5858 | kfree(phba->sli4_hba.rpi_bmask); |
| 5859 | rc = -ENOMEM; |
| 5860 | goto err_exit; |
| 5861 | } |
| 5862 | |
| 5863 | /* |
| 5864 | * The next_rpi was initialized with the maximum available |
| 5865 | * count but the port may allocate a smaller number. Catch |
| 5866 | * that case and update the next_rpi. |
| 5867 | */ |
| 5868 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5869 | |
| 5870 | /* Initialize local ptrs for common extent processing later. */ |
| 5871 | bmask = phba->sli4_hba.rpi_bmask; |
| 5872 | ids = phba->sli4_hba.rpi_ids; |
| 5873 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5874 | break; |
| 5875 | case LPFC_RSC_TYPE_FCOE_VPI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5876 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5877 | GFP_KERNEL); |
| 5878 | if (unlikely(!phba->vpi_bmask)) { |
| 5879 | rc = -ENOMEM; |
| 5880 | goto err_exit; |
| 5881 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5882 | phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5883 | GFP_KERNEL); |
| 5884 | if (unlikely(!phba->vpi_ids)) { |
| 5885 | kfree(phba->vpi_bmask); |
| 5886 | rc = -ENOMEM; |
| 5887 | goto err_exit; |
| 5888 | } |
| 5889 | |
| 5890 | /* Initialize local ptrs for common extent processing later. */ |
| 5891 | bmask = phba->vpi_bmask; |
| 5892 | ids = phba->vpi_ids; |
| 5893 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5894 | break; |
| 5895 | case LPFC_RSC_TYPE_FCOE_XRI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5896 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5897 | sizeof(unsigned long), |
| 5898 | GFP_KERNEL); |
| 5899 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5900 | rc = -ENOMEM; |
| 5901 | goto err_exit; |
| 5902 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5903 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5904 | phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5905 | sizeof(uint16_t), |
| 5906 | GFP_KERNEL); |
| 5907 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5908 | kfree(phba->sli4_hba.xri_bmask); |
| 5909 | rc = -ENOMEM; |
| 5910 | goto err_exit; |
| 5911 | } |
| 5912 | |
| 5913 | /* Initialize local ptrs for common extent processing later. */ |
| 5914 | bmask = phba->sli4_hba.xri_bmask; |
| 5915 | ids = phba->sli4_hba.xri_ids; |
| 5916 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5917 | break; |
| 5918 | case LPFC_RSC_TYPE_FCOE_VFI: |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5919 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5920 | sizeof(unsigned long), |
| 5921 | GFP_KERNEL); |
| 5922 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5923 | rc = -ENOMEM; |
| 5924 | goto err_exit; |
| 5925 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5926 | phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5927 | sizeof(uint16_t), |
| 5928 | GFP_KERNEL); |
| 5929 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5930 | kfree(phba->sli4_hba.vfi_bmask); |
| 5931 | rc = -ENOMEM; |
| 5932 | goto err_exit; |
| 5933 | } |
| 5934 | |
| 5935 | /* Initialize local ptrs for common extent processing later. */ |
| 5936 | bmask = phba->sli4_hba.vfi_bmask; |
| 5937 | ids = phba->sli4_hba.vfi_ids; |
| 5938 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5939 | break; |
| 5940 | default: |
| 5941 | /* Unsupported Opcode. Fail call. */ |
| 5942 | id_array = NULL; |
| 5943 | bmask = NULL; |
| 5944 | ids = NULL; |
| 5945 | ext_blk_list = NULL; |
| 5946 | goto err_exit; |
| 5947 | } |
| 5948 | |
| 5949 | /* |
| 5950 | * Complete initializing the extent configuration with the |
| 5951 | * allocated ids assigned to this function. The bitmask serves |
| 5952 | * as an index into the array and manages the available ids. The |
| 5953 | * array just stores the ids communicated to the port via the wqes. |
| 5954 | */ |
| 5955 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5956 | if ((i % 2) == 0) |
| 5957 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5958 | &id_array[k]); |
| 5959 | else |
| 5960 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5961 | &id_array[k]); |
| 5962 | |
| 5963 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5964 | if (unlikely(!rsrc_blks)) { |
| 5965 | rc = -ENOMEM; |
| 5966 | kfree(bmask); |
| 5967 | kfree(ids); |
| 5968 | goto err_exit; |
| 5969 | } |
| 5970 | rsrc_blks->rsrc_start = rsrc_id; |
| 5971 | rsrc_blks->rsrc_size = rsrc_size; |
| 5972 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5973 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5974 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5975 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5976 | lpfc_sli4_get_iocb_cnt(phba); |
| 5977 | phba->sli4_hba.nvme_xri_start = |
| 5978 | phba->sli4_hba.scsi_xri_start + |
| 5979 | phba->sli4_hba.scsi_xri_max; |
| 5980 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5981 | |
| 5982 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5983 | ids[j] = rsrc_id; |
| 5984 | rsrc_id++; |
| 5985 | j++; |
| 5986 | } |
| 5987 | /* Entire word processed. Get next word.*/ |
| 5988 | if ((i % 2) == 1) |
| 5989 | k++; |
| 5990 | } |
| 5991 | err_exit: |
| 5992 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5993 | return rc; |
| 5994 | } |
| 5995 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5996 | |
| 5997 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5998 | /** |
| 5999 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 6000 | * @phba: Pointer to HBA context object. |
| 6001 | * @type: the extent's type. |
| 6002 | * |
| 6003 | * This function deallocates all extents of a particular resource type. |
| 6004 | * SLI4 does not allow for deallocating a particular extent range. It |
| 6005 | * is the caller's responsibility to release all kernel memory resources. |
| 6006 | **/ |
| 6007 | static int |
| 6008 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 6009 | { |
| 6010 | int rc; |
| 6011 | uint32_t length, mbox_tmo = 0; |
| 6012 | LPFC_MBOXQ_t *mbox; |
| 6013 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 6014 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 6015 | |
| 6016 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6017 | if (!mbox) |
| 6018 | return -ENOMEM; |
| 6019 | |
| 6020 | /* |
| 6021 | * This function sends an embedded mailbox because it only sends the |
| 6022 | * the resource type. All extents of this type are released by the |
| 6023 | * port. |
| 6024 | */ |
| 6025 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 6026 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 6027 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6028 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 6029 | length, LPFC_SLI4_MBX_EMBED); |
| 6030 | |
| 6031 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 6032 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 6033 | LPFC_SLI4_MBX_EMBED); |
| 6034 | if (unlikely(rc)) { |
| 6035 | rc = -EIO; |
| 6036 | goto out_free_mbox; |
| 6037 | } |
| 6038 | if (!phba->sli4_hba.intr_enable) |
| 6039 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6040 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6041 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6042 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6043 | } |
| 6044 | if (unlikely(rc)) { |
| 6045 | rc = -EIO; |
| 6046 | goto out_free_mbox; |
| 6047 | } |
| 6048 | |
| 6049 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 6050 | if (bf_get(lpfc_mbox_hdr_status, |
| 6051 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 6052 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6053 | "2919 Failed to release resource extents " |
| 6054 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 6055 | "Resource memory not released.\n", |
| 6056 | type, |
| 6057 | bf_get(lpfc_mbox_hdr_status, |
| 6058 | &dealloc_rsrc->header.cfg_shdr.response), |
| 6059 | bf_get(lpfc_mbox_hdr_add_status, |
| 6060 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 6061 | rc = -EIO; |
| 6062 | goto out_free_mbox; |
| 6063 | } |
| 6064 | |
| 6065 | /* Release kernel memory resources for the specific type. */ |
| 6066 | switch (type) { |
| 6067 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6068 | kfree(phba->vpi_bmask); |
| 6069 | kfree(phba->vpi_ids); |
| 6070 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6071 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6072 | &phba->lpfc_vpi_blk_list, list) { |
| 6073 | list_del_init(&rsrc_blk->list); |
| 6074 | kfree(rsrc_blk); |
| 6075 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6076 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6077 | break; |
| 6078 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6079 | kfree(phba->sli4_hba.xri_bmask); |
| 6080 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6081 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6082 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 6083 | list_del_init(&rsrc_blk->list); |
| 6084 | kfree(rsrc_blk); |
| 6085 | } |
| 6086 | break; |
| 6087 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6088 | kfree(phba->sli4_hba.vfi_bmask); |
| 6089 | kfree(phba->sli4_hba.vfi_ids); |
| 6090 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6091 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6092 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 6093 | list_del_init(&rsrc_blk->list); |
| 6094 | kfree(rsrc_blk); |
| 6095 | } |
| 6096 | break; |
| 6097 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6098 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 6099 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 6100 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 6101 | list_del_init(&rsrc_blk->list); |
| 6102 | kfree(rsrc_blk); |
| 6103 | } |
| 6104 | break; |
| 6105 | default: |
| 6106 | break; |
| 6107 | } |
| 6108 | |
| 6109 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6110 | |
| 6111 | out_free_mbox: |
| 6112 | mempool_free(mbox, phba->mbox_mem_pool); |
| 6113 | return rc; |
| 6114 | } |
| 6115 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 6116 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6117 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 6118 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6119 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6120 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6121 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6122 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 6123 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6124 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6125 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 6126 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6127 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6128 | switch (feature) { |
| 6129 | case LPFC_SET_UE_RECOVERY: |
| 6130 | bf_set(lpfc_mbx_set_feature_UER, |
| 6131 | &mbox->u.mqe.un.set_feature, 1); |
| 6132 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 6133 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6134 | break; |
| 6135 | case LPFC_SET_MDS_DIAGS: |
| 6136 | bf_set(lpfc_mbx_set_feature_mds, |
| 6137 | &mbox->u.mqe.un.set_feature, 1); |
| 6138 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 6139 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6140 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 6141 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 6142 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6143 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6144 | |
| 6145 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6146 | } |
| 6147 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6148 | /** |
| 6149 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 6150 | * @phba: Pointer to HBA context object. |
| 6151 | * |
| 6152 | * This function allocates all SLI4 resource identifiers. |
| 6153 | **/ |
| 6154 | int |
| 6155 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 6156 | { |
| 6157 | int i, rc, error = 0; |
| 6158 | uint16_t count, base; |
| 6159 | unsigned long longs; |
| 6160 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6161 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6162 | 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] | 6163 | if (phba->sli4_hba.extents_in_use) { |
| 6164 | /* |
| 6165 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 6166 | * resource extent count must be read and allocated before |
| 6167 | * provisioning the resource id arrays. |
| 6168 | */ |
| 6169 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 6170 | LPFC_IDX_RSRC_RDY) { |
| 6171 | /* |
| 6172 | * Extent-based resources are set - the driver could |
| 6173 | * be in a port reset. Figure out if any corrective |
| 6174 | * actions need to be taken. |
| 6175 | */ |
| 6176 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6177 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6178 | if (rc != 0) |
| 6179 | error++; |
| 6180 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6181 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6182 | if (rc != 0) |
| 6183 | error++; |
| 6184 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6185 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6186 | if (rc != 0) |
| 6187 | error++; |
| 6188 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 6189 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6190 | if (rc != 0) |
| 6191 | error++; |
| 6192 | |
| 6193 | /* |
| 6194 | * It's possible that the number of resources |
| 6195 | * provided to this port instance changed between |
| 6196 | * resets. Detect this condition and reallocate |
| 6197 | * resources. Otherwise, there is no action. |
| 6198 | */ |
| 6199 | if (error) { |
| 6200 | lpfc_printf_log(phba, KERN_INFO, |
| 6201 | LOG_MBOX | LOG_INIT, |
| 6202 | "2931 Detected extent resource " |
| 6203 | "change. Reallocating all " |
| 6204 | "extents.\n"); |
| 6205 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6206 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6207 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6208 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6209 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6210 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6211 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6212 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6213 | } else |
| 6214 | return 0; |
| 6215 | } |
| 6216 | |
| 6217 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6218 | if (unlikely(rc)) |
| 6219 | goto err_exit; |
| 6220 | |
| 6221 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6222 | if (unlikely(rc)) |
| 6223 | goto err_exit; |
| 6224 | |
| 6225 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6226 | if (unlikely(rc)) |
| 6227 | goto err_exit; |
| 6228 | |
| 6229 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6230 | if (unlikely(rc)) |
| 6231 | goto err_exit; |
| 6232 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6233 | LPFC_IDX_RSRC_RDY); |
| 6234 | return rc; |
| 6235 | } else { |
| 6236 | /* |
| 6237 | * The port does not support resource extents. The XRI, VPI, |
| 6238 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6239 | * Just allocate the bitmasks and provision the resource id |
| 6240 | * arrays. If a port reset is active, the resources don't |
| 6241 | * need any action - just exit. |
| 6242 | */ |
| 6243 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6244 | LPFC_IDX_RSRC_RDY) { |
| 6245 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6246 | lpfc_sli4_remove_rpis(phba); |
| 6247 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6248 | /* RPIs. */ |
| 6249 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6250 | if (count <= 0) { |
| 6251 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6252 | "3279 Invalid provisioning of " |
| 6253 | "rpi:%d\n", count); |
| 6254 | rc = -EINVAL; |
| 6255 | goto err_exit; |
| 6256 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6257 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6258 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6259 | phba->sli4_hba.rpi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6260 | sizeof(unsigned long), |
| 6261 | GFP_KERNEL); |
| 6262 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6263 | rc = -ENOMEM; |
| 6264 | goto err_exit; |
| 6265 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6266 | phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6267 | GFP_KERNEL); |
| 6268 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6269 | rc = -ENOMEM; |
| 6270 | goto free_rpi_bmask; |
| 6271 | } |
| 6272 | |
| 6273 | for (i = 0; i < count; i++) |
| 6274 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6275 | |
| 6276 | /* VPIs. */ |
| 6277 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6278 | if (count <= 0) { |
| 6279 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6280 | "3280 Invalid provisioning of " |
| 6281 | "vpi:%d\n", count); |
| 6282 | rc = -EINVAL; |
| 6283 | goto free_rpi_ids; |
| 6284 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6285 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6286 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6287 | phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6288 | GFP_KERNEL); |
| 6289 | if (unlikely(!phba->vpi_bmask)) { |
| 6290 | rc = -ENOMEM; |
| 6291 | goto free_rpi_ids; |
| 6292 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6293 | phba->vpi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6294 | GFP_KERNEL); |
| 6295 | if (unlikely(!phba->vpi_ids)) { |
| 6296 | rc = -ENOMEM; |
| 6297 | goto free_vpi_bmask; |
| 6298 | } |
| 6299 | |
| 6300 | for (i = 0; i < count; i++) |
| 6301 | phba->vpi_ids[i] = base + i; |
| 6302 | |
| 6303 | /* XRIs. */ |
| 6304 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6305 | if (count <= 0) { |
| 6306 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6307 | "3281 Invalid provisioning of " |
| 6308 | "xri:%d\n", count); |
| 6309 | rc = -EINVAL; |
| 6310 | goto free_vpi_ids; |
| 6311 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6312 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 6313 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6314 | phba->sli4_hba.xri_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6315 | sizeof(unsigned long), |
| 6316 | GFP_KERNEL); |
| 6317 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6318 | rc = -ENOMEM; |
| 6319 | goto free_vpi_ids; |
| 6320 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6321 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6322 | phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6323 | GFP_KERNEL); |
| 6324 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6325 | rc = -ENOMEM; |
| 6326 | goto free_xri_bmask; |
| 6327 | } |
| 6328 | |
| 6329 | for (i = 0; i < count; i++) |
| 6330 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6331 | |
| 6332 | /* VFIs. */ |
| 6333 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6334 | if (count <= 0) { |
| 6335 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6336 | "3282 Invalid provisioning of " |
| 6337 | "vfi:%d\n", count); |
| 6338 | rc = -EINVAL; |
| 6339 | goto free_xri_ids; |
| 6340 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6341 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6342 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6343 | phba->sli4_hba.vfi_bmask = kcalloc(longs, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6344 | sizeof(unsigned long), |
| 6345 | GFP_KERNEL); |
| 6346 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6347 | rc = -ENOMEM; |
| 6348 | goto free_xri_ids; |
| 6349 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6350 | phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t), |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6351 | GFP_KERNEL); |
| 6352 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6353 | rc = -ENOMEM; |
| 6354 | goto free_vfi_bmask; |
| 6355 | } |
| 6356 | |
| 6357 | for (i = 0; i < count; i++) |
| 6358 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6359 | |
| 6360 | /* |
| 6361 | * Mark all resources ready. An HBA reset doesn't need |
| 6362 | * to reset the initialization. |
| 6363 | */ |
| 6364 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6365 | LPFC_IDX_RSRC_RDY); |
| 6366 | return 0; |
| 6367 | } |
| 6368 | |
| 6369 | free_vfi_bmask: |
| 6370 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6371 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6372 | free_xri_ids: |
| 6373 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6374 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6375 | free_xri_bmask: |
| 6376 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6377 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6378 | free_vpi_ids: |
| 6379 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6380 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6381 | free_vpi_bmask: |
| 6382 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6383 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6384 | free_rpi_ids: |
| 6385 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6386 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6387 | free_rpi_bmask: |
| 6388 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6389 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6390 | err_exit: |
| 6391 | return rc; |
| 6392 | } |
| 6393 | |
| 6394 | /** |
| 6395 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6396 | * @phba: Pointer to HBA context object. |
| 6397 | * |
| 6398 | * This function allocates the number of elements for the specified |
| 6399 | * resource type. |
| 6400 | **/ |
| 6401 | int |
| 6402 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 6403 | { |
| 6404 | if (phba->sli4_hba.extents_in_use) { |
| 6405 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6406 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6407 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6408 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6409 | } else { |
| 6410 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6411 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6412 | kfree(phba->vpi_ids); |
| 6413 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6414 | kfree(phba->sli4_hba.xri_bmask); |
| 6415 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6416 | kfree(phba->sli4_hba.vfi_bmask); |
| 6417 | kfree(phba->sli4_hba.vfi_ids); |
| 6418 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6419 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6420 | } |
| 6421 | |
| 6422 | return 0; |
| 6423 | } |
| 6424 | |
| 6425 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6426 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6427 | * @phba: Pointer to HBA context object. |
| 6428 | * @type: The resource extent type. |
| 6429 | * @extnt_count: buffer to hold port extent count response |
| 6430 | * @extnt_size: buffer to hold port extent size response. |
| 6431 | * |
| 6432 | * This function calls the port to read the host allocated extents |
| 6433 | * for a particular type. |
| 6434 | **/ |
| 6435 | int |
| 6436 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6437 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6438 | { |
| 6439 | bool emb; |
| 6440 | int rc = 0; |
| 6441 | uint16_t curr_blks = 0; |
| 6442 | uint32_t req_len, emb_len; |
| 6443 | uint32_t alloc_len, mbox_tmo; |
| 6444 | struct list_head *blk_list_head; |
| 6445 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6446 | LPFC_MBOXQ_t *mbox; |
| 6447 | void *virtaddr = NULL; |
| 6448 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6449 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6450 | union lpfc_sli4_cfg_shdr *shdr; |
| 6451 | |
| 6452 | switch (type) { |
| 6453 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6454 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6455 | break; |
| 6456 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6457 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6458 | break; |
| 6459 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6460 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6461 | break; |
| 6462 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6463 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6464 | break; |
| 6465 | default: |
| 6466 | return -EIO; |
| 6467 | } |
| 6468 | |
| 6469 | /* Count the number of extents currently allocatd for this type. */ |
| 6470 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6471 | if (curr_blks == 0) { |
| 6472 | /* |
| 6473 | * The GET_ALLOCATED mailbox does not return the size, |
| 6474 | * just the count. The size should be just the size |
| 6475 | * stored in the current allocated block and all sizes |
| 6476 | * for an extent type are the same so set the return |
| 6477 | * value now. |
| 6478 | */ |
| 6479 | *extnt_size = rsrc_blk->rsrc_size; |
| 6480 | } |
| 6481 | curr_blks++; |
| 6482 | } |
| 6483 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6484 | /* |
| 6485 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6486 | * accounts for extents-specific word. |
| 6487 | */ |
| 6488 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6489 | sizeof(uint32_t); |
| 6490 | |
| 6491 | /* |
| 6492 | * Presume the allocation and response will fit into an embedded |
| 6493 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6494 | */ |
| 6495 | emb = LPFC_SLI4_MBX_EMBED; |
| 6496 | req_len = emb_len; |
| 6497 | if (req_len > emb_len) { |
| 6498 | req_len = curr_blks * sizeof(uint16_t) + |
| 6499 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6500 | sizeof(uint32_t); |
| 6501 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6502 | } |
| 6503 | |
| 6504 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6505 | if (!mbox) |
| 6506 | return -ENOMEM; |
| 6507 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6508 | |
| 6509 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6510 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6511 | req_len, emb); |
| 6512 | if (alloc_len < req_len) { |
| 6513 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6514 | "2983 Allocated DMA memory size (x%x) is " |
| 6515 | "less than the requested DMA memory " |
| 6516 | "size (x%x)\n", alloc_len, req_len); |
| 6517 | rc = -ENOMEM; |
| 6518 | goto err_exit; |
| 6519 | } |
| 6520 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6521 | if (unlikely(rc)) { |
| 6522 | rc = -EIO; |
| 6523 | goto err_exit; |
| 6524 | } |
| 6525 | |
| 6526 | if (!phba->sli4_hba.intr_enable) |
| 6527 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6528 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6529 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6530 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6531 | } |
| 6532 | |
| 6533 | if (unlikely(rc)) { |
| 6534 | rc = -EIO; |
| 6535 | goto err_exit; |
| 6536 | } |
| 6537 | |
| 6538 | /* |
| 6539 | * Figure out where the response is located. Then get local pointers |
| 6540 | * to the response data. The port does not guarantee to respond to |
| 6541 | * all extents counts request so update the local variable with the |
| 6542 | * allocated count from the port. |
| 6543 | */ |
| 6544 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6545 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6546 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6547 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6548 | } else { |
| 6549 | virtaddr = mbox->sge_array->addr[0]; |
| 6550 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6551 | shdr = &n_rsrc->cfg_shdr; |
| 6552 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6553 | } |
| 6554 | |
| 6555 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6556 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6557 | "2984 Failed to read allocated resources " |
| 6558 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6559 | type, |
| 6560 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6561 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6562 | rc = -EIO; |
| 6563 | goto err_exit; |
| 6564 | } |
| 6565 | err_exit: |
| 6566 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6567 | return rc; |
| 6568 | } |
| 6569 | |
| 6570 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 6571 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6572 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6573 | * @pring: Pointer to driver SLI ring object. |
| 6574 | * @sgl_list: linked link of sgl buffers to post |
| 6575 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6576 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6577 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6578 | * repost them to the port by using SGL block post. This is needed after a |
| 6579 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6580 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 6581 | * 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] | 6582 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6583 | * mailbox command for posting. |
| 6584 | * |
| 6585 | * Returns: 0 = success, non-zero failure. |
| 6586 | **/ |
| 6587 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6588 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 6589 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6590 | { |
| 6591 | struct lpfc_sglq *sglq_entry = NULL; |
| 6592 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6593 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6594 | int status, total_cnt; |
| 6595 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6596 | int last_xritag = NO_XRI; |
| 6597 | LIST_HEAD(prep_sgl_list); |
| 6598 | LIST_HEAD(blck_sgl_list); |
| 6599 | LIST_HEAD(allc_sgl_list); |
| 6600 | LIST_HEAD(post_sgl_list); |
| 6601 | LIST_HEAD(free_sgl_list); |
| 6602 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6603 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6604 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6605 | list_splice_init(sgl_list, &allc_sgl_list); |
| 6606 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6607 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6608 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6609 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6610 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6611 | &allc_sgl_list, list) { |
| 6612 | list_del_init(&sglq_entry->list); |
| 6613 | block_cnt++; |
| 6614 | if ((last_xritag != NO_XRI) && |
| 6615 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6616 | /* a hole in xri block, form a sgl posting block */ |
| 6617 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6618 | post_cnt = block_cnt - 1; |
| 6619 | /* prepare list for next posting block */ |
| 6620 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6621 | block_cnt = 1; |
| 6622 | } else { |
| 6623 | /* prepare list for next posting block */ |
| 6624 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6625 | /* enough sgls for non-embed sgl mbox command */ |
| 6626 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6627 | list_splice_init(&prep_sgl_list, |
| 6628 | &blck_sgl_list); |
| 6629 | post_cnt = block_cnt; |
| 6630 | block_cnt = 0; |
| 6631 | } |
| 6632 | } |
| 6633 | num_posted++; |
| 6634 | |
| 6635 | /* keep track of last sgl's xritag */ |
| 6636 | last_xritag = sglq_entry->sli4_xritag; |
| 6637 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6638 | /* end of repost sgl list condition for buffers */ |
| 6639 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6640 | if (post_cnt == 0) { |
| 6641 | list_splice_init(&prep_sgl_list, |
| 6642 | &blck_sgl_list); |
| 6643 | post_cnt = block_cnt; |
| 6644 | } else if (block_cnt == 1) { |
| 6645 | status = lpfc_sli4_post_sgl(phba, |
| 6646 | sglq_entry->phys, 0, |
| 6647 | sglq_entry->sli4_xritag); |
| 6648 | if (!status) { |
| 6649 | /* successful, put sgl to posted list */ |
| 6650 | list_add_tail(&sglq_entry->list, |
| 6651 | &post_sgl_list); |
| 6652 | } else { |
| 6653 | /* Failure, put sgl to free list */ |
| 6654 | lpfc_printf_log(phba, KERN_WARNING, |
| 6655 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6656 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6657 | "sgl, xritag:x%x\n", |
| 6658 | sglq_entry->sli4_xritag); |
| 6659 | list_add_tail(&sglq_entry->list, |
| 6660 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6661 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6662 | } |
| 6663 | } |
| 6664 | } |
| 6665 | |
| 6666 | /* continue until a nembed page worth of sgls */ |
| 6667 | if (post_cnt == 0) |
| 6668 | continue; |
| 6669 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6670 | /* post the buffer list sgls as a block */ |
| 6671 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 6672 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6673 | |
| 6674 | if (!status) { |
| 6675 | /* success, put sgl list to posted sgl list */ |
| 6676 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6677 | } else { |
| 6678 | /* Failure, put sgl list to free sgl list */ |
| 6679 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6680 | struct lpfc_sglq, |
| 6681 | list); |
| 6682 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6683 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6684 | "xritag:x%x-x%x\n", |
| 6685 | sglq_entry_first->sli4_xritag, |
| 6686 | (sglq_entry_first->sli4_xritag + |
| 6687 | post_cnt - 1)); |
| 6688 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6689 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6690 | } |
| 6691 | |
| 6692 | /* don't reset xirtag due to hole in xri block */ |
| 6693 | if (block_cnt == 0) |
| 6694 | last_xritag = NO_XRI; |
| 6695 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6696 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6697 | post_cnt = 0; |
| 6698 | } |
| 6699 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6700 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6701 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6702 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6703 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6704 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6705 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6706 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6707 | list_splice_init(&post_sgl_list, sgl_list); |
| 6708 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6709 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6710 | } else { |
| 6711 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6712 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6713 | return -EIO; |
| 6714 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6715 | |
| 6716 | /* return the number of XRIs actually posted */ |
| 6717 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6718 | } |
| 6719 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6720 | void |
| 6721 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 6722 | { |
| 6723 | uint32_t len; |
| 6724 | |
| 6725 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 6726 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6727 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6728 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 6729 | LPFC_SLI4_MBX_EMBED); |
| 6730 | |
| 6731 | 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] | 6732 | mbox->u.mqe.un.set_host_data.param_len = |
| 6733 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6734 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 6735 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 6736 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 6737 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 6738 | } |
| 6739 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6740 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6741 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6742 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6743 | { |
| 6744 | int rc, i; |
| 6745 | struct lpfc_rqe hrqe; |
| 6746 | struct lpfc_rqe drqe; |
| 6747 | struct lpfc_rqb *rqbp; |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 6748 | unsigned long flags; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6749 | struct rqb_dmabuf *rqb_buffer; |
| 6750 | LIST_HEAD(rqb_buf_list); |
| 6751 | |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 6752 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6753 | rqbp = hrq->rqbp; |
| 6754 | for (i = 0; i < count; i++) { |
| 6755 | /* IF RQ is already full, don't bother */ |
| 6756 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) |
| 6757 | break; |
| 6758 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 6759 | if (!rqb_buffer) |
| 6760 | break; |
| 6761 | rqb_buffer->hrq = hrq; |
| 6762 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6763 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6764 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 6765 | } |
| 6766 | while (!list_empty(&rqb_buf_list)) { |
| 6767 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 6768 | hbuf.list); |
| 6769 | |
| 6770 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 6771 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 6772 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 6773 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 6774 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 6775 | if (rc < 0) { |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 6776 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6777 | "6421 Cannot post to HRQ %d: %x %x %x " |
| 6778 | "DRQ %x %x\n", |
| 6779 | hrq->queue_id, |
| 6780 | hrq->host_index, |
| 6781 | hrq->hba_index, |
| 6782 | hrq->entry_count, |
| 6783 | drq->host_index, |
| 6784 | drq->hba_index); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6785 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 6786 | } else { |
| 6787 | list_add_tail(&rqb_buffer->hbuf.list, |
| 6788 | &rqbp->rqb_buffer_list); |
| 6789 | rqbp->buffer_count++; |
| 6790 | } |
| 6791 | } |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 6792 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6793 | return 1; |
| 6794 | } |
| 6795 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6796 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 6797 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6798 | * @phba: Pointer to HBA context object. |
| 6799 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 6800 | * This function is the main SLI4 device initialization PCI function. This |
| 6801 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6802 | * HBA error attention handler code. Caller is not required to hold any |
| 6803 | * locks. |
| 6804 | **/ |
| 6805 | int |
| 6806 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6807 | { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6808 | int rc, i, cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6809 | LPFC_MBOXQ_t *mboxq; |
| 6810 | struct lpfc_mqe *mqe; |
| 6811 | uint8_t *vpd; |
| 6812 | uint32_t vpd_size; |
| 6813 | uint32_t ftr_rsp = 0; |
| 6814 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6815 | struct lpfc_vport *vport = phba->pport; |
| 6816 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6817 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6818 | |
| 6819 | /* Perform a PCI function reset to start from clean */ |
| 6820 | rc = lpfc_pci_function_reset(phba); |
| 6821 | if (unlikely(rc)) |
| 6822 | return -ENODEV; |
| 6823 | |
| 6824 | /* Check the HBA Host Status Register for readyness */ |
| 6825 | rc = lpfc_sli4_post_status_check(phba); |
| 6826 | if (unlikely(rc)) |
| 6827 | return -ENODEV; |
| 6828 | else { |
| 6829 | spin_lock_irq(&phba->hbalock); |
| 6830 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6831 | spin_unlock_irq(&phba->hbalock); |
| 6832 | } |
| 6833 | |
| 6834 | /* |
| 6835 | * Allocate a single mailbox container for initializing the |
| 6836 | * port. |
| 6837 | */ |
| 6838 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6839 | if (!mboxq) |
| 6840 | return -ENOMEM; |
| 6841 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6842 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6843 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6844 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6845 | if (!vpd) { |
| 6846 | rc = -ENOMEM; |
| 6847 | goto out_free_mbox; |
| 6848 | } |
| 6849 | |
| 6850 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6851 | if (unlikely(rc)) { |
| 6852 | kfree(vpd); |
| 6853 | goto out_free_mbox; |
| 6854 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6855 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6856 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6857 | 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] | 6858 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6859 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6860 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 6861 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6862 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6863 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6864 | |
| 6865 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6866 | LPFC_DCBX_CEE_MODE) |
| 6867 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6868 | else |
| 6869 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6870 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6871 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6872 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6873 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6874 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6875 | "0376 READ_REV Error. SLI Level %d " |
| 6876 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6877 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6878 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6879 | kfree(vpd); |
| 6880 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6881 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6882 | |
| 6883 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6884 | * Continue initialization with default values even if driver failed |
| 6885 | * to read FCoE param config regions, only read parameters if the |
| 6886 | * board is FCoE |
| 6887 | */ |
| 6888 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6889 | lpfc_sli4_read_fcoe_params(phba)) |
| 6890 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6891 | "2570 Failed to read FCoE parameters\n"); |
| 6892 | |
| 6893 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6894 | * Retrieve sli4 device physical port name, failure of doing it |
| 6895 | * is considered as non-fatal. |
| 6896 | */ |
| 6897 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6898 | if (!rc) |
| 6899 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6900 | "3080 Successful retrieving SLI4 device " |
| 6901 | "physical port name: %s.\n", phba->Port); |
| 6902 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6903 | /* |
| 6904 | * Evaluate the read rev and vpd data. Populate the driver |
| 6905 | * state with the results. If this routine fails, the failure |
| 6906 | * is not fatal as the driver will use generic values. |
| 6907 | */ |
| 6908 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6909 | if (unlikely(!rc)) { |
| 6910 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6911 | "0377 Error %d parsing vpd. " |
| 6912 | "Using defaults.\n", rc); |
| 6913 | rc = 0; |
| 6914 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6915 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6916 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6917 | /* Save information as VPD data */ |
| 6918 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6919 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 6920 | |
| 6921 | /* |
| 6922 | * This is because first G7 ASIC doesn't support the standard |
| 6923 | * 0x5a NVME cmd descriptor type/subtype |
| 6924 | */ |
| 6925 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 6926 | LPFC_SLI_INTF_IF_TYPE_6) && |
| 6927 | (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) && |
| 6928 | (phba->vpd.rev.smRev == 0) && |
| 6929 | (phba->cfg_nvme_embed_cmd == 1)) |
| 6930 | phba->cfg_nvme_embed_cmd = 0; |
| 6931 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6932 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6933 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6934 | &mqe->un.read_rev); |
| 6935 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6936 | &mqe->un.read_rev); |
| 6937 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6938 | &mqe->un.read_rev); |
| 6939 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6940 | &mqe->un.read_rev); |
| 6941 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6942 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6943 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6944 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6945 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6946 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6947 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6948 | "(%d):0380 READ_REV Status x%x " |
| 6949 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6950 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6951 | bf_get(lpfc_mqe_status, mqe), |
| 6952 | phba->vpd.rev.opFwName, |
| 6953 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6954 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6955 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6956 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 6957 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 6958 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 6959 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6960 | "3362 LUN queue depth changed from %d to %d\n", |
| 6961 | phba->pport->cfg_lun_queue_depth, rc); |
| 6962 | phba->pport->cfg_lun_queue_depth = rc; |
| 6963 | } |
| 6964 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6965 | 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] | 6966 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6967 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 6968 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6969 | if (rc == MBX_SUCCESS) { |
| 6970 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 6971 | /* Set 1Sec interval to detect UE */ |
| 6972 | phba->eratt_poll_interval = 1; |
| 6973 | phba->sli4_hba.ue_to_sr = bf_get( |
| 6974 | lpfc_mbx_set_feature_UESR, |
| 6975 | &mboxq->u.mqe.un.set_feature); |
| 6976 | phba->sli4_hba.ue_to_rp = bf_get( |
| 6977 | lpfc_mbx_set_feature_UERP, |
| 6978 | &mboxq->u.mqe.un.set_feature); |
| 6979 | } |
| 6980 | } |
| 6981 | |
| 6982 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 6983 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 6984 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 6985 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6986 | if (rc != MBX_SUCCESS) |
| 6987 | phba->mds_diags_support = 0; |
| 6988 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6989 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6990 | /* |
| 6991 | * Discover the port's supported feature set and match it against the |
| 6992 | * hosts requests. |
| 6993 | */ |
| 6994 | lpfc_request_features(phba, mboxq); |
| 6995 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6996 | if (unlikely(rc)) { |
| 6997 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6998 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6999 | } |
| 7000 | |
| 7001 | /* |
| 7002 | * The port must support FCP initiator mode as this is the |
| 7003 | * only mode running in the host. |
| 7004 | */ |
| 7005 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 7006 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7007 | "0378 No support for fcpi mode.\n"); |
| 7008 | ftr_rsp++; |
| 7009 | } |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 7010 | |
| 7011 | /* Performance Hints are ONLY for FCoE */ |
| 7012 | if (phba->hba_flag & HBA_FCOE_MODE) { |
| 7013 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 7014 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 7015 | else |
| 7016 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
| 7017 | } |
| 7018 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7019 | /* |
| 7020 | * If the port cannot support the host's requested features |
| 7021 | * then turn off the global config parameters to disable the |
| 7022 | * feature in the driver. This is not a fatal error. |
| 7023 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7024 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 7025 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) { |
| 7026 | phba->cfg_enable_bg = 0; |
| 7027 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7028 | ftr_rsp++; |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 7029 | } |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 7030 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7031 | |
| 7032 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 7033 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7034 | ftr_rsp++; |
| 7035 | |
| 7036 | if (ftr_rsp) { |
| 7037 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7038 | "0379 Feature Mismatch Data: x%08x %08x " |
| 7039 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 7040 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 7041 | phba->cfg_enable_npiv, phba->max_vpi); |
| 7042 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 7043 | phba->cfg_enable_bg = 0; |
| 7044 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 7045 | phba->cfg_enable_npiv = 0; |
| 7046 | } |
| 7047 | |
| 7048 | /* These SLI3 features are assumed in SLI4 */ |
| 7049 | spin_lock_irq(&phba->hbalock); |
| 7050 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 7051 | spin_unlock_irq(&phba->hbalock); |
| 7052 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7053 | /* |
| 7054 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 7055 | * calls depends on these resources to complete port setup. |
| 7056 | */ |
| 7057 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 7058 | if (rc) { |
| 7059 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7060 | "2920 Failed to alloc Resource IDs " |
| 7061 | "rc = x%x\n", rc); |
| 7062 | goto out_free_mbox; |
| 7063 | } |
| 7064 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 7065 | lpfc_set_host_data(phba, mboxq); |
| 7066 | |
| 7067 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7068 | if (rc) { |
| 7069 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 7070 | "2134 Failed to set host os driver version %x", |
| 7071 | rc); |
| 7072 | } |
| 7073 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7074 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7075 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 7076 | if (rc) { |
| 7077 | phba->link_state = LPFC_HBA_ERROR; |
| 7078 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7079 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 7080 | } |
| 7081 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7082 | mboxq->vport = vport; |
| 7083 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7084 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 7085 | if (rc == MBX_SUCCESS) { |
| 7086 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 7087 | rc = 0; |
| 7088 | } |
| 7089 | |
| 7090 | /* |
| 7091 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 7092 | * it to the mbuf pool. |
| 7093 | */ |
| 7094 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 7095 | kfree(mp); |
| 7096 | mboxq->context1 = NULL; |
| 7097 | if (unlikely(rc)) { |
| 7098 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7099 | "0382 READ_SPARAM command failed " |
| 7100 | "status %d, mbxStatus x%x\n", |
| 7101 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 7102 | phba->link_state = LPFC_HBA_ERROR; |
| 7103 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7104 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7105 | } |
| 7106 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7107 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7108 | |
| 7109 | /* Update the fc_host data structures with new wwn. */ |
| 7110 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 7111 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 7112 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7113 | /* Create all the SLI4 queues */ |
| 7114 | rc = lpfc_sli4_queue_create(phba); |
| 7115 | if (rc) { |
| 7116 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7117 | "3089 Failed to allocate queues\n"); |
| 7118 | rc = -ENODEV; |
| 7119 | goto out_free_mbox; |
| 7120 | } |
| 7121 | /* Set up all the queues to the device */ |
| 7122 | rc = lpfc_sli4_queue_setup(phba); |
| 7123 | if (unlikely(rc)) { |
| 7124 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7125 | "0381 Error %d during queue setup.\n ", rc); |
| 7126 | goto out_stop_timers; |
| 7127 | } |
| 7128 | /* Initialize the driver internal SLI layer lists. */ |
| 7129 | lpfc_sli4_setup(phba); |
| 7130 | lpfc_sli4_queue_init(phba); |
| 7131 | |
| 7132 | /* update host els xri-sgl sizes and mappings */ |
| 7133 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7134 | if (unlikely(rc)) { |
| 7135 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7136 | "1400 Failed to update xri-sgl size and " |
| 7137 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7138 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7139 | } |
| 7140 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7141 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7142 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 7143 | phba->sli4_hba.els_xri_cnt); |
| 7144 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7145 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7146 | "0582 Error %d during els sgl post " |
| 7147 | "operation\n", rc); |
| 7148 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7149 | goto out_destroy_queue; |
| 7150 | } |
| 7151 | phba->sli4_hba.els_xri_cnt = rc; |
| 7152 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7153 | if (phba->nvmet_support) { |
| 7154 | /* update host nvmet xri-sgl sizes and mappings */ |
| 7155 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 7156 | if (unlikely(rc)) { |
| 7157 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7158 | "6308 Failed to update nvmet-sgl size " |
| 7159 | "and mapping: %d\n", rc); |
| 7160 | goto out_destroy_queue; |
| 7161 | } |
| 7162 | |
| 7163 | /* register the nvmet sgl pool to the port */ |
| 7164 | rc = lpfc_sli4_repost_sgl_list( |
| 7165 | phba, |
| 7166 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 7167 | phba->sli4_hba.nvmet_xri_cnt); |
| 7168 | if (unlikely(rc < 0)) { |
| 7169 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7170 | "3117 Error %d during nvmet " |
| 7171 | "sgl post\n", rc); |
| 7172 | rc = -ENODEV; |
| 7173 | goto out_destroy_queue; |
| 7174 | } |
| 7175 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7176 | |
| 7177 | cnt = phba->cfg_iocb_cnt * 1024; |
| 7178 | /* We need 1 iocbq for every SGL, for IO processing */ |
| 7179 | cnt += phba->sli4_hba.nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7180 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7181 | /* update host scsi xri-sgl sizes and mappings */ |
| 7182 | rc = lpfc_sli4_scsi_sgl_update(phba); |
| 7183 | if (unlikely(rc)) { |
| 7184 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7185 | "6309 Failed to update scsi-sgl size " |
| 7186 | "and mapping: %d\n", rc); |
| 7187 | goto out_destroy_queue; |
| 7188 | } |
| 7189 | |
| 7190 | /* update host nvme xri-sgl sizes and mappings */ |
| 7191 | rc = lpfc_sli4_nvme_sgl_update(phba); |
| 7192 | if (unlikely(rc)) { |
| 7193 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7194 | "6082 Failed to update nvme-sgl size " |
| 7195 | "and mapping: %d\n", rc); |
| 7196 | goto out_destroy_queue; |
| 7197 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7198 | |
| 7199 | cnt = phba->cfg_iocb_cnt * 1024; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7200 | } |
| 7201 | |
| 7202 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7203 | /* Initialize and populate the iocb list per host */ |
| 7204 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7205 | "2821 initialize iocb list %d total %d\n", |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7206 | phba->cfg_iocb_cnt, cnt); |
| 7207 | rc = lpfc_init_iocb_list(phba, cnt); |
| 7208 | if (rc) { |
| 7209 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7210 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7211 | goto out_destroy_queue; |
| 7212 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7213 | } |
| 7214 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 7215 | if (phba->nvmet_support) |
| 7216 | lpfc_nvmet_create_targetport(phba); |
| 7217 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7218 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7219 | /* Post initial buffers to all RQs created */ |
| 7220 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 7221 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 7222 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 7223 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 7224 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 7225 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7226 | rqbp->buffer_count = 0; |
| 7227 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7228 | lpfc_post_rq_buffer( |
| 7229 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 7230 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | 2448e48 | 2018-04-09 14:24:24 -0700 | [diff] [blame] | 7231 | phba->cfg_nvmet_mrq_post, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7232 | } |
| 7233 | } |
| 7234 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7235 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 7236 | /* register the allocated scsi sgl pool to the port */ |
| 7237 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 7238 | if (unlikely(rc)) { |
| 7239 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7240 | "0383 Error %d during scsi sgl post " |
| 7241 | "operation\n", rc); |
| 7242 | /* Some Scsi buffers were moved to abort scsi list */ |
| 7243 | /* A pci function reset will repost them */ |
| 7244 | rc = -ENODEV; |
| 7245 | goto out_destroy_queue; |
| 7246 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7247 | } |
| 7248 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 7249 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 7250 | (phba->nvmet_support == 0)) { |
| 7251 | |
| 7252 | /* register the allocated nvme sgl pool to the port */ |
| 7253 | rc = lpfc_repost_nvme_sgl_list(phba); |
| 7254 | if (unlikely(rc)) { |
| 7255 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7256 | "6116 Error %d during nvme sgl post " |
| 7257 | "operation\n", rc); |
| 7258 | /* Some NVME buffers were moved to abort nvme list */ |
| 7259 | /* A pci function reset will repost them */ |
| 7260 | rc = -ENODEV; |
| 7261 | goto out_destroy_queue; |
| 7262 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7263 | } |
| 7264 | |
| 7265 | /* Post the rpi header region to the device. */ |
| 7266 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7267 | if (unlikely(rc)) { |
| 7268 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7269 | "0393 Error %d during rpi post operation\n", |
| 7270 | rc); |
| 7271 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7272 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7273 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7274 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7275 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7276 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7277 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7278 | /* |
| 7279 | * The FC Port needs to register FCFI (index 0) |
| 7280 | */ |
| 7281 | lpfc_reg_fcfi(phba, mboxq); |
| 7282 | mboxq->vport = phba->pport; |
| 7283 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7284 | if (rc != MBX_SUCCESS) |
| 7285 | goto out_unset_queue; |
| 7286 | rc = 0; |
| 7287 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7288 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7289 | } else { |
| 7290 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7291 | |
| 7292 | /* First register the FCFI */ |
| 7293 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7294 | mboxq->vport = phba->pport; |
| 7295 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7296 | if (rc != MBX_SUCCESS) |
| 7297 | goto out_unset_queue; |
| 7298 | rc = 0; |
| 7299 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7300 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7301 | |
| 7302 | /* Next register the MRQs */ |
| 7303 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7304 | mboxq->vport = phba->pport; |
| 7305 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7306 | if (rc != MBX_SUCCESS) |
| 7307 | goto out_unset_queue; |
| 7308 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7309 | } |
| 7310 | /* Check if the port is configured to be disabled */ |
| 7311 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7312 | } |
| 7313 | |
| 7314 | /* Arm the CQs and then EQs on device */ |
| 7315 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7316 | |
| 7317 | /* Indicate device interrupt mode */ |
| 7318 | phba->sli4_hba.intr_enable = 1; |
| 7319 | |
| 7320 | /* Allow asynchronous mailbox command to go through */ |
| 7321 | spin_lock_irq(&phba->hbalock); |
| 7322 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7323 | spin_unlock_irq(&phba->hbalock); |
| 7324 | |
| 7325 | /* Post receive buffers to the device */ |
| 7326 | lpfc_sli4_rb_setup(phba); |
| 7327 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7328 | /* Reset HBA FCF states after HBA reset */ |
| 7329 | phba->fcf.fcf_flag = 0; |
| 7330 | phba->fcf.current_rec.flag = 0; |
| 7331 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7332 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7333 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7334 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7335 | |
| 7336 | /* Start heart beat timer */ |
| 7337 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7338 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7339 | phba->hb_outstanding = 0; |
| 7340 | phba->last_completion_time = jiffies; |
| 7341 | |
| 7342 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7343 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7344 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7345 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7346 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7347 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7348 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7349 | if (!rc) { |
| 7350 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7351 | "2829 This device supports " |
| 7352 | "Advanced Error Reporting (AER)\n"); |
| 7353 | spin_lock_irq(&phba->hbalock); |
| 7354 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7355 | spin_unlock_irq(&phba->hbalock); |
| 7356 | } else { |
| 7357 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7358 | "2830 This device does not support " |
| 7359 | "Advanced Error Reporting (AER)\n"); |
| 7360 | phba->cfg_aer_support = 0; |
| 7361 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7362 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7363 | } |
| 7364 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7365 | /* |
| 7366 | * The port is ready, set the host's link state to LINK_DOWN |
| 7367 | * in preparation for link interrupts. |
| 7368 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7369 | spin_lock_irq(&phba->hbalock); |
| 7370 | phba->link_state = LPFC_LINK_DOWN; |
| 7371 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7372 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7373 | (phba->hba_flag & LINK_DISABLED)) { |
| 7374 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7375 | "3103 Adapter Link is disabled.\n"); |
| 7376 | lpfc_down_link(phba, mboxq); |
| 7377 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7378 | if (rc != MBX_SUCCESS) { |
| 7379 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7380 | "3104 Adapter failed to issue " |
| 7381 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 7382 | goto out_unset_queue; |
| 7383 | } |
| 7384 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7385 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7386 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7387 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7388 | if (rc) |
| 7389 | goto out_unset_queue; |
| 7390 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7391 | } |
| 7392 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7393 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7394 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7395 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7396 | lpfc_sli4_queue_unset(phba); |
| 7397 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7398 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7399 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7400 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7401 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7402 | out_free_mbox: |
| 7403 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7404 | return rc; |
| 7405 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7406 | |
| 7407 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7408 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7409 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7410 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7411 | * This is the callback function for mailbox timer. The mailbox |
| 7412 | * timer is armed when a new mailbox command is issued and the timer |
| 7413 | * is deleted when the mailbox complete. The function is called by |
| 7414 | * the kernel timer code when a mailbox does not complete within |
| 7415 | * expected time. This function wakes up the worker thread to |
| 7416 | * process the mailbox timeout and returns. All the processing is |
| 7417 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 7418 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7419 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7420 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7421 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7422 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7423 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7424 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7425 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7426 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7427 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7428 | if (!tmo_posted) |
| 7429 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 7430 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 7431 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7432 | if (!tmo_posted) |
| 7433 | lpfc_worker_wake_up(phba); |
| 7434 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7435 | } |
| 7436 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7437 | /** |
| 7438 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 7439 | * are pending |
| 7440 | * @phba: Pointer to HBA context object. |
| 7441 | * |
| 7442 | * This function checks if any mailbox completions are present on the mailbox |
| 7443 | * completion queue. |
| 7444 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 7445 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7446 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 7447 | { |
| 7448 | |
| 7449 | uint32_t idx; |
| 7450 | struct lpfc_queue *mcq; |
| 7451 | struct lpfc_mcqe *mcqe; |
| 7452 | bool pending_completions = false; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7453 | uint8_t qe_valid; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7454 | |
| 7455 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7456 | return false; |
| 7457 | |
| 7458 | /* Check for completions on mailbox completion queue */ |
| 7459 | |
| 7460 | mcq = phba->sli4_hba.mbx_cq; |
| 7461 | idx = mcq->hba_index; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7462 | qe_valid = mcq->qe_valid; |
| 7463 | 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] | 7464 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 7465 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 7466 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 7467 | pending_completions = true; |
| 7468 | break; |
| 7469 | } |
| 7470 | idx = (idx + 1) % mcq->entry_count; |
| 7471 | if (mcq->hba_index == idx) |
| 7472 | break; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 7473 | |
| 7474 | /* if the index wrapped around, toggle the valid bit */ |
| 7475 | if (phba->sli4_hba.pc_sli4_params.cqav && !idx) |
| 7476 | qe_valid = (qe_valid) ? 0 : 1; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7477 | } |
| 7478 | return pending_completions; |
| 7479 | |
| 7480 | } |
| 7481 | |
| 7482 | /** |
| 7483 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 7484 | * that were missed. |
| 7485 | * @phba: Pointer to HBA context object. |
| 7486 | * |
| 7487 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 7488 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 7489 | * checks to see if mbox completions are on the mailbox completion queue |
| 7490 | * and will process all the completions associated with the eq for the |
| 7491 | * mailbox completion queue. |
| 7492 | **/ |
| 7493 | bool |
| 7494 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 7495 | { |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7496 | struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7497 | uint32_t eqidx; |
| 7498 | struct lpfc_queue *fpeq = NULL; |
| 7499 | struct lpfc_eqe *eqe; |
| 7500 | bool mbox_pending; |
| 7501 | |
| 7502 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7503 | return false; |
| 7504 | |
| 7505 | /* Find the eq associated with the mcq */ |
| 7506 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7507 | if (sli4_hba->hba_eq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7508 | for (eqidx = 0; eqidx < phba->io_channel_irqs; eqidx++) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7509 | if (sli4_hba->hba_eq[eqidx]->queue_id == |
| 7510 | sli4_hba->mbx_cq->assoc_qid) { |
| 7511 | fpeq = sli4_hba->hba_eq[eqidx]; |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7512 | break; |
| 7513 | } |
| 7514 | if (!fpeq) |
| 7515 | return false; |
| 7516 | |
| 7517 | /* Turn off interrupts from this EQ */ |
| 7518 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7519 | sli4_hba->sli4_eq_clr_intr(fpeq); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7520 | |
| 7521 | /* Check to see if a mbox completion is pending */ |
| 7522 | |
| 7523 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 7524 | |
| 7525 | /* |
| 7526 | * If a mbox completion is pending, process all the events on EQ |
| 7527 | * associated with the mbox completion queue (this could include |
| 7528 | * mailbox commands, async events, els commands, receive queue data |
| 7529 | * and fcp commands) |
| 7530 | */ |
| 7531 | |
| 7532 | if (mbox_pending) |
| 7533 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 7534 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); |
| 7535 | fpeq->EQ_processed++; |
| 7536 | } |
| 7537 | |
| 7538 | /* Always clear and re-arm the EQ */ |
| 7539 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 7540 | sli4_hba->sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7541 | |
| 7542 | return mbox_pending; |
| 7543 | |
| 7544 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7545 | |
| 7546 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7547 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7548 | * @phba: Pointer to HBA context object. |
| 7549 | * |
| 7550 | * This function is called from worker thread when a mailbox command times out. |
| 7551 | * The caller is not required to hold any locks. This function will reset the |
| 7552 | * HBA and recover all the pending commands. |
| 7553 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7554 | void |
| 7555 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 7556 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7557 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7558 | MAILBOX_t *mb = NULL; |
| 7559 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7560 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7561 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7562 | /* If the mailbox completed, process the completion and return */ |
| 7563 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 7564 | return; |
| 7565 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7566 | if (pmbox != NULL) |
| 7567 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7568 | /* Check the pmbox pointer first. There is a race condition |
| 7569 | * between the mbox timeout handler getting executed in the |
| 7570 | * worklist and the mailbox actually completing. When this |
| 7571 | * race condition occurs, the mbox_active will be NULL. |
| 7572 | */ |
| 7573 | spin_lock_irq(&phba->hbalock); |
| 7574 | if (pmbox == NULL) { |
| 7575 | lpfc_printf_log(phba, KERN_WARNING, |
| 7576 | LOG_MBOX | LOG_SLI, |
| 7577 | "0353 Active Mailbox cleared - mailbox timeout " |
| 7578 | "exiting\n"); |
| 7579 | spin_unlock_irq(&phba->hbalock); |
| 7580 | return; |
| 7581 | } |
| 7582 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7583 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7584 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7585 | "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] | 7586 | mb->mbxCommand, |
| 7587 | phba->pport->port_state, |
| 7588 | phba->sli.sli_flag, |
| 7589 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7590 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7591 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7592 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 7593 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7594 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7595 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7596 | spin_lock_irq(&phba->pport->work_port_lock); |
| 7597 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 7598 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 7599 | spin_lock_irq(&phba->hbalock); |
| 7600 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 7601 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7602 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7603 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 7604 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7605 | |
| 7606 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 7607 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7608 | |
| 7609 | /* Reset the HBA device */ |
| 7610 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7611 | } |
| 7612 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7613 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7614 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7615 | * @phba: Pointer to HBA context object. |
| 7616 | * @pmbox: Pointer to mailbox object. |
| 7617 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7618 | * |
| 7619 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7620 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 7621 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7622 | * The mailbox command can be submitted in polling mode, in which case |
| 7623 | * this function will wait in a polling loop for the completion of the |
| 7624 | * mailbox. |
| 7625 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 7626 | * function will submit the command and returns immediately without waiting |
| 7627 | * for the mailbox completion. The no_wait is supported only when HBA |
| 7628 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 7629 | * The SLI interface allows only one mailbox pending at a time. If the |
| 7630 | * mailbox is issued in polling mode and there is already a mailbox |
| 7631 | * pending, then the function will return an error. If the mailbox is issued |
| 7632 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 7633 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 7634 | * The sli layer owns the mailbox object until the completion of mailbox |
| 7635 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 7636 | * return codes the caller owns the mailbox command after the return of |
| 7637 | * the function. |
| 7638 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7639 | static int |
| 7640 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 7641 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7642 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7643 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7644 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7645 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7646 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7647 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7648 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7649 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7650 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7651 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7652 | int processing_queue = 0; |
| 7653 | |
| 7654 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7655 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 7656 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7657 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7658 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7659 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7660 | return MBX_SUCCESS; |
| 7661 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7662 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7663 | pmbox = lpfc_mbox_get(phba); |
| 7664 | if (!pmbox) { |
| 7665 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7666 | return MBX_SUCCESS; |
| 7667 | } |
| 7668 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7669 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7670 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7671 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7672 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7673 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7674 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7675 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7676 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7677 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7678 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7679 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7680 | } |
| 7681 | } |
| 7682 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7683 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7684 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 7685 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7686 | goto out_not_finished; |
| 7687 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7688 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7689 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7690 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 7691 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7692 | goto out_not_finished; |
| 7693 | } |
| 7694 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7695 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7696 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7697 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7698 | status = MBX_SUCCESS; |
| 7699 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7700 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 7701 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7702 | |
| 7703 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7704 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7705 | "(%d):0311 Mailbox command x%x cannot " |
| 7706 | "issue Data: x%x x%x\n", |
| 7707 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7708 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7709 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7710 | } |
| 7711 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7712 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7713 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 7714 | !(hc_copy & HC_MBINT_ENA)) { |
| 7715 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7716 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7717 | "(%d):2528 Mailbox command x%x cannot " |
| 7718 | "issue Data: x%x x%x\n", |
| 7719 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7720 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7721 | goto out_not_finished; |
| 7722 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 7723 | } |
| 7724 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7725 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7726 | /* Polling for a mbox command when another one is already active |
| 7727 | * is not allowed in SLI. Also, the driver must have established |
| 7728 | * SLI2 mode to queue and process multiple mbox commands. |
| 7729 | */ |
| 7730 | |
| 7731 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7732 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7733 | |
| 7734 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7735 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7736 | "(%d):2529 Mailbox command x%x " |
| 7737 | "cannot issue Data: x%x x%x\n", |
| 7738 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7739 | pmbox->u.mb.mbxCommand, |
| 7740 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7741 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7742 | } |
| 7743 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7744 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7745 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7746 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7747 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7748 | "(%d):2530 Mailbox command x%x " |
| 7749 | "cannot issue Data: x%x x%x\n", |
| 7750 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7751 | pmbox->u.mb.mbxCommand, |
| 7752 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7753 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7754 | } |
| 7755 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7756 | /* Another mailbox command is still being processed, queue this |
| 7757 | * command to be processed later. |
| 7758 | */ |
| 7759 | lpfc_mbox_put(phba, pmbox); |
| 7760 | |
| 7761 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7762 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7763 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7764 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7765 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 7766 | mbx->mbxCommand, |
| 7767 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7768 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7769 | |
| 7770 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7771 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7772 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7773 | if (pmbox->vport) { |
| 7774 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7775 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7776 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7777 | (uint32_t)mbx->mbxCommand, |
| 7778 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7779 | } |
| 7780 | else { |
| 7781 | lpfc_debugfs_disc_trc(phba->pport, |
| 7782 | LPFC_DISC_TRC_MBOX, |
| 7783 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7784 | (uint32_t)mbx->mbxCommand, |
| 7785 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7786 | } |
| 7787 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7788 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7789 | } |
| 7790 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7791 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7792 | |
| 7793 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 7794 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7795 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7796 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7797 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7798 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7799 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7800 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7801 | "(%d):2531 Mailbox command x%x " |
| 7802 | "cannot issue Data: x%x x%x\n", |
| 7803 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7804 | pmbox->u.mb.mbxCommand, |
| 7805 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7806 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7807 | } |
| 7808 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7809 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7810 | 1000); |
| 7811 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7812 | } |
| 7813 | |
| 7814 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7815 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7816 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7817 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7818 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 7819 | mbx->mbxCommand, |
| 7820 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7821 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7822 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7823 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7824 | if (pmbox->vport) { |
| 7825 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7826 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7827 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7828 | (uint32_t)mbx->mbxCommand, |
| 7829 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7830 | } |
| 7831 | else { |
| 7832 | lpfc_debugfs_disc_trc(phba->pport, |
| 7833 | LPFC_DISC_TRC_MBOX, |
| 7834 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7835 | (uint32_t)mbx->mbxCommand, |
| 7836 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7837 | } |
| 7838 | } |
| 7839 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7840 | psli->slistat.mbox_cmd++; |
| 7841 | evtctr = psli->slistat.mbox_event; |
| 7842 | |
| 7843 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7844 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7845 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7846 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7847 | /* Populate mbox extension offset word. */ |
| 7848 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7849 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7850 | = (uint8_t *)phba->mbox_ext |
| 7851 | - (uint8_t *)phba->mbox; |
| 7852 | } |
| 7853 | |
| 7854 | /* Copy the mailbox extension data */ |
| 7855 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7856 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 7857 | (uint8_t *)phba->mbox_ext, |
| 7858 | pmbox->in_ext_byte_len); |
| 7859 | } |
| 7860 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7861 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7862 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7863 | /* Populate mbox extension offset word. */ |
| 7864 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7865 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7866 | = MAILBOX_HBA_EXT_OFFSET; |
| 7867 | |
| 7868 | /* Copy the mailbox extension data */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7869 | if (pmbox->in_ext_byte_len && pmbox->context2) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7870 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 7871 | MAILBOX_HBA_EXT_OFFSET, |
| 7872 | pmbox->context2, pmbox->in_ext_byte_len); |
| 7873 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7874 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7875 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7876 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 7877 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7878 | |
| 7879 | /* First copy mbox command data to HBA SLIM, skip past first |
| 7880 | word */ |
| 7881 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7882 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7883 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 7884 | |
| 7885 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7886 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7887 | to_slim = phba->MBslimaddr; |
| 7888 | writel(ldata, to_slim); |
| 7889 | readl(to_slim); /* flush */ |
| 7890 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7891 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7892 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7893 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7894 | } |
| 7895 | |
| 7896 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7897 | |
| 7898 | switch (flag) { |
| 7899 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7900 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7901 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7902 | /* Interrupt board to do it */ |
| 7903 | writel(CA_MBATT, phba->CAregaddr); |
| 7904 | readl(phba->CAregaddr); /* flush */ |
| 7905 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7906 | break; |
| 7907 | |
| 7908 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7909 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7910 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7911 | /* Interrupt board to do it */ |
| 7912 | writel(CA_MBATT, phba->CAregaddr); |
| 7913 | readl(phba->CAregaddr); /* flush */ |
| 7914 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7915 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7916 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7917 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7918 | word0 = le32_to_cpu(word0); |
| 7919 | } else { |
| 7920 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7921 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 7922 | spin_unlock_irqrestore(&phba->hbalock, |
| 7923 | drvr_flag); |
| 7924 | goto out_not_finished; |
| 7925 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7926 | } |
| 7927 | |
| 7928 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7929 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7930 | spin_unlock_irqrestore(&phba->hbalock, |
| 7931 | drvr_flag); |
| 7932 | goto out_not_finished; |
| 7933 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7934 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7935 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7936 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7937 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7938 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 7939 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7940 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7941 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7942 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7943 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7944 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7945 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7946 | } |
| 7947 | |
| 7948 | /* Check if we took a mbox interrupt while we were |
| 7949 | polling */ |
| 7950 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 7951 | && (evtctr != psli->slistat.mbox_event)) |
| 7952 | break; |
| 7953 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7954 | if (i++ > 10) { |
| 7955 | spin_unlock_irqrestore(&phba->hbalock, |
| 7956 | drvr_flag); |
| 7957 | msleep(1); |
| 7958 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7959 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7960 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7961 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7962 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7963 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7964 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7965 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7966 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7967 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7968 | /* Check real SLIM for any errors */ |
| 7969 | slimword0 = readl(phba->MBslimaddr); |
| 7970 | slimmb = (MAILBOX_t *) & slimword0; |
| 7971 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 7972 | && slimmb->mbxStatus) { |
| 7973 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7974 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7975 | word0 = slimword0; |
| 7976 | } |
| 7977 | } |
| 7978 | } else { |
| 7979 | /* First copy command data */ |
| 7980 | word0 = readl(phba->MBslimaddr); |
| 7981 | } |
| 7982 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7983 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7984 | spin_unlock_irqrestore(&phba->hbalock, |
| 7985 | drvr_flag); |
| 7986 | goto out_not_finished; |
| 7987 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7988 | } |
| 7989 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7990 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7991 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7992 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 7993 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7994 | /* Copy the mailbox extension data */ |
| 7995 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7996 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 7997 | pmbox->context2, |
| 7998 | pmbox->out_ext_byte_len); |
| 7999 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8000 | } else { |
| 8001 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8002 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8003 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8004 | /* Copy the mailbox extension data */ |
| 8005 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 8006 | lpfc_memcpy_from_slim(pmbox->context2, |
| 8007 | phba->MBslimaddr + |
| 8008 | MAILBOX_HBA_EXT_OFFSET, |
| 8009 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8010 | } |
| 8011 | } |
| 8012 | |
| 8013 | writel(HA_MBATT, phba->HAregaddr); |
| 8014 | readl(phba->HAregaddr); /* flush */ |
| 8015 | |
| 8016 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 8017 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8018 | } |
| 8019 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8020 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 8021 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8022 | |
| 8023 | out_not_finished: |
| 8024 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8025 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 8026 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 8027 | } |
| 8028 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8029 | } |
| 8030 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8031 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8032 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 8033 | * @phba: Pointer to HBA context object. |
| 8034 | * |
| 8035 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 8036 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 8037 | * possible outstanding mailbox command before return. |
| 8038 | * |
| 8039 | * Returns: |
| 8040 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 8041 | * the outstanding mailbox command timed out. |
| 8042 | **/ |
| 8043 | static int |
| 8044 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 8045 | { |
| 8046 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8047 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8048 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8049 | |
| 8050 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 8051 | spin_lock_irq(&phba->hbalock); |
| 8052 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8053 | /* Determine how long we might wait for the active mailbox |
| 8054 | * command to be gracefully completed by firmware. |
| 8055 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8056 | if (phba->sli.mbox_active) |
| 8057 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 8058 | phba->sli.mbox_active) * |
| 8059 | 1000) + jiffies; |
| 8060 | spin_unlock_irq(&phba->hbalock); |
| 8061 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 8062 | /* Make sure the mailbox is really active */ |
| 8063 | if (timeout) |
| 8064 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 8065 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8066 | /* Wait for the outstnading mailbox command to complete */ |
| 8067 | while (phba->sli.mbox_active) { |
| 8068 | /* Check active mailbox complete status every 2ms */ |
| 8069 | msleep(2); |
| 8070 | if (time_after(jiffies, timeout)) { |
| 8071 | /* Timeout, marked the outstanding cmd not complete */ |
| 8072 | rc = 1; |
| 8073 | break; |
| 8074 | } |
| 8075 | } |
| 8076 | |
| 8077 | /* Can not cleanly block async mailbox command, fails it */ |
| 8078 | if (rc) { |
| 8079 | spin_lock_irq(&phba->hbalock); |
| 8080 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8081 | spin_unlock_irq(&phba->hbalock); |
| 8082 | } |
| 8083 | return rc; |
| 8084 | } |
| 8085 | |
| 8086 | /** |
| 8087 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 8088 | * @phba: Pointer to HBA context object. |
| 8089 | * |
| 8090 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 8091 | * commands from the driver internal pending mailbox queue. It makes sure |
| 8092 | * that there is no outstanding mailbox command before resuming posting |
| 8093 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 8094 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 8095 | * mailbox command posting. |
| 8096 | **/ |
| 8097 | static void |
| 8098 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 8099 | { |
| 8100 | struct lpfc_sli *psli = &phba->sli; |
| 8101 | |
| 8102 | spin_lock_irq(&phba->hbalock); |
| 8103 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8104 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 8105 | spin_unlock_irq(&phba->hbalock); |
| 8106 | return; |
| 8107 | } |
| 8108 | |
| 8109 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 8110 | * successful or timeout, after timing-out the outstanding mailbox |
| 8111 | * command shall always be removed, so just unblock posting async |
| 8112 | * mailbox command and resume |
| 8113 | */ |
| 8114 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 8115 | spin_unlock_irq(&phba->hbalock); |
| 8116 | |
| 8117 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 8118 | lpfc_worker_wake_up(phba); |
| 8119 | } |
| 8120 | |
| 8121 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8122 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 8123 | * @phba: Pointer to HBA context object. |
| 8124 | * @mboxq: Pointer to mailbox object. |
| 8125 | * |
| 8126 | * The function waits for the bootstrap mailbox register ready bit from |
| 8127 | * port for twice the regular mailbox command timeout value. |
| 8128 | * |
| 8129 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 8130 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 8131 | **/ |
| 8132 | static int |
| 8133 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8134 | { |
| 8135 | uint32_t db_ready; |
| 8136 | unsigned long timeout; |
| 8137 | struct lpfc_register bmbx_reg; |
| 8138 | |
| 8139 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 8140 | * 1000) + jiffies; |
| 8141 | |
| 8142 | do { |
| 8143 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 8144 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 8145 | if (!db_ready) |
| 8146 | msleep(2); |
| 8147 | |
| 8148 | if (time_after(jiffies, timeout)) |
| 8149 | return MBXERR_ERROR; |
| 8150 | } while (!db_ready); |
| 8151 | |
| 8152 | return 0; |
| 8153 | } |
| 8154 | |
| 8155 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8156 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 8157 | * @phba: Pointer to HBA context object. |
| 8158 | * @mboxq: Pointer to mailbox object. |
| 8159 | * |
| 8160 | * The function posts a mailbox to the port. The mailbox is expected |
| 8161 | * to be comletely filled in and ready for the port to operate on it. |
| 8162 | * This routine executes a synchronous completion operation on the |
| 8163 | * mailbox by polling for its completion. |
| 8164 | * |
| 8165 | * The caller must not be holding any locks when calling this routine. |
| 8166 | * |
| 8167 | * Returns: |
| 8168 | * MBX_SUCCESS - mailbox posted successfully |
| 8169 | * Any of the MBX error values. |
| 8170 | **/ |
| 8171 | static int |
| 8172 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 8173 | { |
| 8174 | int rc = MBX_SUCCESS; |
| 8175 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8176 | uint32_t mcqe_status; |
| 8177 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8178 | struct lpfc_sli *psli = &phba->sli; |
| 8179 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 8180 | struct lpfc_bmbx_create *mbox_rgn; |
| 8181 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8182 | |
| 8183 | /* |
| 8184 | * Only one mailbox can be active to the bootstrap mailbox region |
| 8185 | * at a time and there is no queueing provided. |
| 8186 | */ |
| 8187 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8188 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8189 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8190 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8191 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8192 | "cannot issue Data: x%x x%x\n", |
| 8193 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8194 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8195 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8196 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8197 | psli->sli_flag, MBX_POLL); |
| 8198 | return MBXERR_ERROR; |
| 8199 | } |
| 8200 | /* The server grabs the token and owns it until release */ |
| 8201 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8202 | phba->sli.mbox_active = mboxq; |
| 8203 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8204 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8205 | /* wait for bootstrap mbox register for readyness */ |
| 8206 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8207 | if (rc) |
| 8208 | goto exit; |
| 8209 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8210 | /* |
| 8211 | * Initialize the bootstrap memory region to avoid stale data areas |
| 8212 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 8213 | * the bmbx mailbox region. |
| 8214 | */ |
| 8215 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 8216 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8217 | lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 8218 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8219 | |
| 8220 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 8221 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8222 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 8223 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8224 | /* wait for bootstrap mbox register for hi-address write done */ |
| 8225 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8226 | if (rc) |
| 8227 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8228 | |
| 8229 | /* Post the low mailbox dma address to the port. */ |
| 8230 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8231 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8232 | /* wait for bootstrap mbox register for low address write done */ |
| 8233 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8234 | if (rc) |
| 8235 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8236 | |
| 8237 | /* |
| 8238 | * Read the CQ to ensure the mailbox has completed. |
| 8239 | * If so, update the mailbox status so that the upper layers |
| 8240 | * can complete the request normally. |
| 8241 | */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8242 | lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 8243 | sizeof(struct lpfc_mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8244 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 8245 | lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 8246 | sizeof(struct lpfc_mcqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8247 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8248 | /* |
| 8249 | * When the CQE status indicates a failure and the mailbox status |
| 8250 | * indicates success then copy the CQE status into the mailbox status |
| 8251 | * (and prefix it with x4000). |
| 8252 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8253 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8254 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8255 | bf_set(lpfc_mqe_status, mb, |
| 8256 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8257 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8258 | } else |
| 8259 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8260 | |
| 8261 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8262 | "(%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] | 8263 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8264 | " 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] | 8265 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8266 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8267 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8268 | bf_get(lpfc_mqe_status, mb), |
| 8269 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8270 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8271 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8272 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8273 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8274 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8275 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8276 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8277 | mboxq->mcqe.trailer); |
| 8278 | exit: |
| 8279 | /* We are holding the token, no needed for lock when release */ |
| 8280 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8281 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8282 | phba->sli.mbox_active = NULL; |
| 8283 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8284 | return rc; |
| 8285 | } |
| 8286 | |
| 8287 | /** |
| 8288 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8289 | * @phba: Pointer to HBA context object. |
| 8290 | * @pmbox: Pointer to mailbox object. |
| 8291 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8292 | * |
| 8293 | * This function is called by discovery code and HBA management code to submit |
| 8294 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8295 | * |
| 8296 | * Return codes the caller owns the mailbox command after the return of the |
| 8297 | * function. |
| 8298 | **/ |
| 8299 | static int |
| 8300 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8301 | uint32_t flag) |
| 8302 | { |
| 8303 | struct lpfc_sli *psli = &phba->sli; |
| 8304 | unsigned long iflags; |
| 8305 | int rc; |
| 8306 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8307 | /* dump from issue mailbox command if setup */ |
| 8308 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8309 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8310 | rc = lpfc_mbox_dev_check(phba); |
| 8311 | if (unlikely(rc)) { |
| 8312 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8313 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8314 | "cannot issue Data: x%x x%x\n", |
| 8315 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8316 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8317 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8318 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8319 | psli->sli_flag, flag); |
| 8320 | goto out_not_finished; |
| 8321 | } |
| 8322 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8323 | /* Detect polling mode and jump to a handler */ |
| 8324 | if (!phba->sli4_hba.intr_enable) { |
| 8325 | if (flag == MBX_POLL) |
| 8326 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8327 | else |
| 8328 | rc = -EIO; |
| 8329 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8330 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8331 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8332 | "(x%x/x%x) failure: " |
| 8333 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8334 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8335 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8336 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8337 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8338 | mboxq), |
| 8339 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8340 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8341 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8342 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8343 | bf_get(lpfc_mcqe_ext_status, |
| 8344 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8345 | psli->sli_flag, flag); |
| 8346 | return rc; |
| 8347 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8348 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8349 | "(%d):2542 Try to issue mailbox command " |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8350 | "x%x (x%x/x%x) synchronously ahead of async " |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8351 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8352 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8353 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8354 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8355 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8356 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8357 | /* Try to block the asynchronous mailbox posting */ |
| 8358 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8359 | if (!rc) { |
| 8360 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8361 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8362 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8363 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8364 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8365 | "(%d):2597 Sync Mailbox command " |
| 8366 | "x%x (x%x/x%x) failure: " |
| 8367 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8368 | "Data: x%x x%x\n,", |
| 8369 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8370 | mboxq->u.mb.mbxCommand, |
| 8371 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8372 | mboxq), |
| 8373 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8374 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8375 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8376 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8377 | bf_get(lpfc_mcqe_ext_status, |
| 8378 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8379 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8380 | /* Unblock the async mailbox posting afterward */ |
| 8381 | lpfc_sli4_async_mbox_unblock(phba); |
| 8382 | } |
| 8383 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8384 | } |
| 8385 | |
| 8386 | /* Now, interrupt mode asynchrous mailbox command */ |
| 8387 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8388 | if (rc) { |
| 8389 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8390 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8391 | "cannot issue Data: x%x x%x\n", |
| 8392 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8393 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8394 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8395 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8396 | psli->sli_flag, flag); |
| 8397 | goto out_not_finished; |
| 8398 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8399 | |
| 8400 | /* Put the mailbox command to the driver internal FIFO */ |
| 8401 | psli->slistat.mbox_busy++; |
| 8402 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8403 | lpfc_mbox_put(phba, mboxq); |
| 8404 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8405 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8406 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8407 | "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] | 8408 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 8409 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8410 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8411 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8412 | phba->pport->port_state, |
| 8413 | psli->sli_flag, MBX_NOWAIT); |
| 8414 | /* Wake up worker thread to transport mailbox command from head */ |
| 8415 | lpfc_worker_wake_up(phba); |
| 8416 | |
| 8417 | return MBX_BUSY; |
| 8418 | |
| 8419 | out_not_finished: |
| 8420 | return MBX_NOT_FINISHED; |
| 8421 | } |
| 8422 | |
| 8423 | /** |
| 8424 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 8425 | * @phba: Pointer to HBA context object. |
| 8426 | * |
| 8427 | * This function is called by worker thread to send a mailbox command to |
| 8428 | * SLI4 HBA firmware. |
| 8429 | * |
| 8430 | **/ |
| 8431 | int |
| 8432 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 8433 | { |
| 8434 | struct lpfc_sli *psli = &phba->sli; |
| 8435 | LPFC_MBOXQ_t *mboxq; |
| 8436 | int rc = MBX_SUCCESS; |
| 8437 | unsigned long iflags; |
| 8438 | struct lpfc_mqe *mqe; |
| 8439 | uint32_t mbx_cmnd; |
| 8440 | |
| 8441 | /* Check interrupt mode before post async mailbox command */ |
| 8442 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 8443 | return MBX_NOT_FINISHED; |
| 8444 | |
| 8445 | /* Check for mailbox command service token */ |
| 8446 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8447 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8448 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8449 | return MBX_NOT_FINISHED; |
| 8450 | } |
| 8451 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8452 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8453 | return MBX_NOT_FINISHED; |
| 8454 | } |
| 8455 | if (unlikely(phba->sli.mbox_active)) { |
| 8456 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8457 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8458 | "0384 There is pending active mailbox cmd\n"); |
| 8459 | return MBX_NOT_FINISHED; |
| 8460 | } |
| 8461 | /* Take the mailbox command service token */ |
| 8462 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8463 | |
| 8464 | /* Get the next mailbox command from head of queue */ |
| 8465 | mboxq = lpfc_mbox_get(phba); |
| 8466 | |
| 8467 | /* If no more mailbox command waiting for post, we're done */ |
| 8468 | if (!mboxq) { |
| 8469 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8470 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8471 | return MBX_SUCCESS; |
| 8472 | } |
| 8473 | phba->sli.mbox_active = mboxq; |
| 8474 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8475 | |
| 8476 | /* Check device readiness for posting mailbox command */ |
| 8477 | rc = lpfc_mbox_dev_check(phba); |
| 8478 | if (unlikely(rc)) |
| 8479 | /* Driver clean routine will clean up pending mailbox */ |
| 8480 | goto out_not_finished; |
| 8481 | |
| 8482 | /* Prepare the mbox command to be posted */ |
| 8483 | mqe = &mboxq->u.mqe; |
| 8484 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 8485 | |
| 8486 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 8487 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8488 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8489 | |
| 8490 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8491 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8492 | "x%x x%x\n", |
| 8493 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8494 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8495 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8496 | phba->pport->port_state, psli->sli_flag); |
| 8497 | |
| 8498 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 8499 | if (mboxq->vport) { |
| 8500 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 8501 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8502 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 8503 | mbx_cmnd, mqe->un.mb_words[0], |
| 8504 | mqe->un.mb_words[1]); |
| 8505 | } else { |
| 8506 | lpfc_debugfs_disc_trc(phba->pport, |
| 8507 | LPFC_DISC_TRC_MBOX, |
| 8508 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 8509 | mbx_cmnd, mqe->un.mb_words[0], |
| 8510 | mqe->un.mb_words[1]); |
| 8511 | } |
| 8512 | } |
| 8513 | psli->slistat.mbox_cmd++; |
| 8514 | |
| 8515 | /* Post the mailbox command to the port */ |
| 8516 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 8517 | if (rc != MBX_SUCCESS) { |
| 8518 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8519 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8520 | "cannot issue Data: x%x x%x\n", |
| 8521 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8522 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8523 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8524 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8525 | psli->sli_flag, MBX_NOWAIT); |
| 8526 | goto out_not_finished; |
| 8527 | } |
| 8528 | |
| 8529 | return rc; |
| 8530 | |
| 8531 | out_not_finished: |
| 8532 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 8533 | if (phba->sli.mbox_active) { |
| 8534 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8535 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8536 | /* Release the token */ |
| 8537 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8538 | phba->sli.mbox_active = NULL; |
| 8539 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8540 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8541 | |
| 8542 | return MBX_NOT_FINISHED; |
| 8543 | } |
| 8544 | |
| 8545 | /** |
| 8546 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 8547 | * @phba: Pointer to HBA context object. |
| 8548 | * @pmbox: Pointer to mailbox object. |
| 8549 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8550 | * |
| 8551 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 8552 | * the API jump table function pointer from the lpfc_hba struct. |
| 8553 | * |
| 8554 | * Return codes the caller owns the mailbox command after the return of the |
| 8555 | * function. |
| 8556 | **/ |
| 8557 | int |
| 8558 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 8559 | { |
| 8560 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 8561 | } |
| 8562 | |
| 8563 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8564 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8565 | * @phba: The hba struct for which this call is being executed. |
| 8566 | * @dev_grp: The HBA PCI-Device group number. |
| 8567 | * |
| 8568 | * This routine sets up the mbox interface API function jump table in @phba |
| 8569 | * struct. |
| 8570 | * Returns: 0 - success, -ENODEV - failure. |
| 8571 | **/ |
| 8572 | int |
| 8573 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8574 | { |
| 8575 | |
| 8576 | switch (dev_grp) { |
| 8577 | case LPFC_PCI_DEV_LP: |
| 8578 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 8579 | phba->lpfc_sli_handle_slow_ring_event = |
| 8580 | lpfc_sli_handle_slow_ring_event_s3; |
| 8581 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 8582 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 8583 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 8584 | break; |
| 8585 | case LPFC_PCI_DEV_OC: |
| 8586 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 8587 | phba->lpfc_sli_handle_slow_ring_event = |
| 8588 | lpfc_sli_handle_slow_ring_event_s4; |
| 8589 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 8590 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 8591 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 8592 | break; |
| 8593 | default: |
| 8594 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8595 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 8596 | dev_grp); |
| 8597 | return -ENODEV; |
| 8598 | break; |
| 8599 | } |
| 8600 | return 0; |
| 8601 | } |
| 8602 | |
| 8603 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8604 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8605 | * @phba: Pointer to HBA context object. |
| 8606 | * @pring: Pointer to driver SLI ring object. |
| 8607 | * @piocb: Pointer to address of newly added command iocb. |
| 8608 | * |
| 8609 | * This function is called with hbalock held to add a command |
| 8610 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 8611 | * to the ring. |
| 8612 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8613 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8614 | __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] | 8615 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8616 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8617 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8618 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 8619 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8620 | } |
| 8621 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8622 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8623 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8624 | * @phba: Pointer to HBA context object. |
| 8625 | * @pring: Pointer to driver SLI ring object. |
| 8626 | * @piocb: Pointer to address of newly added command iocb. |
| 8627 | * |
| 8628 | * This function is called with hbalock held before a new |
| 8629 | * iocb is submitted to the firmware. This function checks |
| 8630 | * txq to flush the iocbs in txq to Firmware before |
| 8631 | * submitting new iocbs to the Firmware. |
| 8632 | * If there are iocbs in the txq which need to be submitted |
| 8633 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 8634 | * of the txq after dequeuing it from txq. |
| 8635 | * If there is no iocb in the txq then the function will return |
| 8636 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 8637 | * *piocb to find if there are more commands in the txq. |
| 8638 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8639 | static struct lpfc_iocbq * |
| 8640 | 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] | 8641 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8642 | { |
| 8643 | struct lpfc_iocbq * nextiocb; |
| 8644 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8645 | lockdep_assert_held(&phba->hbalock); |
| 8646 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8647 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 8648 | if (!nextiocb) { |
| 8649 | nextiocb = *piocb; |
| 8650 | *piocb = NULL; |
| 8651 | } |
| 8652 | |
| 8653 | return nextiocb; |
| 8654 | } |
| 8655 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8656 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8657 | * __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] | 8658 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8659 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8660 | * @piocb: Pointer to command iocb. |
| 8661 | * @flag: Flag indicating if this command can be put into txq. |
| 8662 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8663 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 8664 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 8665 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 8666 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 8667 | * this function allows only iocbs for posting buffers. This function finds |
| 8668 | * next available slot in the command ring and posts the command to the |
| 8669 | * available slot and writes the port attention register to request HBA start |
| 8670 | * processing new iocb. If there is no slot available in the ring and |
| 8671 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 8672 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8673 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8674 | * This function is called with hbalock held. The function will return success |
| 8675 | * after it successfully submit the iocb to firmware or after adding to the |
| 8676 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8677 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8678 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8679 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8680 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8681 | { |
| 8682 | struct lpfc_iocbq *nextiocb; |
| 8683 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8684 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8685 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8686 | lockdep_assert_held(&phba->hbalock); |
| 8687 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8688 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 8689 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 8690 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 8691 | lpfc_printf_log(phba, KERN_ERR, |
| 8692 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8693 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8694 | piocb->iocb.ulpCommand); |
| 8695 | dump_stack(); |
| 8696 | return IOCB_ERROR; |
| 8697 | } |
| 8698 | |
| 8699 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8700 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 8701 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 8702 | return IOCB_ERROR; |
| 8703 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8704 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8705 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 8706 | return IOCB_ERROR; |
| 8707 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8708 | /* |
| 8709 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 8710 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8711 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8712 | return IOCB_ERROR; |
| 8713 | |
| 8714 | /* |
| 8715 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8716 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8717 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8718 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8719 | goto iocb_busy; |
| 8720 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8721 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8722 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8723 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8724 | * can be issued if the link is not up. |
| 8725 | */ |
| 8726 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8727 | case CMD_GEN_REQUEST64_CR: |
| 8728 | case CMD_GEN_REQUEST64_CX: |
| 8729 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 8730 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8731 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8732 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 8733 | MENLO_TRANSPORT_TYPE)) |
| 8734 | |
| 8735 | goto iocb_busy; |
| 8736 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8737 | case CMD_QUE_RING_BUF_CN: |
| 8738 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8739 | /* |
| 8740 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 8741 | * completion, iocb_cmpl MUST be 0. |
| 8742 | */ |
| 8743 | if (piocb->iocb_cmpl) |
| 8744 | piocb->iocb_cmpl = NULL; |
| 8745 | /*FALLTHROUGH*/ |
| 8746 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8747 | case CMD_CLOSE_XRI_CN: |
| 8748 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8749 | break; |
| 8750 | default: |
| 8751 | goto iocb_busy; |
| 8752 | } |
| 8753 | |
| 8754 | /* |
| 8755 | * For FCP commands, we must be in a state where we can process link |
| 8756 | * attention events. |
| 8757 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8758 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8759 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8760 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8761 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8762 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8763 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 8764 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 8765 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 8766 | |
| 8767 | if (iocb) |
| 8768 | lpfc_sli_update_ring(phba, pring); |
| 8769 | else |
| 8770 | lpfc_sli_update_full_ring(phba, pring); |
| 8771 | |
| 8772 | if (!piocb) |
| 8773 | return IOCB_SUCCESS; |
| 8774 | |
| 8775 | goto out_busy; |
| 8776 | |
| 8777 | iocb_busy: |
| 8778 | pring->stats.iocb_cmd_delay++; |
| 8779 | |
| 8780 | out_busy: |
| 8781 | |
| 8782 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8783 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8784 | return IOCB_SUCCESS; |
| 8785 | } |
| 8786 | |
| 8787 | return IOCB_BUSY; |
| 8788 | } |
| 8789 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8790 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8791 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 8792 | * @phba: Pointer to HBA context object. |
| 8793 | * @piocb: Pointer to command iocb. |
| 8794 | * @sglq: Pointer to the scatter gather queue object. |
| 8795 | * |
| 8796 | * This routine converts the bpl or bde that is in the IOCB |
| 8797 | * to a sgl list for the sli4 hardware. The physical address |
| 8798 | * of the bpl/bde is converted back to a virtual address. |
| 8799 | * If the IOCB contains a BPL then the list of BDE's is |
| 8800 | * converted to sli4_sge's. If the IOCB contains a single |
| 8801 | * BDE then it is converted to a single sli_sge. |
| 8802 | * The IOCB is still in cpu endianess so the contents of |
| 8803 | * the bpl can be used without byte swapping. |
| 8804 | * |
| 8805 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 8806 | **/ |
| 8807 | static uint16_t |
| 8808 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 8809 | struct lpfc_sglq *sglq) |
| 8810 | { |
| 8811 | uint16_t xritag = NO_XRI; |
| 8812 | struct ulp_bde64 *bpl = NULL; |
| 8813 | struct ulp_bde64 bde; |
| 8814 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8815 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8816 | IOCB_t *icmd; |
| 8817 | int numBdes = 0; |
| 8818 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8819 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 8820 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8821 | |
| 8822 | if (!piocbq || !sglq) |
| 8823 | return xritag; |
| 8824 | |
| 8825 | sgl = (struct sli4_sge *)sglq->sgl; |
| 8826 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8827 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 8828 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8829 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 8830 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 8831 | sizeof(struct ulp_bde64); |
| 8832 | /* The addrHigh and addrLow fields within the IOCB |
| 8833 | * have not been byteswapped yet so there is no |
| 8834 | * need to swap them back. |
| 8835 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8836 | if (piocbq->context3) |
| 8837 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 8838 | else |
| 8839 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8840 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8841 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8842 | if (!bpl) |
| 8843 | return xritag; |
| 8844 | |
| 8845 | for (i = 0; i < numBdes; i++) { |
| 8846 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8847 | sgl->addr_hi = bpl->addrHigh; |
| 8848 | sgl->addr_lo = bpl->addrLow; |
| 8849 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8850 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8851 | if ((i+1) == numBdes) |
| 8852 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8853 | else |
| 8854 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8855 | /* swap the size field back to the cpu so we |
| 8856 | * can assign it to the sgl. |
| 8857 | */ |
| 8858 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 8859 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8860 | /* The offsets in the sgl need to be accumulated |
| 8861 | * separately for the request and reply lists. |
| 8862 | * The request is always first, the reply follows. |
| 8863 | */ |
| 8864 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 8865 | /* add up the reply sg entries */ |
| 8866 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 8867 | inbound++; |
| 8868 | /* first inbound? reset the offset */ |
| 8869 | if (inbound == 1) |
| 8870 | offset = 0; |
| 8871 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 8872 | bf_set(lpfc_sli4_sge_type, sgl, |
| 8873 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8874 | offset += bde.tus.f.bdeSize; |
| 8875 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8876 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8877 | bpl++; |
| 8878 | sgl++; |
| 8879 | } |
| 8880 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 8881 | /* The addrHigh and addrLow fields of the BDE have not |
| 8882 | * been byteswapped yet so they need to be swapped |
| 8883 | * before putting them in the sgl. |
| 8884 | */ |
| 8885 | sgl->addr_hi = |
| 8886 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 8887 | sgl->addr_lo = |
| 8888 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8889 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8890 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8891 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8892 | sgl->sge_len = |
| 8893 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8894 | } |
| 8895 | return sglq->sli4_xritag; |
| 8896 | } |
| 8897 | |
| 8898 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8899 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 8900 | * @phba: Pointer to HBA context object. |
| 8901 | * @piocb: Pointer to command iocb. |
| 8902 | * @wqe: Pointer to the work queue entry. |
| 8903 | * |
| 8904 | * This routine converts the iocb command to its Work Queue Entry |
| 8905 | * equivalent. The wqe pointer should not have any fields set when |
| 8906 | * this routine is called because it will memcpy over them. |
| 8907 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 8908 | * wqe. |
| 8909 | * |
| 8910 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 8911 | **/ |
| 8912 | static int |
| 8913 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 8914 | union lpfc_wqe128 *wqe) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8915 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8916 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8917 | uint8_t ct = 0; |
| 8918 | uint32_t fip; |
| 8919 | uint32_t abort_tag; |
| 8920 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 8921 | uint8_t cmnd; |
| 8922 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8923 | uint16_t abrt_iotag; |
| 8924 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8925 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8926 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8927 | int numBdes, i; |
| 8928 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8929 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8930 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8931 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8932 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 8933 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8934 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8935 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8936 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8937 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8938 | command_type = ELS_COMMAND_FIP; |
| 8939 | else |
| 8940 | command_type = ELS_COMMAND_NON_FIP; |
| 8941 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8942 | if (phba->fcp_embed_io) |
| 8943 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8944 | /* Some of the fields are in the right position already */ |
| 8945 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 8946 | if (iocbq->iocb.ulpCommand != CMD_SEND_FRAME) { |
| 8947 | /* The ct field has moved so reset */ |
| 8948 | wqe->generic.wqe_com.word7 = 0; |
| 8949 | wqe->generic.wqe_com.word10 = 0; |
| 8950 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8951 | |
| 8952 | abort_tag = (uint32_t) iocbq->iotag; |
| 8953 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8954 | /* words0-2 bpl convert bde */ |
| 8955 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8956 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8957 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8958 | bpl = (struct ulp_bde64 *) |
| 8959 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 8960 | if (!bpl) |
| 8961 | return IOCB_ERROR; |
| 8962 | |
| 8963 | /* Should already be byte swapped. */ |
| 8964 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 8965 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 8966 | /* swap the size field back to the cpu so we |
| 8967 | * can assign it to the sgl. |
| 8968 | */ |
| 8969 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8970 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 8971 | total_len = 0; |
| 8972 | for (i = 0; i < numBdes; i++) { |
| 8973 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 8974 | total_len += bde.tus.f.bdeSize; |
| 8975 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8976 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8977 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8978 | |
| 8979 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 8980 | cmnd = iocbq->iocb.ulpCommand; |
| 8981 | |
| 8982 | switch (iocbq->iocb.ulpCommand) { |
| 8983 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 8984 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 8985 | ndlp = iocbq->context_un.ndlp; |
| 8986 | else |
| 8987 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8988 | if (!iocbq->iocb.ulpLe) { |
| 8989 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8990 | "2007 Only Limited Edition cmd Format" |
| 8991 | " supported 0x%x\n", |
| 8992 | iocbq->iocb.ulpCommand); |
| 8993 | return IOCB_ERROR; |
| 8994 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8995 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8996 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8997 | /* Els_reguest64 has a TMO */ |
| 8998 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 8999 | iocbq->iocb.ulpTimeout); |
| 9000 | /* Need a VF for word 4 set the vf bit*/ |
| 9001 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 9002 | /* And a VFID for word 12 */ |
| 9003 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9004 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9005 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9006 | iocbq->iocb.ulpContext); |
| 9007 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 9008 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9009 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9010 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9011 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 9012 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9013 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9014 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9015 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9016 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9017 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9018 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9019 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9020 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 9021 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9022 | *pcmd == ELS_CMD_PLOGI)) { |
| 9023 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 9024 | bf_set(els_req64_sid, &wqe->els_req, |
| 9025 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9026 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 9027 | !(phba->fc_topology == |
| 9028 | LPFC_TOPOLOGY_LOOP)) |
| 9029 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9030 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 9031 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 9032 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 9033 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9034 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 9035 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 9036 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 9037 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 9038 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9039 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 9040 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9041 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 9042 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 9043 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9044 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 9045 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9046 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9047 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9048 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9049 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9050 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 9051 | iocbq->iocb.un.ulpWord[3]); |
| 9052 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9053 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9054 | /* The entire sequence is transmitted for this IOCB */ |
| 9055 | xmit_len = total_len; |
| 9056 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9057 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 9058 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9059 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9060 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 9061 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9062 | /* word4 relative_offset memcpy */ |
| 9063 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9064 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 9065 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 9066 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 9067 | LPFC_WQE_IOD_WRITE); |
| 9068 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 9069 | LPFC_WQE_LENLOC_WORD12); |
| 9070 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9071 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 9072 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9073 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9074 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9075 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 9076 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9077 | /* word4 iocb=rsvd wqe=rsvd */ |
| 9078 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 9079 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9080 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9081 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9082 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 9083 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9084 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 9085 | LPFC_WQE_LENLOC_WORD3); |
| 9086 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9087 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9088 | case CMD_FCP_IWRITE64_CR: |
| 9089 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9090 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9091 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9092 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 9093 | xmit_len + sizeof(struct fcp_rsp)); |
| 9094 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 9095 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9096 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9097 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9098 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 9099 | iocbq->iocb.ulpFCP2Rcvy); |
| 9100 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 9101 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9102 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9103 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 9104 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9105 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9106 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9107 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9108 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9109 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 9110 | if (iocbq->priority) { |
| 9111 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9112 | (iocbq->priority << 1)); |
| 9113 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9114 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 9115 | (phba->cfg_XLanePriority << 1)); |
| 9116 | } |
| 9117 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9118 | /* Note, word 10 is already initialized to 0 */ |
| 9119 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9120 | /* Don't set PBDE for Perf hints, just fcp_embed_pbde */ |
| 9121 | if (phba->fcp_embed_pbde) |
| 9122 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1); |
| 9123 | else |
| 9124 | bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0); |
| 9125 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9126 | if (phba->fcp_embed_io) { |
| 9127 | struct lpfc_scsi_buf *lpfc_cmd; |
| 9128 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9129 | struct fcp_cmnd *fcp_cmnd; |
| 9130 | uint32_t *ptr; |
| 9131 | |
| 9132 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9133 | |
| 9134 | lpfc_cmd = iocbq->context1; |
| 9135 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 9136 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9137 | |
| 9138 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9139 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9140 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9141 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9142 | wqe->generic.bde.addrHigh = 0; |
| 9143 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9144 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9145 | bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1); |
| 9146 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9147 | |
| 9148 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9149 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9150 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9151 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9152 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9153 | case CMD_FCP_IREAD64_CR: |
| 9154 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9155 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9156 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 9157 | xmit_len + sizeof(struct fcp_rsp)); |
| 9158 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 9159 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9160 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 9161 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 9162 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 9163 | iocbq->iocb.ulpFCP2Rcvy); |
| 9164 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9165 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9166 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 9167 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 9168 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9169 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 9170 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9171 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9172 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9173 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 9174 | if (iocbq->priority) { |
| 9175 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9176 | (iocbq->priority << 1)); |
| 9177 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9178 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 9179 | (phba->cfg_XLanePriority << 1)); |
| 9180 | } |
| 9181 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9182 | /* Note, word 10 is already initialized to 0 */ |
| 9183 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 9184 | /* Don't set PBDE for Perf hints, just fcp_embed_pbde */ |
| 9185 | if (phba->fcp_embed_pbde) |
| 9186 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1); |
| 9187 | else |
| 9188 | bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0); |
| 9189 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9190 | if (phba->fcp_embed_io) { |
| 9191 | struct lpfc_scsi_buf *lpfc_cmd; |
| 9192 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9193 | struct fcp_cmnd *fcp_cmnd; |
| 9194 | uint32_t *ptr; |
| 9195 | |
| 9196 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9197 | |
| 9198 | lpfc_cmd = iocbq->context1; |
| 9199 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 9200 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9201 | |
| 9202 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9203 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9204 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9205 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9206 | wqe->generic.bde.addrHigh = 0; |
| 9207 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9208 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9209 | bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1); |
| 9210 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9211 | |
| 9212 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9213 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9214 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9215 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9216 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9217 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 9218 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 9219 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 9220 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 9221 | xmit_len + sizeof(struct fcp_rsp)); |
| 9222 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 9223 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9224 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9225 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 9226 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9227 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 9228 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9229 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 9230 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 9231 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 9232 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 9233 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9234 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9235 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9236 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 9237 | if (iocbq->priority) { |
| 9238 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9239 | (iocbq->priority << 1)); |
| 9240 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9241 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9242 | (phba->cfg_XLanePriority << 1)); |
| 9243 | } |
| 9244 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9245 | /* Note, word 10 is already initialized to 0 */ |
| 9246 | |
| 9247 | if (phba->fcp_embed_io) { |
| 9248 | struct lpfc_scsi_buf *lpfc_cmd; |
| 9249 | struct sli4_sge *sgl; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9250 | struct fcp_cmnd *fcp_cmnd; |
| 9251 | uint32_t *ptr; |
| 9252 | |
| 9253 | /* 128 byte wqe support here */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9254 | |
| 9255 | lpfc_cmd = iocbq->context1; |
| 9256 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 9257 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9258 | |
| 9259 | /* Word 0-2 - FCP_CMND */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9260 | wqe->generic.bde.tus.f.bdeFlags = |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9261 | BUFF_TYPE_BDE_IMMED; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9262 | wqe->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9263 | wqe->generic.bde.addrHigh = 0; |
| 9264 | wqe->generic.bde.addrLow = 88; /* Word 22 */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9265 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9266 | bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1); |
| 9267 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9268 | |
| 9269 | /* Word 22-29 FCP CMND Payload */ |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9270 | ptr = &wqe->words[22]; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9271 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9272 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9273 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9274 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9275 | /* For this command calculate the xmit length of the |
| 9276 | * request bde. |
| 9277 | */ |
| 9278 | xmit_len = 0; |
| 9279 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9280 | sizeof(struct ulp_bde64); |
| 9281 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9282 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9283 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9284 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9285 | xmit_len += bde.tus.f.bdeSize; |
| 9286 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9287 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9288 | wqe->gen_req.request_payload_len = xmit_len; |
| 9289 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9290 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9291 | /* word6 context tag copied in memcpy */ |
| 9292 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9293 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9294 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9295 | "2015 Invalid CT %x command 0x%x\n", |
| 9296 | ct, iocbq->iocb.ulpCommand); |
| 9297 | return IOCB_ERROR; |
| 9298 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9299 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9300 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9301 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9302 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9303 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9304 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9305 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9306 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9307 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9308 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9309 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9310 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9311 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9312 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9313 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9314 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9315 | /* word4 */ |
| 9316 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9317 | /* word5 iocb=rsvd wge=did */ |
| 9318 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9319 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9320 | |
| 9321 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9322 | &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9323 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9324 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9325 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9326 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9327 | iocbq->vport->fc_myDID); |
| 9328 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9329 | bf_set(wqe_els_did, |
| 9330 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9331 | } |
| 9332 | } |
| 9333 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9334 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9335 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9336 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9337 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9338 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9339 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9340 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9341 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9342 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9343 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9344 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9345 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9346 | LPFC_WQE_LENLOC_WORD3); |
| 9347 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9348 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9349 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9350 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9351 | iocbq->context2)->virt); |
| 9352 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9353 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9354 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9355 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9356 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9357 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9358 | phba->vpi_ids[phba->pport->vpi]); |
| 9359 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9360 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9361 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9362 | case CMD_CLOSE_XRI_CN: |
| 9363 | case CMD_ABORT_XRI_CN: |
| 9364 | case CMD_ABORT_XRI_CX: |
| 9365 | /* words 0-2 memcpy should be 0 rserved */ |
| 9366 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9367 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9368 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9369 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9370 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9371 | } else |
| 9372 | fip = 0; |
| 9373 | |
| 9374 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9375 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9376 | * The link is down, or the command was ELS_FIP |
| 9377 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9378 | * on the wire. |
| 9379 | */ |
| 9380 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9381 | else |
| 9382 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9383 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9384 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9385 | wqe->abort_cmd.rsrvd5 = 0; |
| 9386 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9387 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9388 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9389 | /* |
| 9390 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9391 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9392 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9393 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 9394 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 9395 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 9396 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9397 | cmnd = CMD_ABORT_XRI_CX; |
| 9398 | command_type = OTHER_COMMAND; |
| 9399 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9400 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9401 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9402 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9403 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9404 | * we re-construct this WQE here based on information in |
| 9405 | * iocbq from scratch. |
| 9406 | */ |
| 9407 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9408 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9409 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9410 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 9411 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9412 | LPFC_ABTS_UNSOL_INT) { |
| 9413 | /* ABTS sent by initiator to CT exchange, the |
| 9414 | * RX_ID field will be filled with the newly |
| 9415 | * allocated responder XRI. |
| 9416 | */ |
| 9417 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 9418 | iocbq->sli4_xritag); |
| 9419 | } else { |
| 9420 | /* ABTS sent by responder to CT exchange, the |
| 9421 | * RX_ID field will be filled with the responder |
| 9422 | * RX_ID from ABTS. |
| 9423 | */ |
| 9424 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9425 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9426 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9427 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 9428 | 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] | 9429 | |
| 9430 | /* Use CT=VPI */ |
| 9431 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 9432 | ndlp->nlp_DID); |
| 9433 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 9434 | iocbq->iocb.ulpContext); |
| 9435 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9436 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9437 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9438 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 9439 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 9440 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9441 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 9442 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9443 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 9444 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 9445 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 9446 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 9447 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 9448 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 9449 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 9450 | } |
| 9451 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9452 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9453 | case CMD_SEND_FRAME: |
| 9454 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9455 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9456 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9457 | case CMD_XRI_ABORTED_CX: |
| 9458 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9459 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 9460 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 9461 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 9462 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 9463 | default: |
| 9464 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9465 | "2014 Invalid command 0x%x\n", |
| 9466 | iocbq->iocb.ulpCommand); |
| 9467 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9468 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9469 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9470 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 9471 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 9472 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 9473 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 9474 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 9475 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 9476 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 9477 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 9478 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9479 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9480 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9481 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 9482 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 9483 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 9484 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 9485 | 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] | 9486 | return 0; |
| 9487 | } |
| 9488 | |
| 9489 | /** |
| 9490 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 9491 | * @phba: Pointer to HBA context object. |
| 9492 | * @ring_number: SLI ring number to issue iocb on. |
| 9493 | * @piocb: Pointer to command iocb. |
| 9494 | * @flag: Flag indicating if this command can be put into txq. |
| 9495 | * |
| 9496 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 9497 | * an iocb command to an HBA with SLI-4 interface spec. |
| 9498 | * |
| 9499 | * This function is called with hbalock held. The function will return success |
| 9500 | * after it successfully submit the iocb to firmware or after adding to the |
| 9501 | * txq. |
| 9502 | **/ |
| 9503 | static int |
| 9504 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 9505 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9506 | { |
| 9507 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9508 | union lpfc_wqe128 wqe; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9509 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9510 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9511 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9512 | /* Get the WQ */ |
| 9513 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 9514 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
| 9515 | if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) |
| 9516 | wq = phba->sli4_hba.fcp_wq[piocb->hba_wqidx]; |
| 9517 | else |
| 9518 | wq = phba->sli4_hba.oas_wq; |
| 9519 | } else { |
| 9520 | wq = phba->sli4_hba.els_wq; |
| 9521 | } |
| 9522 | |
| 9523 | /* Get corresponding ring */ |
| 9524 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9525 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9526 | /* |
| 9527 | * The WQE can be either 64 or 128 bytes, |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9528 | */ |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9529 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9530 | lockdep_assert_held(&phba->hbalock); |
| 9531 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9532 | if (piocb->sli4_xritag == NO_XRI) { |
| 9533 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9534 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9535 | sglq = NULL; |
| 9536 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9537 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9538 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9539 | __lpfc_sli_ringtx_put(phba, |
| 9540 | pring, piocb); |
| 9541 | return IOCB_SUCCESS; |
| 9542 | } else { |
| 9543 | return IOCB_BUSY; |
| 9544 | } |
| 9545 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9546 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9547 | if (!sglq) { |
| 9548 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9549 | __lpfc_sli_ringtx_put(phba, |
| 9550 | pring, |
| 9551 | piocb); |
| 9552 | return IOCB_SUCCESS; |
| 9553 | } else |
| 9554 | return IOCB_BUSY; |
| 9555 | } |
| 9556 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9557 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9558 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9559 | /* These IO's already have an XRI and a mapped sgl. */ |
| 9560 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9561 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9562 | /* |
| 9563 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9564 | * sglq is on the active list |
| 9565 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 9566 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9567 | if (!sglq) |
| 9568 | return IOCB_ERROR; |
| 9569 | } |
| 9570 | |
| 9571 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9572 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9573 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9574 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9575 | return IOCB_ERROR; |
| 9576 | } |
| 9577 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9578 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9579 | return IOCB_ERROR; |
| 9580 | |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 9581 | if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9582 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9583 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 9584 | |
| 9585 | return 0; |
| 9586 | } |
| 9587 | |
| 9588 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9589 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 9590 | * |
| 9591 | * This routine wraps the actual lockless version for issusing IOCB function |
| 9592 | * pointer from the lpfc_hba struct. |
| 9593 | * |
| 9594 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9595 | * IOCB_ERROR - Error |
| 9596 | * IOCB_SUCCESS - Success |
| 9597 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9598 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9599 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9600 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 9601 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9602 | { |
| 9603 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9604 | } |
| 9605 | |
| 9606 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9607 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9608 | * @phba: The hba struct for which this call is being executed. |
| 9609 | * @dev_grp: The HBA PCI-Device group number. |
| 9610 | * |
| 9611 | * This routine sets up the SLI interface API function jump table in @phba |
| 9612 | * struct. |
| 9613 | * Returns: 0 - success, -ENODEV - failure. |
| 9614 | **/ |
| 9615 | int |
| 9616 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9617 | { |
| 9618 | |
| 9619 | switch (dev_grp) { |
| 9620 | case LPFC_PCI_DEV_LP: |
| 9621 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 9622 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 9623 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9624 | case LPFC_PCI_DEV_OC: |
| 9625 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 9626 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 9627 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9628 | default: |
| 9629 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9630 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 9631 | dev_grp); |
| 9632 | return -ENODEV; |
| 9633 | break; |
| 9634 | } |
| 9635 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 9636 | return 0; |
| 9637 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9638 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9639 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9640 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9641 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9642 | * @piocb: Pointer to command iocb. |
| 9643 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9644 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 9645 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9646 | * 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] | 9647 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9648 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9649 | struct lpfc_sli_ring * |
| 9650 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9651 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9652 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9653 | if (!(phba->cfg_fof) || |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9654 | (!(piocb->iocb_flag & LPFC_IO_FOF))) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9655 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9656 | return NULL; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9657 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9658 | * for abort iocb hba_wqidx should already |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9659 | * be setup based on what work queue we used. |
| 9660 | */ |
Dick Kennedy | 8e036a9 | 2017-09-29 17:34:35 -0700 | [diff] [blame] | 9661 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9662 | piocb->hba_wqidx = |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9663 | lpfc_sli4_scmd_to_wqidx_distr(phba, |
| 9664 | piocb->context1); |
Dick Kennedy | 8e036a9 | 2017-09-29 17:34:35 -0700 | [diff] [blame] | 9665 | piocb->hba_wqidx = piocb->hba_wqidx % |
| 9666 | phba->cfg_fcp_io_channel; |
| 9667 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9668 | return phba->sli4_hba.fcp_wq[piocb->hba_wqidx]->pring; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9669 | } else { |
| 9670 | if (unlikely(!phba->sli4_hba.oas_wq)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9671 | return NULL; |
| 9672 | piocb->hba_wqidx = 0; |
| 9673 | return phba->sli4_hba.oas_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9674 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9675 | } else { |
| 9676 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 9677 | return NULL; |
| 9678 | piocb->hba_wqidx = 0; |
| 9679 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9680 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9681 | } |
| 9682 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9683 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9684 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9685 | * @phba: Pointer to HBA context object. |
| 9686 | * @pring: Pointer to driver SLI ring object. |
| 9687 | * @piocb: Pointer to command iocb. |
| 9688 | * @flag: Flag indicating if this command can be put into txq. |
| 9689 | * |
| 9690 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 9691 | * function. This function gets the hbalock and calls |
| 9692 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 9693 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 9694 | * functions which do not hold hbalock. |
| 9695 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9696 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9697 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9698 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9699 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9700 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9701 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9702 | struct lpfc_queue *fpeq; |
| 9703 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9704 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9705 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9706 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9707 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9708 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 9709 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9710 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9711 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9712 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9713 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9714 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9715 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9716 | if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9717 | idx = piocb->hba_wqidx; |
| 9718 | hba_eq_hdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9719 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9720 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9721 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9722 | /* Get associated EQ with this index */ |
| 9723 | fpeq = phba->sli4_hba.hba_eq[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9724 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9725 | /* Turn off interrupts from this EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 9726 | phba->sli4_hba.sli4_eq_clr_intr(fpeq); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9727 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9728 | /* |
| 9729 | * Process all the events on FCP EQ |
| 9730 | */ |
| 9731 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 9732 | lpfc_sli4_hba_handle_eqe(phba, |
| 9733 | eqe, idx); |
| 9734 | fpeq->EQ_processed++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9735 | } |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9736 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9737 | /* Always clear and re-arm the EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 9738 | phba->sli4_hba.sli4_eq_release(fpeq, |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9739 | LPFC_QUEUE_REARM); |
| 9740 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9741 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9742 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9743 | } else { |
| 9744 | /* For now, SLI2/3 will still use hbalock */ |
| 9745 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9746 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9747 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9748 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9749 | return rc; |
| 9750 | } |
| 9751 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9752 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9753 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9754 | * @phba: Pointer to HBA context object. |
| 9755 | * |
| 9756 | * This function is called while driver attaches with the |
| 9757 | * HBA to setup the extra ring. The extra ring is used |
| 9758 | * only when driver needs to support target mode functionality |
| 9759 | * or IP over FC functionalities. |
| 9760 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9761 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9762 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9763 | static int |
| 9764 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 9765 | { |
| 9766 | struct lpfc_sli *psli; |
| 9767 | struct lpfc_sli_ring *pring; |
| 9768 | |
| 9769 | psli = &phba->sli; |
| 9770 | |
| 9771 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9772 | |
| 9773 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9774 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9775 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9776 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9777 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9778 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9779 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9780 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9781 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9782 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9783 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9784 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9785 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9786 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9787 | |
| 9788 | /* Setup default profile for this ring */ |
| 9789 | pring->iotag_max = 4096; |
| 9790 | pring->num_mask = 1; |
| 9791 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9792 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 9793 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9794 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 9795 | return 0; |
| 9796 | } |
| 9797 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9798 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 9799 | * @phba: Pointer to HBA context object. |
| 9800 | * @iocbq: Pointer to iocb object. |
| 9801 | * |
| 9802 | * The async_event handler calls this routine when it receives |
| 9803 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 9804 | * this event when an Abort Sequence request to an rport fails |
| 9805 | * twice in succession. The abort could be originated by the |
| 9806 | * driver or by the port. The ABTS could have been for an ELS |
| 9807 | * or FCP IO. The port only generates this event when an ABTS |
| 9808 | * fails to complete after one retry. |
| 9809 | */ |
| 9810 | static void |
| 9811 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 9812 | struct lpfc_iocbq *iocbq) |
| 9813 | { |
| 9814 | struct lpfc_nodelist *ndlp = NULL; |
| 9815 | uint16_t rpi = 0, vpi = 0; |
| 9816 | struct lpfc_vport *vport = NULL; |
| 9817 | |
| 9818 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 9819 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 9820 | rpi = iocbq->iocb.ulpContext; |
| 9821 | |
| 9822 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9823 | "3092 Port generated ABTS async event " |
| 9824 | "on vpi %d rpi %d status 0x%x\n", |
| 9825 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 9826 | |
| 9827 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 9828 | if (!vport) |
| 9829 | goto err_exit; |
| 9830 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 9831 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 9832 | goto err_exit; |
| 9833 | |
| 9834 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 9835 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9836 | return; |
| 9837 | |
| 9838 | err_exit: |
| 9839 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9840 | "3095 Event Context not found, no " |
| 9841 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 9842 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 9843 | vpi, rpi); |
| 9844 | } |
| 9845 | |
| 9846 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 9847 | * @phba: pointer to HBA context object. |
| 9848 | * @ndlp: nodelist pointer for the impacted rport. |
| 9849 | * @axri: pointer to the wcqe containing the failed exchange. |
| 9850 | * |
| 9851 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 9852 | * port. The port generates this event when an abort exchange request to an |
| 9853 | * rport fails twice in succession with no reply. The abort could be originated |
| 9854 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 9855 | */ |
| 9856 | void |
| 9857 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 9858 | struct lpfc_nodelist *ndlp, |
| 9859 | struct sli4_wcqe_xri_aborted *axri) |
| 9860 | { |
| 9861 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9862 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9863 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9864 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9865 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9866 | "3115 Node Context not found, driver " |
| 9867 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9868 | return; |
| 9869 | } |
| 9870 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9871 | vport = ndlp->vport; |
| 9872 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9873 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9874 | "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] | 9875 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9876 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9877 | bf_get(lpfc_wcqe_xa_status, axri), |
| 9878 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9879 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9880 | /* |
| 9881 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 9882 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 9883 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 9884 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 9885 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9886 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 9887 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9888 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9889 | } |
| 9890 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9891 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9892 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9893 | * @phba: Pointer to HBA context object. |
| 9894 | * @pring: Pointer to driver SLI ring object. |
| 9895 | * @iocbq: Pointer to iocb object. |
| 9896 | * |
| 9897 | * This function is called by the slow ring event handler |
| 9898 | * function when there is an ASYNC event iocb in the ring. |
| 9899 | * This function is called with no lock held. |
| 9900 | * Currently this function handles only temperature related |
| 9901 | * ASYNC events. The function decodes the temperature sensor |
| 9902 | * event message and posts events for the management applications. |
| 9903 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9904 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9905 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 9906 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 9907 | { |
| 9908 | IOCB_t *icmd; |
| 9909 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9910 | struct temp_event temp_event_data; |
| 9911 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9912 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9913 | |
| 9914 | icmd = &iocbq->iocb; |
| 9915 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9916 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9917 | switch (evt_code) { |
| 9918 | case ASYNC_TEMP_WARN: |
| 9919 | case ASYNC_TEMP_SAFE: |
| 9920 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 9921 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 9922 | if (evt_code == ASYNC_TEMP_WARN) { |
| 9923 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 9924 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9925 | "0347 Adapter is very hot, please take " |
| 9926 | "corrective action. temperature : %d Celsius\n", |
| 9927 | (uint32_t) icmd->ulpContext); |
| 9928 | } else { |
| 9929 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 9930 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9931 | "0340 Adapter temperature is OK now. " |
| 9932 | "temperature : %d Celsius\n", |
| 9933 | (uint32_t) icmd->ulpContext); |
| 9934 | } |
| 9935 | |
| 9936 | /* Send temperature change event to applications */ |
| 9937 | shost = lpfc_shost_from_vport(phba->pport); |
| 9938 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 9939 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 9940 | LPFC_NL_VENDOR_ID); |
| 9941 | break; |
| 9942 | case ASYNC_STATUS_CN: |
| 9943 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 9944 | break; |
| 9945 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9946 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9947 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9948 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 9949 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9950 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 9951 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 9952 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 9953 | "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] | 9954 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9955 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 9956 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 9957 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 9958 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 9959 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9960 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9961 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9962 | } |
| 9963 | |
| 9964 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9965 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9966 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9967 | * @phba: Pointer to HBA context object. |
| 9968 | * |
| 9969 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 9970 | * number of iocbs per ring and iotags. This function is |
| 9971 | * called while driver attach to the HBA and before the |
| 9972 | * interrupts are enabled. So there is no need for locking. |
| 9973 | * |
| 9974 | * This function always returns 0. |
| 9975 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9976 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9977 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 9978 | { |
| 9979 | struct lpfc_sli_ring *pring; |
| 9980 | |
| 9981 | pring = phba->sli4_hba.els_wq->pring; |
| 9982 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 9983 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 9984 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9985 | pring->prt[0].type = FC_TYPE_ELS; |
| 9986 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 9987 | lpfc_els_unsol_event; |
| 9988 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 9989 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9990 | pring->prt[1].type = FC_TYPE_ELS; |
| 9991 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 9992 | lpfc_els_unsol_event; |
| 9993 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9994 | /* NameServer Inquiry */ |
| 9995 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 9996 | /* NameServer */ |
| 9997 | pring->prt[2].type = FC_TYPE_CT; |
| 9998 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 9999 | lpfc_ct_unsol_event; |
| 10000 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10001 | /* NameServer response */ |
| 10002 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 10003 | /* NameServer */ |
| 10004 | pring->prt[3].type = FC_TYPE_CT; |
| 10005 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 10006 | lpfc_ct_unsol_event; |
| 10007 | return 0; |
| 10008 | } |
| 10009 | |
| 10010 | /** |
| 10011 | * lpfc_sli_setup - SLI ring setup function |
| 10012 | * @phba: Pointer to HBA context object. |
| 10013 | * |
| 10014 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 10015 | * number of iocbs per ring and iotags. This function is |
| 10016 | * called while driver attach to the HBA and before the |
| 10017 | * interrupts are enabled. So there is no need for locking. |
| 10018 | * |
| 10019 | * This function always returns 0. SLI3 only. |
| 10020 | **/ |
| 10021 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10022 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 10023 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10024 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10025 | struct lpfc_sli *psli = &phba->sli; |
| 10026 | struct lpfc_sli_ring *pring; |
| 10027 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 10028 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10029 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10030 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10031 | psli->iocbq_lookup = NULL; |
| 10032 | psli->iocbq_lookup_len = 0; |
| 10033 | psli->last_iotag = 0; |
| 10034 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10035 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10036 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10037 | switch (i) { |
| 10038 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 10039 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10040 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 10041 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 10042 | pring->sli.sli3.numCiocb += |
| 10043 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 10044 | pring->sli.sli3.numRiocb += |
| 10045 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 10046 | pring->sli.sli3.numCiocb += |
| 10047 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 10048 | pring->sli.sli3.numRiocb += |
| 10049 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 10050 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10051 | SLI3_IOCB_CMD_SIZE : |
| 10052 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10053 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10054 | SLI3_IOCB_RSP_SIZE : |
| 10055 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10056 | pring->iotag_ctr = 0; |
| 10057 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10058 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10059 | pring->fast_iotag = pring->iotag_max; |
| 10060 | pring->num_mask = 0; |
| 10061 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 10062 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10063 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10064 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 10065 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 10066 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10067 | SLI3_IOCB_CMD_SIZE : |
| 10068 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10069 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10070 | SLI3_IOCB_RSP_SIZE : |
| 10071 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10072 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10073 | pring->num_mask = 0; |
| 10074 | break; |
| 10075 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 10076 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10077 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 10078 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 10079 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10080 | SLI3_IOCB_CMD_SIZE : |
| 10081 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10082 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10083 | SLI3_IOCB_RSP_SIZE : |
| 10084 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10085 | pring->fast_iotag = 0; |
| 10086 | pring->iotag_ctr = 0; |
| 10087 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 10088 | pring->lpfc_sli_rcv_async_status = |
| 10089 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10090 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10091 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10092 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 10093 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10094 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10095 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10096 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10097 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 10098 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10099 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10100 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10101 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 10102 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10103 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10104 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10105 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10106 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10107 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10108 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 10109 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10110 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10111 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 10112 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10113 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10114 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10115 | break; |
| 10116 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10117 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 10118 | pring->sli.sli3.sizeCiocb) + |
| 10119 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10120 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10121 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10122 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10123 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 10124 | "SLI2 SLIM Data: x%x x%lx\n", |
| 10125 | phba->brd_no, totiocbsize, |
| 10126 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10127 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 10128 | if (phba->cfg_multi_ring_support == 2) |
| 10129 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10130 | |
| 10131 | return 0; |
| 10132 | } |
| 10133 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10134 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10135 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10136 | * @phba: Pointer to HBA context object. |
| 10137 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10138 | * 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] | 10139 | * ring. This function also initializes ring indices of each ring. |
| 10140 | * This function is called during the initialization of the SLI |
| 10141 | * interface of an HBA. |
| 10142 | * This function is called with no lock held and always returns |
| 10143 | * 1. |
| 10144 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10145 | void |
| 10146 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 10147 | { |
| 10148 | struct lpfc_sli *psli; |
| 10149 | struct lpfc_sli_ring *pring; |
| 10150 | int i; |
| 10151 | |
| 10152 | psli = &phba->sli; |
| 10153 | spin_lock_irq(&phba->hbalock); |
| 10154 | INIT_LIST_HEAD(&psli->mboxq); |
| 10155 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 10156 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10157 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
| 10158 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
| 10159 | pring->flag = 0; |
| 10160 | pring->ringno = LPFC_FCP_RING; |
| 10161 | INIT_LIST_HEAD(&pring->txq); |
| 10162 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10163 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10164 | spin_lock_init(&pring->ring_lock); |
| 10165 | } |
| 10166 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 10167 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 10168 | pring->flag = 0; |
| 10169 | pring->ringno = LPFC_FCP_RING; |
| 10170 | INIT_LIST_HEAD(&pring->txq); |
| 10171 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10172 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10173 | spin_lock_init(&pring->ring_lock); |
| 10174 | } |
| 10175 | pring = phba->sli4_hba.els_wq->pring; |
| 10176 | pring->flag = 0; |
| 10177 | pring->ringno = LPFC_ELS_RING; |
| 10178 | INIT_LIST_HEAD(&pring->txq); |
| 10179 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10180 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10181 | spin_lock_init(&pring->ring_lock); |
| 10182 | |
| 10183 | if (phba->cfg_nvme_io_channel) { |
| 10184 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 10185 | pring->flag = 0; |
| 10186 | pring->ringno = LPFC_ELS_RING; |
| 10187 | INIT_LIST_HEAD(&pring->txq); |
| 10188 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10189 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10190 | spin_lock_init(&pring->ring_lock); |
| 10191 | } |
| 10192 | |
| 10193 | if (phba->cfg_fof) { |
| 10194 | pring = phba->sli4_hba.oas_wq->pring; |
| 10195 | pring->flag = 0; |
| 10196 | pring->ringno = LPFC_FCP_RING; |
| 10197 | INIT_LIST_HEAD(&pring->txq); |
| 10198 | INIT_LIST_HEAD(&pring->txcmplq); |
| 10199 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 10200 | spin_lock_init(&pring->ring_lock); |
| 10201 | } |
| 10202 | |
| 10203 | spin_unlock_irq(&phba->hbalock); |
| 10204 | } |
| 10205 | |
| 10206 | /** |
| 10207 | * lpfc_sli_queue_init - Queue initialization function |
| 10208 | * @phba: Pointer to HBA context object. |
| 10209 | * |
| 10210 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 10211 | * ring. This function also initializes ring indices of each ring. |
| 10212 | * This function is called during the initialization of the SLI |
| 10213 | * interface of an HBA. |
| 10214 | * This function is called with no lock held and always returns |
| 10215 | * 1. |
| 10216 | **/ |
| 10217 | void |
| 10218 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10219 | { |
| 10220 | struct lpfc_sli *psli; |
| 10221 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10222 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10223 | |
| 10224 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10225 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10226 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10227 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10228 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10229 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10230 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10231 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10232 | pring->sli.sli3.next_cmdidx = 0; |
| 10233 | pring->sli.sli3.local_getidx = 0; |
| 10234 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10235 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 10236 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10237 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10238 | pring->flag = 0; |
| 10239 | INIT_LIST_HEAD(&pring->txq); |
| 10240 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10241 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10242 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10243 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10244 | } |
| 10245 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10246 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10247 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 10248 | * @phba: Pointer to HBA context object. |
| 10249 | * |
| 10250 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 10251 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 10252 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 10253 | * command; and completed mailbox command queue. It is caller's responsibility |
| 10254 | * to make sure that the driver is in the proper state to flush the mailbox |
| 10255 | * command sub-system. Namely, the posting of mailbox commands into the |
| 10256 | * pending mailbox command queue from the various clients must be stopped; |
| 10257 | * either the HBA is in a state that it will never works on the outstanding |
| 10258 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 10259 | * mailbox command has been completed. |
| 10260 | **/ |
| 10261 | static void |
| 10262 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10263 | { |
| 10264 | LIST_HEAD(completions); |
| 10265 | struct lpfc_sli *psli = &phba->sli; |
| 10266 | LPFC_MBOXQ_t *pmb; |
| 10267 | unsigned long iflag; |
| 10268 | |
| 10269 | /* Flush all the mailbox commands in the mbox system */ |
| 10270 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 10271 | /* The pending mailbox command queue */ |
| 10272 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10273 | /* The outstanding active mailbox command */ |
| 10274 | if (psli->mbox_active) { |
| 10275 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10276 | psli->mbox_active = NULL; |
| 10277 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10278 | } |
| 10279 | /* The completed mailbox command queue */ |
| 10280 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10281 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10282 | |
| 10283 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10284 | while (!list_empty(&completions)) { |
| 10285 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10286 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10287 | if (pmb->mbox_cmpl) |
| 10288 | pmb->mbox_cmpl(phba, pmb); |
| 10289 | } |
| 10290 | } |
| 10291 | |
| 10292 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10293 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10294 | * @vport: Pointer to virtual port object. |
| 10295 | * |
| 10296 | * lpfc_sli_host_down is called to clean up the resources |
| 10297 | * associated with a vport before destroying virtual |
| 10298 | * port data structures. |
| 10299 | * This function does following operations: |
| 10300 | * - Free discovery resources associated with this virtual |
| 10301 | * port. |
| 10302 | * - Free iocbs associated with this virtual port in |
| 10303 | * the txq. |
| 10304 | * - Send abort for all iocb commands associated with this |
| 10305 | * vport in txcmplq. |
| 10306 | * |
| 10307 | * This function is called with no lock held and always returns 1. |
| 10308 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10309 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10310 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10311 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10312 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10313 | struct lpfc_hba *phba = vport->phba; |
| 10314 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10315 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10316 | struct lpfc_sli_ring *pring; |
| 10317 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10318 | int i; |
| 10319 | unsigned long flags = 0; |
| 10320 | uint16_t prev_pring_flag; |
| 10321 | |
| 10322 | lpfc_cleanup_discovery_resources(vport); |
| 10323 | |
| 10324 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10325 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10326 | /* |
| 10327 | * Error everything on the txq since these iocbs |
| 10328 | * have not been given to the FW yet. |
| 10329 | * Also issue ABTS for everything on the txcmplq |
| 10330 | */ |
| 10331 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10332 | for (i = 0; i < psli->num_rings; i++) { |
| 10333 | pring = &psli->sli3_ring[i]; |
| 10334 | prev_pring_flag = pring->flag; |
| 10335 | /* Only slow rings */ |
| 10336 | if (pring->ringno == LPFC_ELS_RING) { |
| 10337 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10338 | /* Set the lpfc data pending flag */ |
| 10339 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10340 | } |
| 10341 | list_for_each_entry_safe(iocb, next_iocb, |
| 10342 | &pring->txq, list) { |
| 10343 | if (iocb->vport != vport) |
| 10344 | continue; |
| 10345 | list_move_tail(&iocb->list, &completions); |
| 10346 | } |
| 10347 | list_for_each_entry_safe(iocb, next_iocb, |
| 10348 | &pring->txcmplq, list) { |
| 10349 | if (iocb->vport != vport) |
| 10350 | continue; |
| 10351 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10352 | } |
| 10353 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10354 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10355 | } else { |
| 10356 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10357 | pring = qp->pring; |
| 10358 | if (!pring) |
| 10359 | continue; |
| 10360 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10361 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10362 | /* Set the lpfc data pending flag */ |
| 10363 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10364 | } |
| 10365 | prev_pring_flag = pring->flag; |
| 10366 | spin_lock_irq(&pring->ring_lock); |
| 10367 | list_for_each_entry_safe(iocb, next_iocb, |
| 10368 | &pring->txq, list) { |
| 10369 | if (iocb->vport != vport) |
| 10370 | continue; |
| 10371 | list_move_tail(&iocb->list, &completions); |
| 10372 | } |
| 10373 | spin_unlock_irq(&pring->ring_lock); |
| 10374 | list_for_each_entry_safe(iocb, next_iocb, |
| 10375 | &pring->txcmplq, list) { |
| 10376 | if (iocb->vport != vport) |
| 10377 | continue; |
| 10378 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10379 | } |
| 10380 | pring->flag = prev_pring_flag; |
| 10381 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10382 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10383 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10384 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10385 | /* Cancel all the IOCBs from the completions list */ |
| 10386 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10387 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10388 | return 1; |
| 10389 | } |
| 10390 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10391 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10392 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10393 | * @phba: Pointer to HBA context object. |
| 10394 | * |
| 10395 | * This function cleans up all iocb, buffers, mailbox commands |
| 10396 | * while shutting down the HBA. This function is called with no |
| 10397 | * lock held and always returns 1. |
| 10398 | * This function does the following to cleanup driver resources: |
| 10399 | * - Free discovery resources for each virtual port |
| 10400 | * - Cleanup any pending fabric iocbs |
| 10401 | * - Iterate through the iocb txq and free each entry |
| 10402 | * in the list. |
| 10403 | * - Free up any buffer posted to the HBA |
| 10404 | * - Free mailbox commands in the mailbox queue. |
| 10405 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10406 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10407 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10408 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10409 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10410 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10411 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10412 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10413 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10414 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10415 | int i; |
| 10416 | |
| 10417 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10418 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10419 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10420 | lpfc_hba_down_prep(phba); |
| 10421 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10422 | lpfc_fabric_abort_hba(phba); |
| 10423 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10424 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10425 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10426 | /* |
| 10427 | * Error everything on the txq since these iocbs |
| 10428 | * have not been given to the FW yet. |
| 10429 | */ |
| 10430 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10431 | for (i = 0; i < psli->num_rings; i++) { |
| 10432 | pring = &psli->sli3_ring[i]; |
| 10433 | /* Only slow rings */ |
| 10434 | if (pring->ringno == LPFC_ELS_RING) { |
| 10435 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10436 | /* Set the lpfc data pending flag */ |
| 10437 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10438 | } |
| 10439 | list_splice_init(&pring->txq, &completions); |
| 10440 | } |
| 10441 | } else { |
| 10442 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10443 | pring = qp->pring; |
| 10444 | if (!pring) |
| 10445 | continue; |
| 10446 | spin_lock_irq(&pring->ring_lock); |
| 10447 | list_splice_init(&pring->txq, &completions); |
| 10448 | spin_unlock_irq(&pring->ring_lock); |
| 10449 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10450 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10451 | /* Set the lpfc data pending flag */ |
| 10452 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10453 | } |
| 10454 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10455 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10456 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10457 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10458 | /* Cancel all the IOCBs from the completions list */ |
| 10459 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10460 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10461 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10462 | spin_lock_irqsave(&phba->hbalock, flags); |
| 10463 | list_splice_init(&phba->elsbuf, &completions); |
| 10464 | phba->elsbuf_cnt = 0; |
| 10465 | phba->elsbuf_prev_cnt = 0; |
| 10466 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10467 | |
| 10468 | while (!list_empty(&completions)) { |
| 10469 | list_remove_head(&completions, buf_ptr, |
| 10470 | struct lpfc_dmabuf, list); |
| 10471 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 10472 | kfree(buf_ptr); |
| 10473 | } |
| 10474 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10475 | /* Return any active mbox cmds */ |
| 10476 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10477 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10478 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10479 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10480 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10481 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10482 | return 1; |
| 10483 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10484 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10485 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10486 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10487 | * @srcp: Source memory pointer. |
| 10488 | * @destp: Destination memory pointer. |
| 10489 | * @cnt: Number of words required to be copied. |
| 10490 | * |
| 10491 | * This function is used for copying data between driver memory |
| 10492 | * and the SLI memory. This function also changes the endianness |
| 10493 | * of each word if native endianness is different from SLI |
| 10494 | * endianness. This function can be called with or without |
| 10495 | * lock. |
| 10496 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10497 | void |
| 10498 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10499 | { |
| 10500 | uint32_t *src = srcp; |
| 10501 | uint32_t *dest = destp; |
| 10502 | uint32_t ldata; |
| 10503 | int i; |
| 10504 | |
| 10505 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 10506 | ldata = *src; |
| 10507 | ldata = le32_to_cpu(ldata); |
| 10508 | *dest = ldata; |
| 10509 | src++; |
| 10510 | dest++; |
| 10511 | } |
| 10512 | } |
| 10513 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10514 | |
| 10515 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 10516 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 10517 | * @srcp: Source memory pointer. |
| 10518 | * @destp: Destination memory pointer. |
| 10519 | * @cnt: Number of words required to be copied. |
| 10520 | * |
| 10521 | * This function is used for copying data between a data structure |
| 10522 | * with big endian representation to local endianness. |
| 10523 | * This function can be called with or without lock. |
| 10524 | **/ |
| 10525 | void |
| 10526 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10527 | { |
| 10528 | uint32_t *src = srcp; |
| 10529 | uint32_t *dest = destp; |
| 10530 | uint32_t ldata; |
| 10531 | int i; |
| 10532 | |
| 10533 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 10534 | ldata = *src; |
| 10535 | ldata = be32_to_cpu(ldata); |
| 10536 | *dest = ldata; |
| 10537 | src++; |
| 10538 | dest++; |
| 10539 | } |
| 10540 | } |
| 10541 | |
| 10542 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10543 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10544 | * @phba: Pointer to HBA context object. |
| 10545 | * @pring: Pointer to driver SLI ring object. |
| 10546 | * @mp: Pointer to driver buffer object. |
| 10547 | * |
| 10548 | * This function is called with no lock held. |
| 10549 | * It always return zero after adding the buffer to the postbufq |
| 10550 | * buffer list. |
| 10551 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10552 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10553 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10554 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10555 | { |
| 10556 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 10557 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10558 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10559 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10560 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10561 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10562 | return 0; |
| 10563 | } |
| 10564 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10565 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10566 | * 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] | 10567 | * @phba: Pointer to HBA context object. |
| 10568 | * |
| 10569 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 10570 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 10571 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 10572 | * does not conflict with tags of buffer posted for unsolicited events. |
| 10573 | * The function returns the allocated tag. The function is called with |
| 10574 | * no locks held. |
| 10575 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10576 | uint32_t |
| 10577 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 10578 | { |
| 10579 | spin_lock_irq(&phba->hbalock); |
| 10580 | phba->buffer_tag_count++; |
| 10581 | /* |
| 10582 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 10583 | * a tag assigned by HBQ. |
| 10584 | */ |
| 10585 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 10586 | spin_unlock_irq(&phba->hbalock); |
| 10587 | return phba->buffer_tag_count; |
| 10588 | } |
| 10589 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10590 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10591 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10592 | * @phba: Pointer to HBA context object. |
| 10593 | * @pring: Pointer to driver SLI ring object. |
| 10594 | * @tag: Buffer tag. |
| 10595 | * |
| 10596 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 10597 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 10598 | * iocb is posted to the response ring with the tag of the buffer. |
| 10599 | * This function searches the pring->postbufq list using the tag |
| 10600 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 10601 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 10602 | * buffer is returned to the caller else NULL is returned. |
| 10603 | * This function is called with no lock held. |
| 10604 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10605 | struct lpfc_dmabuf * |
| 10606 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10607 | uint32_t tag) |
| 10608 | { |
| 10609 | struct lpfc_dmabuf *mp, *next_mp; |
| 10610 | struct list_head *slp = &pring->postbufq; |
| 10611 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10612 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10613 | spin_lock_irq(&phba->hbalock); |
| 10614 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10615 | if (mp->buffer_tag == tag) { |
| 10616 | list_del_init(&mp->list); |
| 10617 | pring->postbufq_cnt--; |
| 10618 | spin_unlock_irq(&phba->hbalock); |
| 10619 | return mp; |
| 10620 | } |
| 10621 | } |
| 10622 | |
| 10623 | spin_unlock_irq(&phba->hbalock); |
| 10624 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10625 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10626 | "ring %d Data x%lx x%p x%p x%x\n", |
| 10627 | pring->ringno, (unsigned long) tag, |
| 10628 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10629 | |
| 10630 | return NULL; |
| 10631 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10632 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10633 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10634 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10635 | * @phba: Pointer to HBA context object. |
| 10636 | * @pring: Pointer to driver SLI ring object. |
| 10637 | * @phys: DMA address of the buffer. |
| 10638 | * |
| 10639 | * This function searches the buffer list using the dma_address |
| 10640 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 10641 | * corresponding to the dma_address. The function returns the |
| 10642 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 10643 | * This function is called by the ct and els unsolicited event |
| 10644 | * handlers to get the buffer associated with the unsolicited |
| 10645 | * event. |
| 10646 | * |
| 10647 | * This function is called with no lock held. |
| 10648 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10649 | struct lpfc_dmabuf * |
| 10650 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10651 | dma_addr_t phys) |
| 10652 | { |
| 10653 | struct lpfc_dmabuf *mp, *next_mp; |
| 10654 | struct list_head *slp = &pring->postbufq; |
| 10655 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10656 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10657 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10658 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10659 | if (mp->phys == phys) { |
| 10660 | list_del_init(&mp->list); |
| 10661 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10662 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10663 | return mp; |
| 10664 | } |
| 10665 | } |
| 10666 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10667 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10668 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10669 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10670 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10671 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10672 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10673 | return NULL; |
| 10674 | } |
| 10675 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10676 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10677 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10678 | * @phba: Pointer to HBA context object. |
| 10679 | * @cmdiocb: Pointer to driver command iocb object. |
| 10680 | * @rspiocb: Pointer to driver response iocb object. |
| 10681 | * |
| 10682 | * This function is the completion handler for the abort iocbs for |
| 10683 | * ELS commands. This function is called from the ELS ring event |
| 10684 | * handler with no lock held. This function frees memory resources |
| 10685 | * associated with the abort iocb. |
| 10686 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10687 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10688 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10689 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10690 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10691 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10692 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10693 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10694 | |
| 10695 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10696 | |
| 10697 | /* |
| 10698 | * Assume that the port already completed and returned, or |
| 10699 | * will return the iocb. Just Log the message. |
| 10700 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10701 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 10702 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 10703 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10704 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10705 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 10706 | if (abort_iotag != 0 && |
| 10707 | abort_iotag <= phba->sli.last_iotag) |
| 10708 | abort_iocb = |
| 10709 | phba->sli.iocbq_lookup[abort_iotag]; |
| 10710 | } else |
| 10711 | /* For sli4 the abort_tag is the XRI, |
| 10712 | * so the abort routine puts the iotag of the iocb |
| 10713 | * being aborted in the context field of the abort |
| 10714 | * IOCB. |
| 10715 | */ |
| 10716 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10717 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10718 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 10719 | "0327 Cannot abort els iocb %p " |
| 10720 | "with tag %x context %x, abort status %x, " |
| 10721 | "abort code %x\n", |
| 10722 | abort_iocb, abort_iotag, abort_context, |
| 10723 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10724 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10725 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10726 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10727 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10728 | return; |
| 10729 | } |
| 10730 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10731 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10732 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10733 | * @phba: Pointer to HBA context object. |
| 10734 | * @cmdiocb: Pointer to driver command iocb object. |
| 10735 | * @rspiocb: Pointer to driver response iocb object. |
| 10736 | * |
| 10737 | * The function is called from SLI ring event handler with no |
| 10738 | * lock held. This function is the completion handler for ELS commands |
| 10739 | * which are aborted. The function frees memory resources used for |
| 10740 | * the aborted ELS commands. |
| 10741 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10742 | static void |
| 10743 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10744 | struct lpfc_iocbq *rspiocb) |
| 10745 | { |
| 10746 | IOCB_t *irsp = &rspiocb->iocb; |
| 10747 | |
| 10748 | /* ELS cmd tag <ulpIoTag> completes */ |
| 10749 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10750 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10751 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10752 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10753 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10754 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 10755 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 10756 | else |
| 10757 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10758 | return; |
| 10759 | } |
| 10760 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10761 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10762 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10763 | * @phba: Pointer to HBA context object. |
| 10764 | * @pring: Pointer to driver SLI ring object. |
| 10765 | * @cmdiocb: Pointer to driver command iocb object. |
| 10766 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10767 | * This function issues an abort iocb for the provided command iocb down to |
| 10768 | * the port. Other than the case the outstanding command iocb is an abort |
| 10769 | * request, this function issues abort out unconditionally. This function is |
| 10770 | * called with hbalock held. The function returns 0 when it fails due to |
| 10771 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10772 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10773 | static int |
| 10774 | 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] | 10775 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10776 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10777 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10778 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10779 | IOCB_t *icmd = NULL; |
| 10780 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10781 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10782 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10783 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10784 | lockdep_assert_held(&phba->hbalock); |
| 10785 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10786 | /* |
| 10787 | * There are certain command types we don't want to abort. And we |
| 10788 | * don't want to abort commands that are already in the process of |
| 10789 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10790 | */ |
| 10791 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10792 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10793 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 10794 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10795 | return 0; |
| 10796 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10797 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10798 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10799 | if (abtsiocbp == NULL) |
| 10800 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10801 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10802 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10803 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10804 | */ |
| 10805 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10806 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10807 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10808 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10809 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10810 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10811 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10812 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 10813 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10814 | else |
| 10815 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10816 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10817 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10818 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10819 | /* 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] | 10820 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10821 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 10822 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10823 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 10824 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10825 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10826 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10827 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 10828 | else |
| 10829 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 10830 | |
| 10831 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 10832 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 10833 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10834 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 10835 | "0339 Abort xri x%x, original iotag x%x, " |
| 10836 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10837 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10838 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10839 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10840 | |
| 10841 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10842 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 10843 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10844 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10845 | /* Note: both hbalock and ring_lock need to be set here */ |
| 10846 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10847 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10848 | abtsiocbp, 0); |
| 10849 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 10850 | } else { |
| 10851 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10852 | abtsiocbp, 0); |
| 10853 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10854 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10855 | if (retval) |
| 10856 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10857 | |
| 10858 | /* |
| 10859 | * Caller to this routine should check for IOCB_ERROR |
| 10860 | * and handle it properly. This routine no longer removes |
| 10861 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 10862 | */ |
| 10863 | return retval; |
| 10864 | } |
| 10865 | |
| 10866 | /** |
| 10867 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 10868 | * @phba: Pointer to HBA context object. |
| 10869 | * @pring: Pointer to driver SLI ring object. |
| 10870 | * @cmdiocb: Pointer to driver command iocb object. |
| 10871 | * |
| 10872 | * This function issues an abort iocb for the provided command iocb. In case |
| 10873 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 10874 | * ring. Instead, the callback function shall be changed to those commands |
| 10875 | * so that nothing happens when them finishes. This function is called with |
| 10876 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 10877 | * request. |
| 10878 | **/ |
| 10879 | int |
| 10880 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10881 | struct lpfc_iocbq *cmdiocb) |
| 10882 | { |
| 10883 | struct lpfc_vport *vport = cmdiocb->vport; |
| 10884 | int retval = IOCB_ERROR; |
| 10885 | IOCB_t *icmd = NULL; |
| 10886 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10887 | lockdep_assert_held(&phba->hbalock); |
| 10888 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10889 | /* |
| 10890 | * There are certain command types we don't want to abort. And we |
| 10891 | * don't want to abort commands that are already in the process of |
| 10892 | * being aborted. |
| 10893 | */ |
| 10894 | icmd = &cmdiocb->iocb; |
| 10895 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 10896 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 10897 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 10898 | return 0; |
| 10899 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 10900 | if (!pring) { |
| 10901 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 10902 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10903 | else |
| 10904 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10905 | goto abort_iotag_exit; |
| 10906 | } |
| 10907 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10908 | /* |
| 10909 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 10910 | * the callback so that nothing happens when it finishes. |
| 10911 | */ |
| 10912 | if ((vport->load_flag & FC_UNLOADING) && |
| 10913 | (pring->ringno == LPFC_ELS_RING)) { |
| 10914 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 10915 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10916 | else |
| 10917 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10918 | goto abort_iotag_exit; |
| 10919 | } |
| 10920 | |
| 10921 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 10922 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 10923 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10924 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10925 | /* |
| 10926 | * Caller to this routine should check for IOCB_ERROR |
| 10927 | * and handle it properly. This routine no longer removes |
| 10928 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10929 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10930 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10931 | } |
| 10932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10933 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10934 | * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb |
| 10935 | * @phba: Pointer to HBA context object. |
| 10936 | * @pring: Pointer to driver SLI ring object. |
| 10937 | * @cmdiocb: Pointer to driver command iocb object. |
| 10938 | * |
| 10939 | * This function issues an abort iocb for the provided command iocb down to |
| 10940 | * the port. Other than the case the outstanding command iocb is an abort |
| 10941 | * request, this function issues abort out unconditionally. This function is |
| 10942 | * called with hbalock held. The function returns 0 when it fails due to |
| 10943 | * memory allocation failure or when the command iocb is an abort request. |
| 10944 | **/ |
| 10945 | static int |
| 10946 | lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10947 | struct lpfc_iocbq *cmdiocb) |
| 10948 | { |
| 10949 | struct lpfc_vport *vport = cmdiocb->vport; |
| 10950 | struct lpfc_iocbq *abtsiocbp; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 10951 | union lpfc_wqe128 *abts_wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10952 | int retval; |
| 10953 | |
| 10954 | /* |
| 10955 | * There are certain command types we don't want to abort. And we |
| 10956 | * don't want to abort commands that are already in the process of |
| 10957 | * being aborted. |
| 10958 | */ |
| 10959 | if (cmdiocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 10960 | cmdiocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN || |
| 10961 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 10962 | return 0; |
| 10963 | |
| 10964 | /* issue ABTS for this io based on iotag */ |
| 10965 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| 10966 | if (abtsiocbp == NULL) |
| 10967 | return 0; |
| 10968 | |
| 10969 | /* This signals the response to set the correct status |
| 10970 | * before calling the completion handler |
| 10971 | */ |
| 10972 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10973 | |
| 10974 | /* Complete prepping the abort wqe and issue to the FW. */ |
| 10975 | abts_wqe = &abtsiocbp->wqe; |
| 10976 | bf_set(abort_cmd_ia, &abts_wqe->abort_cmd, 0); |
| 10977 | bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); |
| 10978 | |
| 10979 | /* Explicitly set reserved fields to zero.*/ |
| 10980 | abts_wqe->abort_cmd.rsrvd4 = 0; |
| 10981 | abts_wqe->abort_cmd.rsrvd5 = 0; |
| 10982 | |
| 10983 | /* WQE Common - word 6. Context is XRI tag. Set 0. */ |
| 10984 | bf_set(wqe_xri_tag, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10985 | bf_set(wqe_ctxt_tag, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10986 | |
| 10987 | /* word 7 */ |
| 10988 | bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10989 | bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 10990 | bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com, |
| 10991 | cmdiocb->iocb.ulpClass); |
| 10992 | |
| 10993 | /* word 8 - tell the FW to abort the IO associated with this |
| 10994 | * outstanding exchange ID. |
| 10995 | */ |
| 10996 | abts_wqe->abort_cmd.wqe_com.abort_tag = cmdiocb->sli4_xritag; |
| 10997 | |
| 10998 | /* word 9 - this is the iotag for the abts_wqe completion. */ |
| 10999 | bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, |
| 11000 | abtsiocbp->iotag); |
| 11001 | |
| 11002 | /* word 10 */ |
| 11003 | bf_set(wqe_wqid, &abts_wqe->abort_cmd.wqe_com, cmdiocb->hba_wqidx); |
| 11004 | bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); |
| 11005 | bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 11006 | |
| 11007 | /* word 11 */ |
| 11008 | bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); |
| 11009 | bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); |
| 11010 | bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
| 11011 | |
| 11012 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 11013 | abtsiocbp->iocb_flag |= LPFC_IO_NVME; |
| 11014 | abtsiocbp->vport = vport; |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11015 | abtsiocbp->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11016 | retval = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abtsiocbp); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 11017 | if (retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11018 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 11019 | "6147 Failed abts issue_wqe with status x%x " |
| 11020 | "for oxid x%x\n", |
| 11021 | retval, cmdiocb->sli4_xritag); |
| 11022 | lpfc_sli_release_iocbq(phba, abtsiocbp); |
| 11023 | return retval; |
| 11024 | } |
| 11025 | |
| 11026 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 11027 | "6148 Drv Abort NVME Request Issued for " |
| 11028 | "ox_id x%x on reqtag x%x\n", |
| 11029 | cmdiocb->sli4_xritag, |
| 11030 | abtsiocbp->iotag); |
| 11031 | |
| 11032 | return retval; |
| 11033 | } |
| 11034 | |
| 11035 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11036 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 11037 | * @phba: pointer to lpfc HBA data structure. |
| 11038 | * |
| 11039 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 11040 | **/ |
| 11041 | void |
| 11042 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 11043 | { |
| 11044 | struct lpfc_sli *psli = &phba->sli; |
| 11045 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11046 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11047 | int i; |
| 11048 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11049 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11050 | for (i = 0; i < psli->num_rings; i++) { |
| 11051 | pring = &psli->sli3_ring[i]; |
| 11052 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 11053 | } |
| 11054 | return; |
| 11055 | } |
| 11056 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 11057 | pring = qp->pring; |
| 11058 | if (!pring) |
| 11059 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11060 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11061 | } |
| 11062 | } |
| 11063 | |
| 11064 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11065 | * 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] | 11066 | * @iocbq: Pointer to driver iocb object. |
| 11067 | * @vport: Pointer to driver virtual port object. |
| 11068 | * @tgt_id: SCSI ID of the target. |
| 11069 | * @lun_id: LUN ID of the scsi device. |
| 11070 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 11071 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11072 | * 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] | 11073 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 11074 | * 0 if the filtering criteria is met for the given iocb and will return |
| 11075 | * 1 if the filtering criteria is not met. |
| 11076 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 11077 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 11078 | * lun_id parameter. |
| 11079 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 11080 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 11081 | * parameters. |
| 11082 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 11083 | * given iocb is for the SCSI host associated with the given vport. |
| 11084 | * This function is called with no locks held. |
| 11085 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11086 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11087 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 11088 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11089 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11090 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11091 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11092 | int rc = 1; |
| 11093 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11094 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 11095 | return rc; |
| 11096 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11097 | if (iocbq->vport != vport) |
| 11098 | return rc; |
| 11099 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11100 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11101 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11102 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11103 | return rc; |
| 11104 | |
| 11105 | switch (ctx_cmd) { |
| 11106 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11107 | if ((lpfc_cmd->rdata->pnode) && |
| 11108 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 11109 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11110 | rc = 0; |
| 11111 | break; |
| 11112 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11113 | if ((lpfc_cmd->rdata->pnode) && |
| 11114 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11115 | rc = 0; |
| 11116 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11117 | case LPFC_CTX_HOST: |
| 11118 | rc = 0; |
| 11119 | break; |
| 11120 | default: |
| 11121 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 11122 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11123 | break; |
| 11124 | } |
| 11125 | |
| 11126 | return rc; |
| 11127 | } |
| 11128 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11129 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11130 | * 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] | 11131 | * @vport: Pointer to virtual port. |
| 11132 | * @tgt_id: SCSI ID of the target. |
| 11133 | * @lun_id: LUN ID of the scsi device. |
| 11134 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11135 | * |
| 11136 | * This function returns number of FCP commands pending for the vport. |
| 11137 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 11138 | * commands pending on the vport associated with SCSI device specified |
| 11139 | * by tgt_id and lun_id parameters. |
| 11140 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 11141 | * commands pending on the vport associated with SCSI target specified |
| 11142 | * by tgt_id parameter. |
| 11143 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 11144 | * commands pending on the vport. |
| 11145 | * This function returns the number of iocbs which satisfy the filter. |
| 11146 | * This function is called without any lock held. |
| 11147 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11148 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11149 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 11150 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11151 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11152 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11153 | struct lpfc_iocbq *iocbq; |
| 11154 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11155 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11156 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11157 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 11158 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11159 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11160 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 11161 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11162 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11163 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 11164 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11165 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11166 | return sum; |
| 11167 | } |
| 11168 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11169 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11170 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11171 | * @phba: Pointer to HBA context object |
| 11172 | * @cmdiocb: Pointer to command iocb object. |
| 11173 | * @rspiocb: Pointer to response iocb object. |
| 11174 | * |
| 11175 | * This function is called when an aborted FCP iocb completes. This |
| 11176 | * function is called by the ring event handler with no lock held. |
| 11177 | * This function frees the iocb. |
| 11178 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11179 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11180 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 11181 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11182 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11183 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 11184 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 11185 | "original iotag x%x, abort cmd iotag x%x " |
| 11186 | "status 0x%x, reason 0x%x\n", |
| 11187 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 11188 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 11189 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 11190 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11191 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11192 | return; |
| 11193 | } |
| 11194 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11195 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11196 | * 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] | 11197 | * @vport: Pointer to virtual port. |
| 11198 | * @pring: Pointer to driver SLI ring object. |
| 11199 | * @tgt_id: SCSI ID of the target. |
| 11200 | * @lun_id: LUN ID of the scsi device. |
| 11201 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11202 | * |
| 11203 | * This function sends an abort command for every SCSI command |
| 11204 | * associated with the given virtual port pending on the ring |
| 11205 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11206 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11207 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11208 | * parameters |
| 11209 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11210 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11211 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11212 | * FCP iocbs associated with virtual port. |
| 11213 | * This function returns number of iocbs it failed to abort. |
| 11214 | * This function is called with no locks held. |
| 11215 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11216 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11217 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11218 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11219 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11220 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11221 | struct lpfc_iocbq *iocbq; |
| 11222 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11223 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11224 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11225 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11226 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11227 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11228 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11229 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11230 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11231 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11232 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11233 | continue; |
| 11234 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11235 | /* |
| 11236 | * If the iocbq is already being aborted, don't take a second |
| 11237 | * action, but do count it. |
| 11238 | */ |
| 11239 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11240 | continue; |
| 11241 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11242 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11243 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11244 | if (abtsiocb == NULL) { |
| 11245 | errcnt++; |
| 11246 | continue; |
| 11247 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11248 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11249 | /* indicate the IO is being aborted by the driver. */ |
| 11250 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11251 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11252 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11253 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11254 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11255 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11256 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 11257 | else |
| 11258 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11259 | abtsiocb->iocb.ulpLe = 1; |
| 11260 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11261 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11262 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11263 | /* 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] | 11264 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11265 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11266 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11267 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11268 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11269 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11270 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11271 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11272 | else |
| 11273 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11274 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11275 | /* Setup callback routine and issue the command. */ |
| 11276 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11277 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11278 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11279 | if (!pring_s4) |
| 11280 | continue; |
| 11281 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11282 | abtsiocb, 0); |
| 11283 | } else |
| 11284 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11285 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11286 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11287 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11288 | errcnt++; |
| 11289 | continue; |
| 11290 | } |
| 11291 | } |
| 11292 | |
| 11293 | return errcnt; |
| 11294 | } |
| 11295 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11296 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11297 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11298 | * @vport: Pointer to virtual port. |
| 11299 | * @pring: Pointer to driver SLI ring object. |
| 11300 | * @tgt_id: SCSI ID of the target. |
| 11301 | * @lun_id: LUN ID of the scsi device. |
| 11302 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11303 | * |
| 11304 | * This function sends an abort command for every SCSI command |
| 11305 | * associated with the given virtual port pending on the ring |
| 11306 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11307 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11308 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11309 | * parameters |
| 11310 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11311 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11312 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11313 | * FCP iocbs associated with virtual port. |
| 11314 | * This function returns number of iocbs it aborted . |
| 11315 | * This function is called with no locks held right after a taskmgmt |
| 11316 | * command is sent. |
| 11317 | **/ |
| 11318 | int |
| 11319 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11320 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11321 | { |
| 11322 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11323 | struct lpfc_scsi_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11324 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11325 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11326 | struct lpfc_iocbq *iocbq; |
| 11327 | IOCB_t *icmd; |
| 11328 | int sum, i, ret_val; |
| 11329 | unsigned long iflags; |
| 11330 | struct lpfc_sli_ring *pring_s4; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11331 | |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11332 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11333 | |
| 11334 | /* all I/Os are in process of being flushed */ |
| 11335 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11336 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11337 | return 0; |
| 11338 | } |
| 11339 | sum = 0; |
| 11340 | |
| 11341 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11342 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11343 | |
| 11344 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11345 | cmd) != 0) |
| 11346 | continue; |
| 11347 | |
| 11348 | /* |
| 11349 | * If the iocbq is already being aborted, don't take a second |
| 11350 | * action, but do count it. |
| 11351 | */ |
| 11352 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11353 | continue; |
| 11354 | |
| 11355 | /* issue ABTS for this IOCB based on iotag */ |
| 11356 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
| 11357 | if (abtsiocbq == NULL) |
| 11358 | continue; |
| 11359 | |
| 11360 | icmd = &iocbq->iocb; |
| 11361 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11362 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11363 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11364 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11365 | iocbq->sli4_xritag; |
| 11366 | else |
| 11367 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11368 | abtsiocbq->iocb.ulpLe = 1; |
| 11369 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11370 | abtsiocbq->vport = vport; |
| 11371 | |
| 11372 | /* 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] | 11373 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11374 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11375 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11376 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11377 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11378 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11379 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 11380 | ndlp = lpfc_cmd->rdata->pnode; |
| 11381 | |
| 11382 | if (lpfc_is_link_up(phba) && |
| 11383 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11384 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11385 | else |
| 11386 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11387 | |
| 11388 | /* Setup callback routine and issue the command. */ |
| 11389 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11390 | |
| 11391 | /* |
| 11392 | * Indicate the IO is being aborted by the driver and set |
| 11393 | * the caller's flag into the aborted IO. |
| 11394 | */ |
| 11395 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11396 | |
| 11397 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11398 | pring_s4 = lpfc_sli4_calc_ring(phba, abtsiocbq); |
| 11399 | if (!pring_s4) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11400 | continue; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11401 | /* Note: both hbalock and ring_lock must be set here */ |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11402 | spin_lock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11403 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11404 | abtsiocbq, 0); |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11405 | spin_unlock(&pring_s4->ring_lock); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11406 | } else { |
| 11407 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11408 | abtsiocbq, 0); |
| 11409 | } |
| 11410 | |
| 11411 | |
| 11412 | if (ret_val == IOCB_ERROR) |
| 11413 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11414 | else |
| 11415 | sum++; |
| 11416 | } |
James Smart | 59c68ea | 2018-04-09 14:24:25 -0700 | [diff] [blame] | 11417 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11418 | return sum; |
| 11419 | } |
| 11420 | |
| 11421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11422 | * 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] | 11423 | * @phba: Pointer to HBA context object. |
| 11424 | * @cmdiocbq: Pointer to command iocb. |
| 11425 | * @rspiocbq: Pointer to response iocb. |
| 11426 | * |
| 11427 | * This function is the completion handler for iocbs issued using |
| 11428 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11429 | * ring event handler function without any lock held. This function |
| 11430 | * can be called from both worker thread context and interrupt |
| 11431 | * context. This function also can be called from other thread which |
| 11432 | * cleans up the SLI layer objects. |
| 11433 | * This function copy the contents of the response iocb to the |
| 11434 | * response iocb memory object provided by the caller of |
| 11435 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11436 | * sleeps for the iocb completion. |
| 11437 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11438 | static void |
| 11439 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11440 | struct lpfc_iocbq *cmdiocbq, |
| 11441 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11442 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11443 | wait_queue_head_t *pdone_q; |
| 11444 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11445 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11446 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11447 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11448 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11449 | |
| 11450 | /* |
| 11451 | * A time out has occurred for the iocb. If a time out |
| 11452 | * completion handler has been supplied, call it. Otherwise, |
| 11453 | * just free the iocbq. |
| 11454 | */ |
| 11455 | |
| 11456 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11457 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11458 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11459 | if (cmdiocbq->iocb_cmpl) |
| 11460 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11461 | else |
| 11462 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11463 | return; |
| 11464 | } |
| 11465 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11466 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11467 | if (cmdiocbq->context2 && rspiocbq) |
| 11468 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11469 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11470 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11471 | /* Set the exchange busy flag for task management commands */ |
| 11472 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11473 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 11474 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 11475 | cur_iocbq); |
| 11476 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 11477 | } |
| 11478 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11479 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11480 | if (pdone_q) |
| 11481 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11482 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11483 | return; |
| 11484 | } |
| 11485 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11486 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11487 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 11488 | * @phba: Pointer to HBA context object.. |
| 11489 | * @piocbq: Pointer to command iocb. |
| 11490 | * @flag: Flag to test. |
| 11491 | * |
| 11492 | * This routine grabs the hbalock and then test the iocb_flag to |
| 11493 | * see if the passed in flag is set. |
| 11494 | * Returns: |
| 11495 | * 1 if flag is set. |
| 11496 | * 0 if flag is not set. |
| 11497 | **/ |
| 11498 | static int |
| 11499 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 11500 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 11501 | { |
| 11502 | unsigned long iflags; |
| 11503 | int ret; |
| 11504 | |
| 11505 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11506 | ret = piocbq->iocb_flag & flag; |
| 11507 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11508 | return ret; |
| 11509 | |
| 11510 | } |
| 11511 | |
| 11512 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11513 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11514 | * @phba: Pointer to HBA context object.. |
| 11515 | * @pring: Pointer to sli ring. |
| 11516 | * @piocb: Pointer to command iocb. |
| 11517 | * @prspiocbq: Pointer to response iocb. |
| 11518 | * @timeout: Timeout in number of seconds. |
| 11519 | * |
| 11520 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11521 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 11522 | * to handle iocbs which time out. If the field is NULL, the |
| 11523 | * function shall free the iocbq structure. If more clean up is |
| 11524 | * needed, the caller is expected to provide a completion function |
| 11525 | * that will provide the needed clean up. If the iocb command is |
| 11526 | * not completed within timeout seconds, the function will either |
| 11527 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 11528 | * completion function set in the iocb_cmpl field and then return |
| 11529 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 11530 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11531 | * The function waits for the iocb completion using an |
| 11532 | * non-interruptible wait. |
| 11533 | * This function will sleep while waiting for iocb completion. |
| 11534 | * So, this function should not be called from any context which |
| 11535 | * does not allow sleeping. Due to the same reason, this function |
| 11536 | * cannot be called with interrupt disabled. |
| 11537 | * This function assumes that the iocb completions occur while |
| 11538 | * this function sleep. So, this function cannot be called from |
| 11539 | * the thread which process iocb completion for this ring. |
| 11540 | * This function clears the iocb_flag of the iocb object before |
| 11541 | * issuing the iocb and the iocb completion handler sets this |
| 11542 | * flag and wakes this thread when the iocb completes. |
| 11543 | * The contents of the response iocb will be copied to prspiocbq |
| 11544 | * by the completion handler when the command completes. |
| 11545 | * This function returns IOCB_SUCCESS when success. |
| 11546 | * This function is called with no lock held. |
| 11547 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11548 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11549 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11550 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11551 | struct lpfc_iocbq *piocb, |
| 11552 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11553 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11554 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11555 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11556 | long timeleft, timeout_req = 0; |
| 11557 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11558 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11559 | struct lpfc_iocbq *iocb; |
| 11560 | int txq_cnt = 0; |
| 11561 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11562 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11563 | unsigned long iflags; |
| 11564 | bool iocb_completed = true; |
| 11565 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11566 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 11567 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 11568 | else |
| 11569 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11570 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11571 | * If the caller has provided a response iocbq buffer, then context2 |
| 11572 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11573 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11574 | if (prspiocbq) { |
| 11575 | if (piocb->context2) |
| 11576 | return IOCB_ERROR; |
| 11577 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11578 | } |
| 11579 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11580 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11581 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 11582 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11583 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11584 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11585 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11586 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11587 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11588 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 11589 | writel(creg_val, phba->HCregaddr); |
| 11590 | readl(phba->HCregaddr); /* flush */ |
| 11591 | } |
| 11592 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11593 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 11594 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11595 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11596 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11597 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11598 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11599 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11600 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11601 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11602 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11603 | /* |
| 11604 | * IOCB timed out. Inform the wake iocb wait |
| 11605 | * completion function and set local status |
| 11606 | */ |
| 11607 | |
| 11608 | iocb_completed = false; |
| 11609 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 11610 | } |
| 11611 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11612 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11613 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11614 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 11615 | /* Note: we are not indicating if the IOCB has a success |
| 11616 | * status or not - that's for the caller to check. |
| 11617 | * IOCB_SUCCESS means just that the command was sent and |
| 11618 | * completed. Not that it completed successfully. |
| 11619 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11620 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11621 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11622 | "0338 IOCB wait timeout error - no " |
| 11623 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11624 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11625 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11626 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11627 | "0330 IOCB wake NOT set, " |
| 11628 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11629 | timeout, (timeleft / jiffies)); |
| 11630 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11631 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11632 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11633 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 11634 | list_for_each_entry(iocb, &pring->txq, list) { |
| 11635 | txq_cnt++; |
| 11636 | } |
| 11637 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 11638 | txcmplq_cnt++; |
| 11639 | } |
| 11640 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11641 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 11642 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 11643 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11644 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11645 | } else { |
| 11646 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11647 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11648 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11649 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11650 | } |
| 11651 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11652 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11653 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11654 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11655 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 11656 | writel(creg_val, phba->HCregaddr); |
| 11657 | readl(phba->HCregaddr); /* flush */ |
| 11658 | } |
| 11659 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11660 | if (prspiocbq) |
| 11661 | piocb->context2 = NULL; |
| 11662 | |
| 11663 | piocb->context_un.wait_queue = NULL; |
| 11664 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11665 | return retval; |
| 11666 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11667 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11668 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11669 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11670 | * @phba: Pointer to HBA context object. |
| 11671 | * @pmboxq: Pointer to driver mailbox object. |
| 11672 | * @timeout: Timeout in number of seconds. |
| 11673 | * |
| 11674 | * This function issues the mailbox to firmware and waits for the |
| 11675 | * mailbox command to complete. If the mailbox command is not |
| 11676 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 11677 | * The function waits for the mailbox completion using an |
| 11678 | * interruptible wait. If the thread is woken up due to a |
| 11679 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 11680 | * should not free the mailbox resources, if this function returns |
| 11681 | * MBX_TIMEOUT. |
| 11682 | * This function will sleep while waiting for mailbox completion. |
| 11683 | * So, this function should not be called from any context which |
| 11684 | * does not allow sleeping. Due to the same reason, this function |
| 11685 | * cannot be called with interrupt disabled. |
| 11686 | * This function assumes that the mailbox completion occurs while |
| 11687 | * this function sleep. So, this function cannot be called from |
| 11688 | * the worker thread which processes mailbox completion. |
| 11689 | * This function is called in the context of HBA management |
| 11690 | * applications. |
| 11691 | * This function returns MBX_SUCCESS when successful. |
| 11692 | * This function is called with no lock held. |
| 11693 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11694 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11695 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11696 | uint32_t timeout) |
| 11697 | { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 11698 | struct completion mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11699 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11700 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11701 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11702 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11703 | /* setup wake call as IOCB callback */ |
| 11704 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11705 | |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 11706 | /* setup context3 field to pass wait_queue pointer to wake function */ |
| 11707 | init_completion(&mbox_done); |
| 11708 | pmboxq->context3 = &mbox_done; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11709 | /* now issue the command */ |
| 11710 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11711 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 11712 | wait_for_completion_timeout(&mbox_done, |
| 11713 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11714 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11715 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | e29d74f | 2018-03-05 12:04:07 -0800 | [diff] [blame] | 11716 | pmboxq->context3 = NULL; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11717 | /* |
| 11718 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 11719 | * else do not free the resources. |
| 11720 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 11721 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11722 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 11723 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11724 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11725 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 11726 | } |
| 11727 | spin_unlock_irqrestore(&phba->hbalock, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11728 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11729 | return retval; |
| 11730 | } |
| 11731 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11732 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11733 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11734 | * @phba: Pointer to HBA context. |
| 11735 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11736 | * This function is called to shutdown the driver's mailbox sub-system. |
| 11737 | * It first marks the mailbox sub-system is in a block state to prevent |
| 11738 | * the asynchronous mailbox command from issued off the pending mailbox |
| 11739 | * command queue. If the mailbox command sub-system shutdown is due to |
| 11740 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 11741 | * the mailbox sub-system flush routine to forcefully bring down the |
| 11742 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 11743 | * as with offline or HBA function reset), this routine will wait for the |
| 11744 | * outstanding mailbox command to complete before invoking the mailbox |
| 11745 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11746 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11747 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11748 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11749 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11750 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11751 | unsigned long timeout; |
| 11752 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11753 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 11754 | /* delay 100ms for port state */ |
| 11755 | msleep(100); |
| 11756 | lpfc_sli_mbox_sys_flush(phba); |
| 11757 | return; |
| 11758 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11759 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 11760 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11761 | spin_lock_irq(&phba->hbalock); |
| 11762 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11763 | |
| 11764 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11765 | /* Determine how long we might wait for the active mailbox |
| 11766 | * command to be gracefully completed by firmware. |
| 11767 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11768 | if (phba->sli.mbox_active) |
| 11769 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 11770 | phba->sli.mbox_active) * |
| 11771 | 1000) + jiffies; |
| 11772 | spin_unlock_irq(&phba->hbalock); |
| 11773 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11774 | while (phba->sli.mbox_active) { |
| 11775 | /* Check active mailbox complete status every 2ms */ |
| 11776 | msleep(2); |
| 11777 | if (time_after(jiffies, timeout)) |
| 11778 | /* Timeout, let the mailbox flush routine to |
| 11779 | * forcefully release active mailbox command |
| 11780 | */ |
| 11781 | break; |
| 11782 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 11783 | } else |
| 11784 | spin_unlock_irq(&phba->hbalock); |
| 11785 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11786 | lpfc_sli_mbox_sys_flush(phba); |
| 11787 | } |
| 11788 | |
| 11789 | /** |
| 11790 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 11791 | * @phba: Pointer to HBA context. |
| 11792 | * |
| 11793 | * This function is called to read the SLI3 device error attention registers |
| 11794 | * for possible error attention events. The caller must hold the hostlock |
| 11795 | * with spin_lock_irq(). |
| 11796 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11797 | * 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] | 11798 | * Register and returns 0 otherwise. |
| 11799 | **/ |
| 11800 | static int |
| 11801 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 11802 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 11803 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11804 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11805 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11806 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11807 | goto unplug_err; |
| 11808 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11809 | if (ha_copy & HA_ERATT) { |
| 11810 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11811 | if (lpfc_sli_read_hs(phba)) |
| 11812 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11813 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11814 | /* Check if there is a deferred error condition is active */ |
| 11815 | if ((HS_FFER1 & phba->work_hs) && |
| 11816 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 11817 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11818 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11819 | /* Clear all interrupt enable conditions */ |
| 11820 | writel(0, phba->HCregaddr); |
| 11821 | readl(phba->HCregaddr); |
| 11822 | } |
| 11823 | |
| 11824 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11825 | phba->work_ha |= HA_ERATT; |
| 11826 | /* Indicate polling handles this ERATT */ |
| 11827 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11828 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11829 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11830 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11831 | |
| 11832 | unplug_err: |
| 11833 | /* Set the driver HS work bitmap */ |
| 11834 | phba->work_hs |= UNPLUG_ERR; |
| 11835 | /* Set the driver HA work bitmap */ |
| 11836 | phba->work_ha |= HA_ERATT; |
| 11837 | /* Indicate polling handles this ERATT */ |
| 11838 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11839 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11840 | } |
| 11841 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11842 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11843 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 11844 | * @phba: Pointer to HBA context. |
| 11845 | * |
| 11846 | * This function is called to read the SLI4 device error attention registers |
| 11847 | * for possible error attention events. The caller must hold the hostlock |
| 11848 | * with spin_lock_irq(). |
| 11849 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11850 | * 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] | 11851 | * Register and returns 0 otherwise. |
| 11852 | **/ |
| 11853 | static int |
| 11854 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 11855 | { |
| 11856 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11857 | uint32_t if_type, portsmphr; |
| 11858 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11859 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11860 | /* |
| 11861 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11862 | * registers for error attention. This can be changed later. |
| 11863 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11864 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 11865 | switch (if_type) { |
| 11866 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11867 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 11868 | &uerr_sta_lo) || |
| 11869 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 11870 | &uerr_sta_hi)) { |
| 11871 | phba->work_hs |= UNPLUG_ERR; |
| 11872 | phba->work_ha |= HA_ERATT; |
| 11873 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11874 | return 1; |
| 11875 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11876 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 11877 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 11878 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11879 | "1423 HBA Unrecoverable error: " |
| 11880 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 11881 | "ue_mask_lo_reg=0x%x, " |
| 11882 | "ue_mask_hi_reg=0x%x\n", |
| 11883 | uerr_sta_lo, uerr_sta_hi, |
| 11884 | phba->sli4_hba.ue_mask_lo, |
| 11885 | phba->sli4_hba.ue_mask_hi); |
| 11886 | phba->work_status[0] = uerr_sta_lo; |
| 11887 | phba->work_status[1] = uerr_sta_hi; |
| 11888 | phba->work_ha |= HA_ERATT; |
| 11889 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11890 | return 1; |
| 11891 | } |
| 11892 | break; |
| 11893 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 11894 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11895 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 11896 | &portstat_reg.word0) || |
| 11897 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 11898 | &portsmphr)){ |
| 11899 | phba->work_hs |= UNPLUG_ERR; |
| 11900 | phba->work_ha |= HA_ERATT; |
| 11901 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11902 | return 1; |
| 11903 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11904 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 11905 | phba->work_status[0] = |
| 11906 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 11907 | phba->work_status[1] = |
| 11908 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 11909 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11910 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11911 | "port status reg 0x%x, " |
| 11912 | "port smphr reg 0x%x, " |
| 11913 | "error 1=0x%x, error 2=0x%x\n", |
| 11914 | portstat_reg.word0, |
| 11915 | portsmphr, |
| 11916 | phba->work_status[0], |
| 11917 | phba->work_status[1]); |
| 11918 | phba->work_ha |= HA_ERATT; |
| 11919 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11920 | return 1; |
| 11921 | } |
| 11922 | break; |
| 11923 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 11924 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11926 | "2886 HBA Error Attention on unsupported " |
| 11927 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11928 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11929 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11930 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11931 | return 0; |
| 11932 | } |
| 11933 | |
| 11934 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11935 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11936 | * @phba: Pointer to HBA context. |
| 11937 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11938 | * 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] | 11939 | * error attention register bit for error attention events. |
| 11940 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11941 | * 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] | 11942 | * Register and returns 0 otherwise. |
| 11943 | **/ |
| 11944 | int |
| 11945 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 11946 | { |
| 11947 | uint32_t ha_copy; |
| 11948 | |
| 11949 | /* If somebody is waiting to handle an eratt, don't process it |
| 11950 | * here. The brdkill function will do this. |
| 11951 | */ |
| 11952 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11953 | return 0; |
| 11954 | |
| 11955 | /* Check if interrupt handler handles this ERATT */ |
| 11956 | spin_lock_irq(&phba->hbalock); |
| 11957 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 11958 | /* Interrupt handler has handled ERATT */ |
| 11959 | spin_unlock_irq(&phba->hbalock); |
| 11960 | return 0; |
| 11961 | } |
| 11962 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11963 | /* |
| 11964 | * If there is deferred error attention, do not check for error |
| 11965 | * attention |
| 11966 | */ |
| 11967 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 11968 | spin_unlock_irq(&phba->hbalock); |
| 11969 | return 0; |
| 11970 | } |
| 11971 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11972 | /* If PCI channel is offline, don't process it */ |
| 11973 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11974 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11975 | return 0; |
| 11976 | } |
| 11977 | |
| 11978 | switch (phba->sli_rev) { |
| 11979 | case LPFC_SLI_REV2: |
| 11980 | case LPFC_SLI_REV3: |
| 11981 | /* Read chip Host Attention (HA) register */ |
| 11982 | ha_copy = lpfc_sli_eratt_read(phba); |
| 11983 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11984 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11985 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11986 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 11987 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11988 | default: |
| 11989 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11990 | "0299 Invalid SLI revision (%d)\n", |
| 11991 | phba->sli_rev); |
| 11992 | ha_copy = 0; |
| 11993 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11994 | } |
| 11995 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11996 | |
| 11997 | return ha_copy; |
| 11998 | } |
| 11999 | |
| 12000 | /** |
| 12001 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 12002 | * @phba: Pointer to HBA context. |
| 12003 | * |
| 12004 | * This inline routine checks whether a device or its PCI slot is in a state |
| 12005 | * that the interrupt should be handled. |
| 12006 | * |
| 12007 | * This function returns 0 if the device or the PCI slot is in a state that |
| 12008 | * interrupt should be handled, otherwise -EIO. |
| 12009 | */ |
| 12010 | static inline int |
| 12011 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 12012 | { |
| 12013 | /* If the pci channel is offline, ignore all the interrupts */ |
| 12014 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 12015 | return -EIO; |
| 12016 | |
| 12017 | /* Update device level interrupt statistics */ |
| 12018 | phba->sli.slistat.sli_intr++; |
| 12019 | |
| 12020 | /* Ignore all interrupts during initialization. */ |
| 12021 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 12022 | return -EIO; |
| 12023 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12024 | return 0; |
| 12025 | } |
| 12026 | |
| 12027 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12028 | * 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] | 12029 | * @irq: Interrupt number. |
| 12030 | * @dev_id: The device context pointer. |
| 12031 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12032 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12033 | * service routine when device with SLI-3 interface spec is enabled with |
| 12034 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 12035 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 12036 | * interrupt mode, this function is called as part of the device-level |
| 12037 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 12038 | * is undergoing initialization, the interrupt handler will not process |
| 12039 | * the interrupt. The link attention and ELS ring attention events are |
| 12040 | * handled by the worker thread. The interrupt handler signals the worker |
| 12041 | * thread and returns for these events. This function is called without |
| 12042 | * 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] | 12043 | * structures. |
| 12044 | * |
| 12045 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12046 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12047 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12048 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12049 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12050 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12051 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12052 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12053 | uint32_t work_ha_copy; |
| 12054 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12055 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12056 | uint32_t control; |
| 12057 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12058 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12059 | struct lpfc_vport *vport; |
| 12060 | struct lpfc_nodelist *ndlp; |
| 12061 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12062 | LPFC_MBOXQ_t *pmb; |
| 12063 | int rc; |
| 12064 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12065 | /* |
| 12066 | * Get the driver's phba structure from the dev_id and |
| 12067 | * assume the HBA is not interrupting. |
| 12068 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12069 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12070 | |
| 12071 | if (unlikely(!phba)) |
| 12072 | return IRQ_NONE; |
| 12073 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12074 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12075 | * Stuff needs to be attented to when this function is invoked as an |
| 12076 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12077 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12078 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12079 | /* Check device state for handling interrupt */ |
| 12080 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12081 | return IRQ_NONE; |
| 12082 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12083 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12084 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12085 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12086 | /* If somebody is waiting to handle an eratt don't process it |
| 12087 | * here. The brdkill function will do this. |
| 12088 | */ |
| 12089 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 12090 | ha_copy &= ~HA_ERATT; |
| 12091 | /* Check the need for handling ERATT in interrupt handler */ |
| 12092 | if (ha_copy & HA_ERATT) { |
| 12093 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12094 | /* ERATT polling has handled ERATT */ |
| 12095 | ha_copy &= ~HA_ERATT; |
| 12096 | else |
| 12097 | /* Indicate interrupt handler handles ERATT */ |
| 12098 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12099 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12100 | |
| 12101 | /* |
| 12102 | * If there is deferred error attention, do not check for any |
| 12103 | * interrupt. |
| 12104 | */ |
| 12105 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12106 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12107 | return IRQ_NONE; |
| 12108 | } |
| 12109 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12110 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12111 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 12112 | goto unplug_error; |
| 12113 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12114 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 12115 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12116 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12117 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 12118 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12119 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12120 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12121 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12122 | } else |
| 12123 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12124 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12125 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 12126 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12127 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12128 | if (work_ha_copy & HA_LATT) { |
| 12129 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 12130 | /* |
| 12131 | * Turn off Link Attention interrupts |
| 12132 | * until CLEAR_LA done |
| 12133 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12134 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12135 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12136 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12137 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12138 | control &= ~HC_LAINT_ENA; |
| 12139 | writel(control, phba->HCregaddr); |
| 12140 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12141 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12142 | } |
| 12143 | else |
| 12144 | work_ha_copy &= ~HA_LATT; |
| 12145 | } |
| 12146 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12147 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12148 | /* |
| 12149 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 12150 | * the only slow ring. |
| 12151 | */ |
| 12152 | status = (work_ha_copy & |
| 12153 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12154 | status >>= (4*LPFC_ELS_RING); |
| 12155 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12156 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12157 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 12158 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12159 | |
| 12160 | lpfc_debugfs_slow_ring_trc(phba, |
| 12161 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 12162 | control, status, |
| 12163 | (uint32_t)phba->sli.slistat.sli_intr); |
| 12164 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12165 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12166 | lpfc_debugfs_slow_ring_trc(phba, |
| 12167 | "ISR Disable ring:" |
| 12168 | "pwork:x%x hawork:x%x wait:x%x", |
| 12169 | phba->work_ha, work_ha_copy, |
| 12170 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12171 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12172 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12173 | control &= |
| 12174 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12175 | writel(control, phba->HCregaddr); |
| 12176 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12177 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12178 | else { |
| 12179 | lpfc_debugfs_slow_ring_trc(phba, |
| 12180 | "ISR slow ring: pwork:" |
| 12181 | "x%x hawork:x%x wait:x%x", |
| 12182 | phba->work_ha, work_ha_copy, |
| 12183 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12184 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 12185 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12186 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12187 | } |
| 12188 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12189 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12190 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12191 | if (lpfc_sli_read_hs(phba)) |
| 12192 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12193 | /* |
| 12194 | * Check if there is a deferred error condition |
| 12195 | * is active |
| 12196 | */ |
| 12197 | if ((HS_FFER1 & phba->work_hs) && |
| 12198 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 12199 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 12200 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12201 | phba->hba_flag |= DEFER_ERATT; |
| 12202 | /* Clear all interrupt enable conditions */ |
| 12203 | writel(0, phba->HCregaddr); |
| 12204 | readl(phba->HCregaddr); |
| 12205 | } |
| 12206 | } |
| 12207 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12208 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12209 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12210 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12211 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12212 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12213 | |
| 12214 | /* First check out the status word */ |
| 12215 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 12216 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12217 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12218 | /* |
| 12219 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 12220 | * mbxStatus <status> |
| 12221 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12222 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12223 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12224 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12225 | "Interrupt mbxCommand x%x " |
| 12226 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12227 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12228 | pmbox->mbxCommand, |
| 12229 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12230 | /* clear mailbox attention bit */ |
| 12231 | work_ha_copy &= ~HA_MBATT; |
| 12232 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12233 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12234 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12235 | phba->last_completion_time = jiffies; |
| 12236 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12237 | if (pmb->mbox_cmpl) { |
| 12238 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 12239 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12240 | if (pmb->out_ext_byte_len && |
| 12241 | pmb->context2) |
| 12242 | lpfc_sli_pcimem_bcopy( |
| 12243 | phba->mbox_ext, |
| 12244 | pmb->context2, |
| 12245 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12246 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12247 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12248 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12249 | |
| 12250 | lpfc_debugfs_disc_trc(vport, |
| 12251 | LPFC_DISC_TRC_MBOX_VPORT, |
| 12252 | "MBOX dflt rpi: : " |
| 12253 | "status:x%x rpi:x%x", |
| 12254 | (uint32_t)pmbox->mbxStatus, |
| 12255 | pmbox->un.varWords[0], 0); |
| 12256 | |
| 12257 | if (!pmbox->mbxStatus) { |
| 12258 | mp = (struct lpfc_dmabuf *) |
| 12259 | (pmb->context1); |
| 12260 | ndlp = (struct lpfc_nodelist *) |
| 12261 | pmb->context2; |
| 12262 | |
| 12263 | /* Reg_LOGIN of dflt RPI was |
| 12264 | * successful. new lets get |
| 12265 | * rid of the RPI using the |
| 12266 | * same mbox buffer. |
| 12267 | */ |
| 12268 | lpfc_unreg_login(phba, |
| 12269 | vport->vpi, |
| 12270 | pmbox->un.varWords[0], |
| 12271 | pmb); |
| 12272 | pmb->mbox_cmpl = |
| 12273 | lpfc_mbx_cmpl_dflt_rpi; |
| 12274 | pmb->context1 = mp; |
| 12275 | pmb->context2 = ndlp; |
| 12276 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12277 | rc = lpfc_sli_issue_mbox(phba, |
| 12278 | pmb, |
| 12279 | MBX_NOWAIT); |
| 12280 | if (rc != MBX_BUSY) |
| 12281 | lpfc_printf_log(phba, |
| 12282 | KERN_ERR, |
| 12283 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12284 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12285 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12286 | if (rc != MBX_NOT_FINISHED) |
| 12287 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12288 | } |
| 12289 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12290 | spin_lock_irqsave( |
| 12291 | &phba->pport->work_port_lock, |
| 12292 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12293 | phba->pport->work_port_events &= |
| 12294 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12295 | spin_unlock_irqrestore( |
| 12296 | &phba->pport->work_port_lock, |
| 12297 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12298 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12299 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12300 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12301 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12302 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12303 | if ((work_ha_copy & HA_MBATT) && |
| 12304 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12305 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12306 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12307 | do { |
| 12308 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12309 | MBX_NOWAIT); |
| 12310 | } while (rc == MBX_NOT_FINISHED); |
| 12311 | if (rc != MBX_SUCCESS) |
| 12312 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12313 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12314 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12315 | } |
| 12316 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12317 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12318 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12319 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12320 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12321 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12322 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12323 | unplug_error: |
| 12324 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12325 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12326 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12327 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12328 | |
| 12329 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12330 | * 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] | 12331 | * @irq: Interrupt number. |
| 12332 | * @dev_id: The device context pointer. |
| 12333 | * |
| 12334 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12335 | * service routine when device with SLI-3 interface spec is enabled with |
| 12336 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12337 | * ring event in the HBA. However, when the device is enabled with either |
| 12338 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12339 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12340 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12341 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12342 | * the intrrupt context. This function is called without any lock held. |
| 12343 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12344 | * |
| 12345 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12346 | * returns IRQ_NONE. |
| 12347 | **/ |
| 12348 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12349 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12350 | { |
| 12351 | struct lpfc_hba *phba; |
| 12352 | uint32_t ha_copy; |
| 12353 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12354 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12355 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12356 | |
| 12357 | /* Get the driver's phba structure from the dev_id and |
| 12358 | * assume the HBA is not interrupting. |
| 12359 | */ |
| 12360 | phba = (struct lpfc_hba *) dev_id; |
| 12361 | |
| 12362 | if (unlikely(!phba)) |
| 12363 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12364 | |
| 12365 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12366 | * Stuff needs to be attented to when this function is invoked as an |
| 12367 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12368 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12369 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12370 | /* Check device state for handling interrupt */ |
| 12371 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12372 | return IRQ_NONE; |
| 12373 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12374 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12375 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12376 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12377 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12378 | /* |
| 12379 | * If there is deferred error attention, do not check for |
| 12380 | * any interrupt. |
| 12381 | */ |
| 12382 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12383 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12384 | return IRQ_NONE; |
| 12385 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12386 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12387 | phba->HAregaddr); |
| 12388 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12389 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12390 | } else |
| 12391 | ha_copy = phba->ha_copy; |
| 12392 | |
| 12393 | /* |
| 12394 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12395 | */ |
| 12396 | ha_copy &= ~(phba->work_ha_mask); |
| 12397 | |
| 12398 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12399 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12400 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12401 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12402 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12403 | |
| 12404 | if (phba->cfg_multi_ring_support == 2) { |
| 12405 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12406 | * Process all events on extra ring. Take the optimized path |
| 12407 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12408 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12409 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12410 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12411 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12412 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12413 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12414 | status); |
| 12415 | } |
| 12416 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12417 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12418 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12419 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12420 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12421 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12422 | * @irq: Interrupt number. |
| 12423 | * @dev_id: The device context pointer. |
| 12424 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12425 | * This function is the HBA device-level interrupt handler to device with |
| 12426 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12427 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12428 | * requires driver attention. This function invokes the slow-path interrupt |
| 12429 | * attention handling function and fast-path interrupt attention handling |
| 12430 | * function in turn to process the relevant HBA attention events. This |
| 12431 | * function is called without any lock held. It gets the hbalock to access |
| 12432 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12433 | * |
| 12434 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12435 | * returns IRQ_NONE. |
| 12436 | **/ |
| 12437 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12438 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12439 | { |
| 12440 | struct lpfc_hba *phba; |
| 12441 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12442 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12443 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12444 | |
| 12445 | /* |
| 12446 | * Get the driver's phba structure from the dev_id and |
| 12447 | * assume the HBA is not interrupting. |
| 12448 | */ |
| 12449 | phba = (struct lpfc_hba *) dev_id; |
| 12450 | |
| 12451 | if (unlikely(!phba)) |
| 12452 | return IRQ_NONE; |
| 12453 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12454 | /* Check device state for handling interrupt */ |
| 12455 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12456 | return IRQ_NONE; |
| 12457 | |
| 12458 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12459 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12460 | spin_unlock(&phba->hbalock); |
| 12461 | return IRQ_HANDLED; |
| 12462 | } |
| 12463 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12464 | if (unlikely(!phba->ha_copy)) { |
| 12465 | spin_unlock(&phba->hbalock); |
| 12466 | return IRQ_NONE; |
| 12467 | } else if (phba->ha_copy & HA_ERATT) { |
| 12468 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12469 | /* ERATT polling has handled ERATT */ |
| 12470 | phba->ha_copy &= ~HA_ERATT; |
| 12471 | else |
| 12472 | /* Indicate interrupt handler handles ERATT */ |
| 12473 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12474 | } |
| 12475 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12476 | /* |
| 12477 | * If there is deferred error attention, do not check for any interrupt. |
| 12478 | */ |
| 12479 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 12480 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12481 | return IRQ_NONE; |
| 12482 | } |
| 12483 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12484 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12485 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 12486 | spin_unlock(&phba->hbalock); |
| 12487 | return IRQ_HANDLED; |
| 12488 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12489 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 12490 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12491 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12492 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12493 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12494 | readl(phba->HAregaddr); /* flush */ |
| 12495 | spin_unlock(&phba->hbalock); |
| 12496 | |
| 12497 | /* |
| 12498 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12499 | */ |
| 12500 | |
| 12501 | /* status of events with mailbox and link attention */ |
| 12502 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 12503 | |
| 12504 | /* status of events with ELS ring */ |
| 12505 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12506 | status2 >>= (4*LPFC_ELS_RING); |
| 12507 | |
| 12508 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12509 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12510 | else |
| 12511 | sp_irq_rc = IRQ_NONE; |
| 12512 | |
| 12513 | /* |
| 12514 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12515 | */ |
| 12516 | |
| 12517 | /* status of events with FCP ring */ |
| 12518 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 12519 | status1 >>= (4*LPFC_FCP_RING); |
| 12520 | |
| 12521 | /* status of events with extra ring */ |
| 12522 | if (phba->cfg_multi_ring_support == 2) { |
| 12523 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 12524 | status2 >>= (4*LPFC_EXTRA_RING); |
| 12525 | } else |
| 12526 | status2 = 0; |
| 12527 | |
| 12528 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12529 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12530 | else |
| 12531 | fp_irq_rc = IRQ_NONE; |
| 12532 | |
| 12533 | /* Return device-level interrupt handling status */ |
| 12534 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12535 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12536 | |
| 12537 | /** |
| 12538 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 12539 | * @phba: pointer to lpfc hba data structure. |
| 12540 | * |
| 12541 | * This routine is invoked by the worker thread to process all the pending |
| 12542 | * SLI4 FCP abort XRI events. |
| 12543 | **/ |
| 12544 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12545 | { |
| 12546 | struct lpfc_cq_event *cq_event; |
| 12547 | |
| 12548 | /* First, declare the fcp xri abort event has been handled */ |
| 12549 | spin_lock_irq(&phba->hbalock); |
| 12550 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 12551 | spin_unlock_irq(&phba->hbalock); |
| 12552 | /* Now, handle all the fcp xri abort events */ |
| 12553 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 12554 | /* Get the first event from the head of the event queue */ |
| 12555 | spin_lock_irq(&phba->hbalock); |
| 12556 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 12557 | cq_event, struct lpfc_cq_event, list); |
| 12558 | spin_unlock_irq(&phba->hbalock); |
| 12559 | /* Notify aborted XRI for FCP work queue */ |
| 12560 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12561 | /* Free the event processed back to the free pool */ |
| 12562 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12563 | } |
| 12564 | } |
| 12565 | |
| 12566 | /** |
| 12567 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 12568 | * @phba: pointer to lpfc hba data structure. |
| 12569 | * |
| 12570 | * This routine is invoked by the worker thread to process all the pending |
| 12571 | * SLI4 els abort xri events. |
| 12572 | **/ |
| 12573 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12574 | { |
| 12575 | struct lpfc_cq_event *cq_event; |
| 12576 | |
| 12577 | /* First, declare the els xri abort event has been handled */ |
| 12578 | spin_lock_irq(&phba->hbalock); |
| 12579 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 12580 | spin_unlock_irq(&phba->hbalock); |
| 12581 | /* Now, handle all the els xri abort events */ |
| 12582 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 12583 | /* Get the first event from the head of the event queue */ |
| 12584 | spin_lock_irq(&phba->hbalock); |
| 12585 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 12586 | cq_event, struct lpfc_cq_event, list); |
| 12587 | spin_unlock_irq(&phba->hbalock); |
| 12588 | /* Notify aborted XRI for ELS work queue */ |
| 12589 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12590 | /* Free the event processed back to the free pool */ |
| 12591 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12592 | } |
| 12593 | } |
| 12594 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12595 | /** |
| 12596 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 12597 | * @phba: pointer to lpfc hba data structure |
| 12598 | * @pIocbIn: pointer to the rspiocbq |
| 12599 | * @pIocbOut: pointer to the cmdiocbq |
| 12600 | * @wcqe: pointer to the complete wcqe |
| 12601 | * |
| 12602 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 12603 | * by copying all the IOCB fields from command iocbq and transferring the |
| 12604 | * completion status information from the complete wcqe. |
| 12605 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12606 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12607 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 12608 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12609 | struct lpfc_iocbq *pIocbOut, |
| 12610 | struct lpfc_wcqe_complete *wcqe) |
| 12611 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12612 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12613 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12614 | uint32_t status, max_response; |
| 12615 | struct lpfc_dmabuf *dmabuf; |
| 12616 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12617 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 12618 | |
| 12619 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 12620 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12621 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12622 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 12623 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12624 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 12625 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 12626 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 12627 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 12628 | wcqe->total_data_placed; |
| 12629 | else |
| 12630 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12631 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12632 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12633 | switch (pIocbOut->iocb.ulpCommand) { |
| 12634 | case CMD_ELS_REQUEST64_CR: |
| 12635 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12636 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12637 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 12638 | max_response = bde.tus.f.bdeSize; |
| 12639 | break; |
| 12640 | case CMD_GEN_REQUEST64_CR: |
| 12641 | max_response = 0; |
| 12642 | if (!pIocbOut->context3) |
| 12643 | break; |
| 12644 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 12645 | sizeof(struct ulp_bde64); |
| 12646 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12647 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12648 | for (i = 0; i < numBdes; i++) { |
| 12649 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 12650 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 12651 | max_response += bde.tus.f.bdeSize; |
| 12652 | } |
| 12653 | break; |
| 12654 | default: |
| 12655 | max_response = wcqe->total_data_placed; |
| 12656 | break; |
| 12657 | } |
| 12658 | if (max_response < wcqe->total_data_placed) |
| 12659 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 12660 | else |
| 12661 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 12662 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12663 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12664 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12665 | /* Convert BG errors for completion status */ |
| 12666 | if (status == CQE_STATUS_DI_ERROR) { |
| 12667 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 12668 | |
| 12669 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 12670 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 12671 | else |
| 12672 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 12673 | |
| 12674 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 12675 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 12676 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12677 | BGS_GUARD_ERR_MASK; |
| 12678 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 12679 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12680 | BGS_APPTAG_ERR_MASK; |
| 12681 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 12682 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12683 | BGS_REFTAG_ERR_MASK; |
| 12684 | |
| 12685 | /* Check to see if there was any good data before the error */ |
| 12686 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 12687 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12688 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 12689 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 12690 | wcqe->total_data_placed; |
| 12691 | } |
| 12692 | |
| 12693 | /* |
| 12694 | * Set ALL the error bits to indicate we don't know what |
| 12695 | * type of error it is. |
| 12696 | */ |
| 12697 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 12698 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12699 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 12700 | BGS_GUARD_ERR_MASK); |
| 12701 | } |
| 12702 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12703 | /* Pick up HBA exchange busy condition */ |
| 12704 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 12705 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12706 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 12707 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12708 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12709 | } |
| 12710 | |
| 12711 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12712 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 12713 | * @phba: Pointer to HBA context object. |
| 12714 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12715 | * |
| 12716 | * This routine handles an ELS work-queue completion event and construct |
| 12717 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 12718 | * discovery engine to handle. |
| 12719 | * |
| 12720 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 12721 | **/ |
| 12722 | static struct lpfc_iocbq * |
| 12723 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 12724 | struct lpfc_iocbq *irspiocbq) |
| 12725 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12726 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12727 | struct lpfc_iocbq *cmdiocbq; |
| 12728 | struct lpfc_wcqe_complete *wcqe; |
| 12729 | unsigned long iflags; |
| 12730 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12731 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 12732 | if (unlikely(!pring)) |
| 12733 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12734 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12735 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12736 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12737 | pring->stats.iocb_event++; |
| 12738 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 12739 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 12740 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12741 | if (unlikely(!cmdiocbq)) { |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12742 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12743 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12744 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12745 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 12746 | wcqe->word0, wcqe->total_data_placed, |
| 12747 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12748 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 12749 | return NULL; |
| 12750 | } |
| 12751 | |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12752 | /* Put the iocb back on the txcmplq */ |
| 12753 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 12754 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 12755 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12756 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12757 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12758 | |
| 12759 | return irspiocbq; |
| 12760 | } |
| 12761 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 12762 | inline struct lpfc_cq_event * |
| 12763 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 12764 | { |
| 12765 | struct lpfc_cq_event *cq_event; |
| 12766 | |
| 12767 | /* Allocate a new internal CQ_EVENT entry */ |
| 12768 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 12769 | if (!cq_event) { |
| 12770 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12771 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 12772 | return NULL; |
| 12773 | } |
| 12774 | |
| 12775 | /* Move the CQE into the event */ |
| 12776 | memcpy(&cq_event->cqe, entry, size); |
| 12777 | return cq_event; |
| 12778 | } |
| 12779 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12780 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12781 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 12782 | * @phba: Pointer to HBA context object. |
| 12783 | * @cqe: Pointer to mailbox completion queue entry. |
| 12784 | * |
| 12785 | * This routine process a mailbox completion queue entry with asynchrous |
| 12786 | * event. |
| 12787 | * |
| 12788 | * Return: true if work posted to worker thread, otherwise false. |
| 12789 | **/ |
| 12790 | static bool |
| 12791 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 12792 | { |
| 12793 | struct lpfc_cq_event *cq_event; |
| 12794 | unsigned long iflags; |
| 12795 | |
| 12796 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 12797 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 12798 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 12799 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 12800 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 12801 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 12802 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12803 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12804 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12805 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 12806 | /* Set the async event flag */ |
| 12807 | phba->hba_flag |= ASYNC_EVENT; |
| 12808 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12809 | |
| 12810 | return true; |
| 12811 | } |
| 12812 | |
| 12813 | /** |
| 12814 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 12815 | * @phba: Pointer to HBA context object. |
| 12816 | * @cqe: Pointer to mailbox completion queue entry. |
| 12817 | * |
| 12818 | * This routine process a mailbox completion queue entry with mailbox |
| 12819 | * completion event. |
| 12820 | * |
| 12821 | * Return: true if work posted to worker thread, otherwise false. |
| 12822 | **/ |
| 12823 | static bool |
| 12824 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 12825 | { |
| 12826 | uint32_t mcqe_status; |
| 12827 | MAILBOX_t *mbox, *pmbox; |
| 12828 | struct lpfc_mqe *mqe; |
| 12829 | struct lpfc_vport *vport; |
| 12830 | struct lpfc_nodelist *ndlp; |
| 12831 | struct lpfc_dmabuf *mp; |
| 12832 | unsigned long iflags; |
| 12833 | LPFC_MBOXQ_t *pmb; |
| 12834 | bool workposted = false; |
| 12835 | int rc; |
| 12836 | |
| 12837 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 12838 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 12839 | goto out_no_mqe_complete; |
| 12840 | |
| 12841 | /* Get the reference to the active mbox command */ |
| 12842 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12843 | pmb = phba->sli.mbox_active; |
| 12844 | if (unlikely(!pmb)) { |
| 12845 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 12846 | "1832 No pending MBOX command to handle\n"); |
| 12847 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12848 | goto out_no_mqe_complete; |
| 12849 | } |
| 12850 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12851 | mqe = &pmb->u.mqe; |
| 12852 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 12853 | mbox = phba->mbox; |
| 12854 | vport = pmb->vport; |
| 12855 | |
| 12856 | /* Reset heartbeat timer */ |
| 12857 | phba->last_completion_time = jiffies; |
| 12858 | del_timer(&phba->sli.mbox_tmo); |
| 12859 | |
| 12860 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 12861 | if (pmb->mbox_cmpl && mbox) |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 12862 | lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12863 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12864 | /* |
| 12865 | * For mcqe errors, conditionally move a modified error code to |
| 12866 | * the mbox so that the error will not be missed. |
| 12867 | */ |
| 12868 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 12869 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 12870 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 12871 | bf_set(lpfc_mqe_status, mqe, |
| 12872 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 12873 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12874 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12875 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12876 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 12877 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 12878 | mcqe_status, |
| 12879 | pmbox->un.varWords[0], 0); |
| 12880 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 12881 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 12882 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 12883 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 12884 | * RID of the PPI using the same mbox buffer. |
| 12885 | */ |
| 12886 | lpfc_unreg_login(phba, vport->vpi, |
| 12887 | pmbox->un.varWords[0], pmb); |
| 12888 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 12889 | pmb->context1 = mp; |
| 12890 | pmb->context2 = ndlp; |
| 12891 | pmb->vport = vport; |
| 12892 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 12893 | if (rc != MBX_BUSY) |
| 12894 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12895 | LOG_SLI, "0385 rc should " |
| 12896 | "have been MBX_BUSY\n"); |
| 12897 | if (rc != MBX_NOT_FINISHED) |
| 12898 | goto send_current_mbox; |
| 12899 | } |
| 12900 | } |
| 12901 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 12902 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 12903 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 12904 | |
| 12905 | /* There is mailbox completion work to do */ |
| 12906 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12907 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 12908 | phba->work_ha |= HA_MBATT; |
| 12909 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12910 | workposted = true; |
| 12911 | |
| 12912 | send_current_mbox: |
| 12913 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12914 | /* Release the mailbox command posting token */ |
| 12915 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 12916 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 12917 | phba->sli.mbox_active = NULL; |
| 12918 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12919 | /* Wake up worker thread to post the next pending mailbox command */ |
| 12920 | lpfc_worker_wake_up(phba); |
| 12921 | out_no_mqe_complete: |
| 12922 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 12923 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 12924 | return workposted; |
| 12925 | } |
| 12926 | |
| 12927 | /** |
| 12928 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 12929 | * @phba: Pointer to HBA context object. |
| 12930 | * @cqe: Pointer to mailbox completion queue entry. |
| 12931 | * |
| 12932 | * This routine process a mailbox completion queue entry, it invokes the |
| 12933 | * proper mailbox complete handling or asynchrous event handling routine |
| 12934 | * according to the MCQE's async bit. |
| 12935 | * |
| 12936 | * Return: true if work posted to worker thread, otherwise false. |
| 12937 | **/ |
| 12938 | static bool |
| 12939 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 12940 | { |
| 12941 | struct lpfc_mcqe mcqe; |
| 12942 | bool workposted; |
| 12943 | |
| 12944 | /* Copy the mailbox MCQE and convert endian order as needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 12945 | lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12946 | |
| 12947 | /* Invoke the proper event handling routine */ |
| 12948 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 12949 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 12950 | else |
| 12951 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 12952 | return workposted; |
| 12953 | } |
| 12954 | |
| 12955 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12956 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 12957 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12958 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12959 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12960 | * |
| 12961 | * This routine handles an ELS work-queue completion event. |
| 12962 | * |
| 12963 | * Return: true if work posted to worker thread, otherwise false. |
| 12964 | **/ |
| 12965 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12966 | 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] | 12967 | struct lpfc_wcqe_complete *wcqe) |
| 12968 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12969 | struct lpfc_iocbq *irspiocbq; |
| 12970 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12971 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12972 | int txq_cnt = 0; |
| 12973 | int txcmplq_cnt = 0; |
| 12974 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12975 | |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 12976 | /* Check for response status */ |
| 12977 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 12978 | /* Log the error status */ |
| 12979 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 12980 | "0357 ELS CQE error: status=x%x: " |
| 12981 | "CQE: %08x %08x %08x %08x\n", |
| 12982 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 12983 | wcqe->word0, wcqe->total_data_placed, |
| 12984 | wcqe->parameter, wcqe->word3); |
| 12985 | } |
| 12986 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12987 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12988 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 12989 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12990 | if (!list_empty(&pring->txq)) |
| 12991 | txq_cnt++; |
| 12992 | if (!list_empty(&pring->txcmplq)) |
| 12993 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12994 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12995 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 12996 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12997 | txq_cnt, phba->iocb_cnt, |
| 12998 | fcp_txcmplq_cnt, |
| 12999 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13000 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13001 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13002 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13003 | /* Save off the slow-path queue event for work thread to process */ |
| 13004 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13005 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13006 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13007 | &phba->sli4_hba.sp_queue_event); |
| 13008 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13009 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13010 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13011 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13012 | } |
| 13013 | |
| 13014 | /** |
| 13015 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 13016 | * @phba: Pointer to HBA context object. |
| 13017 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13018 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13019 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13020 | * proper WQ release routine to the slow-path WQ. |
| 13021 | **/ |
| 13022 | static void |
| 13023 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 13024 | struct lpfc_wcqe_release *wcqe) |
| 13025 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13026 | /* sanity check on queue memory */ |
| 13027 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 13028 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13029 | /* Check for the slow-path ELS work queue */ |
| 13030 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 13031 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 13032 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13033 | else |
| 13034 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13035 | "2579 Slow-path wqe consume event carries " |
| 13036 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 13037 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 13038 | phba->sli4_hba.els_wq->queue_id); |
| 13039 | } |
| 13040 | |
| 13041 | /** |
| 13042 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 13043 | * @phba: Pointer to HBA context object. |
| 13044 | * @cq: Pointer to a WQ completion queue. |
| 13045 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13046 | * |
| 13047 | * This routine handles an XRI abort event. |
| 13048 | * |
| 13049 | * Return: true if work posted to worker thread, otherwise false. |
| 13050 | **/ |
| 13051 | static bool |
| 13052 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 13053 | struct lpfc_queue *cq, |
| 13054 | struct sli4_wcqe_xri_aborted *wcqe) |
| 13055 | { |
| 13056 | bool workposted = false; |
| 13057 | struct lpfc_cq_event *cq_event; |
| 13058 | unsigned long iflags; |
| 13059 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13060 | switch (cq->subtype) { |
| 13061 | case LPFC_FCP: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13062 | cq_event = lpfc_cq_event_setup( |
| 13063 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 13064 | if (!cq_event) |
| 13065 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13066 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13067 | list_add_tail(&cq_event->list, |
| 13068 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 13069 | /* Set the fcp xri abort event flag */ |
| 13070 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 13071 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13072 | workposted = true; |
| 13073 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 13074 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13075 | case LPFC_ELS: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13076 | cq_event = lpfc_cq_event_setup( |
| 13077 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 13078 | if (!cq_event) |
| 13079 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13080 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13081 | list_add_tail(&cq_event->list, |
| 13082 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 13083 | /* Set the els xri abort event flag */ |
| 13084 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 13085 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13086 | workposted = true; |
| 13087 | break; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13088 | case LPFC_NVME: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 13089 | /* Notify aborted XRI for NVME work queue */ |
| 13090 | if (phba->nvmet_support) |
| 13091 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 13092 | else |
| 13093 | lpfc_sli4_nvme_xri_aborted(phba, wcqe); |
| 13094 | |
| 13095 | workposted = false; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13096 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13097 | default: |
| 13098 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 13099 | "0603 Invalid CQ subtype %d: " |
| 13100 | "%08x %08x %08x %08x\n", |
| 13101 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 13102 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13103 | workposted = false; |
| 13104 | break; |
| 13105 | } |
| 13106 | return workposted; |
| 13107 | } |
| 13108 | |
| 13109 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13110 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13111 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13112 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13113 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13114 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13115 | * |
| 13116 | * Return: true if work posted to worker thread, otherwise false. |
| 13117 | **/ |
| 13118 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13119 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 13120 | { |
| 13121 | bool workposted = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13122 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13123 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 13124 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13125 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13126 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13127 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13128 | unsigned long iflags; |
| 13129 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13130 | /* sanity check on queue memory */ |
| 13131 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13132 | return workposted; |
| 13133 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13134 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13135 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13136 | else |
| 13137 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13138 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13139 | goto out; |
| 13140 | |
| 13141 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13142 | switch (status) { |
| 13143 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13144 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13145 | "2537 Receive Frame Truncated!!\n"); |
| 13146 | case FC_STATUS_RQ_SUCCESS: |
| 13147 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13148 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13149 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 13150 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13151 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13152 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13153 | goto out; |
| 13154 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13155 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13156 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13157 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13158 | |
| 13159 | /* If a NVME LS event (type 0x28), treat it as Fast path */ |
| 13160 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13161 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13162 | /* save off the frame for the word thread to process */ |
| 13163 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13164 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13165 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13166 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13167 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13168 | workposted = true; |
| 13169 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13170 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13171 | if (phba->nvmet_support) { |
| 13172 | tgtp = phba->targetport->private; |
| 13173 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13174 | "6402 RQE Error x%x, posted %d err_cnt " |
| 13175 | "%d: %x %x %x\n", |
| 13176 | status, hrq->RQ_buf_posted, |
| 13177 | hrq->RQ_no_posted_buf, |
| 13178 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13179 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13180 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13181 | } |
| 13182 | /* fallthrough */ |
| 13183 | |
| 13184 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13185 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13186 | /* Post more buffers if possible */ |
| 13187 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13188 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 13189 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13190 | workposted = true; |
| 13191 | break; |
| 13192 | } |
| 13193 | out: |
| 13194 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13195 | } |
| 13196 | |
| 13197 | /** |
| 13198 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 13199 | * @phba: Pointer to HBA context object. |
| 13200 | * @cq: Pointer to the completion queue. |
| 13201 | * @wcqe: Pointer to a completion queue entry. |
| 13202 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13203 | * 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] | 13204 | * entry. |
| 13205 | * |
| 13206 | * Return: true if work posted to worker thread, otherwise false. |
| 13207 | **/ |
| 13208 | static bool |
| 13209 | 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] | 13210 | struct lpfc_cqe *cqe) |
| 13211 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13212 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13213 | bool workposted = false; |
| 13214 | |
| 13215 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13216 | lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13217 | |
| 13218 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13219 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13220 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13221 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13222 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13223 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13224 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13225 | break; |
| 13226 | case CQE_CODE_RELEASE_WQE: |
| 13227 | /* Process the WQ release event */ |
| 13228 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13229 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13230 | break; |
| 13231 | case CQE_CODE_XRI_ABORTED: |
| 13232 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13233 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13234 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13235 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13236 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13237 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13238 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13239 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13240 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13241 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13242 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13243 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13244 | default: |
| 13245 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13246 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13247 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13248 | break; |
| 13249 | } |
| 13250 | return workposted; |
| 13251 | } |
| 13252 | |
| 13253 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13254 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13255 | * @phba: Pointer to HBA context object. |
| 13256 | * @eqe: Pointer to fast-path event queue entry. |
| 13257 | * |
| 13258 | * This routine process a event queue entry from the slow-path event queue. |
| 13259 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13260 | * completion event on a completion queue, if not, an error shall be logged |
| 13261 | * and just return. Otherwise, it will get to the corresponding completion |
| 13262 | * queue and process all the entries on that completion queue, rearm the |
| 13263 | * completion queue, and then return. |
| 13264 | * |
| 13265 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13266 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13267 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13268 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13269 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13270 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13271 | uint16_t cqid; |
| 13272 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13273 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13274 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13275 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13276 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13277 | if (childq->queue_id == cqid) { |
| 13278 | cq = childq; |
| 13279 | break; |
| 13280 | } |
| 13281 | } |
| 13282 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13283 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13284 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13285 | "0365 Slow-path CQ identifier " |
| 13286 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13287 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13288 | } |
| 13289 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13290 | /* Save EQ associated with this CQ */ |
| 13291 | cq->assoc_qp = speq; |
| 13292 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13293 | if (!queue_work(phba->wq, &cq->spwork)) |
| 13294 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13295 | "0390 Cannot schedule soft IRQ " |
| 13296 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13297 | cqid, cq->queue_id, smp_processor_id()); |
| 13298 | } |
| 13299 | |
| 13300 | /** |
| 13301 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
| 13302 | * @phba: Pointer to HBA context object. |
| 13303 | * |
| 13304 | * This routine process a event queue entry from the slow-path event queue. |
| 13305 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13306 | * completion event on a completion queue, if not, an error shall be logged |
| 13307 | * and just return. Otherwise, it will get to the corresponding completion |
| 13308 | * queue and process all the entries on that completion queue, rearm the |
| 13309 | * completion queue, and then return. |
| 13310 | * |
| 13311 | **/ |
| 13312 | static void |
| 13313 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 13314 | { |
| 13315 | struct lpfc_queue *cq = |
| 13316 | container_of(work, struct lpfc_queue, spwork); |
| 13317 | struct lpfc_hba *phba = cq->phba; |
| 13318 | struct lpfc_cqe *cqe; |
| 13319 | bool workposted = false; |
| 13320 | int ccount = 0; |
| 13321 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13322 | /* Process all the entries to the CQ */ |
| 13323 | switch (cq->type) { |
| 13324 | case LPFC_MCQ: |
| 13325 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 13326 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13327 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13328 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13329 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13330 | } |
| 13331 | break; |
| 13332 | case LPFC_WCQ: |
| 13333 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13334 | if (cq->subtype == LPFC_FCP || |
| 13335 | cq->subtype == LPFC_NVME) { |
| 13336 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13337 | if (phba->ktime_on) |
| 13338 | cq->isr_timestamp = ktime_get_ns(); |
| 13339 | else |
| 13340 | cq->isr_timestamp = 0; |
| 13341 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13342 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13343 | cqe); |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13344 | } else { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13345 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 13346 | cqe); |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13347 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13348 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13349 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13350 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13351 | |
| 13352 | /* Track the max number of CQEs processed in 1 EQ */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13353 | if (ccount > cq->CQ_max_cqe) |
| 13354 | cq->CQ_max_cqe = ccount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13355 | break; |
| 13356 | default: |
| 13357 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13358 | "0370 Invalid completion queue type (%d)\n", |
| 13359 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13360 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13361 | } |
| 13362 | |
| 13363 | /* Catch the no cq entry condition, log an error */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13364 | if (unlikely(ccount == 0)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13365 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13366 | "0371 No entry from the CQ: identifier " |
| 13367 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 13368 | |
| 13369 | /* In any case, flash and re-arm the RCQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 13370 | phba->sli4_hba.sli4_cq_release(cq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13371 | |
| 13372 | /* wake up worker thread if there are works to be done */ |
| 13373 | if (workposted) |
| 13374 | lpfc_worker_wake_up(phba); |
| 13375 | } |
| 13376 | |
| 13377 | /** |
| 13378 | * 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] | 13379 | * @phba: Pointer to HBA context object. |
| 13380 | * @cq: Pointer to associated CQ |
| 13381 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13382 | * |
| 13383 | * This routine process a fast-path work queue completion entry from fast-path |
| 13384 | * event queue for FCP command response completion. |
| 13385 | **/ |
| 13386 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13387 | 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] | 13388 | struct lpfc_wcqe_complete *wcqe) |
| 13389 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13390 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13391 | struct lpfc_iocbq *cmdiocbq; |
| 13392 | struct lpfc_iocbq irspiocbq; |
| 13393 | unsigned long iflags; |
| 13394 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13395 | /* Check for response status */ |
| 13396 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13397 | /* If resource errors reported from HBA, reduce queue |
| 13398 | * depth of the SCSI device. |
| 13399 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13400 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 13401 | IOSTAT_LOCAL_REJECT)) && |
| 13402 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 13403 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13404 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13405 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13406 | /* Log the error status */ |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13407 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 13408 | "0373 FCP CQE error: status=x%x: " |
| 13409 | "CQE: %08x %08x %08x %08x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13410 | bf_get(lpfc_wcqe_c_status, wcqe), |
James Smart | 11f0e34 | 2018-05-04 20:37:57 -0700 | [diff] [blame] | 13411 | wcqe->word0, wcqe->total_data_placed, |
| 13412 | wcqe->parameter, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13413 | } |
| 13414 | |
| 13415 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13416 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 13417 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13418 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13419 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13420 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13421 | if (unlikely(!cmdiocbq)) { |
| 13422 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13423 | "0374 FCP complete with no corresponding " |
| 13424 | "cmdiocb: iotag (%d)\n", |
| 13425 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13426 | return; |
| 13427 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13428 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13429 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 13430 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13431 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 13432 | if (cmdiocbq->wqe_cmpl) { |
| 13433 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13434 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13435 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13436 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13437 | } |
| 13438 | |
| 13439 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 13440 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 13441 | return; |
| 13442 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13443 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13444 | "0375 FCP cmdiocb not callback function " |
| 13445 | "iotag: (%d)\n", |
| 13446 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13447 | return; |
| 13448 | } |
| 13449 | |
| 13450 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13451 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13452 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 13453 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13454 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13455 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13456 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13457 | } |
| 13458 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13459 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 13460 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 13461 | } |
| 13462 | |
| 13463 | /** |
| 13464 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 13465 | * @phba: Pointer to HBA context object. |
| 13466 | * @cq: Pointer to completion queue. |
| 13467 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13468 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13469 | * 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] | 13470 | * proper WQ release routine to the slow-path WQ. |
| 13471 | **/ |
| 13472 | static void |
| 13473 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13474 | struct lpfc_wcqe_release *wcqe) |
| 13475 | { |
| 13476 | struct lpfc_queue *childwq; |
| 13477 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13478 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13479 | |
| 13480 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13481 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13482 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13483 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13484 | lpfc_sli4_wq_release(childwq, |
| 13485 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 13486 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 13487 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13488 | wqid_matched = true; |
| 13489 | break; |
| 13490 | } |
| 13491 | } |
| 13492 | /* Report warning log message if no match found */ |
| 13493 | if (wqid_matched != true) |
| 13494 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13495 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13496 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13497 | } |
| 13498 | |
| 13499 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13500 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 13501 | * @phba: Pointer to HBA context object. |
| 13502 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 13503 | * |
| 13504 | * This routine process a receive-queue completion queue entry. |
| 13505 | * |
| 13506 | * Return: true if work posted to worker thread, otherwise false. |
| 13507 | **/ |
| 13508 | static bool |
| 13509 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13510 | struct lpfc_rcqe *rcqe) |
| 13511 | { |
| 13512 | bool workposted = false; |
| 13513 | struct lpfc_queue *hrq; |
| 13514 | struct lpfc_queue *drq; |
| 13515 | struct rqb_dmabuf *dma_buf; |
| 13516 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13517 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13518 | uint32_t status, rq_id; |
| 13519 | unsigned long iflags; |
| 13520 | uint32_t fctl, idx; |
| 13521 | |
| 13522 | if ((phba->nvmet_support == 0) || |
| 13523 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 13524 | return workposted; |
| 13525 | |
| 13526 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13527 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 13528 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 13529 | |
| 13530 | /* sanity check on queue memory */ |
| 13531 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13532 | return workposted; |
| 13533 | |
| 13534 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13535 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13536 | else |
| 13537 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13538 | |
| 13539 | if ((phba->nvmet_support == 0) || |
| 13540 | (rq_id != hrq->queue_id)) |
| 13541 | return workposted; |
| 13542 | |
| 13543 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13544 | switch (status) { |
| 13545 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13546 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13547 | "6126 Receive Frame Truncated!!\n"); |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 13548 | /* Drop thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13549 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13550 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13551 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13552 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 13553 | if (!dma_buf) { |
| 13554 | hrq->RQ_no_buf_found++; |
| 13555 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13556 | goto out; |
| 13557 | } |
| 13558 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13559 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13560 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13561 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13562 | |
| 13563 | /* Just some basic sanity checks on FCP Command frame */ |
| 13564 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 13565 | fc_hdr->fh_f_ctl[1] << 8 | |
| 13566 | fc_hdr->fh_f_ctl[2]); |
| 13567 | if (((fctl & |
| 13568 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 13569 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 13570 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 13571 | goto drop; |
| 13572 | |
| 13573 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
| 13574 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 13575 | lpfc_nvmet_unsol_fcp_event( |
Dick Kennedy | 66d7ce9 | 2017-08-23 16:55:42 -0700 | [diff] [blame] | 13576 | phba, idx, dma_buf, |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13577 | cq->isr_timestamp); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13578 | return false; |
| 13579 | } |
| 13580 | drop: |
| 13581 | lpfc_in_buf_free(phba, &dma_buf->dbuf); |
| 13582 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13583 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13584 | if (phba->nvmet_support) { |
| 13585 | tgtp = phba->targetport->private; |
| 13586 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13587 | "6401 RQE Error x%x, posted %d err_cnt " |
| 13588 | "%d: %x %x %x\n", |
| 13589 | status, hrq->RQ_buf_posted, |
| 13590 | hrq->RQ_no_posted_buf, |
| 13591 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13592 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13593 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13594 | } |
| 13595 | /* fallthrough */ |
| 13596 | |
| 13597 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13598 | hrq->RQ_no_posted_buf++; |
| 13599 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13600 | break; |
| 13601 | } |
| 13602 | out: |
| 13603 | return workposted; |
| 13604 | } |
| 13605 | |
| 13606 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13607 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13608 | * @cq: Pointer to the completion queue. |
| 13609 | * @eqe: Pointer to fast-path completion queue entry. |
| 13610 | * |
| 13611 | * This routine process a fast-path work queue completion entry from fast-path |
| 13612 | * event queue for FCP command response completion. |
| 13613 | **/ |
| 13614 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13615 | 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] | 13616 | struct lpfc_cqe *cqe) |
| 13617 | { |
| 13618 | struct lpfc_wcqe_release wcqe; |
| 13619 | bool workposted = false; |
| 13620 | |
| 13621 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 48f8fdb | 2018-05-04 20:37:51 -0700 | [diff] [blame] | 13622 | lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13623 | |
| 13624 | /* Check and process for different type of WCQE and dispatch */ |
| 13625 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 13626 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13627 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13628 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13629 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 13630 | phba->last_completion_time = jiffies; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13631 | if ((cq->subtype == LPFC_FCP) || (cq->subtype == LPFC_NVME)) |
| 13632 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
| 13633 | (struct lpfc_wcqe_complete *)&wcqe); |
| 13634 | if (cq->subtype == LPFC_NVME_LS) |
| 13635 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13636 | (struct lpfc_wcqe_complete *)&wcqe); |
| 13637 | break; |
| 13638 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13639 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13640 | /* Process the WQ release event */ |
| 13641 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 13642 | (struct lpfc_wcqe_release *)&wcqe); |
| 13643 | break; |
| 13644 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13645 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13646 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13647 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13648 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 13649 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 13650 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13651 | case CQE_CODE_RECEIVE_V1: |
| 13652 | case CQE_CODE_RECEIVE: |
| 13653 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13654 | if (cq->subtype == LPFC_NVMET) { |
| 13655 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 13656 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 13657 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13658 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13659 | default: |
| 13660 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13661 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13662 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 13663 | break; |
| 13664 | } |
| 13665 | return workposted; |
| 13666 | } |
| 13667 | |
| 13668 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13669 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13670 | * @phba: Pointer to HBA context object. |
| 13671 | * @eqe: Pointer to fast-path event queue entry. |
| 13672 | * |
| 13673 | * This routine process a event queue entry from the fast-path event queue. |
| 13674 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13675 | * completion event on a completion queue, if not, an error shall be logged |
| 13676 | * and just return. Otherwise, it will get to the corresponding completion |
| 13677 | * queue and process all the entries on the completion queue, rearm the |
| 13678 | * completion queue, and then return. |
| 13679 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13680 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13681 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13682 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13683 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13684 | struct lpfc_queue *cq = NULL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13685 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13686 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13687 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13688 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13689 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13690 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13691 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 13692 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13693 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13694 | } |
| 13695 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13696 | /* Get the reference to the corresponding CQ */ |
| 13697 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 13698 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13699 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 13700 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13701 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 13702 | /* Process NVMET unsol rcv */ |
| 13703 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 13704 | goto process_cq; |
| 13705 | } |
| 13706 | } |
| 13707 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13708 | if (phba->sli4_hba.nvme_cq_map && |
| 13709 | (cqid == phba->sli4_hba.nvme_cq_map[qidx])) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 13710 | /* Process NVME / NVMET command completion */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13711 | cq = phba->sli4_hba.nvme_cq[qidx]; |
| 13712 | goto process_cq; |
| 13713 | } |
| 13714 | |
| 13715 | if (phba->sli4_hba.fcp_cq_map && |
| 13716 | (cqid == phba->sli4_hba.fcp_cq_map[qidx])) { |
| 13717 | /* Process FCP command completion */ |
| 13718 | cq = phba->sli4_hba.fcp_cq[qidx]; |
| 13719 | goto process_cq; |
| 13720 | } |
| 13721 | |
| 13722 | if (phba->sli4_hba.nvmels_cq && |
| 13723 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 13724 | /* Process NVME unsol rcv */ |
| 13725 | cq = phba->sli4_hba.nvmels_cq; |
| 13726 | } |
| 13727 | |
| 13728 | /* Otherwise this is a Slow path event */ |
| 13729 | if (cq == NULL) { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13730 | lpfc_sli4_sp_handle_eqe(phba, eqe, phba->sli4_hba.hba_eq[qidx]); |
| 13731 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13732 | } |
| 13733 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13734 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13735 | if (unlikely(cqid != cq->queue_id)) { |
| 13736 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13737 | "0368 Miss-matched fast-path completion " |
| 13738 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 13739 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13740 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13741 | } |
| 13742 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13743 | /* Save EQ associated with this CQ */ |
| 13744 | cq->assoc_qp = phba->sli4_hba.hba_eq[qidx]; |
| 13745 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13746 | if (!queue_work(phba->wq, &cq->irqwork)) |
| 13747 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13748 | "0363 Cannot schedule soft IRQ " |
| 13749 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13750 | cqid, cq->queue_id, smp_processor_id()); |
| 13751 | } |
| 13752 | |
| 13753 | /** |
| 13754 | * lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 13755 | * @phba: Pointer to HBA context object. |
| 13756 | * @eqe: Pointer to fast-path event queue entry. |
| 13757 | * |
| 13758 | * This routine process a event queue entry from the fast-path event queue. |
| 13759 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13760 | * completion event on a completion queue, if not, an error shall be logged |
| 13761 | * and just return. Otherwise, it will get to the corresponding completion |
| 13762 | * queue and process all the entries on the completion queue, rearm the |
| 13763 | * completion queue, and then return. |
| 13764 | **/ |
| 13765 | static void |
| 13766 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
| 13767 | { |
| 13768 | struct lpfc_queue *cq = |
| 13769 | container_of(work, struct lpfc_queue, irqwork); |
| 13770 | struct lpfc_hba *phba = cq->phba; |
| 13771 | struct lpfc_cqe *cqe; |
| 13772 | bool workposted = false; |
| 13773 | int ccount = 0; |
| 13774 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13775 | /* Process all the entries to the CQ */ |
| 13776 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13777 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13778 | if (phba->ktime_on) |
| 13779 | cq->isr_timestamp = ktime_get_ns(); |
| 13780 | else |
| 13781 | cq->isr_timestamp = 0; |
| 13782 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13783 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, cqe); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13784 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13785 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13786 | } |
| 13787 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13788 | /* Track the max number of CQEs processed in 1 EQ */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13789 | if (ccount > cq->CQ_max_cqe) |
| 13790 | cq->CQ_max_cqe = ccount; |
| 13791 | cq->assoc_qp->EQ_cqe_cnt += ccount; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13792 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13793 | /* Catch the no cq entry condition */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13794 | if (unlikely(ccount == 0)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13795 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13796 | "0369 No entry from fast-path completion " |
| 13797 | "queue fcpcqid=%d\n", cq->queue_id); |
| 13798 | |
| 13799 | /* In any case, flash and re-arm the CQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 13800 | phba->sli4_hba.sli4_cq_release(cq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13801 | |
| 13802 | /* wake up worker thread if there are works to be done */ |
| 13803 | if (workposted) |
| 13804 | lpfc_worker_wake_up(phba); |
| 13805 | } |
| 13806 | |
| 13807 | static void |
| 13808 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 13809 | { |
| 13810 | struct lpfc_eqe *eqe; |
| 13811 | |
| 13812 | /* walk all the EQ entries and drop on the floor */ |
| 13813 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 13814 | ; |
| 13815 | |
| 13816 | /* Clear and re-arm the EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 13817 | phba->sli4_hba.sli4_eq_release(eq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13818 | } |
| 13819 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13820 | |
| 13821 | /** |
| 13822 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue |
| 13823 | * entry |
| 13824 | * @phba: Pointer to HBA context object. |
| 13825 | * @eqe: Pointer to fast-path event queue entry. |
| 13826 | * |
| 13827 | * This routine process a event queue entry from the Flash Optimized Fabric |
| 13828 | * event queue. It will check the MajorCode and MinorCode to determine this |
| 13829 | * is for a completion event on a completion queue, if not, an error shall be |
| 13830 | * logged and just return. Otherwise, it will get to the corresponding |
| 13831 | * completion queue and process all the entries on the completion queue, rearm |
| 13832 | * the completion queue, and then return. |
| 13833 | **/ |
| 13834 | static void |
| 13835 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 13836 | { |
| 13837 | struct lpfc_queue *cq; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13838 | uint16_t cqid; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13839 | |
| 13840 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
| 13841 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13842 | "9147 Not a valid completion " |
| 13843 | "event: majorcode=x%x, minorcode=x%x\n", |
| 13844 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 13845 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
| 13846 | return; |
| 13847 | } |
| 13848 | |
| 13849 | /* Get the reference to the corresponding CQ */ |
| 13850 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 13851 | |
| 13852 | /* Next check for OAS */ |
| 13853 | cq = phba->sli4_hba.oas_cq; |
| 13854 | if (unlikely(!cq)) { |
| 13855 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13856 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13857 | "9148 OAS completion queue " |
| 13858 | "does not exist\n"); |
| 13859 | return; |
| 13860 | } |
| 13861 | |
| 13862 | if (unlikely(cqid != cq->queue_id)) { |
| 13863 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13864 | "9149 Miss-matched fast-path compl " |
| 13865 | "queue id: eqcqid=%d, fcpcqid=%d\n", |
| 13866 | cqid, cq->queue_id); |
| 13867 | return; |
| 13868 | } |
| 13869 | |
James Smart | d41b65b | 2017-06-15 22:56:41 -0700 | [diff] [blame] | 13870 | /* Save EQ associated with this CQ */ |
| 13871 | cq->assoc_qp = phba->sli4_hba.fof_eq; |
| 13872 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13873 | /* CQ work will be processed on CPU affinitized to this IRQ */ |
| 13874 | if (!queue_work(phba->wq, &cq->irqwork)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13875 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13876 | "0367 Cannot schedule soft IRQ " |
| 13877 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13878 | cqid, cq->queue_id, smp_processor_id()); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13879 | } |
| 13880 | |
| 13881 | /** |
| 13882 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device |
| 13883 | * @irq: Interrupt number. |
| 13884 | * @dev_id: The device context pointer. |
| 13885 | * |
| 13886 | * This function is directly called from the PCI layer as an interrupt |
| 13887 | * service routine when device with SLI-4 interface spec is enabled with |
| 13888 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric |
| 13889 | * IOCB ring event in the HBA. However, when the device is enabled with either |
| 13890 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 13891 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 13892 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 13893 | * process the interrupt. The Flash Optimized Fabric ring event are handled in |
| 13894 | * the intrrupt context. This function is called without any lock held. |
| 13895 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 13896 | * the EQ to CQ are one-to-one map such that the EQ index is |
| 13897 | * equal to that of CQ index. |
| 13898 | * |
| 13899 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 13900 | * returns IRQ_NONE. |
| 13901 | **/ |
| 13902 | irqreturn_t |
| 13903 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) |
| 13904 | { |
| 13905 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13906 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13907 | struct lpfc_queue *eq; |
| 13908 | struct lpfc_eqe *eqe; |
| 13909 | unsigned long iflag; |
| 13910 | int ecount = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13911 | |
| 13912 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13913 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 13914 | phba = hba_eq_hdl->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13915 | |
| 13916 | if (unlikely(!phba)) |
| 13917 | return IRQ_NONE; |
| 13918 | |
| 13919 | /* Get to the EQ struct associated with this vector */ |
| 13920 | eq = phba->sli4_hba.fof_eq; |
| 13921 | if (unlikely(!eq)) |
| 13922 | return IRQ_NONE; |
| 13923 | |
| 13924 | /* Check device state for handling interrupt */ |
| 13925 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13926 | /* Check again for link_state with lock held */ |
| 13927 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 13928 | if (phba->link_state < LPFC_LINK_DOWN) |
| 13929 | /* Flush, clear interrupt, and rearm the EQ */ |
| 13930 | lpfc_sli4_eq_flush(phba, eq); |
| 13931 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 13932 | return IRQ_NONE; |
| 13933 | } |
| 13934 | |
| 13935 | /* |
| 13936 | * Process all the event on FCP fast-path EQ |
| 13937 | */ |
| 13938 | while ((eqe = lpfc_sli4_eq_get(eq))) { |
| 13939 | lpfc_sli4_fof_handle_eqe(phba, eqe); |
| 13940 | if (!(++ecount % eq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13941 | break; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13942 | eq->EQ_processed++; |
| 13943 | } |
| 13944 | |
| 13945 | /* Track the max number of EQEs processed in 1 intr */ |
| 13946 | if (ecount > eq->EQ_max_eqe) |
| 13947 | eq->EQ_max_eqe = ecount; |
| 13948 | |
| 13949 | |
| 13950 | if (unlikely(ecount == 0)) { |
| 13951 | eq->EQ_no_entry++; |
| 13952 | |
| 13953 | if (phba->intr_type == MSIX) |
| 13954 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 13955 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13956 | "9145 MSI-X interrupt with no EQE\n"); |
| 13957 | else { |
| 13958 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13959 | "9146 ISR interrupt with no EQE\n"); |
| 13960 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 13961 | return IRQ_NONE; |
| 13962 | } |
| 13963 | } |
| 13964 | /* Always clear and re-arm the fast-path EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 13965 | phba->sli4_hba.sli4_eq_release(eq, LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13966 | return IRQ_HANDLED; |
| 13967 | } |
| 13968 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13969 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13970 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13971 | * @irq: Interrupt number. |
| 13972 | * @dev_id: The device context pointer. |
| 13973 | * |
| 13974 | * This function is directly called from the PCI layer as an interrupt |
| 13975 | * service routine when device with SLI-4 interface spec is enabled with |
| 13976 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 13977 | * ring event in the HBA. However, when the device is enabled with either |
| 13978 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 13979 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 13980 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 13981 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 13982 | * the intrrupt context. This function is called without any lock held. |
| 13983 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 13984 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 13985 | * equal to that of FCP CQ index. |
| 13986 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13987 | * The link attention and ELS ring attention events are handled |
| 13988 | * by the worker thread. The interrupt handler signals the worker thread |
| 13989 | * and returns for these events. This function is called without any lock |
| 13990 | * held. It gets the hbalock to access and update SLI data structures. |
| 13991 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13992 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 13993 | * returns IRQ_NONE. |
| 13994 | **/ |
| 13995 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13996 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13997 | { |
| 13998 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13999 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14000 | struct lpfc_queue *fpeq; |
| 14001 | struct lpfc_eqe *eqe; |
| 14002 | unsigned long iflag; |
| 14003 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14004 | int hba_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14005 | |
| 14006 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14007 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 14008 | phba = hba_eq_hdl->phba; |
| 14009 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14010 | |
| 14011 | if (unlikely(!phba)) |
| 14012 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14013 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 14014 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14015 | |
| 14016 | /* Get to the EQ struct associated with this vector */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14017 | fpeq = phba->sli4_hba.hba_eq[hba_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14018 | if (unlikely(!fpeq)) |
| 14019 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14020 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14021 | if (lpfc_fcp_look_ahead) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14022 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 14023 | phba->sli4_hba.sli4_eq_clr_intr(fpeq); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14024 | else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14025 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14026 | return IRQ_NONE; |
| 14027 | } |
| 14028 | } |
| 14029 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14030 | /* Check device state for handling interrupt */ |
| 14031 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 14032 | /* Check again for link_state with lock held */ |
| 14033 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 14034 | if (phba->link_state < LPFC_LINK_DOWN) |
| 14035 | /* Flush, clear interrupt, and rearm the EQ */ |
| 14036 | lpfc_sli4_eq_flush(phba, fpeq); |
| 14037 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14038 | if (lpfc_fcp_look_ahead) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14039 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14040 | return IRQ_NONE; |
| 14041 | } |
| 14042 | |
| 14043 | /* |
| 14044 | * Process all the event on FCP fast-path EQ |
| 14045 | */ |
| 14046 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14047 | lpfc_sli4_hba_handle_eqe(phba, eqe, hba_eqidx); |
| 14048 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 14049 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14050 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14051 | } |
| 14052 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14053 | /* Track the max number of EQEs processed in 1 intr */ |
| 14054 | if (ecount > fpeq->EQ_max_eqe) |
| 14055 | fpeq->EQ_max_eqe = ecount; |
| 14056 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14057 | /* Always clear and re-arm the fast-path EQ */ |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 14058 | phba->sli4_hba.sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14059 | |
| 14060 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 14061 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14062 | |
| 14063 | if (lpfc_fcp_look_ahead) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14064 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14065 | return IRQ_NONE; |
| 14066 | } |
| 14067 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14068 | if (phba->intr_type == MSIX) |
| 14069 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 14070 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 14071 | "0358 MSI-X interrupt with no EQE\n"); |
| 14072 | else |
| 14073 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 14074 | return IRQ_NONE; |
| 14075 | } |
| 14076 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 14077 | if (lpfc_fcp_look_ahead) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14078 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
| 14079 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14080 | return IRQ_HANDLED; |
| 14081 | } /* lpfc_sli4_fp_intr_handler */ |
| 14082 | |
| 14083 | /** |
| 14084 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 14085 | * @irq: Interrupt number. |
| 14086 | * @dev_id: The device context pointer. |
| 14087 | * |
| 14088 | * This function is the device-level interrupt handler to device with SLI-4 |
| 14089 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 14090 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 14091 | * driver attention. This function invokes the slow-path interrupt attention |
| 14092 | * handling function and fast-path interrupt attention handling function in |
| 14093 | * turn to process the relevant HBA attention events. This function is called |
| 14094 | * without any lock held. It gets the hbalock to access and update SLI data |
| 14095 | * structures. |
| 14096 | * |
| 14097 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 14098 | * returns IRQ_NONE. |
| 14099 | **/ |
| 14100 | irqreturn_t |
| 14101 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 14102 | { |
| 14103 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14104 | irqreturn_t hba_irq_rc; |
| 14105 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14106 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14107 | |
| 14108 | /* Get the driver's phba structure from the dev_id */ |
| 14109 | phba = (struct lpfc_hba *)dev_id; |
| 14110 | |
| 14111 | if (unlikely(!phba)) |
| 14112 | return IRQ_NONE; |
| 14113 | |
| 14114 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14115 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 14116 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14117 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14118 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14119 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14120 | if (hba_irq_rc == IRQ_HANDLED) |
| 14121 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14122 | } |
| 14123 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14124 | if (phba->cfg_fof) { |
| 14125 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14126 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14127 | if (hba_irq_rc == IRQ_HANDLED) |
| 14128 | hba_handled |= true; |
| 14129 | } |
| 14130 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14131 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14132 | } /* lpfc_sli4_intr_handler */ |
| 14133 | |
| 14134 | /** |
| 14135 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 14136 | * @queue: The queue structure to free. |
| 14137 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 14138 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14139 | * the host resident queue. This function must be called after destroying the |
| 14140 | * queue on the HBA. |
| 14141 | **/ |
| 14142 | void |
| 14143 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 14144 | { |
| 14145 | struct lpfc_dmabuf *dmabuf; |
| 14146 | |
| 14147 | if (!queue) |
| 14148 | return; |
| 14149 | |
| 14150 | while (!list_empty(&queue->page_list)) { |
| 14151 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 14152 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14153 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14154 | dmabuf->virt, dmabuf->phys); |
| 14155 | kfree(dmabuf); |
| 14156 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14157 | if (queue->rqbp) { |
| 14158 | lpfc_free_rq_buffer(queue->phba, queue); |
| 14159 | kfree(queue->rqbp); |
| 14160 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 14161 | |
| 14162 | if (!list_empty(&queue->wq_list)) |
| 14163 | list_del(&queue->wq_list); |
| 14164 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14165 | kfree(queue); |
| 14166 | return; |
| 14167 | } |
| 14168 | |
| 14169 | /** |
| 14170 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 14171 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14172 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14173 | * @entry_size: The size of each queue entry for this queue. |
| 14174 | * @entry count: The number of entries that this queue will handle. |
| 14175 | * |
| 14176 | * This function allocates a queue structure and the DMAable memory used for |
| 14177 | * the host resident queue. This function must be called before creating the |
| 14178 | * queue on the HBA. |
| 14179 | **/ |
| 14180 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14181 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
| 14182 | uint32_t entry_size, uint32_t entry_count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14183 | { |
| 14184 | struct lpfc_queue *queue; |
| 14185 | struct lpfc_dmabuf *dmabuf; |
| 14186 | int x, total_qe_count; |
| 14187 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14188 | 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] | 14189 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14190 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14191 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14192 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14193 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 14194 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 14195 | if (!queue) |
| 14196 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14197 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 14198 | hw_page_size))/hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14199 | |
| 14200 | /* If needed, Adjust page count to match the max the adapter supports */ |
| 14201 | if (queue->page_count > phba->sli4_hba.pc_sli4_params.wqpcnt) |
| 14202 | queue->page_count = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 14203 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14204 | INIT_LIST_HEAD(&queue->list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14205 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 14206 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14207 | INIT_LIST_HEAD(&queue->page_list); |
| 14208 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14209 | |
| 14210 | /* Set queue parameters now. If the system cannot provide memory |
| 14211 | * resources, the free routine needs to know what was allocated. |
| 14212 | */ |
| 14213 | queue->entry_size = entry_size; |
| 14214 | queue->entry_count = entry_count; |
| 14215 | queue->page_size = hw_page_size; |
| 14216 | queue->phba = phba; |
| 14217 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14218 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 14219 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 14220 | if (!dmabuf) |
| 14221 | goto out_fail; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 14222 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 14223 | hw_page_size, &dmabuf->phys, |
| 14224 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14225 | if (!dmabuf->virt) { |
| 14226 | kfree(dmabuf); |
| 14227 | goto out_fail; |
| 14228 | } |
| 14229 | dmabuf->buffer_tag = x; |
| 14230 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 14231 | /* initialize queue's entry array */ |
| 14232 | dma_pointer = dmabuf->virt; |
| 14233 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14234 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14235 | total_qe_count++, dma_pointer += entry_size) { |
| 14236 | queue->qe[total_qe_count].address = dma_pointer; |
| 14237 | } |
| 14238 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14239 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 14240 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14241 | |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14242 | /* entry_repost will be set during q creation */ |
| 14243 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14244 | return queue; |
| 14245 | out_fail: |
| 14246 | lpfc_sli4_queue_free(queue); |
| 14247 | return NULL; |
| 14248 | } |
| 14249 | |
| 14250 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14251 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 14252 | * @phba: HBA structure that indicates port to create a queue on. |
| 14253 | * @pci_barset: PCI BAR set flag. |
| 14254 | * |
| 14255 | * This function shall perform iomap of the specified PCI BAR address to host |
| 14256 | * memory address if not already done so and return it. The returned host |
| 14257 | * memory address can be NULL. |
| 14258 | */ |
| 14259 | static void __iomem * |
| 14260 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 14261 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14262 | if (!phba->pcidev) |
| 14263 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14264 | |
| 14265 | switch (pci_barset) { |
| 14266 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14267 | return phba->pci_bar0_memmap_p; |
| 14268 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14269 | return phba->pci_bar2_memmap_p; |
| 14270 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14271 | return phba->pci_bar4_memmap_p; |
| 14272 | default: |
| 14273 | break; |
| 14274 | } |
| 14275 | return NULL; |
| 14276 | } |
| 14277 | |
| 14278 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14279 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on FCP EQs |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14280 | * @phba: HBA structure that indicates port to create a queue on. |
| 14281 | * @startq: The starting FCP EQ to modify |
| 14282 | * |
| 14283 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 14284 | * The command allows up to LPFC_MAX_EQ_DELAY_EQID_CNT EQ ID's to be |
| 14285 | * updated in one mailbox command. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14286 | * |
| 14287 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 14288 | * is used to get the starting FCP EQ to change. |
| 14289 | * This function is asynchronous and will wait for the mailbox |
| 14290 | * command to finish before continuing. |
| 14291 | * |
| 14292 | * On success this function will return a zero. If unable to allocate enough |
| 14293 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14294 | * fails this function will return -ENXIO. |
| 14295 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14296 | int |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14297 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
| 14298 | uint32_t numq, uint32_t imax) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14299 | { |
| 14300 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14301 | LPFC_MBOXQ_t *mbox; |
| 14302 | struct lpfc_queue *eq; |
| 14303 | int cnt, rc, length, status = 0; |
| 14304 | uint32_t shdr_status, shdr_add_status; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14305 | uint32_t result, val; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14306 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14307 | union lpfc_sli4_cfg_shdr *shdr; |
| 14308 | uint16_t dmult; |
| 14309 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14310 | if (startq >= phba->io_channel_irqs) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14311 | return 0; |
| 14312 | |
| 14313 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14314 | if (!mbox) |
| 14315 | return -ENOMEM; |
| 14316 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14317 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14318 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14319 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14320 | length, LPFC_SLI4_MBX_EMBED); |
| 14321 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14322 | |
| 14323 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14324 | result = imax / phba->io_channel_irqs; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14325 | if (result > LPFC_DMULT_CONST || result == 0) |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14326 | dmult = 0; |
| 14327 | else |
| 14328 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14329 | if (dmult > LPFC_DMULT_MAX) |
| 14330 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14331 | |
| 14332 | cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14333 | for (qidx = startq; qidx < phba->io_channel_irqs; qidx++) { |
| 14334 | eq = phba->sli4_hba.hba_eq[qidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14335 | if (!eq) |
| 14336 | continue; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14337 | eq->q_mode = imax; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14338 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14339 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14340 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 14341 | cnt++; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14342 | |
| 14343 | /* q_mode is only used for auto_imax */ |
| 14344 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14345 | /* Use EQ Delay Register method for q_mode */ |
| 14346 | |
| 14347 | /* Convert for EQ Delay register */ |
| 14348 | val = phba->cfg_fcp_imax; |
| 14349 | if (val) { |
| 14350 | /* First, interrupts per sec per EQ */ |
| 14351 | val = phba->cfg_fcp_imax / |
| 14352 | phba->io_channel_irqs; |
| 14353 | |
| 14354 | /* us delay between each interrupt */ |
| 14355 | val = LPFC_SEC_TO_USEC / val; |
| 14356 | } |
| 14357 | eq->q_mode = val; |
| 14358 | } else { |
| 14359 | eq->q_mode = imax; |
| 14360 | } |
| 14361 | |
| 14362 | if (cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14363 | break; |
| 14364 | } |
| 14365 | eq_delay->u.request.num_eq = cnt; |
| 14366 | |
| 14367 | mbox->vport = phba->pport; |
| 14368 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14369 | mbox->context1 = NULL; |
| 14370 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14371 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 14372 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14373 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14374 | if (shdr_status || shdr_add_status || rc) { |
| 14375 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14376 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 14377 | "status x%x add_status x%x, mbx status x%x\n", |
| 14378 | shdr_status, shdr_add_status, rc); |
| 14379 | status = -ENXIO; |
| 14380 | } |
| 14381 | mempool_free(mbox, phba->mbox_mem_pool); |
| 14382 | return status; |
| 14383 | } |
| 14384 | |
| 14385 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14386 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 14387 | * @phba: HBA structure that indicates port to create a queue on. |
| 14388 | * @eq: The queue structure to use to create the event queue. |
| 14389 | * @imax: The maximum interrupt per second limit. |
| 14390 | * |
| 14391 | * This function creates an event queue, as detailed in @eq, on a port, |
| 14392 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 14393 | * |
| 14394 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 14395 | * is used to get the entry count and entry size that are necessary to |
| 14396 | * determine the number of pages to allocate and use for this queue. This |
| 14397 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 14398 | * event queue. This function is asynchronous and will wait for the mailbox |
| 14399 | * command to finish before continuing. |
| 14400 | * |
| 14401 | * 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] | 14402 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14403 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14404 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14405 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14406 | 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] | 14407 | { |
| 14408 | struct lpfc_mbx_eq_create *eq_create; |
| 14409 | LPFC_MBOXQ_t *mbox; |
| 14410 | int rc, length, status = 0; |
| 14411 | struct lpfc_dmabuf *dmabuf; |
| 14412 | uint32_t shdr_status, shdr_add_status; |
| 14413 | union lpfc_sli4_cfg_shdr *shdr; |
| 14414 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14415 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14416 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14417 | /* sanity check on queue memory */ |
| 14418 | if (!eq) |
| 14419 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14420 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14421 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14422 | |
| 14423 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14424 | if (!mbox) |
| 14425 | return -ENOMEM; |
| 14426 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 14427 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14428 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14429 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 14430 | length, LPFC_SLI4_MBX_EMBED); |
| 14431 | eq_create = &mbox->u.mqe.un.eq_create; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14432 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14433 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 14434 | eq->page_count); |
| 14435 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 14436 | LPFC_EQE_SIZE); |
| 14437 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14438 | |
| 14439 | /* Use version 2 of CREATE_EQ if eqav is set */ |
| 14440 | if (phba->sli4_hba.pc_sli4_params.eqav) { |
| 14441 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14442 | LPFC_Q_CREATE_VERSION_2); |
| 14443 | bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context, |
| 14444 | phba->sli4_hba.pc_sli4_params.eqav); |
| 14445 | } |
| 14446 | |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 14447 | /* don't setup delay multiplier using EQ_CREATE */ |
| 14448 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14449 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 14450 | dmult); |
| 14451 | switch (eq->entry_count) { |
| 14452 | default: |
| 14453 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14454 | "0360 Unsupported EQ count. (%d)\n", |
| 14455 | eq->entry_count); |
| 14456 | if (eq->entry_count < 256) |
| 14457 | return -EINVAL; |
| 14458 | /* otherwise default to smallest count (drop through) */ |
| 14459 | case 256: |
| 14460 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14461 | LPFC_EQ_CNT_256); |
| 14462 | break; |
| 14463 | case 512: |
| 14464 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14465 | LPFC_EQ_CNT_512); |
| 14466 | break; |
| 14467 | case 1024: |
| 14468 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14469 | LPFC_EQ_CNT_1024); |
| 14470 | break; |
| 14471 | case 2048: |
| 14472 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14473 | LPFC_EQ_CNT_2048); |
| 14474 | break; |
| 14475 | case 4096: |
| 14476 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14477 | LPFC_EQ_CNT_4096); |
| 14478 | break; |
| 14479 | } |
| 14480 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14481 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14482 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14483 | putPaddrLow(dmabuf->phys); |
| 14484 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14485 | putPaddrHigh(dmabuf->phys); |
| 14486 | } |
| 14487 | mbox->vport = phba->pport; |
| 14488 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14489 | mbox->context1 = NULL; |
| 14490 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14491 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14492 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14493 | if (shdr_status || shdr_add_status || rc) { |
| 14494 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14495 | "2500 EQ_CREATE mailbox failed with " |
| 14496 | "status x%x add_status x%x, mbx status x%x\n", |
| 14497 | shdr_status, shdr_add_status, rc); |
| 14498 | status = -ENXIO; |
| 14499 | } |
| 14500 | eq->type = LPFC_EQ; |
| 14501 | eq->subtype = LPFC_NONE; |
| 14502 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 14503 | if (eq->queue_id == 0xFFFF) |
| 14504 | status = -ENXIO; |
| 14505 | eq->host_index = 0; |
| 14506 | eq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14507 | eq->entry_repost = LPFC_EQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14508 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14509 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14510 | return status; |
| 14511 | } |
| 14512 | |
| 14513 | /** |
| 14514 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 14515 | * @phba: HBA structure that indicates port to create a queue on. |
| 14516 | * @cq: The queue structure to use to create the completion queue. |
| 14517 | * @eq: The event queue to bind this completion queue to. |
| 14518 | * |
| 14519 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 14520 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 14521 | * |
| 14522 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14523 | * is used to get the entry count and entry size that are necessary to |
| 14524 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14525 | * is used to indicate which event queue to bind this completion queue to. This |
| 14526 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 14527 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14528 | * command to finish before continuing. |
| 14529 | * |
| 14530 | * 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] | 14531 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14532 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14533 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14534 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14535 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14536 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 14537 | { |
| 14538 | struct lpfc_mbx_cq_create *cq_create; |
| 14539 | struct lpfc_dmabuf *dmabuf; |
| 14540 | LPFC_MBOXQ_t *mbox; |
| 14541 | int rc, length, status = 0; |
| 14542 | uint32_t shdr_status, shdr_add_status; |
| 14543 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14544 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14545 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14546 | /* sanity check on queue memory */ |
| 14547 | if (!cq || !eq) |
| 14548 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14549 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14550 | hw_page_size = cq->page_size; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14551 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14552 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14553 | if (!mbox) |
| 14554 | return -ENOMEM; |
| 14555 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 14556 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14557 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14558 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 14559 | length, LPFC_SLI4_MBX_EMBED); |
| 14560 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14561 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14562 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 14563 | cq->page_count); |
| 14564 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 14565 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14566 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14567 | phba->sli4_hba.pc_sli4_params.cqv); |
| 14568 | 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] | 14569 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 14570 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14571 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 14572 | eq->queue_id); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14573 | bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context, |
| 14574 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14575 | } else { |
| 14576 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 14577 | eq->queue_id); |
| 14578 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14579 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14580 | case 2048: |
| 14581 | case 4096: |
| 14582 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14583 | LPFC_Q_CREATE_VERSION_2) { |
| 14584 | cq_create->u.request.context.lpfc_cq_context_count = |
| 14585 | cq->entry_count; |
| 14586 | bf_set(lpfc_cq_context_count, |
| 14587 | &cq_create->u.request.context, |
| 14588 | LPFC_CQ_CNT_WORD7); |
| 14589 | break; |
| 14590 | } |
| 14591 | /* Fall Thru */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14592 | default: |
| 14593 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14594 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14595 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14596 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14597 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14598 | if (cq->entry_count < 256) { |
| 14599 | status = -EINVAL; |
| 14600 | goto out; |
| 14601 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14602 | /* otherwise default to smallest count (drop through) */ |
| 14603 | case 256: |
| 14604 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14605 | LPFC_CQ_CNT_256); |
| 14606 | break; |
| 14607 | case 512: |
| 14608 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14609 | LPFC_CQ_CNT_512); |
| 14610 | break; |
| 14611 | case 1024: |
| 14612 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14613 | LPFC_CQ_CNT_1024); |
| 14614 | break; |
| 14615 | } |
| 14616 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14617 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14618 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14619 | putPaddrLow(dmabuf->phys); |
| 14620 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14621 | putPaddrHigh(dmabuf->phys); |
| 14622 | } |
| 14623 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14624 | |
| 14625 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14626 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14627 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14628 | if (shdr_status || shdr_add_status || rc) { |
| 14629 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14630 | "2501 CQ_CREATE mailbox failed with " |
| 14631 | "status x%x add_status x%x, mbx status x%x\n", |
| 14632 | shdr_status, shdr_add_status, rc); |
| 14633 | status = -ENXIO; |
| 14634 | goto out; |
| 14635 | } |
| 14636 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 14637 | if (cq->queue_id == 0xFFFF) { |
| 14638 | status = -ENXIO; |
| 14639 | goto out; |
| 14640 | } |
| 14641 | /* link the cq onto the parent eq child list */ |
| 14642 | list_add_tail(&cq->list, &eq->child_list); |
| 14643 | /* Set up completion queue's type and subtype */ |
| 14644 | cq->type = type; |
| 14645 | cq->subtype = subtype; |
| 14646 | 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] | 14647 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14648 | cq->host_index = 0; |
| 14649 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14650 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14651 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14652 | out: |
| 14653 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14654 | return status; |
| 14655 | } |
| 14656 | |
| 14657 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14658 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 14659 | * @phba: HBA structure that indicates port to create a queue on. |
| 14660 | * @cqp: The queue structure array to use to create the completion queues. |
| 14661 | * @eqp: The event queue array to bind these completion queues to. |
| 14662 | * |
| 14663 | * This function creates a set of completion queue, s to support MRQ |
| 14664 | * as detailed in @cqp, on a port, |
| 14665 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 14666 | * |
| 14667 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14668 | * is used to get the entry count and entry size that are necessary to |
| 14669 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14670 | * is used to indicate which event queue to bind this completion queue to. This |
| 14671 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 14672 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14673 | * command to finish before continuing. |
| 14674 | * |
| 14675 | * On success this function will return a zero. If unable to allocate enough |
| 14676 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14677 | * fails this function will return -ENXIO. |
| 14678 | **/ |
| 14679 | int |
| 14680 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
| 14681 | struct lpfc_queue **eqp, uint32_t type, uint32_t subtype) |
| 14682 | { |
| 14683 | struct lpfc_queue *cq; |
| 14684 | struct lpfc_queue *eq; |
| 14685 | struct lpfc_mbx_cq_create_set *cq_set; |
| 14686 | struct lpfc_dmabuf *dmabuf; |
| 14687 | LPFC_MBOXQ_t *mbox; |
| 14688 | int rc, length, alloclen, status = 0; |
| 14689 | int cnt, idx, numcq, page_idx = 0; |
| 14690 | uint32_t shdr_status, shdr_add_status; |
| 14691 | union lpfc_sli4_cfg_shdr *shdr; |
| 14692 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14693 | |
| 14694 | /* sanity check on queue memory */ |
| 14695 | numcq = phba->cfg_nvmet_mrq; |
| 14696 | if (!cqp || !eqp || !numcq) |
| 14697 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14698 | |
| 14699 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14700 | if (!mbox) |
| 14701 | return -ENOMEM; |
| 14702 | |
| 14703 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 14704 | length += ((numcq * cqp[0]->page_count) * |
| 14705 | sizeof(struct dma_address)); |
| 14706 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14707 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 14708 | LPFC_SLI4_MBX_NEMBED); |
| 14709 | if (alloclen < length) { |
| 14710 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14711 | "3098 Allocated DMA memory size (%d) is " |
| 14712 | "less than the requested DMA memory size " |
| 14713 | "(%d)\n", alloclen, length); |
| 14714 | status = -ENOMEM; |
| 14715 | goto out; |
| 14716 | } |
| 14717 | cq_set = mbox->sge_array->addr[0]; |
| 14718 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 14719 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 14720 | |
| 14721 | for (idx = 0; idx < numcq; idx++) { |
| 14722 | cq = cqp[idx]; |
| 14723 | eq = eqp[idx]; |
| 14724 | if (!cq || !eq) { |
| 14725 | status = -ENOMEM; |
| 14726 | goto out; |
| 14727 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14728 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14729 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14730 | |
| 14731 | switch (idx) { |
| 14732 | case 0: |
| 14733 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 14734 | &cq_set->u.request, |
| 14735 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 14736 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 14737 | &cq_set->u.request, cq->page_count); |
| 14738 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 14739 | &cq_set->u.request, 1); |
| 14740 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 14741 | &cq_set->u.request, 1); |
| 14742 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 14743 | &cq_set->u.request, 0); |
| 14744 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 14745 | &cq_set->u.request, numcq); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 14746 | bf_set(lpfc_mbx_cq_create_set_autovalid, |
| 14747 | &cq_set->u.request, |
| 14748 | phba->sli4_hba.pc_sli4_params.cqav); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14749 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14750 | case 2048: |
| 14751 | case 4096: |
| 14752 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14753 | LPFC_Q_CREATE_VERSION_2) { |
| 14754 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14755 | &cq_set->u.request, |
| 14756 | cq->entry_count); |
| 14757 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14758 | &cq_set->u.request, |
| 14759 | LPFC_CQ_CNT_WORD7); |
| 14760 | break; |
| 14761 | } |
| 14762 | /* Fall Thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14763 | default: |
| 14764 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14765 | "3118 Bad CQ count. (%d)\n", |
| 14766 | cq->entry_count); |
| 14767 | if (cq->entry_count < 256) { |
| 14768 | status = -EINVAL; |
| 14769 | goto out; |
| 14770 | } |
| 14771 | /* otherwise default to smallest (drop thru) */ |
| 14772 | case 256: |
| 14773 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14774 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 14775 | break; |
| 14776 | case 512: |
| 14777 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14778 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 14779 | break; |
| 14780 | case 1024: |
| 14781 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14782 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 14783 | break; |
| 14784 | } |
| 14785 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 14786 | &cq_set->u.request, eq->queue_id); |
| 14787 | break; |
| 14788 | case 1: |
| 14789 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 14790 | &cq_set->u.request, eq->queue_id); |
| 14791 | break; |
| 14792 | case 2: |
| 14793 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 14794 | &cq_set->u.request, eq->queue_id); |
| 14795 | break; |
| 14796 | case 3: |
| 14797 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 14798 | &cq_set->u.request, eq->queue_id); |
| 14799 | break; |
| 14800 | case 4: |
| 14801 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 14802 | &cq_set->u.request, eq->queue_id); |
| 14803 | break; |
| 14804 | case 5: |
| 14805 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 14806 | &cq_set->u.request, eq->queue_id); |
| 14807 | break; |
| 14808 | case 6: |
| 14809 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 14810 | &cq_set->u.request, eq->queue_id); |
| 14811 | break; |
| 14812 | case 7: |
| 14813 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 14814 | &cq_set->u.request, eq->queue_id); |
| 14815 | break; |
| 14816 | case 8: |
| 14817 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 14818 | &cq_set->u.request, eq->queue_id); |
| 14819 | break; |
| 14820 | case 9: |
| 14821 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 14822 | &cq_set->u.request, eq->queue_id); |
| 14823 | break; |
| 14824 | case 10: |
| 14825 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 14826 | &cq_set->u.request, eq->queue_id); |
| 14827 | break; |
| 14828 | case 11: |
| 14829 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 14830 | &cq_set->u.request, eq->queue_id); |
| 14831 | break; |
| 14832 | case 12: |
| 14833 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 14834 | &cq_set->u.request, eq->queue_id); |
| 14835 | break; |
| 14836 | case 13: |
| 14837 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 14838 | &cq_set->u.request, eq->queue_id); |
| 14839 | break; |
| 14840 | case 14: |
| 14841 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 14842 | &cq_set->u.request, eq->queue_id); |
| 14843 | break; |
| 14844 | case 15: |
| 14845 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 14846 | &cq_set->u.request, eq->queue_id); |
| 14847 | break; |
| 14848 | } |
| 14849 | |
| 14850 | /* link the cq onto the parent eq child list */ |
| 14851 | list_add_tail(&cq->list, &eq->child_list); |
| 14852 | /* Set up completion queue's type and subtype */ |
| 14853 | cq->type = type; |
| 14854 | cq->subtype = subtype; |
| 14855 | cq->assoc_qid = eq->queue_id; |
| 14856 | cq->host_index = 0; |
| 14857 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14858 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14859 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14860 | |
| 14861 | rc = 0; |
| 14862 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 14863 | memset(dmabuf->virt, 0, hw_page_size); |
| 14864 | cnt = page_idx + dmabuf->buffer_tag; |
| 14865 | cq_set->u.request.page[cnt].addr_lo = |
| 14866 | putPaddrLow(dmabuf->phys); |
| 14867 | cq_set->u.request.page[cnt].addr_hi = |
| 14868 | putPaddrHigh(dmabuf->phys); |
| 14869 | rc++; |
| 14870 | } |
| 14871 | page_idx += rc; |
| 14872 | } |
| 14873 | |
| 14874 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14875 | |
| 14876 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14877 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14878 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14879 | if (shdr_status || shdr_add_status || rc) { |
| 14880 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14881 | "3119 CQ_CREATE_SET mailbox failed with " |
| 14882 | "status x%x add_status x%x, mbx status x%x\n", |
| 14883 | shdr_status, shdr_add_status, rc); |
| 14884 | status = -ENXIO; |
| 14885 | goto out; |
| 14886 | } |
| 14887 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 14888 | if (rc == 0xFFFF) { |
| 14889 | status = -ENXIO; |
| 14890 | goto out; |
| 14891 | } |
| 14892 | |
| 14893 | for (idx = 0; idx < numcq; idx++) { |
| 14894 | cq = cqp[idx]; |
| 14895 | cq->queue_id = rc + idx; |
| 14896 | } |
| 14897 | |
| 14898 | out: |
| 14899 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14900 | return status; |
| 14901 | } |
| 14902 | |
| 14903 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14904 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14905 | * @phba: HBA structure that indicates port to create a queue on. |
| 14906 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14907 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 14908 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14909 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14910 | * This function provides failback (fb) functionality when the |
| 14911 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 14912 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14913 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14914 | * This routine cannot fail as all attributes were previously accessed and |
| 14915 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14916 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14917 | static void |
| 14918 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 14919 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14920 | { |
| 14921 | struct lpfc_mbx_mq_create *mq_create; |
| 14922 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14923 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14924 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14925 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 14926 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14927 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14928 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 14929 | length, LPFC_SLI4_MBX_EMBED); |
| 14930 | mq_create = &mbox->u.mqe.un.mq_create; |
| 14931 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14932 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14933 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14934 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14935 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 14936 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14937 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14938 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14939 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14940 | break; |
| 14941 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14942 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14943 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14944 | break; |
| 14945 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14946 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14947 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14948 | break; |
| 14949 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14950 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14951 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14952 | break; |
| 14953 | } |
| 14954 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 14955 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14956 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14957 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14958 | putPaddrHigh(dmabuf->phys); |
| 14959 | } |
| 14960 | } |
| 14961 | |
| 14962 | /** |
| 14963 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 14964 | * @phba: HBA structure that indicates port to create a queue on. |
| 14965 | * @mq: The queue structure to use to create the mailbox queue. |
| 14966 | * @cq: The completion queue to associate with this cq. |
| 14967 | * @subtype: The queue's subtype. |
| 14968 | * |
| 14969 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 14970 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 14971 | * |
| 14972 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14973 | * is used to get the entry count and entry size that are necessary to |
| 14974 | * determine the number of pages to allocate and use for this queue. This |
| 14975 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 14976 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 14977 | * command to finish before continuing. |
| 14978 | * |
| 14979 | * 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] | 14980 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14981 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14982 | **/ |
| 14983 | int32_t |
| 14984 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 14985 | struct lpfc_queue *cq, uint32_t subtype) |
| 14986 | { |
| 14987 | struct lpfc_mbx_mq_create *mq_create; |
| 14988 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 14989 | struct lpfc_dmabuf *dmabuf; |
| 14990 | LPFC_MBOXQ_t *mbox; |
| 14991 | int rc, length, status = 0; |
| 14992 | uint32_t shdr_status, shdr_add_status; |
| 14993 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14994 | 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] | 14995 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14996 | /* sanity check on queue memory */ |
| 14997 | if (!mq || !cq) |
| 14998 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14999 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15000 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15001 | |
| 15002 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15003 | if (!mbox) |
| 15004 | return -ENOMEM; |
| 15005 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 15006 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15007 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15008 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 15009 | length, LPFC_SLI4_MBX_EMBED); |
| 15010 | |
| 15011 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15012 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15013 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 15014 | &mq_create_ext->u.request, mq->page_count); |
| 15015 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 15016 | &mq_create_ext->u.request, 1); |
| 15017 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15018 | &mq_create_ext->u.request, 1); |
| 15019 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 15020 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 15021 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 15022 | &mq_create_ext->u.request, 1); |
| 15023 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 15024 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15025 | 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] | 15026 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15027 | phba->sli4_hba.pc_sli4_params.mqv); |
| 15028 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 15029 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 15030 | cq->queue_id); |
| 15031 | else |
| 15032 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 15033 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15034 | switch (mq->entry_count) { |
| 15035 | default: |
| 15036 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15037 | "0362 Unsupported MQ count. (%d)\n", |
| 15038 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15039 | if (mq->entry_count < 16) { |
| 15040 | status = -EINVAL; |
| 15041 | goto out; |
| 15042 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15043 | /* otherwise default to smallest count (drop through) */ |
| 15044 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15045 | bf_set(lpfc_mq_context_ring_size, |
| 15046 | &mq_create_ext->u.request.context, |
| 15047 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15048 | break; |
| 15049 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15050 | bf_set(lpfc_mq_context_ring_size, |
| 15051 | &mq_create_ext->u.request.context, |
| 15052 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15053 | break; |
| 15054 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15055 | bf_set(lpfc_mq_context_ring_size, |
| 15056 | &mq_create_ext->u.request.context, |
| 15057 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15058 | break; |
| 15059 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15060 | bf_set(lpfc_mq_context_ring_size, |
| 15061 | &mq_create_ext->u.request.context, |
| 15062 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15063 | break; |
| 15064 | } |
| 15065 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15066 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15067 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15068 | putPaddrLow(dmabuf->phys); |
| 15069 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15070 | putPaddrHigh(dmabuf->phys); |
| 15071 | } |
| 15072 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 15073 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15074 | &mq_create_ext->u.response); |
| 15075 | if (rc != MBX_SUCCESS) { |
| 15076 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15077 | "2795 MQ_CREATE_EXT failed with " |
| 15078 | "status x%x. Failback to MQ_CREATE.\n", |
| 15079 | rc); |
| 15080 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 15081 | mq_create = &mbox->u.mqe.un.mq_create; |
| 15082 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15083 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 15084 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 15085 | &mq_create->u.response); |
| 15086 | } |
| 15087 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15088 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15089 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15090 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15091 | if (shdr_status || shdr_add_status || rc) { |
| 15092 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15093 | "2502 MQ_CREATE mailbox failed with " |
| 15094 | "status x%x add_status x%x, mbx status x%x\n", |
| 15095 | shdr_status, shdr_add_status, rc); |
| 15096 | status = -ENXIO; |
| 15097 | goto out; |
| 15098 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15099 | if (mq->queue_id == 0xFFFF) { |
| 15100 | status = -ENXIO; |
| 15101 | goto out; |
| 15102 | } |
| 15103 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15104 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15105 | mq->subtype = subtype; |
| 15106 | mq->host_index = 0; |
| 15107 | mq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 15108 | mq->entry_repost = LPFC_MQ_REPOST; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15109 | |
| 15110 | /* link the mq onto the parent cq child list */ |
| 15111 | list_add_tail(&mq->list, &cq->child_list); |
| 15112 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15113 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15114 | return status; |
| 15115 | } |
| 15116 | |
| 15117 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15118 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 15119 | * @phba: HBA structure that indicates port to create a queue on. |
| 15120 | * @wq: The queue structure to use to create the work queue. |
| 15121 | * @cq: The completion queue to bind this work queue to. |
| 15122 | * @subtype: The subtype of the work queue indicating its functionality. |
| 15123 | * |
| 15124 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 15125 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 15126 | * |
| 15127 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 15128 | * is used to get the entry count and entry size that are necessary to |
| 15129 | * determine the number of pages to allocate and use for this queue. The @cq |
| 15130 | * is used to indicate which completion queue to bind this work queue to. This |
| 15131 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 15132 | * work queue. This function is asynchronous and will wait for the mailbox |
| 15133 | * command to finish before continuing. |
| 15134 | * |
| 15135 | * 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] | 15136 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15137 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15138 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15139 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15140 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 15141 | struct lpfc_queue *cq, uint32_t subtype) |
| 15142 | { |
| 15143 | struct lpfc_mbx_wq_create *wq_create; |
| 15144 | struct lpfc_dmabuf *dmabuf; |
| 15145 | LPFC_MBOXQ_t *mbox; |
| 15146 | int rc, length, status = 0; |
| 15147 | uint32_t shdr_status, shdr_add_status; |
| 15148 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15149 | 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] | 15150 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15151 | void __iomem *bar_memmap_p; |
| 15152 | uint32_t db_offset; |
| 15153 | uint16_t pci_barset; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15154 | uint8_t dpp_barset; |
| 15155 | uint32_t dpp_offset; |
| 15156 | unsigned long pg_addr; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15157 | uint8_t wq_create_version; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15158 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15159 | /* sanity check on queue memory */ |
| 15160 | if (!wq || !cq) |
| 15161 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15162 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15163 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15164 | |
| 15165 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15166 | if (!mbox) |
| 15167 | return -ENOMEM; |
| 15168 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 15169 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15170 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15171 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 15172 | length, LPFC_SLI4_MBX_EMBED); |
| 15173 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15174 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15175 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 15176 | wq->page_count); |
| 15177 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 15178 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15179 | |
| 15180 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15181 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15182 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15183 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 15184 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 15185 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15186 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15187 | else |
| 15188 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15189 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15190 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15191 | if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) |
| 15192 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 15193 | else |
| 15194 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 15195 | |
| 15196 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15197 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15198 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 15199 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 15200 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15201 | LPFC_Q_CREATE_VERSION_1); |
| 15202 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15203 | switch (wq->entry_size) { |
| 15204 | default: |
| 15205 | case 64: |
| 15206 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15207 | &wq_create->u.request_1, |
| 15208 | LPFC_WQ_WQE_SIZE_64); |
| 15209 | break; |
| 15210 | case 128: |
| 15211 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 15212 | &wq_create->u.request_1, |
| 15213 | LPFC_WQ_WQE_SIZE_128); |
| 15214 | break; |
| 15215 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15216 | /* Request DPP by default */ |
| 15217 | 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] | 15218 | bf_set(lpfc_mbx_wq_create_page_size, |
| 15219 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15220 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15221 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15222 | break; |
| 15223 | default: |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15224 | page = wq_create->u.request.page; |
| 15225 | break; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15226 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15227 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15228 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15229 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15230 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 15231 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15232 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15233 | |
| 15234 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15235 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 15236 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15237 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15238 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15239 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15240 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15241 | if (shdr_status || shdr_add_status || rc) { |
| 15242 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15243 | "2503 WQ_CREATE mailbox failed with " |
| 15244 | "status x%x add_status x%x, mbx status x%x\n", |
| 15245 | shdr_status, shdr_add_status, rc); |
| 15246 | status = -ENXIO; |
| 15247 | goto out; |
| 15248 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15249 | |
| 15250 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) |
| 15251 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, |
| 15252 | &wq_create->u.response); |
| 15253 | else |
| 15254 | wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id, |
| 15255 | &wq_create->u.response_1); |
| 15256 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15257 | if (wq->queue_id == 0xFFFF) { |
| 15258 | status = -ENXIO; |
| 15259 | goto out; |
| 15260 | } |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15261 | |
| 15262 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15263 | if (wq_create_version == LPFC_Q_CREATE_VERSION_0) { |
| 15264 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15265 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 15266 | &wq_create->u.response); |
| 15267 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15268 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15269 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15270 | "3265 WQ[%d] doorbell format " |
| 15271 | "not supported: x%x\n", |
| 15272 | wq->queue_id, wq->db_format); |
| 15273 | status = -EINVAL; |
| 15274 | goto out; |
| 15275 | } |
| 15276 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 15277 | &wq_create->u.response); |
| 15278 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15279 | pci_barset); |
| 15280 | if (!bar_memmap_p) { |
| 15281 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15282 | "3263 WQ[%d] failed to memmap " |
| 15283 | "pci barset:x%x\n", |
| 15284 | wq->queue_id, pci_barset); |
| 15285 | status = -ENOMEM; |
| 15286 | goto out; |
| 15287 | } |
| 15288 | db_offset = wq_create->u.response.doorbell_offset; |
| 15289 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 15290 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 15291 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15292 | "3252 WQ[%d] doorbell offset " |
| 15293 | "not supported: x%x\n", |
| 15294 | wq->queue_id, db_offset); |
| 15295 | status = -EINVAL; |
| 15296 | goto out; |
| 15297 | } |
| 15298 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15299 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15300 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15301 | "format:x%x\n", wq->queue_id, |
| 15302 | pci_barset, db_offset, wq->db_format); |
| 15303 | } else |
| 15304 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15305 | } else { |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 15306 | /* Check if DPP was honored by the firmware */ |
| 15307 | wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp, |
| 15308 | &wq_create->u.response_1); |
| 15309 | if (wq->dpp_enable) { |
| 15310 | pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set, |
| 15311 | &wq_create->u.response_1); |
| 15312 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15313 | pci_barset); |
| 15314 | if (!bar_memmap_p) { |
| 15315 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15316 | "3267 WQ[%d] failed to memmap " |
| 15317 | "pci barset:x%x\n", |
| 15318 | wq->queue_id, pci_barset); |
| 15319 | status = -ENOMEM; |
| 15320 | goto out; |
| 15321 | } |
| 15322 | db_offset = wq_create->u.response_1.doorbell_offset; |
| 15323 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15324 | wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id, |
| 15325 | &wq_create->u.response_1); |
| 15326 | dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar, |
| 15327 | &wq_create->u.response_1); |
| 15328 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, |
| 15329 | dpp_barset); |
| 15330 | if (!bar_memmap_p) { |
| 15331 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15332 | "3268 WQ[%d] failed to memmap " |
| 15333 | "pci barset:x%x\n", |
| 15334 | wq->queue_id, dpp_barset); |
| 15335 | status = -ENOMEM; |
| 15336 | goto out; |
| 15337 | } |
| 15338 | dpp_offset = wq_create->u.response_1.dpp_offset; |
| 15339 | wq->dpp_regaddr = bar_memmap_p + dpp_offset; |
| 15340 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 15341 | "3271 WQ[%d]: barset:x%x, offset:x%x, " |
| 15342 | "dpp_id:x%x dpp_barset:x%x " |
| 15343 | "dpp_offset:x%x\n", |
| 15344 | wq->queue_id, pci_barset, db_offset, |
| 15345 | wq->dpp_id, dpp_barset, dpp_offset); |
| 15346 | |
| 15347 | /* Enable combined writes for DPP aperture */ |
| 15348 | pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK; |
| 15349 | #ifdef CONFIG_X86 |
| 15350 | rc = set_memory_wc(pg_addr, 1); |
| 15351 | if (rc) { |
| 15352 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15353 | "3272 Cannot setup Combined " |
| 15354 | "Write on WQ[%d] - disable DPP\n", |
| 15355 | wq->queue_id); |
| 15356 | phba->cfg_enable_dpp = 0; |
| 15357 | } |
| 15358 | #else |
| 15359 | phba->cfg_enable_dpp = 0; |
| 15360 | #endif |
| 15361 | } else |
| 15362 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15363 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15364 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 15365 | if (wq->pring == NULL) { |
| 15366 | status = -ENOMEM; |
| 15367 | goto out; |
| 15368 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15369 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15370 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15371 | wq->subtype = subtype; |
| 15372 | wq->host_index = 0; |
| 15373 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 15374 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15375 | |
| 15376 | /* link the wq onto the parent cq child list */ |
| 15377 | list_add_tail(&wq->list, &cq->child_list); |
| 15378 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15379 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15380 | return status; |
| 15381 | } |
| 15382 | |
| 15383 | /** |
| 15384 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 15385 | * @phba: HBA structure that indicates port to create a queue on. |
| 15386 | * @hrq: The queue structure to use to create the header receive queue. |
| 15387 | * @drq: The queue structure to use to create the data receive queue. |
| 15388 | * @cq: The completion queue to bind this work queue to. |
| 15389 | * |
| 15390 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15391 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15392 | * to the HBA. |
| 15393 | * |
| 15394 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15395 | * struct is used to get the entry count that is necessary to determine the |
| 15396 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15397 | * completion queue to bind received buffers that are posted to these queues to. |
| 15398 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15399 | * receive queue pair. This function is asynchronous and will wait for the |
| 15400 | * mailbox command to finish before continuing. |
| 15401 | * |
| 15402 | * 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] | 15403 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15404 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15405 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15406 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15407 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15408 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 15409 | { |
| 15410 | struct lpfc_mbx_rq_create *rq_create; |
| 15411 | struct lpfc_dmabuf *dmabuf; |
| 15412 | LPFC_MBOXQ_t *mbox; |
| 15413 | int rc, length, status = 0; |
| 15414 | uint32_t shdr_status, shdr_add_status; |
| 15415 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15416 | 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] | 15417 | void __iomem *bar_memmap_p; |
| 15418 | uint32_t db_offset; |
| 15419 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15420 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15421 | /* sanity check on queue memory */ |
| 15422 | if (!hrq || !drq || !cq) |
| 15423 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15424 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15425 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15426 | |
| 15427 | if (hrq->entry_count != drq->entry_count) |
| 15428 | return -EINVAL; |
| 15429 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15430 | if (!mbox) |
| 15431 | return -ENOMEM; |
| 15432 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 15433 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15434 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15435 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15436 | length, LPFC_SLI4_MBX_EMBED); |
| 15437 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15438 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15439 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15440 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15441 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15442 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15443 | &rq_create->u.request.context, |
| 15444 | hrq->entry_count); |
| 15445 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15446 | bf_set(lpfc_rq_context_rqe_size, |
| 15447 | &rq_create->u.request.context, |
| 15448 | LPFC_RQE_SIZE_8); |
| 15449 | bf_set(lpfc_rq_context_page_size, |
| 15450 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15451 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15452 | } else { |
| 15453 | switch (hrq->entry_count) { |
| 15454 | default: |
| 15455 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15456 | "2535 Unsupported RQ count. (%d)\n", |
| 15457 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15458 | if (hrq->entry_count < 512) { |
| 15459 | status = -EINVAL; |
| 15460 | goto out; |
| 15461 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15462 | /* otherwise default to smallest count (drop through) */ |
| 15463 | case 512: |
| 15464 | bf_set(lpfc_rq_context_rqe_count, |
| 15465 | &rq_create->u.request.context, |
| 15466 | LPFC_RQ_RING_SIZE_512); |
| 15467 | break; |
| 15468 | case 1024: |
| 15469 | bf_set(lpfc_rq_context_rqe_count, |
| 15470 | &rq_create->u.request.context, |
| 15471 | LPFC_RQ_RING_SIZE_1024); |
| 15472 | break; |
| 15473 | case 2048: |
| 15474 | bf_set(lpfc_rq_context_rqe_count, |
| 15475 | &rq_create->u.request.context, |
| 15476 | LPFC_RQ_RING_SIZE_2048); |
| 15477 | break; |
| 15478 | case 4096: |
| 15479 | bf_set(lpfc_rq_context_rqe_count, |
| 15480 | &rq_create->u.request.context, |
| 15481 | LPFC_RQ_RING_SIZE_4096); |
| 15482 | break; |
| 15483 | } |
| 15484 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 15485 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15486 | } |
| 15487 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15488 | cq->queue_id); |
| 15489 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15490 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15491 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15492 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15493 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15494 | putPaddrLow(dmabuf->phys); |
| 15495 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15496 | putPaddrHigh(dmabuf->phys); |
| 15497 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15498 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15499 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 15500 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15501 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15502 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15503 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15504 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15505 | if (shdr_status || shdr_add_status || rc) { |
| 15506 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15507 | "2504 RQ_CREATE mailbox failed with " |
| 15508 | "status x%x add_status x%x, mbx status x%x\n", |
| 15509 | shdr_status, shdr_add_status, rc); |
| 15510 | status = -ENXIO; |
| 15511 | goto out; |
| 15512 | } |
| 15513 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15514 | if (hrq->queue_id == 0xFFFF) { |
| 15515 | status = -ENXIO; |
| 15516 | goto out; |
| 15517 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15518 | |
| 15519 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15520 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 15521 | &rq_create->u.response); |
| 15522 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15523 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15524 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15525 | "3262 RQ [%d] doorbell format not " |
| 15526 | "supported: x%x\n", hrq->queue_id, |
| 15527 | hrq->db_format); |
| 15528 | status = -EINVAL; |
| 15529 | goto out; |
| 15530 | } |
| 15531 | |
| 15532 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 15533 | &rq_create->u.response); |
| 15534 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15535 | if (!bar_memmap_p) { |
| 15536 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15537 | "3269 RQ[%d] failed to memmap pci " |
| 15538 | "barset:x%x\n", hrq->queue_id, |
| 15539 | pci_barset); |
| 15540 | status = -ENOMEM; |
| 15541 | goto out; |
| 15542 | } |
| 15543 | |
| 15544 | db_offset = rq_create->u.response.doorbell_offset; |
| 15545 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 15546 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 15547 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15548 | "3270 RQ[%d] doorbell offset not " |
| 15549 | "supported: x%x\n", hrq->queue_id, |
| 15550 | db_offset); |
| 15551 | status = -EINVAL; |
| 15552 | goto out; |
| 15553 | } |
| 15554 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 15555 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15556 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 15557 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 15558 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15559 | } else { |
| 15560 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15561 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15562 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15563 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15564 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15565 | hrq->subtype = subtype; |
| 15566 | hrq->host_index = 0; |
| 15567 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15568 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15569 | |
| 15570 | /* now create the data queue */ |
| 15571 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15572 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15573 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15574 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15575 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15576 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15577 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15578 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15579 | if (subtype == LPFC_NVMET) |
| 15580 | rq_create->u.request.context.buffer_size = |
| 15581 | LPFC_NVMET_DATA_BUF_SIZE; |
| 15582 | else |
| 15583 | rq_create->u.request.context.buffer_size = |
| 15584 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15585 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 15586 | LPFC_RQE_SIZE_8); |
| 15587 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 15588 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15589 | } else { |
| 15590 | switch (drq->entry_count) { |
| 15591 | default: |
| 15592 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15593 | "2536 Unsupported RQ count. (%d)\n", |
| 15594 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15595 | if (drq->entry_count < 512) { |
| 15596 | status = -EINVAL; |
| 15597 | goto out; |
| 15598 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15599 | /* otherwise default to smallest count (drop through) */ |
| 15600 | case 512: |
| 15601 | bf_set(lpfc_rq_context_rqe_count, |
| 15602 | &rq_create->u.request.context, |
| 15603 | LPFC_RQ_RING_SIZE_512); |
| 15604 | break; |
| 15605 | case 1024: |
| 15606 | bf_set(lpfc_rq_context_rqe_count, |
| 15607 | &rq_create->u.request.context, |
| 15608 | LPFC_RQ_RING_SIZE_1024); |
| 15609 | break; |
| 15610 | case 2048: |
| 15611 | bf_set(lpfc_rq_context_rqe_count, |
| 15612 | &rq_create->u.request.context, |
| 15613 | LPFC_RQ_RING_SIZE_2048); |
| 15614 | break; |
| 15615 | case 4096: |
| 15616 | bf_set(lpfc_rq_context_rqe_count, |
| 15617 | &rq_create->u.request.context, |
| 15618 | LPFC_RQ_RING_SIZE_4096); |
| 15619 | break; |
| 15620 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15621 | if (subtype == LPFC_NVMET) |
| 15622 | bf_set(lpfc_rq_context_buf_size, |
| 15623 | &rq_create->u.request.context, |
| 15624 | LPFC_NVMET_DATA_BUF_SIZE); |
| 15625 | else |
| 15626 | bf_set(lpfc_rq_context_buf_size, |
| 15627 | &rq_create->u.request.context, |
| 15628 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15629 | } |
| 15630 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15631 | cq->queue_id); |
| 15632 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15633 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15634 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15635 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15636 | putPaddrLow(dmabuf->phys); |
| 15637 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15638 | putPaddrHigh(dmabuf->phys); |
| 15639 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15640 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15641 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15642 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15643 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15644 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15645 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15646 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15647 | if (shdr_status || shdr_add_status || rc) { |
| 15648 | status = -ENXIO; |
| 15649 | goto out; |
| 15650 | } |
| 15651 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15652 | if (drq->queue_id == 0xFFFF) { |
| 15653 | status = -ENXIO; |
| 15654 | goto out; |
| 15655 | } |
| 15656 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15657 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15658 | drq->subtype = subtype; |
| 15659 | drq->host_index = 0; |
| 15660 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15661 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15662 | |
| 15663 | /* link the header and data RQs onto the parent cq child list */ |
| 15664 | list_add_tail(&hrq->list, &cq->child_list); |
| 15665 | list_add_tail(&drq->list, &cq->child_list); |
| 15666 | |
| 15667 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15668 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15669 | return status; |
| 15670 | } |
| 15671 | |
| 15672 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15673 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 15674 | * @phba: HBA structure that indicates port to create a queue on. |
| 15675 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 15676 | * @drqp: The queue structure array to use to create the data receive queues. |
| 15677 | * @cqp: The completion queue array to bind these receive queues to. |
| 15678 | * |
| 15679 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15680 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15681 | * to the HBA. |
| 15682 | * |
| 15683 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15684 | * struct is used to get the entry count that is necessary to determine the |
| 15685 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15686 | * completion queue to bind received buffers that are posted to these queues to. |
| 15687 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15688 | * receive queue pair. This function is asynchronous and will wait for the |
| 15689 | * mailbox command to finish before continuing. |
| 15690 | * |
| 15691 | * On success this function will return a zero. If unable to allocate enough |
| 15692 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15693 | * fails this function will return -ENXIO. |
| 15694 | **/ |
| 15695 | int |
| 15696 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 15697 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 15698 | uint32_t subtype) |
| 15699 | { |
| 15700 | struct lpfc_queue *hrq, *drq, *cq; |
| 15701 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 15702 | struct lpfc_dmabuf *dmabuf; |
| 15703 | LPFC_MBOXQ_t *mbox; |
| 15704 | int rc, length, alloclen, status = 0; |
| 15705 | int cnt, idx, numrq, page_idx = 0; |
| 15706 | uint32_t shdr_status, shdr_add_status; |
| 15707 | union lpfc_sli4_cfg_shdr *shdr; |
| 15708 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15709 | |
| 15710 | numrq = phba->cfg_nvmet_mrq; |
| 15711 | /* sanity check on array memory */ |
| 15712 | if (!hrqp || !drqp || !cqp || !numrq) |
| 15713 | return -ENODEV; |
| 15714 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15715 | hw_page_size = SLI4_PAGE_SIZE; |
| 15716 | |
| 15717 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15718 | if (!mbox) |
| 15719 | return -ENOMEM; |
| 15720 | |
| 15721 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 15722 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 15723 | sizeof(struct dma_address)); |
| 15724 | |
| 15725 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15726 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 15727 | LPFC_SLI4_MBX_NEMBED); |
| 15728 | if (alloclen < length) { |
| 15729 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15730 | "3099 Allocated DMA memory size (%d) is " |
| 15731 | "less than the requested DMA memory size " |
| 15732 | "(%d)\n", alloclen, length); |
| 15733 | status = -ENOMEM; |
| 15734 | goto out; |
| 15735 | } |
| 15736 | |
| 15737 | |
| 15738 | |
| 15739 | rq_create = mbox->sge_array->addr[0]; |
| 15740 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 15741 | |
| 15742 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 15743 | cnt = 0; |
| 15744 | |
| 15745 | for (idx = 0; idx < numrq; idx++) { |
| 15746 | hrq = hrqp[idx]; |
| 15747 | drq = drqp[idx]; |
| 15748 | cq = cqp[idx]; |
| 15749 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15750 | /* sanity check on queue memory */ |
| 15751 | if (!hrq || !drq || !cq) { |
| 15752 | status = -ENODEV; |
| 15753 | goto out; |
| 15754 | } |
| 15755 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 15756 | if (hrq->entry_count != drq->entry_count) { |
| 15757 | status = -EINVAL; |
| 15758 | goto out; |
| 15759 | } |
| 15760 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15761 | if (idx == 0) { |
| 15762 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 15763 | &rq_create->u.request, |
| 15764 | hrq->page_count); |
| 15765 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 15766 | &rq_create->u.request, (numrq * 2)); |
| 15767 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 15768 | 1); |
| 15769 | bf_set(lpfc_rq_context_base_cq, |
| 15770 | &rq_create->u.request.context, |
| 15771 | cq->queue_id); |
| 15772 | bf_set(lpfc_rq_context_data_size, |
| 15773 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15774 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15775 | bf_set(lpfc_rq_context_hdr_size, |
| 15776 | &rq_create->u.request.context, |
| 15777 | LPFC_HDR_BUF_SIZE); |
| 15778 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15779 | &rq_create->u.request.context, |
| 15780 | hrq->entry_count); |
| 15781 | bf_set(lpfc_rq_context_rqe_size, |
| 15782 | &rq_create->u.request.context, |
| 15783 | LPFC_RQE_SIZE_8); |
| 15784 | bf_set(lpfc_rq_context_page_size, |
| 15785 | &rq_create->u.request.context, |
| 15786 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 15787 | } |
| 15788 | rc = 0; |
| 15789 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 15790 | memset(dmabuf->virt, 0, hw_page_size); |
| 15791 | cnt = page_idx + dmabuf->buffer_tag; |
| 15792 | rq_create->u.request.page[cnt].addr_lo = |
| 15793 | putPaddrLow(dmabuf->phys); |
| 15794 | rq_create->u.request.page[cnt].addr_hi = |
| 15795 | putPaddrHigh(dmabuf->phys); |
| 15796 | rc++; |
| 15797 | } |
| 15798 | page_idx += rc; |
| 15799 | |
| 15800 | rc = 0; |
| 15801 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15802 | memset(dmabuf->virt, 0, hw_page_size); |
| 15803 | cnt = page_idx + dmabuf->buffer_tag; |
| 15804 | rq_create->u.request.page[cnt].addr_lo = |
| 15805 | putPaddrLow(dmabuf->phys); |
| 15806 | rq_create->u.request.page[cnt].addr_hi = |
| 15807 | putPaddrHigh(dmabuf->phys); |
| 15808 | rc++; |
| 15809 | } |
| 15810 | page_idx += rc; |
| 15811 | |
| 15812 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15813 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15814 | hrq->type = LPFC_HRQ; |
| 15815 | hrq->assoc_qid = cq->queue_id; |
| 15816 | hrq->subtype = subtype; |
| 15817 | hrq->host_index = 0; |
| 15818 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15819 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15820 | |
| 15821 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 15822 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15823 | drq->type = LPFC_DRQ; |
| 15824 | drq->assoc_qid = cq->queue_id; |
| 15825 | drq->subtype = subtype; |
| 15826 | drq->host_index = 0; |
| 15827 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15828 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15829 | |
| 15830 | list_add_tail(&hrq->list, &cq->child_list); |
| 15831 | list_add_tail(&drq->list, &cq->child_list); |
| 15832 | } |
| 15833 | |
| 15834 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15835 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15836 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15837 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15838 | if (shdr_status || shdr_add_status || rc) { |
| 15839 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15840 | "3120 RQ_CREATE mailbox failed with " |
| 15841 | "status x%x add_status x%x, mbx status x%x\n", |
| 15842 | shdr_status, shdr_add_status, rc); |
| 15843 | status = -ENXIO; |
| 15844 | goto out; |
| 15845 | } |
| 15846 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15847 | if (rc == 0xFFFF) { |
| 15848 | status = -ENXIO; |
| 15849 | goto out; |
| 15850 | } |
| 15851 | |
| 15852 | /* Initialize all RQs with associated queue id */ |
| 15853 | for (idx = 0; idx < numrq; idx++) { |
| 15854 | hrq = hrqp[idx]; |
| 15855 | hrq->queue_id = rc + (2 * idx); |
| 15856 | drq = drqp[idx]; |
| 15857 | drq->queue_id = rc + (2 * idx) + 1; |
| 15858 | } |
| 15859 | |
| 15860 | out: |
| 15861 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15862 | return status; |
| 15863 | } |
| 15864 | |
| 15865 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15866 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 15867 | * @eq: The queue structure associated with the queue to destroy. |
| 15868 | * |
| 15869 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 15870 | * command, specific to the type of queue, to the HBA. |
| 15871 | * |
| 15872 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 15873 | * |
| 15874 | * 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] | 15875 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15876 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15877 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15878 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 15879 | { |
| 15880 | LPFC_MBOXQ_t *mbox; |
| 15881 | int rc, length, status = 0; |
| 15882 | uint32_t shdr_status, shdr_add_status; |
| 15883 | union lpfc_sli4_cfg_shdr *shdr; |
| 15884 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15885 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15886 | if (!eq) |
| 15887 | return -ENODEV; |
| 15888 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15889 | if (!mbox) |
| 15890 | return -ENOMEM; |
| 15891 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 15892 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15893 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15894 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 15895 | length, LPFC_SLI4_MBX_EMBED); |
| 15896 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 15897 | eq->queue_id); |
| 15898 | mbox->vport = eq->phba->pport; |
| 15899 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15900 | |
| 15901 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 15902 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15903 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15904 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 15905 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15906 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15907 | if (shdr_status || shdr_add_status || rc) { |
| 15908 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15909 | "2505 EQ_DESTROY mailbox failed with " |
| 15910 | "status x%x add_status x%x, mbx status x%x\n", |
| 15911 | shdr_status, shdr_add_status, rc); |
| 15912 | status = -ENXIO; |
| 15913 | } |
| 15914 | |
| 15915 | /* Remove eq from any list */ |
| 15916 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15917 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15918 | return status; |
| 15919 | } |
| 15920 | |
| 15921 | /** |
| 15922 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 15923 | * @cq: The queue structure associated with the queue to destroy. |
| 15924 | * |
| 15925 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 15926 | * command, specific to the type of queue, to the HBA. |
| 15927 | * |
| 15928 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 15929 | * |
| 15930 | * 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] | 15931 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15932 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15933 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15934 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 15935 | { |
| 15936 | LPFC_MBOXQ_t *mbox; |
| 15937 | int rc, length, status = 0; |
| 15938 | uint32_t shdr_status, shdr_add_status; |
| 15939 | union lpfc_sli4_cfg_shdr *shdr; |
| 15940 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15941 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15942 | if (!cq) |
| 15943 | return -ENODEV; |
| 15944 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15945 | if (!mbox) |
| 15946 | return -ENOMEM; |
| 15947 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 15948 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15949 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15950 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 15951 | length, LPFC_SLI4_MBX_EMBED); |
| 15952 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 15953 | cq->queue_id); |
| 15954 | mbox->vport = cq->phba->pport; |
| 15955 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15956 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 15957 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15958 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15959 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 15960 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15961 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15962 | if (shdr_status || shdr_add_status || rc) { |
| 15963 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15964 | "2506 CQ_DESTROY mailbox failed with " |
| 15965 | "status x%x add_status x%x, mbx status x%x\n", |
| 15966 | shdr_status, shdr_add_status, rc); |
| 15967 | status = -ENXIO; |
| 15968 | } |
| 15969 | /* Remove cq from any list */ |
| 15970 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15971 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15972 | return status; |
| 15973 | } |
| 15974 | |
| 15975 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15976 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 15977 | * @qm: The queue structure associated with the queue to destroy. |
| 15978 | * |
| 15979 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 15980 | * command, specific to the type of queue, to the HBA. |
| 15981 | * |
| 15982 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 15983 | * |
| 15984 | * 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] | 15985 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15986 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15987 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15988 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 15989 | { |
| 15990 | LPFC_MBOXQ_t *mbox; |
| 15991 | int rc, length, status = 0; |
| 15992 | uint32_t shdr_status, shdr_add_status; |
| 15993 | union lpfc_sli4_cfg_shdr *shdr; |
| 15994 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15995 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15996 | if (!mq) |
| 15997 | return -ENODEV; |
| 15998 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15999 | if (!mbox) |
| 16000 | return -ENOMEM; |
| 16001 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 16002 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16003 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 16004 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 16005 | length, LPFC_SLI4_MBX_EMBED); |
| 16006 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 16007 | mq->queue_id); |
| 16008 | mbox->vport = mq->phba->pport; |
| 16009 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16010 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 16011 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16012 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16013 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 16014 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16015 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16016 | if (shdr_status || shdr_add_status || rc) { |
| 16017 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16018 | "2507 MQ_DESTROY mailbox failed with " |
| 16019 | "status x%x add_status x%x, mbx status x%x\n", |
| 16020 | shdr_status, shdr_add_status, rc); |
| 16021 | status = -ENXIO; |
| 16022 | } |
| 16023 | /* Remove mq from any list */ |
| 16024 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16025 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 16026 | return status; |
| 16027 | } |
| 16028 | |
| 16029 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16030 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 16031 | * @wq: The queue structure associated with the queue to destroy. |
| 16032 | * |
| 16033 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 16034 | * command, specific to the type of queue, to the HBA. |
| 16035 | * |
| 16036 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 16037 | * |
| 16038 | * 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] | 16039 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16040 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16041 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16042 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 16043 | { |
| 16044 | LPFC_MBOXQ_t *mbox; |
| 16045 | int rc, length, status = 0; |
| 16046 | uint32_t shdr_status, shdr_add_status; |
| 16047 | union lpfc_sli4_cfg_shdr *shdr; |
| 16048 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16049 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16050 | if (!wq) |
| 16051 | return -ENODEV; |
| 16052 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16053 | if (!mbox) |
| 16054 | return -ENOMEM; |
| 16055 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 16056 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 16057 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16058 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 16059 | length, LPFC_SLI4_MBX_EMBED); |
| 16060 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 16061 | wq->queue_id); |
| 16062 | mbox->vport = wq->phba->pport; |
| 16063 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16064 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 16065 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16066 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 16067 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16068 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16069 | if (shdr_status || shdr_add_status || rc) { |
| 16070 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16071 | "2508 WQ_DESTROY mailbox failed with " |
| 16072 | "status x%x add_status x%x, mbx status x%x\n", |
| 16073 | shdr_status, shdr_add_status, rc); |
| 16074 | status = -ENXIO; |
| 16075 | } |
| 16076 | /* Remove wq from any list */ |
| 16077 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 16078 | kfree(wq->pring); |
| 16079 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16080 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16081 | return status; |
| 16082 | } |
| 16083 | |
| 16084 | /** |
| 16085 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 16086 | * @rq: The queue structure associated with the queue to destroy. |
| 16087 | * |
| 16088 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 16089 | * command, specific to the type of queue, to the HBA. |
| 16090 | * |
| 16091 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 16092 | * |
| 16093 | * 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] | 16094 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16095 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16096 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16097 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 16098 | struct lpfc_queue *drq) |
| 16099 | { |
| 16100 | LPFC_MBOXQ_t *mbox; |
| 16101 | int rc, length, status = 0; |
| 16102 | uint32_t shdr_status, shdr_add_status; |
| 16103 | union lpfc_sli4_cfg_shdr *shdr; |
| 16104 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 16105 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16106 | if (!hrq || !drq) |
| 16107 | return -ENODEV; |
| 16108 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 16109 | if (!mbox) |
| 16110 | return -ENOMEM; |
| 16111 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16112 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16113 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16114 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 16115 | length, LPFC_SLI4_MBX_EMBED); |
| 16116 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16117 | hrq->queue_id); |
| 16118 | mbox->vport = hrq->phba->pport; |
| 16119 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 16120 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 16121 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16122 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16123 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16124 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16125 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16126 | if (shdr_status || shdr_add_status || rc) { |
| 16127 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16128 | "2509 RQ_DESTROY mailbox failed with " |
| 16129 | "status x%x add_status x%x, mbx status x%x\n", |
| 16130 | shdr_status, shdr_add_status, rc); |
| 16131 | if (rc != MBX_TIMEOUT) |
| 16132 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 16133 | return -ENXIO; |
| 16134 | } |
| 16135 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 16136 | drq->queue_id); |
| 16137 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 16138 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 16139 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 16140 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16141 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16142 | if (shdr_status || shdr_add_status || rc) { |
| 16143 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16144 | "2510 RQ_DESTROY mailbox failed with " |
| 16145 | "status x%x add_status x%x, mbx status x%x\n", |
| 16146 | shdr_status, shdr_add_status, rc); |
| 16147 | status = -ENXIO; |
| 16148 | } |
| 16149 | list_del_init(&hrq->list); |
| 16150 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16151 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16152 | return status; |
| 16153 | } |
| 16154 | |
| 16155 | /** |
| 16156 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 16157 | * @phba: The virtual port for which this call being executed. |
| 16158 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 16159 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 16160 | * @xritag: the xritag that ties this io to the SGL pages. |
| 16161 | * |
| 16162 | * This routine will post the sgl pages for the IO that has the xritag |
| 16163 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 16164 | * creation and persists for as long as the driver is loaded. |
| 16165 | * if the caller has fewer than 256 scatter gather segments to map then |
| 16166 | * pdma_phys_addr1 should be 0. |
| 16167 | * If the caller needs to map more than 256 scatter gather segment then |
| 16168 | * pdma_phys_addr1 should be a valid physical address. |
| 16169 | * physical address for SGLs must be 64 byte aligned. |
| 16170 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 16171 | * the second sgl can have between 1 and 256 entries. |
| 16172 | * |
| 16173 | * Return codes: |
| 16174 | * 0 - Success |
| 16175 | * -ENXIO, -ENOMEM - Failure |
| 16176 | **/ |
| 16177 | int |
| 16178 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 16179 | dma_addr_t pdma_phys_addr0, |
| 16180 | dma_addr_t pdma_phys_addr1, |
| 16181 | uint16_t xritag) |
| 16182 | { |
| 16183 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 16184 | LPFC_MBOXQ_t *mbox; |
| 16185 | int rc; |
| 16186 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16187 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16188 | union lpfc_sli4_cfg_shdr *shdr; |
| 16189 | |
| 16190 | if (xritag == NO_XRI) { |
| 16191 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16192 | "0364 Invalid param:\n"); |
| 16193 | return -EINVAL; |
| 16194 | } |
| 16195 | |
| 16196 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16197 | if (!mbox) |
| 16198 | return -ENOMEM; |
| 16199 | |
| 16200 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16201 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 16202 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 16203 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16204 | |
| 16205 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 16206 | &mbox->u.mqe.un.post_sgl_pages; |
| 16207 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 16208 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 16209 | |
| 16210 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 16211 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 16212 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 16213 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 16214 | |
| 16215 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 16216 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 16217 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 16218 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 16219 | if (!phba->sli4_hba.intr_enable) |
| 16220 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16221 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16222 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16223 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16224 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16225 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 16226 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 16227 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16228 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16229 | if (rc != MBX_TIMEOUT) |
| 16230 | mempool_free(mbox, phba->mbox_mem_pool); |
| 16231 | if (shdr_status || shdr_add_status || rc) { |
| 16232 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16233 | "2511 POST_SGL mailbox failed with " |
| 16234 | "status x%x add_status x%x, mbx status x%x\n", |
| 16235 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16236 | } |
| 16237 | return 0; |
| 16238 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16239 | |
| 16240 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16241 | * 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] | 16242 | * @phba: pointer to lpfc hba data structure. |
| 16243 | * |
| 16244 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16245 | * HBA consistent with the SLI-4 interface spec. This routine |
| 16246 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 16247 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16248 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 16249 | * Returns |
| 16250 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 16251 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 16252 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16253 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16254 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 16255 | { |
| 16256 | unsigned long xri; |
| 16257 | |
| 16258 | /* |
| 16259 | * Fetch the next logical xri. Because this index is logical, |
| 16260 | * the driver starts at 0 each time. |
| 16261 | */ |
| 16262 | spin_lock_irq(&phba->hbalock); |
| 16263 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 16264 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 16265 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 16266 | spin_unlock_irq(&phba->hbalock); |
| 16267 | return NO_XRI; |
| 16268 | } else { |
| 16269 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 16270 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16271 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16272 | spin_unlock_irq(&phba->hbalock); |
| 16273 | return xri; |
| 16274 | } |
| 16275 | |
| 16276 | /** |
| 16277 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16278 | * @phba: pointer to lpfc hba data structure. |
| 16279 | * |
| 16280 | * This routine is invoked to release an xri to the pool of |
| 16281 | * available rpis maintained by the driver. |
| 16282 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16283 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16284 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16285 | { |
| 16286 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16287 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 16288 | } |
| 16289 | } |
| 16290 | |
| 16291 | /** |
| 16292 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16293 | * @phba: pointer to lpfc hba data structure. |
| 16294 | * |
| 16295 | * This routine is invoked to release an xri to the pool of |
| 16296 | * available rpis maintained by the driver. |
| 16297 | **/ |
| 16298 | void |
| 16299 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16300 | { |
| 16301 | spin_lock_irq(&phba->hbalock); |
| 16302 | __lpfc_sli4_free_xri(phba, xri); |
| 16303 | spin_unlock_irq(&phba->hbalock); |
| 16304 | } |
| 16305 | |
| 16306 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16307 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 16308 | * @phba: Pointer to HBA context object. |
| 16309 | * |
| 16310 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 16311 | * it will return 0xffff. |
| 16312 | * The function returns the allocated xritag if successful, else returns zero. |
| 16313 | * Zero is not a valid xritag. |
| 16314 | * The caller is not required to hold any lock. |
| 16315 | **/ |
| 16316 | uint16_t |
| 16317 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 16318 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16319 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16320 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16321 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 16322 | if (xri_index == NO_XRI) |
| 16323 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 16324 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 16325 | " Max XRI is %d, Used XRI is %d\n", |
| 16326 | xri_index, |
| 16327 | phba->sli4_hba.max_cfg_param.max_xri, |
| 16328 | phba->sli4_hba.max_cfg_param.xri_used); |
| 16329 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16330 | } |
| 16331 | |
| 16332 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16333 | * 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] | 16334 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16335 | * @post_sgl_list: pointer to els sgl entry list. |
| 16336 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16337 | * |
| 16338 | * This routine is invoked to post a block of driver's sgl pages to the |
| 16339 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 16340 | * is only called when the driver is loading and after all IO has been |
| 16341 | * stopped. |
| 16342 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16343 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16344 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16345 | struct list_head *post_sgl_list, |
| 16346 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16347 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16348 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16349 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16350 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16351 | void *viraddr; |
| 16352 | LPFC_MBOXQ_t *mbox; |
| 16353 | uint32_t reqlen, alloclen, pg_pairs; |
| 16354 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16355 | uint16_t xritag_start = 0; |
| 16356 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16357 | uint32_t shdr_status, shdr_add_status; |
| 16358 | union lpfc_sli4_cfg_shdr *shdr; |
| 16359 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16360 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16361 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16362 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16363 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16364 | "2559 Block sgl registration required DMA " |
| 16365 | "size (%d) great than a page\n", reqlen); |
| 16366 | return -ENOMEM; |
| 16367 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16368 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16369 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16370 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16371 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16372 | |
| 16373 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16374 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16375 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16376 | LPFC_SLI4_MBX_NEMBED); |
| 16377 | |
| 16378 | if (alloclen < reqlen) { |
| 16379 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16380 | "0285 Allocated DMA memory size (%d) is " |
| 16381 | "less than the requested DMA memory " |
| 16382 | "size (%d)\n", alloclen, reqlen); |
| 16383 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16384 | return -ENOMEM; |
| 16385 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16386 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16387 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16388 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16389 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16390 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16391 | pg_pairs = 0; |
| 16392 | 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] | 16393 | /* Set up the sge entry */ |
| 16394 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16395 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 16396 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16397 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 16398 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16399 | cpu_to_le32(putPaddrLow(0)); |
| 16400 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16401 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16402 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16403 | /* Keep the first xritag on the list */ |
| 16404 | if (pg_pairs == 0) |
| 16405 | xritag_start = sglq_entry->sli4_xritag; |
| 16406 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16407 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16408 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16409 | |
| 16410 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16411 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16412 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16413 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16414 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16415 | if (!phba->sli4_hba.intr_enable) |
| 16416 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16417 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16418 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16419 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16420 | } |
| 16421 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16422 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16423 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16424 | if (rc != MBX_TIMEOUT) |
| 16425 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16426 | if (shdr_status || shdr_add_status || rc) { |
| 16427 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16428 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 16429 | "status x%x add_status x%x mbx status x%x\n", |
| 16430 | shdr_status, shdr_add_status, rc); |
| 16431 | rc = -ENXIO; |
| 16432 | } |
| 16433 | return rc; |
| 16434 | } |
| 16435 | |
| 16436 | /** |
| 16437 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 16438 | * @phba: pointer to lpfc hba data structure. |
| 16439 | * @sblist: pointer to scsi buffer list. |
| 16440 | * @count: number of scsi buffers on the list. |
| 16441 | * |
| 16442 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 16443 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 16444 | * No Lock is held. |
| 16445 | * |
| 16446 | **/ |
| 16447 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16448 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 16449 | struct list_head *sblist, |
| 16450 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16451 | { |
| 16452 | struct lpfc_scsi_buf *psb; |
| 16453 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16454 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16455 | void *viraddr; |
| 16456 | LPFC_MBOXQ_t *mbox; |
| 16457 | uint32_t reqlen, alloclen, pg_pairs; |
| 16458 | uint32_t mbox_tmo; |
| 16459 | uint16_t xritag_start = 0; |
| 16460 | int rc = 0; |
| 16461 | uint32_t shdr_status, shdr_add_status; |
| 16462 | dma_addr_t pdma_phys_bpl1; |
| 16463 | union lpfc_sli4_cfg_shdr *shdr; |
| 16464 | |
| 16465 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16466 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16467 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16468 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16469 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 16470 | "0217 Block sgl registration required DMA " |
| 16471 | "size (%d) great than a page\n", reqlen); |
| 16472 | return -ENOMEM; |
| 16473 | } |
| 16474 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16475 | if (!mbox) { |
| 16476 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16477 | "0283 Failed to allocate mbox cmd memory\n"); |
| 16478 | return -ENOMEM; |
| 16479 | } |
| 16480 | |
| 16481 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16482 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16483 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16484 | LPFC_SLI4_MBX_NEMBED); |
| 16485 | |
| 16486 | if (alloclen < reqlen) { |
| 16487 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16488 | "2561 Allocated DMA memory size (%d) is " |
| 16489 | "less than the requested DMA memory " |
| 16490 | "size (%d)\n", alloclen, reqlen); |
| 16491 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16492 | return -ENOMEM; |
| 16493 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16494 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16495 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16496 | viraddr = mbox->sge_array->addr[0]; |
| 16497 | |
| 16498 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 16499 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16500 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16501 | |
| 16502 | pg_pairs = 0; |
| 16503 | list_for_each_entry(psb, sblist, list) { |
| 16504 | /* Set up the sge entry */ |
| 16505 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16506 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 16507 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16508 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 16509 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 16510 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 16511 | else |
| 16512 | pdma_phys_bpl1 = 0; |
| 16513 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16514 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 16515 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16516 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 16517 | /* Keep the first xritag on the list */ |
| 16518 | if (pg_pairs == 0) |
| 16519 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 16520 | sgl_pg_pairs++; |
| 16521 | pg_pairs++; |
| 16522 | } |
| 16523 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 16524 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 16525 | /* Perform endian conversion if necessary */ |
| 16526 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 16527 | |
| 16528 | if (!phba->sli4_hba.intr_enable) |
| 16529 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16530 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16531 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16532 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16533 | } |
| 16534 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16535 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16536 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16537 | if (rc != MBX_TIMEOUT) |
| 16538 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16539 | if (shdr_status || shdr_add_status || rc) { |
| 16540 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16541 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 16542 | "status x%x add_status x%x mbx status x%x\n", |
| 16543 | shdr_status, shdr_add_status, rc); |
| 16544 | rc = -ENXIO; |
| 16545 | } |
| 16546 | return rc; |
| 16547 | } |
| 16548 | |
| 16549 | /** |
| 16550 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 16551 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 16552 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16553 | * |
| 16554 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 16555 | * valid type of frame that the LPFC driver will handle. This function will |
| 16556 | * return a zero if the frame is a valid frame or a non zero value when the |
| 16557 | * frame does not pass the check. |
| 16558 | **/ |
| 16559 | static int |
| 16560 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 16561 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 16562 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16563 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16564 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16565 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16566 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 16567 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16568 | switch (fc_hdr->fh_r_ctl) { |
| 16569 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 16570 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 16571 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 16572 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 16573 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 16574 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 16575 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 16576 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 16577 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 16578 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 16579 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 16580 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 16581 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 16582 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 16583 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 16584 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 16585 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 16586 | case FC_RCTL_BA_PRMT: |
| 16587 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 16588 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 16589 | case FC_RCTL_P_RJT: /* port reject */ |
| 16590 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 16591 | case FC_RCTL_P_BSY: /* port busy */ |
| 16592 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 16593 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 16594 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16595 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16596 | case FC_RCTL_END: /* end */ |
| 16597 | break; |
| 16598 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 16599 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16600 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 16601 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 16602 | default: |
| 16603 | goto drop; |
| 16604 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16605 | |
| 16606 | #define FC_TYPE_VENDOR_UNIQUE 0xFF |
| 16607 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16608 | switch (fc_hdr->fh_type) { |
| 16609 | case FC_TYPE_BLS: |
| 16610 | case FC_TYPE_ELS: |
| 16611 | case FC_TYPE_FCP: |
| 16612 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16613 | case FC_TYPE_NVME: |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16614 | case FC_TYPE_VENDOR_UNIQUE: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16615 | break; |
| 16616 | case FC_TYPE_IP: |
| 16617 | case FC_TYPE_ILS: |
| 16618 | default: |
| 16619 | goto drop; |
| 16620 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16621 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16622 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16623 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 16624 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16625 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 16626 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 16627 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 16628 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 16629 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16630 | return 0; |
| 16631 | drop: |
| 16632 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16633 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 16634 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16635 | return 1; |
| 16636 | } |
| 16637 | |
| 16638 | /** |
| 16639 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 16640 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16641 | * |
| 16642 | * This function processes the FC header to retrieve the VFI from the VF |
| 16643 | * header, if one exists. This function will return the VFI if one exists |
| 16644 | * or 0 if no VSAN Header exists. |
| 16645 | **/ |
| 16646 | static uint32_t |
| 16647 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 16648 | { |
| 16649 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16650 | |
| 16651 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 16652 | return 0; |
| 16653 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 16654 | } |
| 16655 | |
| 16656 | /** |
| 16657 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 16658 | * @phba: Pointer to the HBA structure to search for the vport on |
| 16659 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16660 | * @fcfi: The FC Fabric ID that the frame came from |
| 16661 | * |
| 16662 | * This function searches the @phba for a vport that matches the content of the |
| 16663 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 16664 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 16665 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 16666 | * vport. |
| 16667 | **/ |
| 16668 | static struct lpfc_vport * |
| 16669 | 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] | 16670 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16671 | { |
| 16672 | struct lpfc_vport **vports; |
| 16673 | struct lpfc_vport *vport = NULL; |
| 16674 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16675 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 16676 | if (did == Fabric_DID) |
| 16677 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16678 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 16679 | !(phba->link_state == LPFC_HBA_READY)) |
| 16680 | return phba->pport; |
| 16681 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16682 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16683 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16684 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 16685 | if (phba->fcf.fcfi == fcfi && |
| 16686 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 16687 | vports[i]->fc_myDID == did) { |
| 16688 | vport = vports[i]; |
| 16689 | break; |
| 16690 | } |
| 16691 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16692 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16693 | lpfc_destroy_vport_work_array(phba, vports); |
| 16694 | return vport; |
| 16695 | } |
| 16696 | |
| 16697 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16698 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 16699 | * @vport: The vport to work on. |
| 16700 | * |
| 16701 | * This function updates the receive sequence time stamp for this vport. The |
| 16702 | * receive sequence time stamp indicates the time that the last frame of the |
| 16703 | * the sequence that has been idle for the longest amount of time was received. |
| 16704 | * the driver uses this time stamp to indicate if any received sequences have |
| 16705 | * timed out. |
| 16706 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16707 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16708 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 16709 | { |
| 16710 | struct lpfc_dmabuf *h_buf; |
| 16711 | struct hbq_dmabuf *dmabuf = NULL; |
| 16712 | |
| 16713 | /* get the oldest sequence on the rcv list */ |
| 16714 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 16715 | struct lpfc_dmabuf, list); |
| 16716 | if (!h_buf) |
| 16717 | return; |
| 16718 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16719 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 16720 | } |
| 16721 | |
| 16722 | /** |
| 16723 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 16724 | * @vport: The vport that the received sequences were sent to. |
| 16725 | * |
| 16726 | * This function cleans up all outstanding received sequences. This is called |
| 16727 | * by the driver when a link event or user action invalidates all the received |
| 16728 | * sequences. |
| 16729 | **/ |
| 16730 | void |
| 16731 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 16732 | { |
| 16733 | struct lpfc_dmabuf *h_buf, *hnext; |
| 16734 | struct lpfc_dmabuf *d_buf, *dnext; |
| 16735 | struct hbq_dmabuf *dmabuf = NULL; |
| 16736 | |
| 16737 | /* start with the oldest sequence on the rcv list */ |
| 16738 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 16739 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16740 | list_del_init(&dmabuf->hbuf.list); |
| 16741 | list_for_each_entry_safe(d_buf, dnext, |
| 16742 | &dmabuf->dbuf.list, list) { |
| 16743 | list_del_init(&d_buf->list); |
| 16744 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16745 | } |
| 16746 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 16747 | } |
| 16748 | } |
| 16749 | |
| 16750 | /** |
| 16751 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 16752 | * @vport: The vport that the received sequences were sent to. |
| 16753 | * |
| 16754 | * This function determines whether any received sequences have timed out by |
| 16755 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 16756 | * indicates that there is at least one timed out sequence this routine will |
| 16757 | * go through the received sequences one at a time from most inactive to most |
| 16758 | * active to determine which ones need to be cleaned up. Once it has determined |
| 16759 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 16760 | * without sending an abort. |
| 16761 | **/ |
| 16762 | void |
| 16763 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 16764 | { |
| 16765 | struct lpfc_dmabuf *h_buf, *hnext; |
| 16766 | struct lpfc_dmabuf *d_buf, *dnext; |
| 16767 | struct hbq_dmabuf *dmabuf = NULL; |
| 16768 | unsigned long timeout; |
| 16769 | int abort_count = 0; |
| 16770 | |
| 16771 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 16772 | vport->rcv_buffer_time_stamp); |
| 16773 | if (list_empty(&vport->rcv_buffer_list) || |
| 16774 | time_before(jiffies, timeout)) |
| 16775 | return; |
| 16776 | /* start with the oldest sequence on the rcv list */ |
| 16777 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 16778 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16779 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 16780 | dmabuf->time_stamp); |
| 16781 | if (time_before(jiffies, timeout)) |
| 16782 | break; |
| 16783 | abort_count++; |
| 16784 | list_del_init(&dmabuf->hbuf.list); |
| 16785 | list_for_each_entry_safe(d_buf, dnext, |
| 16786 | &dmabuf->dbuf.list, list) { |
| 16787 | list_del_init(&d_buf->list); |
| 16788 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16789 | } |
| 16790 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 16791 | } |
| 16792 | if (abort_count) |
| 16793 | lpfc_update_rcv_time_stamp(vport); |
| 16794 | } |
| 16795 | |
| 16796 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16797 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 16798 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 16799 | * |
| 16800 | * This function searches through the existing incomplete sequences that have |
| 16801 | * been sent to this @vport. If the frame matches one of the incomplete |
| 16802 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 16803 | * make up that sequence. If no sequence is found that matches this frame then |
| 16804 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 16805 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 16806 | * the frame was linked to. |
| 16807 | **/ |
| 16808 | static struct hbq_dmabuf * |
| 16809 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 16810 | { |
| 16811 | struct fc_frame_header *new_hdr; |
| 16812 | struct fc_frame_header *temp_hdr; |
| 16813 | struct lpfc_dmabuf *d_buf; |
| 16814 | struct lpfc_dmabuf *h_buf; |
| 16815 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 16816 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16817 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16818 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16819 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16820 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16821 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16822 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16823 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 16824 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 16825 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 16826 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 16827 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 16828 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 16829 | continue; |
| 16830 | /* found a pending sequence that matches this frame */ |
| 16831 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16832 | break; |
| 16833 | } |
| 16834 | if (!seq_dmabuf) { |
| 16835 | /* |
| 16836 | * This indicates first frame received for this sequence. |
| 16837 | * Queue the buffer on the vport's rcv_buffer_list. |
| 16838 | */ |
| 16839 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16840 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16841 | return dmabuf; |
| 16842 | } |
| 16843 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16844 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 16845 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16846 | list_del_init(&seq_dmabuf->hbuf.list); |
| 16847 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 16848 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16849 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16850 | return dmabuf; |
| 16851 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16852 | /* move this sequence to the tail to indicate a young sequence */ |
| 16853 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 16854 | seq_dmabuf->time_stamp = jiffies; |
| 16855 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16856 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 16857 | temp_hdr = dmabuf->hbuf.virt; |
| 16858 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 16859 | return seq_dmabuf; |
| 16860 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16861 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16862 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 16863 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16864 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 16865 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 16866 | /* |
| 16867 | * If the frame's sequence count is greater than the frame on |
| 16868 | * the list then insert the frame right after this frame |
| 16869 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16870 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 16871 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16872 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16873 | found = 1; |
| 16874 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16875 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16876 | |
| 16877 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 16878 | break; |
| 16879 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16880 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16881 | |
| 16882 | if (found) |
| 16883 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16884 | return NULL; |
| 16885 | } |
| 16886 | |
| 16887 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16888 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 16889 | * @vport: pointer to a vitural port |
| 16890 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16891 | * |
| 16892 | * This function tries to abort from the partially assembed sequence, described |
| 16893 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 16894 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 16895 | * the frames from the partially assembled sequence. |
| 16896 | * |
| 16897 | * Return |
| 16898 | * true -- if there is matching partially assembled sequence present and all |
| 16899 | * the frames freed with the sequence; |
| 16900 | * false -- if there is no matching partially assembled sequence present so |
| 16901 | * nothing got aborted in the lower layer driver |
| 16902 | **/ |
| 16903 | static bool |
| 16904 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 16905 | struct hbq_dmabuf *dmabuf) |
| 16906 | { |
| 16907 | struct fc_frame_header *new_hdr; |
| 16908 | struct fc_frame_header *temp_hdr; |
| 16909 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 16910 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 16911 | |
| 16912 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 16913 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 16914 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 16915 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 16916 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 16917 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 16918 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 16919 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 16920 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 16921 | continue; |
| 16922 | /* found a pending sequence that matches this frame */ |
| 16923 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16924 | break; |
| 16925 | } |
| 16926 | |
| 16927 | /* Free up all the frames from the partially assembled sequence */ |
| 16928 | if (seq_dmabuf) { |
| 16929 | list_for_each_entry_safe(d_buf, n_buf, |
| 16930 | &seq_dmabuf->dbuf.list, list) { |
| 16931 | list_del_init(&d_buf->list); |
| 16932 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16933 | } |
| 16934 | return true; |
| 16935 | } |
| 16936 | return false; |
| 16937 | } |
| 16938 | |
| 16939 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16940 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 16941 | * @vport: pointer to a vitural port |
| 16942 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16943 | * |
| 16944 | * This function tries to abort from the assembed sequence from upper level |
| 16945 | * protocol, described by the information from basic abbort @dmabuf. It |
| 16946 | * checks to see whether such pending context exists at upper level protocol. |
| 16947 | * If so, it shall clean up the pending context. |
| 16948 | * |
| 16949 | * Return |
| 16950 | * true -- if there is matching pending context of the sequence cleaned |
| 16951 | * at ulp; |
| 16952 | * false -- if there is no matching pending context of the sequence present |
| 16953 | * at ulp. |
| 16954 | **/ |
| 16955 | static bool |
| 16956 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 16957 | { |
| 16958 | struct lpfc_hba *phba = vport->phba; |
| 16959 | int handled; |
| 16960 | |
| 16961 | /* Accepting abort at ulp with SLI4 only */ |
| 16962 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 16963 | return false; |
| 16964 | |
| 16965 | /* Register all caring upper level protocols to attend abort */ |
| 16966 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 16967 | if (handled) |
| 16968 | return true; |
| 16969 | |
| 16970 | return false; |
| 16971 | } |
| 16972 | |
| 16973 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16974 | * 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] | 16975 | * @phba: Pointer to HBA context object. |
| 16976 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 16977 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 16978 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16979 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16980 | * event. It properly releases the memory allocated to the sequence abort |
| 16981 | * accept iocb. |
| 16982 | **/ |
| 16983 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16984 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16985 | struct lpfc_iocbq *cmd_iocbq, |
| 16986 | struct lpfc_iocbq *rsp_iocbq) |
| 16987 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16988 | struct lpfc_nodelist *ndlp; |
| 16989 | |
| 16990 | if (cmd_iocbq) { |
| 16991 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 16992 | lpfc_nlp_put(ndlp); |
| 16993 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16994 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16995 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 16996 | |
| 16997 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 16998 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 16999 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17000 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 17001 | rsp_iocbq->iocb.ulpStatus, |
| 17002 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17003 | } |
| 17004 | |
| 17005 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17006 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 17007 | * @phba: Pointer to HBA context object. |
| 17008 | * @xri: xri id in transaction. |
| 17009 | * |
| 17010 | * This function validates the xri maps to the known range of XRIs allocated an |
| 17011 | * used by the driver. |
| 17012 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17013 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17014 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 17015 | uint16_t xri) |
| 17016 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 17017 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17018 | |
| 17019 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 17020 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 17021 | return i; |
| 17022 | } |
| 17023 | return NO_XRI; |
| 17024 | } |
| 17025 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17026 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17027 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17028 | * @phba: Pointer to HBA context object. |
| 17029 | * @fc_hdr: pointer to a FC frame header. |
| 17030 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17031 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17032 | * event after aborting the sequence handling. |
| 17033 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17034 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17035 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 17036 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17037 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17038 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17039 | struct lpfc_iocbq *ctiocb = NULL; |
| 17040 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17041 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17042 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17043 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17044 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17045 | |
| 17046 | if (!lpfc_is_link_up(phba)) |
| 17047 | return; |
| 17048 | |
| 17049 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 17050 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17051 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17052 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17053 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17054 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 17055 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17056 | if (!ndlp) { |
| 17057 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17058 | "1268 Failed to allocate ndlp for " |
| 17059 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 17060 | return; |
| 17061 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17062 | /* Put ndlp onto pport node list */ |
| 17063 | lpfc_enqueue_node(vport, ndlp); |
| 17064 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 17065 | /* re-setup ndlp without removing from node list */ |
| 17066 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 17067 | if (!ndlp) { |
| 17068 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 17069 | "3275 Failed to active ndlp found " |
| 17070 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 17071 | return; |
| 17072 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17073 | } |
| 17074 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17075 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17076 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 17077 | if (!ctiocb) |
| 17078 | return; |
| 17079 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17080 | /* Extract the F_CTL field from FC_HDR */ |
| 17081 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 17082 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17083 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17084 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17085 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17086 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 17087 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 17088 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 17089 | |
| 17090 | /* Fill in the rest of iocb fields */ |
| 17091 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 17092 | icmd->ulpBdeCount = 0; |
| 17093 | icmd->ulpLe = 1; |
| 17094 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17095 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17096 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17097 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17098 | ctiocb->iocb_cmpl = NULL; |
| 17099 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17100 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17101 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17102 | ctiocb->sli4_xritag = NO_XRI; |
| 17103 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 17104 | if (fctl & FC_FC_EX_CTX) |
| 17105 | /* Exchange responder sent the abort so we |
| 17106 | * own the oxid. |
| 17107 | */ |
| 17108 | xri = oxid; |
| 17109 | else |
| 17110 | xri = rxid; |
| 17111 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 17112 | if (lxri != NO_XRI) |
| 17113 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 17114 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17115 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 17116 | * the oxid maps to the FCP XRI range, the port no longer has |
| 17117 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 17118 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17119 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17120 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17121 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17122 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17123 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17124 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17125 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17126 | } |
| 17127 | |
| 17128 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 17129 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 17130 | * the IOCB for a BA_RJT. |
| 17131 | */ |
| 17132 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17133 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 17134 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 17135 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 17136 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 17137 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17138 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17139 | if (fctl & FC_FC_EX_CTX) { |
| 17140 | /* ABTS sent by responder to CT exchange, construction |
| 17141 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 17142 | * field and RX_ID from ABTS for RX_ID field. |
| 17143 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17144 | 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] | 17145 | } else { |
| 17146 | /* ABTS sent by initiator to CT exchange, construction |
| 17147 | * 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] | 17148 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17149 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17150 | 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] | 17151 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 17152 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17153 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17154 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17155 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17156 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 17157 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 17158 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17159 | |
| 17160 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 17161 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17162 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 17163 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 17164 | "xri x%x, Data x%x\n", |
| 17165 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 17166 | phba->link_state); |
| 17167 | lpfc_nlp_put(ndlp); |
| 17168 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 17169 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 17170 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17171 | } |
| 17172 | |
| 17173 | /** |
| 17174 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 17175 | * @vport: Pointer to the vport on which this sequence was received |
| 17176 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17177 | * |
| 17178 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 17179 | * receive sequence is only partially assembed by the driver, it shall abort |
| 17180 | * the partially assembled frames for the sequence. Otherwise, if the |
| 17181 | * unsolicited receive sequence has been completely assembled and passed to |
| 17182 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 17183 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 17184 | * accept to accept the abort. |
| 17185 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17186 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17187 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 17188 | struct hbq_dmabuf *dmabuf) |
| 17189 | { |
| 17190 | struct lpfc_hba *phba = vport->phba; |
| 17191 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17192 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17193 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17194 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17195 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 17196 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17197 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17198 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17199 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17200 | /* ABTS by responder to exchange, no cleanup needed */ |
| 17201 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17202 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17203 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 17204 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 17205 | if (aborted == false) |
| 17206 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 17207 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17208 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17209 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 17210 | if (phba->nvmet_support) { |
| 17211 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 17212 | return; |
| 17213 | } |
| 17214 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 17215 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 17216 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17217 | } |
| 17218 | |
| 17219 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17220 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 17221 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17222 | * |
| 17223 | * This function checks the sequence, starting with the frame described by |
| 17224 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 17225 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 17226 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 17227 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 17228 | * set. 3) That there are no holes in the sequence count. The function will |
| 17229 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 17230 | **/ |
| 17231 | static int |
| 17232 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 17233 | { |
| 17234 | struct fc_frame_header *hdr; |
| 17235 | struct lpfc_dmabuf *d_buf; |
| 17236 | struct hbq_dmabuf *seq_dmabuf; |
| 17237 | uint32_t fctl; |
| 17238 | int seq_count = 0; |
| 17239 | |
| 17240 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17241 | /* make sure first fame of sequence has a sequence count of zero */ |
| 17242 | if (hdr->fh_seq_cnt != seq_count) |
| 17243 | return 0; |
| 17244 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17245 | hdr->fh_f_ctl[1] << 8 | |
| 17246 | hdr->fh_f_ctl[2]); |
| 17247 | /* If last frame of sequence we can return success. */ |
| 17248 | if (fctl & FC_FC_END_SEQ) |
| 17249 | return 1; |
| 17250 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 17251 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17252 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17253 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17254 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17255 | return 0; |
| 17256 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 17257 | hdr->fh_f_ctl[1] << 8 | |
| 17258 | hdr->fh_f_ctl[2]); |
| 17259 | /* If last frame of sequence we can return success. */ |
| 17260 | if (fctl & FC_FC_END_SEQ) |
| 17261 | return 1; |
| 17262 | } |
| 17263 | return 0; |
| 17264 | } |
| 17265 | |
| 17266 | /** |
| 17267 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 17268 | * @vport: Pointer to the vport on which this sequence was received |
| 17269 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 17270 | * |
| 17271 | * This function takes a sequence, described by a list of frames, and creates |
| 17272 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 17273 | * used to issue to the generic unsolicited sequence handler. This routine |
| 17274 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 17275 | * to allocate an iocbq then it throw out the received frames that were not |
| 17276 | * able to be described and return a pointer to the first iocbq. If unable to |
| 17277 | * allocate any iocbqs (including the first) this function will return NULL. |
| 17278 | **/ |
| 17279 | static struct lpfc_iocbq * |
| 17280 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 17281 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17282 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17283 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 17284 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 17285 | struct fc_frame_header *fc_hdr; |
| 17286 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17287 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17288 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17289 | |
| 17290 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17291 | /* remove from receive buffer list */ |
| 17292 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17293 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17294 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17295 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17296 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17297 | /* Get an iocbq struct to fill in. */ |
| 17298 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17299 | if (first_iocbq) { |
| 17300 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17301 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17302 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17303 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17304 | |
| 17305 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 17306 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 17307 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 17308 | first_iocbq->iocb.un.rcvels.parmRo = |
| 17309 | sli4_did_from_fc_hdr(fc_hdr); |
| 17310 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 17311 | } else |
| 17312 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17313 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 17314 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 17315 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 17316 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 17317 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 17318 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17319 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17320 | tot_len = bf_get(lpfc_rcqe_length, |
| 17321 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17322 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17323 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 17324 | first_iocbq->context3 = NULL; |
| 17325 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17326 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 17327 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17328 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17329 | else |
| 17330 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 17331 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17332 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17333 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17334 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17335 | } |
| 17336 | iocbq = first_iocbq; |
| 17337 | /* |
| 17338 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 17339 | * of buffers for this sequence and save two buffers in each IOCBq |
| 17340 | */ |
| 17341 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 17342 | if (!iocbq) { |
| 17343 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17344 | continue; |
| 17345 | } |
| 17346 | if (!iocbq->context3) { |
| 17347 | iocbq->context3 = d_buf; |
| 17348 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17349 | /* We need to get the size out of the right CQE */ |
| 17350 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17351 | len = bf_get(lpfc_rcqe_length, |
| 17352 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17353 | pbde = (struct ulp_bde64 *) |
| 17354 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 17355 | if (len > LPFC_DATA_BUF_SIZE) |
| 17356 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 17357 | else |
| 17358 | pbde->tus.f.bdeSize = len; |
| 17359 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17360 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 17361 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17362 | } else { |
| 17363 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17364 | if (!iocbq) { |
| 17365 | if (first_iocbq) { |
| 17366 | first_iocbq->iocb.ulpStatus = |
| 17367 | IOSTAT_FCP_RSP_ERROR; |
| 17368 | first_iocbq->iocb.un.ulpWord[4] = |
| 17369 | IOERR_NO_RESOURCES; |
| 17370 | } |
| 17371 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17372 | continue; |
| 17373 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17374 | /* We need to get the size out of the right CQE */ |
| 17375 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17376 | len = bf_get(lpfc_rcqe_length, |
| 17377 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17378 | iocbq->context2 = d_buf; |
| 17379 | iocbq->context3 = NULL; |
| 17380 | iocbq->iocb.ulpBdeCount = 1; |
| 17381 | if (len > LPFC_DATA_BUF_SIZE) |
| 17382 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 17383 | LPFC_DATA_BUF_SIZE; |
| 17384 | else |
| 17385 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 17386 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17387 | tot_len += len; |
| 17388 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 17389 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17390 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 17391 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 17392 | } |
| 17393 | } |
| 17394 | return first_iocbq; |
| 17395 | } |
| 17396 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17397 | static void |
| 17398 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 17399 | struct hbq_dmabuf *seq_dmabuf) |
| 17400 | { |
| 17401 | struct fc_frame_header *fc_hdr; |
| 17402 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 17403 | struct lpfc_hba *phba = vport->phba; |
| 17404 | |
| 17405 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17406 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 17407 | if (!iocbq) { |
| 17408 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17409 | "2707 Ring %d handler: Failed to allocate " |
| 17410 | "iocb Rctl x%x Type x%x received\n", |
| 17411 | LPFC_ELS_RING, |
| 17412 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17413 | return; |
| 17414 | } |
| 17415 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17416 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17417 | iocbq, fc_hdr->fh_r_ctl, |
| 17418 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17419 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17420 | "2540 Ring %d handler: unexpected Rctl " |
| 17421 | "x%x Type x%x received\n", |
| 17422 | LPFC_ELS_RING, |
| 17423 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17424 | |
| 17425 | /* Free iocb created in lpfc_prep_seq */ |
| 17426 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 17427 | &iocbq->list, list) { |
| 17428 | list_del_init(&curr_iocb->list); |
| 17429 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 17430 | } |
| 17431 | lpfc_sli_release_iocbq(phba, iocbq); |
| 17432 | } |
| 17433 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17434 | static void |
| 17435 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 17436 | struct lpfc_iocbq *rspiocb) |
| 17437 | { |
| 17438 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 17439 | |
| 17440 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17441 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17442 | kfree(pcmd); |
| 17443 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 17444 | } |
| 17445 | |
| 17446 | static void |
| 17447 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 17448 | struct hbq_dmabuf *dmabuf) |
| 17449 | { |
| 17450 | struct fc_frame_header *fc_hdr; |
| 17451 | struct lpfc_hba *phba = vport->phba; |
| 17452 | struct lpfc_iocbq *iocbq = NULL; |
| 17453 | union lpfc_wqe *wqe; |
| 17454 | struct lpfc_dmabuf *pcmd = NULL; |
| 17455 | uint32_t frame_len; |
| 17456 | int rc; |
| 17457 | |
| 17458 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17459 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17460 | |
| 17461 | /* Send the received frame back */ |
| 17462 | iocbq = lpfc_sli_get_iocbq(phba); |
| 17463 | if (!iocbq) |
| 17464 | goto exit; |
| 17465 | |
| 17466 | /* Allocate buffer for command payload */ |
| 17467 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 17468 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17469 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17470 | &pcmd->phys); |
| 17471 | if (!pcmd || !pcmd->virt) |
| 17472 | goto exit; |
| 17473 | |
| 17474 | INIT_LIST_HEAD(&pcmd->list); |
| 17475 | |
| 17476 | /* copyin the payload */ |
| 17477 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 17478 | |
| 17479 | /* fill in BDE's for command */ |
| 17480 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 17481 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 17482 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 17483 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 17484 | |
| 17485 | iocbq->context2 = pcmd; |
| 17486 | iocbq->vport = vport; |
| 17487 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 17488 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 17489 | |
| 17490 | /* |
| 17491 | * Setup rest of the iocb as though it were a WQE |
| 17492 | * Build the SEND_FRAME WQE |
| 17493 | */ |
| 17494 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 17495 | |
| 17496 | wqe->send_frame.frame_len = frame_len; |
| 17497 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 17498 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 17499 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 17500 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 17501 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 17502 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 17503 | |
| 17504 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 17505 | iocbq->iocb.ulpLe = 1; |
| 17506 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 17507 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 17508 | if (rc == IOCB_ERROR) |
| 17509 | goto exit; |
| 17510 | |
| 17511 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17512 | return; |
| 17513 | |
| 17514 | exit: |
| 17515 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 17516 | "2023 Unable to process MDS loopback frame\n"); |
| 17517 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17518 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17519 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 17520 | if (iocbq) |
| 17521 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17522 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17523 | } |
| 17524 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17525 | /** |
| 17526 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 17527 | * @phba: Pointer to HBA context object. |
| 17528 | * |
| 17529 | * This function is called with no lock held. This function processes all |
| 17530 | * the received buffers and gives it to upper layers when a received buffer |
| 17531 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17532 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17533 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 17534 | * appropriate receive function when the final frame in a sequence is received. |
| 17535 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17536 | void |
| 17537 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 17538 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17539 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17540 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17541 | struct fc_frame_header *fc_hdr; |
| 17542 | struct lpfc_vport *vport; |
| 17543 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17544 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17545 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17546 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17547 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17548 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17549 | /* check to see if this a valid type of frame */ |
| 17550 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 17551 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17552 | return; |
| 17553 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17554 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17555 | if ((bf_get(lpfc_cqe_code, |
| 17556 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 17557 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 17558 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17559 | else |
| 17560 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 17561 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17562 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17563 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
| 17564 | vport = phba->pport; |
| 17565 | /* Handle MDS Loopback frames */ |
| 17566 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 17567 | return; |
| 17568 | } |
| 17569 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17570 | /* d_id this frame is directed to */ |
| 17571 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 17572 | |
| 17573 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17574 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17575 | /* throw out the frame */ |
| 17576 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17577 | return; |
| 17578 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17579 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17580 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 17581 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 17582 | (did != Fabric_DID)) { |
| 17583 | /* |
| 17584 | * Throw out the frame if we are not pt2pt. |
| 17585 | * The pt2pt protocol allows for discovery frames |
| 17586 | * to be received without a registered VPI. |
| 17587 | */ |
| 17588 | if (!(vport->fc_flag & FC_PT2PT) || |
| 17589 | (phba->link_state == LPFC_HBA_READY)) { |
| 17590 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17591 | return; |
| 17592 | } |
| 17593 | } |
| 17594 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17595 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 17596 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 17597 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 17598 | return; |
| 17599 | } |
| 17600 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17601 | /* Link this frame */ |
| 17602 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 17603 | if (!seq_dmabuf) { |
| 17604 | /* unable to add frame to vport - throw it out */ |
| 17605 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17606 | return; |
| 17607 | } |
| 17608 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17609 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17610 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17611 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17612 | /* Send the complete sequence to the upper layer protocol */ |
| 17613 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17614 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17615 | |
| 17616 | /** |
| 17617 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 17618 | * @phba: pointer to lpfc hba data structure. |
| 17619 | * |
| 17620 | * This routine is invoked to post rpi header templates to the |
| 17621 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17622 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17623 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17624 | * |
| 17625 | * This routine does not require any locks. It's usage is expected |
| 17626 | * to be driver load or reset recovery when the driver is |
| 17627 | * sequential. |
| 17628 | * |
| 17629 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17630 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17631 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17632 | * When this error occurs, the driver is not guaranteed |
| 17633 | * to have any rpi regions posted to the device and |
| 17634 | * must either attempt to repost the regions or take a |
| 17635 | * fatal error. |
| 17636 | **/ |
| 17637 | int |
| 17638 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 17639 | { |
| 17640 | struct lpfc_rpi_hdr *rpi_page; |
| 17641 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17642 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17643 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17644 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 17645 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 17646 | goto exit; |
| 17647 | if (phba->sli4_hba.extents_in_use) |
| 17648 | return -EIO; |
| 17649 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17650 | 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] | 17651 | /* |
| 17652 | * Assign the rpi headers a physical rpi only if the driver |
| 17653 | * has not initialized those resources. A port reset only |
| 17654 | * needs the headers posted. |
| 17655 | */ |
| 17656 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 17657 | LPFC_RPI_RSRC_RDY) |
| 17658 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 17659 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17660 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 17661 | if (rc != MBX_SUCCESS) { |
| 17662 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17663 | "2008 Error %d posting all rpi " |
| 17664 | "headers\n", rc); |
| 17665 | rc = -EIO; |
| 17666 | break; |
| 17667 | } |
| 17668 | } |
| 17669 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17670 | exit: |
| 17671 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 17672 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17673 | return rc; |
| 17674 | } |
| 17675 | |
| 17676 | /** |
| 17677 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 17678 | * @phba: pointer to lpfc hba data structure. |
| 17679 | * @rpi_page: pointer to the rpi memory region. |
| 17680 | * |
| 17681 | * This routine is invoked to post a single rpi header to the |
| 17682 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 17683 | * maps up to 64 rpi context regions. |
| 17684 | * |
| 17685 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17686 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17687 | * -ENOMEM - No available memory |
| 17688 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17689 | **/ |
| 17690 | int |
| 17691 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 17692 | { |
| 17693 | LPFC_MBOXQ_t *mboxq; |
| 17694 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 17695 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17696 | uint32_t shdr_status, shdr_add_status; |
| 17697 | union lpfc_sli4_cfg_shdr *shdr; |
| 17698 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17699 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 17700 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 17701 | return rc; |
| 17702 | if (phba->sli4_hba.extents_in_use) |
| 17703 | return -EIO; |
| 17704 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17705 | /* The port is notified of the header region via a mailbox command. */ |
| 17706 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17707 | if (!mboxq) { |
| 17708 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17709 | "2001 Unable to allocate memory for issuing " |
| 17710 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 17711 | return -ENOMEM; |
| 17712 | } |
| 17713 | |
| 17714 | /* Post all rpi memory regions to the port. */ |
| 17715 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17716 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17717 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 17718 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 17719 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 17720 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17721 | |
| 17722 | |
| 17723 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17724 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 17725 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17726 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 17727 | hdr_tmpl, rpi_page->page_count); |
| 17728 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17729 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 17730 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 17731 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17732 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 17733 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17734 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17735 | if (rc != MBX_TIMEOUT) |
| 17736 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 17737 | if (shdr_status || shdr_add_status || rc) { |
| 17738 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17739 | "2514 POST_RPI_HDR mailbox failed with " |
| 17740 | "status x%x add_status x%x, mbx status x%x\n", |
| 17741 | shdr_status, shdr_add_status, rc); |
| 17742 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 17743 | } else { |
| 17744 | /* |
| 17745 | * The next_rpi stores the next logical module-64 rpi value used |
| 17746 | * to post physical rpis in subsequent rpi postings. |
| 17747 | */ |
| 17748 | spin_lock_irq(&phba->hbalock); |
| 17749 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 17750 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17751 | } |
| 17752 | return rc; |
| 17753 | } |
| 17754 | |
| 17755 | /** |
| 17756 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 17757 | * @phba: pointer to lpfc hba data structure. |
| 17758 | * |
| 17759 | * This routine is invoked to post rpi header templates to the |
| 17760 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17761 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17762 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17763 | * |
| 17764 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17765 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17766 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 17767 | **/ |
| 17768 | int |
| 17769 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 17770 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17771 | unsigned long rpi; |
| 17772 | uint16_t max_rpi, rpi_limit; |
| 17773 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17774 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17775 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17776 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17777 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17778 | * Fetch the next logical rpi. Because this index is logical, |
| 17779 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17780 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17781 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 17782 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 17783 | rpi_limit = phba->sli4_hba.next_rpi; |
| 17784 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17785 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 17786 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17787 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 17788 | else { |
| 17789 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 17790 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 17791 | phba->sli4_hba.rpi_count++; |
| 17792 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 17793 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 17794 | "0001 rpi:%x max:%x lim:%x\n", |
| 17795 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17796 | |
| 17797 | /* |
| 17798 | * 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] | 17799 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17800 | */ |
| 17801 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 17802 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17803 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17804 | return rpi; |
| 17805 | } |
| 17806 | |
| 17807 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17808 | * RPI header postings are not required for SLI4 ports capable of |
| 17809 | * extents. |
| 17810 | */ |
| 17811 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17812 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17813 | return rpi; |
| 17814 | } |
| 17815 | |
| 17816 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17817 | * If the driver is running low on rpi resources, allocate another |
| 17818 | * page now. Note that the next_rpi value is used because |
| 17819 | * it represents how many are actually in use whereas max_rpi notes |
| 17820 | * how many are supported max by the device. |
| 17821 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17822 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17823 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17824 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 17825 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 17826 | if (!rpi_hdr) { |
| 17827 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17828 | "2002 Error Could not grow rpi " |
| 17829 | "count\n"); |
| 17830 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17831 | lrpi = rpi_hdr->start_rpi; |
| 17832 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17833 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 17834 | } |
| 17835 | } |
| 17836 | |
| 17837 | return rpi; |
| 17838 | } |
| 17839 | |
| 17840 | /** |
| 17841 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 17842 | * @phba: pointer to lpfc hba data structure. |
| 17843 | * |
| 17844 | * This routine is invoked to release an rpi to the pool of |
| 17845 | * available rpis maintained by the driver. |
| 17846 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17847 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 17848 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 17849 | { |
| 17850 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 17851 | phba->sli4_hba.rpi_count--; |
| 17852 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 17853 | } |
| 17854 | } |
| 17855 | |
| 17856 | /** |
| 17857 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 17858 | * @phba: pointer to lpfc hba data structure. |
| 17859 | * |
| 17860 | * This routine is invoked to release an rpi to the pool of |
| 17861 | * available rpis maintained by the driver. |
| 17862 | **/ |
| 17863 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17864 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 17865 | { |
| 17866 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 17867 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17868 | spin_unlock_irq(&phba->hbalock); |
| 17869 | } |
| 17870 | |
| 17871 | /** |
| 17872 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 17873 | * @phba: pointer to lpfc hba data structure. |
| 17874 | * |
| 17875 | * This routine is invoked to remove the memory region that |
| 17876 | * provided rpi via a bitmask. |
| 17877 | **/ |
| 17878 | void |
| 17879 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 17880 | { |
| 17881 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17882 | kfree(phba->sli4_hba.rpi_ids); |
| 17883 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17884 | } |
| 17885 | |
| 17886 | /** |
| 17887 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 17888 | * @phba: pointer to lpfc hba data structure. |
| 17889 | * |
| 17890 | * This routine is invoked to remove the memory region that |
| 17891 | * provided rpi via a bitmask. |
| 17892 | **/ |
| 17893 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17894 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 17895 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17896 | { |
| 17897 | LPFC_MBOXQ_t *mboxq; |
| 17898 | struct lpfc_hba *phba = ndlp->phba; |
| 17899 | int rc; |
| 17900 | |
| 17901 | /* The port is notified of the header region via a mailbox command. */ |
| 17902 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17903 | if (!mboxq) |
| 17904 | return -ENOMEM; |
| 17905 | |
| 17906 | /* Post all rpi memory regions to the port. */ |
| 17907 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17908 | if (cmpl) { |
| 17909 | mboxq->mbox_cmpl = cmpl; |
| 17910 | mboxq->context1 = arg; |
| 17911 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 17912 | } else |
| 17913 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17914 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17915 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17916 | if (rc == MBX_NOT_FINISHED) { |
| 17917 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17918 | "2010 Resume RPI Mailbox failed " |
| 17919 | "status %d, mbxStatus x%x\n", rc, |
| 17920 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 17921 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 17922 | return -EIO; |
| 17923 | } |
| 17924 | return 0; |
| 17925 | } |
| 17926 | |
| 17927 | /** |
| 17928 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17929 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17930 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17931 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17932 | * |
| 17933 | * Returns: |
| 17934 | * 0 success |
| 17935 | * -Evalue otherwise |
| 17936 | **/ |
| 17937 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17938 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17939 | { |
| 17940 | LPFC_MBOXQ_t *mboxq; |
| 17941 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17942 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17943 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17944 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17945 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17946 | if (!mboxq) |
| 17947 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17948 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17949 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17950 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17951 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17952 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17953 | "2022 INIT VPI Mailbox failed " |
| 17954 | "status %d, mbxStatus x%x\n", rc, |
| 17955 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17956 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17957 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17958 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17959 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17960 | |
| 17961 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17962 | } |
| 17963 | |
| 17964 | /** |
| 17965 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 17966 | * @phba: pointer to lpfc hba data structure. |
| 17967 | * @mboxq: Pointer to mailbox object. |
| 17968 | * |
| 17969 | * This routine is invoked to manually add a single FCF record. The caller |
| 17970 | * must pass a completely initialized FCF_Record. This routine takes |
| 17971 | * care of the nonembedded mailbox operations. |
| 17972 | **/ |
| 17973 | static void |
| 17974 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 17975 | { |
| 17976 | void *virt_addr; |
| 17977 | union lpfc_sli4_cfg_shdr *shdr; |
| 17978 | uint32_t shdr_status, shdr_add_status; |
| 17979 | |
| 17980 | virt_addr = mboxq->sge_array->addr[0]; |
| 17981 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17982 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 17983 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17984 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17985 | |
| 17986 | if ((shdr_status || shdr_add_status) && |
| 17987 | (shdr_status != STATUS_FCF_IN_USE)) |
| 17988 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17989 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 17990 | "status x%x add_status x%x\n", |
| 17991 | shdr_status, shdr_add_status); |
| 17992 | |
| 17993 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17994 | } |
| 17995 | |
| 17996 | /** |
| 17997 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 17998 | * @phba: pointer to lpfc hba data structure. |
| 17999 | * @fcf_record: pointer to the initialized fcf record to add. |
| 18000 | * |
| 18001 | * This routine is invoked to manually add a single FCF record. The caller |
| 18002 | * must pass a completely initialized FCF_Record. This routine takes |
| 18003 | * care of the nonembedded mailbox operations. |
| 18004 | **/ |
| 18005 | int |
| 18006 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 18007 | { |
| 18008 | int rc = 0; |
| 18009 | LPFC_MBOXQ_t *mboxq; |
| 18010 | uint8_t *bytep; |
| 18011 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18012 | struct lpfc_mbx_sge sge; |
| 18013 | uint32_t alloc_len, req_len; |
| 18014 | uint32_t fcfindex; |
| 18015 | |
| 18016 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18017 | if (!mboxq) { |
| 18018 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18019 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 18020 | return -ENOMEM; |
| 18021 | } |
| 18022 | |
| 18023 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 18024 | sizeof(uint32_t); |
| 18025 | |
| 18026 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 18027 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18028 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 18029 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 18030 | if (alloc_len < req_len) { |
| 18031 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18032 | "2523 Allocated DMA memory size (x%x) is " |
| 18033 | "less than the requested DMA memory " |
| 18034 | "size (x%x)\n", alloc_len, req_len); |
| 18035 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18036 | return -ENOMEM; |
| 18037 | } |
| 18038 | |
| 18039 | /* |
| 18040 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 18041 | * routine only uses a single SGE. |
| 18042 | */ |
| 18043 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18044 | virt_addr = mboxq->sge_array->addr[0]; |
| 18045 | /* |
| 18046 | * Configure the FCF record for FCFI 0. This is the driver's |
| 18047 | * hardcoded default and gets used in nonFIP mode. |
| 18048 | */ |
| 18049 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 18050 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 18051 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 18052 | |
| 18053 | /* |
| 18054 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 18055 | * the FCoE header plus word10. The data copy needs to be endian |
| 18056 | * correct. |
| 18057 | */ |
| 18058 | bytep += sizeof(uint32_t); |
| 18059 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 18060 | mboxq->vport = phba->pport; |
| 18061 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 18062 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18063 | if (rc == MBX_NOT_FINISHED) { |
| 18064 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18065 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 18066 | "status 0x%x\n", rc); |
| 18067 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18068 | rc = -EIO; |
| 18069 | } else |
| 18070 | rc = 0; |
| 18071 | |
| 18072 | return rc; |
| 18073 | } |
| 18074 | |
| 18075 | /** |
| 18076 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 18077 | * @phba: pointer to lpfc hba data structure. |
| 18078 | * @fcf_record: pointer to the fcf record to write the default data. |
| 18079 | * @fcf_index: FCF table entry index. |
| 18080 | * |
| 18081 | * This routine is invoked to build the driver's default FCF record. The |
| 18082 | * values used are hardcoded. This routine handles memory initialization. |
| 18083 | * |
| 18084 | **/ |
| 18085 | void |
| 18086 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 18087 | struct fcf_record *fcf_record, |
| 18088 | uint16_t fcf_index) |
| 18089 | { |
| 18090 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 18091 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 18092 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 18093 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 18094 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 18095 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 18096 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 18097 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 18098 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 18099 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 18100 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 18101 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 18102 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 18103 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 18104 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18105 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 18106 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 18107 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 18108 | /* Set the VLAN bit map */ |
| 18109 | if (phba->valid_vlan) { |
| 18110 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 18111 | = 1 << (phba->vlan_id % 8); |
| 18112 | } |
| 18113 | } |
| 18114 | |
| 18115 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18116 | * 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] | 18117 | * @phba: pointer to lpfc hba data structure. |
| 18118 | * @fcf_index: FCF table entry offset. |
| 18119 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18120 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 18121 | * record and processing it one at a time starting from the @fcf_index |
| 18122 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 18123 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18124 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18125 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18126 | **/ |
| 18127 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18128 | 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] | 18129 | { |
| 18130 | int rc = 0, error; |
| 18131 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18132 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18133 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 18134 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18135 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18136 | if (!mboxq) { |
| 18137 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18138 | "2000 Failed to allocate mbox for " |
| 18139 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18140 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18141 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18142 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18143 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18144 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18145 | if (rc) { |
| 18146 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18147 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18148 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18149 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18150 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18151 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18152 | |
| 18153 | spin_lock_irq(&phba->hbalock); |
| 18154 | phba->hba_flag |= FCF_TS_INPROG; |
| 18155 | spin_unlock_irq(&phba->hbalock); |
| 18156 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18157 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18158 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18159 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18160 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 18161 | /* Reset eligible FCF count for new scan */ |
| 18162 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 18163 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18164 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 18165 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18166 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18167 | if (error) { |
| 18168 | if (mboxq) |
| 18169 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18170 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18171 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18172 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 18173 | spin_unlock_irq(&phba->hbalock); |
| 18174 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 18175 | return error; |
| 18176 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18177 | |
| 18178 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18179 | * 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] | 18180 | * @phba: pointer to lpfc hba data structure. |
| 18181 | * @fcf_index: FCF table entry offset. |
| 18182 | * |
| 18183 | * 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] | 18184 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18185 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18186 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18187 | * otherwise. |
| 18188 | **/ |
| 18189 | int |
| 18190 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18191 | { |
| 18192 | int rc = 0, error; |
| 18193 | LPFC_MBOXQ_t *mboxq; |
| 18194 | |
| 18195 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18196 | if (!mboxq) { |
| 18197 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18198 | "2763 Failed to allocate mbox for " |
| 18199 | "READ_FCF cmd\n"); |
| 18200 | error = -ENOMEM; |
| 18201 | goto fail_fcf_read; |
| 18202 | } |
| 18203 | /* Construct the read FCF record mailbox command */ |
| 18204 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18205 | if (rc) { |
| 18206 | error = -EINVAL; |
| 18207 | goto fail_fcf_read; |
| 18208 | } |
| 18209 | /* Issue the mailbox command asynchronously */ |
| 18210 | mboxq->vport = phba->pport; |
| 18211 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 18212 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18213 | if (rc == MBX_NOT_FINISHED) |
| 18214 | error = -EIO; |
| 18215 | else |
| 18216 | error = 0; |
| 18217 | |
| 18218 | fail_fcf_read: |
| 18219 | if (error && mboxq) |
| 18220 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18221 | return error; |
| 18222 | } |
| 18223 | |
| 18224 | /** |
| 18225 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 18226 | * @phba: pointer to lpfc hba data structure. |
| 18227 | * @fcf_index: FCF table entry offset. |
| 18228 | * |
| 18229 | * 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] | 18230 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18231 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 18232 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18233 | * otherwise. |
| 18234 | **/ |
| 18235 | int |
| 18236 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18237 | { |
| 18238 | int rc = 0, error; |
| 18239 | LPFC_MBOXQ_t *mboxq; |
| 18240 | |
| 18241 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18242 | if (!mboxq) { |
| 18243 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 18244 | "2758 Failed to allocate mbox for " |
| 18245 | "READ_FCF cmd\n"); |
| 18246 | error = -ENOMEM; |
| 18247 | goto fail_fcf_read; |
| 18248 | } |
| 18249 | /* Construct the read FCF record mailbox command */ |
| 18250 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 18251 | if (rc) { |
| 18252 | error = -EINVAL; |
| 18253 | goto fail_fcf_read; |
| 18254 | } |
| 18255 | /* Issue the mailbox command asynchronously */ |
| 18256 | mboxq->vport = phba->pport; |
| 18257 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 18258 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 18259 | if (rc == MBX_NOT_FINISHED) |
| 18260 | error = -EIO; |
| 18261 | else |
| 18262 | error = 0; |
| 18263 | |
| 18264 | fail_fcf_read: |
| 18265 | if (error && mboxq) |
| 18266 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 18267 | return error; |
| 18268 | } |
| 18269 | |
| 18270 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18271 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18272 | * phba pointer to the lpfc_hba struct for this port. |
| 18273 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 18274 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 18275 | * rr_bmask based on their priority level. Starting from the highest priority |
| 18276 | * to the lowest. The most likely FCF candidate will be in the highest |
| 18277 | * priority group. When this routine is called it searches the fcf_pri list for |
| 18278 | * next lowest priority group and repopulates the rr_bmask with only those |
| 18279 | * fcf_indexes. |
| 18280 | * returns: |
| 18281 | * 1=success 0=failure |
| 18282 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18283 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18284 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 18285 | { |
| 18286 | uint16_t next_fcf_pri; |
| 18287 | uint16_t last_index; |
| 18288 | struct lpfc_fcf_pri *fcf_pri; |
| 18289 | int rc; |
| 18290 | int ret = 0; |
| 18291 | |
| 18292 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 18293 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18294 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 18295 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18296 | |
| 18297 | /* Verify the priority list has 2 or more entries */ |
| 18298 | spin_lock_irq(&phba->hbalock); |
| 18299 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 18300 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 18301 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18302 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 18303 | "3061 Last IDX %d\n", last_index); |
| 18304 | return 0; /* Empty rr list */ |
| 18305 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18306 | spin_unlock_irq(&phba->hbalock); |
| 18307 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18308 | next_fcf_pri = 0; |
| 18309 | /* |
| 18310 | * Clear the rr_bmask and set all of the bits that are at this |
| 18311 | * priority. |
| 18312 | */ |
| 18313 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 18314 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 18315 | spin_lock_irq(&phba->hbalock); |
| 18316 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18317 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 18318 | continue; |
| 18319 | /* |
| 18320 | * the 1st priority that has not FLOGI failed |
| 18321 | * will be the highest. |
| 18322 | */ |
| 18323 | if (!next_fcf_pri) |
| 18324 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18325 | spin_unlock_irq(&phba->hbalock); |
| 18326 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18327 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18328 | fcf_pri->fcf_rec.fcf_index); |
| 18329 | if (rc) |
| 18330 | return 0; |
| 18331 | } |
| 18332 | spin_lock_irq(&phba->hbalock); |
| 18333 | } |
| 18334 | /* |
| 18335 | * if next_fcf_pri was not set above and the list is not empty then |
| 18336 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 18337 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18338 | */ |
| 18339 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 18340 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18341 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 18342 | /* |
| 18343 | * the 1st priority that has not FLOGI failed |
| 18344 | * will be the highest. |
| 18345 | */ |
| 18346 | if (!next_fcf_pri) |
| 18347 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18348 | spin_unlock_irq(&phba->hbalock); |
| 18349 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18350 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18351 | fcf_pri->fcf_rec.fcf_index); |
| 18352 | if (rc) |
| 18353 | return 0; |
| 18354 | } |
| 18355 | spin_lock_irq(&phba->hbalock); |
| 18356 | } |
| 18357 | } else |
| 18358 | ret = 1; |
| 18359 | spin_unlock_irq(&phba->hbalock); |
| 18360 | |
| 18361 | return ret; |
| 18362 | } |
| 18363 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18364 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 18365 | * @phba: pointer to lpfc hba data structure. |
| 18366 | * |
| 18367 | * This routine is to get the next eligible FCF record index in a round |
| 18368 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18369 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18370 | * shall be returned, otherwise, the next eligible FCF record's index |
| 18371 | * shall be returned. |
| 18372 | **/ |
| 18373 | uint16_t |
| 18374 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 18375 | { |
| 18376 | uint16_t next_fcf_index; |
| 18377 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18378 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18379 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18380 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 18381 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18382 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18383 | /* Determine the next fcf index to check */ |
| 18384 | 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] | 18385 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18386 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18387 | next_fcf_index); |
| 18388 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18389 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18390 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18391 | /* |
| 18392 | * If we have wrapped then we need to clear the bits that |
| 18393 | * have been tested so that we can detect when we should |
| 18394 | * change the priority level. |
| 18395 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18396 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18397 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18398 | } |
| 18399 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18400 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18401 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18402 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 18403 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 18404 | /* |
| 18405 | * If next fcf index is not found check if there are lower |
| 18406 | * Priority level fcf's in the fcf_priority list. |
| 18407 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 18408 | * at that level and continue the selection process. |
| 18409 | */ |
| 18410 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18411 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18412 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18413 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18414 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 18415 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18416 | else { |
| 18417 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18418 | "3063 Only FCF available idx %d, flag %x\n", |
| 18419 | next_fcf_index, |
| 18420 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 18421 | return next_fcf_index; |
| 18422 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18423 | } |
| 18424 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18425 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 18426 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18427 | LPFC_FCF_FLOGI_FAILED) { |
| 18428 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 18429 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18430 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18431 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18432 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18433 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18434 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18435 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 18436 | next_fcf_index); |
| 18437 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18438 | return next_fcf_index; |
| 18439 | } |
| 18440 | |
| 18441 | /** |
| 18442 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 18443 | * @phba: pointer to lpfc hba data structure. |
| 18444 | * |
| 18445 | * 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] | 18446 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18447 | * does not go beyond the range of the driver allocated bmask dimension |
| 18448 | * before setting the bit. |
| 18449 | * |
| 18450 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 18451 | * -EINVAL. |
| 18452 | **/ |
| 18453 | int |
| 18454 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18455 | { |
| 18456 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18457 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18458 | "2610 FCF (x%x) reached driver's book " |
| 18459 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18460 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18461 | return -EINVAL; |
| 18462 | } |
| 18463 | /* Set the eligible FCF record index bmask */ |
| 18464 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 18465 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18466 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18467 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18468 | "bmask\n", fcf_index); |
| 18469 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18470 | return 0; |
| 18471 | } |
| 18472 | |
| 18473 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18474 | * 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] | 18475 | * @phba: pointer to lpfc hba data structure. |
| 18476 | * |
| 18477 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18478 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18479 | * does not go beyond the range of the driver allocated bmask dimension |
| 18480 | * before clearing the bit. |
| 18481 | **/ |
| 18482 | void |
| 18483 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18484 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18485 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18486 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18487 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18488 | "2762 FCF (x%x) reached driver's book " |
| 18489 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18490 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18491 | return; |
| 18492 | } |
| 18493 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18494 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18495 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 18496 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18497 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 18498 | list_del_init(&fcf_pri->list); |
| 18499 | break; |
| 18500 | } |
| 18501 | } |
| 18502 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18503 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18504 | |
| 18505 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18506 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18507 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18508 | } |
| 18509 | |
| 18510 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18511 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 18512 | * @phba: pointer to lpfc hba data structure. |
| 18513 | * |
| 18514 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 18515 | * command. If the mailbox command returned failure, it will try to stop the |
| 18516 | * FCF rediscover wait timer. |
| 18517 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18518 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18519 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 18520 | { |
| 18521 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18522 | uint32_t shdr_status, shdr_add_status; |
| 18523 | |
| 18524 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18525 | |
| 18526 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 18527 | &redisc_fcf->header.cfg_shdr.response); |
| 18528 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 18529 | &redisc_fcf->header.cfg_shdr.response); |
| 18530 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18531 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18532 | "2746 Requesting for FCF rediscovery failed " |
| 18533 | "status x%x add_status x%x\n", |
| 18534 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18535 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18536 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18537 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18538 | spin_unlock_irq(&phba->hbalock); |
| 18539 | /* |
| 18540 | * CVL event triggered FCF rediscover request failed, |
| 18541 | * last resort to re-try current registered FCF entry. |
| 18542 | */ |
| 18543 | lpfc_retry_pport_discovery(phba); |
| 18544 | } else { |
| 18545 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18546 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18547 | spin_unlock_irq(&phba->hbalock); |
| 18548 | /* |
| 18549 | * DEAD FCF event triggered FCF rediscover request |
| 18550 | * failed, last resort to fail over as a link down |
| 18551 | * to FCF registration. |
| 18552 | */ |
| 18553 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 18554 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18555 | } else { |
| 18556 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18557 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18558 | /* |
| 18559 | * Start FCF rediscovery wait timer for pending FCF |
| 18560 | * before rescan FCF record table. |
| 18561 | */ |
| 18562 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18563 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18564 | |
| 18565 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18566 | } |
| 18567 | |
| 18568 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18569 | * 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] | 18570 | * @phba: pointer to lpfc hba data structure. |
| 18571 | * |
| 18572 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 18573 | * by the port. |
| 18574 | **/ |
| 18575 | int |
| 18576 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 18577 | { |
| 18578 | LPFC_MBOXQ_t *mbox; |
| 18579 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18580 | int rc, length; |
| 18581 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18582 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 18583 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 18584 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18585 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18586 | if (!mbox) { |
| 18587 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18588 | "2745 Failed to allocate mbox for " |
| 18589 | "requesting FCF rediscover.\n"); |
| 18590 | return -ENOMEM; |
| 18591 | } |
| 18592 | |
| 18593 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 18594 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 18595 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18596 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 18597 | length, LPFC_SLI4_MBX_EMBED); |
| 18598 | |
| 18599 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18600 | /* Set count to 0 for invalidating the entire FCF database */ |
| 18601 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 18602 | |
| 18603 | /* Issue the mailbox command asynchronously */ |
| 18604 | mbox->vport = phba->pport; |
| 18605 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 18606 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 18607 | |
| 18608 | if (rc == MBX_NOT_FINISHED) { |
| 18609 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18610 | return -EIO; |
| 18611 | } |
| 18612 | return 0; |
| 18613 | } |
| 18614 | |
| 18615 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18616 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 18617 | * @phba: pointer to lpfc hba data structure. |
| 18618 | * |
| 18619 | * This function is the failover routine as a last resort to the FCF DEAD |
| 18620 | * event when driver failed to perform fast FCF failover. |
| 18621 | **/ |
| 18622 | void |
| 18623 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 18624 | { |
| 18625 | uint32_t link_state; |
| 18626 | |
| 18627 | /* |
| 18628 | * Last resort as FCF DEAD event failover will treat this as |
| 18629 | * a link down, but save the link state because we don't want |
| 18630 | * it to be changed to Link Down unless it is already down. |
| 18631 | */ |
| 18632 | link_state = phba->link_state; |
| 18633 | lpfc_linkdown(phba); |
| 18634 | phba->link_state = link_state; |
| 18635 | |
| 18636 | /* Unregister FCF if no devices connected to it */ |
| 18637 | lpfc_unregister_unused_fcf(phba); |
| 18638 | } |
| 18639 | |
| 18640 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18641 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18642 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18643 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18644 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18645 | * This function gets SLI3 port configure region 23 data through memory dump |
| 18646 | * mailbox command. When it successfully retrieves data, the size of the data |
| 18647 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18648 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18649 | static uint32_t |
| 18650 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18651 | { |
| 18652 | LPFC_MBOXQ_t *pmb = NULL; |
| 18653 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18654 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18655 | int rc; |
| 18656 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18657 | if (!rgn23_data) |
| 18658 | return 0; |
| 18659 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18660 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18661 | if (!pmb) { |
| 18662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18663 | "2600 failed to allocate mailbox memory\n"); |
| 18664 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18665 | } |
| 18666 | mb = &pmb->u.mb; |
| 18667 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18668 | do { |
| 18669 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 18670 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 18671 | |
| 18672 | if (rc != MBX_SUCCESS) { |
| 18673 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18674 | "2601 failed to read config " |
| 18675 | "region 23, rc 0x%x Status 0x%x\n", |
| 18676 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18677 | mb->un.varDmp.word_cnt = 0; |
| 18678 | } |
| 18679 | /* |
| 18680 | * dump mem may return a zero when finished or we got a |
| 18681 | * mailbox error, either way we are done. |
| 18682 | */ |
| 18683 | if (mb->un.varDmp.word_cnt == 0) |
| 18684 | break; |
| 18685 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 18686 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 18687 | |
| 18688 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18689 | rgn23_data + offset, |
| 18690 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18691 | offset += mb->un.varDmp.word_cnt; |
| 18692 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 18693 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18694 | mempool_free(pmb, phba->mbox_mem_pool); |
| 18695 | return offset; |
| 18696 | } |
| 18697 | |
| 18698 | /** |
| 18699 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 18700 | * @phba: pointer to lpfc hba data structure. |
| 18701 | * @rgn23_data: pointer to configure region 23 data. |
| 18702 | * |
| 18703 | * This function gets SLI4 port configure region 23 data through memory dump |
| 18704 | * mailbox command. When it successfully retrieves data, the size of the data |
| 18705 | * will be returned, otherwise, 0 will be returned. |
| 18706 | **/ |
| 18707 | static uint32_t |
| 18708 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 18709 | { |
| 18710 | LPFC_MBOXQ_t *mboxq = NULL; |
| 18711 | struct lpfc_dmabuf *mp = NULL; |
| 18712 | struct lpfc_mqe *mqe; |
| 18713 | uint32_t data_length = 0; |
| 18714 | int rc; |
| 18715 | |
| 18716 | if (!rgn23_data) |
| 18717 | return 0; |
| 18718 | |
| 18719 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18720 | if (!mboxq) { |
| 18721 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18722 | "3105 failed to allocate mailbox memory\n"); |
| 18723 | return 0; |
| 18724 | } |
| 18725 | |
| 18726 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 18727 | goto out; |
| 18728 | mqe = &mboxq->u.mqe; |
| 18729 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 18730 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 18731 | if (rc) |
| 18732 | goto out; |
| 18733 | data_length = mqe->un.mb_words[5]; |
| 18734 | if (data_length == 0) |
| 18735 | goto out; |
| 18736 | if (data_length > DMP_RGN23_SIZE) { |
| 18737 | data_length = 0; |
| 18738 | goto out; |
| 18739 | } |
| 18740 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 18741 | out: |
| 18742 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18743 | if (mp) { |
| 18744 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 18745 | kfree(mp); |
| 18746 | } |
| 18747 | return data_length; |
| 18748 | } |
| 18749 | |
| 18750 | /** |
| 18751 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 18752 | * @phba: pointer to lpfc hba data structure. |
| 18753 | * |
| 18754 | * This function read region 23 and parse TLV for port status to |
| 18755 | * decide if the user disaled the port. If the TLV indicates the |
| 18756 | * port is disabled, the hba_flag is set accordingly. |
| 18757 | **/ |
| 18758 | void |
| 18759 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 18760 | { |
| 18761 | uint8_t *rgn23_data = NULL; |
| 18762 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 18763 | uint32_t offset = 0; |
| 18764 | |
| 18765 | /* Get adapter Region 23 data */ |
| 18766 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 18767 | if (!rgn23_data) |
| 18768 | goto out; |
| 18769 | |
| 18770 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 18771 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 18772 | else { |
| 18773 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 18774 | &phba->sli4_hba.sli_intf); |
| 18775 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 18776 | goto out; |
| 18777 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 18778 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18779 | |
| 18780 | if (!data_size) |
| 18781 | goto out; |
| 18782 | |
| 18783 | /* Check the region signature first */ |
| 18784 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 18785 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18786 | "2619 Config region 23 has bad signature\n"); |
| 18787 | goto out; |
| 18788 | } |
| 18789 | offset += 4; |
| 18790 | |
| 18791 | /* Check the data structure version */ |
| 18792 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 18793 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18794 | "2620 Config region 23 has bad version\n"); |
| 18795 | goto out; |
| 18796 | } |
| 18797 | offset += 4; |
| 18798 | |
| 18799 | /* Parse TLV entries in the region */ |
| 18800 | while (offset < data_size) { |
| 18801 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 18802 | break; |
| 18803 | /* |
| 18804 | * If the TLV is not driver specific TLV or driver id is |
| 18805 | * not linux driver id, skip the record. |
| 18806 | */ |
| 18807 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 18808 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 18809 | (rgn23_data[offset + 3] != 0)) { |
| 18810 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 18811 | continue; |
| 18812 | } |
| 18813 | |
| 18814 | /* Driver found a driver specific TLV in the config region */ |
| 18815 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 18816 | offset += 4; |
| 18817 | tlv_offset = 0; |
| 18818 | |
| 18819 | /* |
| 18820 | * Search for configured port state sub-TLV. |
| 18821 | */ |
| 18822 | while ((offset < data_size) && |
| 18823 | (tlv_offset < sub_tlv_len)) { |
| 18824 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 18825 | offset += 4; |
| 18826 | tlv_offset += 4; |
| 18827 | break; |
| 18828 | } |
| 18829 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 18830 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 18831 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 18832 | continue; |
| 18833 | } |
| 18834 | |
| 18835 | /* This HBA contains PORT_STE configured */ |
| 18836 | if (!rgn23_data[offset + 2]) |
| 18837 | phba->hba_flag |= LINK_DISABLED; |
| 18838 | |
| 18839 | goto out; |
| 18840 | } |
| 18841 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18842 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18843 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18844 | kfree(rgn23_data); |
| 18845 | return; |
| 18846 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18847 | |
| 18848 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 18849 | * lpfc_wr_object - write an object to the firmware |
| 18850 | * @phba: HBA structure that indicates port to create a queue on. |
| 18851 | * @dmabuf_list: list of dmabufs to write to the port. |
| 18852 | * @size: the total byte value of the objects to write to the port. |
| 18853 | * @offset: the current offset to be used to start the transfer. |
| 18854 | * |
| 18855 | * This routine will create a wr_object mailbox command to send to the port. |
| 18856 | * the mailbox command will be constructed using the dma buffers described in |
| 18857 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 18858 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 18859 | * used to indicate the starting offset of the transfer and will also return |
| 18860 | * the offset after the write object mailbox has completed. @size is used to |
| 18861 | * determine the end of the object and whether the eof bit should be set. |
| 18862 | * |
| 18863 | * Return 0 is successful and offset will contain the the new offset to use |
| 18864 | * for the next write. |
| 18865 | * Return negative value for error cases. |
| 18866 | **/ |
| 18867 | int |
| 18868 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 18869 | uint32_t size, uint32_t *offset) |
| 18870 | { |
| 18871 | struct lpfc_mbx_wr_object *wr_object; |
| 18872 | LPFC_MBOXQ_t *mbox; |
| 18873 | int rc = 0, i = 0; |
| 18874 | uint32_t shdr_status, shdr_add_status; |
| 18875 | uint32_t mbox_tmo; |
| 18876 | union lpfc_sli4_cfg_shdr *shdr; |
| 18877 | struct lpfc_dmabuf *dmabuf; |
| 18878 | uint32_t written = 0; |
| 18879 | |
| 18880 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18881 | if (!mbox) |
| 18882 | return -ENOMEM; |
| 18883 | |
| 18884 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 18885 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 18886 | sizeof(struct lpfc_mbx_wr_object) - |
| 18887 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 18888 | |
| 18889 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 18890 | wr_object->u.request.write_offset = *offset; |
| 18891 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 18892 | wr_object->u.request.object_name[0] = |
| 18893 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 18894 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 18895 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 18896 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 18897 | break; |
| 18898 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 18899 | wr_object->u.request.bde[i].addrHigh = |
| 18900 | putPaddrHigh(dmabuf->phys); |
| 18901 | if (written + SLI4_PAGE_SIZE >= size) { |
| 18902 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 18903 | (size - written); |
| 18904 | written += (size - written); |
| 18905 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 18906 | } else { |
| 18907 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 18908 | SLI4_PAGE_SIZE; |
| 18909 | written += SLI4_PAGE_SIZE; |
| 18910 | } |
| 18911 | i++; |
| 18912 | } |
| 18913 | wr_object->u.request.bde_count = i; |
| 18914 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 18915 | if (!phba->sli4_hba.intr_enable) |
| 18916 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 18917 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18918 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 18919 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 18920 | } |
| 18921 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18922 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 18923 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18924 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18925 | if (rc != MBX_TIMEOUT) |
| 18926 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18927 | if (shdr_status || shdr_add_status || rc) { |
| 18928 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18929 | "3025 Write Object mailbox failed with " |
| 18930 | "status x%x add_status x%x, mbx status x%x\n", |
| 18931 | shdr_status, shdr_add_status, rc); |
| 18932 | rc = -ENXIO; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 18933 | *offset = shdr_add_status; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 18934 | } else |
| 18935 | *offset += wr_object->u.response.actual_write_length; |
| 18936 | return rc; |
| 18937 | } |
| 18938 | |
| 18939 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18940 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 18941 | * @vport: pointer to vport data structure. |
| 18942 | * |
| 18943 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 18944 | * and REG_VPI mailbox commands associated with the vport. This function |
| 18945 | * is called when driver want to restart discovery of the vport due to |
| 18946 | * a Clear Virtual Link event. |
| 18947 | **/ |
| 18948 | void |
| 18949 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 18950 | { |
| 18951 | struct lpfc_hba *phba = vport->phba; |
| 18952 | LPFC_MBOXQ_t *mb, *nextmb; |
| 18953 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18954 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18955 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 18956 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18957 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 18958 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18959 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18960 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18961 | spin_lock_irq(&phba->hbalock); |
| 18962 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 18963 | if (mb->vport != vport) |
| 18964 | continue; |
| 18965 | |
| 18966 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 18967 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 18968 | continue; |
| 18969 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18970 | list_del(&mb->list); |
| 18971 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 18972 | } |
| 18973 | /* Clean up active mailbox command with the vport */ |
| 18974 | mb = phba->sli.mbox_active; |
| 18975 | if (mb && (mb->vport == vport)) { |
| 18976 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 18977 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 18978 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 18979 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 18980 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 18981 | /* Put reference count for delayed processing */ |
| 18982 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 18983 | /* Unregister the RPI when mailbox complete */ |
| 18984 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 18985 | } |
| 18986 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 18987 | /* Cleanup any mailbox completions which are not yet processed */ |
| 18988 | do { |
| 18989 | restart_loop = 0; |
| 18990 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 18991 | /* |
| 18992 | * If this mailox is already processed or it is |
| 18993 | * for another vport ignore it. |
| 18994 | */ |
| 18995 | if ((mb->vport != vport) || |
| 18996 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 18997 | continue; |
| 18998 | |
| 18999 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 19000 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 19001 | continue; |
| 19002 | |
| 19003 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 19004 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 19005 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 19006 | /* Unregister the RPI when mailbox complete */ |
| 19007 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 19008 | restart_loop = 1; |
| 19009 | spin_unlock_irq(&phba->hbalock); |
| 19010 | spin_lock(shost->host_lock); |
| 19011 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19012 | spin_unlock(shost->host_lock); |
| 19013 | spin_lock_irq(&phba->hbalock); |
| 19014 | break; |
| 19015 | } |
| 19016 | } |
| 19017 | } while (restart_loop); |
| 19018 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19019 | spin_unlock_irq(&phba->hbalock); |
| 19020 | |
| 19021 | /* Release the cleaned-up mailbox commands */ |
| 19022 | while (!list_empty(&mbox_cmd_list)) { |
| 19023 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19024 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 19025 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 19026 | if (mp) { |
| 19027 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 19028 | kfree(mp); |
| 19029 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19030 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19031 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19032 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19033 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 19034 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 19035 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19036 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 19037 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19038 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19039 | mempool_free(mb, phba->mbox_mem_pool); |
| 19040 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 19041 | |
| 19042 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 19043 | if (act_mbx_ndlp) { |
| 19044 | spin_lock(shost->host_lock); |
| 19045 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 19046 | spin_unlock(shost->host_lock); |
| 19047 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19048 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 19049 | } |
| 19050 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19051 | /** |
| 19052 | * lpfc_drain_txq - Drain the txq |
| 19053 | * @phba: Pointer to HBA context object. |
| 19054 | * |
| 19055 | * This function attempt to submit IOCBs on the txq |
| 19056 | * to the adapter. For SLI4 adapters, the txq contains |
| 19057 | * ELS IOCBs that have been deferred because the there |
| 19058 | * are no SGLs. This congestion can occur with large |
| 19059 | * vport counts during node discovery. |
| 19060 | **/ |
| 19061 | |
| 19062 | uint32_t |
| 19063 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 19064 | { |
| 19065 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19066 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 19067 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19068 | unsigned long iflags = 0; |
| 19069 | char *fail_msg = NULL; |
| 19070 | struct lpfc_sglq *sglq; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19071 | union lpfc_wqe128 wqe; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 19072 | uint32_t txq_cnt = 0; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19073 | struct lpfc_queue *wq; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19074 | |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19075 | if (phba->link_flag & LS_MDS_LOOPBACK) { |
| 19076 | /* MDS WQE are posted only to first WQ*/ |
| 19077 | wq = phba->sli4_hba.fcp_wq[0]; |
| 19078 | if (unlikely(!wq)) |
| 19079 | return 0; |
| 19080 | pring = wq->pring; |
| 19081 | } else { |
| 19082 | wq = phba->sli4_hba.els_wq; |
| 19083 | if (unlikely(!wq)) |
| 19084 | return 0; |
| 19085 | pring = lpfc_phba_elsring(phba); |
| 19086 | } |
| 19087 | |
| 19088 | if (unlikely(!pring) || list_empty(&pring->txq)) |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 19089 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19090 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19091 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19092 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 19093 | txq_cnt++; |
| 19094 | } |
| 19095 | |
| 19096 | if (txq_cnt > pring->txq_max) |
| 19097 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19098 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19099 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19100 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19101 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19102 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19103 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19104 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19105 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19106 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19107 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19108 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19109 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 19110 | break; |
| 19111 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19112 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19113 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 19114 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19115 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19116 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19117 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19118 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19119 | |
| 19120 | /* The xri and iocb resources secured, |
| 19121 | * attempt to issue request |
| 19122 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 19123 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19124 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 19125 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 19126 | fail_msg = "to convert bpl to sgl"; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19127 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19128 | fail_msg = "to convert iocb to wqe"; |
James Smart | dc19e3b | 2018-05-24 21:08:57 -0700 | [diff] [blame] | 19129 | else if (lpfc_sli4_wq_put(wq, &wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19130 | fail_msg = " - Wq is full"; |
| 19131 | else |
| 19132 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 19133 | |
| 19134 | if (fail_msg) { |
| 19135 | /* Failed means we can't issue and need to cancel */ |
| 19136 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 19137 | "2822 IOCB failed %s iotag 0x%x " |
| 19138 | "xri 0x%x\n", |
| 19139 | fail_msg, |
| 19140 | piocbq->iotag, piocbq->sli4_xritag); |
| 19141 | list_add_tail(&piocbq->list, &completions); |
| 19142 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 19143 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19144 | } |
| 19145 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19146 | /* Cancel all the IOCBs that cannot be issued */ |
| 19147 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 19148 | IOERR_SLI_ABORTED); |
| 19149 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 19150 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 19151 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19152 | |
| 19153 | /** |
| 19154 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 19155 | * @phba: Pointer to HBA context object. |
| 19156 | * @pwqe: Pointer to command WQE. |
| 19157 | * @sglq: Pointer to the scatter gather queue object. |
| 19158 | * |
| 19159 | * This routine converts the bpl or bde that is in the WQE |
| 19160 | * to a sgl list for the sli4 hardware. The physical address |
| 19161 | * of the bpl/bde is converted back to a virtual address. |
| 19162 | * If the WQE contains a BPL then the list of BDE's is |
| 19163 | * converted to sli4_sge's. If the WQE contains a single |
| 19164 | * BDE then it is converted to a single sli_sge. |
| 19165 | * The WQE is still in cpu endianness so the contents of |
| 19166 | * the bpl can be used without byte swapping. |
| 19167 | * |
| 19168 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 19169 | */ |
| 19170 | static uint16_t |
| 19171 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 19172 | struct lpfc_sglq *sglq) |
| 19173 | { |
| 19174 | uint16_t xritag = NO_XRI; |
| 19175 | struct ulp_bde64 *bpl = NULL; |
| 19176 | struct ulp_bde64 bde; |
| 19177 | struct sli4_sge *sgl = NULL; |
| 19178 | struct lpfc_dmabuf *dmabuf; |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19179 | union lpfc_wqe128 *wqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19180 | int numBdes = 0; |
| 19181 | int i = 0; |
| 19182 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 19183 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 19184 | uint32_t cmd; |
| 19185 | |
| 19186 | if (!pwqeq || !sglq) |
| 19187 | return xritag; |
| 19188 | |
| 19189 | sgl = (struct sli4_sge *)sglq->sgl; |
| 19190 | wqe = &pwqeq->wqe; |
| 19191 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 19192 | |
| 19193 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 19194 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 19195 | return sglq->sli4_xritag; |
| 19196 | numBdes = pwqeq->rsvd2; |
| 19197 | if (numBdes) { |
| 19198 | /* The addrHigh and addrLow fields within the WQE |
| 19199 | * have not been byteswapped yet so there is no |
| 19200 | * need to swap them back. |
| 19201 | */ |
| 19202 | if (pwqeq->context3) |
| 19203 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 19204 | else |
| 19205 | return xritag; |
| 19206 | |
| 19207 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 19208 | if (!bpl) |
| 19209 | return xritag; |
| 19210 | |
| 19211 | for (i = 0; i < numBdes; i++) { |
| 19212 | /* Should already be byte swapped. */ |
| 19213 | sgl->addr_hi = bpl->addrHigh; |
| 19214 | sgl->addr_lo = bpl->addrLow; |
| 19215 | |
| 19216 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19217 | if ((i+1) == numBdes) |
| 19218 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19219 | else |
| 19220 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 19221 | /* swap the size field back to the cpu so we |
| 19222 | * can assign it to the sgl. |
| 19223 | */ |
| 19224 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 19225 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 19226 | /* The offsets in the sgl need to be accumulated |
| 19227 | * separately for the request and reply lists. |
| 19228 | * The request is always first, the reply follows. |
| 19229 | */ |
| 19230 | switch (cmd) { |
| 19231 | case CMD_GEN_REQUEST64_WQE: |
| 19232 | /* add up the reply sg entries */ |
| 19233 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 19234 | inbound++; |
| 19235 | /* first inbound? reset the offset */ |
| 19236 | if (inbound == 1) |
| 19237 | offset = 0; |
| 19238 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19239 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19240 | LPFC_SGE_TYPE_DATA); |
| 19241 | offset += bde.tus.f.bdeSize; |
| 19242 | break; |
| 19243 | case CMD_FCP_TRSP64_WQE: |
| 19244 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 19245 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19246 | LPFC_SGE_TYPE_DATA); |
| 19247 | break; |
| 19248 | case CMD_FCP_TSEND64_WQE: |
| 19249 | case CMD_FCP_TRECEIVE64_WQE: |
| 19250 | bf_set(lpfc_sli4_sge_type, sgl, |
| 19251 | bpl->tus.f.bdeFlags); |
| 19252 | if (i < 3) |
| 19253 | offset = 0; |
| 19254 | else |
| 19255 | offset += bde.tus.f.bdeSize; |
| 19256 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 19257 | break; |
| 19258 | } |
| 19259 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19260 | bpl++; |
| 19261 | sgl++; |
| 19262 | } |
| 19263 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 19264 | /* The addrHigh and addrLow fields of the BDE have not |
| 19265 | * been byteswapped yet so they need to be swapped |
| 19266 | * before putting them in the sgl. |
| 19267 | */ |
| 19268 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 19269 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 19270 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 19271 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 19272 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 19273 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 19274 | } |
| 19275 | return sglq->sli4_xritag; |
| 19276 | } |
| 19277 | |
| 19278 | /** |
| 19279 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 19280 | * @phba: Pointer to HBA context object. |
| 19281 | * @ring_number: Base sli ring number |
| 19282 | * @pwqe: Pointer to command WQE. |
| 19283 | **/ |
| 19284 | int |
| 19285 | lpfc_sli4_issue_wqe(struct lpfc_hba *phba, uint32_t ring_number, |
| 19286 | struct lpfc_iocbq *pwqe) |
| 19287 | { |
James Smart | 205e824 | 2018-03-05 12:04:03 -0800 | [diff] [blame] | 19288 | union lpfc_wqe128 *wqe = &pwqe->wqe; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19289 | struct lpfc_nvmet_rcv_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19290 | struct lpfc_queue *wq; |
| 19291 | struct lpfc_sglq *sglq; |
| 19292 | struct lpfc_sli_ring *pring; |
| 19293 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19294 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19295 | |
| 19296 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 19297 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 19298 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 19299 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 19300 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 19301 | if (!sglq) { |
| 19302 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19303 | return WQE_BUSY; |
| 19304 | } |
| 19305 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19306 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19307 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 19308 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19309 | return WQE_ERROR; |
| 19310 | } |
| 19311 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19312 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19313 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 19314 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19315 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19316 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19317 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19318 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19319 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19320 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19321 | return 0; |
| 19322 | } |
| 19323 | |
| 19324 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 19325 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 19326 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
| 19327 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; |
| 19328 | |
| 19329 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 19330 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; |
| 19331 | bf_set(wqe_cqid, &wqe->generic.wqe_com, |
| 19332 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19333 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19334 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19335 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19336 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19337 | } |
| 19338 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19339 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19340 | return 0; |
| 19341 | } |
| 19342 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19343 | /* NVMET requests */ |
| 19344 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 19345 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
| 19346 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; |
| 19347 | |
| 19348 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 19349 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 19350 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19351 | if (pwqe->sli4_xritag == NO_XRI) { |
| 19352 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19353 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19354 | } |
| 19355 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19356 | pwqe->sli4_xritag); |
| 19357 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; |
| 19358 | bf_set(wqe_cqid, &wqe->generic.wqe_com, |
| 19359 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19360 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19361 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19362 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19363 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19364 | } |
| 19365 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19366 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19367 | return 0; |
| 19368 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19369 | return WQE_ERROR; |
| 19370 | } |