| 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 | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Limited 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> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 38 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 39 | #include <linux/nvme-fc-driver.h> |
| 40 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 41 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 42 | #include "lpfc_hw.h" |
| 43 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 44 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 45 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 48 | #include "lpfc_scsi.h" |
| 49 | #include "lpfc_nvme.h" |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 50 | #include "lpfc_nvmet.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 51 | #include "lpfc_crtn.h" |
| 52 | #include "lpfc_logmsg.h" |
| 53 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 54 | #include "lpfc_debugfs.h" |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 55 | #include "lpfc_vport.h" |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 56 | #include "lpfc_version.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 57 | |
| 58 | /* There are only four IOCB completion types. */ |
| 59 | typedef enum _lpfc_iocb_type { |
| 60 | LPFC_UNKNOWN_IOCB, |
| 61 | LPFC_UNSOL_IOCB, |
| 62 | LPFC_SOL_IOCB, |
| 63 | LPFC_ABORT_IOCB |
| 64 | } lpfc_iocb_type; |
| 65 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 66 | |
| 67 | /* Provide function prototypes local to this module. */ |
| 68 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 69 | uint32_t); |
| 70 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 71 | uint8_t *, uint32_t *); |
| 72 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 73 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 74 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 75 | struct hbq_dmabuf *); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 76 | static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 77 | struct hbq_dmabuf *dmabuf); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 78 | 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] | 79 | struct lpfc_cqe *); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 80 | 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] | 81 | int); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 82 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, |
| 83 | struct lpfc_eqe *eqe, uint32_t qidx); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 84 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 85 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 86 | static int lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, |
| 87 | struct lpfc_sli_ring *pring, |
| 88 | struct lpfc_iocbq *cmdiocb); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 89 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 90 | static IOCB_t * |
| 91 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 92 | { |
| 93 | return &iocbq->iocb; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 98 | * @q: The Work Queue to operate on. |
| 99 | * @wqe: The work Queue Entry to put on the Work queue. |
| 100 | * |
| 101 | * This routine will copy the contents of @wqe to the next available entry on |
| 102 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 103 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 104 | * successful. If no entries are available on @q then this function will return |
| 105 | * -ENOMEM. |
| 106 | * The caller is expected to hold the hbalock when calling this routine. |
| 107 | **/ |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 108 | static int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 109 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) |
| 110 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 111 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 112 | struct lpfc_register doorbell; |
| 113 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 114 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 115 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 116 | /* sanity check on queue memory */ |
| 117 | if (unlikely(!q)) |
| 118 | return -ENOMEM; |
| 119 | temp_wqe = q->qe[q->host_index].wqe; |
| 120 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 121 | /* 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] | 122 | idx = ((q->host_index + 1) % q->entry_count); |
| 123 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 124 | q->WQ_overflow++; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 125 | return -EBUSY; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 126 | } |
| 127 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 128 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 129 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 130 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | 04673e3 | 2018-01-30 15:58:45 -0800 | [diff] [blame] | 131 | else |
| 132 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 0); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 133 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 134 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 135 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
James Smart | 6b3b3bd | 2016-12-19 15:07:30 -0800 | [diff] [blame] | 136 | /* ensure WQE bcopy flushed before doorbell write */ |
| 137 | wmb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 138 | |
| 139 | /* Update the host index before invoking device */ |
| 140 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 141 | |
| 142 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 143 | |
| 144 | /* Ring Doorbell */ |
| 145 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 146 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
| 147 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
| 148 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index); |
| 149 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
| 150 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 151 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 152 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 153 | } else { |
| 154 | return -EINVAL; |
| 155 | } |
| 156 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 163 | * @q: The Work Queue to operate on. |
| 164 | * @index: The index to advance the hba index to. |
| 165 | * |
| 166 | * This routine will update the HBA index of a queue to reflect consumption of |
| 167 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 168 | * an entry the host calls this function to update the queue's internal |
| 169 | * pointers. This routine returns the number of entries that were consumed by |
| 170 | * the HBA. |
| 171 | **/ |
| 172 | static uint32_t |
| 173 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 174 | { |
| 175 | uint32_t released = 0; |
| 176 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 177 | /* sanity check on queue memory */ |
| 178 | if (unlikely(!q)) |
| 179 | return 0; |
| 180 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 181 | if (q->hba_index == index) |
| 182 | return 0; |
| 183 | do { |
| 184 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 185 | released++; |
| 186 | } while (q->hba_index != index); |
| 187 | return released; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 192 | * @q: The Mailbox Queue to operate on. |
| 193 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 194 | * |
| 195 | * This routine will copy the contents of @mqe to the next available entry on |
| 196 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 197 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 198 | * successful. If no entries are available on @q then this function will return |
| 199 | * -ENOMEM. |
| 200 | * The caller is expected to hold the hbalock when calling this routine. |
| 201 | **/ |
| 202 | static uint32_t |
| 203 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 204 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 205 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 206 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 207 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 208 | /* sanity check on queue memory */ |
| 209 | if (unlikely(!q)) |
| 210 | return -ENOMEM; |
| 211 | temp_mqe = q->qe[q->host_index].mqe; |
| 212 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 213 | /* If the host has not yet processed the next entry then we are done */ |
| 214 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 215 | return -ENOMEM; |
| 216 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 217 | /* Save off the mailbox pointer for completion */ |
| 218 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 219 | |
| 220 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 221 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 222 | |
| 223 | /* Ring Doorbell */ |
| 224 | doorbell.word0 = 0; |
| 225 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 226 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 227 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 233 | * @q: The Mailbox Queue to operate on. |
| 234 | * |
| 235 | * This routine will update the HBA index of a queue to reflect consumption of |
| 236 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 237 | * an entry the host calls this function to update the queue's internal |
| 238 | * pointers. This routine returns the number of entries that were consumed by |
| 239 | * the HBA. |
| 240 | **/ |
| 241 | static uint32_t |
| 242 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 243 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 244 | /* sanity check on queue memory */ |
| 245 | if (unlikely(!q)) |
| 246 | return 0; |
| 247 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 248 | /* Clear the mailbox pointer for completion */ |
| 249 | q->phba->mbox = NULL; |
| 250 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 251 | return 1; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 256 | * @q: The Event Queue to get the first valid EQE from |
| 257 | * |
| 258 | * This routine will get the first valid Event Queue Entry from @q, update |
| 259 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 260 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 261 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 262 | **/ |
| 263 | static struct lpfc_eqe * |
| 264 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 265 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 266 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 267 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 268 | |
| 269 | /* sanity check on queue memory */ |
| 270 | if (unlikely(!q)) |
| 271 | return NULL; |
| 272 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 273 | |
| 274 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 275 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 276 | return NULL; |
| 277 | /* 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] | 278 | idx = ((q->hba_index + 1) % q->entry_count); |
| 279 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 280 | return NULL; |
| 281 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 282 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 283 | |
| 284 | /* |
| 285 | * insert barrier for instruction interlock : data from the hardware |
| 286 | * 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] | 287 | * upon. Speculative instructions were allowing a bcopy at the start |
| 288 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 289 | * after our return, to copy data before the valid bit check above |
| 290 | * was done. As such, some of the copied data was stale. The barrier |
| 291 | * ensures the check is before any data is copied. |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 292 | */ |
| 293 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 294 | return eqe; |
| 295 | } |
| 296 | |
| 297 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 298 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 299 | * @q: The Event Queue to disable interrupts |
| 300 | * |
| 301 | **/ |
| 302 | static inline void |
| 303 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 304 | { |
| 305 | struct lpfc_register doorbell; |
| 306 | |
| 307 | doorbell.word0 = 0; |
| 308 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 309 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 310 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 311 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 312 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
| 313 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 314 | } |
| 315 | |
| 316 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 317 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 318 | * @q: The Event Queue that the host has completed processing for. |
| 319 | * @arm: Indicates whether the host wants to arms this CQ. |
| 320 | * |
| 321 | * This routine will mark all Event Queue Entries on @q, from the last |
| 322 | * known completed entry to the last entry that was processed, as completed |
| 323 | * by clearing the valid bit for each completion queue entry. Then it will |
| 324 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 325 | * The internal host index in the @q will be updated by this routine to indicate |
| 326 | * that the host has finished processing the entries. The @arm parameter |
| 327 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 328 | * |
| 329 | * This function will return the number of EQEs that were popped. |
| 330 | **/ |
| 331 | uint32_t |
| 332 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 333 | { |
| 334 | uint32_t released = 0; |
| 335 | struct lpfc_eqe *temp_eqe; |
| 336 | struct lpfc_register doorbell; |
| 337 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 338 | /* sanity check on queue memory */ |
| 339 | if (unlikely(!q)) |
| 340 | return 0; |
| 341 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 342 | /* while there are valid entries */ |
| 343 | while (q->hba_index != q->host_index) { |
| 344 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 345 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 346 | released++; |
| 347 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 348 | } |
| 349 | if (unlikely(released == 0 && !arm)) |
| 350 | return 0; |
| 351 | |
| 352 | /* ring doorbell for number popped */ |
| 353 | doorbell.word0 = 0; |
| 354 | if (arm) { |
| 355 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 356 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 357 | } |
| 358 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 359 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 360 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 361 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 362 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 363 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 364 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 365 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 366 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 367 | return released; |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 372 | * @q: The Completion Queue to get the first valid CQE from |
| 373 | * |
| 374 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 375 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 376 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 377 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 378 | **/ |
| 379 | static struct lpfc_cqe * |
| 380 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 381 | { |
| 382 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 383 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 384 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 385 | /* sanity check on queue memory */ |
| 386 | if (unlikely(!q)) |
| 387 | return NULL; |
| 388 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 389 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 390 | if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 391 | return NULL; |
| 392 | /* 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] | 393 | idx = ((q->hba_index + 1) % q->entry_count); |
| 394 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 395 | return NULL; |
| 396 | |
| 397 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 398 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 399 | |
| 400 | /* |
| 401 | * insert barrier for instruction interlock : data from the hardware |
| 402 | * 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] | 403 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 404 | * instructions allowing action on content before valid bit checked, |
| 405 | * add barrier here as well. May not be needed as "content" is a |
| 406 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 407 | */ |
| 408 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 409 | return cqe; |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 414 | * @q: The Completion Queue that the host has completed processing for. |
| 415 | * @arm: Indicates whether the host wants to arms this CQ. |
| 416 | * |
| 417 | * This routine will mark all Completion queue entries on @q, from the last |
| 418 | * known completed entry to the last entry that was processed, as completed |
| 419 | * by clearing the valid bit for each completion queue entry. Then it will |
| 420 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 421 | * The internal host index in the @q will be updated by this routine to indicate |
| 422 | * that the host has finished processing the entries. The @arm parameter |
| 423 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 424 | * |
| 425 | * This function will return the number of CQEs that were released. |
| 426 | **/ |
| 427 | uint32_t |
| 428 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 429 | { |
| 430 | uint32_t released = 0; |
| 431 | struct lpfc_cqe *temp_qe; |
| 432 | struct lpfc_register doorbell; |
| 433 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 434 | /* sanity check on queue memory */ |
| 435 | if (unlikely(!q)) |
| 436 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 437 | /* while there are valid entries */ |
| 438 | while (q->hba_index != q->host_index) { |
| 439 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 440 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 441 | released++; |
| 442 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 443 | } |
| 444 | if (unlikely(released == 0 && !arm)) |
| 445 | return 0; |
| 446 | |
| 447 | /* ring doorbell for number popped */ |
| 448 | doorbell.word0 = 0; |
| 449 | if (arm) |
| 450 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 451 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 452 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 453 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 454 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 455 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 456 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 457 | return released; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 462 | * @q: The Header Receive Queue to operate on. |
| 463 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 464 | * |
| 465 | * This routine will copy the contents of @wqe to the next available entry on |
| 466 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 467 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 468 | * index that the rqe was copied to if successful. If no entries are available |
| 469 | * on @q then this function will return -ENOMEM. |
| 470 | * The caller is expected to hold the hbalock when calling this routine. |
| 471 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 472 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 473 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 474 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 475 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 476 | struct lpfc_rqe *temp_hrqe; |
| 477 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 478 | struct lpfc_register doorbell; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 479 | int hq_put_index; |
| 480 | int dq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 481 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 482 | /* sanity check on queue memory */ |
| 483 | if (unlikely(!hq) || unlikely(!dq)) |
| 484 | return -ENOMEM; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 485 | hq_put_index = hq->host_index; |
| 486 | dq_put_index = dq->host_index; |
| 487 | temp_hrqe = hq->qe[hq_put_index].rqe; |
| 488 | temp_drqe = dq->qe[dq_put_index].rqe; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 489 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 490 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 491 | return -EINVAL; |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 492 | if (hq_put_index != dq_put_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 493 | return -EINVAL; |
| 494 | /* 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] | 495 | if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 496 | return -EBUSY; |
| 497 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 498 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 499 | |
| 500 | /* Update the host index to point to the next slot */ |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 501 | hq->host_index = ((hq_put_index + 1) % hq->entry_count); |
| 502 | dq->host_index = ((dq_put_index + 1) % dq->entry_count); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 503 | hq->RQ_buf_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 504 | |
| 505 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 506 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 507 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 508 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 509 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
| 510 | hq->entry_repost); |
| 511 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 512 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 513 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
| 514 | hq->entry_repost); |
| 515 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 516 | hq->host_index); |
| 517 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 518 | } else { |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 522 | } |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 523 | return hq_put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /** |
| 527 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 528 | * @q: The Header Receive Queue to operate on. |
| 529 | * |
| 530 | * This routine will update the HBA index of a queue to reflect consumption of |
| 531 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 532 | * consumed an entry the host calls this function to update the queue's |
| 533 | * internal pointers. This routine returns the number of entries that were |
| 534 | * consumed by the HBA. |
| 535 | **/ |
| 536 | static uint32_t |
| 537 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 538 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 539 | /* sanity check on queue memory */ |
| 540 | if (unlikely(!hq) || unlikely(!dq)) |
| 541 | return 0; |
| 542 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 543 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 544 | return 0; |
| 545 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 546 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 547 | return 1; |
| 548 | } |
| 549 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 550 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 551 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 552 | * @phba: Pointer to HBA context object. |
| 553 | * @pring: Pointer to driver SLI ring object. |
| 554 | * |
| 555 | * This function returns pointer to next command iocb entry |
| 556 | * in the command ring. The caller must hold hbalock to prevent |
| 557 | * other threads consume the next command iocb. |
| 558 | * SLI-2/SLI-3 provide different sized iocbs. |
| 559 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 560 | static inline IOCB_t * |
| 561 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 562 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 563 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 564 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 565 | } |
| 566 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 567 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 568 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 569 | * @phba: Pointer to HBA context object. |
| 570 | * @pring: Pointer to driver SLI ring object. |
| 571 | * |
| 572 | * This function returns pointer to next response iocb entry |
| 573 | * in the response ring. The caller must hold hbalock to make sure |
| 574 | * that no other thread consume the next response iocb. |
| 575 | * SLI-2/SLI-3 provide different sized iocbs. |
| 576 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 577 | static inline IOCB_t * |
| 578 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 579 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 580 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 581 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 582 | } |
| 583 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 584 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 585 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 586 | * @phba: Pointer to HBA context object. |
| 587 | * |
| 588 | * This function is called with hbalock held. This function |
| 589 | * allocates a new driver iocb object from the iocb pool. If the |
| 590 | * allocation is successful, it returns pointer to the newly |
| 591 | * allocated iocb object else it returns NULL. |
| 592 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 593 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 594 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 595 | { |
| 596 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 597 | struct lpfc_iocbq * iocbq = NULL; |
| 598 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 599 | lockdep_assert_held(&phba->hbalock); |
| 600 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 601 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 602 | if (iocbq) |
| 603 | phba->iocb_cnt++; |
| 604 | if (phba->iocb_cnt > phba->iocb_max) |
| 605 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 606 | return iocbq; |
| 607 | } |
| 608 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 609 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 610 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 611 | * @phba: Pointer to HBA context object. |
| 612 | * @xritag: XRI value. |
| 613 | * |
| 614 | * This function clears the sglq pointer from the array of acive |
| 615 | * sglq's. The xritag that is passed in is used to index into the |
| 616 | * array. Before the xritag can be used it needs to be adjusted |
| 617 | * by subtracting the xribase. |
| 618 | * |
| 619 | * Returns sglq ponter = success, NULL = Failure. |
| 620 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 621 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 622 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 623 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 624 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 625 | |
| 626 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 627 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 628 | return sglq; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 633 | * @phba: Pointer to HBA context object. |
| 634 | * @xritag: XRI value. |
| 635 | * |
| 636 | * This function returns the sglq pointer from the array of acive |
| 637 | * sglq's. The xritag that is passed in is used to index into the |
| 638 | * array. Before the xritag can be used it needs to be adjusted |
| 639 | * by subtracting the xribase. |
| 640 | * |
| 641 | * Returns sglq ponter = success, NULL = Failure. |
| 642 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 643 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 644 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 645 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 646 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 647 | |
| 648 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 649 | return sglq; |
| 650 | } |
| 651 | |
| 652 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 653 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 654 | * @phba: Pointer to HBA context object. |
| 655 | * @xritag: xri used in this exchange. |
| 656 | * @rrq: The RRQ to be cleared. |
| 657 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 658 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 659 | void |
| 660 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 661 | uint16_t xritag, |
| 662 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 663 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 664 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 665 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 666 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 667 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 668 | |
| 669 | /* The target DID could have been swapped (cable swap) |
| 670 | * we should use the ndlp from the findnode if it is |
| 671 | * available. |
| 672 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 673 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 674 | ndlp = rrq->ndlp; |
| 675 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 676 | if (!ndlp) |
| 677 | goto out; |
| 678 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 679 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 680 | rrq->send_rrq = 0; |
| 681 | rrq->xritag = 0; |
| 682 | rrq->rrq_stop_time = 0; |
| 683 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 684 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 685 | mempool_free(rrq, phba->rrq_pool); |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 690 | * @phba: Pointer to HBA context object. |
| 691 | * |
| 692 | * This function is called with hbalock held. This function |
| 693 | * Checks if stop_time (ratov from setting rrq active) has |
| 694 | * been reached, if it has and the send_rrq flag is set then |
| 695 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 696 | * then it will just call the routine to clear the rrq and |
| 697 | * free the rrq resource. |
| 698 | * The timer is set to the next rrq that is going to expire before |
| 699 | * leaving the routine. |
| 700 | * |
| 701 | **/ |
| 702 | void |
| 703 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 704 | { |
| 705 | struct lpfc_node_rrq *rrq; |
| 706 | struct lpfc_node_rrq *nextrrq; |
| 707 | unsigned long next_time; |
| 708 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 709 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 710 | |
| 711 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 712 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 713 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 714 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 715 | &phba->active_rrq_list, list) { |
| 716 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 717 | list_move(&rrq->list, &send_rrq); |
| 718 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 719 | next_time = rrq->rrq_stop_time; |
| 720 | } |
| 721 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 722 | if ((!list_empty(&phba->active_rrq_list)) && |
| 723 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 724 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 725 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 726 | list_del(&rrq->list); |
| 727 | if (!rrq->send_rrq) |
| 728 | /* this call will free the rrq */ |
| 729 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 730 | else if (lpfc_send_rrq(phba, rrq)) { |
| 731 | /* if we send the rrq then the completion handler |
| 732 | * will clear the bit in the xribitmap. |
| 733 | */ |
| 734 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 735 | rrq); |
| 736 | } |
| 737 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /** |
| 741 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 742 | * @vport: Pointer to vport context object. |
| 743 | * @xri: The xri used in the exchange. |
| 744 | * @did: The targets DID for this exchange. |
| 745 | * |
| 746 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 747 | * rrq = rrq for this xri and target. |
| 748 | **/ |
| 749 | struct lpfc_node_rrq * |
| 750 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 751 | { |
| 752 | struct lpfc_hba *phba = vport->phba; |
| 753 | struct lpfc_node_rrq *rrq; |
| 754 | struct lpfc_node_rrq *nextrrq; |
| 755 | unsigned long iflags; |
| 756 | |
| 757 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 758 | return NULL; |
| 759 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 760 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 761 | if (rrq->vport == vport && rrq->xritag == xri && |
| 762 | rrq->nlp_DID == did){ |
| 763 | list_del(&rrq->list); |
| 764 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 765 | return rrq; |
| 766 | } |
| 767 | } |
| 768 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 769 | return NULL; |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 774 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 775 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 776 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 777 | * phba->active_rrq_list and clear the rrq. |
| 778 | * 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] | 779 | **/ |
| 780 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 781 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 782 | |
| 783 | { |
| 784 | struct lpfc_hba *phba = vport->phba; |
| 785 | struct lpfc_node_rrq *rrq; |
| 786 | struct lpfc_node_rrq *nextrrq; |
| 787 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 788 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 789 | |
| 790 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 791 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 792 | if (!ndlp) { |
| 793 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 794 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 795 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 796 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 797 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 798 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 799 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 800 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 801 | |
| 802 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 803 | list_del(&rrq->list); |
| 804 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 805 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 809 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 810 | * @phba: Pointer to HBA context object. |
| 811 | * @ndlp: Targets nodelist pointer for this exchange. |
| 812 | * @xritag the xri in the bitmap to test. |
| 813 | * |
| 814 | * This function is called with hbalock held. This function |
| 815 | * returns 0 = rrq not active for this xri |
| 816 | * 1 = rrq is valid for this xri. |
| 817 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 818 | int |
| 819 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 820 | uint16_t xritag) |
| 821 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 822 | lockdep_assert_held(&phba->hbalock); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 823 | if (!ndlp) |
| 824 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 825 | if (!ndlp->active_rrqs_xri_bitmap) |
| 826 | return 0; |
| 827 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 828 | return 1; |
| 829 | else |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | /** |
| 834 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 835 | * @phba: Pointer to HBA context object. |
| 836 | * @ndlp: nodelist pointer for this target. |
| 837 | * @xritag: xri used in this exchange. |
| 838 | * @rxid: Remote Exchange ID. |
| 839 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 840 | * |
| 841 | * This function takes the hbalock. |
| 842 | * The active bit is always set in the active rrq xri_bitmap even |
| 843 | * if there is no slot avaiable for the other rrq information. |
| 844 | * |
| 845 | * returns 0 rrq actived for this xri |
| 846 | * < 0 No memory or invalid ndlp. |
| 847 | **/ |
| 848 | int |
| 849 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 850 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 851 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 852 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 853 | struct lpfc_node_rrq *rrq; |
| 854 | int empty; |
| 855 | |
| 856 | if (!ndlp) |
| 857 | return -EINVAL; |
| 858 | |
| 859 | if (!phba->cfg_enable_rrq) |
| 860 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 861 | |
| 862 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 863 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 864 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 865 | goto out; |
| 866 | } |
| 867 | |
| 868 | /* |
| 869 | * set the active bit even if there is no mem available. |
| 870 | */ |
| 871 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 872 | goto out; |
| 873 | |
| 874 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 875 | goto out; |
| 876 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 877 | if (!ndlp->active_rrqs_xri_bitmap) |
| 878 | goto out; |
| 879 | |
| 880 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 881 | goto out; |
| 882 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 883 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 884 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 885 | if (!rrq) { |
| 886 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 887 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 888 | " DID:0x%x Send:%d\n", |
| 889 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 890 | return -EINVAL; |
| 891 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 892 | if (phba->cfg_enable_rrq == 1) |
| 893 | rrq->send_rrq = send_rrq; |
| 894 | else |
| 895 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 896 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 897 | rrq->rrq_stop_time = jiffies + |
| 898 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 899 | rrq->ndlp = ndlp; |
| 900 | rrq->nlp_DID = ndlp->nlp_DID; |
| 901 | rrq->vport = ndlp->vport; |
| 902 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 903 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 904 | empty = list_empty(&phba->active_rrq_list); |
| 905 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 906 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 907 | if (empty) |
| 908 | lpfc_worker_wake_up(phba); |
| 909 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 910 | return 0; |
| 911 | out: |
| 912 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 913 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 914 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 915 | " DID:0x%x Send:%d\n", |
| 916 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 917 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 921 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 922 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 923 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 924 | * |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 925 | * This function is called with the ring lock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 926 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 927 | * list is not empty then it is successful, it returns pointer to the newly |
| 928 | * allocated sglq object else it returns NULL. |
| 929 | **/ |
| 930 | static struct lpfc_sglq * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 931 | __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] | 932 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 933 | 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] | 934 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 935 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 936 | struct lpfc_scsi_buf *lpfc_cmd; |
| 937 | struct lpfc_nodelist *ndlp; |
| 938 | int found = 0; |
| 939 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 940 | lockdep_assert_held(&phba->hbalock); |
| 941 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 942 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 943 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 944 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 945 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 946 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 947 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 948 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 949 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 950 | ndlp = NULL; |
| 951 | else |
| 952 | ndlp = piocbq->context_un.ndlp; |
| 953 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 954 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 955 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 956 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 957 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 958 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 959 | start_sglq = sglq; |
| 960 | while (!found) { |
| 961 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 962 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 963 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 964 | test_bit(sglq->sli4_lxritag, |
| 965 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 966 | /* This xri has an rrq outstanding for this DID. |
| 967 | * put it back in the list and get another xri. |
| 968 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 969 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 970 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 971 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 972 | struct lpfc_sglq, list); |
| 973 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 974 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 975 | sglq = NULL; |
| 976 | break; |
| 977 | } else |
| 978 | continue; |
| 979 | } |
| 980 | sglq->ndlp = ndlp; |
| 981 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 982 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 983 | sglq->state = SGL_ALLOCATED; |
| 984 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 985 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 986 | return sglq; |
| 987 | } |
| 988 | |
| 989 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 990 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 991 | * @phba: Pointer to HBA context object. |
| 992 | * @piocb: Pointer to the iocbq. |
| 993 | * |
| 994 | * This function is called with the sgl_list lock held. This function |
| 995 | * gets a new driver sglq object from the sglq list. If the |
| 996 | * list is not empty then it is successful, it returns pointer to the newly |
| 997 | * allocated sglq object else it returns NULL. |
| 998 | **/ |
| 999 | struct lpfc_sglq * |
| 1000 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 1001 | { |
| 1002 | struct list_head *lpfc_nvmet_sgl_list; |
| 1003 | struct lpfc_sglq *sglq = NULL; |
| 1004 | |
| 1005 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1006 | |
| 1007 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1008 | |
| 1009 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1010 | if (!sglq) |
| 1011 | return NULL; |
| 1012 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1013 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1014 | return sglq; |
| 1015 | } |
| 1016 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1017 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1018 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1019 | * @phba: Pointer to HBA context object. |
| 1020 | * |
| 1021 | * This function is called with no lock held. This function |
| 1022 | * allocates a new driver iocb object from the iocb pool. If the |
| 1023 | * allocation is successful, it returns pointer to the newly |
| 1024 | * allocated iocb object else it returns NULL. |
| 1025 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1026 | struct lpfc_iocbq * |
| 1027 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1028 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1029 | struct lpfc_iocbq * iocbq = NULL; |
| 1030 | unsigned long iflags; |
| 1031 | |
| 1032 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1033 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1034 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1035 | return iocbq; |
| 1036 | } |
| 1037 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1038 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1039 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1040 | * @phba: Pointer to HBA context object. |
| 1041 | * @iocbq: Pointer to driver iocb object. |
| 1042 | * |
| 1043 | * This function is called with hbalock held to release driver |
| 1044 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1045 | * does not change for each use of the iocb object. This function |
| 1046 | * clears all other fields of the iocb object when it is freed. |
| 1047 | * The sqlq structure that holds the xritag and phys and virtual |
| 1048 | * mappings for the scatter gather list is retrieved from the |
| 1049 | * active array of sglq. The get of the sglq pointer also clears |
| 1050 | * the entry in the array. If the status of the IO indiactes that |
| 1051 | * this IO was aborted then the sglq entry it put on the |
| 1052 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1053 | * 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] | 1054 | * entry is added to the free list (lpfc_els_sgl_list). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1055 | **/ |
| 1056 | static void |
| 1057 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1058 | { |
| 1059 | struct lpfc_sglq *sglq; |
| 1060 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1061 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1062 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1063 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1064 | lockdep_assert_held(&phba->hbalock); |
| 1065 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1066 | if (iocbq->sli4_xritag == NO_XRI) |
| 1067 | sglq = NULL; |
| 1068 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1069 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1070 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1071 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1072 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1073 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1074 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1075 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1076 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1077 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1078 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1079 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1080 | spin_unlock_irqrestore( |
| 1081 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1082 | goto out; |
| 1083 | } |
| 1084 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1085 | pring = phba->sli4_hba.els_wq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1086 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1087 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1088 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1089 | iflag); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1090 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1091 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1092 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1093 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1094 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1095 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1096 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1097 | sglq->state = SGL_FREED; |
| 1098 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1099 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1100 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1101 | spin_unlock_irqrestore( |
| 1102 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1103 | |
| 1104 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1105 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1106 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1107 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1108 | } |
| 1109 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1110 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1111 | /* |
| 1112 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1113 | */ |
| 1114 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1115 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1116 | iocbq->sli4_xritag = NO_XRI; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1117 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 1118 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1119 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1120 | } |
| 1121 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1122 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1123 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1124 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1125 | * @phba: Pointer to HBA context object. |
| 1126 | * @iocbq: Pointer to driver iocb object. |
| 1127 | * |
| 1128 | * This function is called with hbalock held to release driver |
| 1129 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1130 | * does not change for each use of the iocb object. This function |
| 1131 | * clears all other fields of the iocb object when it is freed. |
| 1132 | **/ |
| 1133 | static void |
| 1134 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1135 | { |
| 1136 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1137 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1138 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1139 | |
| 1140 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1141 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1142 | */ |
| 1143 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1144 | iocbq->sli4_xritag = NO_XRI; |
| 1145 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1146 | } |
| 1147 | |
| 1148 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1149 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1150 | * @phba: Pointer to HBA context object. |
| 1151 | * @iocbq: Pointer to driver iocb object. |
| 1152 | * |
| 1153 | * This function is called with hbalock held to release driver |
| 1154 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1155 | * does not change for each use of the iocb object. This function |
| 1156 | * clears all other fields of the iocb object when it is freed. |
| 1157 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1158 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1159 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1160 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1161 | lockdep_assert_held(&phba->hbalock); |
| 1162 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1163 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1164 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1165 | } |
| 1166 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1167 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1168 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1169 | * @phba: Pointer to HBA context object. |
| 1170 | * @iocbq: Pointer to driver iocb object. |
| 1171 | * |
| 1172 | * This function is called with no lock held to release the iocb to |
| 1173 | * iocb pool. |
| 1174 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1175 | void |
| 1176 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1177 | { |
| 1178 | unsigned long iflags; |
| 1179 | |
| 1180 | /* |
| 1181 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1182 | */ |
| 1183 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1184 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1185 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1186 | } |
| 1187 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1188 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1189 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1190 | * @phba: Pointer to HBA context object. |
| 1191 | * @iocblist: List of IOCBs. |
| 1192 | * @ulpstatus: ULP status in IOCB command field. |
| 1193 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1194 | * |
| 1195 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1196 | * on the list by invoking the complete callback function associated with the |
| 1197 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1198 | * fields. |
| 1199 | **/ |
| 1200 | void |
| 1201 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1202 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1203 | { |
| 1204 | struct lpfc_iocbq *piocb; |
| 1205 | |
| 1206 | while (!list_empty(iocblist)) { |
| 1207 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1208 | if (!piocb->iocb_cmpl) |
| 1209 | lpfc_sli_release_iocbq(phba, piocb); |
| 1210 | else { |
| 1211 | piocb->iocb.ulpStatus = ulpstatus; |
| 1212 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1213 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1214 | } |
| 1215 | } |
| 1216 | return; |
| 1217 | } |
| 1218 | |
| 1219 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1220 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1221 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1222 | * |
| 1223 | * This function is called by ring event handler function to get the iocb type. |
| 1224 | * This function translates the iocb command to an iocb command type used to |
| 1225 | * decide the final disposition of each completed IOCB. |
| 1226 | * The function returns |
| 1227 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1228 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1229 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1230 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1231 | * |
| 1232 | * The caller is not required to hold any lock. |
| 1233 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1234 | static lpfc_iocb_type |
| 1235 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1236 | { |
| 1237 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1238 | |
| 1239 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1240 | return 0; |
| 1241 | |
| 1242 | switch (iocb_cmnd) { |
| 1243 | case CMD_XMIT_SEQUENCE_CR: |
| 1244 | case CMD_XMIT_SEQUENCE_CX: |
| 1245 | case CMD_XMIT_BCAST_CN: |
| 1246 | case CMD_XMIT_BCAST_CX: |
| 1247 | case CMD_ELS_REQUEST_CR: |
| 1248 | case CMD_ELS_REQUEST_CX: |
| 1249 | case CMD_CREATE_XRI_CR: |
| 1250 | case CMD_CREATE_XRI_CX: |
| 1251 | case CMD_GET_RPI_CN: |
| 1252 | case CMD_XMIT_ELS_RSP_CX: |
| 1253 | case CMD_GET_RPI_CR: |
| 1254 | case CMD_FCP_IWRITE_CR: |
| 1255 | case CMD_FCP_IWRITE_CX: |
| 1256 | case CMD_FCP_IREAD_CR: |
| 1257 | case CMD_FCP_IREAD_CX: |
| 1258 | case CMD_FCP_ICMND_CR: |
| 1259 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1260 | case CMD_FCP_TSEND_CX: |
| 1261 | case CMD_FCP_TRSP_CX: |
| 1262 | case CMD_FCP_TRECEIVE_CX: |
| 1263 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1264 | case CMD_ADAPTER_MSG: |
| 1265 | case CMD_ADAPTER_DUMP: |
| 1266 | case CMD_XMIT_SEQUENCE64_CR: |
| 1267 | case CMD_XMIT_SEQUENCE64_CX: |
| 1268 | case CMD_XMIT_BCAST64_CN: |
| 1269 | case CMD_XMIT_BCAST64_CX: |
| 1270 | case CMD_ELS_REQUEST64_CR: |
| 1271 | case CMD_ELS_REQUEST64_CX: |
| 1272 | case CMD_FCP_IWRITE64_CR: |
| 1273 | case CMD_FCP_IWRITE64_CX: |
| 1274 | case CMD_FCP_IREAD64_CR: |
| 1275 | case CMD_FCP_IREAD64_CX: |
| 1276 | case CMD_FCP_ICMND64_CR: |
| 1277 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1278 | case CMD_FCP_TSEND64_CX: |
| 1279 | case CMD_FCP_TRSP64_CX: |
| 1280 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1281 | case CMD_GEN_REQUEST64_CR: |
| 1282 | case CMD_GEN_REQUEST64_CX: |
| 1283 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1284 | case DSSCMD_IWRITE64_CR: |
| 1285 | case DSSCMD_IWRITE64_CX: |
| 1286 | case DSSCMD_IREAD64_CR: |
| 1287 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1288 | type = LPFC_SOL_IOCB; |
| 1289 | break; |
| 1290 | case CMD_ABORT_XRI_CN: |
| 1291 | case CMD_ABORT_XRI_CX: |
| 1292 | case CMD_CLOSE_XRI_CN: |
| 1293 | case CMD_CLOSE_XRI_CX: |
| 1294 | case CMD_XRI_ABORTED_CX: |
| 1295 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1296 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1297 | type = LPFC_ABORT_IOCB; |
| 1298 | break; |
| 1299 | case CMD_RCV_SEQUENCE_CX: |
| 1300 | case CMD_RCV_ELS_REQ_CX: |
| 1301 | case CMD_RCV_SEQUENCE64_CX: |
| 1302 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1303 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1304 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1305 | case CMD_IOCB_RCV_ELS64_CX: |
| 1306 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1307 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1308 | type = LPFC_UNSOL_IOCB; |
| 1309 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1310 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1311 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1312 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1313 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1314 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1315 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1316 | case CMD_IOCB_RET_HBQE64_CN: |
| 1317 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1318 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1319 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1320 | case CMD_IOCB_LOGENTRY_CN: |
| 1321 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1322 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1323 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1324 | type = LPFC_UNKNOWN_IOCB; |
| 1325 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1326 | default: |
| 1327 | type = LPFC_UNKNOWN_IOCB; |
| 1328 | break; |
| 1329 | } |
| 1330 | |
| 1331 | return type; |
| 1332 | } |
| 1333 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1334 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1335 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1336 | * @phba: Pointer to HBA context object. |
| 1337 | * |
| 1338 | * This function is called from SLI initialization code |
| 1339 | * to configure every ring of the HBA's SLI interface. The |
| 1340 | * caller is not required to hold any lock. This function issues |
| 1341 | * a config_ring mailbox command for each ring. |
| 1342 | * This function returns zero if successful else returns a negative |
| 1343 | * error code. |
| 1344 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1345 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1346 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1347 | { |
| 1348 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1349 | LPFC_MBOXQ_t *pmb; |
| 1350 | MAILBOX_t *pmbox; |
| 1351 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1352 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1353 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1354 | if (!pmb) |
| 1355 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1356 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1357 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1358 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1359 | lpfc_config_ring(phba, i, pmb); |
| 1360 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1361 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1362 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1363 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1364 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1365 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1366 | rc, pmbox->mbxCommand, |
| 1367 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1368 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1369 | ret = -ENXIO; |
| 1370 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1371 | } |
| 1372 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1373 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1374 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1375 | } |
| 1376 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1377 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1378 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1379 | * @phba: Pointer to HBA context object. |
| 1380 | * @pring: Pointer to driver SLI ring object. |
| 1381 | * @piocb: Pointer to the driver iocb object. |
| 1382 | * |
| 1383 | * This function is called with hbalock held. The function adds the |
| 1384 | * new iocb to txcmplq of the given ring. This function always returns |
| 1385 | * 0. If this function is called for ELS ring, this function checks if |
| 1386 | * there is a vport associated with the ELS command. This function also |
| 1387 | * starts els_tmofunc timer if this is an ELS command. |
| 1388 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1389 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1390 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1391 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1392 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1393 | lockdep_assert_held(&phba->hbalock); |
| 1394 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1395 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1396 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1397 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1398 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1399 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1400 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1401 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1402 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1403 | BUG_ON(!piocb->vport); |
| 1404 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1405 | mod_timer(&piocb->vport->els_tmofunc, |
| 1406 | jiffies + |
| 1407 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1408 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1409 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1410 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | } |
| 1412 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1413 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1414 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1415 | * @phba: Pointer to HBA context object. |
| 1416 | * @pring: Pointer to driver SLI ring object. |
| 1417 | * |
| 1418 | * This function is called with hbalock held to get next |
| 1419 | * iocb in txq of the given ring. If there is any iocb in |
| 1420 | * the txq, the function returns first iocb in the list after |
| 1421 | * removing the iocb from the list, else it returns NULL. |
| 1422 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1423 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1424 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1425 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1426 | struct lpfc_iocbq *cmd_iocb; |
| 1427 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1428 | lockdep_assert_held(&phba->hbalock); |
| 1429 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1430 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1431 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1432 | } |
| 1433 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1434 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1435 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1436 | * @phba: Pointer to HBA context object. |
| 1437 | * @pring: Pointer to driver SLI ring object. |
| 1438 | * |
| 1439 | * This function is called with hbalock held and the caller must post the |
| 1440 | * iocb without releasing the lock. If the caller releases the lock, |
| 1441 | * iocb slot returned by the function is not guaranteed to be available. |
| 1442 | * The function returns pointer to the next available iocb slot if there |
| 1443 | * is available slot in the ring, else it returns NULL. |
| 1444 | * If the get index of the ring is ahead of the put index, the function |
| 1445 | * will post an error attention event to the worker thread to take the |
| 1446 | * HBA to offline state. |
| 1447 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1448 | static IOCB_t * |
| 1449 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1450 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1451 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1452 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1453 | |
| 1454 | lockdep_assert_held(&phba->hbalock); |
| 1455 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1456 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1457 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1458 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1459 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1460 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1461 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1462 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1463 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1464 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1465 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1466 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1467 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1468 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1469 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1470 | pring->sli.sli3.local_getidx, |
| 1471 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1472 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1473 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1474 | /* |
| 1475 | * All error attention handlers are posted to |
| 1476 | * worker thread |
| 1477 | */ |
| 1478 | phba->work_ha |= HA_ERATT; |
| 1479 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1480 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1481 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1482 | |
| 1483 | return NULL; |
| 1484 | } |
| 1485 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1486 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1487 | return NULL; |
| 1488 | } |
| 1489 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1490 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1491 | } |
| 1492 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1493 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1494 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1495 | * @phba: Pointer to HBA context object. |
| 1496 | * @iocbq: Pointer to driver iocb object. |
| 1497 | * |
| 1498 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1499 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1500 | * array and assigns a new iotag. |
| 1501 | * The function returns the allocated iotag if successful, else returns zero. |
| 1502 | * Zero is not a valid iotag. |
| 1503 | * The caller is not required to hold any lock. |
| 1504 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1505 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1506 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1507 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1508 | struct lpfc_iocbq **new_arr; |
| 1509 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1510 | size_t new_len; |
| 1511 | struct lpfc_sli *psli = &phba->sli; |
| 1512 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1513 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1514 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1515 | iotag = psli->last_iotag; |
| 1516 | if(++iotag < psli->iocbq_lookup_len) { |
| 1517 | psli->last_iotag = iotag; |
| 1518 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1519 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1520 | iocbq->iotag = iotag; |
| 1521 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1522 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1523 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1524 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1525 | spin_unlock_irq(&phba->hbalock); |
| 1526 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1527 | GFP_KERNEL); |
| 1528 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1529 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1530 | old_arr = psli->iocbq_lookup; |
| 1531 | if (new_len <= psli->iocbq_lookup_len) { |
| 1532 | /* highly unprobable case */ |
| 1533 | kfree(new_arr); |
| 1534 | iotag = psli->last_iotag; |
| 1535 | if(++iotag < psli->iocbq_lookup_len) { |
| 1536 | psli->last_iotag = iotag; |
| 1537 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1538 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1539 | iocbq->iotag = iotag; |
| 1540 | return iotag; |
| 1541 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1542 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1543 | return 0; |
| 1544 | } |
| 1545 | if (psli->iocbq_lookup) |
| 1546 | memcpy(new_arr, old_arr, |
| 1547 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1548 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1549 | psli->iocbq_lookup = new_arr; |
| 1550 | psli->iocbq_lookup_len = new_len; |
| 1551 | psli->last_iotag = iotag; |
| 1552 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1553 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1554 | iocbq->iotag = iotag; |
| 1555 | kfree(old_arr); |
| 1556 | return iotag; |
| 1557 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1558 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1559 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1560 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1561 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1562 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1563 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1564 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1565 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1566 | } |
| 1567 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1568 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1569 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1570 | * @phba: Pointer to HBA context object. |
| 1571 | * @pring: Pointer to driver SLI ring object. |
| 1572 | * @iocb: Pointer to iocb slot in the ring. |
| 1573 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1574 | * posted to firmware. |
| 1575 | * |
| 1576 | * This function is called with hbalock held to post a new iocb to |
| 1577 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1578 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1579 | * a completion call back for this iocb else the function will free the |
| 1580 | * iocb object. |
| 1581 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1582 | static void |
| 1583 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1584 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1585 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1586 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1587 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1588 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1589 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1590 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1591 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1592 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1593 | if (pring->ringno == LPFC_ELS_RING) { |
| 1594 | lpfc_debugfs_slow_ring_trc(phba, |
| 1595 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1596 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1597 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1598 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1599 | } |
| 1600 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1601 | /* |
| 1602 | * Issue iocb command to adapter |
| 1603 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1604 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1605 | wmb(); |
| 1606 | pring->stats.iocb_cmd++; |
| 1607 | |
| 1608 | /* |
| 1609 | * If there is no completion routine to call, we can release the |
| 1610 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1611 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1612 | */ |
| 1613 | if (nextiocb->iocb_cmpl) |
| 1614 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1615 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1616 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1617 | |
| 1618 | /* |
| 1619 | * Let the HBA know what IOCB slot will be the next one the |
| 1620 | * driver will put a command into. |
| 1621 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1622 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1623 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1624 | } |
| 1625 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1626 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1627 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1628 | * @phba: Pointer to HBA context object. |
| 1629 | * @pring: Pointer to driver SLI ring object. |
| 1630 | * |
| 1631 | * The caller is not required to hold any lock for calling this function. |
| 1632 | * This function updates the chip attention bits for the ring to inform firmware |
| 1633 | * that there are pending work to be done for this ring and requests an |
| 1634 | * interrupt when there is space available in the ring. This function is |
| 1635 | * called when the driver is unable to post more iocbs to the ring due |
| 1636 | * to unavailability of space in the ring. |
| 1637 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1638 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1639 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1640 | { |
| 1641 | int ringno = pring->ringno; |
| 1642 | |
| 1643 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1644 | |
| 1645 | wmb(); |
| 1646 | |
| 1647 | /* |
| 1648 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1649 | * The HBA will tell us when an IOCB entry is available. |
| 1650 | */ |
| 1651 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1652 | readl(phba->CAregaddr); /* flush */ |
| 1653 | |
| 1654 | pring->stats.iocb_cmd_full++; |
| 1655 | } |
| 1656 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1657 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1658 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1659 | * @phba: Pointer to HBA context object. |
| 1660 | * @pring: Pointer to driver SLI ring object. |
| 1661 | * |
| 1662 | * This function updates the chip attention register bit for the |
| 1663 | * given ring to inform HBA that there is more work to be done |
| 1664 | * in this ring. The caller is not required to hold any lock. |
| 1665 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1666 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1667 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1668 | { |
| 1669 | int ringno = pring->ringno; |
| 1670 | |
| 1671 | /* |
| 1672 | * Tell the HBA that there is work to do in this ring. |
| 1673 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1674 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1675 | wmb(); |
| 1676 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1677 | readl(phba->CAregaddr); /* flush */ |
| 1678 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1679 | } |
| 1680 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1681 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1682 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1683 | * @phba: Pointer to HBA context object. |
| 1684 | * @pring: Pointer to driver SLI ring object. |
| 1685 | * |
| 1686 | * This function is called with hbalock held to post pending iocbs |
| 1687 | * in the txq to the firmware. This function is called when driver |
| 1688 | * detects space available in the ring. |
| 1689 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1690 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1691 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1692 | { |
| 1693 | IOCB_t *iocb; |
| 1694 | struct lpfc_iocbq *nextiocb; |
| 1695 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1696 | lockdep_assert_held(&phba->hbalock); |
| 1697 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1698 | /* |
| 1699 | * Check to see if: |
| 1700 | * (a) there is anything on the txq to send |
| 1701 | * (b) link is up |
| 1702 | * (c) link attention events can be processed (fcp ring only) |
| 1703 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1704 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1705 | |
| 1706 | if (lpfc_is_link_up(phba) && |
| 1707 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1708 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1709 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1710 | |
| 1711 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1712 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1713 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1714 | |
| 1715 | if (iocb) |
| 1716 | lpfc_sli_update_ring(phba, pring); |
| 1717 | else |
| 1718 | lpfc_sli_update_full_ring(phba, pring); |
| 1719 | } |
| 1720 | |
| 1721 | return; |
| 1722 | } |
| 1723 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1724 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1725 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1726 | * @phba: Pointer to HBA context object. |
| 1727 | * @hbqno: HBQ number. |
| 1728 | * |
| 1729 | * This function is called with hbalock held to get the next |
| 1730 | * available slot for the given HBQ. If there is free slot |
| 1731 | * available for the HBQ it will return pointer to the next available |
| 1732 | * HBQ entry else it will return NULL. |
| 1733 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1734 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1735 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1736 | { |
| 1737 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1738 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1739 | lockdep_assert_held(&phba->hbalock); |
| 1740 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1741 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1742 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1743 | hbqp->next_hbqPutIdx = 0; |
| 1744 | |
| 1745 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1746 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1747 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1748 | |
| 1749 | hbqp->local_hbqGetIdx = getidx; |
| 1750 | |
| 1751 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1752 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1753 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1754 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1755 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1756 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1757 | hbqp->entry_count); |
| 1758 | |
| 1759 | phba->link_state = LPFC_HBA_ERROR; |
| 1760 | return NULL; |
| 1761 | } |
| 1762 | |
| 1763 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1764 | return NULL; |
| 1765 | } |
| 1766 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1767 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1768 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1769 | } |
| 1770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1771 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1772 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1773 | * @phba: Pointer to HBA context object. |
| 1774 | * |
| 1775 | * This function is called with no lock held to free all the |
| 1776 | * hbq buffers while uninitializing the SLI interface. It also |
| 1777 | * frees the HBQ buffers returned by the firmware but not yet |
| 1778 | * processed by the upper layers. |
| 1779 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1780 | void |
| 1781 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1782 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1783 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1784 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1785 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1786 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1787 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1788 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1789 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1790 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1791 | for (i = 0; i < hbq_count; ++i) { |
| 1792 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1793 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1794 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1795 | list_del(&hbq_buf->dbuf.list); |
| 1796 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1797 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1798 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1799 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1800 | |
| 1801 | /* Mark the HBQs not in use */ |
| 1802 | phba->hbq_in_use = 0; |
| 1803 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1804 | } |
| 1805 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1806 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1807 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1808 | * @phba: Pointer to HBA context object. |
| 1809 | * @hbqno: HBQ number. |
| 1810 | * @hbq_buf: Pointer to HBQ buffer. |
| 1811 | * |
| 1812 | * This function is called with the hbalock held to post a |
| 1813 | * hbq buffer to the firmware. If the function finds an empty |
| 1814 | * slot in the HBQ, it will post the buffer. The function will return |
| 1815 | * pointer to the hbq entry if it successfully post the buffer |
| 1816 | * else it will return NULL. |
| 1817 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1818 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1819 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1820 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1821 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1822 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1823 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1824 | } |
| 1825 | |
| 1826 | /** |
| 1827 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 1828 | * @phba: Pointer to HBA context object. |
| 1829 | * @hbqno: HBQ number. |
| 1830 | * @hbq_buf: Pointer to HBQ buffer. |
| 1831 | * |
| 1832 | * This function is called with the hbalock held to post a hbq buffer to the |
| 1833 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1834 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1835 | * it successfully post the buffer else it will return an error. |
| 1836 | **/ |
| 1837 | static int |
| 1838 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1839 | struct hbq_dmabuf *hbq_buf) |
| 1840 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1841 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1842 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1843 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1844 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1845 | /* Get next HBQ entry slot to use */ |
| 1846 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1847 | if (hbqe) { |
| 1848 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1849 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1850 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1851 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1852 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1853 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1854 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1855 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1856 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1857 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1858 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1859 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1860 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1861 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1862 | return 0; |
| 1863 | } else |
| 1864 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1865 | } |
| 1866 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1867 | /** |
| 1868 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1869 | * @phba: Pointer to HBA context object. |
| 1870 | * @hbqno: HBQ number. |
| 1871 | * @hbq_buf: Pointer to HBQ buffer. |
| 1872 | * |
| 1873 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1874 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1875 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1876 | **/ |
| 1877 | static int |
| 1878 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1879 | struct hbq_dmabuf *hbq_buf) |
| 1880 | { |
| 1881 | int rc; |
| 1882 | struct lpfc_rqe hrqe; |
| 1883 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1884 | struct lpfc_queue *hrq; |
| 1885 | struct lpfc_queue *drq; |
| 1886 | |
| 1887 | if (hbqno != LPFC_ELS_HBQ) |
| 1888 | return 1; |
| 1889 | hrq = phba->sli4_hba.hdr_rq; |
| 1890 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1891 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1892 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1893 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1894 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1895 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1896 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1897 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1898 | if (rc < 0) |
| 1899 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1900 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1901 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1902 | return 0; |
| 1903 | } |
| 1904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1905 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1906 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1907 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1908 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1909 | .mask_count = 0, |
| 1910 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1911 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1912 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1913 | .init_count = 40, |
| 1914 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1915 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1916 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1917 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1918 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1919 | &lpfc_els_hbq, |
| 1920 | }; |
| 1921 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1922 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1923 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1924 | * @phba: Pointer to HBA context object. |
| 1925 | * @hbqno: HBQ number. |
| 1926 | * @count: Number of HBQ buffers to be posted. |
| 1927 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1928 | * This function is called with no lock held to post more hbq buffers to the |
| 1929 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1930 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1931 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1932 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1933 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1934 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1935 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1936 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1937 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1938 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1939 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1940 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1941 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1942 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1943 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1944 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1945 | phba->hbqs[hbqno].buffer_count; |
| 1946 | if (!count) |
| 1947 | return 0; |
| 1948 | /* Allocate HBQ entries */ |
| 1949 | for (i = 0; i < count; i++) { |
| 1950 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1951 | if (!hbq_buffer) |
| 1952 | break; |
| 1953 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1954 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1955 | /* Check whether HBQ is still in use */ |
| 1956 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1957 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1958 | goto err; |
| 1959 | while (!list_empty(&hbq_buf_list)) { |
| 1960 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1961 | dbuf.list); |
| 1962 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1963 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1964 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1965 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1966 | posted++; |
| 1967 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1968 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1969 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1970 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1971 | return posted; |
| 1972 | err: |
| 1973 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1974 | while (!list_empty(&hbq_buf_list)) { |
| 1975 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1976 | dbuf.list); |
| 1977 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1978 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1979 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1980 | } |
| 1981 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1982 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1983 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1984 | * @phba: Pointer to HBA context object. |
| 1985 | * @qno: HBQ number. |
| 1986 | * |
| 1987 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1988 | * is called with no lock held. The function returns the number of HBQ entries |
| 1989 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1990 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1991 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1992 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1993 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1994 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1995 | return 0; |
| 1996 | else |
| 1997 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1998 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1999 | } |
| 2000 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2001 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2002 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2003 | * @phba: Pointer to HBA context object. |
| 2004 | * @qno: HBQ queue number. |
| 2005 | * |
| 2006 | * This function is called from SLI initialization code path with |
| 2007 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2008 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2009 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2010 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2011 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2012 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2013 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2014 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2015 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2016 | else |
| 2017 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2018 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2019 | } |
| 2020 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2021 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2022 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 2023 | * @phba: Pointer to HBA context object. |
| 2024 | * @hbqno: HBQ number. |
| 2025 | * |
| 2026 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2027 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2028 | **/ |
| 2029 | static struct hbq_dmabuf * |
| 2030 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2031 | { |
| 2032 | struct lpfc_dmabuf *d_buf; |
| 2033 | |
| 2034 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2035 | if (!d_buf) |
| 2036 | return NULL; |
| 2037 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2038 | } |
| 2039 | |
| 2040 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2041 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2042 | * @phba: Pointer to HBA context object. |
| 2043 | * @hbqno: HBQ number. |
| 2044 | * |
| 2045 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2046 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2047 | **/ |
| 2048 | static struct rqb_dmabuf * |
| 2049 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2050 | { |
| 2051 | struct lpfc_dmabuf *h_buf; |
| 2052 | struct lpfc_rqb *rqbp; |
| 2053 | |
| 2054 | rqbp = hrq->rqbp; |
| 2055 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2056 | struct lpfc_dmabuf, list); |
| 2057 | if (!h_buf) |
| 2058 | return NULL; |
| 2059 | rqbp->buffer_count--; |
| 2060 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2061 | } |
| 2062 | |
| 2063 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2064 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2065 | * @phba: Pointer to HBA context object. |
| 2066 | * @tag: Tag of the hbq buffer. |
| 2067 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2068 | * This function searches for the hbq buffer associated with the given tag in |
| 2069 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2070 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2071 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2072 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2073 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2074 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2075 | struct lpfc_dmabuf *d_buf; |
| 2076 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2077 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2078 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2079 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2080 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2081 | return NULL; |
| 2082 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2083 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2084 | 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] | 2085 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2086 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2087 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2088 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2089 | } |
| 2090 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2091 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2092 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2093 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2094 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2095 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2096 | } |
| 2097 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2098 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2099 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2100 | * @phba: Pointer to HBA context object. |
| 2101 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2102 | * |
| 2103 | * This function is called with hbalock. This function gives back |
| 2104 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2105 | * post the buffer, it will free the buffer. |
| 2106 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2107 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2108 | 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] | 2109 | { |
| 2110 | uint32_t hbqno; |
| 2111 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2112 | if (hbq_buffer) { |
| 2113 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2114 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2115 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2116 | } |
| 2117 | } |
| 2118 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2119 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2120 | * 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] | 2121 | * @mbxCommand: mailbox command code. |
| 2122 | * |
| 2123 | * This function is called by the mailbox event handler function to verify |
| 2124 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2125 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2126 | * and the mailbox event handler will take the HBA offline. |
| 2127 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2128 | static int |
| 2129 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2130 | { |
| 2131 | uint8_t ret; |
| 2132 | |
| 2133 | switch (mbxCommand) { |
| 2134 | case MBX_LOAD_SM: |
| 2135 | case MBX_READ_NV: |
| 2136 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2137 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2138 | case MBX_RUN_BIU_DIAG: |
| 2139 | case MBX_INIT_LINK: |
| 2140 | case MBX_DOWN_LINK: |
| 2141 | case MBX_CONFIG_LINK: |
| 2142 | case MBX_CONFIG_RING: |
| 2143 | case MBX_RESET_RING: |
| 2144 | case MBX_READ_CONFIG: |
| 2145 | case MBX_READ_RCONFIG: |
| 2146 | case MBX_READ_SPARM: |
| 2147 | case MBX_READ_STATUS: |
| 2148 | case MBX_READ_RPI: |
| 2149 | case MBX_READ_XRI: |
| 2150 | case MBX_READ_REV: |
| 2151 | case MBX_READ_LNK_STAT: |
| 2152 | case MBX_REG_LOGIN: |
| 2153 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2154 | case MBX_CLEAR_LA: |
| 2155 | case MBX_DUMP_MEMORY: |
| 2156 | case MBX_DUMP_CONTEXT: |
| 2157 | case MBX_RUN_DIAGS: |
| 2158 | case MBX_RESTART: |
| 2159 | case MBX_UPDATE_CFG: |
| 2160 | case MBX_DOWN_LOAD: |
| 2161 | case MBX_DEL_LD_ENTRY: |
| 2162 | case MBX_RUN_PROGRAM: |
| 2163 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2164 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2165 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2166 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2167 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2168 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | case MBX_LOAD_AREA: |
| 2170 | case MBX_RUN_BIU_DIAG64: |
| 2171 | case MBX_CONFIG_PORT: |
| 2172 | case MBX_READ_SPARM64: |
| 2173 | case MBX_READ_RPI64: |
| 2174 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2175 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2176 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2177 | case MBX_SET_DEBUG: |
| 2178 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2179 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2180 | case MBX_REG_VPI: |
| 2181 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2182 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2183 | case MBX_PORT_CAPABILITIES: |
| 2184 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2185 | case MBX_SLI4_CONFIG: |
| 2186 | case MBX_SLI4_REQ_FTRS: |
| 2187 | case MBX_REG_FCFI: |
| 2188 | case MBX_UNREG_FCFI: |
| 2189 | case MBX_REG_VFI: |
| 2190 | case MBX_UNREG_VFI: |
| 2191 | case MBX_INIT_VPI: |
| 2192 | case MBX_INIT_VFI: |
| 2193 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2194 | case MBX_READ_EVENT_LOG_STATUS: |
| 2195 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2196 | case MBX_SECURITY_MGMT: |
| 2197 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2198 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2199 | ret = mbxCommand; |
| 2200 | break; |
| 2201 | default: |
| 2202 | ret = MBX_SHUTDOWN; |
| 2203 | break; |
| 2204 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2205 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2206 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2207 | |
| 2208 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2209 | * 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] | 2210 | * @phba: Pointer to HBA context object. |
| 2211 | * @pmboxq: Pointer to mailbox command. |
| 2212 | * |
| 2213 | * This is completion handler function for mailbox commands issued from |
| 2214 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2215 | * mailbox event handler function with no lock held. This function |
| 2216 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2217 | * of the mailbox. |
| 2218 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2219 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2220 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2221 | { |
| 2222 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2223 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2224 | |
| 2225 | /* |
| 2226 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2227 | * continued running. |
| 2228 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2229 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2230 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2232 | if (pdone_q) |
| 2233 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2234 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | return; |
| 2236 | } |
| 2237 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2238 | |
| 2239 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2240 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2241 | * @phba: Pointer to HBA context object. |
| 2242 | * @pmb: Pointer to mailbox object. |
| 2243 | * |
| 2244 | * This function is the default mailbox completion handler. It |
| 2245 | * frees the memory resources associated with the completed mailbox |
| 2246 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2247 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2248 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2249 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2250 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2252 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2253 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2254 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2255 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2256 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2257 | int rc; |
| 2258 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2259 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2260 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2261 | if (mp) { |
| 2262 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2263 | kfree(mp); |
| 2264 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2265 | |
| 2266 | /* |
| 2267 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2268 | * is in re-discovery driver need to cleanup the RPI. |
| 2269 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2270 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2271 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2272 | !pmb->u.mb.mbxStatus) { |
| 2273 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2274 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2275 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2276 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2277 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2278 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2279 | if (rc != MBX_NOT_FINISHED) |
| 2280 | return; |
| 2281 | } |
| 2282 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2283 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2284 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2285 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2286 | shost = lpfc_shost_from_vport(vport); |
| 2287 | spin_lock_irq(shost->host_lock); |
| 2288 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2289 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2290 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2291 | } |
| 2292 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2293 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2294 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2295 | lpfc_nlp_put(ndlp); |
| 2296 | pmb->context2 = NULL; |
| 2297 | } |
| 2298 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2299 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2300 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2301 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2302 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2303 | "2860 SLI authentication is required " |
| 2304 | "for INIT_LINK but has not done yet\n"); |
| 2305 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2306 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2307 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2308 | else |
| 2309 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2311 | /** |
| 2312 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2313 | * @phba: Pointer to HBA context object. |
| 2314 | * @pmb: Pointer to mailbox object. |
| 2315 | * |
| 2316 | * This function is the unreg rpi mailbox completion handler. It |
| 2317 | * frees the memory resources associated with the completed mailbox |
| 2318 | * command. An additional refrenece is put on the ndlp to prevent |
| 2319 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2320 | * the unreg mailbox command completes, this routine puts the |
| 2321 | * reference back. |
| 2322 | * |
| 2323 | **/ |
| 2324 | void |
| 2325 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2326 | { |
| 2327 | struct lpfc_vport *vport = pmb->vport; |
| 2328 | struct lpfc_nodelist *ndlp; |
| 2329 | |
| 2330 | ndlp = pmb->context1; |
| 2331 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2332 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2333 | (bf_get(lpfc_sli_intf_if_type, |
| 2334 | &phba->sli4_hba.sli_intf) == |
| 2335 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2336 | if (ndlp) { |
| 2337 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 2338 | "0010 UNREG_LOGIN vpi:%x " |
| 2339 | "rpi:%x DID:%x map:%x %p\n", |
| 2340 | vport->vpi, ndlp->nlp_rpi, |
| 2341 | ndlp->nlp_DID, |
| 2342 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2343 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2344 | lpfc_nlp_put(ndlp); |
| 2345 | } |
| 2346 | } |
| 2347 | } |
| 2348 | |
| 2349 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2350 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2351 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2352 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2353 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2354 | * @phba: Pointer to HBA context object. |
| 2355 | * |
| 2356 | * This function is called with no lock held. This function processes all |
| 2357 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2358 | * service routine processes mailbox completion interrupt and adds completed |
| 2359 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2360 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2361 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2362 | * function returns the mailbox commands to the upper layer by calling the |
| 2363 | * completion handler function of each mailbox. |
| 2364 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2365 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2366 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2367 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2368 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2370 | int rc; |
| 2371 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | |
| 2373 | phba->sli.slistat.mbox_event++; |
| 2374 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2375 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2376 | spin_lock_irq(&phba->hbalock); |
| 2377 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2378 | spin_unlock_irq(&phba->hbalock); |
| 2379 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2380 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2381 | do { |
| 2382 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2383 | if (pmb == NULL) |
| 2384 | break; |
| 2385 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2386 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2387 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2388 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2389 | if (pmb->vport) { |
| 2390 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2391 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2392 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2393 | (uint32_t)pmbox->mbxCommand, |
| 2394 | pmbox->un.varWords[0], |
| 2395 | pmbox->un.varWords[1]); |
| 2396 | } |
| 2397 | else { |
| 2398 | lpfc_debugfs_disc_trc(phba->pport, |
| 2399 | LPFC_DISC_TRC_MBOX, |
| 2400 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2401 | (uint32_t)pmbox->mbxCommand, |
| 2402 | pmbox->un.varWords[0], |
| 2403 | pmbox->un.varWords[1]); |
| 2404 | } |
| 2405 | } |
| 2406 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | /* |
| 2408 | * It is a fatal error if unknown mbox command completion. |
| 2409 | */ |
| 2410 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2411 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2412 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2413 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2414 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2415 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2416 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2417 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2418 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2419 | pmb), |
| 2420 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2421 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2422 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2423 | phba->work_hs = HS_FFER3; |
| 2424 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2425 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2426 | } |
| 2427 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2428 | if (pmbox->mbxStatus) { |
| 2429 | phba->sli.slistat.mbox_stat_err++; |
| 2430 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2431 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2432 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2433 | LOG_MBOX | LOG_SLI, |
| 2434 | "(%d):0305 Mbox cmd cmpl " |
| 2435 | "error - RETRYing Data: x%x " |
| 2436 | "(x%x/x%x) x%x x%x x%x\n", |
| 2437 | pmb->vport ? pmb->vport->vpi : 0, |
| 2438 | pmbox->mbxCommand, |
| 2439 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2440 | pmb), |
| 2441 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2442 | pmb), |
| 2443 | pmbox->mbxStatus, |
| 2444 | pmbox->un.varWords[0], |
| 2445 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2446 | pmbox->mbxStatus = 0; |
| 2447 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2448 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2449 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2450 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2455 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2456 | "(%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] | 2457 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2458 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2459 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2460 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2461 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2462 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2463 | pmb->mbox_cmpl, |
| 2464 | *((uint32_t *) pmbox), |
| 2465 | pmbox->un.varWords[0], |
| 2466 | pmbox->un.varWords[1], |
| 2467 | pmbox->un.varWords[2], |
| 2468 | pmbox->un.varWords[3], |
| 2469 | pmbox->un.varWords[4], |
| 2470 | pmbox->un.varWords[5], |
| 2471 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2472 | pmbox->un.varWords[7], |
| 2473 | pmbox->un.varWords[8], |
| 2474 | pmbox->un.varWords[9], |
| 2475 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2476 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2477 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2478 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2479 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2480 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2481 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2482 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2483 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2484 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2485 | * @phba: Pointer to HBA context object. |
| 2486 | * @pring: Pointer to driver SLI ring object. |
| 2487 | * @tag: buffer tag. |
| 2488 | * |
| 2489 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2490 | * is set in the tag the buffer is posted for a particular exchange, |
| 2491 | * the function will return the buffer without replacing the buffer. |
| 2492 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2493 | * returns the buffer and also posts another buffer to the firmware. |
| 2494 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2495 | static struct lpfc_dmabuf * |
| 2496 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2497 | struct lpfc_sli_ring *pring, |
| 2498 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2499 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2500 | struct hbq_dmabuf *hbq_entry; |
| 2501 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2502 | if (tag & QUE_BUFTAG_BIT) |
| 2503 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2504 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2505 | if (!hbq_entry) |
| 2506 | return NULL; |
| 2507 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2508 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2509 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2510 | /** |
| 2511 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2512 | * @phba: Pointer to HBA context object. |
| 2513 | * @pring: Pointer to driver SLI ring object. |
| 2514 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2515 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2516 | * @fch_type: the type for the first frame of the sequence. |
| 2517 | * |
| 2518 | * This function is called with no lock held. This function uses the r_ctl and |
| 2519 | * type of the received sequence to find the correct callback function to call |
| 2520 | * to process the sequence. |
| 2521 | **/ |
| 2522 | static int |
| 2523 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2524 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2525 | uint32_t fch_type) |
| 2526 | { |
| 2527 | int i; |
| 2528 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2529 | switch (fch_type) { |
| 2530 | case FC_TYPE_NVME: |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2531 | lpfc_nvmet_unsol_ls_event(phba, pring, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2532 | return 1; |
| 2533 | default: |
| 2534 | break; |
| 2535 | } |
| 2536 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2537 | /* unSolicited Responses */ |
| 2538 | if (pring->prt[0].profile) { |
| 2539 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2540 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2541 | saveq); |
| 2542 | return 1; |
| 2543 | } |
| 2544 | /* We must search, based on rctl / type |
| 2545 | for the right routine */ |
| 2546 | for (i = 0; i < pring->num_mask; i++) { |
| 2547 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2548 | (pring->prt[i].type == fch_type)) { |
| 2549 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2550 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2551 | (phba, pring, saveq); |
| 2552 | return 1; |
| 2553 | } |
| 2554 | } |
| 2555 | return 0; |
| 2556 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2557 | |
| 2558 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2559 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2560 | * @phba: Pointer to HBA context object. |
| 2561 | * @pring: Pointer to driver SLI ring object. |
| 2562 | * @saveq: Pointer to the unsolicited iocb. |
| 2563 | * |
| 2564 | * This function is called with no lock held by the ring event handler |
| 2565 | * when there is an unsolicited iocb posted to the response ring by the |
| 2566 | * firmware. This function gets the buffer associated with the iocbs |
| 2567 | * and calls the event handler for the ring. This function handles both |
| 2568 | * qring buffers and hbq buffers. |
| 2569 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2570 | * upper layer functions will free the iocb objects. |
| 2571 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2572 | static int |
| 2573 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2574 | struct lpfc_iocbq *saveq) |
| 2575 | { |
| 2576 | IOCB_t * irsp; |
| 2577 | WORD5 * w5p; |
| 2578 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2579 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2580 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2581 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2582 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2583 | |
| 2584 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2585 | if (pring->lpfc_sli_rcv_async_status) |
| 2586 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2587 | else |
| 2588 | lpfc_printf_log(phba, |
| 2589 | KERN_WARNING, |
| 2590 | LOG_SLI, |
| 2591 | "0316 Ring %d handler: unexpected " |
| 2592 | "ASYNC_STATUS iocb received evt_code " |
| 2593 | "0x%x\n", |
| 2594 | pring->ringno, |
| 2595 | irsp->un.asyncstat.evt_code); |
| 2596 | return 1; |
| 2597 | } |
| 2598 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2599 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2600 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2601 | if (irsp->ulpBdeCount > 0) { |
| 2602 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2603 | irsp->un.ulpWord[3]); |
| 2604 | lpfc_in_buf_free(phba, dmzbuf); |
| 2605 | } |
| 2606 | |
| 2607 | if (irsp->ulpBdeCount > 1) { |
| 2608 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2609 | irsp->unsli3.sli3Words[3]); |
| 2610 | lpfc_in_buf_free(phba, dmzbuf); |
| 2611 | } |
| 2612 | |
| 2613 | if (irsp->ulpBdeCount > 2) { |
| 2614 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2615 | irsp->unsli3.sli3Words[7]); |
| 2616 | lpfc_in_buf_free(phba, dmzbuf); |
| 2617 | } |
| 2618 | |
| 2619 | return 1; |
| 2620 | } |
| 2621 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2622 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2623 | if (irsp->ulpBdeCount != 0) { |
| 2624 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2625 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2626 | if (!saveq->context2) |
| 2627 | lpfc_printf_log(phba, |
| 2628 | KERN_ERR, |
| 2629 | LOG_SLI, |
| 2630 | "0341 Ring %d Cannot find buffer for " |
| 2631 | "an unsolicited iocb. tag 0x%x\n", |
| 2632 | pring->ringno, |
| 2633 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2634 | } |
| 2635 | if (irsp->ulpBdeCount == 2) { |
| 2636 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2637 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2638 | if (!saveq->context3) |
| 2639 | lpfc_printf_log(phba, |
| 2640 | KERN_ERR, |
| 2641 | LOG_SLI, |
| 2642 | "0342 Ring %d Cannot find buffer for an" |
| 2643 | " unsolicited iocb. tag 0x%x\n", |
| 2644 | pring->ringno, |
| 2645 | irsp->unsli3.sli3Words[7]); |
| 2646 | } |
| 2647 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2648 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2649 | if (irsp->ulpBdeCount != 0) { |
| 2650 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2651 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2652 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2653 | lpfc_printf_log(phba, |
| 2654 | KERN_ERR, |
| 2655 | LOG_SLI, |
| 2656 | "0343 Ring %d Cannot find " |
| 2657 | "buffer for an unsolicited iocb" |
| 2658 | ". tag 0x%x\n", pring->ringno, |
| 2659 | irsp->un.ulpWord[3]); |
| 2660 | } |
| 2661 | if (irsp->ulpBdeCount == 2) { |
| 2662 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2663 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2664 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2665 | lpfc_printf_log(phba, |
| 2666 | KERN_ERR, |
| 2667 | LOG_SLI, |
| 2668 | "0344 Ring %d Cannot find " |
| 2669 | "buffer for an unsolicited " |
| 2670 | "iocb. tag 0x%x\n", |
| 2671 | pring->ringno, |
| 2672 | irsp->unsli3.sli3Words[7]); |
| 2673 | } |
| 2674 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2675 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2676 | if (irsp->ulpBdeCount != 0 && |
| 2677 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2678 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2679 | int found = 0; |
| 2680 | |
| 2681 | /* search continue save q for same XRI */ |
| 2682 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2683 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2684 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2685 | list_add_tail(&saveq->list, &iocbq->list); |
| 2686 | found = 1; |
| 2687 | break; |
| 2688 | } |
| 2689 | } |
| 2690 | if (!found) |
| 2691 | list_add_tail(&saveq->clist, |
| 2692 | &pring->iocb_continue_saveq); |
| 2693 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2694 | list_del_init(&iocbq->clist); |
| 2695 | saveq = iocbq; |
| 2696 | irsp = &(saveq->iocb); |
| 2697 | } else |
| 2698 | return 0; |
| 2699 | } |
| 2700 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2701 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2702 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2703 | Rctl = FC_RCTL_ELS_REQ; |
| 2704 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2705 | } else { |
| 2706 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2707 | Rctl = w5p->hcsw.Rctl; |
| 2708 | Type = w5p->hcsw.Type; |
| 2709 | |
| 2710 | /* Firmware Workaround */ |
| 2711 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2712 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2713 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2714 | Rctl = FC_RCTL_ELS_REQ; |
| 2715 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2716 | w5p->hcsw.Rctl = Rctl; |
| 2717 | w5p->hcsw.Type = Type; |
| 2718 | } |
| 2719 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2720 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2721 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2722 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2723 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2724 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2725 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2726 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2727 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 | } |
| 2729 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2730 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2731 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2732 | * @phba: Pointer to HBA context object. |
| 2733 | * @pring: Pointer to driver SLI ring object. |
| 2734 | * @prspiocb: Pointer to response iocb object. |
| 2735 | * |
| 2736 | * This function looks up the iocb_lookup table to get the command iocb |
| 2737 | * corresponding to the given response iocb using the iotag of the |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 2738 | * response iocb. This function is called with the hbalock held |
| 2739 | * for sli3 devices or the ring_lock for sli4 devices. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2740 | * This function returns the command iocb object if it finds the command |
| 2741 | * iocb else returns NULL. |
| 2742 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2743 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2744 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2745 | struct lpfc_sli_ring *pring, |
| 2746 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2747 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2748 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2749 | uint16_t iotag; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2750 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2752 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2753 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2754 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2755 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2756 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2757 | /* remove from txcmpl queue list */ |
| 2758 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2759 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2760 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2761 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2762 | } |
| 2763 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2764 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2765 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2766 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2767 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2768 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2769 | return NULL; |
| 2770 | } |
| 2771 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2772 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2773 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2774 | * @phba: Pointer to HBA context object. |
| 2775 | * @pring: Pointer to driver SLI ring object. |
| 2776 | * @iotag: IOCB tag. |
| 2777 | * |
| 2778 | * This function looks up the iocb_lookup table to get the command iocb |
| 2779 | * corresponding to the given iotag. This function is called with the |
| 2780 | * hbalock held. |
| 2781 | * This function returns the command iocb object if it finds the command |
| 2782 | * iocb else returns NULL. |
| 2783 | **/ |
| 2784 | static struct lpfc_iocbq * |
| 2785 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2786 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2787 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2788 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2789 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2790 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2791 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2792 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2793 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2794 | /* remove from txcmpl queue list */ |
| 2795 | list_del_init(&cmd_iocb->list); |
| 2796 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2797 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2798 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2799 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2800 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2801 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2802 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 2803 | "iocb_flag x%x\n", |
| 2804 | iotag, phba->sli.last_iotag, |
| 2805 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2806 | return NULL; |
| 2807 | } |
| 2808 | |
| 2809 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2810 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2811 | * @phba: Pointer to HBA context object. |
| 2812 | * @pring: Pointer to driver SLI ring object. |
| 2813 | * @saveq: Pointer to the response iocb to be processed. |
| 2814 | * |
| 2815 | * This function is called by the ring event handler for non-fcp |
| 2816 | * rings when there is a new response iocb in the response ring. |
| 2817 | * The caller is not required to hold any locks. This function |
| 2818 | * gets the command iocb associated with the response iocb and |
| 2819 | * calls the completion handler for the command iocb. If there |
| 2820 | * is no completion handler, the function will free the resources |
| 2821 | * associated with command iocb. If the response iocb is for |
| 2822 | * an already aborted command iocb, the status of the completion |
| 2823 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2824 | * This function always returns 1. |
| 2825 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2826 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2827 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2828 | struct lpfc_iocbq *saveq) |
| 2829 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2830 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2831 | int rc = 1; |
| 2832 | unsigned long iflag; |
| 2833 | |
| 2834 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 2835 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2836 | spin_lock_irqsave(&pring->ring_lock, iflag); |
| 2837 | else |
| 2838 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2839 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
Dick Kennedy | 341b2aa | 2017-11-07 12:59:02 -0800 | [diff] [blame] | 2840 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2841 | spin_unlock_irqrestore(&pring->ring_lock, iflag); |
| 2842 | else |
| 2843 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2844 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2845 | if (cmdiocbp) { |
| 2846 | if (cmdiocbp->iocb_cmpl) { |
| 2847 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2848 | * If an ELS command failed send an event to mgmt |
| 2849 | * application. |
| 2850 | */ |
| 2851 | if (saveq->iocb.ulpStatus && |
| 2852 | (pring->ringno == LPFC_ELS_RING) && |
| 2853 | (cmdiocbp->iocb.ulpCommand == |
| 2854 | CMD_ELS_REQUEST64_CR)) |
| 2855 | lpfc_send_els_failure_event(phba, |
| 2856 | cmdiocbp, saveq); |
| 2857 | |
| 2858 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2859 | * Post all ELS completions to the worker thread. |
| 2860 | * All other are passed to the completion callback. |
| 2861 | */ |
| 2862 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2863 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2864 | (cmdiocbp->iocb_flag & |
| 2865 | LPFC_DRIVER_ABORTED)) { |
| 2866 | spin_lock_irqsave(&phba->hbalock, |
| 2867 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2868 | cmdiocbp->iocb_flag &= |
| 2869 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2870 | spin_unlock_irqrestore(&phba->hbalock, |
| 2871 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2872 | saveq->iocb.ulpStatus = |
| 2873 | IOSTAT_LOCAL_REJECT; |
| 2874 | saveq->iocb.un.ulpWord[4] = |
| 2875 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2876 | |
| 2877 | /* Firmware could still be in progress |
| 2878 | * of DMAing payload, so don't free data |
| 2879 | * buffer till after a hbeat. |
| 2880 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2881 | spin_lock_irqsave(&phba->hbalock, |
| 2882 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2883 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2884 | spin_unlock_irqrestore(&phba->hbalock, |
| 2885 | iflag); |
| 2886 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2887 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2888 | if (saveq->iocb_flag & |
| 2889 | LPFC_EXCHANGE_BUSY) { |
| 2890 | /* Set cmdiocb flag for the |
| 2891 | * exchange busy so sgl (xri) |
| 2892 | * will not be released until |
| 2893 | * the abort xri is received |
| 2894 | * from hba. |
| 2895 | */ |
| 2896 | spin_lock_irqsave( |
| 2897 | &phba->hbalock, iflag); |
| 2898 | cmdiocbp->iocb_flag |= |
| 2899 | LPFC_EXCHANGE_BUSY; |
| 2900 | spin_unlock_irqrestore( |
| 2901 | &phba->hbalock, iflag); |
| 2902 | } |
| 2903 | if (cmdiocbp->iocb_flag & |
| 2904 | LPFC_DRIVER_ABORTED) { |
| 2905 | /* |
| 2906 | * Clear LPFC_DRIVER_ABORTED |
| 2907 | * bit in case it was driver |
| 2908 | * initiated abort. |
| 2909 | */ |
| 2910 | spin_lock_irqsave( |
| 2911 | &phba->hbalock, iflag); |
| 2912 | cmdiocbp->iocb_flag &= |
| 2913 | ~LPFC_DRIVER_ABORTED; |
| 2914 | spin_unlock_irqrestore( |
| 2915 | &phba->hbalock, iflag); |
| 2916 | cmdiocbp->iocb.ulpStatus = |
| 2917 | IOSTAT_LOCAL_REJECT; |
| 2918 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2919 | IOERR_ABORT_REQUESTED; |
| 2920 | /* |
| 2921 | * For SLI4, irsiocb contains |
| 2922 | * NO_XRI in sli_xritag, it |
| 2923 | * shall not affect releasing |
| 2924 | * sgl (xri) process. |
| 2925 | */ |
| 2926 | saveq->iocb.ulpStatus = |
| 2927 | IOSTAT_LOCAL_REJECT; |
| 2928 | saveq->iocb.un.ulpWord[4] = |
| 2929 | IOERR_SLI_ABORTED; |
| 2930 | spin_lock_irqsave( |
| 2931 | &phba->hbalock, iflag); |
| 2932 | saveq->iocb_flag |= |
| 2933 | LPFC_DELAY_MEM_FREE; |
| 2934 | spin_unlock_irqrestore( |
| 2935 | &phba->hbalock, iflag); |
| 2936 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2937 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2938 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2939 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2940 | } else |
| 2941 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2942 | } else { |
| 2943 | /* |
| 2944 | * Unknown initiating command based on the response iotag. |
| 2945 | * This could be the case on the ELS ring because of |
| 2946 | * lpfc_els_abort(). |
| 2947 | */ |
| 2948 | if (pring->ringno != LPFC_ELS_RING) { |
| 2949 | /* |
| 2950 | * Ring <ringno> handler: unexpected completion IoTag |
| 2951 | * <IoTag> |
| 2952 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2953 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2954 | "0322 Ring %d handler: " |
| 2955 | "unexpected completion IoTag x%x " |
| 2956 | "Data: x%x x%x x%x x%x\n", |
| 2957 | pring->ringno, |
| 2958 | saveq->iocb.ulpIoTag, |
| 2959 | saveq->iocb.ulpStatus, |
| 2960 | saveq->iocb.un.ulpWord[4], |
| 2961 | saveq->iocb.ulpCommand, |
| 2962 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2963 | } |
| 2964 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2965 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2966 | return rc; |
| 2967 | } |
| 2968 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2969 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2970 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2971 | * @phba: Pointer to HBA context object. |
| 2972 | * @pring: Pointer to driver SLI ring object. |
| 2973 | * |
| 2974 | * This function is called from the iocb ring event handlers when |
| 2975 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2976 | * an error attention condition to the worker thread and the worker |
| 2977 | * thread will transition the HBA to offline state. |
| 2978 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2979 | static void |
| 2980 | 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] | 2981 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2982 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2983 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2984 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2985 | * rsp ring <portRspMax> |
| 2986 | */ |
| 2987 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2988 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2989 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2990 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2991 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2992 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2993 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2994 | |
| 2995 | /* |
| 2996 | * All error attention handlers are posted to |
| 2997 | * worker thread |
| 2998 | */ |
| 2999 | phba->work_ha |= HA_ERATT; |
| 3000 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3001 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 3002 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3003 | |
| 3004 | return; |
| 3005 | } |
| 3006 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3007 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3008 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3009 | * @ptr: Pointer to address of HBA context object. |
| 3010 | * |
| 3011 | * This function is invoked by the Error Attention polling timer when the |
| 3012 | * timer times out. It will check the SLI Error Attention register for |
| 3013 | * possible attention events. If so, it will post an Error Attention event |
| 3014 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3015 | * Error Attention polling timer for the next poll. |
| 3016 | **/ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3017 | void lpfc_poll_eratt(struct timer_list *t) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3018 | { |
| 3019 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3020 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3021 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3022 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3023 | phba = from_timer(phba, t, eratt_poll); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3024 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3025 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3026 | sli_intr = phba->sli.slistat.sli_intr; |
| 3027 | |
| 3028 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3029 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3030 | sli_intr); |
| 3031 | else |
| 3032 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3033 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3034 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3035 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3036 | phba->sli.slistat.sli_ips = cnt; |
| 3037 | |
| 3038 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3039 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3040 | /* Check chip HA register for error event */ |
| 3041 | eratt = lpfc_sli_check_eratt(phba); |
| 3042 | |
| 3043 | if (eratt) |
| 3044 | /* Tell the worker thread there is work to do */ |
| 3045 | lpfc_worker_wake_up(phba); |
| 3046 | else |
| 3047 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3048 | mod_timer(&phba->eratt_poll, |
| 3049 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3050 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3051 | return; |
| 3052 | } |
| 3053 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3054 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3055 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3056 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3057 | * @phba: Pointer to HBA context object. |
| 3058 | * @pring: Pointer to driver SLI ring object. |
| 3059 | * @mask: Host attention register mask for this ring. |
| 3060 | * |
| 3061 | * This function is called from the interrupt context when there is a ring |
| 3062 | * event for the fcp ring. The caller does not hold any lock. |
| 3063 | * 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] | 3064 | * 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] | 3065 | * LE bit set. The function will call the completion handler of the command iocb |
| 3066 | * if the response iocb indicates a completion for a command iocb or it is |
| 3067 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3068 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3069 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3070 | * to check it explicitly. |
| 3071 | */ |
| 3072 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3073 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3074 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3075 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3076 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3077 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3078 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3079 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3080 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3081 | uint32_t status; |
| 3082 | uint32_t portRspPut, portRspMax; |
| 3083 | int rc = 1; |
| 3084 | lpfc_iocb_type type; |
| 3085 | unsigned long iflag; |
| 3086 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3087 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3088 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3089 | pring->stats.iocb_event++; |
| 3090 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3091 | /* |
| 3092 | * The next available response entry should never exceed the maximum |
| 3093 | * entries. If it does, treat it as an adapter hardware error. |
| 3094 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3095 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3096 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3097 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3098 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3099 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3100 | return 1; |
| 3101 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3102 | if (phba->fcp_ring_in_use) { |
| 3103 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3104 | return 1; |
| 3105 | } else |
| 3106 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3107 | |
| 3108 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3109 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3110 | /* |
| 3111 | * Fetch an entry off the ring and copy it into a local data |
| 3112 | * structure. The copy involves a byte-swap since the |
| 3113 | * network byte order and pci byte orders are different. |
| 3114 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3115 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3116 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3117 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3118 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3119 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3120 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3121 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3122 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3123 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3124 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3125 | irsp = &rspiocbq.iocb; |
| 3126 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3127 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3128 | pring->stats.iocb_rsp++; |
| 3129 | rsp_cmpl++; |
| 3130 | |
| 3131 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3132 | /* |
| 3133 | * If resource errors reported from HBA, reduce |
| 3134 | * queuedepths of the SCSI device. |
| 3135 | */ |
| 3136 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3137 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3138 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3139 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3140 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3141 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3142 | } |
| 3143 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3144 | /* Rsp ring <ringno> error: IOCB */ |
| 3145 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3146 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3147 | "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] | 3148 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3149 | irsp->un.ulpWord[0], |
| 3150 | irsp->un.ulpWord[1], |
| 3151 | irsp->un.ulpWord[2], |
| 3152 | irsp->un.ulpWord[3], |
| 3153 | irsp->un.ulpWord[4], |
| 3154 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3155 | *(uint32_t *)&irsp->un1, |
| 3156 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | switch (type) { |
| 3160 | case LPFC_ABORT_IOCB: |
| 3161 | case LPFC_SOL_IOCB: |
| 3162 | /* |
| 3163 | * Idle exchange closed via ABTS from port. No iocb |
| 3164 | * resources need to be recovered. |
| 3165 | */ |
| 3166 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3167 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3168 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3169 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3170 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3171 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3172 | break; |
| 3173 | } |
| 3174 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3175 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3176 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3177 | if (unlikely(!cmdiocbq)) |
| 3178 | break; |
| 3179 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3180 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3181 | if (cmdiocbq->iocb_cmpl) { |
| 3182 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3183 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3184 | &rspiocbq); |
| 3185 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3186 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3187 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3188 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3189 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3190 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3191 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3192 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3193 | default: |
| 3194 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3195 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3196 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3197 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3198 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3199 | dev_warn(&((phba->pcidev)->dev), |
| 3200 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3201 | phba->brd_no, adaptermsg); |
| 3202 | } else { |
| 3203 | /* Unknown IOCB command */ |
| 3204 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3205 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3206 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3207 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3208 | irsp->ulpStatus, |
| 3209 | irsp->ulpIoTag, |
| 3210 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3211 | } |
| 3212 | break; |
| 3213 | } |
| 3214 | |
| 3215 | /* |
| 3216 | * The response IOCB has been processed. Update the ring |
| 3217 | * pointer in SLIM. If the port response put pointer has not |
| 3218 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3219 | * response put pointer. |
| 3220 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3221 | writel(pring->sli.sli3.rspidx, |
| 3222 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3223 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3224 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3225 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3226 | } |
| 3227 | |
| 3228 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3229 | pring->stats.iocb_rsp_full++; |
| 3230 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3231 | writel(status, phba->CAregaddr); |
| 3232 | readl(phba->CAregaddr); |
| 3233 | } |
| 3234 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3235 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3236 | pring->stats.iocb_cmd_empty++; |
| 3237 | |
| 3238 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3239 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3240 | lpfc_sli_resume_iocb(phba, pring); |
| 3241 | |
| 3242 | if ((pring->lpfc_sli_cmd_available)) |
| 3243 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3244 | |
| 3245 | } |
| 3246 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3247 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3248 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3249 | return rc; |
| 3250 | } |
| 3251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3252 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3253 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3254 | * @phba: Pointer to HBA context object. |
| 3255 | * @pring: Pointer to driver SLI ring object. |
| 3256 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3257 | * |
| 3258 | * This function is called from the worker thread when there is a slow-path |
| 3259 | * response IOCB to process. This function chains all the response iocbs until |
| 3260 | * seeing the iocb with the LE bit set. The function will call |
| 3261 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3262 | * completion of a command iocb. The function will call the |
| 3263 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3264 | * The function frees the resources or calls the completion handler if this |
| 3265 | * iocb is an abort completion. The function returns NULL when the response |
| 3266 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3267 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3268 | * response iocb passed in. |
| 3269 | **/ |
| 3270 | static struct lpfc_iocbq * |
| 3271 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3272 | struct lpfc_iocbq *rspiocbp) |
| 3273 | { |
| 3274 | struct lpfc_iocbq *saveq; |
| 3275 | struct lpfc_iocbq *cmdiocbp; |
| 3276 | struct lpfc_iocbq *next_iocb; |
| 3277 | IOCB_t *irsp = NULL; |
| 3278 | uint32_t free_saveq; |
| 3279 | uint8_t iocb_cmd_type; |
| 3280 | lpfc_iocb_type type; |
| 3281 | unsigned long iflag; |
| 3282 | int rc; |
| 3283 | |
| 3284 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3285 | /* First add the response iocb to the countinueq list */ |
| 3286 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3287 | pring->iocb_continueq_cnt++; |
| 3288 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3289 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3290 | irsp = &rspiocbp->iocb; |
| 3291 | if (irsp->ulpLe) { |
| 3292 | /* |
| 3293 | * By default, the driver expects to free all resources |
| 3294 | * associated with this iocb completion. |
| 3295 | */ |
| 3296 | free_saveq = 1; |
| 3297 | saveq = list_get_first(&pring->iocb_continueq, |
| 3298 | struct lpfc_iocbq, list); |
| 3299 | irsp = &(saveq->iocb); |
| 3300 | list_del_init(&pring->iocb_continueq); |
| 3301 | pring->iocb_continueq_cnt = 0; |
| 3302 | |
| 3303 | pring->stats.iocb_rsp++; |
| 3304 | |
| 3305 | /* |
| 3306 | * If resource errors reported from HBA, reduce |
| 3307 | * queuedepths of the SCSI device. |
| 3308 | */ |
| 3309 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3310 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3311 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3312 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3313 | phba->lpfc_rampdown_queue_depth(phba); |
| 3314 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3315 | } |
| 3316 | |
| 3317 | if (irsp->ulpStatus) { |
| 3318 | /* Rsp ring <ringno> error: IOCB */ |
| 3319 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3320 | "0328 Rsp Ring %d error: " |
| 3321 | "IOCB Data: " |
| 3322 | "x%x x%x x%x x%x " |
| 3323 | "x%x x%x x%x x%x " |
| 3324 | "x%x x%x x%x x%x " |
| 3325 | "x%x x%x x%x x%x\n", |
| 3326 | pring->ringno, |
| 3327 | irsp->un.ulpWord[0], |
| 3328 | irsp->un.ulpWord[1], |
| 3329 | irsp->un.ulpWord[2], |
| 3330 | irsp->un.ulpWord[3], |
| 3331 | irsp->un.ulpWord[4], |
| 3332 | irsp->un.ulpWord[5], |
| 3333 | *(((uint32_t *) irsp) + 6), |
| 3334 | *(((uint32_t *) irsp) + 7), |
| 3335 | *(((uint32_t *) irsp) + 8), |
| 3336 | *(((uint32_t *) irsp) + 9), |
| 3337 | *(((uint32_t *) irsp) + 10), |
| 3338 | *(((uint32_t *) irsp) + 11), |
| 3339 | *(((uint32_t *) irsp) + 12), |
| 3340 | *(((uint32_t *) irsp) + 13), |
| 3341 | *(((uint32_t *) irsp) + 14), |
| 3342 | *(((uint32_t *) irsp) + 15)); |
| 3343 | } |
| 3344 | |
| 3345 | /* |
| 3346 | * Fetch the IOCB command type and call the correct completion |
| 3347 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3348 | * get freed back to the lpfc_iocb_list by the discovery |
| 3349 | * kernel thread. |
| 3350 | */ |
| 3351 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3352 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3353 | switch (type) { |
| 3354 | case LPFC_SOL_IOCB: |
| 3355 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3356 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3357 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3358 | break; |
| 3359 | |
| 3360 | case LPFC_UNSOL_IOCB: |
| 3361 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3362 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3363 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3364 | if (!rc) |
| 3365 | free_saveq = 0; |
| 3366 | break; |
| 3367 | |
| 3368 | case LPFC_ABORT_IOCB: |
| 3369 | cmdiocbp = NULL; |
| 3370 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3371 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3372 | saveq); |
| 3373 | if (cmdiocbp) { |
| 3374 | /* Call the specified completion routine */ |
| 3375 | if (cmdiocbp->iocb_cmpl) { |
| 3376 | spin_unlock_irqrestore(&phba->hbalock, |
| 3377 | iflag); |
| 3378 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3379 | saveq); |
| 3380 | spin_lock_irqsave(&phba->hbalock, |
| 3381 | iflag); |
| 3382 | } else |
| 3383 | __lpfc_sli_release_iocbq(phba, |
| 3384 | cmdiocbp); |
| 3385 | } |
| 3386 | break; |
| 3387 | |
| 3388 | case LPFC_UNKNOWN_IOCB: |
| 3389 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3390 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3391 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3392 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3393 | MAX_MSG_DATA); |
| 3394 | dev_warn(&((phba->pcidev)->dev), |
| 3395 | "lpfc%d: %s\n", |
| 3396 | phba->brd_no, adaptermsg); |
| 3397 | } else { |
| 3398 | /* Unknown IOCB command */ |
| 3399 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3400 | "0335 Unknown IOCB " |
| 3401 | "command Data: x%x " |
| 3402 | "x%x x%x x%x\n", |
| 3403 | irsp->ulpCommand, |
| 3404 | irsp->ulpStatus, |
| 3405 | irsp->ulpIoTag, |
| 3406 | irsp->ulpContext); |
| 3407 | } |
| 3408 | break; |
| 3409 | } |
| 3410 | |
| 3411 | if (free_saveq) { |
| 3412 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3413 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3414 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3415 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3416 | } |
| 3417 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3418 | } |
| 3419 | rspiocbp = NULL; |
| 3420 | } |
| 3421 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3422 | return rspiocbp; |
| 3423 | } |
| 3424 | |
| 3425 | /** |
| 3426 | * 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] | 3427 | * @phba: Pointer to HBA context object. |
| 3428 | * @pring: Pointer to driver SLI ring object. |
| 3429 | * @mask: Host attention register mask for this ring. |
| 3430 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3431 | * This routine wraps the actual slow_ring event process routine from the |
| 3432 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3433 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3434 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3435 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3436 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3437 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3438 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3439 | } |
| 3440 | |
| 3441 | /** |
| 3442 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3443 | * @phba: Pointer to HBA context object. |
| 3444 | * @pring: Pointer to driver SLI ring object. |
| 3445 | * @mask: Host attention register mask for this ring. |
| 3446 | * |
| 3447 | * This function is called from the worker thread when there is a ring event |
| 3448 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3449 | * remove each response iocb in the response ring and calls the handle |
| 3450 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3451 | **/ |
| 3452 | static void |
| 3453 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3454 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3455 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3456 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3457 | IOCB_t *entry; |
| 3458 | IOCB_t *irsp = NULL; |
| 3459 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3460 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3461 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3462 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3463 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3464 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3465 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3466 | pring->stats.iocb_event++; |
| 3467 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3468 | /* |
| 3469 | * The next available response entry should never exceed the maximum |
| 3470 | * entries. If it does, treat it as an adapter hardware error. |
| 3471 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3472 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3473 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3474 | if (portRspPut >= portRspMax) { |
| 3475 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3476 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3477 | * rsp ring <portRspMax> |
| 3478 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3479 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3480 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3481 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3482 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3483 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3484 | phba->link_state = LPFC_HBA_ERROR; |
| 3485 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3486 | |
| 3487 | phba->work_hs = HS_FFER3; |
| 3488 | lpfc_handle_eratt(phba); |
| 3489 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3490 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3494 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3495 | /* |
| 3496 | * Build a completion list and call the appropriate handler. |
| 3497 | * The process is to get the next available response iocb, get |
| 3498 | * a free iocb from the list, copy the response data into the |
| 3499 | * free iocb, insert to the continuation list, and update the |
| 3500 | * next response index to slim. This process makes response |
| 3501 | * iocb's in the ring available to DMA as fast as possible but |
| 3502 | * pays a penalty for a copy operation. Since the iocb is |
| 3503 | * only 32 bytes, this penalty is considered small relative to |
| 3504 | * the PCI reads for register values and a slim write. When |
| 3505 | * the ulpLe field is set, the entire Command has been |
| 3506 | * received. |
| 3507 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3508 | entry = lpfc_resp_iocb(phba, pring); |
| 3509 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3510 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3511 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3512 | if (rspiocbp == NULL) { |
| 3513 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3514 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3515 | break; |
| 3516 | } |
| 3517 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3518 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3519 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3520 | irsp = &rspiocbp->iocb; |
| 3521 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3522 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3523 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3524 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3525 | if (pring->ringno == LPFC_ELS_RING) { |
| 3526 | lpfc_debugfs_slow_ring_trc(phba, |
| 3527 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3528 | *(((uint32_t *) irsp) + 4), |
| 3529 | *(((uint32_t *) irsp) + 6), |
| 3530 | *(((uint32_t *) irsp) + 7)); |
| 3531 | } |
| 3532 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3533 | writel(pring->sli.sli3.rspidx, |
| 3534 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3536 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3537 | /* Handle the response IOCB */ |
| 3538 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3539 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | |
| 3541 | /* |
| 3542 | * If the port response put pointer has not been updated, sync |
| 3543 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3544 | * response put pointer. |
| 3545 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3546 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3547 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3548 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3549 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3551 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3552 | /* At least one response entry has been freed */ |
| 3553 | pring->stats.iocb_rsp_full++; |
| 3554 | /* SET RxRE_RSP in Chip Att register */ |
| 3555 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3556 | writel(status, phba->CAregaddr); |
| 3557 | readl(phba->CAregaddr); /* flush */ |
| 3558 | } |
| 3559 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3560 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3561 | pring->stats.iocb_cmd_empty++; |
| 3562 | |
| 3563 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3564 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3565 | lpfc_sli_resume_iocb(phba, pring); |
| 3566 | |
| 3567 | if ((pring->lpfc_sli_cmd_available)) |
| 3568 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3569 | |
| 3570 | } |
| 3571 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3572 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3573 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3574 | } |
| 3575 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3576 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3577 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3578 | * @phba: Pointer to HBA context object. |
| 3579 | * @pring: Pointer to driver SLI ring object. |
| 3580 | * @mask: Host attention register mask for this ring. |
| 3581 | * |
| 3582 | * This function is called from the worker thread when there is a pending |
| 3583 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3584 | * queue. The caller does not hold any lock. The function will remove each |
| 3585 | * response iocb from the response worker queue and calls the handle |
| 3586 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3587 | **/ |
| 3588 | static void |
| 3589 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3590 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3591 | { |
| 3592 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3593 | struct hbq_dmabuf *dmabuf; |
| 3594 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3595 | unsigned long iflag; |
| 3596 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3597 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3598 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3599 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3600 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3601 | /* Get the response iocb from the head of work queue */ |
| 3602 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3603 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3604 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3605 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3606 | |
| 3607 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3608 | case CQE_CODE_COMPL_WQE: |
| 3609 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3610 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3611 | /* Translate ELS WCQE to response IOCBQ */ |
| 3612 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3613 | irspiocbq); |
| 3614 | if (irspiocbq) |
| 3615 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3616 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3617 | break; |
| 3618 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3619 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3620 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3621 | cq_event); |
| 3622 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3623 | break; |
| 3624 | default: |
| 3625 | break; |
| 3626 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3627 | } |
| 3628 | } |
| 3629 | |
| 3630 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3631 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3632 | * @phba: Pointer to HBA context object. |
| 3633 | * @pring: Pointer to driver SLI ring object. |
| 3634 | * |
| 3635 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3636 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3637 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3638 | * the return of this function. The caller is not required to hold any locks. |
| 3639 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3640 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3641 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3642 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3643 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3644 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3645 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3646 | if (pring->ringno == LPFC_ELS_RING) { |
| 3647 | lpfc_fabric_abort_hba(phba); |
| 3648 | } |
| 3649 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3650 | /* Error everything on txq and txcmplq |
| 3651 | * First do the txq. |
| 3652 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3653 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3654 | spin_lock_irq(&pring->ring_lock); |
| 3655 | list_splice_init(&pring->txq, &completions); |
| 3656 | pring->txq_cnt = 0; |
| 3657 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3658 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3659 | spin_lock_irq(&phba->hbalock); |
| 3660 | /* Next issue ABTS for everything on the txcmplq */ |
| 3661 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3662 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3663 | spin_unlock_irq(&phba->hbalock); |
| 3664 | } else { |
| 3665 | spin_lock_irq(&phba->hbalock); |
| 3666 | list_splice_init(&pring->txq, &completions); |
| 3667 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3668 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3669 | /* Next issue ABTS for everything on the txcmplq */ |
| 3670 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3671 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3672 | spin_unlock_irq(&phba->hbalock); |
| 3673 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3674 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3675 | /* Cancel all the IOCBs from the completions list */ |
| 3676 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3677 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3678 | } |
| 3679 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3680 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3681 | * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring |
| 3682 | * @phba: Pointer to HBA context object. |
| 3683 | * @pring: Pointer to driver SLI ring object. |
| 3684 | * |
| 3685 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3686 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3687 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3688 | * the return of this function. The caller is not required to hold any locks. |
| 3689 | **/ |
| 3690 | void |
| 3691 | lpfc_sli_abort_wqe_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3692 | { |
| 3693 | LIST_HEAD(completions); |
| 3694 | struct lpfc_iocbq *iocb, *next_iocb; |
| 3695 | |
| 3696 | if (pring->ringno == LPFC_ELS_RING) |
| 3697 | lpfc_fabric_abort_hba(phba); |
| 3698 | |
| 3699 | spin_lock_irq(&phba->hbalock); |
| 3700 | /* Next issue ABTS for everything on the txcmplq */ |
| 3701 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3702 | lpfc_sli4_abort_nvme_io(phba, pring, iocb); |
| 3703 | spin_unlock_irq(&phba->hbalock); |
| 3704 | } |
| 3705 | |
| 3706 | |
| 3707 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3708 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3709 | * @phba: Pointer to HBA context object. |
| 3710 | * @pring: Pointer to driver SLI ring object. |
| 3711 | * |
| 3712 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 3713 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3714 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3715 | * the return of this function. The caller is not required to hold any locks. |
| 3716 | **/ |
| 3717 | void |
| 3718 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 3719 | { |
| 3720 | struct lpfc_sli *psli = &phba->sli; |
| 3721 | struct lpfc_sli_ring *pring; |
| 3722 | uint32_t i; |
| 3723 | |
| 3724 | /* Look on all the FCP Rings for the iotag */ |
| 3725 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3726 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3727 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3728 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3729 | } |
| 3730 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3731 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3732 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3733 | } |
| 3734 | } |
| 3735 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3736 | /** |
| 3737 | * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings |
| 3738 | * @phba: Pointer to HBA context object. |
| 3739 | * |
| 3740 | * This function aborts all wqes in NVME rings. This function issues an |
| 3741 | * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in |
| 3742 | * the txcmplq is not guaranteed to complete before the return of this |
| 3743 | * function. The caller is not required to hold any locks. |
| 3744 | **/ |
| 3745 | void |
| 3746 | lpfc_sli_abort_nvme_rings(struct lpfc_hba *phba) |
| 3747 | { |
| 3748 | struct lpfc_sli_ring *pring; |
| 3749 | uint32_t i; |
| 3750 | |
| 3751 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3752 | return; |
| 3753 | |
| 3754 | /* Abort all IO on each NVME ring. */ |
| 3755 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 3756 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 3757 | lpfc_sli_abort_wqe_ring(phba, pring); |
| 3758 | } |
| 3759 | } |
| 3760 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3761 | |
| 3762 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3763 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3764 | * @phba: Pointer to HBA context object. |
| 3765 | * |
| 3766 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3767 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3768 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3769 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3770 | * slot has been permanently disabled. |
| 3771 | **/ |
| 3772 | void |
| 3773 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3774 | { |
| 3775 | LIST_HEAD(txq); |
| 3776 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3777 | struct lpfc_sli *psli = &phba->sli; |
| 3778 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3779 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 3780 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3781 | |
| 3782 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3783 | /* Indicate the I/O queues are flushed */ |
| 3784 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3785 | spin_unlock_irq(&phba->hbalock); |
| 3786 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3787 | /* Look on all the FCP Rings for the iotag */ |
| 3788 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3789 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3790 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3791 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3792 | spin_lock_irq(&pring->ring_lock); |
| 3793 | /* Retrieve everything on txq */ |
| 3794 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 3795 | list_for_each_entry_safe(piocb, next_iocb, |
| 3796 | &pring->txcmplq, list) |
| 3797 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3798 | /* Retrieve everything on the txcmplq */ |
| 3799 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3800 | pring->txq_cnt = 0; |
| 3801 | pring->txcmplq_cnt = 0; |
| 3802 | spin_unlock_irq(&pring->ring_lock); |
| 3803 | |
| 3804 | /* Flush the txq */ |
| 3805 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 3806 | IOSTAT_LOCAL_REJECT, |
| 3807 | IOERR_SLI_DOWN); |
| 3808 | /* Flush the txcmpq */ |
| 3809 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 3810 | IOSTAT_LOCAL_REJECT, |
| 3811 | IOERR_SLI_DOWN); |
| 3812 | } |
| 3813 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3814 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3815 | |
| 3816 | spin_lock_irq(&phba->hbalock); |
| 3817 | /* Retrieve everything on txq */ |
| 3818 | list_splice_init(&pring->txq, &txq); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 3819 | list_for_each_entry_safe(piocb, next_iocb, |
| 3820 | &pring->txcmplq, list) |
| 3821 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3822 | /* Retrieve everything on the txcmplq */ |
| 3823 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3824 | pring->txq_cnt = 0; |
| 3825 | pring->txcmplq_cnt = 0; |
| 3826 | spin_unlock_irq(&phba->hbalock); |
| 3827 | |
| 3828 | /* Flush the txq */ |
| 3829 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3830 | IOERR_SLI_DOWN); |
| 3831 | /* Flush the txcmpq */ |
| 3832 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3833 | IOERR_SLI_DOWN); |
| 3834 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3838 | * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings |
| 3839 | * @phba: Pointer to HBA context object. |
| 3840 | * |
| 3841 | * This function flushes all wqes in the nvme rings and frees all resources |
| 3842 | * in the txcmplq. This function does not issue abort wqes for the IO |
| 3843 | * commands in txcmplq, they will just be returned with |
| 3844 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3845 | * slot has been permanently disabled. |
| 3846 | **/ |
| 3847 | void |
| 3848 | lpfc_sli_flush_nvme_rings(struct lpfc_hba *phba) |
| 3849 | { |
| 3850 | LIST_HEAD(txcmplq); |
| 3851 | struct lpfc_sli_ring *pring; |
| 3852 | uint32_t i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 3853 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3854 | |
| 3855 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3856 | return; |
| 3857 | |
| 3858 | /* Hint to other driver operations that a flush is in progress. */ |
| 3859 | spin_lock_irq(&phba->hbalock); |
| 3860 | phba->hba_flag |= HBA_NVME_IOQ_FLUSH; |
| 3861 | spin_unlock_irq(&phba->hbalock); |
| 3862 | |
| 3863 | /* Cycle through all NVME rings and complete each IO with |
| 3864 | * a local driver reason code. This is a flush so no |
| 3865 | * abort exchange to FW. |
| 3866 | */ |
| 3867 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 3868 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 3869 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3870 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 3871 | list_for_each_entry_safe(piocb, next_iocb, |
| 3872 | &pring->txcmplq, list) |
| 3873 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
| 3874 | /* Retrieve everything on the txcmplq */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3875 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3876 | pring->txcmplq_cnt = 0; |
| 3877 | spin_unlock_irq(&pring->ring_lock); |
| 3878 | |
| 3879 | /* Flush the txcmpq &&&PAE */ |
| 3880 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 3881 | IOSTAT_LOCAL_REJECT, |
| 3882 | IOERR_SLI_DOWN); |
| 3883 | } |
| 3884 | } |
| 3885 | |
| 3886 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3887 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3888 | * @phba: Pointer to HBA context object. |
| 3889 | * @mask: Bit mask to be checked. |
| 3890 | * |
| 3891 | * This function reads the host status register and compares |
| 3892 | * with the provided bit mask to check if HBA completed |
| 3893 | * the restart. This function will wait in a loop for the |
| 3894 | * HBA to complete restart. If the HBA does not restart within |
| 3895 | * 15 iterations, the function will reset the HBA again. The |
| 3896 | * function returns 1 when HBA fail to restart otherwise returns |
| 3897 | * zero. |
| 3898 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3899 | static int |
| 3900 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3901 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3902 | uint32_t status; |
| 3903 | int i = 0; |
| 3904 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3905 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3906 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3907 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3908 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3910 | /* |
| 3911 | * Check status register every 100ms for 5 retries, then every |
| 3912 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3913 | * every 2.5 sec for 4. |
| 3914 | * Break our of the loop if errors occurred during init. |
| 3915 | */ |
| 3916 | while (((status & mask) != mask) && |
| 3917 | !(status & HS_FFERM) && |
| 3918 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3919 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3920 | if (i <= 5) |
| 3921 | msleep(10); |
| 3922 | else if (i <= 10) |
| 3923 | msleep(500); |
| 3924 | else |
| 3925 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3926 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3927 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3928 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3929 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3930 | lpfc_sli_brdrestart(phba); |
| 3931 | } |
| 3932 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3933 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3934 | retval = 1; |
| 3935 | break; |
| 3936 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3937 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3939 | /* Check to see if any errors occurred during init */ |
| 3940 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3941 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3942 | "2751 Adapter failed to restart, " |
| 3943 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3944 | status, |
| 3945 | readl(phba->MBslimaddr + 0xa8), |
| 3946 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3947 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3948 | retval = 1; |
| 3949 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3950 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3951 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3952 | } |
| 3953 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3954 | /** |
| 3955 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3956 | * @phba: Pointer to HBA context object. |
| 3957 | * @mask: Bit mask to be checked. |
| 3958 | * |
| 3959 | * This function checks the host status register to check if HBA is |
| 3960 | * ready. This function will wait in a loop for the HBA to be ready |
| 3961 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3962 | * function again. The function returns 1 when HBA fail to be ready |
| 3963 | * otherwise returns zero. |
| 3964 | **/ |
| 3965 | static int |
| 3966 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3967 | { |
| 3968 | uint32_t status; |
| 3969 | int retval = 0; |
| 3970 | |
| 3971 | /* Read the HBA Host Status Register */ |
| 3972 | status = lpfc_sli4_post_status_check(phba); |
| 3973 | |
| 3974 | if (status) { |
| 3975 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3976 | lpfc_sli_brdrestart(phba); |
| 3977 | status = lpfc_sli4_post_status_check(phba); |
| 3978 | } |
| 3979 | |
| 3980 | /* Check to see if any errors occurred during init */ |
| 3981 | if (status) { |
| 3982 | phba->link_state = LPFC_HBA_ERROR; |
| 3983 | retval = 1; |
| 3984 | } else |
| 3985 | phba->sli4_hba.intr_enable = 0; |
| 3986 | |
| 3987 | return retval; |
| 3988 | } |
| 3989 | |
| 3990 | /** |
| 3991 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3992 | * @phba: Pointer to HBA context object. |
| 3993 | * @mask: Bit mask to be checked. |
| 3994 | * |
| 3995 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3996 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3997 | **/ |
| 3998 | int |
| 3999 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 4000 | { |
| 4001 | return phba->lpfc_sli_brdready(phba, mask); |
| 4002 | } |
| 4003 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4004 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 4005 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4006 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4007 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4008 | * @phba: Pointer to HBA context object. |
| 4009 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 4010 | * This function is called before resetting an HBA. This function is called |
| 4011 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4012 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4013 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4014 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4015 | uint32_t __iomem *resp_buf; |
| 4016 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4017 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4018 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4019 | int i; |
| 4020 | uint8_t hdrtype; |
| 4021 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4022 | lockdep_assert_held(&phba->hbalock); |
| 4023 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4024 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4025 | if (hdrtype != 0x80 || |
| 4026 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4027 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4028 | return; |
| 4029 | |
| 4030 | /* |
| 4031 | * Tell the other part of the chip to suspend temporarily all |
| 4032 | * its DMA activity. |
| 4033 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4034 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4035 | |
| 4036 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4037 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4038 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4039 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4040 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4041 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4042 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4043 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4044 | return; |
| 4045 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4046 | /* Clear Chip error bit */ |
| 4047 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4048 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | mbox = 0; |
| 4052 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4053 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4054 | |
| 4055 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4056 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4057 | writel(mbox, mbox_buf); |
| 4058 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4059 | for (i = 0; i < 50; i++) { |
| 4060 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4061 | return; |
| 4062 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4063 | mdelay(1); |
| 4064 | else |
| 4065 | break; |
| 4066 | } |
| 4067 | resp_data = 0; |
| 4068 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4069 | return; |
| 4070 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4071 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4072 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4073 | goto restore_hc; |
| 4074 | else |
| 4075 | goto clear_errat; |
| 4076 | } |
| 4077 | |
| 4078 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4079 | resp_data = 0; |
| 4080 | for (i = 0; i < 500; i++) { |
| 4081 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4082 | return; |
| 4083 | if (resp_data != mbox) |
| 4084 | mdelay(1); |
| 4085 | else |
| 4086 | break; |
| 4087 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4088 | |
| 4089 | clear_errat: |
| 4090 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4091 | while (++i < 500) { |
| 4092 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4093 | return; |
| 4094 | if (!(ha_copy & HA_ERATT)) |
| 4095 | mdelay(1); |
| 4096 | else |
| 4097 | break; |
| 4098 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4099 | |
| 4100 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4101 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4102 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4103 | } |
| 4104 | |
| 4105 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4106 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4107 | writel(hc_copy, phba->HCregaddr); |
| 4108 | readl(phba->HCregaddr); /* flush */ |
| 4109 | } |
| 4110 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4111 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4112 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4113 | * @phba: Pointer to HBA context object. |
| 4114 | * |
| 4115 | * This function issues a kill_board mailbox command and waits for |
| 4116 | * the error attention interrupt. This function is called for stopping |
| 4117 | * the firmware processing. The caller is not required to hold any |
| 4118 | * locks. This function calls lpfc_hba_down_post function to free |
| 4119 | * any pending commands after the kill. The function will return 1 when it |
| 4120 | * fails to kill the board else will return 0. |
| 4121 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4122 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4123 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4124 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4125 | struct lpfc_sli *psli; |
| 4126 | LPFC_MBOXQ_t *pmb; |
| 4127 | uint32_t status; |
| 4128 | uint32_t ha_copy; |
| 4129 | int retval; |
| 4130 | int i = 0; |
| 4131 | |
| 4132 | psli = &phba->sli; |
| 4133 | |
| 4134 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4135 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4136 | "0329 Kill HBA Data: x%x x%x\n", |
| 4137 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4138 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4139 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4140 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4141 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4142 | |
| 4143 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4144 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4145 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4146 | spin_unlock_irq(&phba->hbalock); |
| 4147 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4148 | return 1; |
| 4149 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4150 | status &= ~HC_ERINT_ENA; |
| 4151 | writel(status, phba->HCregaddr); |
| 4152 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4153 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4154 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4155 | |
| 4156 | lpfc_kill_board(phba, pmb); |
| 4157 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4158 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4159 | |
| 4160 | if (retval != MBX_SUCCESS) { |
| 4161 | if (retval != MBX_BUSY) |
| 4162 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4163 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4164 | "2752 KILL_BOARD command failed retval %d\n", |
| 4165 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4166 | spin_lock_irq(&phba->hbalock); |
| 4167 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4168 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4169 | return 1; |
| 4170 | } |
| 4171 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4172 | spin_lock_irq(&phba->hbalock); |
| 4173 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4174 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4175 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4176 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4177 | |
| 4178 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4179 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4180 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4181 | * board is now undefined. |
| 4182 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4183 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4184 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4185 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4186 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4187 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4188 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4192 | if (ha_copy & HA_ERATT) { |
| 4193 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4194 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4195 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4196 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4197 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4198 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4199 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4200 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4201 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4202 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4203 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4204 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4205 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4206 | } |
| 4207 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4208 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4209 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4210 | * @phba: Pointer to HBA context object. |
| 4211 | * |
| 4212 | * This function resets the HBA by writing HC_INITFF to the control |
| 4213 | * register. After the HBA resets, this function resets all the iocb ring |
| 4214 | * indices. This function disables PCI layer parity checking during |
| 4215 | * the reset. |
| 4216 | * This function returns 0 always. |
| 4217 | * The caller is not required to hold any locks. |
| 4218 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4219 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4220 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4221 | { |
| 4222 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4223 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4224 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4225 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4226 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4227 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4228 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4229 | /* Reset HBA */ |
| 4230 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4231 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4232 | (phba->pport) ? phba->pport->port_state : 0, |
| 4233 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4234 | |
| 4235 | /* perform board reset */ |
| 4236 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4237 | phba->link_events = 0; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4238 | if (phba->pport) { |
| 4239 | phba->pport->fc_myDID = 0; |
| 4240 | phba->pport->fc_prevDID = 0; |
| 4241 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4242 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4243 | /* Turn off parity checking and serr during the physical reset */ |
| 4244 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4245 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4246 | (cfg_value & |
| 4247 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4248 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4249 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4250 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4251 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4252 | writel(HC_INITFF, phba->HCregaddr); |
| 4253 | mdelay(1); |
| 4254 | readl(phba->HCregaddr); /* flush */ |
| 4255 | writel(0, phba->HCregaddr); |
| 4256 | readl(phba->HCregaddr); /* flush */ |
| 4257 | |
| 4258 | /* Restore PCI cmd register */ |
| 4259 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4260 | |
| 4261 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4262 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4263 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4264 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4265 | pring->sli.sli3.rspidx = 0; |
| 4266 | pring->sli.sli3.next_cmdidx = 0; |
| 4267 | pring->sli.sli3.local_getidx = 0; |
| 4268 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4269 | pring->missbufcnt = 0; |
| 4270 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4271 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4272 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4273 | return 0; |
| 4274 | } |
| 4275 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4276 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4277 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4278 | * @phba: Pointer to HBA context object. |
| 4279 | * |
| 4280 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4281 | * checking during resets the device. The caller is not required to hold |
| 4282 | * any locks. |
| 4283 | * |
| 4284 | * This function returns 0 always. |
| 4285 | **/ |
| 4286 | int |
| 4287 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4288 | { |
| 4289 | struct lpfc_sli *psli = &phba->sli; |
| 4290 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4291 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4292 | |
| 4293 | /* Reset HBA */ |
| 4294 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4295 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4296 | phba->pport->port_state, psli->sli_flag, |
| 4297 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4298 | |
| 4299 | /* perform board reset */ |
| 4300 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4301 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4302 | phba->pport->fc_myDID = 0; |
| 4303 | phba->pport->fc_prevDID = 0; |
| 4304 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4305 | spin_lock_irq(&phba->hbalock); |
| 4306 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4307 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4308 | spin_unlock_irq(&phba->hbalock); |
| 4309 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4310 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4311 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4312 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4313 | return rc; |
| 4314 | } |
| 4315 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4316 | /* Now physically reset the device */ |
| 4317 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4318 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4319 | |
| 4320 | /* Turn off parity checking and serr during the physical reset */ |
| 4321 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4322 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4323 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4324 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4325 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4326 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4327 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4328 | /* Restore PCI cmd register */ |
| 4329 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4330 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4331 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | /** |
| 4335 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4336 | * @phba: Pointer to HBA context object. |
| 4337 | * |
| 4338 | * This function is called in the SLI initialization code path to |
| 4339 | * restart the HBA. The caller is not required to hold any lock. |
| 4340 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4341 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4342 | * function to free any pending commands. The function enables |
| 4343 | * POST only during the first initialization. The function returns zero. |
| 4344 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4345 | * command before the return of this function. |
| 4346 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4347 | static int |
| 4348 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4349 | { |
| 4350 | MAILBOX_t *mb; |
| 4351 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4352 | volatile uint32_t word0; |
| 4353 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4354 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4355 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4356 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4357 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4358 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4359 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4360 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4361 | psli = &phba->sli; |
| 4362 | |
| 4363 | /* Restart HBA */ |
| 4364 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4365 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4366 | (phba->pport) ? phba->pport->port_state : 0, |
| 4367 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4368 | |
| 4369 | word0 = 0; |
| 4370 | mb = (MAILBOX_t *) &word0; |
| 4371 | mb->mbxCommand = MBX_RESTART; |
| 4372 | mb->mbxHc = 1; |
| 4373 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4374 | lpfc_reset_barrier(phba); |
| 4375 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4376 | to_slim = phba->MBslimaddr; |
| 4377 | writel(*(uint32_t *) mb, to_slim); |
| 4378 | readl(to_slim); /* flush */ |
| 4379 | |
| 4380 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4381 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4382 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4383 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4384 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4385 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4386 | writel(*(uint32_t *) mb, to_slim); |
| 4387 | readl(to_slim); /* flush */ |
| 4388 | |
| 4389 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4390 | if (phba->pport) |
| 4391 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4392 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4393 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4394 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4395 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4396 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4397 | psli->stats_start = get_seconds(); |
| 4398 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4399 | /* Give the INITFF and Post time to settle. */ |
| 4400 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4401 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4402 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4403 | if (hba_aer_enabled) |
| 4404 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4405 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4406 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4407 | |
| 4408 | return 0; |
| 4409 | } |
| 4410 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4411 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4412 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4413 | * @phba: Pointer to HBA context object. |
| 4414 | * |
| 4415 | * This function is called in the SLI initialization code path to restart |
| 4416 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4417 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4418 | * free any pending commands. |
| 4419 | **/ |
| 4420 | static int |
| 4421 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4422 | { |
| 4423 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4424 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4425 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4426 | |
| 4427 | /* Restart HBA */ |
| 4428 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4429 | "0296 Restart HBA Data: x%x x%x\n", |
| 4430 | phba->pport->port_state, psli->sli_flag); |
| 4431 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4432 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4433 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4434 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4435 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4436 | |
| 4437 | spin_lock_irq(&phba->hbalock); |
| 4438 | phba->pport->stopped = 0; |
| 4439 | phba->link_state = LPFC_INIT_START; |
| 4440 | phba->hba_flag = 0; |
| 4441 | spin_unlock_irq(&phba->hbalock); |
| 4442 | |
| 4443 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4444 | psli->stats_start = get_seconds(); |
| 4445 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4446 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4447 | if (hba_aer_enabled) |
| 4448 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4449 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4450 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4451 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4452 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4453 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4454 | } |
| 4455 | |
| 4456 | /** |
| 4457 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4458 | * @phba: Pointer to HBA context object. |
| 4459 | * |
| 4460 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4461 | * API jump table function pointer from the lpfc_hba struct. |
| 4462 | **/ |
| 4463 | int |
| 4464 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4465 | { |
| 4466 | return phba->lpfc_sli_brdrestart(phba); |
| 4467 | } |
| 4468 | |
| 4469 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4470 | * 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] | 4471 | * @phba: Pointer to HBA context object. |
| 4472 | * |
| 4473 | * This function is called after a HBA restart to wait for successful |
| 4474 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4475 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4476 | * iteration, the function will restart the HBA again. The function returns |
| 4477 | * zero if HBA successfully restarted else returns negative error code. |
| 4478 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4479 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4480 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4481 | { |
| 4482 | uint32_t status, i = 0; |
| 4483 | |
| 4484 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4485 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4486 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4487 | |
| 4488 | /* Check status register to see what current state is */ |
| 4489 | i = 0; |
| 4490 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4491 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4492 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4493 | * retries, then every 1 sec for 50 retires for a total of |
| 4494 | * ~60 seconds before reset the board again and check every |
| 4495 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4496 | * board ready is required by the Falcon FIPS zeroization |
| 4497 | * complete, and any reset the board in between shall cause |
| 4498 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4499 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4500 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4501 | /* Adapter failed to init, timeout, status reg |
| 4502 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4503 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4504 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4505 | "timeout, status reg x%x, " |
| 4506 | "FW Data: A8 x%x AC x%x\n", status, |
| 4507 | readl(phba->MBslimaddr + 0xa8), |
| 4508 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4509 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4510 | return -ETIMEDOUT; |
| 4511 | } |
| 4512 | |
| 4513 | /* Check to see if any errors occurred during init */ |
| 4514 | if (status & HS_FFERM) { |
| 4515 | /* ERROR: During chipset initialization */ |
| 4516 | /* Adapter failed to init, chipset, status reg |
| 4517 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4518 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4519 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4520 | "chipset, status reg x%x, " |
| 4521 | "FW Data: A8 x%x AC x%x\n", status, |
| 4522 | readl(phba->MBslimaddr + 0xa8), |
| 4523 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4524 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4525 | return -EIO; |
| 4526 | } |
| 4527 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4528 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4529 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4530 | else if (i <= 100) |
| 4531 | msleep(100); |
| 4532 | else |
| 4533 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4534 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4535 | if (i == 150) { |
| 4536 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4537 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4538 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4539 | } |
| 4540 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4541 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4542 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | /* Check to see if any errors occurred during init */ |
| 4546 | if (status & HS_FFERM) { |
| 4547 | /* ERROR: During chipset initialization */ |
| 4548 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4549 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4550 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4551 | "status reg x%x, " |
| 4552 | "FW Data: A8 x%x AC x%x\n", status, |
| 4553 | readl(phba->MBslimaddr + 0xa8), |
| 4554 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4555 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4556 | return -EIO; |
| 4557 | } |
| 4558 | |
| 4559 | /* Clear all interrupt enable conditions */ |
| 4560 | writel(0, phba->HCregaddr); |
| 4561 | readl(phba->HCregaddr); /* flush */ |
| 4562 | |
| 4563 | /* setup host attn register */ |
| 4564 | writel(0xffffffff, phba->HAregaddr); |
| 4565 | readl(phba->HAregaddr); /* flush */ |
| 4566 | return 0; |
| 4567 | } |
| 4568 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4569 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4570 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4571 | * |
| 4572 | * This function calculates and returns the number of HBQs required to be |
| 4573 | * configured. |
| 4574 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4575 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4576 | lpfc_sli_hbq_count(void) |
| 4577 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4578 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4579 | } |
| 4580 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4581 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4582 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4583 | * |
| 4584 | * This function adds the number of hbq entries in every HBQ to get |
| 4585 | * the total number of hbq entries required for the HBA and returns |
| 4586 | * the total count. |
| 4587 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4588 | static int |
| 4589 | lpfc_sli_hbq_entry_count(void) |
| 4590 | { |
| 4591 | int hbq_count = lpfc_sli_hbq_count(); |
| 4592 | int count = 0; |
| 4593 | int i; |
| 4594 | |
| 4595 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4596 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4597 | return count; |
| 4598 | } |
| 4599 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4600 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4601 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4602 | * |
| 4603 | * This function calculates amount of memory required for all hbq entries |
| 4604 | * to be configured and returns the total memory required. |
| 4605 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4606 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4607 | lpfc_sli_hbq_size(void) |
| 4608 | { |
| 4609 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4610 | } |
| 4611 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4612 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4613 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4614 | * @phba: Pointer to HBA context object. |
| 4615 | * |
| 4616 | * This function is called during the SLI initialization to configure |
| 4617 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4618 | * required to hold any locks. This function will return zero if successful |
| 4619 | * else it will return negative error code. |
| 4620 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4621 | static int |
| 4622 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4623 | { |
| 4624 | int hbq_count = lpfc_sli_hbq_count(); |
| 4625 | LPFC_MBOXQ_t *pmb; |
| 4626 | MAILBOX_t *pmbox; |
| 4627 | uint32_t hbqno; |
| 4628 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4629 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4630 | /* Get a Mailbox buffer to setup mailbox |
| 4631 | * commands for HBA initialization |
| 4632 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4633 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4634 | |
| 4635 | if (!pmb) |
| 4636 | return -ENOMEM; |
| 4637 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4638 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4639 | |
| 4640 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4641 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4642 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4643 | |
| 4644 | hbq_entry_index = 0; |
| 4645 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4646 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4647 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4648 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4649 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4650 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4651 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4652 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4653 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4654 | |
| 4655 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4656 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4657 | mbxStatus <status>, ring <num> */ |
| 4658 | |
| 4659 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4660 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4661 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4662 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4663 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4664 | pmbox->mbxStatus, hbqno); |
| 4665 | |
| 4666 | phba->link_state = LPFC_HBA_ERROR; |
| 4667 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4668 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4669 | } |
| 4670 | } |
| 4671 | phba->hbq_count = hbq_count; |
| 4672 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4673 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4674 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4675 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4676 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4677 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4678 | return 0; |
| 4679 | } |
| 4680 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4681 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4682 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4683 | * @phba: Pointer to HBA context object. |
| 4684 | * |
| 4685 | * This function is called during the SLI initialization to configure |
| 4686 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4687 | * required to hold any locks. This function will return zero if successful |
| 4688 | * else it will return negative error code. |
| 4689 | **/ |
| 4690 | static int |
| 4691 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4692 | { |
| 4693 | phba->hbq_in_use = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4694 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 4695 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4696 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4697 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4698 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4699 | return 0; |
| 4700 | } |
| 4701 | |
| 4702 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4703 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4704 | * @phba: Pointer to HBA context object. |
| 4705 | * @sli_mode: sli mode - 2/3 |
| 4706 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4707 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4708 | * to issue config_port mailbox command. This function restarts the |
| 4709 | * HBA firmware and issues a config_port mailbox command to configure |
| 4710 | * the SLI interface in the sli mode specified by sli_mode |
| 4711 | * variable. The caller is not required to hold any locks. |
| 4712 | * The function returns 0 if successful, else returns negative error |
| 4713 | * code. |
| 4714 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4715 | int |
| 4716 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4717 | { |
| 4718 | LPFC_MBOXQ_t *pmb; |
| 4719 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4720 | |
| 4721 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4722 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4723 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4724 | return -ENOMEM; |
| 4725 | } |
| 4726 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4727 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4728 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4729 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4730 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4731 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4732 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4733 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4734 | rc = lpfc_sli_chipset_init(phba); |
| 4735 | if (rc) |
| 4736 | break; |
| 4737 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4738 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4739 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4740 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4741 | resetcount++; |
| 4742 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4743 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4744 | * value of 0 means the call was successful. Any other |
| 4745 | * nonzero value is a failure, but if ERESTART is returned, |
| 4746 | * the driver may reset the HBA and try again. |
| 4747 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4748 | rc = lpfc_config_port_prep(phba); |
| 4749 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4750 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4751 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4752 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4753 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4754 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4755 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4756 | lpfc_config_port(phba, pmb); |
| 4757 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4758 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4759 | LPFC_SLI3_HBQ_ENABLED | |
| 4760 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4761 | LPFC_SLI3_BG_ENABLED | |
| 4762 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4763 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4764 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4765 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4766 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4767 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4768 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4769 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4770 | spin_unlock_irq(&phba->hbalock); |
| 4771 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4772 | } else { |
| 4773 | /* Allow asynchronous mailbox command to go through */ |
| 4774 | spin_lock_irq(&phba->hbalock); |
| 4775 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4776 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4777 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4778 | |
| 4779 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4780 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4781 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4782 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4783 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4784 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4785 | if (!done) { |
| 4786 | rc = -EINVAL; |
| 4787 | goto do_prep_failed; |
| 4788 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4789 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4790 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4791 | rc = -ENXIO; |
| 4792 | goto do_prep_failed; |
| 4793 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4794 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4795 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4796 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4797 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4798 | phba->max_vpi : phba->max_vports; |
| 4799 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4800 | } else |
| 4801 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4802 | phba->fips_level = 0; |
| 4803 | phba->fips_spec_rev = 0; |
| 4804 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4805 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4806 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4807 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4808 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4809 | "2850 Security Crypto Active. FIPS x%d " |
| 4810 | "(Spec Rev: x%d)", |
| 4811 | phba->fips_level, phba->fips_spec_rev); |
| 4812 | } |
| 4813 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4814 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4815 | "2856 Config Port Security Crypto " |
| 4816 | "Error: x%x ", |
| 4817 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4818 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4819 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4820 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4821 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4822 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4823 | |
| 4824 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4825 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4826 | |
| 4827 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4828 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4829 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4830 | else |
| 4831 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4832 | "0443 Adapter did not grant " |
| 4833 | "BlockGuard\n"); |
| 4834 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4835 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4836 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4837 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4838 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4839 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4840 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4841 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4842 | return rc; |
| 4843 | } |
| 4844 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4845 | |
| 4846 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4847 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4848 | * @phba: Pointer to HBA context object. |
| 4849 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4850 | * This function is the main SLI initialization function. This function |
| 4851 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4852 | * error attention handler code. Caller is not required to hold any |
| 4853 | * locks. This function issues config_port mailbox command to configure |
| 4854 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4855 | * calls the config_port_post function to issue init_link mailbox |
| 4856 | * command and to start the discovery. The function will return zero |
| 4857 | * if successful, else it will return negative error code. |
| 4858 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4859 | int |
| 4860 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4861 | { |
| 4862 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4863 | int mode = 3, i; |
| 4864 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4865 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4866 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4867 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4868 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4869 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4870 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4871 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4872 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4873 | break; |
| 4874 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4875 | mode = 2; |
| 4876 | break; |
| 4877 | case 0: |
| 4878 | case 3: |
| 4879 | break; |
| 4880 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4881 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4882 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 4883 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4884 | |
| 4885 | break; |
| 4886 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 4887 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4888 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4889 | rc = lpfc_sli_config_port(phba, mode); |
| 4890 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4891 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4892 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4893 | "1820 Unable to select SLI-3. " |
| 4894 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4895 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4896 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 4897 | else if (rc && mode == 2) |
| 4898 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4899 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4900 | goto lpfc_sli_hba_setup_error; |
| 4901 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4902 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4903 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4904 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4905 | if (!rc) { |
| 4906 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4907 | "2709 This device supports " |
| 4908 | "Advanced Error Reporting (AER)\n"); |
| 4909 | spin_lock_irq(&phba->hbalock); |
| 4910 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4911 | spin_unlock_irq(&phba->hbalock); |
| 4912 | } else { |
| 4913 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4914 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 4915 | "Advanced Error Reporting (AER): %d\n", |
| 4916 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4917 | phba->cfg_aer_support = 0; |
| 4918 | } |
| 4919 | } |
| 4920 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4921 | if (phba->sli_rev == 3) { |
| 4922 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4923 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4924 | } else { |
| 4925 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4926 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4927 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4928 | } |
| 4929 | |
| 4930 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4931 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4932 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4933 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4934 | |
| 4935 | if (rc) |
| 4936 | goto lpfc_sli_hba_setup_error; |
| 4937 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4938 | /* Initialize VPIs. */ |
| 4939 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4940 | /* |
| 4941 | * The VPI bitmask and physical ID array are allocated |
| 4942 | * and initialized once only - at driver load. A port |
| 4943 | * reset doesn't need to reinitialize this memory. |
| 4944 | */ |
| 4945 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4946 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4947 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4948 | GFP_KERNEL); |
| 4949 | if (!phba->vpi_bmask) { |
| 4950 | rc = -ENOMEM; |
| 4951 | goto lpfc_sli_hba_setup_error; |
| 4952 | } |
| 4953 | |
| 4954 | phba->vpi_ids = kzalloc( |
| 4955 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4956 | GFP_KERNEL); |
| 4957 | if (!phba->vpi_ids) { |
| 4958 | kfree(phba->vpi_bmask); |
| 4959 | rc = -ENOMEM; |
| 4960 | goto lpfc_sli_hba_setup_error; |
| 4961 | } |
| 4962 | for (i = 0; i < phba->max_vpi; i++) |
| 4963 | phba->vpi_ids[i] = i; |
| 4964 | } |
| 4965 | } |
| 4966 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4967 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4968 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4969 | rc = lpfc_sli_hbq_setup(phba); |
| 4970 | if (rc) |
| 4971 | goto lpfc_sli_hba_setup_error; |
| 4972 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4973 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4974 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4975 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4976 | |
| 4977 | rc = lpfc_config_port_post(phba); |
| 4978 | if (rc) |
| 4979 | goto lpfc_sli_hba_setup_error; |
| 4980 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4981 | return rc; |
| 4982 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4983 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4984 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4985 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4986 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4987 | return rc; |
| 4988 | } |
| 4989 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4990 | /** |
| 4991 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4992 | * @phba: Pointer to HBA context object. |
| 4993 | * @mboxq: mailbox pointer. |
| 4994 | * This function issue a dump mailbox command to read config region |
| 4995 | * 23 and parse the records in the region and populate driver |
| 4996 | * data structure. |
| 4997 | **/ |
| 4998 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4999 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5000 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5001 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5002 | struct lpfc_dmabuf *mp; |
| 5003 | struct lpfc_mqe *mqe; |
| 5004 | uint32_t data_length; |
| 5005 | int rc; |
| 5006 | |
| 5007 | /* Program the default value of vlan_id and fc_map */ |
| 5008 | phba->valid_vlan = 0; |
| 5009 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5010 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5011 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5012 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5013 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5014 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5015 | return -ENOMEM; |
| 5016 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5017 | mqe = &mboxq->u.mqe; |
| 5018 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 5019 | rc = -ENOMEM; |
| 5020 | goto out_free_mboxq; |
| 5021 | } |
| 5022 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5023 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 5024 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5025 | |
| 5026 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5027 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5028 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5029 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5030 | "CQ: x%x x%x x%x x%x\n", |
| 5031 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5032 | bf_get(lpfc_mqe_command, mqe), |
| 5033 | bf_get(lpfc_mqe_status, mqe), |
| 5034 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5035 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5036 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5037 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5038 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5039 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5040 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5041 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5042 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5043 | mboxq->mcqe.word0, |
| 5044 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5045 | mboxq->mcqe.trailer); |
| 5046 | |
| 5047 | if (rc) { |
| 5048 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5049 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5050 | rc = -EIO; |
| 5051 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5052 | } |
| 5053 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5054 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5055 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5056 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5057 | rc = -EIO; |
| 5058 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5059 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5060 | |
| 5061 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5062 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5063 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5064 | rc = 0; |
| 5065 | |
| 5066 | out_free_mboxq: |
| 5067 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5068 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | /** |
| 5072 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5073 | * @phba: pointer to lpfc hba data structure. |
| 5074 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5075 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5076 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5077 | * On output, the number of data bytes in @vpd. |
| 5078 | * |
| 5079 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5080 | * addition, this routine gets the port vpd data. |
| 5081 | * |
| 5082 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5083 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5084 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5085 | **/ |
| 5086 | static int |
| 5087 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5088 | uint8_t *vpd, uint32_t *vpd_size) |
| 5089 | { |
| 5090 | int rc = 0; |
| 5091 | uint32_t dma_size; |
| 5092 | struct lpfc_dmabuf *dmabuf; |
| 5093 | struct lpfc_mqe *mqe; |
| 5094 | |
| 5095 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5096 | if (!dmabuf) |
| 5097 | return -ENOMEM; |
| 5098 | |
| 5099 | /* |
| 5100 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5101 | * mailbox command. |
| 5102 | */ |
| 5103 | dma_size = *vpd_size; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 5104 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
| 5105 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5106 | if (!dmabuf->virt) { |
| 5107 | kfree(dmabuf); |
| 5108 | return -ENOMEM; |
| 5109 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5110 | |
| 5111 | /* |
| 5112 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5113 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5114 | * in SLI3. This code corrects the conflicts. |
| 5115 | */ |
| 5116 | lpfc_read_rev(phba, mboxq); |
| 5117 | mqe = &mboxq->u.mqe; |
| 5118 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5119 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5120 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5121 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5122 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5123 | |
| 5124 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5125 | if (rc) { |
| 5126 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5127 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5128 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5129 | return -EIO; |
| 5130 | } |
| 5131 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5132 | /* |
| 5133 | * The available vpd length cannot be bigger than the |
| 5134 | * DMA buffer passed to the port. Catch the less than |
| 5135 | * case and update the caller's size. |
| 5136 | */ |
| 5137 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5138 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5139 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5140 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5141 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5142 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5143 | dmabuf->virt, dmabuf->phys); |
| 5144 | kfree(dmabuf); |
| 5145 | return 0; |
| 5146 | } |
| 5147 | |
| 5148 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5149 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5150 | * @phba: pointer to lpfc hba data structure. |
| 5151 | * |
| 5152 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5153 | * is attached to. |
| 5154 | * |
| 5155 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5156 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5157 | * otherwise - failed to retrieve physical port name |
| 5158 | **/ |
| 5159 | static int |
| 5160 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5161 | { |
| 5162 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5163 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5164 | struct lpfc_controller_attribute *cntl_attr; |
| 5165 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5166 | void *virtaddr = NULL; |
| 5167 | uint32_t alloclen, reqlen; |
| 5168 | uint32_t shdr_status, shdr_add_status; |
| 5169 | union lpfc_sli4_cfg_shdr *shdr; |
| 5170 | char cport_name = 0; |
| 5171 | int rc; |
| 5172 | |
| 5173 | /* We assume nothing at this point */ |
| 5174 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5175 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5176 | |
| 5177 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5178 | if (!mboxq) |
| 5179 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5180 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5181 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5182 | lpfc_sli4_read_config(phba); |
| 5183 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5184 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5185 | |
| 5186 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5187 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5188 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5189 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5190 | LPFC_SLI4_MBX_NEMBED); |
| 5191 | if (alloclen < reqlen) { |
| 5192 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5193 | "3084 Allocated DMA memory size (%d) is " |
| 5194 | "less than the requested DMA memory size " |
| 5195 | "(%d)\n", alloclen, reqlen); |
| 5196 | rc = -ENOMEM; |
| 5197 | goto out_free_mboxq; |
| 5198 | } |
| 5199 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5200 | virtaddr = mboxq->sge_array->addr[0]; |
| 5201 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5202 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5203 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5204 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5205 | if (shdr_status || shdr_add_status || rc) { |
| 5206 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5207 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5208 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5209 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5210 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5211 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5212 | rc, shdr_status, shdr_add_status); |
| 5213 | rc = -ENXIO; |
| 5214 | goto out_free_mboxq; |
| 5215 | } |
| 5216 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5217 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5218 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5219 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5220 | phba->sli4_hba.lnk_info.lnk_no = |
| 5221 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 5222 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5223 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 5224 | phba->sli4_hba.lnk_info.lnk_tp, |
| 5225 | phba->sli4_hba.lnk_info.lnk_no); |
| 5226 | |
| 5227 | retrieve_ppname: |
| 5228 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5229 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5230 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5231 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5232 | LPFC_SLI4_MBX_EMBED); |
| 5233 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5234 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5235 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5236 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5237 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5238 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5239 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5240 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5241 | if (shdr_status || shdr_add_status || rc) { |
| 5242 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5243 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5244 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5245 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5246 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5247 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5248 | rc, shdr_status, shdr_add_status); |
| 5249 | rc = -ENXIO; |
| 5250 | goto out_free_mboxq; |
| 5251 | } |
| 5252 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5253 | case LPFC_LINK_NUMBER_0: |
| 5254 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5255 | &get_port_name->u.response); |
| 5256 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5257 | break; |
| 5258 | case LPFC_LINK_NUMBER_1: |
| 5259 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5260 | &get_port_name->u.response); |
| 5261 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5262 | break; |
| 5263 | case LPFC_LINK_NUMBER_2: |
| 5264 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5265 | &get_port_name->u.response); |
| 5266 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5267 | break; |
| 5268 | case LPFC_LINK_NUMBER_3: |
| 5269 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5270 | &get_port_name->u.response); |
| 5271 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5272 | break; |
| 5273 | default: |
| 5274 | break; |
| 5275 | } |
| 5276 | |
| 5277 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5278 | phba->Port[0] = cport_name; |
| 5279 | phba->Port[1] = '\0'; |
| 5280 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5281 | "3091 SLI get port name: %s\n", phba->Port); |
| 5282 | } |
| 5283 | |
| 5284 | out_free_mboxq: |
| 5285 | if (rc != MBX_TIMEOUT) { |
| 5286 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5287 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5288 | else |
| 5289 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5290 | } |
| 5291 | return rc; |
| 5292 | } |
| 5293 | |
| 5294 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5295 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5296 | * @phba: pointer to lpfc hba data structure. |
| 5297 | * |
| 5298 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5299 | * event queues |
| 5300 | **/ |
| 5301 | static void |
| 5302 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5303 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5304 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5305 | |
| 5306 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 5307 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5308 | if (phba->sli4_hba.nvmels_cq) |
| 5309 | lpfc_sli4_cq_release(phba->sli4_hba.nvmels_cq, |
| 5310 | LPFC_QUEUE_REARM); |
| 5311 | |
| 5312 | if (phba->sli4_hba.fcp_cq) |
| 5313 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) |
| 5314 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[qidx], |
| 5315 | LPFC_QUEUE_REARM); |
| 5316 | |
| 5317 | if (phba->sli4_hba.nvme_cq) |
| 5318 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) |
| 5319 | lpfc_sli4_cq_release(phba->sli4_hba.nvme_cq[qidx], |
| 5320 | LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5321 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5322 | if (phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5323 | lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM); |
| 5324 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5325 | if (phba->sli4_hba.hba_eq) |
| 5326 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) |
| 5327 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[qidx], |
| 5328 | LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5329 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5330 | if (phba->nvmet_support) { |
| 5331 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
| 5332 | lpfc_sli4_cq_release( |
| 5333 | phba->sli4_hba.nvmet_cqset[qidx], |
| 5334 | LPFC_QUEUE_REARM); |
| 5335 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5336 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5337 | |
| 5338 | if (phba->cfg_fof) |
| 5339 | lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5343 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5344 | * @phba: Pointer to HBA context object. |
| 5345 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5346 | * @extnt_count: buffer to hold port available extent count. |
| 5347 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5348 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5349 | * This function calls the port and retrievs the number of available |
| 5350 | * extents and their size for a particular extent type. |
| 5351 | * |
| 5352 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5353 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5354 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5355 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5356 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5357 | { |
| 5358 | int rc = 0; |
| 5359 | uint32_t length; |
| 5360 | uint32_t mbox_tmo; |
| 5361 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5362 | LPFC_MBOXQ_t *mbox; |
| 5363 | |
| 5364 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5365 | if (!mbox) |
| 5366 | return -ENOMEM; |
| 5367 | |
| 5368 | /* Find out how many extents are available for this resource type */ |
| 5369 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5370 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5371 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5372 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5373 | length, LPFC_SLI4_MBX_EMBED); |
| 5374 | |
| 5375 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5376 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5377 | LPFC_SLI4_MBX_EMBED); |
| 5378 | if (unlikely(rc)) { |
| 5379 | rc = -EIO; |
| 5380 | goto err_exit; |
| 5381 | } |
| 5382 | |
| 5383 | if (!phba->sli4_hba.intr_enable) |
| 5384 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5385 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5386 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5387 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5388 | } |
| 5389 | if (unlikely(rc)) { |
| 5390 | rc = -EIO; |
| 5391 | goto err_exit; |
| 5392 | } |
| 5393 | |
| 5394 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5395 | if (bf_get(lpfc_mbox_hdr_status, |
| 5396 | &rsrc_info->header.cfg_shdr.response)) { |
| 5397 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5398 | "2930 Failed to get resource extents " |
| 5399 | "Status 0x%x Add'l Status 0x%x\n", |
| 5400 | bf_get(lpfc_mbox_hdr_status, |
| 5401 | &rsrc_info->header.cfg_shdr.response), |
| 5402 | bf_get(lpfc_mbox_hdr_add_status, |
| 5403 | &rsrc_info->header.cfg_shdr.response)); |
| 5404 | rc = -EIO; |
| 5405 | goto err_exit; |
| 5406 | } |
| 5407 | |
| 5408 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5409 | &rsrc_info->u.rsp); |
| 5410 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5411 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5412 | |
| 5413 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5414 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5415 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5416 | |
| 5417 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5418 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5419 | return rc; |
| 5420 | } |
| 5421 | |
| 5422 | /** |
| 5423 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5424 | * @phba: Pointer to HBA context object. |
| 5425 | * @type: The extent type to check. |
| 5426 | * |
| 5427 | * This function reads the current available extents from the port and checks |
| 5428 | * if the extent count or extent size has changed since the last access. |
| 5429 | * Callers use this routine post port reset to understand if there is a |
| 5430 | * extent reprovisioning requirement. |
| 5431 | * |
| 5432 | * Returns: |
| 5433 | * -Error: error indicates problem. |
| 5434 | * 1: Extent count or size has changed. |
| 5435 | * 0: No changes. |
| 5436 | **/ |
| 5437 | static int |
| 5438 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5439 | { |
| 5440 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5441 | uint16_t size_diff, rsrc_ext_size; |
| 5442 | int rc = 0; |
| 5443 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5444 | struct list_head *rsrc_blk_list = NULL; |
| 5445 | |
| 5446 | size_diff = 0; |
| 5447 | curr_ext_cnt = 0; |
| 5448 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5449 | &rsrc_ext_cnt, |
| 5450 | &rsrc_ext_size); |
| 5451 | if (unlikely(rc)) |
| 5452 | return -EIO; |
| 5453 | |
| 5454 | switch (type) { |
| 5455 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5456 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5457 | break; |
| 5458 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5459 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5460 | break; |
| 5461 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5462 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5463 | break; |
| 5464 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5465 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5466 | break; |
| 5467 | default: |
| 5468 | break; |
| 5469 | } |
| 5470 | |
| 5471 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5472 | curr_ext_cnt++; |
| 5473 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5474 | size_diff++; |
| 5475 | } |
| 5476 | |
| 5477 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5478 | rc = 1; |
| 5479 | |
| 5480 | return rc; |
| 5481 | } |
| 5482 | |
| 5483 | /** |
| 5484 | * lpfc_sli4_cfg_post_extnts - |
| 5485 | * @phba: Pointer to HBA context object. |
| 5486 | * @extnt_cnt - number of available extents. |
| 5487 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5488 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5489 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5490 | * |
| 5491 | * This function executes the extents allocation request. It also |
| 5492 | * takes care of the amount of memory needed to allocate or get the |
| 5493 | * allocated extents. It is the caller's responsibility to evaluate |
| 5494 | * the response. |
| 5495 | * |
| 5496 | * Returns: |
| 5497 | * -Error: Error value describes the condition found. |
| 5498 | * 0: if successful |
| 5499 | **/ |
| 5500 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5501 | 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] | 5502 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5503 | { |
| 5504 | int rc = 0; |
| 5505 | uint32_t req_len; |
| 5506 | uint32_t emb_len; |
| 5507 | uint32_t alloc_len, mbox_tmo; |
| 5508 | |
| 5509 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5510 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5511 | |
| 5512 | /* |
| 5513 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5514 | * accounts for extents-specific word. |
| 5515 | */ |
| 5516 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5517 | sizeof(uint32_t); |
| 5518 | |
| 5519 | /* |
| 5520 | * Presume the allocation and response will fit into an embedded |
| 5521 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5522 | */ |
| 5523 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5524 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5525 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5526 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5527 | sizeof(uint32_t); |
| 5528 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5529 | } |
| 5530 | |
| 5531 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5532 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5533 | req_len, *emb); |
| 5534 | if (alloc_len < req_len) { |
| 5535 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5536 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5537 | "less than the requested DMA memory " |
| 5538 | "size (x%x)\n", alloc_len, req_len); |
| 5539 | return -ENOMEM; |
| 5540 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5541 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5542 | if (unlikely(rc)) |
| 5543 | return -EIO; |
| 5544 | |
| 5545 | if (!phba->sli4_hba.intr_enable) |
| 5546 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5547 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5548 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5549 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5550 | } |
| 5551 | |
| 5552 | if (unlikely(rc)) |
| 5553 | rc = -EIO; |
| 5554 | return rc; |
| 5555 | } |
| 5556 | |
| 5557 | /** |
| 5558 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5559 | * @phba: Pointer to HBA context object. |
| 5560 | * @type: The resource extent type to allocate. |
| 5561 | * |
| 5562 | * This function allocates the number of elements for the specified |
| 5563 | * resource type. |
| 5564 | **/ |
| 5565 | static int |
| 5566 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5567 | { |
| 5568 | bool emb = false; |
| 5569 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5570 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5571 | uint16_t *ids; |
| 5572 | int i, rc; |
| 5573 | unsigned long longs; |
| 5574 | unsigned long *bmask; |
| 5575 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5576 | LPFC_MBOXQ_t *mbox; |
| 5577 | uint32_t length; |
| 5578 | struct lpfc_id_range *id_array = NULL; |
| 5579 | void *virtaddr = NULL; |
| 5580 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5581 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5582 | struct list_head *ext_blk_list; |
| 5583 | |
| 5584 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5585 | &rsrc_cnt, |
| 5586 | &rsrc_size); |
| 5587 | if (unlikely(rc)) |
| 5588 | return -EIO; |
| 5589 | |
| 5590 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5591 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5592 | "3009 No available Resource Extents " |
| 5593 | "for resource type 0x%x: Count: 0x%x, " |
| 5594 | "Size 0x%x\n", type, rsrc_cnt, |
| 5595 | rsrc_size); |
| 5596 | return -ENOMEM; |
| 5597 | } |
| 5598 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5599 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5600 | "2903 Post resource extents type-0x%x: " |
| 5601 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5602 | |
| 5603 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5604 | if (!mbox) |
| 5605 | return -ENOMEM; |
| 5606 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5607 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5608 | if (unlikely(rc)) { |
| 5609 | rc = -EIO; |
| 5610 | goto err_exit; |
| 5611 | } |
| 5612 | |
| 5613 | /* |
| 5614 | * Figure out where the response is located. Then get local pointers |
| 5615 | * to the response data. The port does not guarantee to respond to |
| 5616 | * all extents counts request so update the local variable with the |
| 5617 | * allocated count from the port. |
| 5618 | */ |
| 5619 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5620 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5621 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5622 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5623 | } else { |
| 5624 | virtaddr = mbox->sge_array->addr[0]; |
| 5625 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5626 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5627 | id_array = &n_rsrc->id; |
| 5628 | } |
| 5629 | |
| 5630 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5631 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5632 | |
| 5633 | /* |
| 5634 | * Based on the resource size and count, correct the base and max |
| 5635 | * resource values. |
| 5636 | */ |
| 5637 | length = sizeof(struct lpfc_rsrc_blks); |
| 5638 | switch (type) { |
| 5639 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5640 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5641 | sizeof(unsigned long), |
| 5642 | GFP_KERNEL); |
| 5643 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5644 | rc = -ENOMEM; |
| 5645 | goto err_exit; |
| 5646 | } |
| 5647 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5648 | sizeof(uint16_t), |
| 5649 | GFP_KERNEL); |
| 5650 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5651 | kfree(phba->sli4_hba.rpi_bmask); |
| 5652 | rc = -ENOMEM; |
| 5653 | goto err_exit; |
| 5654 | } |
| 5655 | |
| 5656 | /* |
| 5657 | * The next_rpi was initialized with the maximum available |
| 5658 | * count but the port may allocate a smaller number. Catch |
| 5659 | * that case and update the next_rpi. |
| 5660 | */ |
| 5661 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5662 | |
| 5663 | /* Initialize local ptrs for common extent processing later. */ |
| 5664 | bmask = phba->sli4_hba.rpi_bmask; |
| 5665 | ids = phba->sli4_hba.rpi_ids; |
| 5666 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5667 | break; |
| 5668 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5669 | phba->vpi_bmask = kzalloc(longs * |
| 5670 | sizeof(unsigned long), |
| 5671 | GFP_KERNEL); |
| 5672 | if (unlikely(!phba->vpi_bmask)) { |
| 5673 | rc = -ENOMEM; |
| 5674 | goto err_exit; |
| 5675 | } |
| 5676 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5677 | sizeof(uint16_t), |
| 5678 | GFP_KERNEL); |
| 5679 | if (unlikely(!phba->vpi_ids)) { |
| 5680 | kfree(phba->vpi_bmask); |
| 5681 | rc = -ENOMEM; |
| 5682 | goto err_exit; |
| 5683 | } |
| 5684 | |
| 5685 | /* Initialize local ptrs for common extent processing later. */ |
| 5686 | bmask = phba->vpi_bmask; |
| 5687 | ids = phba->vpi_ids; |
| 5688 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5689 | break; |
| 5690 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5691 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5692 | sizeof(unsigned long), |
| 5693 | GFP_KERNEL); |
| 5694 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5695 | rc = -ENOMEM; |
| 5696 | goto err_exit; |
| 5697 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5698 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5699 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5700 | sizeof(uint16_t), |
| 5701 | GFP_KERNEL); |
| 5702 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5703 | kfree(phba->sli4_hba.xri_bmask); |
| 5704 | rc = -ENOMEM; |
| 5705 | goto err_exit; |
| 5706 | } |
| 5707 | |
| 5708 | /* Initialize local ptrs for common extent processing later. */ |
| 5709 | bmask = phba->sli4_hba.xri_bmask; |
| 5710 | ids = phba->sli4_hba.xri_ids; |
| 5711 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5712 | break; |
| 5713 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5714 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5715 | sizeof(unsigned long), |
| 5716 | GFP_KERNEL); |
| 5717 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5718 | rc = -ENOMEM; |
| 5719 | goto err_exit; |
| 5720 | } |
| 5721 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5722 | sizeof(uint16_t), |
| 5723 | GFP_KERNEL); |
| 5724 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5725 | kfree(phba->sli4_hba.vfi_bmask); |
| 5726 | rc = -ENOMEM; |
| 5727 | goto err_exit; |
| 5728 | } |
| 5729 | |
| 5730 | /* Initialize local ptrs for common extent processing later. */ |
| 5731 | bmask = phba->sli4_hba.vfi_bmask; |
| 5732 | ids = phba->sli4_hba.vfi_ids; |
| 5733 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5734 | break; |
| 5735 | default: |
| 5736 | /* Unsupported Opcode. Fail call. */ |
| 5737 | id_array = NULL; |
| 5738 | bmask = NULL; |
| 5739 | ids = NULL; |
| 5740 | ext_blk_list = NULL; |
| 5741 | goto err_exit; |
| 5742 | } |
| 5743 | |
| 5744 | /* |
| 5745 | * Complete initializing the extent configuration with the |
| 5746 | * allocated ids assigned to this function. The bitmask serves |
| 5747 | * as an index into the array and manages the available ids. The |
| 5748 | * array just stores the ids communicated to the port via the wqes. |
| 5749 | */ |
| 5750 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5751 | if ((i % 2) == 0) |
| 5752 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5753 | &id_array[k]); |
| 5754 | else |
| 5755 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5756 | &id_array[k]); |
| 5757 | |
| 5758 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5759 | if (unlikely(!rsrc_blks)) { |
| 5760 | rc = -ENOMEM; |
| 5761 | kfree(bmask); |
| 5762 | kfree(ids); |
| 5763 | goto err_exit; |
| 5764 | } |
| 5765 | rsrc_blks->rsrc_start = rsrc_id; |
| 5766 | rsrc_blks->rsrc_size = rsrc_size; |
| 5767 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5768 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5769 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5770 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5771 | lpfc_sli4_get_iocb_cnt(phba); |
| 5772 | phba->sli4_hba.nvme_xri_start = |
| 5773 | phba->sli4_hba.scsi_xri_start + |
| 5774 | phba->sli4_hba.scsi_xri_max; |
| 5775 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5776 | |
| 5777 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5778 | ids[j] = rsrc_id; |
| 5779 | rsrc_id++; |
| 5780 | j++; |
| 5781 | } |
| 5782 | /* Entire word processed. Get next word.*/ |
| 5783 | if ((i % 2) == 1) |
| 5784 | k++; |
| 5785 | } |
| 5786 | err_exit: |
| 5787 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5788 | return rc; |
| 5789 | } |
| 5790 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5791 | |
| 5792 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5793 | /** |
| 5794 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5795 | * @phba: Pointer to HBA context object. |
| 5796 | * @type: the extent's type. |
| 5797 | * |
| 5798 | * This function deallocates all extents of a particular resource type. |
| 5799 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5800 | * is the caller's responsibility to release all kernel memory resources. |
| 5801 | **/ |
| 5802 | static int |
| 5803 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5804 | { |
| 5805 | int rc; |
| 5806 | uint32_t length, mbox_tmo = 0; |
| 5807 | LPFC_MBOXQ_t *mbox; |
| 5808 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5809 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5810 | |
| 5811 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5812 | if (!mbox) |
| 5813 | return -ENOMEM; |
| 5814 | |
| 5815 | /* |
| 5816 | * This function sends an embedded mailbox because it only sends the |
| 5817 | * the resource type. All extents of this type are released by the |
| 5818 | * port. |
| 5819 | */ |
| 5820 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5821 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5822 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5823 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5824 | length, LPFC_SLI4_MBX_EMBED); |
| 5825 | |
| 5826 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5827 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5828 | LPFC_SLI4_MBX_EMBED); |
| 5829 | if (unlikely(rc)) { |
| 5830 | rc = -EIO; |
| 5831 | goto out_free_mbox; |
| 5832 | } |
| 5833 | if (!phba->sli4_hba.intr_enable) |
| 5834 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5835 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5836 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5837 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5838 | } |
| 5839 | if (unlikely(rc)) { |
| 5840 | rc = -EIO; |
| 5841 | goto out_free_mbox; |
| 5842 | } |
| 5843 | |
| 5844 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5845 | if (bf_get(lpfc_mbox_hdr_status, |
| 5846 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5847 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5848 | "2919 Failed to release resource extents " |
| 5849 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5850 | "Resource memory not released.\n", |
| 5851 | type, |
| 5852 | bf_get(lpfc_mbox_hdr_status, |
| 5853 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5854 | bf_get(lpfc_mbox_hdr_add_status, |
| 5855 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5856 | rc = -EIO; |
| 5857 | goto out_free_mbox; |
| 5858 | } |
| 5859 | |
| 5860 | /* Release kernel memory resources for the specific type. */ |
| 5861 | switch (type) { |
| 5862 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5863 | kfree(phba->vpi_bmask); |
| 5864 | kfree(phba->vpi_ids); |
| 5865 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5866 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5867 | &phba->lpfc_vpi_blk_list, list) { |
| 5868 | list_del_init(&rsrc_blk->list); |
| 5869 | kfree(rsrc_blk); |
| 5870 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5871 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5872 | break; |
| 5873 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5874 | kfree(phba->sli4_hba.xri_bmask); |
| 5875 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5876 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5877 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5878 | list_del_init(&rsrc_blk->list); |
| 5879 | kfree(rsrc_blk); |
| 5880 | } |
| 5881 | break; |
| 5882 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5883 | kfree(phba->sli4_hba.vfi_bmask); |
| 5884 | kfree(phba->sli4_hba.vfi_ids); |
| 5885 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5886 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5887 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5888 | list_del_init(&rsrc_blk->list); |
| 5889 | kfree(rsrc_blk); |
| 5890 | } |
| 5891 | break; |
| 5892 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5893 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5894 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5895 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5896 | list_del_init(&rsrc_blk->list); |
| 5897 | kfree(rsrc_blk); |
| 5898 | } |
| 5899 | break; |
| 5900 | default: |
| 5901 | break; |
| 5902 | } |
| 5903 | |
| 5904 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5905 | |
| 5906 | out_free_mbox: |
| 5907 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5908 | return rc; |
| 5909 | } |
| 5910 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5911 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5912 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 5913 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5914 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5915 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5916 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5917 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 5918 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 5919 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5920 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 5921 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5922 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5923 | switch (feature) { |
| 5924 | case LPFC_SET_UE_RECOVERY: |
| 5925 | bf_set(lpfc_mbx_set_feature_UER, |
| 5926 | &mbox->u.mqe.un.set_feature, 1); |
| 5927 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 5928 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 5929 | break; |
| 5930 | case LPFC_SET_MDS_DIAGS: |
| 5931 | bf_set(lpfc_mbx_set_feature_mds, |
| 5932 | &mbox->u.mqe.un.set_feature, 1); |
| 5933 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 5934 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5935 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 5936 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 5937 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5938 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5939 | |
| 5940 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5941 | } |
| 5942 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5943 | /** |
| 5944 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5945 | * @phba: Pointer to HBA context object. |
| 5946 | * |
| 5947 | * This function allocates all SLI4 resource identifiers. |
| 5948 | **/ |
| 5949 | int |
| 5950 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5951 | { |
| 5952 | int i, rc, error = 0; |
| 5953 | uint16_t count, base; |
| 5954 | unsigned long longs; |
| 5955 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5956 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5957 | 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] | 5958 | if (phba->sli4_hba.extents_in_use) { |
| 5959 | /* |
| 5960 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5961 | * resource extent count must be read and allocated before |
| 5962 | * provisioning the resource id arrays. |
| 5963 | */ |
| 5964 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5965 | LPFC_IDX_RSRC_RDY) { |
| 5966 | /* |
| 5967 | * Extent-based resources are set - the driver could |
| 5968 | * be in a port reset. Figure out if any corrective |
| 5969 | * actions need to be taken. |
| 5970 | */ |
| 5971 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5972 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5973 | if (rc != 0) |
| 5974 | error++; |
| 5975 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5976 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5977 | if (rc != 0) |
| 5978 | error++; |
| 5979 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5980 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5981 | if (rc != 0) |
| 5982 | error++; |
| 5983 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5984 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5985 | if (rc != 0) |
| 5986 | error++; |
| 5987 | |
| 5988 | /* |
| 5989 | * It's possible that the number of resources |
| 5990 | * provided to this port instance changed between |
| 5991 | * resets. Detect this condition and reallocate |
| 5992 | * resources. Otherwise, there is no action. |
| 5993 | */ |
| 5994 | if (error) { |
| 5995 | lpfc_printf_log(phba, KERN_INFO, |
| 5996 | LOG_MBOX | LOG_INIT, |
| 5997 | "2931 Detected extent resource " |
| 5998 | "change. Reallocating all " |
| 5999 | "extents.\n"); |
| 6000 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6001 | LPFC_RSC_TYPE_FCOE_VFI); |
| 6002 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6003 | LPFC_RSC_TYPE_FCOE_VPI); |
| 6004 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6005 | LPFC_RSC_TYPE_FCOE_XRI); |
| 6006 | rc = lpfc_sli4_dealloc_extent(phba, |
| 6007 | LPFC_RSC_TYPE_FCOE_RPI); |
| 6008 | } else |
| 6009 | return 0; |
| 6010 | } |
| 6011 | |
| 6012 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6013 | if (unlikely(rc)) |
| 6014 | goto err_exit; |
| 6015 | |
| 6016 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6017 | if (unlikely(rc)) |
| 6018 | goto err_exit; |
| 6019 | |
| 6020 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6021 | if (unlikely(rc)) |
| 6022 | goto err_exit; |
| 6023 | |
| 6024 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6025 | if (unlikely(rc)) |
| 6026 | goto err_exit; |
| 6027 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6028 | LPFC_IDX_RSRC_RDY); |
| 6029 | return rc; |
| 6030 | } else { |
| 6031 | /* |
| 6032 | * The port does not support resource extents. The XRI, VPI, |
| 6033 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6034 | * Just allocate the bitmasks and provision the resource id |
| 6035 | * arrays. If a port reset is active, the resources don't |
| 6036 | * need any action - just exit. |
| 6037 | */ |
| 6038 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6039 | LPFC_IDX_RSRC_RDY) { |
| 6040 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6041 | lpfc_sli4_remove_rpis(phba); |
| 6042 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6043 | /* RPIs. */ |
| 6044 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6045 | if (count <= 0) { |
| 6046 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6047 | "3279 Invalid provisioning of " |
| 6048 | "rpi:%d\n", count); |
| 6049 | rc = -EINVAL; |
| 6050 | goto err_exit; |
| 6051 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6052 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6053 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6054 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 6055 | sizeof(unsigned long), |
| 6056 | GFP_KERNEL); |
| 6057 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6058 | rc = -ENOMEM; |
| 6059 | goto err_exit; |
| 6060 | } |
| 6061 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 6062 | sizeof(uint16_t), |
| 6063 | GFP_KERNEL); |
| 6064 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6065 | rc = -ENOMEM; |
| 6066 | goto free_rpi_bmask; |
| 6067 | } |
| 6068 | |
| 6069 | for (i = 0; i < count; i++) |
| 6070 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6071 | |
| 6072 | /* VPIs. */ |
| 6073 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6074 | if (count <= 0) { |
| 6075 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6076 | "3280 Invalid provisioning of " |
| 6077 | "vpi:%d\n", count); |
| 6078 | rc = -EINVAL; |
| 6079 | goto free_rpi_ids; |
| 6080 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6081 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6082 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6083 | phba->vpi_bmask = kzalloc(longs * |
| 6084 | sizeof(unsigned long), |
| 6085 | GFP_KERNEL); |
| 6086 | if (unlikely(!phba->vpi_bmask)) { |
| 6087 | rc = -ENOMEM; |
| 6088 | goto free_rpi_ids; |
| 6089 | } |
| 6090 | phba->vpi_ids = kzalloc(count * |
| 6091 | sizeof(uint16_t), |
| 6092 | GFP_KERNEL); |
| 6093 | if (unlikely(!phba->vpi_ids)) { |
| 6094 | rc = -ENOMEM; |
| 6095 | goto free_vpi_bmask; |
| 6096 | } |
| 6097 | |
| 6098 | for (i = 0; i < count; i++) |
| 6099 | phba->vpi_ids[i] = base + i; |
| 6100 | |
| 6101 | /* XRIs. */ |
| 6102 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6103 | if (count <= 0) { |
| 6104 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6105 | "3281 Invalid provisioning of " |
| 6106 | "xri:%d\n", count); |
| 6107 | rc = -EINVAL; |
| 6108 | goto free_vpi_ids; |
| 6109 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6110 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 6111 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6112 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 6113 | sizeof(unsigned long), |
| 6114 | GFP_KERNEL); |
| 6115 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6116 | rc = -ENOMEM; |
| 6117 | goto free_vpi_ids; |
| 6118 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6119 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6120 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 6121 | sizeof(uint16_t), |
| 6122 | GFP_KERNEL); |
| 6123 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6124 | rc = -ENOMEM; |
| 6125 | goto free_xri_bmask; |
| 6126 | } |
| 6127 | |
| 6128 | for (i = 0; i < count; i++) |
| 6129 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6130 | |
| 6131 | /* VFIs. */ |
| 6132 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6133 | if (count <= 0) { |
| 6134 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6135 | "3282 Invalid provisioning of " |
| 6136 | "vfi:%d\n", count); |
| 6137 | rc = -EINVAL; |
| 6138 | goto free_xri_ids; |
| 6139 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6140 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6141 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6142 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 6143 | sizeof(unsigned long), |
| 6144 | GFP_KERNEL); |
| 6145 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6146 | rc = -ENOMEM; |
| 6147 | goto free_xri_ids; |
| 6148 | } |
| 6149 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 6150 | sizeof(uint16_t), |
| 6151 | GFP_KERNEL); |
| 6152 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6153 | rc = -ENOMEM; |
| 6154 | goto free_vfi_bmask; |
| 6155 | } |
| 6156 | |
| 6157 | for (i = 0; i < count; i++) |
| 6158 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6159 | |
| 6160 | /* |
| 6161 | * Mark all resources ready. An HBA reset doesn't need |
| 6162 | * to reset the initialization. |
| 6163 | */ |
| 6164 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6165 | LPFC_IDX_RSRC_RDY); |
| 6166 | return 0; |
| 6167 | } |
| 6168 | |
| 6169 | free_vfi_bmask: |
| 6170 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6171 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6172 | free_xri_ids: |
| 6173 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6174 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6175 | free_xri_bmask: |
| 6176 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6177 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6178 | free_vpi_ids: |
| 6179 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6180 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6181 | free_vpi_bmask: |
| 6182 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6183 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6184 | free_rpi_ids: |
| 6185 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6186 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6187 | free_rpi_bmask: |
| 6188 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6189 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6190 | err_exit: |
| 6191 | return rc; |
| 6192 | } |
| 6193 | |
| 6194 | /** |
| 6195 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6196 | * @phba: Pointer to HBA context object. |
| 6197 | * |
| 6198 | * This function allocates the number of elements for the specified |
| 6199 | * resource type. |
| 6200 | **/ |
| 6201 | int |
| 6202 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 6203 | { |
| 6204 | if (phba->sli4_hba.extents_in_use) { |
| 6205 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6206 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6207 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6208 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6209 | } else { |
| 6210 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6211 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6212 | kfree(phba->vpi_ids); |
| 6213 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6214 | kfree(phba->sli4_hba.xri_bmask); |
| 6215 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6216 | kfree(phba->sli4_hba.vfi_bmask); |
| 6217 | kfree(phba->sli4_hba.vfi_ids); |
| 6218 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6219 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6220 | } |
| 6221 | |
| 6222 | return 0; |
| 6223 | } |
| 6224 | |
| 6225 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6226 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6227 | * @phba: Pointer to HBA context object. |
| 6228 | * @type: The resource extent type. |
| 6229 | * @extnt_count: buffer to hold port extent count response |
| 6230 | * @extnt_size: buffer to hold port extent size response. |
| 6231 | * |
| 6232 | * This function calls the port to read the host allocated extents |
| 6233 | * for a particular type. |
| 6234 | **/ |
| 6235 | int |
| 6236 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6237 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6238 | { |
| 6239 | bool emb; |
| 6240 | int rc = 0; |
| 6241 | uint16_t curr_blks = 0; |
| 6242 | uint32_t req_len, emb_len; |
| 6243 | uint32_t alloc_len, mbox_tmo; |
| 6244 | struct list_head *blk_list_head; |
| 6245 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6246 | LPFC_MBOXQ_t *mbox; |
| 6247 | void *virtaddr = NULL; |
| 6248 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6249 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6250 | union lpfc_sli4_cfg_shdr *shdr; |
| 6251 | |
| 6252 | switch (type) { |
| 6253 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6254 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6255 | break; |
| 6256 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6257 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6258 | break; |
| 6259 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6260 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6261 | break; |
| 6262 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6263 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6264 | break; |
| 6265 | default: |
| 6266 | return -EIO; |
| 6267 | } |
| 6268 | |
| 6269 | /* Count the number of extents currently allocatd for this type. */ |
| 6270 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6271 | if (curr_blks == 0) { |
| 6272 | /* |
| 6273 | * The GET_ALLOCATED mailbox does not return the size, |
| 6274 | * just the count. The size should be just the size |
| 6275 | * stored in the current allocated block and all sizes |
| 6276 | * for an extent type are the same so set the return |
| 6277 | * value now. |
| 6278 | */ |
| 6279 | *extnt_size = rsrc_blk->rsrc_size; |
| 6280 | } |
| 6281 | curr_blks++; |
| 6282 | } |
| 6283 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6284 | /* |
| 6285 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6286 | * accounts for extents-specific word. |
| 6287 | */ |
| 6288 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6289 | sizeof(uint32_t); |
| 6290 | |
| 6291 | /* |
| 6292 | * Presume the allocation and response will fit into an embedded |
| 6293 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6294 | */ |
| 6295 | emb = LPFC_SLI4_MBX_EMBED; |
| 6296 | req_len = emb_len; |
| 6297 | if (req_len > emb_len) { |
| 6298 | req_len = curr_blks * sizeof(uint16_t) + |
| 6299 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6300 | sizeof(uint32_t); |
| 6301 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6302 | } |
| 6303 | |
| 6304 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6305 | if (!mbox) |
| 6306 | return -ENOMEM; |
| 6307 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6308 | |
| 6309 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6310 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6311 | req_len, emb); |
| 6312 | if (alloc_len < req_len) { |
| 6313 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6314 | "2983 Allocated DMA memory size (x%x) is " |
| 6315 | "less than the requested DMA memory " |
| 6316 | "size (x%x)\n", alloc_len, req_len); |
| 6317 | rc = -ENOMEM; |
| 6318 | goto err_exit; |
| 6319 | } |
| 6320 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6321 | if (unlikely(rc)) { |
| 6322 | rc = -EIO; |
| 6323 | goto err_exit; |
| 6324 | } |
| 6325 | |
| 6326 | if (!phba->sli4_hba.intr_enable) |
| 6327 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6328 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6329 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6330 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6331 | } |
| 6332 | |
| 6333 | if (unlikely(rc)) { |
| 6334 | rc = -EIO; |
| 6335 | goto err_exit; |
| 6336 | } |
| 6337 | |
| 6338 | /* |
| 6339 | * Figure out where the response is located. Then get local pointers |
| 6340 | * to the response data. The port does not guarantee to respond to |
| 6341 | * all extents counts request so update the local variable with the |
| 6342 | * allocated count from the port. |
| 6343 | */ |
| 6344 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6345 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6346 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6347 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6348 | } else { |
| 6349 | virtaddr = mbox->sge_array->addr[0]; |
| 6350 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6351 | shdr = &n_rsrc->cfg_shdr; |
| 6352 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6353 | } |
| 6354 | |
| 6355 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6356 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6357 | "2984 Failed to read allocated resources " |
| 6358 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6359 | type, |
| 6360 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6361 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6362 | rc = -EIO; |
| 6363 | goto err_exit; |
| 6364 | } |
| 6365 | err_exit: |
| 6366 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6367 | return rc; |
| 6368 | } |
| 6369 | |
| 6370 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 6371 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6372 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6373 | * @pring: Pointer to driver SLI ring object. |
| 6374 | * @sgl_list: linked link of sgl buffers to post |
| 6375 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6376 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6377 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6378 | * repost them to the port by using SGL block post. This is needed after a |
| 6379 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6380 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 6381 | * 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] | 6382 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6383 | * mailbox command for posting. |
| 6384 | * |
| 6385 | * Returns: 0 = success, non-zero failure. |
| 6386 | **/ |
| 6387 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6388 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 6389 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6390 | { |
| 6391 | struct lpfc_sglq *sglq_entry = NULL; |
| 6392 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6393 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6394 | int status, total_cnt; |
| 6395 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6396 | int last_xritag = NO_XRI; |
| 6397 | LIST_HEAD(prep_sgl_list); |
| 6398 | LIST_HEAD(blck_sgl_list); |
| 6399 | LIST_HEAD(allc_sgl_list); |
| 6400 | LIST_HEAD(post_sgl_list); |
| 6401 | LIST_HEAD(free_sgl_list); |
| 6402 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6403 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6404 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6405 | list_splice_init(sgl_list, &allc_sgl_list); |
| 6406 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6407 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6408 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6409 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6410 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6411 | &allc_sgl_list, list) { |
| 6412 | list_del_init(&sglq_entry->list); |
| 6413 | block_cnt++; |
| 6414 | if ((last_xritag != NO_XRI) && |
| 6415 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6416 | /* a hole in xri block, form a sgl posting block */ |
| 6417 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6418 | post_cnt = block_cnt - 1; |
| 6419 | /* prepare list for next posting block */ |
| 6420 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6421 | block_cnt = 1; |
| 6422 | } else { |
| 6423 | /* prepare list for next posting block */ |
| 6424 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6425 | /* enough sgls for non-embed sgl mbox command */ |
| 6426 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6427 | list_splice_init(&prep_sgl_list, |
| 6428 | &blck_sgl_list); |
| 6429 | post_cnt = block_cnt; |
| 6430 | block_cnt = 0; |
| 6431 | } |
| 6432 | } |
| 6433 | num_posted++; |
| 6434 | |
| 6435 | /* keep track of last sgl's xritag */ |
| 6436 | last_xritag = sglq_entry->sli4_xritag; |
| 6437 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6438 | /* end of repost sgl list condition for buffers */ |
| 6439 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6440 | if (post_cnt == 0) { |
| 6441 | list_splice_init(&prep_sgl_list, |
| 6442 | &blck_sgl_list); |
| 6443 | post_cnt = block_cnt; |
| 6444 | } else if (block_cnt == 1) { |
| 6445 | status = lpfc_sli4_post_sgl(phba, |
| 6446 | sglq_entry->phys, 0, |
| 6447 | sglq_entry->sli4_xritag); |
| 6448 | if (!status) { |
| 6449 | /* successful, put sgl to posted list */ |
| 6450 | list_add_tail(&sglq_entry->list, |
| 6451 | &post_sgl_list); |
| 6452 | } else { |
| 6453 | /* Failure, put sgl to free list */ |
| 6454 | lpfc_printf_log(phba, KERN_WARNING, |
| 6455 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6456 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6457 | "sgl, xritag:x%x\n", |
| 6458 | sglq_entry->sli4_xritag); |
| 6459 | list_add_tail(&sglq_entry->list, |
| 6460 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6461 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6462 | } |
| 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | /* continue until a nembed page worth of sgls */ |
| 6467 | if (post_cnt == 0) |
| 6468 | continue; |
| 6469 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6470 | /* post the buffer list sgls as a block */ |
| 6471 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 6472 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6473 | |
| 6474 | if (!status) { |
| 6475 | /* success, put sgl list to posted sgl list */ |
| 6476 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6477 | } else { |
| 6478 | /* Failure, put sgl list to free sgl list */ |
| 6479 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6480 | struct lpfc_sglq, |
| 6481 | list); |
| 6482 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6483 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6484 | "xritag:x%x-x%x\n", |
| 6485 | sglq_entry_first->sli4_xritag, |
| 6486 | (sglq_entry_first->sli4_xritag + |
| 6487 | post_cnt - 1)); |
| 6488 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6489 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | /* don't reset xirtag due to hole in xri block */ |
| 6493 | if (block_cnt == 0) |
| 6494 | last_xritag = NO_XRI; |
| 6495 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6496 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6497 | post_cnt = 0; |
| 6498 | } |
| 6499 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6500 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6501 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6502 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6503 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6504 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6505 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6506 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6507 | list_splice_init(&post_sgl_list, sgl_list); |
| 6508 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6509 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6510 | } else { |
| 6511 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6512 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6513 | return -EIO; |
| 6514 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6515 | |
| 6516 | /* return the number of XRIs actually posted */ |
| 6517 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6518 | } |
| 6519 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6520 | void |
| 6521 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 6522 | { |
| 6523 | uint32_t len; |
| 6524 | |
| 6525 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 6526 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6527 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6528 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 6529 | LPFC_SLI4_MBX_EMBED); |
| 6530 | |
| 6531 | 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] | 6532 | mbox->u.mqe.un.set_host_data.param_len = |
| 6533 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6534 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 6535 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 6536 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 6537 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 6538 | } |
| 6539 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6540 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6541 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6542 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6543 | { |
| 6544 | int rc, i; |
| 6545 | struct lpfc_rqe hrqe; |
| 6546 | struct lpfc_rqe drqe; |
| 6547 | struct lpfc_rqb *rqbp; |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 6548 | unsigned long flags; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6549 | struct rqb_dmabuf *rqb_buffer; |
| 6550 | LIST_HEAD(rqb_buf_list); |
| 6551 | |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 6552 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6553 | rqbp = hrq->rqbp; |
| 6554 | for (i = 0; i < count; i++) { |
| 6555 | /* IF RQ is already full, don't bother */ |
| 6556 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) |
| 6557 | break; |
| 6558 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 6559 | if (!rqb_buffer) |
| 6560 | break; |
| 6561 | rqb_buffer->hrq = hrq; |
| 6562 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6563 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6564 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 6565 | } |
| 6566 | while (!list_empty(&rqb_buf_list)) { |
| 6567 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 6568 | hbuf.list); |
| 6569 | |
| 6570 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 6571 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 6572 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 6573 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 6574 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 6575 | if (rc < 0) { |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 6576 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6577 | "6421 Cannot post to HRQ %d: %x %x %x " |
| 6578 | "DRQ %x %x\n", |
| 6579 | hrq->queue_id, |
| 6580 | hrq->host_index, |
| 6581 | hrq->hba_index, |
| 6582 | hrq->entry_count, |
| 6583 | drq->host_index, |
| 6584 | drq->hba_index); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6585 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 6586 | } else { |
| 6587 | list_add_tail(&rqb_buffer->hbuf.list, |
| 6588 | &rqbp->rqb_buffer_list); |
| 6589 | rqbp->buffer_count++; |
| 6590 | } |
| 6591 | } |
James Smart | 411de51 | 2018-01-30 15:58:52 -0800 | [diff] [blame] | 6592 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6593 | return 1; |
| 6594 | } |
| 6595 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6596 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 6597 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6598 | * @phba: Pointer to HBA context object. |
| 6599 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 6600 | * This function is the main SLI4 device initialization PCI function. This |
| 6601 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6602 | * HBA error attention handler code. Caller is not required to hold any |
| 6603 | * locks. |
| 6604 | **/ |
| 6605 | int |
| 6606 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6607 | { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6608 | int rc, i, cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6609 | LPFC_MBOXQ_t *mboxq; |
| 6610 | struct lpfc_mqe *mqe; |
| 6611 | uint8_t *vpd; |
| 6612 | uint32_t vpd_size; |
| 6613 | uint32_t ftr_rsp = 0; |
| 6614 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6615 | struct lpfc_vport *vport = phba->pport; |
| 6616 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6617 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6618 | |
| 6619 | /* Perform a PCI function reset to start from clean */ |
| 6620 | rc = lpfc_pci_function_reset(phba); |
| 6621 | if (unlikely(rc)) |
| 6622 | return -ENODEV; |
| 6623 | |
| 6624 | /* Check the HBA Host Status Register for readyness */ |
| 6625 | rc = lpfc_sli4_post_status_check(phba); |
| 6626 | if (unlikely(rc)) |
| 6627 | return -ENODEV; |
| 6628 | else { |
| 6629 | spin_lock_irq(&phba->hbalock); |
| 6630 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6631 | spin_unlock_irq(&phba->hbalock); |
| 6632 | } |
| 6633 | |
| 6634 | /* |
| 6635 | * Allocate a single mailbox container for initializing the |
| 6636 | * port. |
| 6637 | */ |
| 6638 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6639 | if (!mboxq) |
| 6640 | return -ENOMEM; |
| 6641 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6642 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6643 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6644 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6645 | if (!vpd) { |
| 6646 | rc = -ENOMEM; |
| 6647 | goto out_free_mbox; |
| 6648 | } |
| 6649 | |
| 6650 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6651 | if (unlikely(rc)) { |
| 6652 | kfree(vpd); |
| 6653 | goto out_free_mbox; |
| 6654 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6655 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6656 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6657 | 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] | 6658 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6659 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6660 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 6661 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6662 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6663 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6664 | |
| 6665 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6666 | LPFC_DCBX_CEE_MODE) |
| 6667 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6668 | else |
| 6669 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6670 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6671 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6672 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6673 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6674 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6675 | "0376 READ_REV Error. SLI Level %d " |
| 6676 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6677 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6678 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6679 | kfree(vpd); |
| 6680 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6681 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6682 | |
| 6683 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6684 | * Continue initialization with default values even if driver failed |
| 6685 | * to read FCoE param config regions, only read parameters if the |
| 6686 | * board is FCoE |
| 6687 | */ |
| 6688 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6689 | lpfc_sli4_read_fcoe_params(phba)) |
| 6690 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6691 | "2570 Failed to read FCoE parameters\n"); |
| 6692 | |
| 6693 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6694 | * Retrieve sli4 device physical port name, failure of doing it |
| 6695 | * is considered as non-fatal. |
| 6696 | */ |
| 6697 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6698 | if (!rc) |
| 6699 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6700 | "3080 Successful retrieving SLI4 device " |
| 6701 | "physical port name: %s.\n", phba->Port); |
| 6702 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6703 | /* |
| 6704 | * Evaluate the read rev and vpd data. Populate the driver |
| 6705 | * state with the results. If this routine fails, the failure |
| 6706 | * is not fatal as the driver will use generic values. |
| 6707 | */ |
| 6708 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6709 | if (unlikely(!rc)) { |
| 6710 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6711 | "0377 Error %d parsing vpd. " |
| 6712 | "Using defaults.\n", rc); |
| 6713 | rc = 0; |
| 6714 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6715 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6716 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6717 | /* Save information as VPD data */ |
| 6718 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6719 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6720 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6721 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6722 | &mqe->un.read_rev); |
| 6723 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6724 | &mqe->un.read_rev); |
| 6725 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6726 | &mqe->un.read_rev); |
| 6727 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6728 | &mqe->un.read_rev); |
| 6729 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6730 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6731 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6732 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6733 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6734 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6735 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6736 | "(%d):0380 READ_REV Status x%x " |
| 6737 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6738 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6739 | bf_get(lpfc_mqe_status, mqe), |
| 6740 | phba->vpd.rev.opFwName, |
| 6741 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6742 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6743 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6744 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 6745 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 6746 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 6747 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6748 | "3362 LUN queue depth changed from %d to %d\n", |
| 6749 | phba->pport->cfg_lun_queue_depth, rc); |
| 6750 | phba->pport->cfg_lun_queue_depth = rc; |
| 6751 | } |
| 6752 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6753 | 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] | 6754 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6755 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 6756 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6757 | if (rc == MBX_SUCCESS) { |
| 6758 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 6759 | /* Set 1Sec interval to detect UE */ |
| 6760 | phba->eratt_poll_interval = 1; |
| 6761 | phba->sli4_hba.ue_to_sr = bf_get( |
| 6762 | lpfc_mbx_set_feature_UESR, |
| 6763 | &mboxq->u.mqe.un.set_feature); |
| 6764 | phba->sli4_hba.ue_to_rp = bf_get( |
| 6765 | lpfc_mbx_set_feature_UERP, |
| 6766 | &mboxq->u.mqe.un.set_feature); |
| 6767 | } |
| 6768 | } |
| 6769 | |
| 6770 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 6771 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 6772 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 6773 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6774 | if (rc != MBX_SUCCESS) |
| 6775 | phba->mds_diags_support = 0; |
| 6776 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6777 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6778 | /* |
| 6779 | * Discover the port's supported feature set and match it against the |
| 6780 | * hosts requests. |
| 6781 | */ |
| 6782 | lpfc_request_features(phba, mboxq); |
| 6783 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6784 | if (unlikely(rc)) { |
| 6785 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6786 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6787 | } |
| 6788 | |
| 6789 | /* |
| 6790 | * The port must support FCP initiator mode as this is the |
| 6791 | * only mode running in the host. |
| 6792 | */ |
| 6793 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6794 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6795 | "0378 No support for fcpi mode.\n"); |
| 6796 | ftr_rsp++; |
| 6797 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6798 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6799 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6800 | else |
| 6801 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6802 | /* |
| 6803 | * If the port cannot support the host's requested features |
| 6804 | * then turn off the global config parameters to disable the |
| 6805 | * feature in the driver. This is not a fatal error. |
| 6806 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6807 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6808 | if (phba->cfg_enable_bg) { |
| 6809 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6810 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6811 | else |
| 6812 | ftr_rsp++; |
| 6813 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6814 | |
| 6815 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6816 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6817 | ftr_rsp++; |
| 6818 | |
| 6819 | if (ftr_rsp) { |
| 6820 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6821 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6822 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6823 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6824 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6825 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6826 | phba->cfg_enable_bg = 0; |
| 6827 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6828 | phba->cfg_enable_npiv = 0; |
| 6829 | } |
| 6830 | |
| 6831 | /* These SLI3 features are assumed in SLI4 */ |
| 6832 | spin_lock_irq(&phba->hbalock); |
| 6833 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6834 | spin_unlock_irq(&phba->hbalock); |
| 6835 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6836 | /* |
| 6837 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6838 | * calls depends on these resources to complete port setup. |
| 6839 | */ |
| 6840 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6841 | if (rc) { |
| 6842 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6843 | "2920 Failed to alloc Resource IDs " |
| 6844 | "rc = x%x\n", rc); |
| 6845 | goto out_free_mbox; |
| 6846 | } |
| 6847 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6848 | lpfc_set_host_data(phba, mboxq); |
| 6849 | |
| 6850 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6851 | if (rc) { |
| 6852 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6853 | "2134 Failed to set host os driver version %x", |
| 6854 | rc); |
| 6855 | } |
| 6856 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6857 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6858 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6859 | if (rc) { |
| 6860 | phba->link_state = LPFC_HBA_ERROR; |
| 6861 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6862 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6863 | } |
| 6864 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6865 | mboxq->vport = vport; |
| 6866 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6867 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6868 | if (rc == MBX_SUCCESS) { |
| 6869 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6870 | rc = 0; |
| 6871 | } |
| 6872 | |
| 6873 | /* |
| 6874 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6875 | * it to the mbuf pool. |
| 6876 | */ |
| 6877 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6878 | kfree(mp); |
| 6879 | mboxq->context1 = NULL; |
| 6880 | if (unlikely(rc)) { |
| 6881 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6882 | "0382 READ_SPARAM command failed " |
| 6883 | "status %d, mbxStatus x%x\n", |
| 6884 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6885 | phba->link_state = LPFC_HBA_ERROR; |
| 6886 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6887 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6888 | } |
| 6889 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6890 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6891 | |
| 6892 | /* Update the fc_host data structures with new wwn. */ |
| 6893 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6894 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6895 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6896 | /* Create all the SLI4 queues */ |
| 6897 | rc = lpfc_sli4_queue_create(phba); |
| 6898 | if (rc) { |
| 6899 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6900 | "3089 Failed to allocate queues\n"); |
| 6901 | rc = -ENODEV; |
| 6902 | goto out_free_mbox; |
| 6903 | } |
| 6904 | /* Set up all the queues to the device */ |
| 6905 | rc = lpfc_sli4_queue_setup(phba); |
| 6906 | if (unlikely(rc)) { |
| 6907 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6908 | "0381 Error %d during queue setup.\n ", rc); |
| 6909 | goto out_stop_timers; |
| 6910 | } |
| 6911 | /* Initialize the driver internal SLI layer lists. */ |
| 6912 | lpfc_sli4_setup(phba); |
| 6913 | lpfc_sli4_queue_init(phba); |
| 6914 | |
| 6915 | /* update host els xri-sgl sizes and mappings */ |
| 6916 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6917 | if (unlikely(rc)) { |
| 6918 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6919 | "1400 Failed to update xri-sgl size and " |
| 6920 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6921 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6922 | } |
| 6923 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6924 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6925 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 6926 | phba->sli4_hba.els_xri_cnt); |
| 6927 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6928 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6929 | "0582 Error %d during els sgl post " |
| 6930 | "operation\n", rc); |
| 6931 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6932 | goto out_destroy_queue; |
| 6933 | } |
| 6934 | phba->sli4_hba.els_xri_cnt = rc; |
| 6935 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6936 | if (phba->nvmet_support) { |
| 6937 | /* update host nvmet xri-sgl sizes and mappings */ |
| 6938 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 6939 | if (unlikely(rc)) { |
| 6940 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6941 | "6308 Failed to update nvmet-sgl size " |
| 6942 | "and mapping: %d\n", rc); |
| 6943 | goto out_destroy_queue; |
| 6944 | } |
| 6945 | |
| 6946 | /* register the nvmet sgl pool to the port */ |
| 6947 | rc = lpfc_sli4_repost_sgl_list( |
| 6948 | phba, |
| 6949 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 6950 | phba->sli4_hba.nvmet_xri_cnt); |
| 6951 | if (unlikely(rc < 0)) { |
| 6952 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6953 | "3117 Error %d during nvmet " |
| 6954 | "sgl post\n", rc); |
| 6955 | rc = -ENODEV; |
| 6956 | goto out_destroy_queue; |
| 6957 | } |
| 6958 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6959 | |
| 6960 | cnt = phba->cfg_iocb_cnt * 1024; |
| 6961 | /* We need 1 iocbq for every SGL, for IO processing */ |
| 6962 | cnt += phba->sli4_hba.nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6963 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6964 | /* update host scsi xri-sgl sizes and mappings */ |
| 6965 | rc = lpfc_sli4_scsi_sgl_update(phba); |
| 6966 | if (unlikely(rc)) { |
| 6967 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6968 | "6309 Failed to update scsi-sgl size " |
| 6969 | "and mapping: %d\n", rc); |
| 6970 | goto out_destroy_queue; |
| 6971 | } |
| 6972 | |
| 6973 | /* update host nvme xri-sgl sizes and mappings */ |
| 6974 | rc = lpfc_sli4_nvme_sgl_update(phba); |
| 6975 | if (unlikely(rc)) { |
| 6976 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6977 | "6082 Failed to update nvme-sgl size " |
| 6978 | "and mapping: %d\n", rc); |
| 6979 | goto out_destroy_queue; |
| 6980 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6981 | |
| 6982 | cnt = phba->cfg_iocb_cnt * 1024; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6983 | } |
| 6984 | |
| 6985 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6986 | /* Initialize and populate the iocb list per host */ |
| 6987 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6988 | "2821 initialize iocb list %d total %d\n", |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6989 | phba->cfg_iocb_cnt, cnt); |
| 6990 | rc = lpfc_init_iocb_list(phba, cnt); |
| 6991 | if (rc) { |
| 6992 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6993 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6994 | goto out_destroy_queue; |
| 6995 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6996 | } |
| 6997 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6998 | if (phba->nvmet_support) |
| 6999 | lpfc_nvmet_create_targetport(phba); |
| 7000 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7001 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7002 | /* Post initial buffers to all RQs created */ |
| 7003 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 7004 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 7005 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 7006 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 7007 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 7008 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7009 | rqbp->buffer_count = 0; |
| 7010 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7011 | lpfc_post_rq_buffer( |
| 7012 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 7013 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7014 | LPFC_NVMET_RQE_DEF_COUNT, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7015 | } |
| 7016 | } |
| 7017 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7018 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 7019 | /* register the allocated scsi sgl pool to the port */ |
| 7020 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 7021 | if (unlikely(rc)) { |
| 7022 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7023 | "0383 Error %d during scsi sgl post " |
| 7024 | "operation\n", rc); |
| 7025 | /* Some Scsi buffers were moved to abort scsi list */ |
| 7026 | /* A pci function reset will repost them */ |
| 7027 | rc = -ENODEV; |
| 7028 | goto out_destroy_queue; |
| 7029 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7030 | } |
| 7031 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 7032 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 7033 | (phba->nvmet_support == 0)) { |
| 7034 | |
| 7035 | /* register the allocated nvme sgl pool to the port */ |
| 7036 | rc = lpfc_repost_nvme_sgl_list(phba); |
| 7037 | if (unlikely(rc)) { |
| 7038 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7039 | "6116 Error %d during nvme sgl post " |
| 7040 | "operation\n", rc); |
| 7041 | /* Some NVME buffers were moved to abort nvme list */ |
| 7042 | /* A pci function reset will repost them */ |
| 7043 | rc = -ENODEV; |
| 7044 | goto out_destroy_queue; |
| 7045 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7046 | } |
| 7047 | |
| 7048 | /* Post the rpi header region to the device. */ |
| 7049 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7050 | if (unlikely(rc)) { |
| 7051 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7052 | "0393 Error %d during rpi post operation\n", |
| 7053 | rc); |
| 7054 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7055 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7056 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7057 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7058 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7059 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7060 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7061 | /* |
| 7062 | * The FC Port needs to register FCFI (index 0) |
| 7063 | */ |
| 7064 | lpfc_reg_fcfi(phba, mboxq); |
| 7065 | mboxq->vport = phba->pport; |
| 7066 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7067 | if (rc != MBX_SUCCESS) |
| 7068 | goto out_unset_queue; |
| 7069 | rc = 0; |
| 7070 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7071 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7072 | } else { |
| 7073 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7074 | |
| 7075 | /* First register the FCFI */ |
| 7076 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7077 | mboxq->vport = phba->pport; |
| 7078 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7079 | if (rc != MBX_SUCCESS) |
| 7080 | goto out_unset_queue; |
| 7081 | rc = 0; |
| 7082 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7083 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7084 | |
| 7085 | /* Next register the MRQs */ |
| 7086 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7087 | mboxq->vport = phba->pport; |
| 7088 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7089 | if (rc != MBX_SUCCESS) |
| 7090 | goto out_unset_queue; |
| 7091 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7092 | } |
| 7093 | /* Check if the port is configured to be disabled */ |
| 7094 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | /* Arm the CQs and then EQs on device */ |
| 7098 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7099 | |
| 7100 | /* Indicate device interrupt mode */ |
| 7101 | phba->sli4_hba.intr_enable = 1; |
| 7102 | |
| 7103 | /* Allow asynchronous mailbox command to go through */ |
| 7104 | spin_lock_irq(&phba->hbalock); |
| 7105 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7106 | spin_unlock_irq(&phba->hbalock); |
| 7107 | |
| 7108 | /* Post receive buffers to the device */ |
| 7109 | lpfc_sli4_rb_setup(phba); |
| 7110 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7111 | /* Reset HBA FCF states after HBA reset */ |
| 7112 | phba->fcf.fcf_flag = 0; |
| 7113 | phba->fcf.current_rec.flag = 0; |
| 7114 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7115 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7116 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7117 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7118 | |
| 7119 | /* Start heart beat timer */ |
| 7120 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7121 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7122 | phba->hb_outstanding = 0; |
| 7123 | phba->last_completion_time = jiffies; |
| 7124 | |
| 7125 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7126 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7127 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7128 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7129 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7130 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7131 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7132 | if (!rc) { |
| 7133 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7134 | "2829 This device supports " |
| 7135 | "Advanced Error Reporting (AER)\n"); |
| 7136 | spin_lock_irq(&phba->hbalock); |
| 7137 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7138 | spin_unlock_irq(&phba->hbalock); |
| 7139 | } else { |
| 7140 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7141 | "2830 This device does not support " |
| 7142 | "Advanced Error Reporting (AER)\n"); |
| 7143 | phba->cfg_aer_support = 0; |
| 7144 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7145 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7146 | } |
| 7147 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7148 | /* |
| 7149 | * The port is ready, set the host's link state to LINK_DOWN |
| 7150 | * in preparation for link interrupts. |
| 7151 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7152 | spin_lock_irq(&phba->hbalock); |
| 7153 | phba->link_state = LPFC_LINK_DOWN; |
| 7154 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7155 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7156 | (phba->hba_flag & LINK_DISABLED)) { |
| 7157 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7158 | "3103 Adapter Link is disabled.\n"); |
| 7159 | lpfc_down_link(phba, mboxq); |
| 7160 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7161 | if (rc != MBX_SUCCESS) { |
| 7162 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7163 | "3104 Adapter failed to issue " |
| 7164 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 7165 | goto out_unset_queue; |
| 7166 | } |
| 7167 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7168 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7169 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7170 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7171 | if (rc) |
| 7172 | goto out_unset_queue; |
| 7173 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7174 | } |
| 7175 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7176 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7177 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7178 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7179 | lpfc_sli4_queue_unset(phba); |
| 7180 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7181 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7182 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7183 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7184 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7185 | out_free_mbox: |
| 7186 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7187 | return rc; |
| 7188 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7189 | |
| 7190 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7191 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7192 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7193 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7194 | * This is the callback function for mailbox timer. The mailbox |
| 7195 | * timer is armed when a new mailbox command is issued and the timer |
| 7196 | * is deleted when the mailbox complete. The function is called by |
| 7197 | * the kernel timer code when a mailbox does not complete within |
| 7198 | * expected time. This function wakes up the worker thread to |
| 7199 | * process the mailbox timeout and returns. All the processing is |
| 7200 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 7201 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7202 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7203 | lpfc_mbox_timeout(struct timer_list *t) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7204 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7205 | struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7206 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7207 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7208 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7209 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7210 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7211 | if (!tmo_posted) |
| 7212 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 7213 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 7214 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7215 | if (!tmo_posted) |
| 7216 | lpfc_worker_wake_up(phba); |
| 7217 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7218 | } |
| 7219 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7220 | /** |
| 7221 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 7222 | * are pending |
| 7223 | * @phba: Pointer to HBA context object. |
| 7224 | * |
| 7225 | * This function checks if any mailbox completions are present on the mailbox |
| 7226 | * completion queue. |
| 7227 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 7228 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7229 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 7230 | { |
| 7231 | |
| 7232 | uint32_t idx; |
| 7233 | struct lpfc_queue *mcq; |
| 7234 | struct lpfc_mcqe *mcqe; |
| 7235 | bool pending_completions = false; |
| 7236 | |
| 7237 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7238 | return false; |
| 7239 | |
| 7240 | /* Check for completions on mailbox completion queue */ |
| 7241 | |
| 7242 | mcq = phba->sli4_hba.mbx_cq; |
| 7243 | idx = mcq->hba_index; |
| 7244 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) { |
| 7245 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 7246 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 7247 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 7248 | pending_completions = true; |
| 7249 | break; |
| 7250 | } |
| 7251 | idx = (idx + 1) % mcq->entry_count; |
| 7252 | if (mcq->hba_index == idx) |
| 7253 | break; |
| 7254 | } |
| 7255 | return pending_completions; |
| 7256 | |
| 7257 | } |
| 7258 | |
| 7259 | /** |
| 7260 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 7261 | * that were missed. |
| 7262 | * @phba: Pointer to HBA context object. |
| 7263 | * |
| 7264 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 7265 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 7266 | * checks to see if mbox completions are on the mailbox completion queue |
| 7267 | * and will process all the completions associated with the eq for the |
| 7268 | * mailbox completion queue. |
| 7269 | **/ |
| 7270 | bool |
| 7271 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 7272 | { |
| 7273 | |
| 7274 | uint32_t eqidx; |
| 7275 | struct lpfc_queue *fpeq = NULL; |
| 7276 | struct lpfc_eqe *eqe; |
| 7277 | bool mbox_pending; |
| 7278 | |
| 7279 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7280 | return false; |
| 7281 | |
| 7282 | /* Find the eq associated with the mcq */ |
| 7283 | |
| 7284 | if (phba->sli4_hba.hba_eq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7285 | for (eqidx = 0; eqidx < phba->io_channel_irqs; eqidx++) |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7286 | if (phba->sli4_hba.hba_eq[eqidx]->queue_id == |
| 7287 | phba->sli4_hba.mbx_cq->assoc_qid) { |
| 7288 | fpeq = phba->sli4_hba.hba_eq[eqidx]; |
| 7289 | break; |
| 7290 | } |
| 7291 | if (!fpeq) |
| 7292 | return false; |
| 7293 | |
| 7294 | /* Turn off interrupts from this EQ */ |
| 7295 | |
| 7296 | lpfc_sli4_eq_clr_intr(fpeq); |
| 7297 | |
| 7298 | /* Check to see if a mbox completion is pending */ |
| 7299 | |
| 7300 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 7301 | |
| 7302 | /* |
| 7303 | * If a mbox completion is pending, process all the events on EQ |
| 7304 | * associated with the mbox completion queue (this could include |
| 7305 | * mailbox commands, async events, els commands, receive queue data |
| 7306 | * and fcp commands) |
| 7307 | */ |
| 7308 | |
| 7309 | if (mbox_pending) |
| 7310 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 7311 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); |
| 7312 | fpeq->EQ_processed++; |
| 7313 | } |
| 7314 | |
| 7315 | /* Always clear and re-arm the EQ */ |
| 7316 | |
| 7317 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 7318 | |
| 7319 | return mbox_pending; |
| 7320 | |
| 7321 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7322 | |
| 7323 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7324 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7325 | * @phba: Pointer to HBA context object. |
| 7326 | * |
| 7327 | * This function is called from worker thread when a mailbox command times out. |
| 7328 | * The caller is not required to hold any locks. This function will reset the |
| 7329 | * HBA and recover all the pending commands. |
| 7330 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7331 | void |
| 7332 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 7333 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7334 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7335 | MAILBOX_t *mb = NULL; |
| 7336 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7337 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7338 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7339 | /* If the mailbox completed, process the completion and return */ |
| 7340 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 7341 | return; |
| 7342 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7343 | if (pmbox != NULL) |
| 7344 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7345 | /* Check the pmbox pointer first. There is a race condition |
| 7346 | * between the mbox timeout handler getting executed in the |
| 7347 | * worklist and the mailbox actually completing. When this |
| 7348 | * race condition occurs, the mbox_active will be NULL. |
| 7349 | */ |
| 7350 | spin_lock_irq(&phba->hbalock); |
| 7351 | if (pmbox == NULL) { |
| 7352 | lpfc_printf_log(phba, KERN_WARNING, |
| 7353 | LOG_MBOX | LOG_SLI, |
| 7354 | "0353 Active Mailbox cleared - mailbox timeout " |
| 7355 | "exiting\n"); |
| 7356 | spin_unlock_irq(&phba->hbalock); |
| 7357 | return; |
| 7358 | } |
| 7359 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7360 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7361 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7362 | "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] | 7363 | mb->mbxCommand, |
| 7364 | phba->pport->port_state, |
| 7365 | phba->sli.sli_flag, |
| 7366 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7367 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7368 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7369 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 7370 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7371 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7372 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7373 | spin_lock_irq(&phba->pport->work_port_lock); |
| 7374 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 7375 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 7376 | spin_lock_irq(&phba->hbalock); |
| 7377 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 7378 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7379 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7380 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 7381 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7382 | |
| 7383 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 7384 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7385 | |
| 7386 | /* Reset the HBA device */ |
| 7387 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7388 | } |
| 7389 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7390 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7391 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7392 | * @phba: Pointer to HBA context object. |
| 7393 | * @pmbox: Pointer to mailbox object. |
| 7394 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7395 | * |
| 7396 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7397 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 7398 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7399 | * The mailbox command can be submitted in polling mode, in which case |
| 7400 | * this function will wait in a polling loop for the completion of the |
| 7401 | * mailbox. |
| 7402 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 7403 | * function will submit the command and returns immediately without waiting |
| 7404 | * for the mailbox completion. The no_wait is supported only when HBA |
| 7405 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 7406 | * The SLI interface allows only one mailbox pending at a time. If the |
| 7407 | * mailbox is issued in polling mode and there is already a mailbox |
| 7408 | * pending, then the function will return an error. If the mailbox is issued |
| 7409 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 7410 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 7411 | * The sli layer owns the mailbox object until the completion of mailbox |
| 7412 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 7413 | * return codes the caller owns the mailbox command after the return of |
| 7414 | * the function. |
| 7415 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7416 | static int |
| 7417 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 7418 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7419 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7420 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7421 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7422 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7423 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7424 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7425 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7426 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7427 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7428 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7429 | int processing_queue = 0; |
| 7430 | |
| 7431 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7432 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 7433 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7434 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7435 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7436 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7437 | return MBX_SUCCESS; |
| 7438 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7439 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7440 | pmbox = lpfc_mbox_get(phba); |
| 7441 | if (!pmbox) { |
| 7442 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7443 | return MBX_SUCCESS; |
| 7444 | } |
| 7445 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7446 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7447 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7448 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7449 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7450 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7451 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7452 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7453 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7454 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7455 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7456 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7457 | } |
| 7458 | } |
| 7459 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7460 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7461 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 7462 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7463 | goto out_not_finished; |
| 7464 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7465 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7466 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7467 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 7468 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7469 | goto out_not_finished; |
| 7470 | } |
| 7471 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7472 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7473 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7474 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7475 | status = MBX_SUCCESS; |
| 7476 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7477 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 7478 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7479 | |
| 7480 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7481 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7482 | "(%d):0311 Mailbox command x%x cannot " |
| 7483 | "issue Data: x%x x%x\n", |
| 7484 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7485 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7486 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7487 | } |
| 7488 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7489 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7490 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 7491 | !(hc_copy & HC_MBINT_ENA)) { |
| 7492 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7493 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7494 | "(%d):2528 Mailbox command x%x cannot " |
| 7495 | "issue Data: x%x x%x\n", |
| 7496 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7497 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7498 | goto out_not_finished; |
| 7499 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 7500 | } |
| 7501 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7502 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7503 | /* Polling for a mbox command when another one is already active |
| 7504 | * is not allowed in SLI. Also, the driver must have established |
| 7505 | * SLI2 mode to queue and process multiple mbox commands. |
| 7506 | */ |
| 7507 | |
| 7508 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7509 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7510 | |
| 7511 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7512 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7513 | "(%d):2529 Mailbox command x%x " |
| 7514 | "cannot issue Data: x%x x%x\n", |
| 7515 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7516 | pmbox->u.mb.mbxCommand, |
| 7517 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7518 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7519 | } |
| 7520 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7521 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7522 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7523 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7524 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7525 | "(%d):2530 Mailbox command x%x " |
| 7526 | "cannot issue Data: x%x x%x\n", |
| 7527 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7528 | pmbox->u.mb.mbxCommand, |
| 7529 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7530 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7531 | } |
| 7532 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7533 | /* Another mailbox command is still being processed, queue this |
| 7534 | * command to be processed later. |
| 7535 | */ |
| 7536 | lpfc_mbox_put(phba, pmbox); |
| 7537 | |
| 7538 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7539 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7540 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7541 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7542 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 7543 | mbx->mbxCommand, |
| 7544 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7545 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7546 | |
| 7547 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7548 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7549 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7550 | if (pmbox->vport) { |
| 7551 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7552 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7553 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7554 | (uint32_t)mbx->mbxCommand, |
| 7555 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7556 | } |
| 7557 | else { |
| 7558 | lpfc_debugfs_disc_trc(phba->pport, |
| 7559 | LPFC_DISC_TRC_MBOX, |
| 7560 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7561 | (uint32_t)mbx->mbxCommand, |
| 7562 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7563 | } |
| 7564 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7565 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7566 | } |
| 7567 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7568 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7569 | |
| 7570 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 7571 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7572 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7573 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7574 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7575 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7576 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7577 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7578 | "(%d):2531 Mailbox command x%x " |
| 7579 | "cannot issue Data: x%x x%x\n", |
| 7580 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7581 | pmbox->u.mb.mbxCommand, |
| 7582 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7583 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7584 | } |
| 7585 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7586 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7587 | 1000); |
| 7588 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7589 | } |
| 7590 | |
| 7591 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7592 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7593 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7594 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7595 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 7596 | mbx->mbxCommand, |
| 7597 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7598 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7599 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7600 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7601 | if (pmbox->vport) { |
| 7602 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7603 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7604 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7605 | (uint32_t)mbx->mbxCommand, |
| 7606 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7607 | } |
| 7608 | else { |
| 7609 | lpfc_debugfs_disc_trc(phba->pport, |
| 7610 | LPFC_DISC_TRC_MBOX, |
| 7611 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7612 | (uint32_t)mbx->mbxCommand, |
| 7613 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7614 | } |
| 7615 | } |
| 7616 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7617 | psli->slistat.mbox_cmd++; |
| 7618 | evtctr = psli->slistat.mbox_event; |
| 7619 | |
| 7620 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7621 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7622 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7623 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7624 | /* Populate mbox extension offset word. */ |
| 7625 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7626 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7627 | = (uint8_t *)phba->mbox_ext |
| 7628 | - (uint8_t *)phba->mbox; |
| 7629 | } |
| 7630 | |
| 7631 | /* Copy the mailbox extension data */ |
| 7632 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7633 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 7634 | (uint8_t *)phba->mbox_ext, |
| 7635 | pmbox->in_ext_byte_len); |
| 7636 | } |
| 7637 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7638 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7639 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7640 | /* Populate mbox extension offset word. */ |
| 7641 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7642 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7643 | = MAILBOX_HBA_EXT_OFFSET; |
| 7644 | |
| 7645 | /* Copy the mailbox extension data */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7646 | if (pmbox->in_ext_byte_len && pmbox->context2) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7647 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 7648 | MAILBOX_HBA_EXT_OFFSET, |
| 7649 | pmbox->context2, pmbox->in_ext_byte_len); |
| 7650 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7651 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7652 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7653 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 7654 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7655 | |
| 7656 | /* First copy mbox command data to HBA SLIM, skip past first |
| 7657 | word */ |
| 7658 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7659 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7660 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 7661 | |
| 7662 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7663 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7664 | to_slim = phba->MBslimaddr; |
| 7665 | writel(ldata, to_slim); |
| 7666 | readl(to_slim); /* flush */ |
| 7667 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7668 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7669 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7670 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7671 | } |
| 7672 | |
| 7673 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7674 | |
| 7675 | switch (flag) { |
| 7676 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7677 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7678 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7679 | /* Interrupt board to do it */ |
| 7680 | writel(CA_MBATT, phba->CAregaddr); |
| 7681 | readl(phba->CAregaddr); /* flush */ |
| 7682 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7683 | break; |
| 7684 | |
| 7685 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7686 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7687 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7688 | /* Interrupt board to do it */ |
| 7689 | writel(CA_MBATT, phba->CAregaddr); |
| 7690 | readl(phba->CAregaddr); /* flush */ |
| 7691 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7692 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7693 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7694 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7695 | word0 = le32_to_cpu(word0); |
| 7696 | } else { |
| 7697 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7698 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 7699 | spin_unlock_irqrestore(&phba->hbalock, |
| 7700 | drvr_flag); |
| 7701 | goto out_not_finished; |
| 7702 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7703 | } |
| 7704 | |
| 7705 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7706 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7707 | spin_unlock_irqrestore(&phba->hbalock, |
| 7708 | drvr_flag); |
| 7709 | goto out_not_finished; |
| 7710 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7711 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7712 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7713 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7714 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7715 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 7716 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7717 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7718 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7719 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7720 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7721 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7722 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7723 | } |
| 7724 | |
| 7725 | /* Check if we took a mbox interrupt while we were |
| 7726 | polling */ |
| 7727 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 7728 | && (evtctr != psli->slistat.mbox_event)) |
| 7729 | break; |
| 7730 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7731 | if (i++ > 10) { |
| 7732 | spin_unlock_irqrestore(&phba->hbalock, |
| 7733 | drvr_flag); |
| 7734 | msleep(1); |
| 7735 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7736 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7737 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7738 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7739 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7740 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7741 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7742 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7743 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7744 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7745 | /* Check real SLIM for any errors */ |
| 7746 | slimword0 = readl(phba->MBslimaddr); |
| 7747 | slimmb = (MAILBOX_t *) & slimword0; |
| 7748 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 7749 | && slimmb->mbxStatus) { |
| 7750 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7751 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7752 | word0 = slimword0; |
| 7753 | } |
| 7754 | } |
| 7755 | } else { |
| 7756 | /* First copy command data */ |
| 7757 | word0 = readl(phba->MBslimaddr); |
| 7758 | } |
| 7759 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7760 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7761 | spin_unlock_irqrestore(&phba->hbalock, |
| 7762 | drvr_flag); |
| 7763 | goto out_not_finished; |
| 7764 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7765 | } |
| 7766 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7767 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7768 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7769 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 7770 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7771 | /* Copy the mailbox extension data */ |
| 7772 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7773 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 7774 | pmbox->context2, |
| 7775 | pmbox->out_ext_byte_len); |
| 7776 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7777 | } else { |
| 7778 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7779 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7780 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7781 | /* Copy the mailbox extension data */ |
| 7782 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7783 | lpfc_memcpy_from_slim(pmbox->context2, |
| 7784 | phba->MBslimaddr + |
| 7785 | MAILBOX_HBA_EXT_OFFSET, |
| 7786 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7787 | } |
| 7788 | } |
| 7789 | |
| 7790 | writel(HA_MBATT, phba->HAregaddr); |
| 7791 | readl(phba->HAregaddr); /* flush */ |
| 7792 | |
| 7793 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7794 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7795 | } |
| 7796 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7797 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7798 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7799 | |
| 7800 | out_not_finished: |
| 7801 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7802 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7803 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 7804 | } |
| 7805 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7806 | } |
| 7807 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7808 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7809 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 7810 | * @phba: Pointer to HBA context object. |
| 7811 | * |
| 7812 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 7813 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 7814 | * possible outstanding mailbox command before return. |
| 7815 | * |
| 7816 | * Returns: |
| 7817 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 7818 | * the outstanding mailbox command timed out. |
| 7819 | **/ |
| 7820 | static int |
| 7821 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 7822 | { |
| 7823 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7824 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7825 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7826 | |
| 7827 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 7828 | spin_lock_irq(&phba->hbalock); |
| 7829 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7830 | /* Determine how long we might wait for the active mailbox |
| 7831 | * command to be gracefully completed by firmware. |
| 7832 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7833 | if (phba->sli.mbox_active) |
| 7834 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 7835 | phba->sli.mbox_active) * |
| 7836 | 1000) + jiffies; |
| 7837 | spin_unlock_irq(&phba->hbalock); |
| 7838 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7839 | /* Make sure the mailbox is really active */ |
| 7840 | if (timeout) |
| 7841 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 7842 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7843 | /* Wait for the outstnading mailbox command to complete */ |
| 7844 | while (phba->sli.mbox_active) { |
| 7845 | /* Check active mailbox complete status every 2ms */ |
| 7846 | msleep(2); |
| 7847 | if (time_after(jiffies, timeout)) { |
| 7848 | /* Timeout, marked the outstanding cmd not complete */ |
| 7849 | rc = 1; |
| 7850 | break; |
| 7851 | } |
| 7852 | } |
| 7853 | |
| 7854 | /* Can not cleanly block async mailbox command, fails it */ |
| 7855 | if (rc) { |
| 7856 | spin_lock_irq(&phba->hbalock); |
| 7857 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7858 | spin_unlock_irq(&phba->hbalock); |
| 7859 | } |
| 7860 | return rc; |
| 7861 | } |
| 7862 | |
| 7863 | /** |
| 7864 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 7865 | * @phba: Pointer to HBA context object. |
| 7866 | * |
| 7867 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7868 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7869 | * that there is no outstanding mailbox command before resuming posting |
| 7870 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7871 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7872 | * mailbox command posting. |
| 7873 | **/ |
| 7874 | static void |
| 7875 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7876 | { |
| 7877 | struct lpfc_sli *psli = &phba->sli; |
| 7878 | |
| 7879 | spin_lock_irq(&phba->hbalock); |
| 7880 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7881 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7882 | spin_unlock_irq(&phba->hbalock); |
| 7883 | return; |
| 7884 | } |
| 7885 | |
| 7886 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7887 | * successful or timeout, after timing-out the outstanding mailbox |
| 7888 | * command shall always be removed, so just unblock posting async |
| 7889 | * mailbox command and resume |
| 7890 | */ |
| 7891 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7892 | spin_unlock_irq(&phba->hbalock); |
| 7893 | |
| 7894 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7895 | lpfc_worker_wake_up(phba); |
| 7896 | } |
| 7897 | |
| 7898 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7899 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 7900 | * @phba: Pointer to HBA context object. |
| 7901 | * @mboxq: Pointer to mailbox object. |
| 7902 | * |
| 7903 | * The function waits for the bootstrap mailbox register ready bit from |
| 7904 | * port for twice the regular mailbox command timeout value. |
| 7905 | * |
| 7906 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 7907 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 7908 | **/ |
| 7909 | static int |
| 7910 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7911 | { |
| 7912 | uint32_t db_ready; |
| 7913 | unsigned long timeout; |
| 7914 | struct lpfc_register bmbx_reg; |
| 7915 | |
| 7916 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 7917 | * 1000) + jiffies; |
| 7918 | |
| 7919 | do { |
| 7920 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7921 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7922 | if (!db_ready) |
| 7923 | msleep(2); |
| 7924 | |
| 7925 | if (time_after(jiffies, timeout)) |
| 7926 | return MBXERR_ERROR; |
| 7927 | } while (!db_ready); |
| 7928 | |
| 7929 | return 0; |
| 7930 | } |
| 7931 | |
| 7932 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7933 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7934 | * @phba: Pointer to HBA context object. |
| 7935 | * @mboxq: Pointer to mailbox object. |
| 7936 | * |
| 7937 | * The function posts a mailbox to the port. The mailbox is expected |
| 7938 | * to be comletely filled in and ready for the port to operate on it. |
| 7939 | * This routine executes a synchronous completion operation on the |
| 7940 | * mailbox by polling for its completion. |
| 7941 | * |
| 7942 | * The caller must not be holding any locks when calling this routine. |
| 7943 | * |
| 7944 | * Returns: |
| 7945 | * MBX_SUCCESS - mailbox posted successfully |
| 7946 | * Any of the MBX error values. |
| 7947 | **/ |
| 7948 | static int |
| 7949 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7950 | { |
| 7951 | int rc = MBX_SUCCESS; |
| 7952 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7953 | uint32_t mcqe_status; |
| 7954 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7955 | struct lpfc_sli *psli = &phba->sli; |
| 7956 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7957 | struct lpfc_bmbx_create *mbox_rgn; |
| 7958 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7959 | |
| 7960 | /* |
| 7961 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7962 | * at a time and there is no queueing provided. |
| 7963 | */ |
| 7964 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7965 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7966 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7967 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7968 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7969 | "cannot issue Data: x%x x%x\n", |
| 7970 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7971 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7972 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7973 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7974 | psli->sli_flag, MBX_POLL); |
| 7975 | return MBXERR_ERROR; |
| 7976 | } |
| 7977 | /* The server grabs the token and owns it until release */ |
| 7978 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7979 | phba->sli.mbox_active = mboxq; |
| 7980 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7981 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7982 | /* wait for bootstrap mbox register for readyness */ |
| 7983 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7984 | if (rc) |
| 7985 | goto exit; |
| 7986 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7987 | /* |
| 7988 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7989 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7990 | * the bmbx mailbox region. |
| 7991 | */ |
| 7992 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7993 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7994 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7995 | sizeof(struct lpfc_mqe)); |
| 7996 | |
| 7997 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7998 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7999 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 8000 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8001 | /* wait for bootstrap mbox register for hi-address write done */ |
| 8002 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8003 | if (rc) |
| 8004 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8005 | |
| 8006 | /* Post the low mailbox dma address to the port. */ |
| 8007 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8008 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 8009 | /* wait for bootstrap mbox register for low address write done */ |
| 8010 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 8011 | if (rc) |
| 8012 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8013 | |
| 8014 | /* |
| 8015 | * Read the CQ to ensure the mailbox has completed. |
| 8016 | * If so, update the mailbox status so that the upper layers |
| 8017 | * can complete the request normally. |
| 8018 | */ |
| 8019 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 8020 | sizeof(struct lpfc_mqe)); |
| 8021 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 8022 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 8023 | sizeof(struct lpfc_mcqe)); |
| 8024 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8025 | /* |
| 8026 | * When the CQE status indicates a failure and the mailbox status |
| 8027 | * indicates success then copy the CQE status into the mailbox status |
| 8028 | * (and prefix it with x4000). |
| 8029 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8030 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8031 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 8032 | bf_set(lpfc_mqe_status, mb, |
| 8033 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8034 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8035 | } else |
| 8036 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8037 | |
| 8038 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8039 | "(%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] | 8040 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8041 | " 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] | 8042 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8043 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8044 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8045 | bf_get(lpfc_mqe_status, mb), |
| 8046 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8047 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8048 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8049 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8050 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8051 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8052 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8053 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8054 | mboxq->mcqe.trailer); |
| 8055 | exit: |
| 8056 | /* We are holding the token, no needed for lock when release */ |
| 8057 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8058 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8059 | phba->sli.mbox_active = NULL; |
| 8060 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8061 | return rc; |
| 8062 | } |
| 8063 | |
| 8064 | /** |
| 8065 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8066 | * @phba: Pointer to HBA context object. |
| 8067 | * @pmbox: Pointer to mailbox object. |
| 8068 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8069 | * |
| 8070 | * This function is called by discovery code and HBA management code to submit |
| 8071 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8072 | * |
| 8073 | * Return codes the caller owns the mailbox command after the return of the |
| 8074 | * function. |
| 8075 | **/ |
| 8076 | static int |
| 8077 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8078 | uint32_t flag) |
| 8079 | { |
| 8080 | struct lpfc_sli *psli = &phba->sli; |
| 8081 | unsigned long iflags; |
| 8082 | int rc; |
| 8083 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8084 | /* dump from issue mailbox command if setup */ |
| 8085 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8086 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8087 | rc = lpfc_mbox_dev_check(phba); |
| 8088 | if (unlikely(rc)) { |
| 8089 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8090 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8091 | "cannot issue Data: x%x x%x\n", |
| 8092 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8093 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8094 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8095 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8096 | psli->sli_flag, flag); |
| 8097 | goto out_not_finished; |
| 8098 | } |
| 8099 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8100 | /* Detect polling mode and jump to a handler */ |
| 8101 | if (!phba->sli4_hba.intr_enable) { |
| 8102 | if (flag == MBX_POLL) |
| 8103 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8104 | else |
| 8105 | rc = -EIO; |
| 8106 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8107 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8108 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8109 | "(x%x/x%x) failure: " |
| 8110 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8111 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8112 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8113 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8114 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8115 | mboxq), |
| 8116 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8117 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8118 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8119 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8120 | bf_get(lpfc_mcqe_ext_status, |
| 8121 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8122 | psli->sli_flag, flag); |
| 8123 | return rc; |
| 8124 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8125 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8126 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8127 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8128 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8129 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8130 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8131 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8132 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8133 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8134 | /* Try to block the asynchronous mailbox posting */ |
| 8135 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8136 | if (!rc) { |
| 8137 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8138 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8139 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8140 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8141 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8142 | "(%d):2597 Sync Mailbox command " |
| 8143 | "x%x (x%x/x%x) failure: " |
| 8144 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8145 | "Data: x%x x%x\n,", |
| 8146 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8147 | mboxq->u.mb.mbxCommand, |
| 8148 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8149 | mboxq), |
| 8150 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8151 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8152 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8153 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8154 | bf_get(lpfc_mcqe_ext_status, |
| 8155 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8156 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8157 | /* Unblock the async mailbox posting afterward */ |
| 8158 | lpfc_sli4_async_mbox_unblock(phba); |
| 8159 | } |
| 8160 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8161 | } |
| 8162 | |
| 8163 | /* Now, interrupt mode asynchrous mailbox command */ |
| 8164 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8165 | if (rc) { |
| 8166 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8167 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8168 | "cannot issue Data: x%x x%x\n", |
| 8169 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8170 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8171 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8172 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8173 | psli->sli_flag, flag); |
| 8174 | goto out_not_finished; |
| 8175 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8176 | |
| 8177 | /* Put the mailbox command to the driver internal FIFO */ |
| 8178 | psli->slistat.mbox_busy++; |
| 8179 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8180 | lpfc_mbox_put(phba, mboxq); |
| 8181 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8182 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8183 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8184 | "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] | 8185 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 8186 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8187 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8188 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8189 | phba->pport->port_state, |
| 8190 | psli->sli_flag, MBX_NOWAIT); |
| 8191 | /* Wake up worker thread to transport mailbox command from head */ |
| 8192 | lpfc_worker_wake_up(phba); |
| 8193 | |
| 8194 | return MBX_BUSY; |
| 8195 | |
| 8196 | out_not_finished: |
| 8197 | return MBX_NOT_FINISHED; |
| 8198 | } |
| 8199 | |
| 8200 | /** |
| 8201 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 8202 | * @phba: Pointer to HBA context object. |
| 8203 | * |
| 8204 | * This function is called by worker thread to send a mailbox command to |
| 8205 | * SLI4 HBA firmware. |
| 8206 | * |
| 8207 | **/ |
| 8208 | int |
| 8209 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 8210 | { |
| 8211 | struct lpfc_sli *psli = &phba->sli; |
| 8212 | LPFC_MBOXQ_t *mboxq; |
| 8213 | int rc = MBX_SUCCESS; |
| 8214 | unsigned long iflags; |
| 8215 | struct lpfc_mqe *mqe; |
| 8216 | uint32_t mbx_cmnd; |
| 8217 | |
| 8218 | /* Check interrupt mode before post async mailbox command */ |
| 8219 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 8220 | return MBX_NOT_FINISHED; |
| 8221 | |
| 8222 | /* Check for mailbox command service token */ |
| 8223 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8224 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8225 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8226 | return MBX_NOT_FINISHED; |
| 8227 | } |
| 8228 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8229 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8230 | return MBX_NOT_FINISHED; |
| 8231 | } |
| 8232 | if (unlikely(phba->sli.mbox_active)) { |
| 8233 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8234 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8235 | "0384 There is pending active mailbox cmd\n"); |
| 8236 | return MBX_NOT_FINISHED; |
| 8237 | } |
| 8238 | /* Take the mailbox command service token */ |
| 8239 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8240 | |
| 8241 | /* Get the next mailbox command from head of queue */ |
| 8242 | mboxq = lpfc_mbox_get(phba); |
| 8243 | |
| 8244 | /* If no more mailbox command waiting for post, we're done */ |
| 8245 | if (!mboxq) { |
| 8246 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8247 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8248 | return MBX_SUCCESS; |
| 8249 | } |
| 8250 | phba->sli.mbox_active = mboxq; |
| 8251 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8252 | |
| 8253 | /* Check device readiness for posting mailbox command */ |
| 8254 | rc = lpfc_mbox_dev_check(phba); |
| 8255 | if (unlikely(rc)) |
| 8256 | /* Driver clean routine will clean up pending mailbox */ |
| 8257 | goto out_not_finished; |
| 8258 | |
| 8259 | /* Prepare the mbox command to be posted */ |
| 8260 | mqe = &mboxq->u.mqe; |
| 8261 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 8262 | |
| 8263 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 8264 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8265 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8266 | |
| 8267 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8268 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8269 | "x%x x%x\n", |
| 8270 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8271 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8272 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8273 | phba->pport->port_state, psli->sli_flag); |
| 8274 | |
| 8275 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 8276 | if (mboxq->vport) { |
| 8277 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 8278 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8279 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 8280 | mbx_cmnd, mqe->un.mb_words[0], |
| 8281 | mqe->un.mb_words[1]); |
| 8282 | } else { |
| 8283 | lpfc_debugfs_disc_trc(phba->pport, |
| 8284 | LPFC_DISC_TRC_MBOX, |
| 8285 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 8286 | mbx_cmnd, mqe->un.mb_words[0], |
| 8287 | mqe->un.mb_words[1]); |
| 8288 | } |
| 8289 | } |
| 8290 | psli->slistat.mbox_cmd++; |
| 8291 | |
| 8292 | /* Post the mailbox command to the port */ |
| 8293 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 8294 | if (rc != MBX_SUCCESS) { |
| 8295 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8296 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8297 | "cannot issue Data: x%x x%x\n", |
| 8298 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8299 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8300 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8301 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8302 | psli->sli_flag, MBX_NOWAIT); |
| 8303 | goto out_not_finished; |
| 8304 | } |
| 8305 | |
| 8306 | return rc; |
| 8307 | |
| 8308 | out_not_finished: |
| 8309 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 8310 | if (phba->sli.mbox_active) { |
| 8311 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8312 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8313 | /* Release the token */ |
| 8314 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8315 | phba->sli.mbox_active = NULL; |
| 8316 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8317 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8318 | |
| 8319 | return MBX_NOT_FINISHED; |
| 8320 | } |
| 8321 | |
| 8322 | /** |
| 8323 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 8324 | * @phba: Pointer to HBA context object. |
| 8325 | * @pmbox: Pointer to mailbox object. |
| 8326 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8327 | * |
| 8328 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 8329 | * the API jump table function pointer from the lpfc_hba struct. |
| 8330 | * |
| 8331 | * Return codes the caller owns the mailbox command after the return of the |
| 8332 | * function. |
| 8333 | **/ |
| 8334 | int |
| 8335 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 8336 | { |
| 8337 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 8338 | } |
| 8339 | |
| 8340 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8341 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8342 | * @phba: The hba struct for which this call is being executed. |
| 8343 | * @dev_grp: The HBA PCI-Device group number. |
| 8344 | * |
| 8345 | * This routine sets up the mbox interface API function jump table in @phba |
| 8346 | * struct. |
| 8347 | * Returns: 0 - success, -ENODEV - failure. |
| 8348 | **/ |
| 8349 | int |
| 8350 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8351 | { |
| 8352 | |
| 8353 | switch (dev_grp) { |
| 8354 | case LPFC_PCI_DEV_LP: |
| 8355 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 8356 | phba->lpfc_sli_handle_slow_ring_event = |
| 8357 | lpfc_sli_handle_slow_ring_event_s3; |
| 8358 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 8359 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 8360 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 8361 | break; |
| 8362 | case LPFC_PCI_DEV_OC: |
| 8363 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 8364 | phba->lpfc_sli_handle_slow_ring_event = |
| 8365 | lpfc_sli_handle_slow_ring_event_s4; |
| 8366 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 8367 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 8368 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 8369 | break; |
| 8370 | default: |
| 8371 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8372 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 8373 | dev_grp); |
| 8374 | return -ENODEV; |
| 8375 | break; |
| 8376 | } |
| 8377 | return 0; |
| 8378 | } |
| 8379 | |
| 8380 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8381 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8382 | * @phba: Pointer to HBA context object. |
| 8383 | * @pring: Pointer to driver SLI ring object. |
| 8384 | * @piocb: Pointer to address of newly added command iocb. |
| 8385 | * |
| 8386 | * This function is called with hbalock held to add a command |
| 8387 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 8388 | * to the ring. |
| 8389 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8390 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8391 | __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] | 8392 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8393 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8394 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8395 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 8396 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8397 | } |
| 8398 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8399 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8400 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8401 | * @phba: Pointer to HBA context object. |
| 8402 | * @pring: Pointer to driver SLI ring object. |
| 8403 | * @piocb: Pointer to address of newly added command iocb. |
| 8404 | * |
| 8405 | * This function is called with hbalock held before a new |
| 8406 | * iocb is submitted to the firmware. This function checks |
| 8407 | * txq to flush the iocbs in txq to Firmware before |
| 8408 | * submitting new iocbs to the Firmware. |
| 8409 | * If there are iocbs in the txq which need to be submitted |
| 8410 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 8411 | * of the txq after dequeuing it from txq. |
| 8412 | * If there is no iocb in the txq then the function will return |
| 8413 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 8414 | * *piocb to find if there are more commands in the txq. |
| 8415 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8416 | static struct lpfc_iocbq * |
| 8417 | 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] | 8418 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8419 | { |
| 8420 | struct lpfc_iocbq * nextiocb; |
| 8421 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8422 | lockdep_assert_held(&phba->hbalock); |
| 8423 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8424 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 8425 | if (!nextiocb) { |
| 8426 | nextiocb = *piocb; |
| 8427 | *piocb = NULL; |
| 8428 | } |
| 8429 | |
| 8430 | return nextiocb; |
| 8431 | } |
| 8432 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8433 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8434 | * __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] | 8435 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8436 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8437 | * @piocb: Pointer to command iocb. |
| 8438 | * @flag: Flag indicating if this command can be put into txq. |
| 8439 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8440 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 8441 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 8442 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 8443 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 8444 | * this function allows only iocbs for posting buffers. This function finds |
| 8445 | * next available slot in the command ring and posts the command to the |
| 8446 | * available slot and writes the port attention register to request HBA start |
| 8447 | * processing new iocb. If there is no slot available in the ring and |
| 8448 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 8449 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8450 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8451 | * This function is called with hbalock held. The function will return success |
| 8452 | * after it successfully submit the iocb to firmware or after adding to the |
| 8453 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8454 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8455 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8456 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8457 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8458 | { |
| 8459 | struct lpfc_iocbq *nextiocb; |
| 8460 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8461 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8462 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8463 | lockdep_assert_held(&phba->hbalock); |
| 8464 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8465 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 8466 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 8467 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 8468 | lpfc_printf_log(phba, KERN_ERR, |
| 8469 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8470 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8471 | piocb->iocb.ulpCommand); |
| 8472 | dump_stack(); |
| 8473 | return IOCB_ERROR; |
| 8474 | } |
| 8475 | |
| 8476 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8477 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 8478 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 8479 | return IOCB_ERROR; |
| 8480 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8481 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8482 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 8483 | return IOCB_ERROR; |
| 8484 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8485 | /* |
| 8486 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 8487 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8488 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8489 | return IOCB_ERROR; |
| 8490 | |
| 8491 | /* |
| 8492 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8493 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8494 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8495 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8496 | goto iocb_busy; |
| 8497 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8498 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8499 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8500 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8501 | * can be issued if the link is not up. |
| 8502 | */ |
| 8503 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8504 | case CMD_GEN_REQUEST64_CR: |
| 8505 | case CMD_GEN_REQUEST64_CX: |
| 8506 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 8507 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8508 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8509 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 8510 | MENLO_TRANSPORT_TYPE)) |
| 8511 | |
| 8512 | goto iocb_busy; |
| 8513 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8514 | case CMD_QUE_RING_BUF_CN: |
| 8515 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8516 | /* |
| 8517 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 8518 | * completion, iocb_cmpl MUST be 0. |
| 8519 | */ |
| 8520 | if (piocb->iocb_cmpl) |
| 8521 | piocb->iocb_cmpl = NULL; |
| 8522 | /*FALLTHROUGH*/ |
| 8523 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8524 | case CMD_CLOSE_XRI_CN: |
| 8525 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8526 | break; |
| 8527 | default: |
| 8528 | goto iocb_busy; |
| 8529 | } |
| 8530 | |
| 8531 | /* |
| 8532 | * For FCP commands, we must be in a state where we can process link |
| 8533 | * attention events. |
| 8534 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8535 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8536 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8537 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8538 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8539 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8540 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 8541 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 8542 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 8543 | |
| 8544 | if (iocb) |
| 8545 | lpfc_sli_update_ring(phba, pring); |
| 8546 | else |
| 8547 | lpfc_sli_update_full_ring(phba, pring); |
| 8548 | |
| 8549 | if (!piocb) |
| 8550 | return IOCB_SUCCESS; |
| 8551 | |
| 8552 | goto out_busy; |
| 8553 | |
| 8554 | iocb_busy: |
| 8555 | pring->stats.iocb_cmd_delay++; |
| 8556 | |
| 8557 | out_busy: |
| 8558 | |
| 8559 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8560 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8561 | return IOCB_SUCCESS; |
| 8562 | } |
| 8563 | |
| 8564 | return IOCB_BUSY; |
| 8565 | } |
| 8566 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8567 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8568 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 8569 | * @phba: Pointer to HBA context object. |
| 8570 | * @piocb: Pointer to command iocb. |
| 8571 | * @sglq: Pointer to the scatter gather queue object. |
| 8572 | * |
| 8573 | * This routine converts the bpl or bde that is in the IOCB |
| 8574 | * to a sgl list for the sli4 hardware. The physical address |
| 8575 | * of the bpl/bde is converted back to a virtual address. |
| 8576 | * If the IOCB contains a BPL then the list of BDE's is |
| 8577 | * converted to sli4_sge's. If the IOCB contains a single |
| 8578 | * BDE then it is converted to a single sli_sge. |
| 8579 | * The IOCB is still in cpu endianess so the contents of |
| 8580 | * the bpl can be used without byte swapping. |
| 8581 | * |
| 8582 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 8583 | **/ |
| 8584 | static uint16_t |
| 8585 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 8586 | struct lpfc_sglq *sglq) |
| 8587 | { |
| 8588 | uint16_t xritag = NO_XRI; |
| 8589 | struct ulp_bde64 *bpl = NULL; |
| 8590 | struct ulp_bde64 bde; |
| 8591 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8592 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8593 | IOCB_t *icmd; |
| 8594 | int numBdes = 0; |
| 8595 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8596 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 8597 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8598 | |
| 8599 | if (!piocbq || !sglq) |
| 8600 | return xritag; |
| 8601 | |
| 8602 | sgl = (struct sli4_sge *)sglq->sgl; |
| 8603 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8604 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 8605 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8606 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 8607 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 8608 | sizeof(struct ulp_bde64); |
| 8609 | /* The addrHigh and addrLow fields within the IOCB |
| 8610 | * have not been byteswapped yet so there is no |
| 8611 | * need to swap them back. |
| 8612 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8613 | if (piocbq->context3) |
| 8614 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 8615 | else |
| 8616 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8617 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8618 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8619 | if (!bpl) |
| 8620 | return xritag; |
| 8621 | |
| 8622 | for (i = 0; i < numBdes; i++) { |
| 8623 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8624 | sgl->addr_hi = bpl->addrHigh; |
| 8625 | sgl->addr_lo = bpl->addrLow; |
| 8626 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8627 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8628 | if ((i+1) == numBdes) |
| 8629 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8630 | else |
| 8631 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8632 | /* swap the size field back to the cpu so we |
| 8633 | * can assign it to the sgl. |
| 8634 | */ |
| 8635 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 8636 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8637 | /* The offsets in the sgl need to be accumulated |
| 8638 | * separately for the request and reply lists. |
| 8639 | * The request is always first, the reply follows. |
| 8640 | */ |
| 8641 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 8642 | /* add up the reply sg entries */ |
| 8643 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 8644 | inbound++; |
| 8645 | /* first inbound? reset the offset */ |
| 8646 | if (inbound == 1) |
| 8647 | offset = 0; |
| 8648 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 8649 | bf_set(lpfc_sli4_sge_type, sgl, |
| 8650 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8651 | offset += bde.tus.f.bdeSize; |
| 8652 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8653 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8654 | bpl++; |
| 8655 | sgl++; |
| 8656 | } |
| 8657 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 8658 | /* The addrHigh and addrLow fields of the BDE have not |
| 8659 | * been byteswapped yet so they need to be swapped |
| 8660 | * before putting them in the sgl. |
| 8661 | */ |
| 8662 | sgl->addr_hi = |
| 8663 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 8664 | sgl->addr_lo = |
| 8665 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8666 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8667 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8668 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8669 | sgl->sge_len = |
| 8670 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8671 | } |
| 8672 | return sglq->sli4_xritag; |
| 8673 | } |
| 8674 | |
| 8675 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8676 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 8677 | * @phba: Pointer to HBA context object. |
| 8678 | * @piocb: Pointer to command iocb. |
| 8679 | * @wqe: Pointer to the work queue entry. |
| 8680 | * |
| 8681 | * This routine converts the iocb command to its Work Queue Entry |
| 8682 | * equivalent. The wqe pointer should not have any fields set when |
| 8683 | * this routine is called because it will memcpy over them. |
| 8684 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 8685 | * wqe. |
| 8686 | * |
| 8687 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 8688 | **/ |
| 8689 | static int |
| 8690 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 8691 | union lpfc_wqe *wqe) |
| 8692 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8693 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8694 | uint8_t ct = 0; |
| 8695 | uint32_t fip; |
| 8696 | uint32_t abort_tag; |
| 8697 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 8698 | uint8_t cmnd; |
| 8699 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8700 | uint16_t abrt_iotag; |
| 8701 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8702 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8703 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8704 | int numBdes, i; |
| 8705 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8706 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8707 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8708 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8709 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 8710 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8711 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8712 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8713 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8714 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8715 | command_type = ELS_COMMAND_FIP; |
| 8716 | else |
| 8717 | command_type = ELS_COMMAND_NON_FIP; |
| 8718 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8719 | if (phba->fcp_embed_io) |
| 8720 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8721 | /* Some of the fields are in the right position already */ |
| 8722 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 8723 | if (iocbq->iocb.ulpCommand != CMD_SEND_FRAME) { |
| 8724 | /* The ct field has moved so reset */ |
| 8725 | wqe->generic.wqe_com.word7 = 0; |
| 8726 | wqe->generic.wqe_com.word10 = 0; |
| 8727 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8728 | |
| 8729 | abort_tag = (uint32_t) iocbq->iotag; |
| 8730 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8731 | /* words0-2 bpl convert bde */ |
| 8732 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8733 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8734 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8735 | bpl = (struct ulp_bde64 *) |
| 8736 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 8737 | if (!bpl) |
| 8738 | return IOCB_ERROR; |
| 8739 | |
| 8740 | /* Should already be byte swapped. */ |
| 8741 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 8742 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 8743 | /* swap the size field back to the cpu so we |
| 8744 | * can assign it to the sgl. |
| 8745 | */ |
| 8746 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8747 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 8748 | total_len = 0; |
| 8749 | for (i = 0; i < numBdes; i++) { |
| 8750 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 8751 | total_len += bde.tus.f.bdeSize; |
| 8752 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8753 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8754 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8755 | |
| 8756 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 8757 | cmnd = iocbq->iocb.ulpCommand; |
| 8758 | |
| 8759 | switch (iocbq->iocb.ulpCommand) { |
| 8760 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 8761 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 8762 | ndlp = iocbq->context_un.ndlp; |
| 8763 | else |
| 8764 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8765 | if (!iocbq->iocb.ulpLe) { |
| 8766 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8767 | "2007 Only Limited Edition cmd Format" |
| 8768 | " supported 0x%x\n", |
| 8769 | iocbq->iocb.ulpCommand); |
| 8770 | return IOCB_ERROR; |
| 8771 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8772 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8773 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8774 | /* Els_reguest64 has a TMO */ |
| 8775 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 8776 | iocbq->iocb.ulpTimeout); |
| 8777 | /* Need a VF for word 4 set the vf bit*/ |
| 8778 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 8779 | /* And a VFID for word 12 */ |
| 8780 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8781 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8782 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8783 | iocbq->iocb.ulpContext); |
| 8784 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 8785 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8786 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8787 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8788 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 8789 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8790 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8791 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8792 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8793 | &phba->sli4_hba.sli_intf); |
| 8794 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8795 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8796 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8797 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 8798 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8799 | *pcmd == ELS_CMD_PLOGI)) { |
| 8800 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 8801 | bf_set(els_req64_sid, &wqe->els_req, |
| 8802 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8803 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 8804 | !(phba->fc_topology == |
| 8805 | LPFC_TOPOLOGY_LOOP)) |
| 8806 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8807 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 8808 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 8809 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 8810 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8811 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 8812 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8813 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 8814 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8815 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8816 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 8817 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8818 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 8819 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 8820 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8821 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 8822 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8823 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8824 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8825 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8826 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8827 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 8828 | iocbq->iocb.un.ulpWord[3]); |
| 8829 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8830 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8831 | /* The entire sequence is transmitted for this IOCB */ |
| 8832 | xmit_len = total_len; |
| 8833 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8834 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 8835 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8836 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8837 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 8838 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8839 | /* word4 relative_offset memcpy */ |
| 8840 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8841 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 8842 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 8843 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 8844 | LPFC_WQE_IOD_WRITE); |
| 8845 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 8846 | LPFC_WQE_LENLOC_WORD12); |
| 8847 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8848 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 8849 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8850 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8851 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8852 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 8853 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8854 | /* word4 iocb=rsvd wqe=rsvd */ |
| 8855 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 8856 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8857 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8858 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8859 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 8860 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8861 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 8862 | LPFC_WQE_LENLOC_WORD3); |
| 8863 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8864 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8865 | case CMD_FCP_IWRITE64_CR: |
| 8866 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8867 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8868 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8869 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 8870 | xmit_len + sizeof(struct fcp_rsp)); |
| 8871 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 8872 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8873 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8874 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8875 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 8876 | iocbq->iocb.ulpFCP2Rcvy); |
| 8877 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 8878 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8879 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8880 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8881 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8882 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8883 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8884 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8885 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8886 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 8887 | if (iocbq->priority) { |
| 8888 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8889 | (iocbq->priority << 1)); |
| 8890 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8891 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8892 | (phba->cfg_XLanePriority << 1)); |
| 8893 | } |
| 8894 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8895 | /* Note, word 10 is already initialized to 0 */ |
| 8896 | |
| 8897 | if (phba->fcp_embed_io) { |
| 8898 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8899 | struct sli4_sge *sgl; |
| 8900 | union lpfc_wqe128 *wqe128; |
| 8901 | struct fcp_cmnd *fcp_cmnd; |
| 8902 | uint32_t *ptr; |
| 8903 | |
| 8904 | /* 128 byte wqe support here */ |
| 8905 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8906 | |
| 8907 | lpfc_cmd = iocbq->context1; |
| 8908 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8909 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8910 | |
| 8911 | /* Word 0-2 - FCP_CMND */ |
| 8912 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8913 | BUFF_TYPE_BDE_IMMED; |
| 8914 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8915 | wqe128->generic.bde.addrHigh = 0; |
| 8916 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8917 | |
| 8918 | bf_set(wqe_wqes, &wqe128->fcp_iwrite.wqe_com, 1); |
| 8919 | |
| 8920 | /* Word 22-29 FCP CMND Payload */ |
| 8921 | ptr = &wqe128->words[22]; |
| 8922 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8923 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8924 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8925 | case CMD_FCP_IREAD64_CR: |
| 8926 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8927 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8928 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 8929 | xmit_len + sizeof(struct fcp_rsp)); |
| 8930 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 8931 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8932 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8933 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8934 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8935 | iocbq->iocb.ulpFCP2Rcvy); |
| 8936 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8937 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8938 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8939 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8940 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8941 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8942 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8943 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8944 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8945 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 8946 | if (iocbq->priority) { |
| 8947 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8948 | (iocbq->priority << 1)); |
| 8949 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8950 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8951 | (phba->cfg_XLanePriority << 1)); |
| 8952 | } |
| 8953 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8954 | /* Note, word 10 is already initialized to 0 */ |
| 8955 | |
| 8956 | if (phba->fcp_embed_io) { |
| 8957 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8958 | struct sli4_sge *sgl; |
| 8959 | union lpfc_wqe128 *wqe128; |
| 8960 | struct fcp_cmnd *fcp_cmnd; |
| 8961 | uint32_t *ptr; |
| 8962 | |
| 8963 | /* 128 byte wqe support here */ |
| 8964 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8965 | |
| 8966 | lpfc_cmd = iocbq->context1; |
| 8967 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8968 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8969 | |
| 8970 | /* Word 0-2 - FCP_CMND */ |
| 8971 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8972 | BUFF_TYPE_BDE_IMMED; |
| 8973 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8974 | wqe128->generic.bde.addrHigh = 0; |
| 8975 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8976 | |
| 8977 | bf_set(wqe_wqes, &wqe128->fcp_iread.wqe_com, 1); |
| 8978 | |
| 8979 | /* Word 22-29 FCP CMND Payload */ |
| 8980 | ptr = &wqe128->words[22]; |
| 8981 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8982 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8983 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8984 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8985 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8986 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8987 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 8988 | xmit_len + sizeof(struct fcp_rsp)); |
| 8989 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 8990 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8991 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8992 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8993 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8994 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8995 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8996 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8997 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8998 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 8999 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 9000 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9001 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 9002 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 9003 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 9004 | if (iocbq->priority) { |
| 9005 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9006 | (iocbq->priority << 1)); |
| 9007 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9008 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 9009 | (phba->cfg_XLanePriority << 1)); |
| 9010 | } |
| 9011 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9012 | /* Note, word 10 is already initialized to 0 */ |
| 9013 | |
| 9014 | if (phba->fcp_embed_io) { |
| 9015 | struct lpfc_scsi_buf *lpfc_cmd; |
| 9016 | struct sli4_sge *sgl; |
| 9017 | union lpfc_wqe128 *wqe128; |
| 9018 | struct fcp_cmnd *fcp_cmnd; |
| 9019 | uint32_t *ptr; |
| 9020 | |
| 9021 | /* 128 byte wqe support here */ |
| 9022 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 9023 | |
| 9024 | lpfc_cmd = iocbq->context1; |
| 9025 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 9026 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 9027 | |
| 9028 | /* Word 0-2 - FCP_CMND */ |
| 9029 | wqe128->generic.bde.tus.f.bdeFlags = |
| 9030 | BUFF_TYPE_BDE_IMMED; |
| 9031 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 9032 | wqe128->generic.bde.addrHigh = 0; |
| 9033 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 9034 | |
| 9035 | bf_set(wqe_wqes, &wqe128->fcp_icmd.wqe_com, 1); |
| 9036 | |
| 9037 | /* Word 22-29 FCP CMND Payload */ |
| 9038 | ptr = &wqe128->words[22]; |
| 9039 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9040 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9041 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9042 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9043 | /* For this command calculate the xmit length of the |
| 9044 | * request bde. |
| 9045 | */ |
| 9046 | xmit_len = 0; |
| 9047 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9048 | sizeof(struct ulp_bde64); |
| 9049 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9050 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9051 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9052 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9053 | xmit_len += bde.tus.f.bdeSize; |
| 9054 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9055 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9056 | wqe->gen_req.request_payload_len = xmit_len; |
| 9057 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9058 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9059 | /* word6 context tag copied in memcpy */ |
| 9060 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9061 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9062 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9063 | "2015 Invalid CT %x command 0x%x\n", |
| 9064 | ct, iocbq->iocb.ulpCommand); |
| 9065 | return IOCB_ERROR; |
| 9066 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9067 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9068 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9069 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9070 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9071 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9072 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9073 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9074 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9075 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9076 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9077 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9078 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9079 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9080 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9081 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9082 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9083 | /* word4 */ |
| 9084 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9085 | /* word5 iocb=rsvd wge=did */ |
| 9086 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9087 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9088 | |
| 9089 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9090 | &phba->sli4_hba.sli_intf); |
| 9091 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 9092 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9093 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9094 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9095 | iocbq->vport->fc_myDID); |
| 9096 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9097 | bf_set(wqe_els_did, |
| 9098 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9099 | } |
| 9100 | } |
| 9101 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9102 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9103 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9104 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9105 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9106 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9107 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9108 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9109 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9110 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9111 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9112 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9113 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9114 | LPFC_WQE_LENLOC_WORD3); |
| 9115 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9116 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9117 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9118 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9119 | iocbq->context2)->virt); |
| 9120 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9121 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9122 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9123 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9124 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9125 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9126 | phba->vpi_ids[phba->pport->vpi]); |
| 9127 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9128 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9129 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9130 | case CMD_CLOSE_XRI_CN: |
| 9131 | case CMD_ABORT_XRI_CN: |
| 9132 | case CMD_ABORT_XRI_CX: |
| 9133 | /* words 0-2 memcpy should be 0 rserved */ |
| 9134 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9135 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9136 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9137 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9138 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9139 | } else |
| 9140 | fip = 0; |
| 9141 | |
| 9142 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9143 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9144 | * The link is down, or the command was ELS_FIP |
| 9145 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9146 | * on the wire. |
| 9147 | */ |
| 9148 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9149 | else |
| 9150 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9151 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9152 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9153 | wqe->abort_cmd.rsrvd5 = 0; |
| 9154 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9155 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9156 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9157 | /* |
| 9158 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9159 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9160 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9161 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 9162 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 9163 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 9164 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9165 | cmnd = CMD_ABORT_XRI_CX; |
| 9166 | command_type = OTHER_COMMAND; |
| 9167 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9168 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9169 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9170 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9171 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9172 | * we re-construct this WQE here based on information in |
| 9173 | * iocbq from scratch. |
| 9174 | */ |
| 9175 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9176 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9177 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9178 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 9179 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9180 | LPFC_ABTS_UNSOL_INT) { |
| 9181 | /* ABTS sent by initiator to CT exchange, the |
| 9182 | * RX_ID field will be filled with the newly |
| 9183 | * allocated responder XRI. |
| 9184 | */ |
| 9185 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 9186 | iocbq->sli4_xritag); |
| 9187 | } else { |
| 9188 | /* ABTS sent by responder to CT exchange, the |
| 9189 | * RX_ID field will be filled with the responder |
| 9190 | * RX_ID from ABTS. |
| 9191 | */ |
| 9192 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9193 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9194 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9195 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 9196 | 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] | 9197 | |
| 9198 | /* Use CT=VPI */ |
| 9199 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 9200 | ndlp->nlp_DID); |
| 9201 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 9202 | iocbq->iocb.ulpContext); |
| 9203 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9204 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9205 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9206 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 9207 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 9208 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9209 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 9210 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9211 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 9212 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 9213 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 9214 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 9215 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 9216 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 9217 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 9218 | } |
| 9219 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9220 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9221 | case CMD_SEND_FRAME: |
| 9222 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9223 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9224 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9225 | case CMD_XRI_ABORTED_CX: |
| 9226 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9227 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 9228 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 9229 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 9230 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 9231 | default: |
| 9232 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9233 | "2014 Invalid command 0x%x\n", |
| 9234 | iocbq->iocb.ulpCommand); |
| 9235 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9236 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9237 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9238 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 9239 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 9240 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 9241 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 9242 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 9243 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 9244 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 9245 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 9246 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9247 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9248 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9249 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 9250 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 9251 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 9252 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 9253 | 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] | 9254 | return 0; |
| 9255 | } |
| 9256 | |
| 9257 | /** |
| 9258 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 9259 | * @phba: Pointer to HBA context object. |
| 9260 | * @ring_number: SLI ring number to issue iocb on. |
| 9261 | * @piocb: Pointer to command iocb. |
| 9262 | * @flag: Flag indicating if this command can be put into txq. |
| 9263 | * |
| 9264 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 9265 | * an iocb command to an HBA with SLI-4 interface spec. |
| 9266 | * |
| 9267 | * This function is called with hbalock held. The function will return success |
| 9268 | * after it successfully submit the iocb to firmware or after adding to the |
| 9269 | * txq. |
| 9270 | **/ |
| 9271 | static int |
| 9272 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 9273 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9274 | { |
| 9275 | struct lpfc_sglq *sglq; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9276 | union lpfc_wqe *wqe; |
| 9277 | union lpfc_wqe128 wqe128; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9278 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9279 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9280 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9281 | /* Get the WQ */ |
| 9282 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 9283 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
| 9284 | if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) |
| 9285 | wq = phba->sli4_hba.fcp_wq[piocb->hba_wqidx]; |
| 9286 | else |
| 9287 | wq = phba->sli4_hba.oas_wq; |
| 9288 | } else { |
| 9289 | wq = phba->sli4_hba.els_wq; |
| 9290 | } |
| 9291 | |
| 9292 | /* Get corresponding ring */ |
| 9293 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9294 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9295 | /* |
| 9296 | * The WQE can be either 64 or 128 bytes, |
| 9297 | * so allocate space on the stack assuming the largest. |
| 9298 | */ |
| 9299 | wqe = (union lpfc_wqe *)&wqe128; |
| 9300 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9301 | lockdep_assert_held(&phba->hbalock); |
| 9302 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9303 | if (piocb->sli4_xritag == NO_XRI) { |
| 9304 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9305 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9306 | sglq = NULL; |
| 9307 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9308 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9309 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9310 | __lpfc_sli_ringtx_put(phba, |
| 9311 | pring, piocb); |
| 9312 | return IOCB_SUCCESS; |
| 9313 | } else { |
| 9314 | return IOCB_BUSY; |
| 9315 | } |
| 9316 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9317 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9318 | if (!sglq) { |
| 9319 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9320 | __lpfc_sli_ringtx_put(phba, |
| 9321 | pring, |
| 9322 | piocb); |
| 9323 | return IOCB_SUCCESS; |
| 9324 | } else |
| 9325 | return IOCB_BUSY; |
| 9326 | } |
| 9327 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9328 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9329 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9330 | /* These IO's already have an XRI and a mapped sgl. */ |
| 9331 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9332 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9333 | /* |
| 9334 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9335 | * sglq is on the active list |
| 9336 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 9337 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9338 | if (!sglq) |
| 9339 | return IOCB_ERROR; |
| 9340 | } |
| 9341 | |
| 9342 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9343 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9344 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9345 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9346 | return IOCB_ERROR; |
| 9347 | } |
| 9348 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9349 | if (lpfc_sli4_iocb2wqe(phba, piocb, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9350 | return IOCB_ERROR; |
| 9351 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9352 | if (lpfc_sli4_wq_put(wq, wqe)) |
| 9353 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9354 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 9355 | |
| 9356 | return 0; |
| 9357 | } |
| 9358 | |
| 9359 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9360 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 9361 | * |
| 9362 | * This routine wraps the actual lockless version for issusing IOCB function |
| 9363 | * pointer from the lpfc_hba struct. |
| 9364 | * |
| 9365 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9366 | * IOCB_ERROR - Error |
| 9367 | * IOCB_SUCCESS - Success |
| 9368 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9369 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9370 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9371 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 9372 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9373 | { |
| 9374 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9375 | } |
| 9376 | |
| 9377 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9378 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9379 | * @phba: The hba struct for which this call is being executed. |
| 9380 | * @dev_grp: The HBA PCI-Device group number. |
| 9381 | * |
| 9382 | * This routine sets up the SLI interface API function jump table in @phba |
| 9383 | * struct. |
| 9384 | * Returns: 0 - success, -ENODEV - failure. |
| 9385 | **/ |
| 9386 | int |
| 9387 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9388 | { |
| 9389 | |
| 9390 | switch (dev_grp) { |
| 9391 | case LPFC_PCI_DEV_LP: |
| 9392 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 9393 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 9394 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9395 | case LPFC_PCI_DEV_OC: |
| 9396 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 9397 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 9398 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9399 | default: |
| 9400 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9401 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 9402 | dev_grp); |
| 9403 | return -ENODEV; |
| 9404 | break; |
| 9405 | } |
| 9406 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 9407 | return 0; |
| 9408 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9409 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9410 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9411 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9412 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9413 | * @piocb: Pointer to command iocb. |
| 9414 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9415 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 9416 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9417 | * 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] | 9418 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9419 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9420 | struct lpfc_sli_ring * |
| 9421 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9422 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9423 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9424 | if (!(phba->cfg_fof) || |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9425 | (!(piocb->iocb_flag & LPFC_IO_FOF))) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9426 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9427 | return NULL; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9428 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9429 | * for abort iocb hba_wqidx should already |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9430 | * be setup based on what work queue we used. |
| 9431 | */ |
Dick Kennedy | 8e036a9 | 2017-09-29 17:34:35 -0700 | [diff] [blame] | 9432 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9433 | piocb->hba_wqidx = |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9434 | lpfc_sli4_scmd_to_wqidx_distr(phba, |
| 9435 | piocb->context1); |
Dick Kennedy | 8e036a9 | 2017-09-29 17:34:35 -0700 | [diff] [blame] | 9436 | piocb->hba_wqidx = piocb->hba_wqidx % |
| 9437 | phba->cfg_fcp_io_channel; |
| 9438 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9439 | return phba->sli4_hba.fcp_wq[piocb->hba_wqidx]->pring; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9440 | } else { |
| 9441 | if (unlikely(!phba->sli4_hba.oas_wq)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9442 | return NULL; |
| 9443 | piocb->hba_wqidx = 0; |
| 9444 | return phba->sli4_hba.oas_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9445 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9446 | } else { |
| 9447 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 9448 | return NULL; |
| 9449 | piocb->hba_wqidx = 0; |
| 9450 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9451 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9452 | } |
| 9453 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9454 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9455 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9456 | * @phba: Pointer to HBA context object. |
| 9457 | * @pring: Pointer to driver SLI ring object. |
| 9458 | * @piocb: Pointer to command iocb. |
| 9459 | * @flag: Flag indicating if this command can be put into txq. |
| 9460 | * |
| 9461 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 9462 | * function. This function gets the hbalock and calls |
| 9463 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 9464 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 9465 | * functions which do not hold hbalock. |
| 9466 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9467 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9468 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9469 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9470 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9471 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9472 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9473 | struct lpfc_queue *fpeq; |
| 9474 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9475 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9476 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9477 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9478 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9479 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 9480 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9481 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9482 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9483 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9484 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9485 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9486 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9487 | if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9488 | idx = piocb->hba_wqidx; |
| 9489 | hba_eq_hdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9490 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9491 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9492 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9493 | /* Get associated EQ with this index */ |
| 9494 | fpeq = phba->sli4_hba.hba_eq[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9495 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9496 | /* Turn off interrupts from this EQ */ |
| 9497 | lpfc_sli4_eq_clr_intr(fpeq); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9498 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9499 | /* |
| 9500 | * Process all the events on FCP EQ |
| 9501 | */ |
| 9502 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 9503 | lpfc_sli4_hba_handle_eqe(phba, |
| 9504 | eqe, idx); |
| 9505 | fpeq->EQ_processed++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9506 | } |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9507 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9508 | /* Always clear and re-arm the EQ */ |
| 9509 | lpfc_sli4_eq_release(fpeq, |
| 9510 | LPFC_QUEUE_REARM); |
| 9511 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9512 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9513 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9514 | } else { |
| 9515 | /* For now, SLI2/3 will still use hbalock */ |
| 9516 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9517 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9518 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9519 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9520 | return rc; |
| 9521 | } |
| 9522 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9523 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9524 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9525 | * @phba: Pointer to HBA context object. |
| 9526 | * |
| 9527 | * This function is called while driver attaches with the |
| 9528 | * HBA to setup the extra ring. The extra ring is used |
| 9529 | * only when driver needs to support target mode functionality |
| 9530 | * or IP over FC functionalities. |
| 9531 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9532 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9533 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9534 | static int |
| 9535 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 9536 | { |
| 9537 | struct lpfc_sli *psli; |
| 9538 | struct lpfc_sli_ring *pring; |
| 9539 | |
| 9540 | psli = &phba->sli; |
| 9541 | |
| 9542 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9543 | |
| 9544 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9545 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9546 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9547 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9548 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9549 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9550 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9551 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9552 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9553 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9554 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9555 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9556 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9557 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9558 | |
| 9559 | /* Setup default profile for this ring */ |
| 9560 | pring->iotag_max = 4096; |
| 9561 | pring->num_mask = 1; |
| 9562 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9563 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 9564 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9565 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 9566 | return 0; |
| 9567 | } |
| 9568 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9569 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 9570 | * @phba: Pointer to HBA context object. |
| 9571 | * @iocbq: Pointer to iocb object. |
| 9572 | * |
| 9573 | * The async_event handler calls this routine when it receives |
| 9574 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 9575 | * this event when an Abort Sequence request to an rport fails |
| 9576 | * twice in succession. The abort could be originated by the |
| 9577 | * driver or by the port. The ABTS could have been for an ELS |
| 9578 | * or FCP IO. The port only generates this event when an ABTS |
| 9579 | * fails to complete after one retry. |
| 9580 | */ |
| 9581 | static void |
| 9582 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 9583 | struct lpfc_iocbq *iocbq) |
| 9584 | { |
| 9585 | struct lpfc_nodelist *ndlp = NULL; |
| 9586 | uint16_t rpi = 0, vpi = 0; |
| 9587 | struct lpfc_vport *vport = NULL; |
| 9588 | |
| 9589 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 9590 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 9591 | rpi = iocbq->iocb.ulpContext; |
| 9592 | |
| 9593 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9594 | "3092 Port generated ABTS async event " |
| 9595 | "on vpi %d rpi %d status 0x%x\n", |
| 9596 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 9597 | |
| 9598 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 9599 | if (!vport) |
| 9600 | goto err_exit; |
| 9601 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 9602 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 9603 | goto err_exit; |
| 9604 | |
| 9605 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 9606 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9607 | return; |
| 9608 | |
| 9609 | err_exit: |
| 9610 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9611 | "3095 Event Context not found, no " |
| 9612 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 9613 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 9614 | vpi, rpi); |
| 9615 | } |
| 9616 | |
| 9617 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 9618 | * @phba: pointer to HBA context object. |
| 9619 | * @ndlp: nodelist pointer for the impacted rport. |
| 9620 | * @axri: pointer to the wcqe containing the failed exchange. |
| 9621 | * |
| 9622 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 9623 | * port. The port generates this event when an abort exchange request to an |
| 9624 | * rport fails twice in succession with no reply. The abort could be originated |
| 9625 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 9626 | */ |
| 9627 | void |
| 9628 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 9629 | struct lpfc_nodelist *ndlp, |
| 9630 | struct sli4_wcqe_xri_aborted *axri) |
| 9631 | { |
| 9632 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9633 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9634 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9635 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9636 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9637 | "3115 Node Context not found, driver " |
| 9638 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9639 | return; |
| 9640 | } |
| 9641 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9642 | vport = ndlp->vport; |
| 9643 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9644 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9645 | "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] | 9646 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9647 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9648 | bf_get(lpfc_wcqe_xa_status, axri), |
| 9649 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9650 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9651 | /* |
| 9652 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 9653 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 9654 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 9655 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 9656 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9657 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 9658 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9659 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9660 | } |
| 9661 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9662 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9663 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9664 | * @phba: Pointer to HBA context object. |
| 9665 | * @pring: Pointer to driver SLI ring object. |
| 9666 | * @iocbq: Pointer to iocb object. |
| 9667 | * |
| 9668 | * This function is called by the slow ring event handler |
| 9669 | * function when there is an ASYNC event iocb in the ring. |
| 9670 | * This function is called with no lock held. |
| 9671 | * Currently this function handles only temperature related |
| 9672 | * ASYNC events. The function decodes the temperature sensor |
| 9673 | * event message and posts events for the management applications. |
| 9674 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9675 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9676 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 9677 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 9678 | { |
| 9679 | IOCB_t *icmd; |
| 9680 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9681 | struct temp_event temp_event_data; |
| 9682 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9683 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9684 | |
| 9685 | icmd = &iocbq->iocb; |
| 9686 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9687 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9688 | switch (evt_code) { |
| 9689 | case ASYNC_TEMP_WARN: |
| 9690 | case ASYNC_TEMP_SAFE: |
| 9691 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 9692 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 9693 | if (evt_code == ASYNC_TEMP_WARN) { |
| 9694 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 9695 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9696 | "0347 Adapter is very hot, please take " |
| 9697 | "corrective action. temperature : %d Celsius\n", |
| 9698 | (uint32_t) icmd->ulpContext); |
| 9699 | } else { |
| 9700 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 9701 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9702 | "0340 Adapter temperature is OK now. " |
| 9703 | "temperature : %d Celsius\n", |
| 9704 | (uint32_t) icmd->ulpContext); |
| 9705 | } |
| 9706 | |
| 9707 | /* Send temperature change event to applications */ |
| 9708 | shost = lpfc_shost_from_vport(phba->pport); |
| 9709 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 9710 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 9711 | LPFC_NL_VENDOR_ID); |
| 9712 | break; |
| 9713 | case ASYNC_STATUS_CN: |
| 9714 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 9715 | break; |
| 9716 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9717 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9718 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9719 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 9720 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9721 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 9722 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 9723 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 9724 | "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] | 9725 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9726 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 9727 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 9728 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 9729 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 9730 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9731 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9732 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9733 | } |
| 9734 | |
| 9735 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9736 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9737 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9738 | * @phba: Pointer to HBA context object. |
| 9739 | * |
| 9740 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 9741 | * number of iocbs per ring and iotags. This function is |
| 9742 | * called while driver attach to the HBA and before the |
| 9743 | * interrupts are enabled. So there is no need for locking. |
| 9744 | * |
| 9745 | * This function always returns 0. |
| 9746 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9747 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9748 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 9749 | { |
| 9750 | struct lpfc_sli_ring *pring; |
| 9751 | |
| 9752 | pring = phba->sli4_hba.els_wq->pring; |
| 9753 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 9754 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 9755 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9756 | pring->prt[0].type = FC_TYPE_ELS; |
| 9757 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 9758 | lpfc_els_unsol_event; |
| 9759 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 9760 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9761 | pring->prt[1].type = FC_TYPE_ELS; |
| 9762 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 9763 | lpfc_els_unsol_event; |
| 9764 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9765 | /* NameServer Inquiry */ |
| 9766 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 9767 | /* NameServer */ |
| 9768 | pring->prt[2].type = FC_TYPE_CT; |
| 9769 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 9770 | lpfc_ct_unsol_event; |
| 9771 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 9772 | /* NameServer response */ |
| 9773 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 9774 | /* NameServer */ |
| 9775 | pring->prt[3].type = FC_TYPE_CT; |
| 9776 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 9777 | lpfc_ct_unsol_event; |
| 9778 | return 0; |
| 9779 | } |
| 9780 | |
| 9781 | /** |
| 9782 | * lpfc_sli_setup - SLI ring setup function |
| 9783 | * @phba: Pointer to HBA context object. |
| 9784 | * |
| 9785 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 9786 | * number of iocbs per ring and iotags. This function is |
| 9787 | * called while driver attach to the HBA and before the |
| 9788 | * interrupts are enabled. So there is no need for locking. |
| 9789 | * |
| 9790 | * This function always returns 0. SLI3 only. |
| 9791 | **/ |
| 9792 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9793 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 9794 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9795 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9796 | struct lpfc_sli *psli = &phba->sli; |
| 9797 | struct lpfc_sli_ring *pring; |
| 9798 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9799 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9800 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9801 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9802 | psli->iocbq_lookup = NULL; |
| 9803 | psli->iocbq_lookup_len = 0; |
| 9804 | psli->last_iotag = 0; |
| 9805 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9806 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9807 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9808 | switch (i) { |
| 9809 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 9810 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9811 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 9812 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 9813 | pring->sli.sli3.numCiocb += |
| 9814 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9815 | pring->sli.sli3.numRiocb += |
| 9816 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9817 | pring->sli.sli3.numCiocb += |
| 9818 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9819 | pring->sli.sli3.numRiocb += |
| 9820 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 9821 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9822 | SLI3_IOCB_CMD_SIZE : |
| 9823 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9824 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9825 | SLI3_IOCB_RSP_SIZE : |
| 9826 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9827 | pring->iotag_ctr = 0; |
| 9828 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9829 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9830 | pring->fast_iotag = pring->iotag_max; |
| 9831 | pring->num_mask = 0; |
| 9832 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9833 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9834 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9835 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 9836 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 9837 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9838 | SLI3_IOCB_CMD_SIZE : |
| 9839 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9840 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9841 | SLI3_IOCB_RSP_SIZE : |
| 9842 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9843 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9844 | pring->num_mask = 0; |
| 9845 | break; |
| 9846 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 9847 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9848 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 9849 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 9850 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9851 | SLI3_IOCB_CMD_SIZE : |
| 9852 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9853 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9854 | SLI3_IOCB_RSP_SIZE : |
| 9855 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9856 | pring->fast_iotag = 0; |
| 9857 | pring->iotag_ctr = 0; |
| 9858 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9859 | pring->lpfc_sli_rcv_async_status = |
| 9860 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9861 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9862 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9863 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9864 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9865 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9866 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9867 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9868 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9869 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9870 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9871 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9872 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9873 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9874 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9875 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9876 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9877 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9878 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9879 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 9880 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9881 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9882 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9883 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9884 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9885 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9886 | break; |
| 9887 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9888 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 9889 | pring->sli.sli3.sizeCiocb) + |
| 9890 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9891 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9892 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9893 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9894 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 9895 | "SLI2 SLIM Data: x%x x%lx\n", |
| 9896 | phba->brd_no, totiocbsize, |
| 9897 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9898 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9899 | if (phba->cfg_multi_ring_support == 2) |
| 9900 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9901 | |
| 9902 | return 0; |
| 9903 | } |
| 9904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9905 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9906 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9907 | * @phba: Pointer to HBA context object. |
| 9908 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9909 | * 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] | 9910 | * ring. This function also initializes ring indices of each ring. |
| 9911 | * This function is called during the initialization of the SLI |
| 9912 | * interface of an HBA. |
| 9913 | * This function is called with no lock held and always returns |
| 9914 | * 1. |
| 9915 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9916 | void |
| 9917 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 9918 | { |
| 9919 | struct lpfc_sli *psli; |
| 9920 | struct lpfc_sli_ring *pring; |
| 9921 | int i; |
| 9922 | |
| 9923 | psli = &phba->sli; |
| 9924 | spin_lock_irq(&phba->hbalock); |
| 9925 | INIT_LIST_HEAD(&psli->mboxq); |
| 9926 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 9927 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 9928 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
| 9929 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
| 9930 | pring->flag = 0; |
| 9931 | pring->ringno = LPFC_FCP_RING; |
| 9932 | INIT_LIST_HEAD(&pring->txq); |
| 9933 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9934 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9935 | spin_lock_init(&pring->ring_lock); |
| 9936 | } |
| 9937 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 9938 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 9939 | pring->flag = 0; |
| 9940 | pring->ringno = LPFC_FCP_RING; |
| 9941 | INIT_LIST_HEAD(&pring->txq); |
| 9942 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9943 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9944 | spin_lock_init(&pring->ring_lock); |
| 9945 | } |
| 9946 | pring = phba->sli4_hba.els_wq->pring; |
| 9947 | pring->flag = 0; |
| 9948 | pring->ringno = LPFC_ELS_RING; |
| 9949 | INIT_LIST_HEAD(&pring->txq); |
| 9950 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9951 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9952 | spin_lock_init(&pring->ring_lock); |
| 9953 | |
| 9954 | if (phba->cfg_nvme_io_channel) { |
| 9955 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 9956 | pring->flag = 0; |
| 9957 | pring->ringno = LPFC_ELS_RING; |
| 9958 | INIT_LIST_HEAD(&pring->txq); |
| 9959 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9960 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9961 | spin_lock_init(&pring->ring_lock); |
| 9962 | } |
| 9963 | |
| 9964 | if (phba->cfg_fof) { |
| 9965 | pring = phba->sli4_hba.oas_wq->pring; |
| 9966 | pring->flag = 0; |
| 9967 | pring->ringno = LPFC_FCP_RING; |
| 9968 | INIT_LIST_HEAD(&pring->txq); |
| 9969 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9970 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9971 | spin_lock_init(&pring->ring_lock); |
| 9972 | } |
| 9973 | |
| 9974 | spin_unlock_irq(&phba->hbalock); |
| 9975 | } |
| 9976 | |
| 9977 | /** |
| 9978 | * lpfc_sli_queue_init - Queue initialization function |
| 9979 | * @phba: Pointer to HBA context object. |
| 9980 | * |
| 9981 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 9982 | * ring. This function also initializes ring indices of each ring. |
| 9983 | * This function is called during the initialization of the SLI |
| 9984 | * interface of an HBA. |
| 9985 | * This function is called with no lock held and always returns |
| 9986 | * 1. |
| 9987 | **/ |
| 9988 | void |
| 9989 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9990 | { |
| 9991 | struct lpfc_sli *psli; |
| 9992 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9993 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9994 | |
| 9995 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9996 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9997 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9998 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9999 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 10000 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10001 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10002 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10003 | pring->sli.sli3.next_cmdidx = 0; |
| 10004 | pring->sli.sli3.local_getidx = 0; |
| 10005 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10006 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 10007 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10008 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10009 | pring->flag = 0; |
| 10010 | INIT_LIST_HEAD(&pring->txq); |
| 10011 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10012 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10013 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10014 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10015 | } |
| 10016 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10017 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10018 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 10019 | * @phba: Pointer to HBA context object. |
| 10020 | * |
| 10021 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 10022 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 10023 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 10024 | * command; and completed mailbox command queue. It is caller's responsibility |
| 10025 | * to make sure that the driver is in the proper state to flush the mailbox |
| 10026 | * command sub-system. Namely, the posting of mailbox commands into the |
| 10027 | * pending mailbox command queue from the various clients must be stopped; |
| 10028 | * either the HBA is in a state that it will never works on the outstanding |
| 10029 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 10030 | * mailbox command has been completed. |
| 10031 | **/ |
| 10032 | static void |
| 10033 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10034 | { |
| 10035 | LIST_HEAD(completions); |
| 10036 | struct lpfc_sli *psli = &phba->sli; |
| 10037 | LPFC_MBOXQ_t *pmb; |
| 10038 | unsigned long iflag; |
| 10039 | |
| 10040 | /* Flush all the mailbox commands in the mbox system */ |
| 10041 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 10042 | /* The pending mailbox command queue */ |
| 10043 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10044 | /* The outstanding active mailbox command */ |
| 10045 | if (psli->mbox_active) { |
| 10046 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10047 | psli->mbox_active = NULL; |
| 10048 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10049 | } |
| 10050 | /* The completed mailbox command queue */ |
| 10051 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10052 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10053 | |
| 10054 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10055 | while (!list_empty(&completions)) { |
| 10056 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10057 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10058 | if (pmb->mbox_cmpl) |
| 10059 | pmb->mbox_cmpl(phba, pmb); |
| 10060 | } |
| 10061 | } |
| 10062 | |
| 10063 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10064 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10065 | * @vport: Pointer to virtual port object. |
| 10066 | * |
| 10067 | * lpfc_sli_host_down is called to clean up the resources |
| 10068 | * associated with a vport before destroying virtual |
| 10069 | * port data structures. |
| 10070 | * This function does following operations: |
| 10071 | * - Free discovery resources associated with this virtual |
| 10072 | * port. |
| 10073 | * - Free iocbs associated with this virtual port in |
| 10074 | * the txq. |
| 10075 | * - Send abort for all iocb commands associated with this |
| 10076 | * vport in txcmplq. |
| 10077 | * |
| 10078 | * This function is called with no lock held and always returns 1. |
| 10079 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10080 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10081 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10082 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10083 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10084 | struct lpfc_hba *phba = vport->phba; |
| 10085 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10086 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10087 | struct lpfc_sli_ring *pring; |
| 10088 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10089 | int i; |
| 10090 | unsigned long flags = 0; |
| 10091 | uint16_t prev_pring_flag; |
| 10092 | |
| 10093 | lpfc_cleanup_discovery_resources(vport); |
| 10094 | |
| 10095 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10096 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10097 | /* |
| 10098 | * Error everything on the txq since these iocbs |
| 10099 | * have not been given to the FW yet. |
| 10100 | * Also issue ABTS for everything on the txcmplq |
| 10101 | */ |
| 10102 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10103 | for (i = 0; i < psli->num_rings; i++) { |
| 10104 | pring = &psli->sli3_ring[i]; |
| 10105 | prev_pring_flag = pring->flag; |
| 10106 | /* Only slow rings */ |
| 10107 | if (pring->ringno == LPFC_ELS_RING) { |
| 10108 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10109 | /* Set the lpfc data pending flag */ |
| 10110 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10111 | } |
| 10112 | list_for_each_entry_safe(iocb, next_iocb, |
| 10113 | &pring->txq, list) { |
| 10114 | if (iocb->vport != vport) |
| 10115 | continue; |
| 10116 | list_move_tail(&iocb->list, &completions); |
| 10117 | } |
| 10118 | list_for_each_entry_safe(iocb, next_iocb, |
| 10119 | &pring->txcmplq, list) { |
| 10120 | if (iocb->vport != vport) |
| 10121 | continue; |
| 10122 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10123 | } |
| 10124 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10125 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10126 | } else { |
| 10127 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10128 | pring = qp->pring; |
| 10129 | if (!pring) |
| 10130 | continue; |
| 10131 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10132 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10133 | /* Set the lpfc data pending flag */ |
| 10134 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10135 | } |
| 10136 | prev_pring_flag = pring->flag; |
| 10137 | spin_lock_irq(&pring->ring_lock); |
| 10138 | list_for_each_entry_safe(iocb, next_iocb, |
| 10139 | &pring->txq, list) { |
| 10140 | if (iocb->vport != vport) |
| 10141 | continue; |
| 10142 | list_move_tail(&iocb->list, &completions); |
| 10143 | } |
| 10144 | spin_unlock_irq(&pring->ring_lock); |
| 10145 | list_for_each_entry_safe(iocb, next_iocb, |
| 10146 | &pring->txcmplq, list) { |
| 10147 | if (iocb->vport != vport) |
| 10148 | continue; |
| 10149 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10150 | } |
| 10151 | pring->flag = prev_pring_flag; |
| 10152 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10153 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10154 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10155 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10156 | /* Cancel all the IOCBs from the completions list */ |
| 10157 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10158 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10159 | return 1; |
| 10160 | } |
| 10161 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10162 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10163 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10164 | * @phba: Pointer to HBA context object. |
| 10165 | * |
| 10166 | * This function cleans up all iocb, buffers, mailbox commands |
| 10167 | * while shutting down the HBA. This function is called with no |
| 10168 | * lock held and always returns 1. |
| 10169 | * This function does the following to cleanup driver resources: |
| 10170 | * - Free discovery resources for each virtual port |
| 10171 | * - Cleanup any pending fabric iocbs |
| 10172 | * - Iterate through the iocb txq and free each entry |
| 10173 | * in the list. |
| 10174 | * - Free up any buffer posted to the HBA |
| 10175 | * - Free mailbox commands in the mailbox queue. |
| 10176 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10177 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10178 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10179 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10180 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10181 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10182 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10183 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10184 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10185 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10186 | int i; |
| 10187 | |
| 10188 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10189 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10190 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10191 | lpfc_hba_down_prep(phba); |
| 10192 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10193 | lpfc_fabric_abort_hba(phba); |
| 10194 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10195 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10196 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10197 | /* |
| 10198 | * Error everything on the txq since these iocbs |
| 10199 | * have not been given to the FW yet. |
| 10200 | */ |
| 10201 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10202 | for (i = 0; i < psli->num_rings; i++) { |
| 10203 | pring = &psli->sli3_ring[i]; |
| 10204 | /* Only slow rings */ |
| 10205 | if (pring->ringno == LPFC_ELS_RING) { |
| 10206 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10207 | /* Set the lpfc data pending flag */ |
| 10208 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10209 | } |
| 10210 | list_splice_init(&pring->txq, &completions); |
| 10211 | } |
| 10212 | } else { |
| 10213 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10214 | pring = qp->pring; |
| 10215 | if (!pring) |
| 10216 | continue; |
| 10217 | spin_lock_irq(&pring->ring_lock); |
| 10218 | list_splice_init(&pring->txq, &completions); |
| 10219 | spin_unlock_irq(&pring->ring_lock); |
| 10220 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10221 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10222 | /* Set the lpfc data pending flag */ |
| 10223 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10224 | } |
| 10225 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10226 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10227 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10228 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10229 | /* Cancel all the IOCBs from the completions list */ |
| 10230 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10231 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10232 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10233 | spin_lock_irqsave(&phba->hbalock, flags); |
| 10234 | list_splice_init(&phba->elsbuf, &completions); |
| 10235 | phba->elsbuf_cnt = 0; |
| 10236 | phba->elsbuf_prev_cnt = 0; |
| 10237 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10238 | |
| 10239 | while (!list_empty(&completions)) { |
| 10240 | list_remove_head(&completions, buf_ptr, |
| 10241 | struct lpfc_dmabuf, list); |
| 10242 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 10243 | kfree(buf_ptr); |
| 10244 | } |
| 10245 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10246 | /* Return any active mbox cmds */ |
| 10247 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10248 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10249 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10250 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10251 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10252 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10253 | return 1; |
| 10254 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10255 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10256 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10257 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10258 | * @srcp: Source memory pointer. |
| 10259 | * @destp: Destination memory pointer. |
| 10260 | * @cnt: Number of words required to be copied. |
| 10261 | * |
| 10262 | * This function is used for copying data between driver memory |
| 10263 | * and the SLI memory. This function also changes the endianness |
| 10264 | * of each word if native endianness is different from SLI |
| 10265 | * endianness. This function can be called with or without |
| 10266 | * lock. |
| 10267 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10268 | void |
| 10269 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10270 | { |
| 10271 | uint32_t *src = srcp; |
| 10272 | uint32_t *dest = destp; |
| 10273 | uint32_t ldata; |
| 10274 | int i; |
| 10275 | |
| 10276 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 10277 | ldata = *src; |
| 10278 | ldata = le32_to_cpu(ldata); |
| 10279 | *dest = ldata; |
| 10280 | src++; |
| 10281 | dest++; |
| 10282 | } |
| 10283 | } |
| 10284 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10285 | |
| 10286 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 10287 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 10288 | * @srcp: Source memory pointer. |
| 10289 | * @destp: Destination memory pointer. |
| 10290 | * @cnt: Number of words required to be copied. |
| 10291 | * |
| 10292 | * This function is used for copying data between a data structure |
| 10293 | * with big endian representation to local endianness. |
| 10294 | * This function can be called with or without lock. |
| 10295 | **/ |
| 10296 | void |
| 10297 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10298 | { |
| 10299 | uint32_t *src = srcp; |
| 10300 | uint32_t *dest = destp; |
| 10301 | uint32_t ldata; |
| 10302 | int i; |
| 10303 | |
| 10304 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 10305 | ldata = *src; |
| 10306 | ldata = be32_to_cpu(ldata); |
| 10307 | *dest = ldata; |
| 10308 | src++; |
| 10309 | dest++; |
| 10310 | } |
| 10311 | } |
| 10312 | |
| 10313 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10314 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10315 | * @phba: Pointer to HBA context object. |
| 10316 | * @pring: Pointer to driver SLI ring object. |
| 10317 | * @mp: Pointer to driver buffer object. |
| 10318 | * |
| 10319 | * This function is called with no lock held. |
| 10320 | * It always return zero after adding the buffer to the postbufq |
| 10321 | * buffer list. |
| 10322 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10323 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10324 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10325 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10326 | { |
| 10327 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 10328 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10329 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10330 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10331 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10332 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10333 | return 0; |
| 10334 | } |
| 10335 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10336 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10337 | * 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] | 10338 | * @phba: Pointer to HBA context object. |
| 10339 | * |
| 10340 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 10341 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 10342 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 10343 | * does not conflict with tags of buffer posted for unsolicited events. |
| 10344 | * The function returns the allocated tag. The function is called with |
| 10345 | * no locks held. |
| 10346 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10347 | uint32_t |
| 10348 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 10349 | { |
| 10350 | spin_lock_irq(&phba->hbalock); |
| 10351 | phba->buffer_tag_count++; |
| 10352 | /* |
| 10353 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 10354 | * a tag assigned by HBQ. |
| 10355 | */ |
| 10356 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 10357 | spin_unlock_irq(&phba->hbalock); |
| 10358 | return phba->buffer_tag_count; |
| 10359 | } |
| 10360 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10361 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10362 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10363 | * @phba: Pointer to HBA context object. |
| 10364 | * @pring: Pointer to driver SLI ring object. |
| 10365 | * @tag: Buffer tag. |
| 10366 | * |
| 10367 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 10368 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 10369 | * iocb is posted to the response ring with the tag of the buffer. |
| 10370 | * This function searches the pring->postbufq list using the tag |
| 10371 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 10372 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 10373 | * buffer is returned to the caller else NULL is returned. |
| 10374 | * This function is called with no lock held. |
| 10375 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10376 | struct lpfc_dmabuf * |
| 10377 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10378 | uint32_t tag) |
| 10379 | { |
| 10380 | struct lpfc_dmabuf *mp, *next_mp; |
| 10381 | struct list_head *slp = &pring->postbufq; |
| 10382 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10383 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10384 | spin_lock_irq(&phba->hbalock); |
| 10385 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10386 | if (mp->buffer_tag == tag) { |
| 10387 | list_del_init(&mp->list); |
| 10388 | pring->postbufq_cnt--; |
| 10389 | spin_unlock_irq(&phba->hbalock); |
| 10390 | return mp; |
| 10391 | } |
| 10392 | } |
| 10393 | |
| 10394 | spin_unlock_irq(&phba->hbalock); |
| 10395 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10396 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10397 | "ring %d Data x%lx x%p x%p x%x\n", |
| 10398 | pring->ringno, (unsigned long) tag, |
| 10399 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10400 | |
| 10401 | return NULL; |
| 10402 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10403 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10404 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10405 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10406 | * @phba: Pointer to HBA context object. |
| 10407 | * @pring: Pointer to driver SLI ring object. |
| 10408 | * @phys: DMA address of the buffer. |
| 10409 | * |
| 10410 | * This function searches the buffer list using the dma_address |
| 10411 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 10412 | * corresponding to the dma_address. The function returns the |
| 10413 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 10414 | * This function is called by the ct and els unsolicited event |
| 10415 | * handlers to get the buffer associated with the unsolicited |
| 10416 | * event. |
| 10417 | * |
| 10418 | * This function is called with no lock held. |
| 10419 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10420 | struct lpfc_dmabuf * |
| 10421 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10422 | dma_addr_t phys) |
| 10423 | { |
| 10424 | struct lpfc_dmabuf *mp, *next_mp; |
| 10425 | struct list_head *slp = &pring->postbufq; |
| 10426 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10427 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10428 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10429 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10430 | if (mp->phys == phys) { |
| 10431 | list_del_init(&mp->list); |
| 10432 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10433 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10434 | return mp; |
| 10435 | } |
| 10436 | } |
| 10437 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10438 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10439 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10440 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10441 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10442 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10443 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10444 | return NULL; |
| 10445 | } |
| 10446 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10447 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10448 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10449 | * @phba: Pointer to HBA context object. |
| 10450 | * @cmdiocb: Pointer to driver command iocb object. |
| 10451 | * @rspiocb: Pointer to driver response iocb object. |
| 10452 | * |
| 10453 | * This function is the completion handler for the abort iocbs for |
| 10454 | * ELS commands. This function is called from the ELS ring event |
| 10455 | * handler with no lock held. This function frees memory resources |
| 10456 | * associated with the abort iocb. |
| 10457 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10458 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10459 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10460 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10461 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10462 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10463 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10464 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10465 | |
| 10466 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10467 | |
| 10468 | /* |
| 10469 | * Assume that the port already completed and returned, or |
| 10470 | * will return the iocb. Just Log the message. |
| 10471 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10472 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 10473 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 10474 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10475 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10476 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 10477 | if (abort_iotag != 0 && |
| 10478 | abort_iotag <= phba->sli.last_iotag) |
| 10479 | abort_iocb = |
| 10480 | phba->sli.iocbq_lookup[abort_iotag]; |
| 10481 | } else |
| 10482 | /* For sli4 the abort_tag is the XRI, |
| 10483 | * so the abort routine puts the iotag of the iocb |
| 10484 | * being aborted in the context field of the abort |
| 10485 | * IOCB. |
| 10486 | */ |
| 10487 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10488 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10489 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 10490 | "0327 Cannot abort els iocb %p " |
| 10491 | "with tag %x context %x, abort status %x, " |
| 10492 | "abort code %x\n", |
| 10493 | abort_iocb, abort_iotag, abort_context, |
| 10494 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10495 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10496 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10497 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10498 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10499 | return; |
| 10500 | } |
| 10501 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10502 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10503 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10504 | * @phba: Pointer to HBA context object. |
| 10505 | * @cmdiocb: Pointer to driver command iocb object. |
| 10506 | * @rspiocb: Pointer to driver response iocb object. |
| 10507 | * |
| 10508 | * The function is called from SLI ring event handler with no |
| 10509 | * lock held. This function is the completion handler for ELS commands |
| 10510 | * which are aborted. The function frees memory resources used for |
| 10511 | * the aborted ELS commands. |
| 10512 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10513 | static void |
| 10514 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10515 | struct lpfc_iocbq *rspiocb) |
| 10516 | { |
| 10517 | IOCB_t *irsp = &rspiocb->iocb; |
| 10518 | |
| 10519 | /* ELS cmd tag <ulpIoTag> completes */ |
| 10520 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10521 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10522 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10523 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10524 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10525 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 10526 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 10527 | else |
| 10528 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10529 | return; |
| 10530 | } |
| 10531 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10532 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10533 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10534 | * @phba: Pointer to HBA context object. |
| 10535 | * @pring: Pointer to driver SLI ring object. |
| 10536 | * @cmdiocb: Pointer to driver command iocb object. |
| 10537 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10538 | * This function issues an abort iocb for the provided command iocb down to |
| 10539 | * the port. Other than the case the outstanding command iocb is an abort |
| 10540 | * request, this function issues abort out unconditionally. This function is |
| 10541 | * called with hbalock held. The function returns 0 when it fails due to |
| 10542 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10543 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10544 | static int |
| 10545 | 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] | 10546 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10547 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10548 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10549 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10550 | IOCB_t *icmd = NULL; |
| 10551 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10552 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10553 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10554 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10555 | lockdep_assert_held(&phba->hbalock); |
| 10556 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10557 | /* |
| 10558 | * There are certain command types we don't want to abort. And we |
| 10559 | * don't want to abort commands that are already in the process of |
| 10560 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10561 | */ |
| 10562 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10563 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10564 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 10565 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10566 | return 0; |
| 10567 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10568 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10569 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10570 | if (abtsiocbp == NULL) |
| 10571 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10572 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10573 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10574 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10575 | */ |
| 10576 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10577 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10578 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10579 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10580 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10581 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10582 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10583 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 10584 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10585 | else |
| 10586 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10587 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10588 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10589 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10590 | /* 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] | 10591 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10592 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 10593 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10594 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 10595 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10596 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10597 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10598 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 10599 | else |
| 10600 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 10601 | |
| 10602 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 10603 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 10604 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10605 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 10606 | "0339 Abort xri x%x, original iotag x%x, " |
| 10607 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10608 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10609 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10610 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10611 | |
| 10612 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10613 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 10614 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10615 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10616 | /* Note: both hbalock and ring_lock need to be set here */ |
| 10617 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10618 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10619 | abtsiocbp, 0); |
| 10620 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 10621 | } else { |
| 10622 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10623 | abtsiocbp, 0); |
| 10624 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10625 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10626 | if (retval) |
| 10627 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10628 | |
| 10629 | /* |
| 10630 | * Caller to this routine should check for IOCB_ERROR |
| 10631 | * and handle it properly. This routine no longer removes |
| 10632 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 10633 | */ |
| 10634 | return retval; |
| 10635 | } |
| 10636 | |
| 10637 | /** |
| 10638 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 10639 | * @phba: Pointer to HBA context object. |
| 10640 | * @pring: Pointer to driver SLI ring object. |
| 10641 | * @cmdiocb: Pointer to driver command iocb object. |
| 10642 | * |
| 10643 | * This function issues an abort iocb for the provided command iocb. In case |
| 10644 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 10645 | * ring. Instead, the callback function shall be changed to those commands |
| 10646 | * so that nothing happens when them finishes. This function is called with |
| 10647 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 10648 | * request. |
| 10649 | **/ |
| 10650 | int |
| 10651 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10652 | struct lpfc_iocbq *cmdiocb) |
| 10653 | { |
| 10654 | struct lpfc_vport *vport = cmdiocb->vport; |
| 10655 | int retval = IOCB_ERROR; |
| 10656 | IOCB_t *icmd = NULL; |
| 10657 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10658 | lockdep_assert_held(&phba->hbalock); |
| 10659 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10660 | /* |
| 10661 | * There are certain command types we don't want to abort. And we |
| 10662 | * don't want to abort commands that are already in the process of |
| 10663 | * being aborted. |
| 10664 | */ |
| 10665 | icmd = &cmdiocb->iocb; |
| 10666 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 10667 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 10668 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 10669 | return 0; |
| 10670 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 10671 | if (!pring) { |
| 10672 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 10673 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10674 | else |
| 10675 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10676 | goto abort_iotag_exit; |
| 10677 | } |
| 10678 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10679 | /* |
| 10680 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 10681 | * the callback so that nothing happens when it finishes. |
| 10682 | */ |
| 10683 | if ((vport->load_flag & FC_UNLOADING) && |
| 10684 | (pring->ringno == LPFC_ELS_RING)) { |
| 10685 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 10686 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10687 | else |
| 10688 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10689 | goto abort_iotag_exit; |
| 10690 | } |
| 10691 | |
| 10692 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 10693 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 10694 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10695 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10696 | /* |
| 10697 | * Caller to this routine should check for IOCB_ERROR |
| 10698 | * and handle it properly. This routine no longer removes |
| 10699 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10700 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10701 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10702 | } |
| 10703 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10704 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10705 | * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb |
| 10706 | * @phba: Pointer to HBA context object. |
| 10707 | * @pring: Pointer to driver SLI ring object. |
| 10708 | * @cmdiocb: Pointer to driver command iocb object. |
| 10709 | * |
| 10710 | * This function issues an abort iocb for the provided command iocb down to |
| 10711 | * the port. Other than the case the outstanding command iocb is an abort |
| 10712 | * request, this function issues abort out unconditionally. This function is |
| 10713 | * called with hbalock held. The function returns 0 when it fails due to |
| 10714 | * memory allocation failure or when the command iocb is an abort request. |
| 10715 | **/ |
| 10716 | static int |
| 10717 | lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10718 | struct lpfc_iocbq *cmdiocb) |
| 10719 | { |
| 10720 | struct lpfc_vport *vport = cmdiocb->vport; |
| 10721 | struct lpfc_iocbq *abtsiocbp; |
| 10722 | union lpfc_wqe *abts_wqe; |
| 10723 | int retval; |
| 10724 | |
| 10725 | /* |
| 10726 | * There are certain command types we don't want to abort. And we |
| 10727 | * don't want to abort commands that are already in the process of |
| 10728 | * being aborted. |
| 10729 | */ |
| 10730 | if (cmdiocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 10731 | cmdiocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN || |
| 10732 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 10733 | return 0; |
| 10734 | |
| 10735 | /* issue ABTS for this io based on iotag */ |
| 10736 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| 10737 | if (abtsiocbp == NULL) |
| 10738 | return 0; |
| 10739 | |
| 10740 | /* This signals the response to set the correct status |
| 10741 | * before calling the completion handler |
| 10742 | */ |
| 10743 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10744 | |
| 10745 | /* Complete prepping the abort wqe and issue to the FW. */ |
| 10746 | abts_wqe = &abtsiocbp->wqe; |
| 10747 | bf_set(abort_cmd_ia, &abts_wqe->abort_cmd, 0); |
| 10748 | bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); |
| 10749 | |
| 10750 | /* Explicitly set reserved fields to zero.*/ |
| 10751 | abts_wqe->abort_cmd.rsrvd4 = 0; |
| 10752 | abts_wqe->abort_cmd.rsrvd5 = 0; |
| 10753 | |
| 10754 | /* WQE Common - word 6. Context is XRI tag. Set 0. */ |
| 10755 | bf_set(wqe_xri_tag, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10756 | bf_set(wqe_ctxt_tag, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10757 | |
| 10758 | /* word 7 */ |
| 10759 | bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10760 | bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 10761 | bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com, |
| 10762 | cmdiocb->iocb.ulpClass); |
| 10763 | |
| 10764 | /* word 8 - tell the FW to abort the IO associated with this |
| 10765 | * outstanding exchange ID. |
| 10766 | */ |
| 10767 | abts_wqe->abort_cmd.wqe_com.abort_tag = cmdiocb->sli4_xritag; |
| 10768 | |
| 10769 | /* word 9 - this is the iotag for the abts_wqe completion. */ |
| 10770 | bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, |
| 10771 | abtsiocbp->iotag); |
| 10772 | |
| 10773 | /* word 10 */ |
| 10774 | bf_set(wqe_wqid, &abts_wqe->abort_cmd.wqe_com, cmdiocb->hba_wqidx); |
| 10775 | bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); |
| 10776 | bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 10777 | |
| 10778 | /* word 11 */ |
| 10779 | bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); |
| 10780 | bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); |
| 10781 | bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
| 10782 | |
| 10783 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 10784 | abtsiocbp->iocb_flag |= LPFC_IO_NVME; |
| 10785 | abtsiocbp->vport = vport; |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 10786 | abtsiocbp->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10787 | retval = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abtsiocbp); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 10788 | if (retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10789 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 10790 | "6147 Failed abts issue_wqe with status x%x " |
| 10791 | "for oxid x%x\n", |
| 10792 | retval, cmdiocb->sli4_xritag); |
| 10793 | lpfc_sli_release_iocbq(phba, abtsiocbp); |
| 10794 | return retval; |
| 10795 | } |
| 10796 | |
| 10797 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 10798 | "6148 Drv Abort NVME Request Issued for " |
| 10799 | "ox_id x%x on reqtag x%x\n", |
| 10800 | cmdiocb->sli4_xritag, |
| 10801 | abtsiocbp->iotag); |
| 10802 | |
| 10803 | return retval; |
| 10804 | } |
| 10805 | |
| 10806 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10807 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 10808 | * @phba: pointer to lpfc HBA data structure. |
| 10809 | * |
| 10810 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 10811 | **/ |
| 10812 | void |
| 10813 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 10814 | { |
| 10815 | struct lpfc_sli *psli = &phba->sli; |
| 10816 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10817 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10818 | int i; |
| 10819 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10820 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10821 | for (i = 0; i < psli->num_rings; i++) { |
| 10822 | pring = &psli->sli3_ring[i]; |
| 10823 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 10824 | } |
| 10825 | return; |
| 10826 | } |
| 10827 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10828 | pring = qp->pring; |
| 10829 | if (!pring) |
| 10830 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 10831 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10832 | } |
| 10833 | } |
| 10834 | |
| 10835 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10836 | * 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] | 10837 | * @iocbq: Pointer to driver iocb object. |
| 10838 | * @vport: Pointer to driver virtual port object. |
| 10839 | * @tgt_id: SCSI ID of the target. |
| 10840 | * @lun_id: LUN ID of the scsi device. |
| 10841 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 10842 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10843 | * 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] | 10844 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 10845 | * 0 if the filtering criteria is met for the given iocb and will return |
| 10846 | * 1 if the filtering criteria is not met. |
| 10847 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 10848 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 10849 | * lun_id parameter. |
| 10850 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 10851 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 10852 | * parameters. |
| 10853 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 10854 | * given iocb is for the SCSI host associated with the given vport. |
| 10855 | * This function is called with no locks held. |
| 10856 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10857 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10858 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 10859 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10860 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10861 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10862 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10863 | int rc = 1; |
| 10864 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10865 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 10866 | return rc; |
| 10867 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10868 | if (iocbq->vport != vport) |
| 10869 | return rc; |
| 10870 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10871 | 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] | 10872 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10873 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10874 | return rc; |
| 10875 | |
| 10876 | switch (ctx_cmd) { |
| 10877 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10878 | if ((lpfc_cmd->rdata->pnode) && |
| 10879 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 10880 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10881 | rc = 0; |
| 10882 | break; |
| 10883 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10884 | if ((lpfc_cmd->rdata->pnode) && |
| 10885 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10886 | rc = 0; |
| 10887 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10888 | case LPFC_CTX_HOST: |
| 10889 | rc = 0; |
| 10890 | break; |
| 10891 | default: |
| 10892 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 10893 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10894 | break; |
| 10895 | } |
| 10896 | |
| 10897 | return rc; |
| 10898 | } |
| 10899 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10900 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10901 | * 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] | 10902 | * @vport: Pointer to virtual port. |
| 10903 | * @tgt_id: SCSI ID of the target. |
| 10904 | * @lun_id: LUN ID of the scsi device. |
| 10905 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10906 | * |
| 10907 | * This function returns number of FCP commands pending for the vport. |
| 10908 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 10909 | * commands pending on the vport associated with SCSI device specified |
| 10910 | * by tgt_id and lun_id parameters. |
| 10911 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 10912 | * commands pending on the vport associated with SCSI target specified |
| 10913 | * by tgt_id parameter. |
| 10914 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 10915 | * commands pending on the vport. |
| 10916 | * This function returns the number of iocbs which satisfy the filter. |
| 10917 | * This function is called without any lock held. |
| 10918 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10919 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10920 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 10921 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10922 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10923 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10924 | struct lpfc_iocbq *iocbq; |
| 10925 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10926 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 10927 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10928 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 10929 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10930 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10931 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 10932 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10933 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10934 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 10935 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10936 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10937 | return sum; |
| 10938 | } |
| 10939 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10940 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10941 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10942 | * @phba: Pointer to HBA context object |
| 10943 | * @cmdiocb: Pointer to command iocb object. |
| 10944 | * @rspiocb: Pointer to response iocb object. |
| 10945 | * |
| 10946 | * This function is called when an aborted FCP iocb completes. This |
| 10947 | * function is called by the ring event handler with no lock held. |
| 10948 | * This function frees the iocb. |
| 10949 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10950 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10951 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10952 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10953 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10954 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 10955 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10956 | "original iotag x%x, abort cmd iotag x%x " |
| 10957 | "status 0x%x, reason 0x%x\n", |
| 10958 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 10959 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 10960 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 10961 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10962 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10963 | return; |
| 10964 | } |
| 10965 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10966 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10967 | * 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] | 10968 | * @vport: Pointer to virtual port. |
| 10969 | * @pring: Pointer to driver SLI ring object. |
| 10970 | * @tgt_id: SCSI ID of the target. |
| 10971 | * @lun_id: LUN ID of the scsi device. |
| 10972 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10973 | * |
| 10974 | * This function sends an abort command for every SCSI command |
| 10975 | * associated with the given virtual port pending on the ring |
| 10976 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 10977 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 10978 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 10979 | * parameters |
| 10980 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 10981 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 10982 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 10983 | * FCP iocbs associated with virtual port. |
| 10984 | * This function returns number of iocbs it failed to abort. |
| 10985 | * This function is called with no locks held. |
| 10986 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10987 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10988 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 10989 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10990 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10991 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10992 | struct lpfc_iocbq *iocbq; |
| 10993 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 10994 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10995 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10996 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10997 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10998 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10999 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11000 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11001 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11002 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11003 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11004 | continue; |
| 11005 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11006 | /* |
| 11007 | * If the iocbq is already being aborted, don't take a second |
| 11008 | * action, but do count it. |
| 11009 | */ |
| 11010 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11011 | continue; |
| 11012 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11013 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11014 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11015 | if (abtsiocb == NULL) { |
| 11016 | errcnt++; |
| 11017 | continue; |
| 11018 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11019 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11020 | /* indicate the IO is being aborted by the driver. */ |
| 11021 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11022 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 11023 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11024 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11025 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11026 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11027 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 11028 | else |
| 11029 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11030 | abtsiocb->iocb.ulpLe = 1; |
| 11031 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 11032 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11033 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11034 | /* 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] | 11035 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11036 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11037 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11038 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11039 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11040 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11041 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11042 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11043 | else |
| 11044 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11045 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11046 | /* Setup callback routine and issue the command. */ |
| 11047 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11048 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11049 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11050 | if (!pring_s4) |
| 11051 | continue; |
| 11052 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11053 | abtsiocb, 0); |
| 11054 | } else |
| 11055 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11056 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11057 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11058 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11059 | errcnt++; |
| 11060 | continue; |
| 11061 | } |
| 11062 | } |
| 11063 | |
| 11064 | return errcnt; |
| 11065 | } |
| 11066 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11067 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11068 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11069 | * @vport: Pointer to virtual port. |
| 11070 | * @pring: Pointer to driver SLI ring object. |
| 11071 | * @tgt_id: SCSI ID of the target. |
| 11072 | * @lun_id: LUN ID of the scsi device. |
| 11073 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11074 | * |
| 11075 | * This function sends an abort command for every SCSI command |
| 11076 | * associated with the given virtual port pending on the ring |
| 11077 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11078 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11079 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11080 | * parameters |
| 11081 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11082 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11083 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11084 | * FCP iocbs associated with virtual port. |
| 11085 | * This function returns number of iocbs it aborted . |
| 11086 | * This function is called with no locks held right after a taskmgmt |
| 11087 | * command is sent. |
| 11088 | **/ |
| 11089 | int |
| 11090 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11091 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11092 | { |
| 11093 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11094 | struct lpfc_scsi_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11095 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11096 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11097 | struct lpfc_iocbq *iocbq; |
| 11098 | IOCB_t *icmd; |
| 11099 | int sum, i, ret_val; |
| 11100 | unsigned long iflags; |
| 11101 | struct lpfc_sli_ring *pring_s4; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11102 | |
| 11103 | spin_lock_irq(&phba->hbalock); |
| 11104 | |
| 11105 | /* all I/Os are in process of being flushed */ |
| 11106 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
| 11107 | spin_unlock_irq(&phba->hbalock); |
| 11108 | return 0; |
| 11109 | } |
| 11110 | sum = 0; |
| 11111 | |
| 11112 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11113 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11114 | |
| 11115 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11116 | cmd) != 0) |
| 11117 | continue; |
| 11118 | |
| 11119 | /* |
| 11120 | * If the iocbq is already being aborted, don't take a second |
| 11121 | * action, but do count it. |
| 11122 | */ |
| 11123 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11124 | continue; |
| 11125 | |
| 11126 | /* issue ABTS for this IOCB based on iotag */ |
| 11127 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
| 11128 | if (abtsiocbq == NULL) |
| 11129 | continue; |
| 11130 | |
| 11131 | icmd = &iocbq->iocb; |
| 11132 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11133 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11134 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11135 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11136 | iocbq->sli4_xritag; |
| 11137 | else |
| 11138 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11139 | abtsiocbq->iocb.ulpLe = 1; |
| 11140 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11141 | abtsiocbq->vport = vport; |
| 11142 | |
| 11143 | /* 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] | 11144 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11145 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11146 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11147 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11148 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11149 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11150 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 11151 | ndlp = lpfc_cmd->rdata->pnode; |
| 11152 | |
| 11153 | if (lpfc_is_link_up(phba) && |
| 11154 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11155 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11156 | else |
| 11157 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11158 | |
| 11159 | /* Setup callback routine and issue the command. */ |
| 11160 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11161 | |
| 11162 | /* |
| 11163 | * Indicate the IO is being aborted by the driver and set |
| 11164 | * the caller's flag into the aborted IO. |
| 11165 | */ |
| 11166 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11167 | |
| 11168 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11169 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11170 | if (pring_s4 == NULL) |
| 11171 | continue; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11172 | /* Note: both hbalock and ring_lock must be set here */ |
| 11173 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); |
| 11174 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11175 | abtsiocbq, 0); |
| 11176 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); |
| 11177 | } else { |
| 11178 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11179 | abtsiocbq, 0); |
| 11180 | } |
| 11181 | |
| 11182 | |
| 11183 | if (ret_val == IOCB_ERROR) |
| 11184 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11185 | else |
| 11186 | sum++; |
| 11187 | } |
| 11188 | spin_unlock_irq(&phba->hbalock); |
| 11189 | return sum; |
| 11190 | } |
| 11191 | |
| 11192 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11193 | * 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] | 11194 | * @phba: Pointer to HBA context object. |
| 11195 | * @cmdiocbq: Pointer to command iocb. |
| 11196 | * @rspiocbq: Pointer to response iocb. |
| 11197 | * |
| 11198 | * This function is the completion handler for iocbs issued using |
| 11199 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11200 | * ring event handler function without any lock held. This function |
| 11201 | * can be called from both worker thread context and interrupt |
| 11202 | * context. This function also can be called from other thread which |
| 11203 | * cleans up the SLI layer objects. |
| 11204 | * This function copy the contents of the response iocb to the |
| 11205 | * response iocb memory object provided by the caller of |
| 11206 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11207 | * sleeps for the iocb completion. |
| 11208 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11209 | static void |
| 11210 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11211 | struct lpfc_iocbq *cmdiocbq, |
| 11212 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11213 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11214 | wait_queue_head_t *pdone_q; |
| 11215 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11216 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11217 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11218 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11219 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11220 | |
| 11221 | /* |
| 11222 | * A time out has occurred for the iocb. If a time out |
| 11223 | * completion handler has been supplied, call it. Otherwise, |
| 11224 | * just free the iocbq. |
| 11225 | */ |
| 11226 | |
| 11227 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11228 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11229 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11230 | if (cmdiocbq->iocb_cmpl) |
| 11231 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11232 | else |
| 11233 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11234 | return; |
| 11235 | } |
| 11236 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11237 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11238 | if (cmdiocbq->context2 && rspiocbq) |
| 11239 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11240 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11241 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11242 | /* Set the exchange busy flag for task management commands */ |
| 11243 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11244 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 11245 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 11246 | cur_iocbq); |
| 11247 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 11248 | } |
| 11249 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11250 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11251 | if (pdone_q) |
| 11252 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11253 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11254 | return; |
| 11255 | } |
| 11256 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11257 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11258 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 11259 | * @phba: Pointer to HBA context object.. |
| 11260 | * @piocbq: Pointer to command iocb. |
| 11261 | * @flag: Flag to test. |
| 11262 | * |
| 11263 | * This routine grabs the hbalock and then test the iocb_flag to |
| 11264 | * see if the passed in flag is set. |
| 11265 | * Returns: |
| 11266 | * 1 if flag is set. |
| 11267 | * 0 if flag is not set. |
| 11268 | **/ |
| 11269 | static int |
| 11270 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 11271 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 11272 | { |
| 11273 | unsigned long iflags; |
| 11274 | int ret; |
| 11275 | |
| 11276 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11277 | ret = piocbq->iocb_flag & flag; |
| 11278 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11279 | return ret; |
| 11280 | |
| 11281 | } |
| 11282 | |
| 11283 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11284 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11285 | * @phba: Pointer to HBA context object.. |
| 11286 | * @pring: Pointer to sli ring. |
| 11287 | * @piocb: Pointer to command iocb. |
| 11288 | * @prspiocbq: Pointer to response iocb. |
| 11289 | * @timeout: Timeout in number of seconds. |
| 11290 | * |
| 11291 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11292 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 11293 | * to handle iocbs which time out. If the field is NULL, the |
| 11294 | * function shall free the iocbq structure. If more clean up is |
| 11295 | * needed, the caller is expected to provide a completion function |
| 11296 | * that will provide the needed clean up. If the iocb command is |
| 11297 | * not completed within timeout seconds, the function will either |
| 11298 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 11299 | * completion function set in the iocb_cmpl field and then return |
| 11300 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 11301 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11302 | * The function waits for the iocb completion using an |
| 11303 | * non-interruptible wait. |
| 11304 | * This function will sleep while waiting for iocb completion. |
| 11305 | * So, this function should not be called from any context which |
| 11306 | * does not allow sleeping. Due to the same reason, this function |
| 11307 | * cannot be called with interrupt disabled. |
| 11308 | * This function assumes that the iocb completions occur while |
| 11309 | * this function sleep. So, this function cannot be called from |
| 11310 | * the thread which process iocb completion for this ring. |
| 11311 | * This function clears the iocb_flag of the iocb object before |
| 11312 | * issuing the iocb and the iocb completion handler sets this |
| 11313 | * flag and wakes this thread when the iocb completes. |
| 11314 | * The contents of the response iocb will be copied to prspiocbq |
| 11315 | * by the completion handler when the command completes. |
| 11316 | * This function returns IOCB_SUCCESS when success. |
| 11317 | * This function is called with no lock held. |
| 11318 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11319 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11320 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11321 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11322 | struct lpfc_iocbq *piocb, |
| 11323 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11324 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11325 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11326 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11327 | long timeleft, timeout_req = 0; |
| 11328 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11329 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11330 | struct lpfc_iocbq *iocb; |
| 11331 | int txq_cnt = 0; |
| 11332 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11333 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11334 | unsigned long iflags; |
| 11335 | bool iocb_completed = true; |
| 11336 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11337 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 11338 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 11339 | else |
| 11340 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11341 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11342 | * If the caller has provided a response iocbq buffer, then context2 |
| 11343 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11344 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11345 | if (prspiocbq) { |
| 11346 | if (piocb->context2) |
| 11347 | return IOCB_ERROR; |
| 11348 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11349 | } |
| 11350 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11351 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11352 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 11353 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11354 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11355 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11356 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11357 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11358 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11359 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 11360 | writel(creg_val, phba->HCregaddr); |
| 11361 | readl(phba->HCregaddr); /* flush */ |
| 11362 | } |
| 11363 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11364 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 11365 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11366 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11367 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11368 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11369 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11370 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11371 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11372 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11373 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11374 | /* |
| 11375 | * IOCB timed out. Inform the wake iocb wait |
| 11376 | * completion function and set local status |
| 11377 | */ |
| 11378 | |
| 11379 | iocb_completed = false; |
| 11380 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 11381 | } |
| 11382 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11383 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11384 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11385 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 11386 | /* Note: we are not indicating if the IOCB has a success |
| 11387 | * status or not - that's for the caller to check. |
| 11388 | * IOCB_SUCCESS means just that the command was sent and |
| 11389 | * completed. Not that it completed successfully. |
| 11390 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11391 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11392 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11393 | "0338 IOCB wait timeout error - no " |
| 11394 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11395 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11396 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11397 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11398 | "0330 IOCB wake NOT set, " |
| 11399 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11400 | timeout, (timeleft / jiffies)); |
| 11401 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11402 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11403 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11404 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 11405 | list_for_each_entry(iocb, &pring->txq, list) { |
| 11406 | txq_cnt++; |
| 11407 | } |
| 11408 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 11409 | txcmplq_cnt++; |
| 11410 | } |
| 11411 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11412 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 11413 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 11414 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11415 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11416 | } else { |
| 11417 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11418 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11419 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11420 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11421 | } |
| 11422 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11423 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11424 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11425 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11426 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 11427 | writel(creg_val, phba->HCregaddr); |
| 11428 | readl(phba->HCregaddr); /* flush */ |
| 11429 | } |
| 11430 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11431 | if (prspiocbq) |
| 11432 | piocb->context2 = NULL; |
| 11433 | |
| 11434 | piocb->context_un.wait_queue = NULL; |
| 11435 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11436 | return retval; |
| 11437 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11438 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11439 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11440 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11441 | * @phba: Pointer to HBA context object. |
| 11442 | * @pmboxq: Pointer to driver mailbox object. |
| 11443 | * @timeout: Timeout in number of seconds. |
| 11444 | * |
| 11445 | * This function issues the mailbox to firmware and waits for the |
| 11446 | * mailbox command to complete. If the mailbox command is not |
| 11447 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 11448 | * The function waits for the mailbox completion using an |
| 11449 | * interruptible wait. If the thread is woken up due to a |
| 11450 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 11451 | * should not free the mailbox resources, if this function returns |
| 11452 | * MBX_TIMEOUT. |
| 11453 | * This function will sleep while waiting for mailbox completion. |
| 11454 | * So, this function should not be called from any context which |
| 11455 | * does not allow sleeping. Due to the same reason, this function |
| 11456 | * cannot be called with interrupt disabled. |
| 11457 | * This function assumes that the mailbox completion occurs while |
| 11458 | * this function sleep. So, this function cannot be called from |
| 11459 | * the worker thread which processes mailbox completion. |
| 11460 | * This function is called in the context of HBA management |
| 11461 | * applications. |
| 11462 | * This function returns MBX_SUCCESS when successful. |
| 11463 | * This function is called with no lock held. |
| 11464 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11465 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11466 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11467 | uint32_t timeout) |
| 11468 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11469 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11470 | MAILBOX_t *mb = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11471 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11472 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11473 | |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11474 | /* The caller might set context1 for extended buffer */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 11475 | if (pmboxq->context1) |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11476 | mb = (MAILBOX_t *)pmboxq->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11477 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11478 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11479 | /* setup wake call as IOCB callback */ |
| 11480 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 11481 | /* setup context field to pass wait_queue pointer to wake function */ |
| 11482 | pmboxq->context1 = &done_q; |
| 11483 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11484 | /* now issue the command */ |
| 11485 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11486 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11487 | wait_event_interruptible_timeout(done_q, |
| 11488 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11489 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11490 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11491 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11492 | /* restore the possible extended buffer for free resource */ |
| 11493 | pmboxq->context1 = (uint8_t *)mb; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11494 | /* |
| 11495 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 11496 | * else do not free the resources. |
| 11497 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 11498 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11499 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 11500 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11501 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11502 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 11503 | } |
| 11504 | spin_unlock_irqrestore(&phba->hbalock, flag); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11505 | } else { |
| 11506 | /* restore the possible extended buffer for free resource */ |
| 11507 | pmboxq->context1 = (uint8_t *)mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11508 | } |
| 11509 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11510 | return retval; |
| 11511 | } |
| 11512 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11513 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11514 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11515 | * @phba: Pointer to HBA context. |
| 11516 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11517 | * This function is called to shutdown the driver's mailbox sub-system. |
| 11518 | * It first marks the mailbox sub-system is in a block state to prevent |
| 11519 | * the asynchronous mailbox command from issued off the pending mailbox |
| 11520 | * command queue. If the mailbox command sub-system shutdown is due to |
| 11521 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 11522 | * the mailbox sub-system flush routine to forcefully bring down the |
| 11523 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 11524 | * as with offline or HBA function reset), this routine will wait for the |
| 11525 | * outstanding mailbox command to complete before invoking the mailbox |
| 11526 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11527 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11528 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11529 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11530 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11531 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11532 | unsigned long timeout; |
| 11533 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11534 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 11535 | /* delay 100ms for port state */ |
| 11536 | msleep(100); |
| 11537 | lpfc_sli_mbox_sys_flush(phba); |
| 11538 | return; |
| 11539 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11540 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 11541 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11542 | spin_lock_irq(&phba->hbalock); |
| 11543 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11544 | |
| 11545 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11546 | /* Determine how long we might wait for the active mailbox |
| 11547 | * command to be gracefully completed by firmware. |
| 11548 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11549 | if (phba->sli.mbox_active) |
| 11550 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 11551 | phba->sli.mbox_active) * |
| 11552 | 1000) + jiffies; |
| 11553 | spin_unlock_irq(&phba->hbalock); |
| 11554 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11555 | while (phba->sli.mbox_active) { |
| 11556 | /* Check active mailbox complete status every 2ms */ |
| 11557 | msleep(2); |
| 11558 | if (time_after(jiffies, timeout)) |
| 11559 | /* Timeout, let the mailbox flush routine to |
| 11560 | * forcefully release active mailbox command |
| 11561 | */ |
| 11562 | break; |
| 11563 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 11564 | } else |
| 11565 | spin_unlock_irq(&phba->hbalock); |
| 11566 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11567 | lpfc_sli_mbox_sys_flush(phba); |
| 11568 | } |
| 11569 | |
| 11570 | /** |
| 11571 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 11572 | * @phba: Pointer to HBA context. |
| 11573 | * |
| 11574 | * This function is called to read the SLI3 device error attention registers |
| 11575 | * for possible error attention events. The caller must hold the hostlock |
| 11576 | * with spin_lock_irq(). |
| 11577 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11578 | * 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] | 11579 | * Register and returns 0 otherwise. |
| 11580 | **/ |
| 11581 | static int |
| 11582 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 11583 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 11584 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11585 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11586 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11587 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11588 | goto unplug_err; |
| 11589 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11590 | if (ha_copy & HA_ERATT) { |
| 11591 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11592 | if (lpfc_sli_read_hs(phba)) |
| 11593 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11594 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11595 | /* Check if there is a deferred error condition is active */ |
| 11596 | if ((HS_FFER1 & phba->work_hs) && |
| 11597 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 11598 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11599 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11600 | /* Clear all interrupt enable conditions */ |
| 11601 | writel(0, phba->HCregaddr); |
| 11602 | readl(phba->HCregaddr); |
| 11603 | } |
| 11604 | |
| 11605 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11606 | phba->work_ha |= HA_ERATT; |
| 11607 | /* Indicate polling handles this ERATT */ |
| 11608 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11609 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11610 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11611 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11612 | |
| 11613 | unplug_err: |
| 11614 | /* Set the driver HS work bitmap */ |
| 11615 | phba->work_hs |= UNPLUG_ERR; |
| 11616 | /* Set the driver HA work bitmap */ |
| 11617 | phba->work_ha |= HA_ERATT; |
| 11618 | /* Indicate polling handles this ERATT */ |
| 11619 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11620 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11621 | } |
| 11622 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11623 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11624 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 11625 | * @phba: Pointer to HBA context. |
| 11626 | * |
| 11627 | * This function is called to read the SLI4 device error attention registers |
| 11628 | * for possible error attention events. The caller must hold the hostlock |
| 11629 | * with spin_lock_irq(). |
| 11630 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11631 | * 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] | 11632 | * Register and returns 0 otherwise. |
| 11633 | **/ |
| 11634 | static int |
| 11635 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 11636 | { |
| 11637 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11638 | uint32_t if_type, portsmphr; |
| 11639 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11640 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11641 | /* |
| 11642 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11643 | * registers for error attention. This can be changed later. |
| 11644 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11645 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 11646 | switch (if_type) { |
| 11647 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11648 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 11649 | &uerr_sta_lo) || |
| 11650 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 11651 | &uerr_sta_hi)) { |
| 11652 | phba->work_hs |= UNPLUG_ERR; |
| 11653 | phba->work_ha |= HA_ERATT; |
| 11654 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11655 | return 1; |
| 11656 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11657 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 11658 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 11659 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11660 | "1423 HBA Unrecoverable error: " |
| 11661 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 11662 | "ue_mask_lo_reg=0x%x, " |
| 11663 | "ue_mask_hi_reg=0x%x\n", |
| 11664 | uerr_sta_lo, uerr_sta_hi, |
| 11665 | phba->sli4_hba.ue_mask_lo, |
| 11666 | phba->sli4_hba.ue_mask_hi); |
| 11667 | phba->work_status[0] = uerr_sta_lo; |
| 11668 | phba->work_status[1] = uerr_sta_hi; |
| 11669 | phba->work_ha |= HA_ERATT; |
| 11670 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11671 | return 1; |
| 11672 | } |
| 11673 | break; |
| 11674 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11675 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 11676 | &portstat_reg.word0) || |
| 11677 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 11678 | &portsmphr)){ |
| 11679 | phba->work_hs |= UNPLUG_ERR; |
| 11680 | phba->work_ha |= HA_ERATT; |
| 11681 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11682 | return 1; |
| 11683 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11684 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 11685 | phba->work_status[0] = |
| 11686 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 11687 | phba->work_status[1] = |
| 11688 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 11689 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11690 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11691 | "port status reg 0x%x, " |
| 11692 | "port smphr reg 0x%x, " |
| 11693 | "error 1=0x%x, error 2=0x%x\n", |
| 11694 | portstat_reg.word0, |
| 11695 | portsmphr, |
| 11696 | phba->work_status[0], |
| 11697 | phba->work_status[1]); |
| 11698 | phba->work_ha |= HA_ERATT; |
| 11699 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11700 | return 1; |
| 11701 | } |
| 11702 | break; |
| 11703 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 11704 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11705 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11706 | "2886 HBA Error Attention on unsupported " |
| 11707 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11708 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11709 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11710 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11711 | return 0; |
| 11712 | } |
| 11713 | |
| 11714 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11715 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11716 | * @phba: Pointer to HBA context. |
| 11717 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11718 | * 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] | 11719 | * error attention register bit for error attention events. |
| 11720 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11721 | * 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] | 11722 | * Register and returns 0 otherwise. |
| 11723 | **/ |
| 11724 | int |
| 11725 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 11726 | { |
| 11727 | uint32_t ha_copy; |
| 11728 | |
| 11729 | /* If somebody is waiting to handle an eratt, don't process it |
| 11730 | * here. The brdkill function will do this. |
| 11731 | */ |
| 11732 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11733 | return 0; |
| 11734 | |
| 11735 | /* Check if interrupt handler handles this ERATT */ |
| 11736 | spin_lock_irq(&phba->hbalock); |
| 11737 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 11738 | /* Interrupt handler has handled ERATT */ |
| 11739 | spin_unlock_irq(&phba->hbalock); |
| 11740 | return 0; |
| 11741 | } |
| 11742 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11743 | /* |
| 11744 | * If there is deferred error attention, do not check for error |
| 11745 | * attention |
| 11746 | */ |
| 11747 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 11748 | spin_unlock_irq(&phba->hbalock); |
| 11749 | return 0; |
| 11750 | } |
| 11751 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11752 | /* If PCI channel is offline, don't process it */ |
| 11753 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11754 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11755 | return 0; |
| 11756 | } |
| 11757 | |
| 11758 | switch (phba->sli_rev) { |
| 11759 | case LPFC_SLI_REV2: |
| 11760 | case LPFC_SLI_REV3: |
| 11761 | /* Read chip Host Attention (HA) register */ |
| 11762 | ha_copy = lpfc_sli_eratt_read(phba); |
| 11763 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11764 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11765 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11766 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 11767 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11768 | default: |
| 11769 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11770 | "0299 Invalid SLI revision (%d)\n", |
| 11771 | phba->sli_rev); |
| 11772 | ha_copy = 0; |
| 11773 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11774 | } |
| 11775 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11776 | |
| 11777 | return ha_copy; |
| 11778 | } |
| 11779 | |
| 11780 | /** |
| 11781 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 11782 | * @phba: Pointer to HBA context. |
| 11783 | * |
| 11784 | * This inline routine checks whether a device or its PCI slot is in a state |
| 11785 | * that the interrupt should be handled. |
| 11786 | * |
| 11787 | * This function returns 0 if the device or the PCI slot is in a state that |
| 11788 | * interrupt should be handled, otherwise -EIO. |
| 11789 | */ |
| 11790 | static inline int |
| 11791 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 11792 | { |
| 11793 | /* If the pci channel is offline, ignore all the interrupts */ |
| 11794 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 11795 | return -EIO; |
| 11796 | |
| 11797 | /* Update device level interrupt statistics */ |
| 11798 | phba->sli.slistat.sli_intr++; |
| 11799 | |
| 11800 | /* Ignore all interrupts during initialization. */ |
| 11801 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 11802 | return -EIO; |
| 11803 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11804 | return 0; |
| 11805 | } |
| 11806 | |
| 11807 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11808 | * 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] | 11809 | * @irq: Interrupt number. |
| 11810 | * @dev_id: The device context pointer. |
| 11811 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11812 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11813 | * service routine when device with SLI-3 interface spec is enabled with |
| 11814 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 11815 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 11816 | * interrupt mode, this function is called as part of the device-level |
| 11817 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 11818 | * is undergoing initialization, the interrupt handler will not process |
| 11819 | * the interrupt. The link attention and ELS ring attention events are |
| 11820 | * handled by the worker thread. The interrupt handler signals the worker |
| 11821 | * thread and returns for these events. This function is called without |
| 11822 | * 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] | 11823 | * structures. |
| 11824 | * |
| 11825 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11826 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11827 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11828 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11829 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11830 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11831 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11832 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11833 | uint32_t work_ha_copy; |
| 11834 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11835 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11836 | uint32_t control; |
| 11837 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11838 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11839 | struct lpfc_vport *vport; |
| 11840 | struct lpfc_nodelist *ndlp; |
| 11841 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11842 | LPFC_MBOXQ_t *pmb; |
| 11843 | int rc; |
| 11844 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11845 | /* |
| 11846 | * Get the driver's phba structure from the dev_id and |
| 11847 | * assume the HBA is not interrupting. |
| 11848 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11849 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11850 | |
| 11851 | if (unlikely(!phba)) |
| 11852 | return IRQ_NONE; |
| 11853 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11854 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11855 | * Stuff needs to be attented to when this function is invoked as an |
| 11856 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11857 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11858 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11859 | /* Check device state for handling interrupt */ |
| 11860 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11861 | return IRQ_NONE; |
| 11862 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11863 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11864 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11865 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11866 | /* If somebody is waiting to handle an eratt don't process it |
| 11867 | * here. The brdkill function will do this. |
| 11868 | */ |
| 11869 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11870 | ha_copy &= ~HA_ERATT; |
| 11871 | /* Check the need for handling ERATT in interrupt handler */ |
| 11872 | if (ha_copy & HA_ERATT) { |
| 11873 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 11874 | /* ERATT polling has handled ERATT */ |
| 11875 | ha_copy &= ~HA_ERATT; |
| 11876 | else |
| 11877 | /* Indicate interrupt handler handles ERATT */ |
| 11878 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11879 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11880 | |
| 11881 | /* |
| 11882 | * If there is deferred error attention, do not check for any |
| 11883 | * interrupt. |
| 11884 | */ |
| 11885 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11886 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11887 | return IRQ_NONE; |
| 11888 | } |
| 11889 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11890 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11891 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 11892 | goto unplug_error; |
| 11893 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11894 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 11895 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 11896 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11897 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 11898 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11899 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11900 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11901 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11902 | } else |
| 11903 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11904 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11905 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 11906 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11907 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11908 | if (work_ha_copy & HA_LATT) { |
| 11909 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 11910 | /* |
| 11911 | * Turn off Link Attention interrupts |
| 11912 | * until CLEAR_LA done |
| 11913 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11914 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11915 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11916 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11917 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11918 | control &= ~HC_LAINT_ENA; |
| 11919 | writel(control, phba->HCregaddr); |
| 11920 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11921 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11922 | } |
| 11923 | else |
| 11924 | work_ha_copy &= ~HA_LATT; |
| 11925 | } |
| 11926 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11927 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11928 | /* |
| 11929 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 11930 | * the only slow ring. |
| 11931 | */ |
| 11932 | status = (work_ha_copy & |
| 11933 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 11934 | status >>= (4*LPFC_ELS_RING); |
| 11935 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11936 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11937 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11938 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11939 | |
| 11940 | lpfc_debugfs_slow_ring_trc(phba, |
| 11941 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 11942 | control, status, |
| 11943 | (uint32_t)phba->sli.slistat.sli_intr); |
| 11944 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11945 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11946 | lpfc_debugfs_slow_ring_trc(phba, |
| 11947 | "ISR Disable ring:" |
| 11948 | "pwork:x%x hawork:x%x wait:x%x", |
| 11949 | phba->work_ha, work_ha_copy, |
| 11950 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11951 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11952 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11953 | control &= |
| 11954 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11955 | writel(control, phba->HCregaddr); |
| 11956 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11957 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11958 | else { |
| 11959 | lpfc_debugfs_slow_ring_trc(phba, |
| 11960 | "ISR slow ring: pwork:" |
| 11961 | "x%x hawork:x%x wait:x%x", |
| 11962 | phba->work_ha, work_ha_copy, |
| 11963 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11964 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11965 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11966 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11967 | } |
| 11968 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11969 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11970 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11971 | if (lpfc_sli_read_hs(phba)) |
| 11972 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11973 | /* |
| 11974 | * Check if there is a deferred error condition |
| 11975 | * is active |
| 11976 | */ |
| 11977 | if ((HS_FFER1 & phba->work_hs) && |
| 11978 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 11979 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 11980 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11981 | phba->hba_flag |= DEFER_ERATT; |
| 11982 | /* Clear all interrupt enable conditions */ |
| 11983 | writel(0, phba->HCregaddr); |
| 11984 | readl(phba->HCregaddr); |
| 11985 | } |
| 11986 | } |
| 11987 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11988 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11989 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11990 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11991 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11992 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11993 | |
| 11994 | /* First check out the status word */ |
| 11995 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 11996 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11997 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11998 | /* |
| 11999 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 12000 | * mbxStatus <status> |
| 12001 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12002 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12003 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12004 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12005 | "Interrupt mbxCommand x%x " |
| 12006 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 12007 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12008 | pmbox->mbxCommand, |
| 12009 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12010 | /* clear mailbox attention bit */ |
| 12011 | work_ha_copy &= ~HA_MBATT; |
| 12012 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12013 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12014 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12015 | phba->last_completion_time = jiffies; |
| 12016 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12017 | if (pmb->mbox_cmpl) { |
| 12018 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 12019 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 12020 | if (pmb->out_ext_byte_len && |
| 12021 | pmb->context2) |
| 12022 | lpfc_sli_pcimem_bcopy( |
| 12023 | phba->mbox_ext, |
| 12024 | pmb->context2, |
| 12025 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12026 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12027 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12028 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12029 | |
| 12030 | lpfc_debugfs_disc_trc(vport, |
| 12031 | LPFC_DISC_TRC_MBOX_VPORT, |
| 12032 | "MBOX dflt rpi: : " |
| 12033 | "status:x%x rpi:x%x", |
| 12034 | (uint32_t)pmbox->mbxStatus, |
| 12035 | pmbox->un.varWords[0], 0); |
| 12036 | |
| 12037 | if (!pmbox->mbxStatus) { |
| 12038 | mp = (struct lpfc_dmabuf *) |
| 12039 | (pmb->context1); |
| 12040 | ndlp = (struct lpfc_nodelist *) |
| 12041 | pmb->context2; |
| 12042 | |
| 12043 | /* Reg_LOGIN of dflt RPI was |
| 12044 | * successful. new lets get |
| 12045 | * rid of the RPI using the |
| 12046 | * same mbox buffer. |
| 12047 | */ |
| 12048 | lpfc_unreg_login(phba, |
| 12049 | vport->vpi, |
| 12050 | pmbox->un.varWords[0], |
| 12051 | pmb); |
| 12052 | pmb->mbox_cmpl = |
| 12053 | lpfc_mbx_cmpl_dflt_rpi; |
| 12054 | pmb->context1 = mp; |
| 12055 | pmb->context2 = ndlp; |
| 12056 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12057 | rc = lpfc_sli_issue_mbox(phba, |
| 12058 | pmb, |
| 12059 | MBX_NOWAIT); |
| 12060 | if (rc != MBX_BUSY) |
| 12061 | lpfc_printf_log(phba, |
| 12062 | KERN_ERR, |
| 12063 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12064 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12065 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12066 | if (rc != MBX_NOT_FINISHED) |
| 12067 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12068 | } |
| 12069 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12070 | spin_lock_irqsave( |
| 12071 | &phba->pport->work_port_lock, |
| 12072 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12073 | phba->pport->work_port_events &= |
| 12074 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12075 | spin_unlock_irqrestore( |
| 12076 | &phba->pport->work_port_lock, |
| 12077 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12078 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12079 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12080 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12081 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12082 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12083 | if ((work_ha_copy & HA_MBATT) && |
| 12084 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12085 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12086 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12087 | do { |
| 12088 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12089 | MBX_NOWAIT); |
| 12090 | } while (rc == MBX_NOT_FINISHED); |
| 12091 | if (rc != MBX_SUCCESS) |
| 12092 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12093 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12094 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12095 | } |
| 12096 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12097 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12098 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12099 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12100 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12101 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12102 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12103 | unplug_error: |
| 12104 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12105 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12106 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12107 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12108 | |
| 12109 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12110 | * 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] | 12111 | * @irq: Interrupt number. |
| 12112 | * @dev_id: The device context pointer. |
| 12113 | * |
| 12114 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12115 | * service routine when device with SLI-3 interface spec is enabled with |
| 12116 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12117 | * ring event in the HBA. However, when the device is enabled with either |
| 12118 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12119 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12120 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12121 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12122 | * the intrrupt context. This function is called without any lock held. |
| 12123 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12124 | * |
| 12125 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12126 | * returns IRQ_NONE. |
| 12127 | **/ |
| 12128 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12129 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12130 | { |
| 12131 | struct lpfc_hba *phba; |
| 12132 | uint32_t ha_copy; |
| 12133 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12134 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12135 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12136 | |
| 12137 | /* Get the driver's phba structure from the dev_id and |
| 12138 | * assume the HBA is not interrupting. |
| 12139 | */ |
| 12140 | phba = (struct lpfc_hba *) dev_id; |
| 12141 | |
| 12142 | if (unlikely(!phba)) |
| 12143 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12144 | |
| 12145 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12146 | * Stuff needs to be attented to when this function is invoked as an |
| 12147 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12148 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12149 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12150 | /* Check device state for handling interrupt */ |
| 12151 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12152 | return IRQ_NONE; |
| 12153 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12154 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12155 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12156 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12157 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12158 | /* |
| 12159 | * If there is deferred error attention, do not check for |
| 12160 | * any interrupt. |
| 12161 | */ |
| 12162 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12163 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12164 | return IRQ_NONE; |
| 12165 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12166 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12167 | phba->HAregaddr); |
| 12168 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12169 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12170 | } else |
| 12171 | ha_copy = phba->ha_copy; |
| 12172 | |
| 12173 | /* |
| 12174 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12175 | */ |
| 12176 | ha_copy &= ~(phba->work_ha_mask); |
| 12177 | |
| 12178 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12179 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12180 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12181 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12182 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12183 | |
| 12184 | if (phba->cfg_multi_ring_support == 2) { |
| 12185 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12186 | * Process all events on extra ring. Take the optimized path |
| 12187 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12188 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12189 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12190 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12191 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12192 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12193 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12194 | status); |
| 12195 | } |
| 12196 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12197 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12198 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12199 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12200 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12201 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12202 | * @irq: Interrupt number. |
| 12203 | * @dev_id: The device context pointer. |
| 12204 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12205 | * This function is the HBA device-level interrupt handler to device with |
| 12206 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12207 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12208 | * requires driver attention. This function invokes the slow-path interrupt |
| 12209 | * attention handling function and fast-path interrupt attention handling |
| 12210 | * function in turn to process the relevant HBA attention events. This |
| 12211 | * function is called without any lock held. It gets the hbalock to access |
| 12212 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12213 | * |
| 12214 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12215 | * returns IRQ_NONE. |
| 12216 | **/ |
| 12217 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12218 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12219 | { |
| 12220 | struct lpfc_hba *phba; |
| 12221 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12222 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12223 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12224 | |
| 12225 | /* |
| 12226 | * Get the driver's phba structure from the dev_id and |
| 12227 | * assume the HBA is not interrupting. |
| 12228 | */ |
| 12229 | phba = (struct lpfc_hba *) dev_id; |
| 12230 | |
| 12231 | if (unlikely(!phba)) |
| 12232 | return IRQ_NONE; |
| 12233 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12234 | /* Check device state for handling interrupt */ |
| 12235 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12236 | return IRQ_NONE; |
| 12237 | |
| 12238 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12239 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12240 | spin_unlock(&phba->hbalock); |
| 12241 | return IRQ_HANDLED; |
| 12242 | } |
| 12243 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12244 | if (unlikely(!phba->ha_copy)) { |
| 12245 | spin_unlock(&phba->hbalock); |
| 12246 | return IRQ_NONE; |
| 12247 | } else if (phba->ha_copy & HA_ERATT) { |
| 12248 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12249 | /* ERATT polling has handled ERATT */ |
| 12250 | phba->ha_copy &= ~HA_ERATT; |
| 12251 | else |
| 12252 | /* Indicate interrupt handler handles ERATT */ |
| 12253 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12254 | } |
| 12255 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12256 | /* |
| 12257 | * If there is deferred error attention, do not check for any interrupt. |
| 12258 | */ |
| 12259 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 12260 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12261 | return IRQ_NONE; |
| 12262 | } |
| 12263 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12264 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12265 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 12266 | spin_unlock(&phba->hbalock); |
| 12267 | return IRQ_HANDLED; |
| 12268 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12269 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 12270 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12271 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12272 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12273 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12274 | readl(phba->HAregaddr); /* flush */ |
| 12275 | spin_unlock(&phba->hbalock); |
| 12276 | |
| 12277 | /* |
| 12278 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12279 | */ |
| 12280 | |
| 12281 | /* status of events with mailbox and link attention */ |
| 12282 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 12283 | |
| 12284 | /* status of events with ELS ring */ |
| 12285 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12286 | status2 >>= (4*LPFC_ELS_RING); |
| 12287 | |
| 12288 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12289 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12290 | else |
| 12291 | sp_irq_rc = IRQ_NONE; |
| 12292 | |
| 12293 | /* |
| 12294 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12295 | */ |
| 12296 | |
| 12297 | /* status of events with FCP ring */ |
| 12298 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 12299 | status1 >>= (4*LPFC_FCP_RING); |
| 12300 | |
| 12301 | /* status of events with extra ring */ |
| 12302 | if (phba->cfg_multi_ring_support == 2) { |
| 12303 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 12304 | status2 >>= (4*LPFC_EXTRA_RING); |
| 12305 | } else |
| 12306 | status2 = 0; |
| 12307 | |
| 12308 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12309 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12310 | else |
| 12311 | fp_irq_rc = IRQ_NONE; |
| 12312 | |
| 12313 | /* Return device-level interrupt handling status */ |
| 12314 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12315 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12316 | |
| 12317 | /** |
| 12318 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 12319 | * @phba: pointer to lpfc hba data structure. |
| 12320 | * |
| 12321 | * This routine is invoked by the worker thread to process all the pending |
| 12322 | * SLI4 FCP abort XRI events. |
| 12323 | **/ |
| 12324 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12325 | { |
| 12326 | struct lpfc_cq_event *cq_event; |
| 12327 | |
| 12328 | /* First, declare the fcp xri abort event has been handled */ |
| 12329 | spin_lock_irq(&phba->hbalock); |
| 12330 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 12331 | spin_unlock_irq(&phba->hbalock); |
| 12332 | /* Now, handle all the fcp xri abort events */ |
| 12333 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 12334 | /* Get the first event from the head of the event queue */ |
| 12335 | spin_lock_irq(&phba->hbalock); |
| 12336 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 12337 | cq_event, struct lpfc_cq_event, list); |
| 12338 | spin_unlock_irq(&phba->hbalock); |
| 12339 | /* Notify aborted XRI for FCP work queue */ |
| 12340 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12341 | /* Free the event processed back to the free pool */ |
| 12342 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12343 | } |
| 12344 | } |
| 12345 | |
| 12346 | /** |
| 12347 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 12348 | * @phba: pointer to lpfc hba data structure. |
| 12349 | * |
| 12350 | * This routine is invoked by the worker thread to process all the pending |
| 12351 | * SLI4 els abort xri events. |
| 12352 | **/ |
| 12353 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12354 | { |
| 12355 | struct lpfc_cq_event *cq_event; |
| 12356 | |
| 12357 | /* First, declare the els xri abort event has been handled */ |
| 12358 | spin_lock_irq(&phba->hbalock); |
| 12359 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 12360 | spin_unlock_irq(&phba->hbalock); |
| 12361 | /* Now, handle all the els xri abort events */ |
| 12362 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 12363 | /* Get the first event from the head of the event queue */ |
| 12364 | spin_lock_irq(&phba->hbalock); |
| 12365 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 12366 | cq_event, struct lpfc_cq_event, list); |
| 12367 | spin_unlock_irq(&phba->hbalock); |
| 12368 | /* Notify aborted XRI for ELS work queue */ |
| 12369 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12370 | /* Free the event processed back to the free pool */ |
| 12371 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12372 | } |
| 12373 | } |
| 12374 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12375 | /** |
| 12376 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 12377 | * @phba: pointer to lpfc hba data structure |
| 12378 | * @pIocbIn: pointer to the rspiocbq |
| 12379 | * @pIocbOut: pointer to the cmdiocbq |
| 12380 | * @wcqe: pointer to the complete wcqe |
| 12381 | * |
| 12382 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 12383 | * by copying all the IOCB fields from command iocbq and transferring the |
| 12384 | * completion status information from the complete wcqe. |
| 12385 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12386 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12387 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 12388 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12389 | struct lpfc_iocbq *pIocbOut, |
| 12390 | struct lpfc_wcqe_complete *wcqe) |
| 12391 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12392 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12393 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12394 | uint32_t status, max_response; |
| 12395 | struct lpfc_dmabuf *dmabuf; |
| 12396 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12397 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 12398 | |
| 12399 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 12400 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12401 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12402 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 12403 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12404 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 12405 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 12406 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 12407 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 12408 | wcqe->total_data_placed; |
| 12409 | else |
| 12410 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12411 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12412 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12413 | switch (pIocbOut->iocb.ulpCommand) { |
| 12414 | case CMD_ELS_REQUEST64_CR: |
| 12415 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12416 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12417 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 12418 | max_response = bde.tus.f.bdeSize; |
| 12419 | break; |
| 12420 | case CMD_GEN_REQUEST64_CR: |
| 12421 | max_response = 0; |
| 12422 | if (!pIocbOut->context3) |
| 12423 | break; |
| 12424 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 12425 | sizeof(struct ulp_bde64); |
| 12426 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12427 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12428 | for (i = 0; i < numBdes; i++) { |
| 12429 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 12430 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 12431 | max_response += bde.tus.f.bdeSize; |
| 12432 | } |
| 12433 | break; |
| 12434 | default: |
| 12435 | max_response = wcqe->total_data_placed; |
| 12436 | break; |
| 12437 | } |
| 12438 | if (max_response < wcqe->total_data_placed) |
| 12439 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 12440 | else |
| 12441 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 12442 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12443 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12444 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12445 | /* Convert BG errors for completion status */ |
| 12446 | if (status == CQE_STATUS_DI_ERROR) { |
| 12447 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 12448 | |
| 12449 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 12450 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 12451 | else |
| 12452 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 12453 | |
| 12454 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 12455 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 12456 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12457 | BGS_GUARD_ERR_MASK; |
| 12458 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 12459 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12460 | BGS_APPTAG_ERR_MASK; |
| 12461 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 12462 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12463 | BGS_REFTAG_ERR_MASK; |
| 12464 | |
| 12465 | /* Check to see if there was any good data before the error */ |
| 12466 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 12467 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12468 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 12469 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 12470 | wcqe->total_data_placed; |
| 12471 | } |
| 12472 | |
| 12473 | /* |
| 12474 | * Set ALL the error bits to indicate we don't know what |
| 12475 | * type of error it is. |
| 12476 | */ |
| 12477 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 12478 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12479 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 12480 | BGS_GUARD_ERR_MASK); |
| 12481 | } |
| 12482 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12483 | /* Pick up HBA exchange busy condition */ |
| 12484 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 12485 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12486 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 12487 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12488 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12489 | } |
| 12490 | |
| 12491 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12492 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 12493 | * @phba: Pointer to HBA context object. |
| 12494 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12495 | * |
| 12496 | * This routine handles an ELS work-queue completion event and construct |
| 12497 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 12498 | * discovery engine to handle. |
| 12499 | * |
| 12500 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 12501 | **/ |
| 12502 | static struct lpfc_iocbq * |
| 12503 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 12504 | struct lpfc_iocbq *irspiocbq) |
| 12505 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12506 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12507 | struct lpfc_iocbq *cmdiocbq; |
| 12508 | struct lpfc_wcqe_complete *wcqe; |
| 12509 | unsigned long iflags; |
| 12510 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12511 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 12512 | if (unlikely(!pring)) |
| 12513 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12514 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12515 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12516 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12517 | pring->stats.iocb_event++; |
| 12518 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 12519 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 12520 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12521 | if (unlikely(!cmdiocbq)) { |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12522 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12523 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12524 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12525 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 12526 | wcqe->word0, wcqe->total_data_placed, |
| 12527 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12528 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 12529 | return NULL; |
| 12530 | } |
| 12531 | |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12532 | /* Put the iocb back on the txcmplq */ |
| 12533 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 12534 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 12535 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12536 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12537 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12538 | |
| 12539 | return irspiocbq; |
| 12540 | } |
| 12541 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 12542 | inline struct lpfc_cq_event * |
| 12543 | lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size) |
| 12544 | { |
| 12545 | struct lpfc_cq_event *cq_event; |
| 12546 | |
| 12547 | /* Allocate a new internal CQ_EVENT entry */ |
| 12548 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 12549 | if (!cq_event) { |
| 12550 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12551 | "0602 Failed to alloc CQ_EVENT entry\n"); |
| 12552 | return NULL; |
| 12553 | } |
| 12554 | |
| 12555 | /* Move the CQE into the event */ |
| 12556 | memcpy(&cq_event->cqe, entry, size); |
| 12557 | return cq_event; |
| 12558 | } |
| 12559 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12560 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12561 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 12562 | * @phba: Pointer to HBA context object. |
| 12563 | * @cqe: Pointer to mailbox completion queue entry. |
| 12564 | * |
| 12565 | * This routine process a mailbox completion queue entry with asynchrous |
| 12566 | * event. |
| 12567 | * |
| 12568 | * Return: true if work posted to worker thread, otherwise false. |
| 12569 | **/ |
| 12570 | static bool |
| 12571 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 12572 | { |
| 12573 | struct lpfc_cq_event *cq_event; |
| 12574 | unsigned long iflags; |
| 12575 | |
| 12576 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 12577 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 12578 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 12579 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 12580 | |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 12581 | cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe)); |
| 12582 | if (!cq_event) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12583 | return false; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12584 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12585 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 12586 | /* Set the async event flag */ |
| 12587 | phba->hba_flag |= ASYNC_EVENT; |
| 12588 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12589 | |
| 12590 | return true; |
| 12591 | } |
| 12592 | |
| 12593 | /** |
| 12594 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 12595 | * @phba: Pointer to HBA context object. |
| 12596 | * @cqe: Pointer to mailbox completion queue entry. |
| 12597 | * |
| 12598 | * This routine process a mailbox completion queue entry with mailbox |
| 12599 | * completion event. |
| 12600 | * |
| 12601 | * Return: true if work posted to worker thread, otherwise false. |
| 12602 | **/ |
| 12603 | static bool |
| 12604 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 12605 | { |
| 12606 | uint32_t mcqe_status; |
| 12607 | MAILBOX_t *mbox, *pmbox; |
| 12608 | struct lpfc_mqe *mqe; |
| 12609 | struct lpfc_vport *vport; |
| 12610 | struct lpfc_nodelist *ndlp; |
| 12611 | struct lpfc_dmabuf *mp; |
| 12612 | unsigned long iflags; |
| 12613 | LPFC_MBOXQ_t *pmb; |
| 12614 | bool workposted = false; |
| 12615 | int rc; |
| 12616 | |
| 12617 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 12618 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 12619 | goto out_no_mqe_complete; |
| 12620 | |
| 12621 | /* Get the reference to the active mbox command */ |
| 12622 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12623 | pmb = phba->sli.mbox_active; |
| 12624 | if (unlikely(!pmb)) { |
| 12625 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 12626 | "1832 No pending MBOX command to handle\n"); |
| 12627 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12628 | goto out_no_mqe_complete; |
| 12629 | } |
| 12630 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12631 | mqe = &pmb->u.mqe; |
| 12632 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 12633 | mbox = phba->mbox; |
| 12634 | vport = pmb->vport; |
| 12635 | |
| 12636 | /* Reset heartbeat timer */ |
| 12637 | phba->last_completion_time = jiffies; |
| 12638 | del_timer(&phba->sli.mbox_tmo); |
| 12639 | |
| 12640 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 12641 | if (pmb->mbox_cmpl && mbox) |
| 12642 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12643 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12644 | /* |
| 12645 | * For mcqe errors, conditionally move a modified error code to |
| 12646 | * the mbox so that the error will not be missed. |
| 12647 | */ |
| 12648 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 12649 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 12650 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 12651 | bf_set(lpfc_mqe_status, mqe, |
| 12652 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 12653 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12654 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12655 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12656 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 12657 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 12658 | mcqe_status, |
| 12659 | pmbox->un.varWords[0], 0); |
| 12660 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 12661 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 12662 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 12663 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 12664 | * RID of the PPI using the same mbox buffer. |
| 12665 | */ |
| 12666 | lpfc_unreg_login(phba, vport->vpi, |
| 12667 | pmbox->un.varWords[0], pmb); |
| 12668 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 12669 | pmb->context1 = mp; |
| 12670 | pmb->context2 = ndlp; |
| 12671 | pmb->vport = vport; |
| 12672 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 12673 | if (rc != MBX_BUSY) |
| 12674 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12675 | LOG_SLI, "0385 rc should " |
| 12676 | "have been MBX_BUSY\n"); |
| 12677 | if (rc != MBX_NOT_FINISHED) |
| 12678 | goto send_current_mbox; |
| 12679 | } |
| 12680 | } |
| 12681 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 12682 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 12683 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 12684 | |
| 12685 | /* There is mailbox completion work to do */ |
| 12686 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12687 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 12688 | phba->work_ha |= HA_MBATT; |
| 12689 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12690 | workposted = true; |
| 12691 | |
| 12692 | send_current_mbox: |
| 12693 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12694 | /* Release the mailbox command posting token */ |
| 12695 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 12696 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 12697 | phba->sli.mbox_active = NULL; |
| 12698 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12699 | /* Wake up worker thread to post the next pending mailbox command */ |
| 12700 | lpfc_worker_wake_up(phba); |
| 12701 | out_no_mqe_complete: |
| 12702 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 12703 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 12704 | return workposted; |
| 12705 | } |
| 12706 | |
| 12707 | /** |
| 12708 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 12709 | * @phba: Pointer to HBA context object. |
| 12710 | * @cqe: Pointer to mailbox completion queue entry. |
| 12711 | * |
| 12712 | * This routine process a mailbox completion queue entry, it invokes the |
| 12713 | * proper mailbox complete handling or asynchrous event handling routine |
| 12714 | * according to the MCQE's async bit. |
| 12715 | * |
| 12716 | * Return: true if work posted to worker thread, otherwise false. |
| 12717 | **/ |
| 12718 | static bool |
| 12719 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 12720 | { |
| 12721 | struct lpfc_mcqe mcqe; |
| 12722 | bool workposted; |
| 12723 | |
| 12724 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 12725 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 12726 | |
| 12727 | /* Invoke the proper event handling routine */ |
| 12728 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 12729 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 12730 | else |
| 12731 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 12732 | return workposted; |
| 12733 | } |
| 12734 | |
| 12735 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12736 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 12737 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12738 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12739 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12740 | * |
| 12741 | * This routine handles an ELS work-queue completion event. |
| 12742 | * |
| 12743 | * Return: true if work posted to worker thread, otherwise false. |
| 12744 | **/ |
| 12745 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12746 | 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] | 12747 | struct lpfc_wcqe_complete *wcqe) |
| 12748 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12749 | struct lpfc_iocbq *irspiocbq; |
| 12750 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12751 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12752 | int txq_cnt = 0; |
| 12753 | int txcmplq_cnt = 0; |
| 12754 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12755 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12756 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12757 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 12758 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12759 | if (!list_empty(&pring->txq)) |
| 12760 | txq_cnt++; |
| 12761 | if (!list_empty(&pring->txcmplq)) |
| 12762 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12763 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12764 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 12765 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12766 | txq_cnt, phba->iocb_cnt, |
| 12767 | fcp_txcmplq_cnt, |
| 12768 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12769 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12770 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12771 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12772 | /* Save off the slow-path queue event for work thread to process */ |
| 12773 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12774 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12775 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12776 | &phba->sli4_hba.sp_queue_event); |
| 12777 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12778 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12779 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12780 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12781 | } |
| 12782 | |
| 12783 | /** |
| 12784 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 12785 | * @phba: Pointer to HBA context object. |
| 12786 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12787 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 12788 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12789 | * proper WQ release routine to the slow-path WQ. |
| 12790 | **/ |
| 12791 | static void |
| 12792 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 12793 | struct lpfc_wcqe_release *wcqe) |
| 12794 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12795 | /* sanity check on queue memory */ |
| 12796 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 12797 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12798 | /* Check for the slow-path ELS work queue */ |
| 12799 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 12800 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 12801 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 12802 | else |
| 12803 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12804 | "2579 Slow-path wqe consume event carries " |
| 12805 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 12806 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 12807 | phba->sli4_hba.els_wq->queue_id); |
| 12808 | } |
| 12809 | |
| 12810 | /** |
| 12811 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 12812 | * @phba: Pointer to HBA context object. |
| 12813 | * @cq: Pointer to a WQ completion queue. |
| 12814 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12815 | * |
| 12816 | * This routine handles an XRI abort event. |
| 12817 | * |
| 12818 | * Return: true if work posted to worker thread, otherwise false. |
| 12819 | **/ |
| 12820 | static bool |
| 12821 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 12822 | struct lpfc_queue *cq, |
| 12823 | struct sli4_wcqe_xri_aborted *wcqe) |
| 12824 | { |
| 12825 | bool workposted = false; |
| 12826 | struct lpfc_cq_event *cq_event; |
| 12827 | unsigned long iflags; |
| 12828 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12829 | switch (cq->subtype) { |
| 12830 | case LPFC_FCP: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 12831 | cq_event = lpfc_cq_event_setup( |
| 12832 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 12833 | if (!cq_event) |
| 12834 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12835 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12836 | list_add_tail(&cq_event->list, |
| 12837 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 12838 | /* Set the fcp xri abort event flag */ |
| 12839 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 12840 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12841 | workposted = true; |
| 12842 | break; |
James Smart | 422c4cb | 2017-11-20 16:00:32 -0800 | [diff] [blame] | 12843 | case LPFC_NVME_LS: /* NVME LS uses ELS resources */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12844 | case LPFC_ELS: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 12845 | cq_event = lpfc_cq_event_setup( |
| 12846 | phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 12847 | if (!cq_event) |
| 12848 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12849 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12850 | list_add_tail(&cq_event->list, |
| 12851 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 12852 | /* Set the els xri abort event flag */ |
| 12853 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 12854 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12855 | workposted = true; |
| 12856 | break; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 12857 | case LPFC_NVME: |
James Smart | 8a5ca10 | 2017-11-20 16:00:30 -0800 | [diff] [blame] | 12858 | /* Notify aborted XRI for NVME work queue */ |
| 12859 | if (phba->nvmet_support) |
| 12860 | lpfc_sli4_nvmet_xri_aborted(phba, wcqe); |
| 12861 | else |
| 12862 | lpfc_sli4_nvme_xri_aborted(phba, wcqe); |
| 12863 | |
| 12864 | workposted = false; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 12865 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12866 | default: |
| 12867 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 12868 | "0603 Invalid CQ subtype %d: " |
| 12869 | "%08x %08x %08x %08x\n", |
| 12870 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 12871 | wcqe->word2, wcqe->word3); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12872 | workposted = false; |
| 12873 | break; |
| 12874 | } |
| 12875 | return workposted; |
| 12876 | } |
| 12877 | |
| 12878 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12879 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12880 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12881 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12882 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12883 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12884 | * |
| 12885 | * Return: true if work posted to worker thread, otherwise false. |
| 12886 | **/ |
| 12887 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12888 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 12889 | { |
| 12890 | bool workposted = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12891 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12892 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 12893 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 12894 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12895 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12896 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12897 | unsigned long iflags; |
| 12898 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12899 | /* sanity check on queue memory */ |
| 12900 | if (unlikely(!hrq) || unlikely(!drq)) |
| 12901 | return workposted; |
| 12902 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12903 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 12904 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 12905 | else |
| 12906 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 12907 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12908 | goto out; |
| 12909 | |
| 12910 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 12911 | switch (status) { |
| 12912 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 12913 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12914 | "2537 Receive Frame Truncated!!\n"); |
| 12915 | case FC_STATUS_RQ_SUCCESS: |
| 12916 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 12917 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12918 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 12919 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12920 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12921 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12922 | goto out; |
| 12923 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12924 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 12925 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12926 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12927 | |
| 12928 | /* If a NVME LS event (type 0x28), treat it as Fast path */ |
| 12929 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 12930 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12931 | /* save off the frame for the word thread to process */ |
| 12932 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12933 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12934 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12935 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12936 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12937 | workposted = true; |
| 12938 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12939 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 12940 | if (phba->nvmet_support) { |
| 12941 | tgtp = phba->targetport->private; |
| 12942 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 12943 | "6402 RQE Error x%x, posted %d err_cnt " |
| 12944 | "%d: %x %x %x\n", |
| 12945 | status, hrq->RQ_buf_posted, |
| 12946 | hrq->RQ_no_posted_buf, |
| 12947 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 12948 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 12949 | atomic_read(&tgtp->xmt_fcp_release)); |
| 12950 | } |
| 12951 | /* fallthrough */ |
| 12952 | |
| 12953 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12954 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12955 | /* Post more buffers if possible */ |
| 12956 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12957 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 12958 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12959 | workposted = true; |
| 12960 | break; |
| 12961 | } |
| 12962 | out: |
| 12963 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12964 | } |
| 12965 | |
| 12966 | /** |
| 12967 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 12968 | * @phba: Pointer to HBA context object. |
| 12969 | * @cq: Pointer to the completion queue. |
| 12970 | * @wcqe: Pointer to a completion queue entry. |
| 12971 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12972 | * 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] | 12973 | * entry. |
| 12974 | * |
| 12975 | * Return: true if work posted to worker thread, otherwise false. |
| 12976 | **/ |
| 12977 | static bool |
| 12978 | 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] | 12979 | struct lpfc_cqe *cqe) |
| 12980 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12981 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12982 | bool workposted = false; |
| 12983 | |
| 12984 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12985 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12986 | |
| 12987 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12988 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12989 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12990 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12991 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12992 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12993 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12994 | break; |
| 12995 | case CQE_CODE_RELEASE_WQE: |
| 12996 | /* Process the WQ release event */ |
| 12997 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12998 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12999 | break; |
| 13000 | case CQE_CODE_XRI_ABORTED: |
| 13001 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13002 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13003 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13004 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13005 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13006 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13007 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13008 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13009 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13010 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13011 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13012 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13013 | default: |
| 13014 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13015 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13016 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13017 | break; |
| 13018 | } |
| 13019 | return workposted; |
| 13020 | } |
| 13021 | |
| 13022 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13023 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13024 | * @phba: Pointer to HBA context object. |
| 13025 | * @eqe: Pointer to fast-path event queue entry. |
| 13026 | * |
| 13027 | * This routine process a event queue entry from the slow-path event queue. |
| 13028 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13029 | * completion event on a completion queue, if not, an error shall be logged |
| 13030 | * and just return. Otherwise, it will get to the corresponding completion |
| 13031 | * queue and process all the entries on that completion queue, rearm the |
| 13032 | * completion queue, and then return. |
| 13033 | * |
| 13034 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13035 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13036 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13037 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13038 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13039 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13040 | uint16_t cqid; |
| 13041 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13042 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13043 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13044 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13045 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13046 | if (childq->queue_id == cqid) { |
| 13047 | cq = childq; |
| 13048 | break; |
| 13049 | } |
| 13050 | } |
| 13051 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13052 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13053 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13054 | "0365 Slow-path CQ identifier " |
| 13055 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13056 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13057 | } |
| 13058 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13059 | /* Save EQ associated with this CQ */ |
| 13060 | cq->assoc_qp = speq; |
| 13061 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13062 | if (!queue_work(phba->wq, &cq->spwork)) |
| 13063 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13064 | "0390 Cannot schedule soft IRQ " |
| 13065 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13066 | cqid, cq->queue_id, smp_processor_id()); |
| 13067 | } |
| 13068 | |
| 13069 | /** |
| 13070 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
| 13071 | * @phba: Pointer to HBA context object. |
| 13072 | * |
| 13073 | * This routine process a event queue entry from the slow-path event queue. |
| 13074 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13075 | * completion event on a completion queue, if not, an error shall be logged |
| 13076 | * and just return. Otherwise, it will get to the corresponding completion |
| 13077 | * queue and process all the entries on that completion queue, rearm the |
| 13078 | * completion queue, and then return. |
| 13079 | * |
| 13080 | **/ |
| 13081 | static void |
| 13082 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 13083 | { |
| 13084 | struct lpfc_queue *cq = |
| 13085 | container_of(work, struct lpfc_queue, spwork); |
| 13086 | struct lpfc_hba *phba = cq->phba; |
| 13087 | struct lpfc_cqe *cqe; |
| 13088 | bool workposted = false; |
| 13089 | int ccount = 0; |
| 13090 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13091 | /* Process all the entries to the CQ */ |
| 13092 | switch (cq->type) { |
| 13093 | case LPFC_MCQ: |
| 13094 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 13095 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13096 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13097 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13098 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13099 | } |
| 13100 | break; |
| 13101 | case LPFC_WCQ: |
| 13102 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13103 | if (cq->subtype == LPFC_FCP || |
| 13104 | cq->subtype == LPFC_NVME) { |
| 13105 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13106 | if (phba->ktime_on) |
| 13107 | cq->isr_timestamp = ktime_get_ns(); |
| 13108 | else |
| 13109 | cq->isr_timestamp = 0; |
| 13110 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13111 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13112 | cqe); |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13113 | } else { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13114 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 13115 | cqe); |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13116 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13117 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13118 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13119 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13120 | |
| 13121 | /* Track the max number of CQEs processed in 1 EQ */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13122 | if (ccount > cq->CQ_max_cqe) |
| 13123 | cq->CQ_max_cqe = ccount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13124 | break; |
| 13125 | default: |
| 13126 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13127 | "0370 Invalid completion queue type (%d)\n", |
| 13128 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13129 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13130 | } |
| 13131 | |
| 13132 | /* Catch the no cq entry condition, log an error */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13133 | if (unlikely(ccount == 0)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13134 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13135 | "0371 No entry from the CQ: identifier " |
| 13136 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 13137 | |
| 13138 | /* In any case, flash and re-arm the RCQ */ |
| 13139 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 13140 | |
| 13141 | /* wake up worker thread if there are works to be done */ |
| 13142 | if (workposted) |
| 13143 | lpfc_worker_wake_up(phba); |
| 13144 | } |
| 13145 | |
| 13146 | /** |
| 13147 | * 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] | 13148 | * @phba: Pointer to HBA context object. |
| 13149 | * @cq: Pointer to associated CQ |
| 13150 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13151 | * |
| 13152 | * This routine process a fast-path work queue completion entry from fast-path |
| 13153 | * event queue for FCP command response completion. |
| 13154 | **/ |
| 13155 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13156 | 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] | 13157 | struct lpfc_wcqe_complete *wcqe) |
| 13158 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13159 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13160 | struct lpfc_iocbq *cmdiocbq; |
| 13161 | struct lpfc_iocbq irspiocbq; |
| 13162 | unsigned long iflags; |
| 13163 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13164 | /* Check for response status */ |
| 13165 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13166 | /* If resource errors reported from HBA, reduce queue |
| 13167 | * depth of the SCSI device. |
| 13168 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13169 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 13170 | IOSTAT_LOCAL_REJECT)) && |
| 13171 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 13172 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13173 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13174 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13175 | /* Log the error status */ |
| 13176 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13177 | "0373 FCP complete error: status=x%x, " |
| 13178 | "hw_status=x%x, total_data_specified=%d, " |
| 13179 | "parameter=x%x, word3=x%x\n", |
| 13180 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13181 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 13182 | wcqe->total_data_placed, wcqe->parameter, |
| 13183 | wcqe->word3); |
| 13184 | } |
| 13185 | |
| 13186 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13187 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 13188 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13189 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13190 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13191 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13192 | if (unlikely(!cmdiocbq)) { |
| 13193 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13194 | "0374 FCP complete with no corresponding " |
| 13195 | "cmdiocb: iotag (%d)\n", |
| 13196 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13197 | return; |
| 13198 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13199 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13200 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 13201 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13202 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 13203 | if (cmdiocbq->wqe_cmpl) { |
| 13204 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13205 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13206 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13207 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13208 | } |
| 13209 | |
| 13210 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 13211 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 13212 | return; |
| 13213 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13214 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13215 | "0375 FCP cmdiocb not callback function " |
| 13216 | "iotag: (%d)\n", |
| 13217 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13218 | return; |
| 13219 | } |
| 13220 | |
| 13221 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13222 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13223 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 13224 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13225 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13226 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13227 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13228 | } |
| 13229 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13230 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 13231 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 13232 | } |
| 13233 | |
| 13234 | /** |
| 13235 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 13236 | * @phba: Pointer to HBA context object. |
| 13237 | * @cq: Pointer to completion queue. |
| 13238 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13239 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13240 | * 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] | 13241 | * proper WQ release routine to the slow-path WQ. |
| 13242 | **/ |
| 13243 | static void |
| 13244 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13245 | struct lpfc_wcqe_release *wcqe) |
| 13246 | { |
| 13247 | struct lpfc_queue *childwq; |
| 13248 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13249 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13250 | |
| 13251 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13252 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13253 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13254 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13255 | lpfc_sli4_wq_release(childwq, |
| 13256 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 13257 | if (childwq->q_flag & HBA_NVMET_WQFULL) |
| 13258 | lpfc_nvmet_wqfull_process(phba, childwq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13259 | wqid_matched = true; |
| 13260 | break; |
| 13261 | } |
| 13262 | } |
| 13263 | /* Report warning log message if no match found */ |
| 13264 | if (wqid_matched != true) |
| 13265 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13266 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13267 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13268 | } |
| 13269 | |
| 13270 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13271 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 13272 | * @phba: Pointer to HBA context object. |
| 13273 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 13274 | * |
| 13275 | * This routine process a receive-queue completion queue entry. |
| 13276 | * |
| 13277 | * Return: true if work posted to worker thread, otherwise false. |
| 13278 | **/ |
| 13279 | static bool |
| 13280 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13281 | struct lpfc_rcqe *rcqe) |
| 13282 | { |
| 13283 | bool workposted = false; |
| 13284 | struct lpfc_queue *hrq; |
| 13285 | struct lpfc_queue *drq; |
| 13286 | struct rqb_dmabuf *dma_buf; |
| 13287 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13288 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13289 | uint32_t status, rq_id; |
| 13290 | unsigned long iflags; |
| 13291 | uint32_t fctl, idx; |
| 13292 | |
| 13293 | if ((phba->nvmet_support == 0) || |
| 13294 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 13295 | return workposted; |
| 13296 | |
| 13297 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13298 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 13299 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 13300 | |
| 13301 | /* sanity check on queue memory */ |
| 13302 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13303 | return workposted; |
| 13304 | |
| 13305 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13306 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13307 | else |
| 13308 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13309 | |
| 13310 | if ((phba->nvmet_support == 0) || |
| 13311 | (rq_id != hrq->queue_id)) |
| 13312 | return workposted; |
| 13313 | |
| 13314 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13315 | switch (status) { |
| 13316 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13317 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13318 | "6126 Receive Frame Truncated!!\n"); |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 13319 | /* Drop thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13320 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13321 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | cbc5de1 | 2017-12-08 17:18:04 -0800 | [diff] [blame] | 13322 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13323 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 13324 | if (!dma_buf) { |
| 13325 | hrq->RQ_no_buf_found++; |
| 13326 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13327 | goto out; |
| 13328 | } |
| 13329 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13330 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13331 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13332 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13333 | |
| 13334 | /* Just some basic sanity checks on FCP Command frame */ |
| 13335 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 13336 | fc_hdr->fh_f_ctl[1] << 8 | |
| 13337 | fc_hdr->fh_f_ctl[2]); |
| 13338 | if (((fctl & |
| 13339 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 13340 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 13341 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 13342 | goto drop; |
| 13343 | |
| 13344 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
| 13345 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 13346 | lpfc_nvmet_unsol_fcp_event( |
Dick Kennedy | 66d7ce9 | 2017-08-23 16:55:42 -0700 | [diff] [blame] | 13347 | phba, idx, dma_buf, |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13348 | cq->isr_timestamp); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13349 | return false; |
| 13350 | } |
| 13351 | drop: |
| 13352 | lpfc_in_buf_free(phba, &dma_buf->dbuf); |
| 13353 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13354 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13355 | if (phba->nvmet_support) { |
| 13356 | tgtp = phba->targetport->private; |
| 13357 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13358 | "6401 RQE Error x%x, posted %d err_cnt " |
| 13359 | "%d: %x %x %x\n", |
| 13360 | status, hrq->RQ_buf_posted, |
| 13361 | hrq->RQ_no_posted_buf, |
| 13362 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13363 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13364 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13365 | } |
| 13366 | /* fallthrough */ |
| 13367 | |
| 13368 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13369 | hrq->RQ_no_posted_buf++; |
| 13370 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13371 | break; |
| 13372 | } |
| 13373 | out: |
| 13374 | return workposted; |
| 13375 | } |
| 13376 | |
| 13377 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13378 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13379 | * @cq: Pointer to the completion queue. |
| 13380 | * @eqe: Pointer to fast-path completion queue entry. |
| 13381 | * |
| 13382 | * This routine process a fast-path work queue completion entry from fast-path |
| 13383 | * event queue for FCP command response completion. |
| 13384 | **/ |
| 13385 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13386 | 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] | 13387 | struct lpfc_cqe *cqe) |
| 13388 | { |
| 13389 | struct lpfc_wcqe_release wcqe; |
| 13390 | bool workposted = false; |
| 13391 | |
| 13392 | /* Copy the work queue CQE and convert endian order if needed */ |
| 13393 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 13394 | |
| 13395 | /* Check and process for different type of WCQE and dispatch */ |
| 13396 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 13397 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13398 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13399 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13400 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 13401 | phba->last_completion_time = jiffies; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13402 | if ((cq->subtype == LPFC_FCP) || (cq->subtype == LPFC_NVME)) |
| 13403 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
| 13404 | (struct lpfc_wcqe_complete *)&wcqe); |
| 13405 | if (cq->subtype == LPFC_NVME_LS) |
| 13406 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13407 | (struct lpfc_wcqe_complete *)&wcqe); |
| 13408 | break; |
| 13409 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13410 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13411 | /* Process the WQ release event */ |
| 13412 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 13413 | (struct lpfc_wcqe_release *)&wcqe); |
| 13414 | break; |
| 13415 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13416 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13417 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13418 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13419 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 13420 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 13421 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13422 | case CQE_CODE_RECEIVE_V1: |
| 13423 | case CQE_CODE_RECEIVE: |
| 13424 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13425 | if (cq->subtype == LPFC_NVMET) { |
| 13426 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 13427 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 13428 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13429 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13430 | default: |
| 13431 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13432 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13433 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 13434 | break; |
| 13435 | } |
| 13436 | return workposted; |
| 13437 | } |
| 13438 | |
| 13439 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13440 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13441 | * @phba: Pointer to HBA context object. |
| 13442 | * @eqe: Pointer to fast-path event queue entry. |
| 13443 | * |
| 13444 | * This routine process a event queue entry from the fast-path event queue. |
| 13445 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13446 | * completion event on a completion queue, if not, an error shall be logged |
| 13447 | * and just return. Otherwise, it will get to the corresponding completion |
| 13448 | * queue and process all the entries on the completion queue, rearm the |
| 13449 | * completion queue, and then return. |
| 13450 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13451 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13452 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13453 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13454 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13455 | struct lpfc_queue *cq = NULL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13456 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13457 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13458 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13459 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13460 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13461 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13462 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 13463 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13464 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13465 | } |
| 13466 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13467 | /* Get the reference to the corresponding CQ */ |
| 13468 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 13469 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13470 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 13471 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13472 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 13473 | /* Process NVMET unsol rcv */ |
| 13474 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 13475 | goto process_cq; |
| 13476 | } |
| 13477 | } |
| 13478 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13479 | if (phba->sli4_hba.nvme_cq_map && |
| 13480 | (cqid == phba->sli4_hba.nvme_cq_map[qidx])) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 13481 | /* Process NVME / NVMET command completion */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13482 | cq = phba->sli4_hba.nvme_cq[qidx]; |
| 13483 | goto process_cq; |
| 13484 | } |
| 13485 | |
| 13486 | if (phba->sli4_hba.fcp_cq_map && |
| 13487 | (cqid == phba->sli4_hba.fcp_cq_map[qidx])) { |
| 13488 | /* Process FCP command completion */ |
| 13489 | cq = phba->sli4_hba.fcp_cq[qidx]; |
| 13490 | goto process_cq; |
| 13491 | } |
| 13492 | |
| 13493 | if (phba->sli4_hba.nvmels_cq && |
| 13494 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 13495 | /* Process NVME unsol rcv */ |
| 13496 | cq = phba->sli4_hba.nvmels_cq; |
| 13497 | } |
| 13498 | |
| 13499 | /* Otherwise this is a Slow path event */ |
| 13500 | if (cq == NULL) { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13501 | lpfc_sli4_sp_handle_eqe(phba, eqe, phba->sli4_hba.hba_eq[qidx]); |
| 13502 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13503 | } |
| 13504 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13505 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13506 | if (unlikely(cqid != cq->queue_id)) { |
| 13507 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13508 | "0368 Miss-matched fast-path completion " |
| 13509 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 13510 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13511 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13512 | } |
| 13513 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13514 | /* Save EQ associated with this CQ */ |
| 13515 | cq->assoc_qp = phba->sli4_hba.hba_eq[qidx]; |
| 13516 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13517 | if (!queue_work(phba->wq, &cq->irqwork)) |
| 13518 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13519 | "0363 Cannot schedule soft IRQ " |
| 13520 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13521 | cqid, cq->queue_id, smp_processor_id()); |
| 13522 | } |
| 13523 | |
| 13524 | /** |
| 13525 | * lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 13526 | * @phba: Pointer to HBA context object. |
| 13527 | * @eqe: Pointer to fast-path event queue entry. |
| 13528 | * |
| 13529 | * This routine process a event queue entry from the fast-path event queue. |
| 13530 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13531 | * completion event on a completion queue, if not, an error shall be logged |
| 13532 | * and just return. Otherwise, it will get to the corresponding completion |
| 13533 | * queue and process all the entries on the completion queue, rearm the |
| 13534 | * completion queue, and then return. |
| 13535 | **/ |
| 13536 | static void |
| 13537 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
| 13538 | { |
| 13539 | struct lpfc_queue *cq = |
| 13540 | container_of(work, struct lpfc_queue, irqwork); |
| 13541 | struct lpfc_hba *phba = cq->phba; |
| 13542 | struct lpfc_cqe *cqe; |
| 13543 | bool workposted = false; |
| 13544 | int ccount = 0; |
| 13545 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13546 | /* Process all the entries to the CQ */ |
| 13547 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13548 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13549 | if (phba->ktime_on) |
| 13550 | cq->isr_timestamp = ktime_get_ns(); |
| 13551 | else |
| 13552 | cq->isr_timestamp = 0; |
| 13553 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13554 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, cqe); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13555 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13556 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13557 | } |
| 13558 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13559 | /* Track the max number of CQEs processed in 1 EQ */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13560 | if (ccount > cq->CQ_max_cqe) |
| 13561 | cq->CQ_max_cqe = ccount; |
| 13562 | cq->assoc_qp->EQ_cqe_cnt += ccount; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13563 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13564 | /* Catch the no cq entry condition */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13565 | if (unlikely(ccount == 0)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13566 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13567 | "0369 No entry from fast-path completion " |
| 13568 | "queue fcpcqid=%d\n", cq->queue_id); |
| 13569 | |
| 13570 | /* In any case, flash and re-arm the CQ */ |
| 13571 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 13572 | |
| 13573 | /* wake up worker thread if there are works to be done */ |
| 13574 | if (workposted) |
| 13575 | lpfc_worker_wake_up(phba); |
| 13576 | } |
| 13577 | |
| 13578 | static void |
| 13579 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 13580 | { |
| 13581 | struct lpfc_eqe *eqe; |
| 13582 | |
| 13583 | /* walk all the EQ entries and drop on the floor */ |
| 13584 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 13585 | ; |
| 13586 | |
| 13587 | /* Clear and re-arm the EQ */ |
| 13588 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 13589 | } |
| 13590 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13591 | |
| 13592 | /** |
| 13593 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue |
| 13594 | * entry |
| 13595 | * @phba: Pointer to HBA context object. |
| 13596 | * @eqe: Pointer to fast-path event queue entry. |
| 13597 | * |
| 13598 | * This routine process a event queue entry from the Flash Optimized Fabric |
| 13599 | * event queue. It will check the MajorCode and MinorCode to determine this |
| 13600 | * is for a completion event on a completion queue, if not, an error shall be |
| 13601 | * logged and just return. Otherwise, it will get to the corresponding |
| 13602 | * completion queue and process all the entries on the completion queue, rearm |
| 13603 | * the completion queue, and then return. |
| 13604 | **/ |
| 13605 | static void |
| 13606 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 13607 | { |
| 13608 | struct lpfc_queue *cq; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13609 | uint16_t cqid; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13610 | |
| 13611 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
| 13612 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13613 | "9147 Not a valid completion " |
| 13614 | "event: majorcode=x%x, minorcode=x%x\n", |
| 13615 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 13616 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
| 13617 | return; |
| 13618 | } |
| 13619 | |
| 13620 | /* Get the reference to the corresponding CQ */ |
| 13621 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 13622 | |
| 13623 | /* Next check for OAS */ |
| 13624 | cq = phba->sli4_hba.oas_cq; |
| 13625 | if (unlikely(!cq)) { |
| 13626 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13627 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13628 | "9148 OAS completion queue " |
| 13629 | "does not exist\n"); |
| 13630 | return; |
| 13631 | } |
| 13632 | |
| 13633 | if (unlikely(cqid != cq->queue_id)) { |
| 13634 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13635 | "9149 Miss-matched fast-path compl " |
| 13636 | "queue id: eqcqid=%d, fcpcqid=%d\n", |
| 13637 | cqid, cq->queue_id); |
| 13638 | return; |
| 13639 | } |
| 13640 | |
James Smart | d41b65b | 2017-06-15 22:56:41 -0700 | [diff] [blame] | 13641 | /* Save EQ associated with this CQ */ |
| 13642 | cq->assoc_qp = phba->sli4_hba.fof_eq; |
| 13643 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13644 | /* CQ work will be processed on CPU affinitized to this IRQ */ |
| 13645 | if (!queue_work(phba->wq, &cq->irqwork)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13646 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13647 | "0367 Cannot schedule soft IRQ " |
| 13648 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13649 | cqid, cq->queue_id, smp_processor_id()); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13650 | } |
| 13651 | |
| 13652 | /** |
| 13653 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device |
| 13654 | * @irq: Interrupt number. |
| 13655 | * @dev_id: The device context pointer. |
| 13656 | * |
| 13657 | * This function is directly called from the PCI layer as an interrupt |
| 13658 | * service routine when device with SLI-4 interface spec is enabled with |
| 13659 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric |
| 13660 | * IOCB ring event in the HBA. However, when the device is enabled with either |
| 13661 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 13662 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 13663 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 13664 | * process the interrupt. The Flash Optimized Fabric ring event are handled in |
| 13665 | * the intrrupt context. This function is called without any lock held. |
| 13666 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 13667 | * the EQ to CQ are one-to-one map such that the EQ index is |
| 13668 | * equal to that of CQ index. |
| 13669 | * |
| 13670 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 13671 | * returns IRQ_NONE. |
| 13672 | **/ |
| 13673 | irqreturn_t |
| 13674 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) |
| 13675 | { |
| 13676 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13677 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13678 | struct lpfc_queue *eq; |
| 13679 | struct lpfc_eqe *eqe; |
| 13680 | unsigned long iflag; |
| 13681 | int ecount = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13682 | |
| 13683 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13684 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 13685 | phba = hba_eq_hdl->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13686 | |
| 13687 | if (unlikely(!phba)) |
| 13688 | return IRQ_NONE; |
| 13689 | |
| 13690 | /* Get to the EQ struct associated with this vector */ |
| 13691 | eq = phba->sli4_hba.fof_eq; |
| 13692 | if (unlikely(!eq)) |
| 13693 | return IRQ_NONE; |
| 13694 | |
| 13695 | /* Check device state for handling interrupt */ |
| 13696 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13697 | /* Check again for link_state with lock held */ |
| 13698 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 13699 | if (phba->link_state < LPFC_LINK_DOWN) |
| 13700 | /* Flush, clear interrupt, and rearm the EQ */ |
| 13701 | lpfc_sli4_eq_flush(phba, eq); |
| 13702 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 13703 | return IRQ_NONE; |
| 13704 | } |
| 13705 | |
| 13706 | /* |
| 13707 | * Process all the event on FCP fast-path EQ |
| 13708 | */ |
| 13709 | while ((eqe = lpfc_sli4_eq_get(eq))) { |
| 13710 | lpfc_sli4_fof_handle_eqe(phba, eqe); |
| 13711 | if (!(++ecount % eq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13712 | break; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13713 | eq->EQ_processed++; |
| 13714 | } |
| 13715 | |
| 13716 | /* Track the max number of EQEs processed in 1 intr */ |
| 13717 | if (ecount > eq->EQ_max_eqe) |
| 13718 | eq->EQ_max_eqe = ecount; |
| 13719 | |
| 13720 | |
| 13721 | if (unlikely(ecount == 0)) { |
| 13722 | eq->EQ_no_entry++; |
| 13723 | |
| 13724 | if (phba->intr_type == MSIX) |
| 13725 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 13726 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13727 | "9145 MSI-X interrupt with no EQE\n"); |
| 13728 | else { |
| 13729 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13730 | "9146 ISR interrupt with no EQE\n"); |
| 13731 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 13732 | return IRQ_NONE; |
| 13733 | } |
| 13734 | } |
| 13735 | /* Always clear and re-arm the fast-path EQ */ |
| 13736 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 13737 | return IRQ_HANDLED; |
| 13738 | } |
| 13739 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13740 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13741 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13742 | * @irq: Interrupt number. |
| 13743 | * @dev_id: The device context pointer. |
| 13744 | * |
| 13745 | * This function is directly called from the PCI layer as an interrupt |
| 13746 | * service routine when device with SLI-4 interface spec is enabled with |
| 13747 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 13748 | * ring event in the HBA. However, when the device is enabled with either |
| 13749 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 13750 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 13751 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 13752 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 13753 | * the intrrupt context. This function is called without any lock held. |
| 13754 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 13755 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 13756 | * equal to that of FCP CQ index. |
| 13757 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13758 | * The link attention and ELS ring attention events are handled |
| 13759 | * by the worker thread. The interrupt handler signals the worker thread |
| 13760 | * and returns for these events. This function is called without any lock |
| 13761 | * held. It gets the hbalock to access and update SLI data structures. |
| 13762 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13763 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 13764 | * returns IRQ_NONE. |
| 13765 | **/ |
| 13766 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13767 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13768 | { |
| 13769 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13770 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13771 | struct lpfc_queue *fpeq; |
| 13772 | struct lpfc_eqe *eqe; |
| 13773 | unsigned long iflag; |
| 13774 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13775 | int hba_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13776 | |
| 13777 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13778 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 13779 | phba = hba_eq_hdl->phba; |
| 13780 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13781 | |
| 13782 | if (unlikely(!phba)) |
| 13783 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13784 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 13785 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13786 | |
| 13787 | /* Get to the EQ struct associated with this vector */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13788 | fpeq = phba->sli4_hba.hba_eq[hba_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13789 | if (unlikely(!fpeq)) |
| 13790 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13791 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13792 | if (lpfc_fcp_look_ahead) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13793 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13794 | lpfc_sli4_eq_clr_intr(fpeq); |
| 13795 | else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13796 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13797 | return IRQ_NONE; |
| 13798 | } |
| 13799 | } |
| 13800 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13801 | /* Check device state for handling interrupt */ |
| 13802 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 13803 | /* Check again for link_state with lock held */ |
| 13804 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 13805 | if (phba->link_state < LPFC_LINK_DOWN) |
| 13806 | /* Flush, clear interrupt, and rearm the EQ */ |
| 13807 | lpfc_sli4_eq_flush(phba, fpeq); |
| 13808 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13809 | if (lpfc_fcp_look_ahead) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13810 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13811 | return IRQ_NONE; |
| 13812 | } |
| 13813 | |
| 13814 | /* |
| 13815 | * Process all the event on FCP fast-path EQ |
| 13816 | */ |
| 13817 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13818 | lpfc_sli4_hba_handle_eqe(phba, eqe, hba_eqidx); |
| 13819 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13820 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13821 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13822 | } |
| 13823 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13824 | /* Track the max number of EQEs processed in 1 intr */ |
| 13825 | if (ecount > fpeq->EQ_max_eqe) |
| 13826 | fpeq->EQ_max_eqe = ecount; |
| 13827 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13828 | /* Always clear and re-arm the fast-path EQ */ |
| 13829 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 13830 | |
| 13831 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13832 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13833 | |
| 13834 | if (lpfc_fcp_look_ahead) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13835 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13836 | return IRQ_NONE; |
| 13837 | } |
| 13838 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13839 | if (phba->intr_type == MSIX) |
| 13840 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 13841 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13842 | "0358 MSI-X interrupt with no EQE\n"); |
| 13843 | else |
| 13844 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 13845 | return IRQ_NONE; |
| 13846 | } |
| 13847 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13848 | if (lpfc_fcp_look_ahead) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13849 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
| 13850 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13851 | return IRQ_HANDLED; |
| 13852 | } /* lpfc_sli4_fp_intr_handler */ |
| 13853 | |
| 13854 | /** |
| 13855 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 13856 | * @irq: Interrupt number. |
| 13857 | * @dev_id: The device context pointer. |
| 13858 | * |
| 13859 | * This function is the device-level interrupt handler to device with SLI-4 |
| 13860 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 13861 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 13862 | * driver attention. This function invokes the slow-path interrupt attention |
| 13863 | * handling function and fast-path interrupt attention handling function in |
| 13864 | * turn to process the relevant HBA attention events. This function is called |
| 13865 | * without any lock held. It gets the hbalock to access and update SLI data |
| 13866 | * structures. |
| 13867 | * |
| 13868 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 13869 | * returns IRQ_NONE. |
| 13870 | **/ |
| 13871 | irqreturn_t |
| 13872 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 13873 | { |
| 13874 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13875 | irqreturn_t hba_irq_rc; |
| 13876 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13877 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13878 | |
| 13879 | /* Get the driver's phba structure from the dev_id */ |
| 13880 | phba = (struct lpfc_hba *)dev_id; |
| 13881 | |
| 13882 | if (unlikely(!phba)) |
| 13883 | return IRQ_NONE; |
| 13884 | |
| 13885 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13886 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 13887 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13888 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13889 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13890 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13891 | if (hba_irq_rc == IRQ_HANDLED) |
| 13892 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13893 | } |
| 13894 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13895 | if (phba->cfg_fof) { |
| 13896 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13897 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13898 | if (hba_irq_rc == IRQ_HANDLED) |
| 13899 | hba_handled |= true; |
| 13900 | } |
| 13901 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13902 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13903 | } /* lpfc_sli4_intr_handler */ |
| 13904 | |
| 13905 | /** |
| 13906 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 13907 | * @queue: The queue structure to free. |
| 13908 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 13909 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13910 | * the host resident queue. This function must be called after destroying the |
| 13911 | * queue on the HBA. |
| 13912 | **/ |
| 13913 | void |
| 13914 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 13915 | { |
| 13916 | struct lpfc_dmabuf *dmabuf; |
| 13917 | |
| 13918 | if (!queue) |
| 13919 | return; |
| 13920 | |
| 13921 | while (!list_empty(&queue->page_list)) { |
| 13922 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 13923 | list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 13924 | dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13925 | dmabuf->virt, dmabuf->phys); |
| 13926 | kfree(dmabuf); |
| 13927 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13928 | if (queue->rqbp) { |
| 13929 | lpfc_free_rq_buffer(queue->phba, queue); |
| 13930 | kfree(queue->rqbp); |
| 13931 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 13932 | |
| 13933 | if (!list_empty(&queue->wq_list)) |
| 13934 | list_del(&queue->wq_list); |
| 13935 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13936 | kfree(queue); |
| 13937 | return; |
| 13938 | } |
| 13939 | |
| 13940 | /** |
| 13941 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 13942 | * @phba: The HBA that this queue is being created on. |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 13943 | * @page_size: The size of a queue page |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13944 | * @entry_size: The size of each queue entry for this queue. |
| 13945 | * @entry count: The number of entries that this queue will handle. |
| 13946 | * |
| 13947 | * This function allocates a queue structure and the DMAable memory used for |
| 13948 | * the host resident queue. This function must be called before creating the |
| 13949 | * queue on the HBA. |
| 13950 | **/ |
| 13951 | struct lpfc_queue * |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 13952 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size, |
| 13953 | uint32_t entry_size, uint32_t entry_count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13954 | { |
| 13955 | struct lpfc_queue *queue; |
| 13956 | struct lpfc_dmabuf *dmabuf; |
| 13957 | int x, total_qe_count; |
| 13958 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13959 | 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] | 13960 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13961 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 13962 | hw_page_size = page_size; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13963 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13964 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 13965 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 13966 | if (!queue) |
| 13967 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13968 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 13969 | hw_page_size))/hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13970 | |
| 13971 | /* If needed, Adjust page count to match the max the adapter supports */ |
| 13972 | if (queue->page_count > phba->sli4_hba.pc_sli4_params.wqpcnt) |
| 13973 | queue->page_count = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 13974 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13975 | INIT_LIST_HEAD(&queue->list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13976 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 6e8e1c1 | 2018-01-30 15:58:49 -0800 | [diff] [blame] | 13977 | INIT_LIST_HEAD(&queue->wqfull_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13978 | INIT_LIST_HEAD(&queue->page_list); |
| 13979 | INIT_LIST_HEAD(&queue->child_list); |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 13980 | |
| 13981 | /* Set queue parameters now. If the system cannot provide memory |
| 13982 | * resources, the free routine needs to know what was allocated. |
| 13983 | */ |
| 13984 | queue->entry_size = entry_size; |
| 13985 | queue->entry_count = entry_count; |
| 13986 | queue->page_size = hw_page_size; |
| 13987 | queue->phba = phba; |
| 13988 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13989 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 13990 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 13991 | if (!dmabuf) |
| 13992 | goto out_fail; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 13993 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 13994 | hw_page_size, &dmabuf->phys, |
| 13995 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13996 | if (!dmabuf->virt) { |
| 13997 | kfree(dmabuf); |
| 13998 | goto out_fail; |
| 13999 | } |
| 14000 | dmabuf->buffer_tag = x; |
| 14001 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 14002 | /* initialize queue's entry array */ |
| 14003 | dma_pointer = dmabuf->virt; |
| 14004 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 14005 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14006 | total_qe_count++, dma_pointer += entry_size) { |
| 14007 | queue->qe[total_qe_count].address = dma_pointer; |
| 14008 | } |
| 14009 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 14010 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 14011 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14012 | |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14013 | /* entry_repost will be set during q creation */ |
| 14014 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14015 | return queue; |
| 14016 | out_fail: |
| 14017 | lpfc_sli4_queue_free(queue); |
| 14018 | return NULL; |
| 14019 | } |
| 14020 | |
| 14021 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14022 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 14023 | * @phba: HBA structure that indicates port to create a queue on. |
| 14024 | * @pci_barset: PCI BAR set flag. |
| 14025 | * |
| 14026 | * This function shall perform iomap of the specified PCI BAR address to host |
| 14027 | * memory address if not already done so and return it. The returned host |
| 14028 | * memory address can be NULL. |
| 14029 | */ |
| 14030 | static void __iomem * |
| 14031 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 14032 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14033 | if (!phba->pcidev) |
| 14034 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14035 | |
| 14036 | switch (pci_barset) { |
| 14037 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14038 | return phba->pci_bar0_memmap_p; |
| 14039 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14040 | return phba->pci_bar2_memmap_p; |
| 14041 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14042 | return phba->pci_bar4_memmap_p; |
| 14043 | default: |
| 14044 | break; |
| 14045 | } |
| 14046 | return NULL; |
| 14047 | } |
| 14048 | |
| 14049 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14050 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on FCP EQs |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14051 | * @phba: HBA structure that indicates port to create a queue on. |
| 14052 | * @startq: The starting FCP EQ to modify |
| 14053 | * |
| 14054 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 14055 | * The command allows up to LPFC_MAX_EQ_DELAY_EQID_CNT EQ ID's to be |
| 14056 | * updated in one mailbox command. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14057 | * |
| 14058 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 14059 | * is used to get the starting FCP EQ to change. |
| 14060 | * This function is asynchronous and will wait for the mailbox |
| 14061 | * command to finish before continuing. |
| 14062 | * |
| 14063 | * On success this function will return a zero. If unable to allocate enough |
| 14064 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14065 | * fails this function will return -ENXIO. |
| 14066 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14067 | int |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14068 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
| 14069 | uint32_t numq, uint32_t imax) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14070 | { |
| 14071 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14072 | LPFC_MBOXQ_t *mbox; |
| 14073 | struct lpfc_queue *eq; |
| 14074 | int cnt, rc, length, status = 0; |
| 14075 | uint32_t shdr_status, shdr_add_status; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14076 | uint32_t result, val; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14077 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14078 | union lpfc_sli4_cfg_shdr *shdr; |
| 14079 | uint16_t dmult; |
| 14080 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14081 | if (startq >= phba->io_channel_irqs) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14082 | return 0; |
| 14083 | |
| 14084 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14085 | if (!mbox) |
| 14086 | return -ENOMEM; |
| 14087 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14088 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14089 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14090 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14091 | length, LPFC_SLI4_MBX_EMBED); |
| 14092 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14093 | |
| 14094 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14095 | result = imax / phba->io_channel_irqs; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14096 | if (result > LPFC_DMULT_CONST || result == 0) |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14097 | dmult = 0; |
| 14098 | else |
| 14099 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14100 | if (dmult > LPFC_DMULT_MAX) |
| 14101 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14102 | |
| 14103 | cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14104 | for (qidx = startq; qidx < phba->io_channel_irqs; qidx++) { |
| 14105 | eq = phba->sli4_hba.hba_eq[qidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14106 | if (!eq) |
| 14107 | continue; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14108 | eq->q_mode = imax; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14109 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14110 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14111 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 14112 | cnt++; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14113 | |
| 14114 | /* q_mode is only used for auto_imax */ |
| 14115 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14116 | /* Use EQ Delay Register method for q_mode */ |
| 14117 | |
| 14118 | /* Convert for EQ Delay register */ |
| 14119 | val = phba->cfg_fcp_imax; |
| 14120 | if (val) { |
| 14121 | /* First, interrupts per sec per EQ */ |
| 14122 | val = phba->cfg_fcp_imax / |
| 14123 | phba->io_channel_irqs; |
| 14124 | |
| 14125 | /* us delay between each interrupt */ |
| 14126 | val = LPFC_SEC_TO_USEC / val; |
| 14127 | } |
| 14128 | eq->q_mode = val; |
| 14129 | } else { |
| 14130 | eq->q_mode = imax; |
| 14131 | } |
| 14132 | |
| 14133 | if (cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14134 | break; |
| 14135 | } |
| 14136 | eq_delay->u.request.num_eq = cnt; |
| 14137 | |
| 14138 | mbox->vport = phba->pport; |
| 14139 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14140 | mbox->context1 = NULL; |
| 14141 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14142 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 14143 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14144 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14145 | if (shdr_status || shdr_add_status || rc) { |
| 14146 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14147 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 14148 | "status x%x add_status x%x, mbx status x%x\n", |
| 14149 | shdr_status, shdr_add_status, rc); |
| 14150 | status = -ENXIO; |
| 14151 | } |
| 14152 | mempool_free(mbox, phba->mbox_mem_pool); |
| 14153 | return status; |
| 14154 | } |
| 14155 | |
| 14156 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14157 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 14158 | * @phba: HBA structure that indicates port to create a queue on. |
| 14159 | * @eq: The queue structure to use to create the event queue. |
| 14160 | * @imax: The maximum interrupt per second limit. |
| 14161 | * |
| 14162 | * This function creates an event queue, as detailed in @eq, on a port, |
| 14163 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 14164 | * |
| 14165 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 14166 | * is used to get the entry count and entry size that are necessary to |
| 14167 | * determine the number of pages to allocate and use for this queue. This |
| 14168 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 14169 | * event queue. This function is asynchronous and will wait for the mailbox |
| 14170 | * command to finish before continuing. |
| 14171 | * |
| 14172 | * 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] | 14173 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14174 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14175 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14176 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14177 | 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] | 14178 | { |
| 14179 | struct lpfc_mbx_eq_create *eq_create; |
| 14180 | LPFC_MBOXQ_t *mbox; |
| 14181 | int rc, length, status = 0; |
| 14182 | struct lpfc_dmabuf *dmabuf; |
| 14183 | uint32_t shdr_status, shdr_add_status; |
| 14184 | union lpfc_sli4_cfg_shdr *shdr; |
| 14185 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14186 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14187 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14188 | /* sanity check on queue memory */ |
| 14189 | if (!eq) |
| 14190 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14191 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14192 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14193 | |
| 14194 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14195 | if (!mbox) |
| 14196 | return -ENOMEM; |
| 14197 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 14198 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14199 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14200 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 14201 | length, LPFC_SLI4_MBX_EMBED); |
| 14202 | eq_create = &mbox->u.mqe.un.eq_create; |
| 14203 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 14204 | eq->page_count); |
| 14205 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 14206 | LPFC_EQE_SIZE); |
| 14207 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 14208 | /* don't setup delay multiplier using EQ_CREATE */ |
| 14209 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14210 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 14211 | dmult); |
| 14212 | switch (eq->entry_count) { |
| 14213 | default: |
| 14214 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14215 | "0360 Unsupported EQ count. (%d)\n", |
| 14216 | eq->entry_count); |
| 14217 | if (eq->entry_count < 256) |
| 14218 | return -EINVAL; |
| 14219 | /* otherwise default to smallest count (drop through) */ |
| 14220 | case 256: |
| 14221 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14222 | LPFC_EQ_CNT_256); |
| 14223 | break; |
| 14224 | case 512: |
| 14225 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14226 | LPFC_EQ_CNT_512); |
| 14227 | break; |
| 14228 | case 1024: |
| 14229 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14230 | LPFC_EQ_CNT_1024); |
| 14231 | break; |
| 14232 | case 2048: |
| 14233 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14234 | LPFC_EQ_CNT_2048); |
| 14235 | break; |
| 14236 | case 4096: |
| 14237 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14238 | LPFC_EQ_CNT_4096); |
| 14239 | break; |
| 14240 | } |
| 14241 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14242 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14243 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14244 | putPaddrLow(dmabuf->phys); |
| 14245 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14246 | putPaddrHigh(dmabuf->phys); |
| 14247 | } |
| 14248 | mbox->vport = phba->pport; |
| 14249 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14250 | mbox->context1 = NULL; |
| 14251 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14252 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 14253 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14254 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14255 | if (shdr_status || shdr_add_status || rc) { |
| 14256 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14257 | "2500 EQ_CREATE mailbox failed with " |
| 14258 | "status x%x add_status x%x, mbx status x%x\n", |
| 14259 | shdr_status, shdr_add_status, rc); |
| 14260 | status = -ENXIO; |
| 14261 | } |
| 14262 | eq->type = LPFC_EQ; |
| 14263 | eq->subtype = LPFC_NONE; |
| 14264 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 14265 | if (eq->queue_id == 0xFFFF) |
| 14266 | status = -ENXIO; |
| 14267 | eq->host_index = 0; |
| 14268 | eq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14269 | eq->entry_repost = LPFC_EQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14270 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14271 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14272 | return status; |
| 14273 | } |
| 14274 | |
| 14275 | /** |
| 14276 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 14277 | * @phba: HBA structure that indicates port to create a queue on. |
| 14278 | * @cq: The queue structure to use to create the completion queue. |
| 14279 | * @eq: The event queue to bind this completion queue to. |
| 14280 | * |
| 14281 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 14282 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 14283 | * |
| 14284 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14285 | * is used to get the entry count and entry size that are necessary to |
| 14286 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14287 | * is used to indicate which event queue to bind this completion queue to. This |
| 14288 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 14289 | * completion queue. 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 |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 14293 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14294 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14295 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14296 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14297 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14298 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 14299 | { |
| 14300 | struct lpfc_mbx_cq_create *cq_create; |
| 14301 | struct lpfc_dmabuf *dmabuf; |
| 14302 | LPFC_MBOXQ_t *mbox; |
| 14303 | int rc, length, status = 0; |
| 14304 | uint32_t shdr_status, shdr_add_status; |
| 14305 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14306 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14307 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14308 | /* sanity check on queue memory */ |
| 14309 | if (!cq || !eq) |
| 14310 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14311 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14312 | hw_page_size = cq->page_size; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14313 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14314 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14315 | if (!mbox) |
| 14316 | return -ENOMEM; |
| 14317 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 14318 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14319 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14320 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 14321 | length, LPFC_SLI4_MBX_EMBED); |
| 14322 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14323 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14324 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 14325 | cq->page_count); |
| 14326 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 14327 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14328 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14329 | phba->sli4_hba.pc_sli4_params.cqv); |
| 14330 | 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] | 14331 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, |
| 14332 | (cq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14333 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 14334 | eq->queue_id); |
| 14335 | } else { |
| 14336 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 14337 | eq->queue_id); |
| 14338 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14339 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14340 | case 2048: |
| 14341 | case 4096: |
| 14342 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14343 | LPFC_Q_CREATE_VERSION_2) { |
| 14344 | cq_create->u.request.context.lpfc_cq_context_count = |
| 14345 | cq->entry_count; |
| 14346 | bf_set(lpfc_cq_context_count, |
| 14347 | &cq_create->u.request.context, |
| 14348 | LPFC_CQ_CNT_WORD7); |
| 14349 | break; |
| 14350 | } |
| 14351 | /* Fall Thru */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14352 | default: |
| 14353 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14354 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14355 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14356 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14357 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14358 | if (cq->entry_count < 256) { |
| 14359 | status = -EINVAL; |
| 14360 | goto out; |
| 14361 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14362 | /* otherwise default to smallest count (drop through) */ |
| 14363 | case 256: |
| 14364 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14365 | LPFC_CQ_CNT_256); |
| 14366 | break; |
| 14367 | case 512: |
| 14368 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14369 | LPFC_CQ_CNT_512); |
| 14370 | break; |
| 14371 | case 1024: |
| 14372 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14373 | LPFC_CQ_CNT_1024); |
| 14374 | break; |
| 14375 | } |
| 14376 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14377 | memset(dmabuf->virt, 0, cq->page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14378 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14379 | putPaddrLow(dmabuf->phys); |
| 14380 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14381 | putPaddrHigh(dmabuf->phys); |
| 14382 | } |
| 14383 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14384 | |
| 14385 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14386 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14387 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14388 | if (shdr_status || shdr_add_status || rc) { |
| 14389 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14390 | "2501 CQ_CREATE mailbox failed with " |
| 14391 | "status x%x add_status x%x, mbx status x%x\n", |
| 14392 | shdr_status, shdr_add_status, rc); |
| 14393 | status = -ENXIO; |
| 14394 | goto out; |
| 14395 | } |
| 14396 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 14397 | if (cq->queue_id == 0xFFFF) { |
| 14398 | status = -ENXIO; |
| 14399 | goto out; |
| 14400 | } |
| 14401 | /* link the cq onto the parent eq child list */ |
| 14402 | list_add_tail(&cq->list, &eq->child_list); |
| 14403 | /* Set up completion queue's type and subtype */ |
| 14404 | cq->type = type; |
| 14405 | cq->subtype = subtype; |
| 14406 | 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] | 14407 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14408 | cq->host_index = 0; |
| 14409 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14410 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14411 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14412 | out: |
| 14413 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14414 | return status; |
| 14415 | } |
| 14416 | |
| 14417 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14418 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 14419 | * @phba: HBA structure that indicates port to create a queue on. |
| 14420 | * @cqp: The queue structure array to use to create the completion queues. |
| 14421 | * @eqp: The event queue array to bind these completion queues to. |
| 14422 | * |
| 14423 | * This function creates a set of completion queue, s to support MRQ |
| 14424 | * as detailed in @cqp, on a port, |
| 14425 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 14426 | * |
| 14427 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14428 | * is used to get the entry count and entry size that are necessary to |
| 14429 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14430 | * is used to indicate which event queue to bind this completion queue to. This |
| 14431 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 14432 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14433 | * command to finish before continuing. |
| 14434 | * |
| 14435 | * On success this function will return a zero. If unable to allocate enough |
| 14436 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14437 | * fails this function will return -ENXIO. |
| 14438 | **/ |
| 14439 | int |
| 14440 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
| 14441 | struct lpfc_queue **eqp, uint32_t type, uint32_t subtype) |
| 14442 | { |
| 14443 | struct lpfc_queue *cq; |
| 14444 | struct lpfc_queue *eq; |
| 14445 | struct lpfc_mbx_cq_create_set *cq_set; |
| 14446 | struct lpfc_dmabuf *dmabuf; |
| 14447 | LPFC_MBOXQ_t *mbox; |
| 14448 | int rc, length, alloclen, status = 0; |
| 14449 | int cnt, idx, numcq, page_idx = 0; |
| 14450 | uint32_t shdr_status, shdr_add_status; |
| 14451 | union lpfc_sli4_cfg_shdr *shdr; |
| 14452 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14453 | |
| 14454 | /* sanity check on queue memory */ |
| 14455 | numcq = phba->cfg_nvmet_mrq; |
| 14456 | if (!cqp || !eqp || !numcq) |
| 14457 | return -ENODEV; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14458 | |
| 14459 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14460 | if (!mbox) |
| 14461 | return -ENOMEM; |
| 14462 | |
| 14463 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 14464 | length += ((numcq * cqp[0]->page_count) * |
| 14465 | sizeof(struct dma_address)); |
| 14466 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14467 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 14468 | LPFC_SLI4_MBX_NEMBED); |
| 14469 | if (alloclen < length) { |
| 14470 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14471 | "3098 Allocated DMA memory size (%d) is " |
| 14472 | "less than the requested DMA memory size " |
| 14473 | "(%d)\n", alloclen, length); |
| 14474 | status = -ENOMEM; |
| 14475 | goto out; |
| 14476 | } |
| 14477 | cq_set = mbox->sge_array->addr[0]; |
| 14478 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 14479 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 14480 | |
| 14481 | for (idx = 0; idx < numcq; idx++) { |
| 14482 | cq = cqp[idx]; |
| 14483 | eq = eqp[idx]; |
| 14484 | if (!cq || !eq) { |
| 14485 | status = -ENOMEM; |
| 14486 | goto out; |
| 14487 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14488 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14489 | hw_page_size = cq->page_size; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14490 | |
| 14491 | switch (idx) { |
| 14492 | case 0: |
| 14493 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 14494 | &cq_set->u.request, |
| 14495 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 14496 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 14497 | &cq_set->u.request, cq->page_count); |
| 14498 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 14499 | &cq_set->u.request, 1); |
| 14500 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 14501 | &cq_set->u.request, 1); |
| 14502 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 14503 | &cq_set->u.request, 0); |
| 14504 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 14505 | &cq_set->u.request, numcq); |
| 14506 | switch (cq->entry_count) { |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14507 | case 2048: |
| 14508 | case 4096: |
| 14509 | if (phba->sli4_hba.pc_sli4_params.cqv == |
| 14510 | LPFC_Q_CREATE_VERSION_2) { |
| 14511 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14512 | &cq_set->u.request, |
| 14513 | cq->entry_count); |
| 14514 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14515 | &cq_set->u.request, |
| 14516 | LPFC_CQ_CNT_WORD7); |
| 14517 | break; |
| 14518 | } |
| 14519 | /* Fall Thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14520 | default: |
| 14521 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14522 | "3118 Bad CQ count. (%d)\n", |
| 14523 | cq->entry_count); |
| 14524 | if (cq->entry_count < 256) { |
| 14525 | status = -EINVAL; |
| 14526 | goto out; |
| 14527 | } |
| 14528 | /* otherwise default to smallest (drop thru) */ |
| 14529 | case 256: |
| 14530 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14531 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 14532 | break; |
| 14533 | case 512: |
| 14534 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14535 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 14536 | break; |
| 14537 | case 1024: |
| 14538 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14539 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 14540 | break; |
| 14541 | } |
| 14542 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 14543 | &cq_set->u.request, eq->queue_id); |
| 14544 | break; |
| 14545 | case 1: |
| 14546 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 14547 | &cq_set->u.request, eq->queue_id); |
| 14548 | break; |
| 14549 | case 2: |
| 14550 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 14551 | &cq_set->u.request, eq->queue_id); |
| 14552 | break; |
| 14553 | case 3: |
| 14554 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 14555 | &cq_set->u.request, eq->queue_id); |
| 14556 | break; |
| 14557 | case 4: |
| 14558 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 14559 | &cq_set->u.request, eq->queue_id); |
| 14560 | break; |
| 14561 | case 5: |
| 14562 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 14563 | &cq_set->u.request, eq->queue_id); |
| 14564 | break; |
| 14565 | case 6: |
| 14566 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 14567 | &cq_set->u.request, eq->queue_id); |
| 14568 | break; |
| 14569 | case 7: |
| 14570 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 14571 | &cq_set->u.request, eq->queue_id); |
| 14572 | break; |
| 14573 | case 8: |
| 14574 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 14575 | &cq_set->u.request, eq->queue_id); |
| 14576 | break; |
| 14577 | case 9: |
| 14578 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 14579 | &cq_set->u.request, eq->queue_id); |
| 14580 | break; |
| 14581 | case 10: |
| 14582 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 14583 | &cq_set->u.request, eq->queue_id); |
| 14584 | break; |
| 14585 | case 11: |
| 14586 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 14587 | &cq_set->u.request, eq->queue_id); |
| 14588 | break; |
| 14589 | case 12: |
| 14590 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 14591 | &cq_set->u.request, eq->queue_id); |
| 14592 | break; |
| 14593 | case 13: |
| 14594 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 14595 | &cq_set->u.request, eq->queue_id); |
| 14596 | break; |
| 14597 | case 14: |
| 14598 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 14599 | &cq_set->u.request, eq->queue_id); |
| 14600 | break; |
| 14601 | case 15: |
| 14602 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 14603 | &cq_set->u.request, eq->queue_id); |
| 14604 | break; |
| 14605 | } |
| 14606 | |
| 14607 | /* link the cq onto the parent eq child list */ |
| 14608 | list_add_tail(&cq->list, &eq->child_list); |
| 14609 | /* Set up completion queue's type and subtype */ |
| 14610 | cq->type = type; |
| 14611 | cq->subtype = subtype; |
| 14612 | cq->assoc_qid = eq->queue_id; |
| 14613 | cq->host_index = 0; |
| 14614 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14615 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14616 | cq->chann = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14617 | |
| 14618 | rc = 0; |
| 14619 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 14620 | memset(dmabuf->virt, 0, hw_page_size); |
| 14621 | cnt = page_idx + dmabuf->buffer_tag; |
| 14622 | cq_set->u.request.page[cnt].addr_lo = |
| 14623 | putPaddrLow(dmabuf->phys); |
| 14624 | cq_set->u.request.page[cnt].addr_hi = |
| 14625 | putPaddrHigh(dmabuf->phys); |
| 14626 | rc++; |
| 14627 | } |
| 14628 | page_idx += rc; |
| 14629 | } |
| 14630 | |
| 14631 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14632 | |
| 14633 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14634 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14635 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14636 | if (shdr_status || shdr_add_status || rc) { |
| 14637 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14638 | "3119 CQ_CREATE_SET mailbox failed with " |
| 14639 | "status x%x add_status x%x, mbx status x%x\n", |
| 14640 | shdr_status, shdr_add_status, rc); |
| 14641 | status = -ENXIO; |
| 14642 | goto out; |
| 14643 | } |
| 14644 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 14645 | if (rc == 0xFFFF) { |
| 14646 | status = -ENXIO; |
| 14647 | goto out; |
| 14648 | } |
| 14649 | |
| 14650 | for (idx = 0; idx < numcq; idx++) { |
| 14651 | cq = cqp[idx]; |
| 14652 | cq->queue_id = rc + idx; |
| 14653 | } |
| 14654 | |
| 14655 | out: |
| 14656 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14657 | return status; |
| 14658 | } |
| 14659 | |
| 14660 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14661 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14662 | * @phba: HBA structure that indicates port to create a queue on. |
| 14663 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14664 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 14665 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14666 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14667 | * This function provides failback (fb) functionality when the |
| 14668 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 14669 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14670 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14671 | * This routine cannot fail as all attributes were previously accessed and |
| 14672 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14673 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14674 | static void |
| 14675 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 14676 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14677 | { |
| 14678 | struct lpfc_mbx_mq_create *mq_create; |
| 14679 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14680 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14681 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14682 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 14683 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14684 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14685 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 14686 | length, LPFC_SLI4_MBX_EMBED); |
| 14687 | mq_create = &mbox->u.mqe.un.mq_create; |
| 14688 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14689 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14690 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14691 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14692 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 14693 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14694 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14695 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14696 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14697 | break; |
| 14698 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14699 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14700 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14701 | break; |
| 14702 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14703 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14704 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14705 | break; |
| 14706 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14707 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14708 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14709 | break; |
| 14710 | } |
| 14711 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 14712 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14713 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14714 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14715 | putPaddrHigh(dmabuf->phys); |
| 14716 | } |
| 14717 | } |
| 14718 | |
| 14719 | /** |
| 14720 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 14721 | * @phba: HBA structure that indicates port to create a queue on. |
| 14722 | * @mq: The queue structure to use to create the mailbox queue. |
| 14723 | * @cq: The completion queue to associate with this cq. |
| 14724 | * @subtype: The queue's subtype. |
| 14725 | * |
| 14726 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 14727 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 14728 | * |
| 14729 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14730 | * is used to get the entry count and entry size that are necessary to |
| 14731 | * determine the number of pages to allocate and use for this queue. This |
| 14732 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 14733 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 14734 | * command to finish before continuing. |
| 14735 | * |
| 14736 | * 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] | 14737 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14738 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14739 | **/ |
| 14740 | int32_t |
| 14741 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 14742 | struct lpfc_queue *cq, uint32_t subtype) |
| 14743 | { |
| 14744 | struct lpfc_mbx_mq_create *mq_create; |
| 14745 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 14746 | struct lpfc_dmabuf *dmabuf; |
| 14747 | LPFC_MBOXQ_t *mbox; |
| 14748 | int rc, length, status = 0; |
| 14749 | uint32_t shdr_status, shdr_add_status; |
| 14750 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14751 | 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] | 14752 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14753 | /* sanity check on queue memory */ |
| 14754 | if (!mq || !cq) |
| 14755 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14756 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14757 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14758 | |
| 14759 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14760 | if (!mbox) |
| 14761 | return -ENOMEM; |
| 14762 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 14763 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14764 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14765 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 14766 | length, LPFC_SLI4_MBX_EMBED); |
| 14767 | |
| 14768 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14769 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 14770 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 14771 | &mq_create_ext->u.request, mq->page_count); |
| 14772 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 14773 | &mq_create_ext->u.request, 1); |
| 14774 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14775 | &mq_create_ext->u.request, 1); |
| 14776 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 14777 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 14778 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 14779 | &mq_create_ext->u.request, 1); |
| 14780 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 14781 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14782 | 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] | 14783 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14784 | phba->sli4_hba.pc_sli4_params.mqv); |
| 14785 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 14786 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 14787 | cq->queue_id); |
| 14788 | else |
| 14789 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 14790 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14791 | switch (mq->entry_count) { |
| 14792 | default: |
| 14793 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14794 | "0362 Unsupported MQ count. (%d)\n", |
| 14795 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14796 | if (mq->entry_count < 16) { |
| 14797 | status = -EINVAL; |
| 14798 | goto out; |
| 14799 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14800 | /* otherwise default to smallest count (drop through) */ |
| 14801 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14802 | bf_set(lpfc_mq_context_ring_size, |
| 14803 | &mq_create_ext->u.request.context, |
| 14804 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14805 | break; |
| 14806 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14807 | bf_set(lpfc_mq_context_ring_size, |
| 14808 | &mq_create_ext->u.request.context, |
| 14809 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14810 | break; |
| 14811 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14812 | bf_set(lpfc_mq_context_ring_size, |
| 14813 | &mq_create_ext->u.request.context, |
| 14814 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14815 | break; |
| 14816 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14817 | bf_set(lpfc_mq_context_ring_size, |
| 14818 | &mq_create_ext->u.request.context, |
| 14819 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14820 | break; |
| 14821 | } |
| 14822 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14823 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14824 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14825 | putPaddrLow(dmabuf->phys); |
| 14826 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14827 | putPaddrHigh(dmabuf->phys); |
| 14828 | } |
| 14829 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14830 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 14831 | &mq_create_ext->u.response); |
| 14832 | if (rc != MBX_SUCCESS) { |
| 14833 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 14834 | "2795 MQ_CREATE_EXT failed with " |
| 14835 | "status x%x. Failback to MQ_CREATE.\n", |
| 14836 | rc); |
| 14837 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 14838 | mq_create = &mbox->u.mqe.un.mq_create; |
| 14839 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14840 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 14841 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 14842 | &mq_create->u.response); |
| 14843 | } |
| 14844 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14845 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14846 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14847 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14848 | if (shdr_status || shdr_add_status || rc) { |
| 14849 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14850 | "2502 MQ_CREATE mailbox failed with " |
| 14851 | "status x%x add_status x%x, mbx status x%x\n", |
| 14852 | shdr_status, shdr_add_status, rc); |
| 14853 | status = -ENXIO; |
| 14854 | goto out; |
| 14855 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14856 | if (mq->queue_id == 0xFFFF) { |
| 14857 | status = -ENXIO; |
| 14858 | goto out; |
| 14859 | } |
| 14860 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 14861 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14862 | mq->subtype = subtype; |
| 14863 | mq->host_index = 0; |
| 14864 | mq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14865 | mq->entry_repost = LPFC_MQ_REPOST; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14866 | |
| 14867 | /* link the mq onto the parent cq child list */ |
| 14868 | list_add_tail(&mq->list, &cq->child_list); |
| 14869 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14870 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14871 | return status; |
| 14872 | } |
| 14873 | |
| 14874 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14875 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 14876 | * @phba: HBA structure that indicates port to create a queue on. |
| 14877 | * @wq: The queue structure to use to create the work queue. |
| 14878 | * @cq: The completion queue to bind this work queue to. |
| 14879 | * @subtype: The subtype of the work queue indicating its functionality. |
| 14880 | * |
| 14881 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 14882 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 14883 | * |
| 14884 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 14885 | * is used to get the entry count and entry size that are necessary to |
| 14886 | * determine the number of pages to allocate and use for this queue. The @cq |
| 14887 | * is used to indicate which completion queue to bind this work queue to. This |
| 14888 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 14889 | * work queue. This function is asynchronous and will wait for the mailbox |
| 14890 | * command to finish before continuing. |
| 14891 | * |
| 14892 | * 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] | 14893 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14894 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14895 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14896 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14897 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 14898 | struct lpfc_queue *cq, uint32_t subtype) |
| 14899 | { |
| 14900 | struct lpfc_mbx_wq_create *wq_create; |
| 14901 | struct lpfc_dmabuf *dmabuf; |
| 14902 | LPFC_MBOXQ_t *mbox; |
| 14903 | int rc, length, status = 0; |
| 14904 | uint32_t shdr_status, shdr_add_status; |
| 14905 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14906 | 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] | 14907 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14908 | void __iomem *bar_memmap_p; |
| 14909 | uint32_t db_offset; |
| 14910 | uint16_t pci_barset; |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14911 | uint8_t wq_create_version; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14912 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14913 | /* sanity check on queue memory */ |
| 14914 | if (!wq || !cq) |
| 14915 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14916 | if (!phba->sli4_hba.pc_sli4_params.supported) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14917 | hw_page_size = wq->page_size; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14918 | |
| 14919 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14920 | if (!mbox) |
| 14921 | return -ENOMEM; |
| 14922 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 14923 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14924 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14925 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 14926 | length, LPFC_SLI4_MBX_EMBED); |
| 14927 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14928 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14929 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 14930 | wq->page_count); |
| 14931 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 14932 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14933 | |
| 14934 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14935 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14936 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14937 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 14938 | if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) || |
| 14939 | (wq->page_size > SLI4_PAGE_SIZE)) |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 14940 | wq_create_version = LPFC_Q_CREATE_VERSION_1; |
| 14941 | else |
| 14942 | wq_create_version = LPFC_Q_CREATE_VERSION_0; |
| 14943 | |
| 14944 | switch (wq_create_version) { |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14945 | case LPFC_Q_CREATE_VERSION_0: |
| 14946 | switch (wq->entry_size) { |
| 14947 | default: |
| 14948 | case 64: |
| 14949 | /* Nothing to do, version 0 ONLY supports 64 byte */ |
| 14950 | page = wq_create->u.request.page; |
| 14951 | break; |
| 14952 | case 128: |
| 14953 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 14954 | LPFC_WQ_SZ128_SUPPORT)) { |
| 14955 | status = -ERANGE; |
| 14956 | goto out; |
| 14957 | } |
| 14958 | /* If we get here the HBA MUST also support V1 and |
| 14959 | * we MUST use it |
| 14960 | */ |
| 14961 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14962 | LPFC_Q_CREATE_VERSION_1); |
| 14963 | |
| 14964 | bf_set(lpfc_mbx_wq_create_wqe_count, |
| 14965 | &wq_create->u.request_1, wq->entry_count); |
| 14966 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 14967 | &wq_create->u.request_1, |
| 14968 | LPFC_WQ_WQE_SIZE_128); |
| 14969 | bf_set(lpfc_mbx_wq_create_page_size, |
| 14970 | &wq_create->u.request_1, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 14971 | LPFC_WQ_PAGE_SIZE_4096); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14972 | page = wq_create->u.request_1.page; |
| 14973 | break; |
| 14974 | } |
| 14975 | break; |
| 14976 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14977 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 14978 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 14979 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14980 | LPFC_Q_CREATE_VERSION_1); |
| 14981 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14982 | switch (wq->entry_size) { |
| 14983 | default: |
| 14984 | case 64: |
| 14985 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 14986 | &wq_create->u.request_1, |
| 14987 | LPFC_WQ_WQE_SIZE_64); |
| 14988 | break; |
| 14989 | case 128: |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14990 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 14991 | LPFC_WQ_SZ128_SUPPORT)) { |
| 14992 | status = -ERANGE; |
| 14993 | goto out; |
| 14994 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14995 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 14996 | &wq_create->u.request_1, |
| 14997 | LPFC_WQ_WQE_SIZE_128); |
| 14998 | break; |
| 14999 | } |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15000 | bf_set(lpfc_mbx_wq_create_page_size, |
| 15001 | &wq_create->u.request_1, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 15002 | (wq->page_size / SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15003 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15004 | break; |
| 15005 | default: |
| 15006 | status = -ERANGE; |
| 15007 | goto out; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15008 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 15009 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15010 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15011 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15012 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 15013 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15014 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15015 | |
| 15016 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15017 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 15018 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15019 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15020 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15021 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15022 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15023 | if (shdr_status || shdr_add_status || rc) { |
| 15024 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15025 | "2503 WQ_CREATE mailbox failed with " |
| 15026 | "status x%x add_status x%x, mbx status x%x\n", |
| 15027 | shdr_status, shdr_add_status, rc); |
| 15028 | status = -ENXIO; |
| 15029 | goto out; |
| 15030 | } |
| 15031 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 15032 | if (wq->queue_id == 0xFFFF) { |
| 15033 | status = -ENXIO; |
| 15034 | goto out; |
| 15035 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15036 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15037 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 15038 | &wq_create->u.response); |
| 15039 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15040 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15041 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15042 | "3265 WQ[%d] doorbell format not " |
| 15043 | "supported: x%x\n", wq->queue_id, |
| 15044 | wq->db_format); |
| 15045 | status = -EINVAL; |
| 15046 | goto out; |
| 15047 | } |
| 15048 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 15049 | &wq_create->u.response); |
| 15050 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15051 | if (!bar_memmap_p) { |
| 15052 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15053 | "3263 WQ[%d] failed to memmap pci " |
| 15054 | "barset:x%x\n", wq->queue_id, |
| 15055 | pci_barset); |
| 15056 | status = -ENOMEM; |
| 15057 | goto out; |
| 15058 | } |
| 15059 | db_offset = wq_create->u.response.doorbell_offset; |
| 15060 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 15061 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 15062 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15063 | "3252 WQ[%d] doorbell offset not " |
| 15064 | "supported: x%x\n", wq->queue_id, |
| 15065 | db_offset); |
| 15066 | status = -EINVAL; |
| 15067 | goto out; |
| 15068 | } |
| 15069 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15070 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15071 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15072 | "format:x%x\n", wq->queue_id, pci_barset, |
| 15073 | db_offset, wq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15074 | } else { |
| 15075 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15076 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
| 15077 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15078 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 15079 | if (wq->pring == NULL) { |
| 15080 | status = -ENOMEM; |
| 15081 | goto out; |
| 15082 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15083 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15084 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15085 | wq->subtype = subtype; |
| 15086 | wq->host_index = 0; |
| 15087 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 15088 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15089 | |
| 15090 | /* link the wq onto the parent cq child list */ |
| 15091 | list_add_tail(&wq->list, &cq->child_list); |
| 15092 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15093 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15094 | return status; |
| 15095 | } |
| 15096 | |
| 15097 | /** |
| 15098 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 15099 | * @phba: HBA structure that indicates port to create a queue on. |
| 15100 | * @hrq: The queue structure to use to create the header receive queue. |
| 15101 | * @drq: The queue structure to use to create the data receive queue. |
| 15102 | * @cq: The completion queue to bind this work queue to. |
| 15103 | * |
| 15104 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15105 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15106 | * to the HBA. |
| 15107 | * |
| 15108 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15109 | * struct is used to get the entry count that is necessary to determine the |
| 15110 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15111 | * completion queue to bind received buffers that are posted to these queues to. |
| 15112 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15113 | * receive queue pair. This function is asynchronous and will wait for the |
| 15114 | * mailbox command to finish before continuing. |
| 15115 | * |
| 15116 | * 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] | 15117 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15118 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15119 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15120 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15121 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15122 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 15123 | { |
| 15124 | struct lpfc_mbx_rq_create *rq_create; |
| 15125 | struct lpfc_dmabuf *dmabuf; |
| 15126 | LPFC_MBOXQ_t *mbox; |
| 15127 | int rc, length, status = 0; |
| 15128 | uint32_t shdr_status, shdr_add_status; |
| 15129 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15130 | 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] | 15131 | void __iomem *bar_memmap_p; |
| 15132 | uint32_t db_offset; |
| 15133 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15134 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15135 | /* sanity check on queue memory */ |
| 15136 | if (!hrq || !drq || !cq) |
| 15137 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15138 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15139 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15140 | |
| 15141 | if (hrq->entry_count != drq->entry_count) |
| 15142 | return -EINVAL; |
| 15143 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15144 | if (!mbox) |
| 15145 | return -ENOMEM; |
| 15146 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 15147 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15148 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15149 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15150 | length, LPFC_SLI4_MBX_EMBED); |
| 15151 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15152 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15153 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15154 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15155 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15156 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15157 | &rq_create->u.request.context, |
| 15158 | hrq->entry_count); |
| 15159 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15160 | bf_set(lpfc_rq_context_rqe_size, |
| 15161 | &rq_create->u.request.context, |
| 15162 | LPFC_RQE_SIZE_8); |
| 15163 | bf_set(lpfc_rq_context_page_size, |
| 15164 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15165 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15166 | } else { |
| 15167 | switch (hrq->entry_count) { |
| 15168 | default: |
| 15169 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15170 | "2535 Unsupported RQ count. (%d)\n", |
| 15171 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15172 | if (hrq->entry_count < 512) { |
| 15173 | status = -EINVAL; |
| 15174 | goto out; |
| 15175 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15176 | /* otherwise default to smallest count (drop through) */ |
| 15177 | case 512: |
| 15178 | bf_set(lpfc_rq_context_rqe_count, |
| 15179 | &rq_create->u.request.context, |
| 15180 | LPFC_RQ_RING_SIZE_512); |
| 15181 | break; |
| 15182 | case 1024: |
| 15183 | bf_set(lpfc_rq_context_rqe_count, |
| 15184 | &rq_create->u.request.context, |
| 15185 | LPFC_RQ_RING_SIZE_1024); |
| 15186 | break; |
| 15187 | case 2048: |
| 15188 | bf_set(lpfc_rq_context_rqe_count, |
| 15189 | &rq_create->u.request.context, |
| 15190 | LPFC_RQ_RING_SIZE_2048); |
| 15191 | break; |
| 15192 | case 4096: |
| 15193 | bf_set(lpfc_rq_context_rqe_count, |
| 15194 | &rq_create->u.request.context, |
| 15195 | LPFC_RQ_RING_SIZE_4096); |
| 15196 | break; |
| 15197 | } |
| 15198 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 15199 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15200 | } |
| 15201 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15202 | cq->queue_id); |
| 15203 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15204 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15205 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15206 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15207 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15208 | putPaddrLow(dmabuf->phys); |
| 15209 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15210 | putPaddrHigh(dmabuf->phys); |
| 15211 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15212 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15213 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 15214 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15215 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15216 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15217 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15218 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15219 | if (shdr_status || shdr_add_status || rc) { |
| 15220 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15221 | "2504 RQ_CREATE mailbox failed with " |
| 15222 | "status x%x add_status x%x, mbx status x%x\n", |
| 15223 | shdr_status, shdr_add_status, rc); |
| 15224 | status = -ENXIO; |
| 15225 | goto out; |
| 15226 | } |
| 15227 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15228 | if (hrq->queue_id == 0xFFFF) { |
| 15229 | status = -ENXIO; |
| 15230 | goto out; |
| 15231 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15232 | |
| 15233 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15234 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 15235 | &rq_create->u.response); |
| 15236 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15237 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15238 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15239 | "3262 RQ [%d] doorbell format not " |
| 15240 | "supported: x%x\n", hrq->queue_id, |
| 15241 | hrq->db_format); |
| 15242 | status = -EINVAL; |
| 15243 | goto out; |
| 15244 | } |
| 15245 | |
| 15246 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 15247 | &rq_create->u.response); |
| 15248 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15249 | if (!bar_memmap_p) { |
| 15250 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15251 | "3269 RQ[%d] failed to memmap pci " |
| 15252 | "barset:x%x\n", hrq->queue_id, |
| 15253 | pci_barset); |
| 15254 | status = -ENOMEM; |
| 15255 | goto out; |
| 15256 | } |
| 15257 | |
| 15258 | db_offset = rq_create->u.response.doorbell_offset; |
| 15259 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 15260 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 15261 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15262 | "3270 RQ[%d] doorbell offset not " |
| 15263 | "supported: x%x\n", hrq->queue_id, |
| 15264 | db_offset); |
| 15265 | status = -EINVAL; |
| 15266 | goto out; |
| 15267 | } |
| 15268 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 15269 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15270 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 15271 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 15272 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15273 | } else { |
| 15274 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15275 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15276 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15277 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15278 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15279 | hrq->subtype = subtype; |
| 15280 | hrq->host_index = 0; |
| 15281 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15282 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15283 | |
| 15284 | /* now create the data queue */ |
| 15285 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15286 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15287 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15288 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15289 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15290 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15291 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15292 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15293 | if (subtype == LPFC_NVMET) |
| 15294 | rq_create->u.request.context.buffer_size = |
| 15295 | LPFC_NVMET_DATA_BUF_SIZE; |
| 15296 | else |
| 15297 | rq_create->u.request.context.buffer_size = |
| 15298 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15299 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 15300 | LPFC_RQE_SIZE_8); |
| 15301 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 15302 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15303 | } else { |
| 15304 | switch (drq->entry_count) { |
| 15305 | default: |
| 15306 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15307 | "2536 Unsupported RQ count. (%d)\n", |
| 15308 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15309 | if (drq->entry_count < 512) { |
| 15310 | status = -EINVAL; |
| 15311 | goto out; |
| 15312 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15313 | /* otherwise default to smallest count (drop through) */ |
| 15314 | case 512: |
| 15315 | bf_set(lpfc_rq_context_rqe_count, |
| 15316 | &rq_create->u.request.context, |
| 15317 | LPFC_RQ_RING_SIZE_512); |
| 15318 | break; |
| 15319 | case 1024: |
| 15320 | bf_set(lpfc_rq_context_rqe_count, |
| 15321 | &rq_create->u.request.context, |
| 15322 | LPFC_RQ_RING_SIZE_1024); |
| 15323 | break; |
| 15324 | case 2048: |
| 15325 | bf_set(lpfc_rq_context_rqe_count, |
| 15326 | &rq_create->u.request.context, |
| 15327 | LPFC_RQ_RING_SIZE_2048); |
| 15328 | break; |
| 15329 | case 4096: |
| 15330 | bf_set(lpfc_rq_context_rqe_count, |
| 15331 | &rq_create->u.request.context, |
| 15332 | LPFC_RQ_RING_SIZE_4096); |
| 15333 | break; |
| 15334 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15335 | if (subtype == LPFC_NVMET) |
| 15336 | bf_set(lpfc_rq_context_buf_size, |
| 15337 | &rq_create->u.request.context, |
| 15338 | LPFC_NVMET_DATA_BUF_SIZE); |
| 15339 | else |
| 15340 | bf_set(lpfc_rq_context_buf_size, |
| 15341 | &rq_create->u.request.context, |
| 15342 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15343 | } |
| 15344 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15345 | cq->queue_id); |
| 15346 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15347 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15348 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15349 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15350 | putPaddrLow(dmabuf->phys); |
| 15351 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15352 | putPaddrHigh(dmabuf->phys); |
| 15353 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15354 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15355 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15356 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15357 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15358 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15359 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15360 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15361 | if (shdr_status || shdr_add_status || rc) { |
| 15362 | status = -ENXIO; |
| 15363 | goto out; |
| 15364 | } |
| 15365 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15366 | if (drq->queue_id == 0xFFFF) { |
| 15367 | status = -ENXIO; |
| 15368 | goto out; |
| 15369 | } |
| 15370 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15371 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15372 | drq->subtype = subtype; |
| 15373 | drq->host_index = 0; |
| 15374 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15375 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15376 | |
| 15377 | /* link the header and data RQs onto the parent cq child list */ |
| 15378 | list_add_tail(&hrq->list, &cq->child_list); |
| 15379 | list_add_tail(&drq->list, &cq->child_list); |
| 15380 | |
| 15381 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15382 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15383 | return status; |
| 15384 | } |
| 15385 | |
| 15386 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15387 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 15388 | * @phba: HBA structure that indicates port to create a queue on. |
| 15389 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 15390 | * @drqp: The queue structure array to use to create the data receive queues. |
| 15391 | * @cqp: The completion queue array to bind these receive queues to. |
| 15392 | * |
| 15393 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15394 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15395 | * to the HBA. |
| 15396 | * |
| 15397 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15398 | * struct is used to get the entry count that is necessary to determine the |
| 15399 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15400 | * completion queue to bind received buffers that are posted to these queues to. |
| 15401 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15402 | * receive queue pair. This function is asynchronous and will wait for the |
| 15403 | * mailbox command to finish before continuing. |
| 15404 | * |
| 15405 | * On success this function will return a zero. If unable to allocate enough |
| 15406 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15407 | * fails this function will return -ENXIO. |
| 15408 | **/ |
| 15409 | int |
| 15410 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 15411 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 15412 | uint32_t subtype) |
| 15413 | { |
| 15414 | struct lpfc_queue *hrq, *drq, *cq; |
| 15415 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 15416 | struct lpfc_dmabuf *dmabuf; |
| 15417 | LPFC_MBOXQ_t *mbox; |
| 15418 | int rc, length, alloclen, status = 0; |
| 15419 | int cnt, idx, numrq, page_idx = 0; |
| 15420 | uint32_t shdr_status, shdr_add_status; |
| 15421 | union lpfc_sli4_cfg_shdr *shdr; |
| 15422 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15423 | |
| 15424 | numrq = phba->cfg_nvmet_mrq; |
| 15425 | /* sanity check on array memory */ |
| 15426 | if (!hrqp || !drqp || !cqp || !numrq) |
| 15427 | return -ENODEV; |
| 15428 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15429 | hw_page_size = SLI4_PAGE_SIZE; |
| 15430 | |
| 15431 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15432 | if (!mbox) |
| 15433 | return -ENOMEM; |
| 15434 | |
| 15435 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 15436 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 15437 | sizeof(struct dma_address)); |
| 15438 | |
| 15439 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15440 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 15441 | LPFC_SLI4_MBX_NEMBED); |
| 15442 | if (alloclen < length) { |
| 15443 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15444 | "3099 Allocated DMA memory size (%d) is " |
| 15445 | "less than the requested DMA memory size " |
| 15446 | "(%d)\n", alloclen, length); |
| 15447 | status = -ENOMEM; |
| 15448 | goto out; |
| 15449 | } |
| 15450 | |
| 15451 | |
| 15452 | |
| 15453 | rq_create = mbox->sge_array->addr[0]; |
| 15454 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 15455 | |
| 15456 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 15457 | cnt = 0; |
| 15458 | |
| 15459 | for (idx = 0; idx < numrq; idx++) { |
| 15460 | hrq = hrqp[idx]; |
| 15461 | drq = drqp[idx]; |
| 15462 | cq = cqp[idx]; |
| 15463 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15464 | /* sanity check on queue memory */ |
| 15465 | if (!hrq || !drq || !cq) { |
| 15466 | status = -ENODEV; |
| 15467 | goto out; |
| 15468 | } |
| 15469 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 15470 | if (hrq->entry_count != drq->entry_count) { |
| 15471 | status = -EINVAL; |
| 15472 | goto out; |
| 15473 | } |
| 15474 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15475 | if (idx == 0) { |
| 15476 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 15477 | &rq_create->u.request, |
| 15478 | hrq->page_count); |
| 15479 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 15480 | &rq_create->u.request, (numrq * 2)); |
| 15481 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 15482 | 1); |
| 15483 | bf_set(lpfc_rq_context_base_cq, |
| 15484 | &rq_create->u.request.context, |
| 15485 | cq->queue_id); |
| 15486 | bf_set(lpfc_rq_context_data_size, |
| 15487 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15488 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15489 | bf_set(lpfc_rq_context_hdr_size, |
| 15490 | &rq_create->u.request.context, |
| 15491 | LPFC_HDR_BUF_SIZE); |
| 15492 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15493 | &rq_create->u.request.context, |
| 15494 | hrq->entry_count); |
| 15495 | bf_set(lpfc_rq_context_rqe_size, |
| 15496 | &rq_create->u.request.context, |
| 15497 | LPFC_RQE_SIZE_8); |
| 15498 | bf_set(lpfc_rq_context_page_size, |
| 15499 | &rq_create->u.request.context, |
| 15500 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 15501 | } |
| 15502 | rc = 0; |
| 15503 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 15504 | memset(dmabuf->virt, 0, hw_page_size); |
| 15505 | cnt = page_idx + dmabuf->buffer_tag; |
| 15506 | rq_create->u.request.page[cnt].addr_lo = |
| 15507 | putPaddrLow(dmabuf->phys); |
| 15508 | rq_create->u.request.page[cnt].addr_hi = |
| 15509 | putPaddrHigh(dmabuf->phys); |
| 15510 | rc++; |
| 15511 | } |
| 15512 | page_idx += rc; |
| 15513 | |
| 15514 | rc = 0; |
| 15515 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15516 | memset(dmabuf->virt, 0, hw_page_size); |
| 15517 | cnt = page_idx + dmabuf->buffer_tag; |
| 15518 | rq_create->u.request.page[cnt].addr_lo = |
| 15519 | putPaddrLow(dmabuf->phys); |
| 15520 | rq_create->u.request.page[cnt].addr_hi = |
| 15521 | putPaddrHigh(dmabuf->phys); |
| 15522 | rc++; |
| 15523 | } |
| 15524 | page_idx += rc; |
| 15525 | |
| 15526 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15527 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15528 | hrq->type = LPFC_HRQ; |
| 15529 | hrq->assoc_qid = cq->queue_id; |
| 15530 | hrq->subtype = subtype; |
| 15531 | hrq->host_index = 0; |
| 15532 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15533 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15534 | |
| 15535 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 15536 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15537 | drq->type = LPFC_DRQ; |
| 15538 | drq->assoc_qid = cq->queue_id; |
| 15539 | drq->subtype = subtype; |
| 15540 | drq->host_index = 0; |
| 15541 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15542 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15543 | |
| 15544 | list_add_tail(&hrq->list, &cq->child_list); |
| 15545 | list_add_tail(&drq->list, &cq->child_list); |
| 15546 | } |
| 15547 | |
| 15548 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15549 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15550 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15551 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15552 | if (shdr_status || shdr_add_status || rc) { |
| 15553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15554 | "3120 RQ_CREATE mailbox failed with " |
| 15555 | "status x%x add_status x%x, mbx status x%x\n", |
| 15556 | shdr_status, shdr_add_status, rc); |
| 15557 | status = -ENXIO; |
| 15558 | goto out; |
| 15559 | } |
| 15560 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15561 | if (rc == 0xFFFF) { |
| 15562 | status = -ENXIO; |
| 15563 | goto out; |
| 15564 | } |
| 15565 | |
| 15566 | /* Initialize all RQs with associated queue id */ |
| 15567 | for (idx = 0; idx < numrq; idx++) { |
| 15568 | hrq = hrqp[idx]; |
| 15569 | hrq->queue_id = rc + (2 * idx); |
| 15570 | drq = drqp[idx]; |
| 15571 | drq->queue_id = rc + (2 * idx) + 1; |
| 15572 | } |
| 15573 | |
| 15574 | out: |
| 15575 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15576 | return status; |
| 15577 | } |
| 15578 | |
| 15579 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15580 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 15581 | * @eq: The queue structure associated with the queue to destroy. |
| 15582 | * |
| 15583 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 15584 | * command, specific to the type of queue, to the HBA. |
| 15585 | * |
| 15586 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 15587 | * |
| 15588 | * 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] | 15589 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15590 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15591 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15592 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 15593 | { |
| 15594 | LPFC_MBOXQ_t *mbox; |
| 15595 | int rc, length, status = 0; |
| 15596 | uint32_t shdr_status, shdr_add_status; |
| 15597 | union lpfc_sli4_cfg_shdr *shdr; |
| 15598 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15599 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15600 | if (!eq) |
| 15601 | return -ENODEV; |
| 15602 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15603 | if (!mbox) |
| 15604 | return -ENOMEM; |
| 15605 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 15606 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15607 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15608 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 15609 | length, LPFC_SLI4_MBX_EMBED); |
| 15610 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 15611 | eq->queue_id); |
| 15612 | mbox->vport = eq->phba->pport; |
| 15613 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15614 | |
| 15615 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 15616 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15617 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15618 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 15619 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15620 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15621 | if (shdr_status || shdr_add_status || rc) { |
| 15622 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15623 | "2505 EQ_DESTROY mailbox failed with " |
| 15624 | "status x%x add_status x%x, mbx status x%x\n", |
| 15625 | shdr_status, shdr_add_status, rc); |
| 15626 | status = -ENXIO; |
| 15627 | } |
| 15628 | |
| 15629 | /* Remove eq from any list */ |
| 15630 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15631 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15632 | return status; |
| 15633 | } |
| 15634 | |
| 15635 | /** |
| 15636 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 15637 | * @cq: The queue structure associated with the queue to destroy. |
| 15638 | * |
| 15639 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 15640 | * command, specific to the type of queue, to the HBA. |
| 15641 | * |
| 15642 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 15643 | * |
| 15644 | * 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] | 15645 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15646 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15647 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15648 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 15649 | { |
| 15650 | LPFC_MBOXQ_t *mbox; |
| 15651 | int rc, length, status = 0; |
| 15652 | uint32_t shdr_status, shdr_add_status; |
| 15653 | union lpfc_sli4_cfg_shdr *shdr; |
| 15654 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15655 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15656 | if (!cq) |
| 15657 | return -ENODEV; |
| 15658 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15659 | if (!mbox) |
| 15660 | return -ENOMEM; |
| 15661 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 15662 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15663 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15664 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 15665 | length, LPFC_SLI4_MBX_EMBED); |
| 15666 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 15667 | cq->queue_id); |
| 15668 | mbox->vport = cq->phba->pport; |
| 15669 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15670 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 15671 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15672 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15673 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 15674 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15675 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15676 | if (shdr_status || shdr_add_status || rc) { |
| 15677 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15678 | "2506 CQ_DESTROY mailbox failed with " |
| 15679 | "status x%x add_status x%x, mbx status x%x\n", |
| 15680 | shdr_status, shdr_add_status, rc); |
| 15681 | status = -ENXIO; |
| 15682 | } |
| 15683 | /* Remove cq from any list */ |
| 15684 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15685 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15686 | return status; |
| 15687 | } |
| 15688 | |
| 15689 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15690 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 15691 | * @qm: The queue structure associated with the queue to destroy. |
| 15692 | * |
| 15693 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 15694 | * command, specific to the type of queue, to the HBA. |
| 15695 | * |
| 15696 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 15697 | * |
| 15698 | * 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] | 15699 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15700 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15701 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15702 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 15703 | { |
| 15704 | LPFC_MBOXQ_t *mbox; |
| 15705 | int rc, length, status = 0; |
| 15706 | uint32_t shdr_status, shdr_add_status; |
| 15707 | union lpfc_sli4_cfg_shdr *shdr; |
| 15708 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15709 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15710 | if (!mq) |
| 15711 | return -ENODEV; |
| 15712 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15713 | if (!mbox) |
| 15714 | return -ENOMEM; |
| 15715 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 15716 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15717 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15718 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 15719 | length, LPFC_SLI4_MBX_EMBED); |
| 15720 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 15721 | mq->queue_id); |
| 15722 | mbox->vport = mq->phba->pport; |
| 15723 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15724 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 15725 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15726 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15727 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 15728 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15729 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15730 | if (shdr_status || shdr_add_status || rc) { |
| 15731 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15732 | "2507 MQ_DESTROY mailbox failed with " |
| 15733 | "status x%x add_status x%x, mbx status x%x\n", |
| 15734 | shdr_status, shdr_add_status, rc); |
| 15735 | status = -ENXIO; |
| 15736 | } |
| 15737 | /* Remove mq from any list */ |
| 15738 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15739 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15740 | return status; |
| 15741 | } |
| 15742 | |
| 15743 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15744 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 15745 | * @wq: The queue structure associated with the queue to destroy. |
| 15746 | * |
| 15747 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 15748 | * command, specific to the type of queue, to the HBA. |
| 15749 | * |
| 15750 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 15751 | * |
| 15752 | * 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] | 15753 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15754 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15755 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15756 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 15757 | { |
| 15758 | LPFC_MBOXQ_t *mbox; |
| 15759 | int rc, length, status = 0; |
| 15760 | uint32_t shdr_status, shdr_add_status; |
| 15761 | union lpfc_sli4_cfg_shdr *shdr; |
| 15762 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15763 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15764 | if (!wq) |
| 15765 | return -ENODEV; |
| 15766 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15767 | if (!mbox) |
| 15768 | return -ENOMEM; |
| 15769 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 15770 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15771 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15772 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 15773 | length, LPFC_SLI4_MBX_EMBED); |
| 15774 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 15775 | wq->queue_id); |
| 15776 | mbox->vport = wq->phba->pport; |
| 15777 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15778 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 15779 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15780 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 15781 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15782 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15783 | if (shdr_status || shdr_add_status || rc) { |
| 15784 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15785 | "2508 WQ_DESTROY mailbox failed with " |
| 15786 | "status x%x add_status x%x, mbx status x%x\n", |
| 15787 | shdr_status, shdr_add_status, rc); |
| 15788 | status = -ENXIO; |
| 15789 | } |
| 15790 | /* Remove wq from any list */ |
| 15791 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 15792 | kfree(wq->pring); |
| 15793 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15794 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15795 | return status; |
| 15796 | } |
| 15797 | |
| 15798 | /** |
| 15799 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 15800 | * @rq: The queue structure associated with the queue to destroy. |
| 15801 | * |
| 15802 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 15803 | * command, specific to the type of queue, to the HBA. |
| 15804 | * |
| 15805 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 15806 | * |
| 15807 | * 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] | 15808 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15809 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15810 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15811 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15812 | struct lpfc_queue *drq) |
| 15813 | { |
| 15814 | LPFC_MBOXQ_t *mbox; |
| 15815 | int rc, length, status = 0; |
| 15816 | uint32_t shdr_status, shdr_add_status; |
| 15817 | union lpfc_sli4_cfg_shdr *shdr; |
| 15818 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15819 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15820 | if (!hrq || !drq) |
| 15821 | return -ENODEV; |
| 15822 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15823 | if (!mbox) |
| 15824 | return -ENOMEM; |
| 15825 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 15826 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15827 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15828 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 15829 | length, LPFC_SLI4_MBX_EMBED); |
| 15830 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 15831 | hrq->queue_id); |
| 15832 | mbox->vport = hrq->phba->pport; |
| 15833 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15834 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 15835 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15836 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15837 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 15838 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15839 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15840 | if (shdr_status || shdr_add_status || rc) { |
| 15841 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15842 | "2509 RQ_DESTROY mailbox failed with " |
| 15843 | "status x%x add_status x%x, mbx status x%x\n", |
| 15844 | shdr_status, shdr_add_status, rc); |
| 15845 | if (rc != MBX_TIMEOUT) |
| 15846 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 15847 | return -ENXIO; |
| 15848 | } |
| 15849 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 15850 | drq->queue_id); |
| 15851 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 15852 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15853 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 15854 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15855 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15856 | if (shdr_status || shdr_add_status || rc) { |
| 15857 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15858 | "2510 RQ_DESTROY mailbox failed with " |
| 15859 | "status x%x add_status x%x, mbx status x%x\n", |
| 15860 | shdr_status, shdr_add_status, rc); |
| 15861 | status = -ENXIO; |
| 15862 | } |
| 15863 | list_del_init(&hrq->list); |
| 15864 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15865 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15866 | return status; |
| 15867 | } |
| 15868 | |
| 15869 | /** |
| 15870 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 15871 | * @phba: The virtual port for which this call being executed. |
| 15872 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 15873 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 15874 | * @xritag: the xritag that ties this io to the SGL pages. |
| 15875 | * |
| 15876 | * This routine will post the sgl pages for the IO that has the xritag |
| 15877 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 15878 | * creation and persists for as long as the driver is loaded. |
| 15879 | * if the caller has fewer than 256 scatter gather segments to map then |
| 15880 | * pdma_phys_addr1 should be 0. |
| 15881 | * If the caller needs to map more than 256 scatter gather segment then |
| 15882 | * pdma_phys_addr1 should be a valid physical address. |
| 15883 | * physical address for SGLs must be 64 byte aligned. |
| 15884 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 15885 | * the second sgl can have between 1 and 256 entries. |
| 15886 | * |
| 15887 | * Return codes: |
| 15888 | * 0 - Success |
| 15889 | * -ENXIO, -ENOMEM - Failure |
| 15890 | **/ |
| 15891 | int |
| 15892 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 15893 | dma_addr_t pdma_phys_addr0, |
| 15894 | dma_addr_t pdma_phys_addr1, |
| 15895 | uint16_t xritag) |
| 15896 | { |
| 15897 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 15898 | LPFC_MBOXQ_t *mbox; |
| 15899 | int rc; |
| 15900 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15901 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15902 | union lpfc_sli4_cfg_shdr *shdr; |
| 15903 | |
| 15904 | if (xritag == NO_XRI) { |
| 15905 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15906 | "0364 Invalid param:\n"); |
| 15907 | return -EINVAL; |
| 15908 | } |
| 15909 | |
| 15910 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15911 | if (!mbox) |
| 15912 | return -ENOMEM; |
| 15913 | |
| 15914 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15915 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 15916 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 15917 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15918 | |
| 15919 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 15920 | &mbox->u.mqe.un.post_sgl_pages; |
| 15921 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 15922 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 15923 | |
| 15924 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 15925 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 15926 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 15927 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 15928 | |
| 15929 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 15930 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 15931 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 15932 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 15933 | if (!phba->sli4_hba.intr_enable) |
| 15934 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15935 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 15936 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15937 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 15938 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15939 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15940 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 15941 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15942 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15943 | if (rc != MBX_TIMEOUT) |
| 15944 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15945 | if (shdr_status || shdr_add_status || rc) { |
| 15946 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15947 | "2511 POST_SGL mailbox failed with " |
| 15948 | "status x%x add_status x%x, mbx status x%x\n", |
| 15949 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15950 | } |
| 15951 | return 0; |
| 15952 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15953 | |
| 15954 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 15955 | * 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] | 15956 | * @phba: pointer to lpfc hba data structure. |
| 15957 | * |
| 15958 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 15959 | * HBA consistent with the SLI-4 interface spec. This routine |
| 15960 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15961 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15962 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 15963 | * Returns |
| 15964 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 15965 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 15966 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 15967 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15968 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 15969 | { |
| 15970 | unsigned long xri; |
| 15971 | |
| 15972 | /* |
| 15973 | * Fetch the next logical xri. Because this index is logical, |
| 15974 | * the driver starts at 0 each time. |
| 15975 | */ |
| 15976 | spin_lock_irq(&phba->hbalock); |
| 15977 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 15978 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 15979 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 15980 | spin_unlock_irq(&phba->hbalock); |
| 15981 | return NO_XRI; |
| 15982 | } else { |
| 15983 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 15984 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15985 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15986 | spin_unlock_irq(&phba->hbalock); |
| 15987 | return xri; |
| 15988 | } |
| 15989 | |
| 15990 | /** |
| 15991 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 15992 | * @phba: pointer to lpfc hba data structure. |
| 15993 | * |
| 15994 | * This routine is invoked to release an xri to the pool of |
| 15995 | * available rpis maintained by the driver. |
| 15996 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 15997 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15998 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 15999 | { |
| 16000 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16001 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 16002 | } |
| 16003 | } |
| 16004 | |
| 16005 | /** |
| 16006 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 16007 | * @phba: pointer to lpfc hba data structure. |
| 16008 | * |
| 16009 | * This routine is invoked to release an xri to the pool of |
| 16010 | * available rpis maintained by the driver. |
| 16011 | **/ |
| 16012 | void |
| 16013 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 16014 | { |
| 16015 | spin_lock_irq(&phba->hbalock); |
| 16016 | __lpfc_sli4_free_xri(phba, xri); |
| 16017 | spin_unlock_irq(&phba->hbalock); |
| 16018 | } |
| 16019 | |
| 16020 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16021 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 16022 | * @phba: Pointer to HBA context object. |
| 16023 | * |
| 16024 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 16025 | * it will return 0xffff. |
| 16026 | * The function returns the allocated xritag if successful, else returns zero. |
| 16027 | * Zero is not a valid xritag. |
| 16028 | * The caller is not required to hold any lock. |
| 16029 | **/ |
| 16030 | uint16_t |
| 16031 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 16032 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16033 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16034 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16035 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 16036 | if (xri_index == NO_XRI) |
| 16037 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 16038 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 16039 | " Max XRI is %d, Used XRI is %d\n", |
| 16040 | xri_index, |
| 16041 | phba->sli4_hba.max_cfg_param.max_xri, |
| 16042 | phba->sli4_hba.max_cfg_param.xri_used); |
| 16043 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16044 | } |
| 16045 | |
| 16046 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16047 | * 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] | 16048 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16049 | * @post_sgl_list: pointer to els sgl entry list. |
| 16050 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16051 | * |
| 16052 | * This routine is invoked to post a block of driver's sgl pages to the |
| 16053 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 16054 | * is only called when the driver is loading and after all IO has been |
| 16055 | * stopped. |
| 16056 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16057 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16058 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16059 | struct list_head *post_sgl_list, |
| 16060 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16061 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16062 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16063 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16064 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16065 | void *viraddr; |
| 16066 | LPFC_MBOXQ_t *mbox; |
| 16067 | uint32_t reqlen, alloclen, pg_pairs; |
| 16068 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16069 | uint16_t xritag_start = 0; |
| 16070 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16071 | uint32_t shdr_status, shdr_add_status; |
| 16072 | union lpfc_sli4_cfg_shdr *shdr; |
| 16073 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16074 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16075 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16076 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16077 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16078 | "2559 Block sgl registration required DMA " |
| 16079 | "size (%d) great than a page\n", reqlen); |
| 16080 | return -ENOMEM; |
| 16081 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16082 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16083 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16084 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16085 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16086 | |
| 16087 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16088 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16089 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16090 | LPFC_SLI4_MBX_NEMBED); |
| 16091 | |
| 16092 | if (alloclen < reqlen) { |
| 16093 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16094 | "0285 Allocated DMA memory size (%d) is " |
| 16095 | "less than the requested DMA memory " |
| 16096 | "size (%d)\n", alloclen, reqlen); |
| 16097 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16098 | return -ENOMEM; |
| 16099 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16100 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16101 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16102 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16103 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16104 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16105 | pg_pairs = 0; |
| 16106 | 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] | 16107 | /* Set up the sge entry */ |
| 16108 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16109 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 16110 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16111 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 16112 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16113 | cpu_to_le32(putPaddrLow(0)); |
| 16114 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16115 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16116 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16117 | /* Keep the first xritag on the list */ |
| 16118 | if (pg_pairs == 0) |
| 16119 | xritag_start = sglq_entry->sli4_xritag; |
| 16120 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16121 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16122 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16123 | |
| 16124 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16125 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16126 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16127 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16128 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16129 | if (!phba->sli4_hba.intr_enable) |
| 16130 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16131 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16132 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16133 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16134 | } |
| 16135 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16136 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16137 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16138 | if (rc != MBX_TIMEOUT) |
| 16139 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16140 | if (shdr_status || shdr_add_status || rc) { |
| 16141 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16142 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 16143 | "status x%x add_status x%x mbx status x%x\n", |
| 16144 | shdr_status, shdr_add_status, rc); |
| 16145 | rc = -ENXIO; |
| 16146 | } |
| 16147 | return rc; |
| 16148 | } |
| 16149 | |
| 16150 | /** |
| 16151 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 16152 | * @phba: pointer to lpfc hba data structure. |
| 16153 | * @sblist: pointer to scsi buffer list. |
| 16154 | * @count: number of scsi buffers on the list. |
| 16155 | * |
| 16156 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 16157 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 16158 | * No Lock is held. |
| 16159 | * |
| 16160 | **/ |
| 16161 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16162 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 16163 | struct list_head *sblist, |
| 16164 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16165 | { |
| 16166 | struct lpfc_scsi_buf *psb; |
| 16167 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16168 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16169 | void *viraddr; |
| 16170 | LPFC_MBOXQ_t *mbox; |
| 16171 | uint32_t reqlen, alloclen, pg_pairs; |
| 16172 | uint32_t mbox_tmo; |
| 16173 | uint16_t xritag_start = 0; |
| 16174 | int rc = 0; |
| 16175 | uint32_t shdr_status, shdr_add_status; |
| 16176 | dma_addr_t pdma_phys_bpl1; |
| 16177 | union lpfc_sli4_cfg_shdr *shdr; |
| 16178 | |
| 16179 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16180 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16181 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16182 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16183 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 16184 | "0217 Block sgl registration required DMA " |
| 16185 | "size (%d) great than a page\n", reqlen); |
| 16186 | return -ENOMEM; |
| 16187 | } |
| 16188 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16189 | if (!mbox) { |
| 16190 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16191 | "0283 Failed to allocate mbox cmd memory\n"); |
| 16192 | return -ENOMEM; |
| 16193 | } |
| 16194 | |
| 16195 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16196 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16197 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16198 | LPFC_SLI4_MBX_NEMBED); |
| 16199 | |
| 16200 | if (alloclen < reqlen) { |
| 16201 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16202 | "2561 Allocated DMA memory size (%d) is " |
| 16203 | "less than the requested DMA memory " |
| 16204 | "size (%d)\n", alloclen, reqlen); |
| 16205 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16206 | return -ENOMEM; |
| 16207 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16208 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16209 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16210 | viraddr = mbox->sge_array->addr[0]; |
| 16211 | |
| 16212 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 16213 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16214 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16215 | |
| 16216 | pg_pairs = 0; |
| 16217 | list_for_each_entry(psb, sblist, list) { |
| 16218 | /* Set up the sge entry */ |
| 16219 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16220 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 16221 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16222 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 16223 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 16224 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 16225 | else |
| 16226 | pdma_phys_bpl1 = 0; |
| 16227 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16228 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 16229 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16230 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 16231 | /* Keep the first xritag on the list */ |
| 16232 | if (pg_pairs == 0) |
| 16233 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 16234 | sgl_pg_pairs++; |
| 16235 | pg_pairs++; |
| 16236 | } |
| 16237 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 16238 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 16239 | /* Perform endian conversion if necessary */ |
| 16240 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 16241 | |
| 16242 | if (!phba->sli4_hba.intr_enable) |
| 16243 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16244 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16245 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16246 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16247 | } |
| 16248 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16249 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16250 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16251 | if (rc != MBX_TIMEOUT) |
| 16252 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16253 | if (shdr_status || shdr_add_status || rc) { |
| 16254 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16255 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 16256 | "status x%x add_status x%x mbx status x%x\n", |
| 16257 | shdr_status, shdr_add_status, rc); |
| 16258 | rc = -ENXIO; |
| 16259 | } |
| 16260 | return rc; |
| 16261 | } |
| 16262 | |
| 16263 | /** |
| 16264 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 16265 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 16266 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16267 | * |
| 16268 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 16269 | * valid type of frame that the LPFC driver will handle. This function will |
| 16270 | * return a zero if the frame is a valid frame or a non zero value when the |
| 16271 | * frame does not pass the check. |
| 16272 | **/ |
| 16273 | static int |
| 16274 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 16275 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 16276 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16277 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16278 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16279 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16280 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 16281 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16282 | switch (fc_hdr->fh_r_ctl) { |
| 16283 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 16284 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 16285 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 16286 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 16287 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 16288 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 16289 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 16290 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 16291 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 16292 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 16293 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 16294 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 16295 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 16296 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 16297 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 16298 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 16299 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 16300 | case FC_RCTL_BA_PRMT: |
| 16301 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 16302 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 16303 | case FC_RCTL_P_RJT: /* port reject */ |
| 16304 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 16305 | case FC_RCTL_P_BSY: /* port busy */ |
| 16306 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 16307 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 16308 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16309 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16310 | case FC_RCTL_END: /* end */ |
| 16311 | break; |
| 16312 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 16313 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16314 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 16315 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 16316 | default: |
| 16317 | goto drop; |
| 16318 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16319 | |
| 16320 | #define FC_TYPE_VENDOR_UNIQUE 0xFF |
| 16321 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16322 | switch (fc_hdr->fh_type) { |
| 16323 | case FC_TYPE_BLS: |
| 16324 | case FC_TYPE_ELS: |
| 16325 | case FC_TYPE_FCP: |
| 16326 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16327 | case FC_TYPE_NVME: |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16328 | case FC_TYPE_VENDOR_UNIQUE: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16329 | break; |
| 16330 | case FC_TYPE_IP: |
| 16331 | case FC_TYPE_ILS: |
| 16332 | default: |
| 16333 | goto drop; |
| 16334 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16335 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16336 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16337 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 16338 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16339 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 16340 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 16341 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 16342 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 16343 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16344 | return 0; |
| 16345 | drop: |
| 16346 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16347 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 16348 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16349 | return 1; |
| 16350 | } |
| 16351 | |
| 16352 | /** |
| 16353 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 16354 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16355 | * |
| 16356 | * This function processes the FC header to retrieve the VFI from the VF |
| 16357 | * header, if one exists. This function will return the VFI if one exists |
| 16358 | * or 0 if no VSAN Header exists. |
| 16359 | **/ |
| 16360 | static uint32_t |
| 16361 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 16362 | { |
| 16363 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16364 | |
| 16365 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 16366 | return 0; |
| 16367 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 16368 | } |
| 16369 | |
| 16370 | /** |
| 16371 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 16372 | * @phba: Pointer to the HBA structure to search for the vport on |
| 16373 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16374 | * @fcfi: The FC Fabric ID that the frame came from |
| 16375 | * |
| 16376 | * This function searches the @phba for a vport that matches the content of the |
| 16377 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 16378 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 16379 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 16380 | * vport. |
| 16381 | **/ |
| 16382 | static struct lpfc_vport * |
| 16383 | 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] | 16384 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16385 | { |
| 16386 | struct lpfc_vport **vports; |
| 16387 | struct lpfc_vport *vport = NULL; |
| 16388 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16389 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 16390 | if (did == Fabric_DID) |
| 16391 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16392 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 16393 | !(phba->link_state == LPFC_HBA_READY)) |
| 16394 | return phba->pport; |
| 16395 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16396 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16397 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16398 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 16399 | if (phba->fcf.fcfi == fcfi && |
| 16400 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 16401 | vports[i]->fc_myDID == did) { |
| 16402 | vport = vports[i]; |
| 16403 | break; |
| 16404 | } |
| 16405 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16406 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16407 | lpfc_destroy_vport_work_array(phba, vports); |
| 16408 | return vport; |
| 16409 | } |
| 16410 | |
| 16411 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16412 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 16413 | * @vport: The vport to work on. |
| 16414 | * |
| 16415 | * This function updates the receive sequence time stamp for this vport. The |
| 16416 | * receive sequence time stamp indicates the time that the last frame of the |
| 16417 | * the sequence that has been idle for the longest amount of time was received. |
| 16418 | * the driver uses this time stamp to indicate if any received sequences have |
| 16419 | * timed out. |
| 16420 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16421 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16422 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 16423 | { |
| 16424 | struct lpfc_dmabuf *h_buf; |
| 16425 | struct hbq_dmabuf *dmabuf = NULL; |
| 16426 | |
| 16427 | /* get the oldest sequence on the rcv list */ |
| 16428 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 16429 | struct lpfc_dmabuf, list); |
| 16430 | if (!h_buf) |
| 16431 | return; |
| 16432 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16433 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 16434 | } |
| 16435 | |
| 16436 | /** |
| 16437 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 16438 | * @vport: The vport that the received sequences were sent to. |
| 16439 | * |
| 16440 | * This function cleans up all outstanding received sequences. This is called |
| 16441 | * by the driver when a link event or user action invalidates all the received |
| 16442 | * sequences. |
| 16443 | **/ |
| 16444 | void |
| 16445 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 16446 | { |
| 16447 | struct lpfc_dmabuf *h_buf, *hnext; |
| 16448 | struct lpfc_dmabuf *d_buf, *dnext; |
| 16449 | struct hbq_dmabuf *dmabuf = NULL; |
| 16450 | |
| 16451 | /* start with the oldest sequence on the rcv list */ |
| 16452 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 16453 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16454 | list_del_init(&dmabuf->hbuf.list); |
| 16455 | list_for_each_entry_safe(d_buf, dnext, |
| 16456 | &dmabuf->dbuf.list, list) { |
| 16457 | list_del_init(&d_buf->list); |
| 16458 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16459 | } |
| 16460 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 16461 | } |
| 16462 | } |
| 16463 | |
| 16464 | /** |
| 16465 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 16466 | * @vport: The vport that the received sequences were sent to. |
| 16467 | * |
| 16468 | * This function determines whether any received sequences have timed out by |
| 16469 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 16470 | * indicates that there is at least one timed out sequence this routine will |
| 16471 | * go through the received sequences one at a time from most inactive to most |
| 16472 | * active to determine which ones need to be cleaned up. Once it has determined |
| 16473 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 16474 | * without sending an abort. |
| 16475 | **/ |
| 16476 | void |
| 16477 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 16478 | { |
| 16479 | struct lpfc_dmabuf *h_buf, *hnext; |
| 16480 | struct lpfc_dmabuf *d_buf, *dnext; |
| 16481 | struct hbq_dmabuf *dmabuf = NULL; |
| 16482 | unsigned long timeout; |
| 16483 | int abort_count = 0; |
| 16484 | |
| 16485 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 16486 | vport->rcv_buffer_time_stamp); |
| 16487 | if (list_empty(&vport->rcv_buffer_list) || |
| 16488 | time_before(jiffies, timeout)) |
| 16489 | return; |
| 16490 | /* start with the oldest sequence on the rcv list */ |
| 16491 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 16492 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16493 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 16494 | dmabuf->time_stamp); |
| 16495 | if (time_before(jiffies, timeout)) |
| 16496 | break; |
| 16497 | abort_count++; |
| 16498 | list_del_init(&dmabuf->hbuf.list); |
| 16499 | list_for_each_entry_safe(d_buf, dnext, |
| 16500 | &dmabuf->dbuf.list, list) { |
| 16501 | list_del_init(&d_buf->list); |
| 16502 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16503 | } |
| 16504 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 16505 | } |
| 16506 | if (abort_count) |
| 16507 | lpfc_update_rcv_time_stamp(vport); |
| 16508 | } |
| 16509 | |
| 16510 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16511 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 16512 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 16513 | * |
| 16514 | * This function searches through the existing incomplete sequences that have |
| 16515 | * been sent to this @vport. If the frame matches one of the incomplete |
| 16516 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 16517 | * make up that sequence. If no sequence is found that matches this frame then |
| 16518 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 16519 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 16520 | * the frame was linked to. |
| 16521 | **/ |
| 16522 | static struct hbq_dmabuf * |
| 16523 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 16524 | { |
| 16525 | struct fc_frame_header *new_hdr; |
| 16526 | struct fc_frame_header *temp_hdr; |
| 16527 | struct lpfc_dmabuf *d_buf; |
| 16528 | struct lpfc_dmabuf *h_buf; |
| 16529 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 16530 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16531 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16532 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16533 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16534 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16535 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16536 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16537 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 16538 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 16539 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 16540 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 16541 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 16542 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 16543 | continue; |
| 16544 | /* found a pending sequence that matches this frame */ |
| 16545 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16546 | break; |
| 16547 | } |
| 16548 | if (!seq_dmabuf) { |
| 16549 | /* |
| 16550 | * This indicates first frame received for this sequence. |
| 16551 | * Queue the buffer on the vport's rcv_buffer_list. |
| 16552 | */ |
| 16553 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16554 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16555 | return dmabuf; |
| 16556 | } |
| 16557 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16558 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 16559 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16560 | list_del_init(&seq_dmabuf->hbuf.list); |
| 16561 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 16562 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16563 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16564 | return dmabuf; |
| 16565 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16566 | /* move this sequence to the tail to indicate a young sequence */ |
| 16567 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 16568 | seq_dmabuf->time_stamp = jiffies; |
| 16569 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16570 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 16571 | temp_hdr = dmabuf->hbuf.virt; |
| 16572 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 16573 | return seq_dmabuf; |
| 16574 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16575 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16576 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 16577 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16578 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 16579 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 16580 | /* |
| 16581 | * If the frame's sequence count is greater than the frame on |
| 16582 | * the list then insert the frame right after this frame |
| 16583 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16584 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 16585 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16586 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16587 | found = 1; |
| 16588 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16589 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16590 | |
| 16591 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 16592 | break; |
| 16593 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16594 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16595 | |
| 16596 | if (found) |
| 16597 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16598 | return NULL; |
| 16599 | } |
| 16600 | |
| 16601 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16602 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 16603 | * @vport: pointer to a vitural port |
| 16604 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16605 | * |
| 16606 | * This function tries to abort from the partially assembed sequence, described |
| 16607 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 16608 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 16609 | * the frames from the partially assembled sequence. |
| 16610 | * |
| 16611 | * Return |
| 16612 | * true -- if there is matching partially assembled sequence present and all |
| 16613 | * the frames freed with the sequence; |
| 16614 | * false -- if there is no matching partially assembled sequence present so |
| 16615 | * nothing got aborted in the lower layer driver |
| 16616 | **/ |
| 16617 | static bool |
| 16618 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 16619 | struct hbq_dmabuf *dmabuf) |
| 16620 | { |
| 16621 | struct fc_frame_header *new_hdr; |
| 16622 | struct fc_frame_header *temp_hdr; |
| 16623 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 16624 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 16625 | |
| 16626 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 16627 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 16628 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 16629 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 16630 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 16631 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 16632 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 16633 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 16634 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 16635 | continue; |
| 16636 | /* found a pending sequence that matches this frame */ |
| 16637 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16638 | break; |
| 16639 | } |
| 16640 | |
| 16641 | /* Free up all the frames from the partially assembled sequence */ |
| 16642 | if (seq_dmabuf) { |
| 16643 | list_for_each_entry_safe(d_buf, n_buf, |
| 16644 | &seq_dmabuf->dbuf.list, list) { |
| 16645 | list_del_init(&d_buf->list); |
| 16646 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16647 | } |
| 16648 | return true; |
| 16649 | } |
| 16650 | return false; |
| 16651 | } |
| 16652 | |
| 16653 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16654 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 16655 | * @vport: pointer to a vitural port |
| 16656 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16657 | * |
| 16658 | * This function tries to abort from the assembed sequence from upper level |
| 16659 | * protocol, described by the information from basic abbort @dmabuf. It |
| 16660 | * checks to see whether such pending context exists at upper level protocol. |
| 16661 | * If so, it shall clean up the pending context. |
| 16662 | * |
| 16663 | * Return |
| 16664 | * true -- if there is matching pending context of the sequence cleaned |
| 16665 | * at ulp; |
| 16666 | * false -- if there is no matching pending context of the sequence present |
| 16667 | * at ulp. |
| 16668 | **/ |
| 16669 | static bool |
| 16670 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 16671 | { |
| 16672 | struct lpfc_hba *phba = vport->phba; |
| 16673 | int handled; |
| 16674 | |
| 16675 | /* Accepting abort at ulp with SLI4 only */ |
| 16676 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 16677 | return false; |
| 16678 | |
| 16679 | /* Register all caring upper level protocols to attend abort */ |
| 16680 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 16681 | if (handled) |
| 16682 | return true; |
| 16683 | |
| 16684 | return false; |
| 16685 | } |
| 16686 | |
| 16687 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16688 | * 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] | 16689 | * @phba: Pointer to HBA context object. |
| 16690 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 16691 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 16692 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16693 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16694 | * event. It properly releases the memory allocated to the sequence abort |
| 16695 | * accept iocb. |
| 16696 | **/ |
| 16697 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16698 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16699 | struct lpfc_iocbq *cmd_iocbq, |
| 16700 | struct lpfc_iocbq *rsp_iocbq) |
| 16701 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16702 | struct lpfc_nodelist *ndlp; |
| 16703 | |
| 16704 | if (cmd_iocbq) { |
| 16705 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 16706 | lpfc_nlp_put(ndlp); |
| 16707 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16708 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16709 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 16710 | |
| 16711 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 16712 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 16713 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16714 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 16715 | rsp_iocbq->iocb.ulpStatus, |
| 16716 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16717 | } |
| 16718 | |
| 16719 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16720 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 16721 | * @phba: Pointer to HBA context object. |
| 16722 | * @xri: xri id in transaction. |
| 16723 | * |
| 16724 | * This function validates the xri maps to the known range of XRIs allocated an |
| 16725 | * used by the driver. |
| 16726 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16727 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16728 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 16729 | uint16_t xri) |
| 16730 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16731 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16732 | |
| 16733 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 16734 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 16735 | return i; |
| 16736 | } |
| 16737 | return NO_XRI; |
| 16738 | } |
| 16739 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16740 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16741 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16742 | * @phba: Pointer to HBA context object. |
| 16743 | * @fc_hdr: pointer to a FC frame header. |
| 16744 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16745 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16746 | * event after aborting the sequence handling. |
| 16747 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 16748 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16749 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 16750 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16751 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16752 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16753 | struct lpfc_iocbq *ctiocb = NULL; |
| 16754 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 16755 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16756 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16757 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16758 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16759 | |
| 16760 | if (!lpfc_is_link_up(phba)) |
| 16761 | return; |
| 16762 | |
| 16763 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 16764 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16765 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16766 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16767 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16768 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 16769 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16770 | if (!ndlp) { |
| 16771 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 16772 | "1268 Failed to allocate ndlp for " |
| 16773 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 16774 | return; |
| 16775 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16776 | /* Put ndlp onto pport node list */ |
| 16777 | lpfc_enqueue_node(vport, ndlp); |
| 16778 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 16779 | /* re-setup ndlp without removing from node list */ |
| 16780 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 16781 | if (!ndlp) { |
| 16782 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 16783 | "3275 Failed to active ndlp found " |
| 16784 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 16785 | return; |
| 16786 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16787 | } |
| 16788 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16789 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16790 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 16791 | if (!ctiocb) |
| 16792 | return; |
| 16793 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16794 | /* Extract the F_CTL field from FC_HDR */ |
| 16795 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 16796 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16797 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16798 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16799 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16800 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 16801 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 16802 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 16803 | |
| 16804 | /* Fill in the rest of iocb fields */ |
| 16805 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 16806 | icmd->ulpBdeCount = 0; |
| 16807 | icmd->ulpLe = 1; |
| 16808 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16809 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16810 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16811 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16812 | ctiocb->iocb_cmpl = NULL; |
| 16813 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16814 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16815 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16816 | ctiocb->sli4_xritag = NO_XRI; |
| 16817 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 16818 | if (fctl & FC_FC_EX_CTX) |
| 16819 | /* Exchange responder sent the abort so we |
| 16820 | * own the oxid. |
| 16821 | */ |
| 16822 | xri = oxid; |
| 16823 | else |
| 16824 | xri = rxid; |
| 16825 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 16826 | if (lxri != NO_XRI) |
| 16827 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 16828 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16829 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 16830 | * the oxid maps to the FCP XRI range, the port no longer has |
| 16831 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 16832 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16833 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16834 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16835 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16836 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 16837 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 16838 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 16839 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 16840 | } |
| 16841 | |
| 16842 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 16843 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 16844 | * the IOCB for a BA_RJT. |
| 16845 | */ |
| 16846 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16847 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 16848 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 16849 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 16850 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 16851 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16852 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16853 | if (fctl & FC_FC_EX_CTX) { |
| 16854 | /* ABTS sent by responder to CT exchange, construction |
| 16855 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 16856 | * field and RX_ID from ABTS for RX_ID field. |
| 16857 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16858 | 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] | 16859 | } else { |
| 16860 | /* ABTS sent by initiator to CT exchange, construction |
| 16861 | * 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] | 16862 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16863 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16864 | 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] | 16865 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 16866 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16867 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16868 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16869 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16870 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 16871 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 16872 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16873 | |
| 16874 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 16875 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16876 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 16877 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 16878 | "xri x%x, Data x%x\n", |
| 16879 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 16880 | phba->link_state); |
| 16881 | lpfc_nlp_put(ndlp); |
| 16882 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16883 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 16884 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16885 | } |
| 16886 | |
| 16887 | /** |
| 16888 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 16889 | * @vport: Pointer to the vport on which this sequence was received |
| 16890 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16891 | * |
| 16892 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 16893 | * receive sequence is only partially assembed by the driver, it shall abort |
| 16894 | * the partially assembled frames for the sequence. Otherwise, if the |
| 16895 | * unsolicited receive sequence has been completely assembled and passed to |
| 16896 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 16897 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 16898 | * accept to accept the abort. |
| 16899 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16900 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16901 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 16902 | struct hbq_dmabuf *dmabuf) |
| 16903 | { |
| 16904 | struct lpfc_hba *phba = vport->phba; |
| 16905 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16906 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16907 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16908 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16909 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 16910 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16911 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16912 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16913 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16914 | /* ABTS by responder to exchange, no cleanup needed */ |
| 16915 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16916 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16917 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 16918 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 16919 | if (aborted == false) |
| 16920 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16921 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16922 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 16923 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 16924 | if (phba->nvmet_support) { |
| 16925 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 16926 | return; |
| 16927 | } |
| 16928 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16929 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 16930 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16931 | } |
| 16932 | |
| 16933 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16934 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 16935 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16936 | * |
| 16937 | * This function checks the sequence, starting with the frame described by |
| 16938 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 16939 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 16940 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 16941 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 16942 | * set. 3) That there are no holes in the sequence count. The function will |
| 16943 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 16944 | **/ |
| 16945 | static int |
| 16946 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 16947 | { |
| 16948 | struct fc_frame_header *hdr; |
| 16949 | struct lpfc_dmabuf *d_buf; |
| 16950 | struct hbq_dmabuf *seq_dmabuf; |
| 16951 | uint32_t fctl; |
| 16952 | int seq_count = 0; |
| 16953 | |
| 16954 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 16955 | /* make sure first fame of sequence has a sequence count of zero */ |
| 16956 | if (hdr->fh_seq_cnt != seq_count) |
| 16957 | return 0; |
| 16958 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 16959 | hdr->fh_f_ctl[1] << 8 | |
| 16960 | hdr->fh_f_ctl[2]); |
| 16961 | /* If last frame of sequence we can return success. */ |
| 16962 | if (fctl & FC_FC_END_SEQ) |
| 16963 | return 1; |
| 16964 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 16965 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 16966 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 16967 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16968 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16969 | return 0; |
| 16970 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 16971 | hdr->fh_f_ctl[1] << 8 | |
| 16972 | hdr->fh_f_ctl[2]); |
| 16973 | /* If last frame of sequence we can return success. */ |
| 16974 | if (fctl & FC_FC_END_SEQ) |
| 16975 | return 1; |
| 16976 | } |
| 16977 | return 0; |
| 16978 | } |
| 16979 | |
| 16980 | /** |
| 16981 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 16982 | * @vport: Pointer to the vport on which this sequence was received |
| 16983 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16984 | * |
| 16985 | * This function takes a sequence, described by a list of frames, and creates |
| 16986 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 16987 | * used to issue to the generic unsolicited sequence handler. This routine |
| 16988 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 16989 | * to allocate an iocbq then it throw out the received frames that were not |
| 16990 | * able to be described and return a pointer to the first iocbq. If unable to |
| 16991 | * allocate any iocbqs (including the first) this function will return NULL. |
| 16992 | **/ |
| 16993 | static struct lpfc_iocbq * |
| 16994 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 16995 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16996 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16997 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 16998 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 16999 | struct fc_frame_header *fc_hdr; |
| 17000 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17001 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 17002 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17003 | |
| 17004 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17005 | /* remove from receive buffer list */ |
| 17006 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 17007 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17008 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17009 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17010 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17011 | /* Get an iocbq struct to fill in. */ |
| 17012 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17013 | if (first_iocbq) { |
| 17014 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 17015 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17016 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17017 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17018 | |
| 17019 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 17020 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 17021 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 17022 | first_iocbq->iocb.un.rcvels.parmRo = |
| 17023 | sli4_did_from_fc_hdr(fc_hdr); |
| 17024 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 17025 | } else |
| 17026 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17027 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 17028 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 17029 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 17030 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 17031 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 17032 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17033 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17034 | tot_len = bf_get(lpfc_rcqe_length, |
| 17035 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17036 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17037 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 17038 | first_iocbq->context3 = NULL; |
| 17039 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17040 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 17041 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17042 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17043 | else |
| 17044 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 17045 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17046 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17047 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17048 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17049 | } |
| 17050 | iocbq = first_iocbq; |
| 17051 | /* |
| 17052 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 17053 | * of buffers for this sequence and save two buffers in each IOCBq |
| 17054 | */ |
| 17055 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 17056 | if (!iocbq) { |
| 17057 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17058 | continue; |
| 17059 | } |
| 17060 | if (!iocbq->context3) { |
| 17061 | iocbq->context3 = d_buf; |
| 17062 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17063 | /* We need to get the size out of the right CQE */ |
| 17064 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17065 | len = bf_get(lpfc_rcqe_length, |
| 17066 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17067 | pbde = (struct ulp_bde64 *) |
| 17068 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 17069 | if (len > LPFC_DATA_BUF_SIZE) |
| 17070 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 17071 | else |
| 17072 | pbde->tus.f.bdeSize = len; |
| 17073 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17074 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 17075 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17076 | } else { |
| 17077 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17078 | if (!iocbq) { |
| 17079 | if (first_iocbq) { |
| 17080 | first_iocbq->iocb.ulpStatus = |
| 17081 | IOSTAT_FCP_RSP_ERROR; |
| 17082 | first_iocbq->iocb.un.ulpWord[4] = |
| 17083 | IOERR_NO_RESOURCES; |
| 17084 | } |
| 17085 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17086 | continue; |
| 17087 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17088 | /* We need to get the size out of the right CQE */ |
| 17089 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17090 | len = bf_get(lpfc_rcqe_length, |
| 17091 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17092 | iocbq->context2 = d_buf; |
| 17093 | iocbq->context3 = NULL; |
| 17094 | iocbq->iocb.ulpBdeCount = 1; |
| 17095 | if (len > LPFC_DATA_BUF_SIZE) |
| 17096 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 17097 | LPFC_DATA_BUF_SIZE; |
| 17098 | else |
| 17099 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 17100 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17101 | tot_len += len; |
| 17102 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 17103 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17104 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 17105 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 17106 | } |
| 17107 | } |
| 17108 | return first_iocbq; |
| 17109 | } |
| 17110 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17111 | static void |
| 17112 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 17113 | struct hbq_dmabuf *seq_dmabuf) |
| 17114 | { |
| 17115 | struct fc_frame_header *fc_hdr; |
| 17116 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 17117 | struct lpfc_hba *phba = vport->phba; |
| 17118 | |
| 17119 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17120 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 17121 | if (!iocbq) { |
| 17122 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17123 | "2707 Ring %d handler: Failed to allocate " |
| 17124 | "iocb Rctl x%x Type x%x received\n", |
| 17125 | LPFC_ELS_RING, |
| 17126 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17127 | return; |
| 17128 | } |
| 17129 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17130 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17131 | iocbq, fc_hdr->fh_r_ctl, |
| 17132 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17133 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17134 | "2540 Ring %d handler: unexpected Rctl " |
| 17135 | "x%x Type x%x received\n", |
| 17136 | LPFC_ELS_RING, |
| 17137 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17138 | |
| 17139 | /* Free iocb created in lpfc_prep_seq */ |
| 17140 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 17141 | &iocbq->list, list) { |
| 17142 | list_del_init(&curr_iocb->list); |
| 17143 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 17144 | } |
| 17145 | lpfc_sli_release_iocbq(phba, iocbq); |
| 17146 | } |
| 17147 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17148 | static void |
| 17149 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 17150 | struct lpfc_iocbq *rspiocb) |
| 17151 | { |
| 17152 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 17153 | |
| 17154 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17155 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17156 | kfree(pcmd); |
| 17157 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 17158 | } |
| 17159 | |
| 17160 | static void |
| 17161 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 17162 | struct hbq_dmabuf *dmabuf) |
| 17163 | { |
| 17164 | struct fc_frame_header *fc_hdr; |
| 17165 | struct lpfc_hba *phba = vport->phba; |
| 17166 | struct lpfc_iocbq *iocbq = NULL; |
| 17167 | union lpfc_wqe *wqe; |
| 17168 | struct lpfc_dmabuf *pcmd = NULL; |
| 17169 | uint32_t frame_len; |
| 17170 | int rc; |
| 17171 | |
| 17172 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17173 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17174 | |
| 17175 | /* Send the received frame back */ |
| 17176 | iocbq = lpfc_sli_get_iocbq(phba); |
| 17177 | if (!iocbq) |
| 17178 | goto exit; |
| 17179 | |
| 17180 | /* Allocate buffer for command payload */ |
| 17181 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 17182 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17183 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17184 | &pcmd->phys); |
| 17185 | if (!pcmd || !pcmd->virt) |
| 17186 | goto exit; |
| 17187 | |
| 17188 | INIT_LIST_HEAD(&pcmd->list); |
| 17189 | |
| 17190 | /* copyin the payload */ |
| 17191 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 17192 | |
| 17193 | /* fill in BDE's for command */ |
| 17194 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 17195 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 17196 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 17197 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 17198 | |
| 17199 | iocbq->context2 = pcmd; |
| 17200 | iocbq->vport = vport; |
| 17201 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 17202 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 17203 | |
| 17204 | /* |
| 17205 | * Setup rest of the iocb as though it were a WQE |
| 17206 | * Build the SEND_FRAME WQE |
| 17207 | */ |
| 17208 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 17209 | |
| 17210 | wqe->send_frame.frame_len = frame_len; |
| 17211 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 17212 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 17213 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 17214 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 17215 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 17216 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 17217 | |
| 17218 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 17219 | iocbq->iocb.ulpLe = 1; |
| 17220 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 17221 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 17222 | if (rc == IOCB_ERROR) |
| 17223 | goto exit; |
| 17224 | |
| 17225 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17226 | return; |
| 17227 | |
| 17228 | exit: |
| 17229 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 17230 | "2023 Unable to process MDS loopback frame\n"); |
| 17231 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17232 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17233 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 17234 | if (iocbq) |
| 17235 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17236 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17237 | } |
| 17238 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17239 | /** |
| 17240 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 17241 | * @phba: Pointer to HBA context object. |
| 17242 | * |
| 17243 | * This function is called with no lock held. This function processes all |
| 17244 | * the received buffers and gives it to upper layers when a received buffer |
| 17245 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17246 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17247 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 17248 | * appropriate receive function when the final frame in a sequence is received. |
| 17249 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17250 | void |
| 17251 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 17252 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17253 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17254 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17255 | struct fc_frame_header *fc_hdr; |
| 17256 | struct lpfc_vport *vport; |
| 17257 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17258 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17259 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17260 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17261 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17262 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17263 | /* check to see if this a valid type of frame */ |
| 17264 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 17265 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17266 | return; |
| 17267 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17268 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17269 | if ((bf_get(lpfc_cqe_code, |
| 17270 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 17271 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 17272 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17273 | else |
| 17274 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 17275 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17276 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17277 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
| 17278 | vport = phba->pport; |
| 17279 | /* Handle MDS Loopback frames */ |
| 17280 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 17281 | return; |
| 17282 | } |
| 17283 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17284 | /* d_id this frame is directed to */ |
| 17285 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 17286 | |
| 17287 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17288 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17289 | /* throw out the frame */ |
| 17290 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17291 | return; |
| 17292 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17293 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17294 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 17295 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 17296 | (did != Fabric_DID)) { |
| 17297 | /* |
| 17298 | * Throw out the frame if we are not pt2pt. |
| 17299 | * The pt2pt protocol allows for discovery frames |
| 17300 | * to be received without a registered VPI. |
| 17301 | */ |
| 17302 | if (!(vport->fc_flag & FC_PT2PT) || |
| 17303 | (phba->link_state == LPFC_HBA_READY)) { |
| 17304 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17305 | return; |
| 17306 | } |
| 17307 | } |
| 17308 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17309 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 17310 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 17311 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 17312 | return; |
| 17313 | } |
| 17314 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17315 | /* Link this frame */ |
| 17316 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 17317 | if (!seq_dmabuf) { |
| 17318 | /* unable to add frame to vport - throw it out */ |
| 17319 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17320 | return; |
| 17321 | } |
| 17322 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17323 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17324 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17325 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17326 | /* Send the complete sequence to the upper layer protocol */ |
| 17327 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17328 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17329 | |
| 17330 | /** |
| 17331 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 17332 | * @phba: pointer to lpfc hba data structure. |
| 17333 | * |
| 17334 | * This routine is invoked to post rpi header templates to the |
| 17335 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17336 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17337 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17338 | * |
| 17339 | * This routine does not require any locks. It's usage is expected |
| 17340 | * to be driver load or reset recovery when the driver is |
| 17341 | * sequential. |
| 17342 | * |
| 17343 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17344 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17345 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17346 | * When this error occurs, the driver is not guaranteed |
| 17347 | * to have any rpi regions posted to the device and |
| 17348 | * must either attempt to repost the regions or take a |
| 17349 | * fatal error. |
| 17350 | **/ |
| 17351 | int |
| 17352 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 17353 | { |
| 17354 | struct lpfc_rpi_hdr *rpi_page; |
| 17355 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17356 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17357 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17358 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 17359 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 17360 | goto exit; |
| 17361 | if (phba->sli4_hba.extents_in_use) |
| 17362 | return -EIO; |
| 17363 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17364 | 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] | 17365 | /* |
| 17366 | * Assign the rpi headers a physical rpi only if the driver |
| 17367 | * has not initialized those resources. A port reset only |
| 17368 | * needs the headers posted. |
| 17369 | */ |
| 17370 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 17371 | LPFC_RPI_RSRC_RDY) |
| 17372 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 17373 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17374 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 17375 | if (rc != MBX_SUCCESS) { |
| 17376 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17377 | "2008 Error %d posting all rpi " |
| 17378 | "headers\n", rc); |
| 17379 | rc = -EIO; |
| 17380 | break; |
| 17381 | } |
| 17382 | } |
| 17383 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17384 | exit: |
| 17385 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 17386 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17387 | return rc; |
| 17388 | } |
| 17389 | |
| 17390 | /** |
| 17391 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 17392 | * @phba: pointer to lpfc hba data structure. |
| 17393 | * @rpi_page: pointer to the rpi memory region. |
| 17394 | * |
| 17395 | * This routine is invoked to post a single rpi header to the |
| 17396 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 17397 | * maps up to 64 rpi context regions. |
| 17398 | * |
| 17399 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17400 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17401 | * -ENOMEM - No available memory |
| 17402 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17403 | **/ |
| 17404 | int |
| 17405 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 17406 | { |
| 17407 | LPFC_MBOXQ_t *mboxq; |
| 17408 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 17409 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17410 | uint32_t shdr_status, shdr_add_status; |
| 17411 | union lpfc_sli4_cfg_shdr *shdr; |
| 17412 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17413 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 17414 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 17415 | return rc; |
| 17416 | if (phba->sli4_hba.extents_in_use) |
| 17417 | return -EIO; |
| 17418 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17419 | /* The port is notified of the header region via a mailbox command. */ |
| 17420 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17421 | if (!mboxq) { |
| 17422 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17423 | "2001 Unable to allocate memory for issuing " |
| 17424 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 17425 | return -ENOMEM; |
| 17426 | } |
| 17427 | |
| 17428 | /* Post all rpi memory regions to the port. */ |
| 17429 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17430 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17431 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 17432 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 17433 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 17434 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17435 | |
| 17436 | |
| 17437 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17438 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 17439 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17440 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 17441 | hdr_tmpl, rpi_page->page_count); |
| 17442 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17443 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 17444 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 17445 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17446 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 17447 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17448 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17449 | if (rc != MBX_TIMEOUT) |
| 17450 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 17451 | if (shdr_status || shdr_add_status || rc) { |
| 17452 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17453 | "2514 POST_RPI_HDR mailbox failed with " |
| 17454 | "status x%x add_status x%x, mbx status x%x\n", |
| 17455 | shdr_status, shdr_add_status, rc); |
| 17456 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 17457 | } else { |
| 17458 | /* |
| 17459 | * The next_rpi stores the next logical module-64 rpi value used |
| 17460 | * to post physical rpis in subsequent rpi postings. |
| 17461 | */ |
| 17462 | spin_lock_irq(&phba->hbalock); |
| 17463 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 17464 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17465 | } |
| 17466 | return rc; |
| 17467 | } |
| 17468 | |
| 17469 | /** |
| 17470 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 17471 | * @phba: pointer to lpfc hba data structure. |
| 17472 | * |
| 17473 | * This routine is invoked to post rpi header templates to the |
| 17474 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17475 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17476 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17477 | * |
| 17478 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17479 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17480 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 17481 | **/ |
| 17482 | int |
| 17483 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 17484 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17485 | unsigned long rpi; |
| 17486 | uint16_t max_rpi, rpi_limit; |
| 17487 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17488 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17489 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17490 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17491 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17492 | * Fetch the next logical rpi. Because this index is logical, |
| 17493 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17494 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17495 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 17496 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 17497 | rpi_limit = phba->sli4_hba.next_rpi; |
| 17498 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17499 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 17500 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17501 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 17502 | else { |
| 17503 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 17504 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 17505 | phba->sli4_hba.rpi_count++; |
| 17506 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 17507 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 17508 | "0001 rpi:%x max:%x lim:%x\n", |
| 17509 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17510 | |
| 17511 | /* |
| 17512 | * 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] | 17513 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17514 | */ |
| 17515 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 17516 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17517 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17518 | return rpi; |
| 17519 | } |
| 17520 | |
| 17521 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17522 | * RPI header postings are not required for SLI4 ports capable of |
| 17523 | * extents. |
| 17524 | */ |
| 17525 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17526 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17527 | return rpi; |
| 17528 | } |
| 17529 | |
| 17530 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17531 | * If the driver is running low on rpi resources, allocate another |
| 17532 | * page now. Note that the next_rpi value is used because |
| 17533 | * it represents how many are actually in use whereas max_rpi notes |
| 17534 | * how many are supported max by the device. |
| 17535 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17536 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17537 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17538 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 17539 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 17540 | if (!rpi_hdr) { |
| 17541 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17542 | "2002 Error Could not grow rpi " |
| 17543 | "count\n"); |
| 17544 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17545 | lrpi = rpi_hdr->start_rpi; |
| 17546 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17547 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 17548 | } |
| 17549 | } |
| 17550 | |
| 17551 | return rpi; |
| 17552 | } |
| 17553 | |
| 17554 | /** |
| 17555 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 17556 | * @phba: pointer to lpfc hba data structure. |
| 17557 | * |
| 17558 | * This routine is invoked to release an rpi to the pool of |
| 17559 | * available rpis maintained by the driver. |
| 17560 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17561 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 17562 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 17563 | { |
| 17564 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 17565 | phba->sli4_hba.rpi_count--; |
| 17566 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 17567 | } |
| 17568 | } |
| 17569 | |
| 17570 | /** |
| 17571 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 17572 | * @phba: pointer to lpfc hba data structure. |
| 17573 | * |
| 17574 | * This routine is invoked to release an rpi to the pool of |
| 17575 | * available rpis maintained by the driver. |
| 17576 | **/ |
| 17577 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17578 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 17579 | { |
| 17580 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 17581 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17582 | spin_unlock_irq(&phba->hbalock); |
| 17583 | } |
| 17584 | |
| 17585 | /** |
| 17586 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 17587 | * @phba: pointer to lpfc hba data structure. |
| 17588 | * |
| 17589 | * This routine is invoked to remove the memory region that |
| 17590 | * provided rpi via a bitmask. |
| 17591 | **/ |
| 17592 | void |
| 17593 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 17594 | { |
| 17595 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17596 | kfree(phba->sli4_hba.rpi_ids); |
| 17597 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17598 | } |
| 17599 | |
| 17600 | /** |
| 17601 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 17602 | * @phba: pointer to lpfc hba data structure. |
| 17603 | * |
| 17604 | * This routine is invoked to remove the memory region that |
| 17605 | * provided rpi via a bitmask. |
| 17606 | **/ |
| 17607 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17608 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 17609 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17610 | { |
| 17611 | LPFC_MBOXQ_t *mboxq; |
| 17612 | struct lpfc_hba *phba = ndlp->phba; |
| 17613 | int rc; |
| 17614 | |
| 17615 | /* The port is notified of the header region via a mailbox command. */ |
| 17616 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17617 | if (!mboxq) |
| 17618 | return -ENOMEM; |
| 17619 | |
| 17620 | /* Post all rpi memory regions to the port. */ |
| 17621 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17622 | if (cmpl) { |
| 17623 | mboxq->mbox_cmpl = cmpl; |
| 17624 | mboxq->context1 = arg; |
| 17625 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 17626 | } else |
| 17627 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17628 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17629 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17630 | if (rc == MBX_NOT_FINISHED) { |
| 17631 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17632 | "2010 Resume RPI Mailbox failed " |
| 17633 | "status %d, mbxStatus x%x\n", rc, |
| 17634 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 17635 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 17636 | return -EIO; |
| 17637 | } |
| 17638 | return 0; |
| 17639 | } |
| 17640 | |
| 17641 | /** |
| 17642 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17643 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17644 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17645 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17646 | * |
| 17647 | * Returns: |
| 17648 | * 0 success |
| 17649 | * -Evalue otherwise |
| 17650 | **/ |
| 17651 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17652 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17653 | { |
| 17654 | LPFC_MBOXQ_t *mboxq; |
| 17655 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17656 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17657 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17658 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17659 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17660 | if (!mboxq) |
| 17661 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17662 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17663 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17664 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17665 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17666 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17667 | "2022 INIT VPI Mailbox failed " |
| 17668 | "status %d, mbxStatus x%x\n", rc, |
| 17669 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17670 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17671 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17672 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17673 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17674 | |
| 17675 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17676 | } |
| 17677 | |
| 17678 | /** |
| 17679 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 17680 | * @phba: pointer to lpfc hba data structure. |
| 17681 | * @mboxq: Pointer to mailbox object. |
| 17682 | * |
| 17683 | * This routine is invoked to manually add a single FCF record. The caller |
| 17684 | * must pass a completely initialized FCF_Record. This routine takes |
| 17685 | * care of the nonembedded mailbox operations. |
| 17686 | **/ |
| 17687 | static void |
| 17688 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 17689 | { |
| 17690 | void *virt_addr; |
| 17691 | union lpfc_sli4_cfg_shdr *shdr; |
| 17692 | uint32_t shdr_status, shdr_add_status; |
| 17693 | |
| 17694 | virt_addr = mboxq->sge_array->addr[0]; |
| 17695 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17696 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 17697 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17698 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17699 | |
| 17700 | if ((shdr_status || shdr_add_status) && |
| 17701 | (shdr_status != STATUS_FCF_IN_USE)) |
| 17702 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17703 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 17704 | "status x%x add_status x%x\n", |
| 17705 | shdr_status, shdr_add_status); |
| 17706 | |
| 17707 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17708 | } |
| 17709 | |
| 17710 | /** |
| 17711 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 17712 | * @phba: pointer to lpfc hba data structure. |
| 17713 | * @fcf_record: pointer to the initialized fcf record to add. |
| 17714 | * |
| 17715 | * This routine is invoked to manually add a single FCF record. The caller |
| 17716 | * must pass a completely initialized FCF_Record. This routine takes |
| 17717 | * care of the nonembedded mailbox operations. |
| 17718 | **/ |
| 17719 | int |
| 17720 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 17721 | { |
| 17722 | int rc = 0; |
| 17723 | LPFC_MBOXQ_t *mboxq; |
| 17724 | uint8_t *bytep; |
| 17725 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17726 | struct lpfc_mbx_sge sge; |
| 17727 | uint32_t alloc_len, req_len; |
| 17728 | uint32_t fcfindex; |
| 17729 | |
| 17730 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17731 | if (!mboxq) { |
| 17732 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17733 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 17734 | return -ENOMEM; |
| 17735 | } |
| 17736 | |
| 17737 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 17738 | sizeof(uint32_t); |
| 17739 | |
| 17740 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 17741 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17742 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 17743 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 17744 | if (alloc_len < req_len) { |
| 17745 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17746 | "2523 Allocated DMA memory size (x%x) is " |
| 17747 | "less than the requested DMA memory " |
| 17748 | "size (x%x)\n", alloc_len, req_len); |
| 17749 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17750 | return -ENOMEM; |
| 17751 | } |
| 17752 | |
| 17753 | /* |
| 17754 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 17755 | * routine only uses a single SGE. |
| 17756 | */ |
| 17757 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17758 | virt_addr = mboxq->sge_array->addr[0]; |
| 17759 | /* |
| 17760 | * Configure the FCF record for FCFI 0. This is the driver's |
| 17761 | * hardcoded default and gets used in nonFIP mode. |
| 17762 | */ |
| 17763 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 17764 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 17765 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 17766 | |
| 17767 | /* |
| 17768 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 17769 | * the FCoE header plus word10. The data copy needs to be endian |
| 17770 | * correct. |
| 17771 | */ |
| 17772 | bytep += sizeof(uint32_t); |
| 17773 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 17774 | mboxq->vport = phba->pport; |
| 17775 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 17776 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17777 | if (rc == MBX_NOT_FINISHED) { |
| 17778 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17779 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 17780 | "status 0x%x\n", rc); |
| 17781 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17782 | rc = -EIO; |
| 17783 | } else |
| 17784 | rc = 0; |
| 17785 | |
| 17786 | return rc; |
| 17787 | } |
| 17788 | |
| 17789 | /** |
| 17790 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 17791 | * @phba: pointer to lpfc hba data structure. |
| 17792 | * @fcf_record: pointer to the fcf record to write the default data. |
| 17793 | * @fcf_index: FCF table entry index. |
| 17794 | * |
| 17795 | * This routine is invoked to build the driver's default FCF record. The |
| 17796 | * values used are hardcoded. This routine handles memory initialization. |
| 17797 | * |
| 17798 | **/ |
| 17799 | void |
| 17800 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 17801 | struct fcf_record *fcf_record, |
| 17802 | uint16_t fcf_index) |
| 17803 | { |
| 17804 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 17805 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 17806 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 17807 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 17808 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 17809 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 17810 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 17811 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 17812 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 17813 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 17814 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 17815 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 17816 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 17817 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 17818 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17819 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 17820 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 17821 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 17822 | /* Set the VLAN bit map */ |
| 17823 | if (phba->valid_vlan) { |
| 17824 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 17825 | = 1 << (phba->vlan_id % 8); |
| 17826 | } |
| 17827 | } |
| 17828 | |
| 17829 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17830 | * 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] | 17831 | * @phba: pointer to lpfc hba data structure. |
| 17832 | * @fcf_index: FCF table entry offset. |
| 17833 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17834 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 17835 | * record and processing it one at a time starting from the @fcf_index |
| 17836 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 17837 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 17838 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17839 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17840 | **/ |
| 17841 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17842 | 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] | 17843 | { |
| 17844 | int rc = 0, error; |
| 17845 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17846 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 17847 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 17848 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17849 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17850 | if (!mboxq) { |
| 17851 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17852 | "2000 Failed to allocate mbox for " |
| 17853 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17854 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17855 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17856 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17857 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17858 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17859 | if (rc) { |
| 17860 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17861 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17862 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17863 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17864 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17865 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17866 | |
| 17867 | spin_lock_irq(&phba->hbalock); |
| 17868 | phba->hba_flag |= FCF_TS_INPROG; |
| 17869 | spin_unlock_irq(&phba->hbalock); |
| 17870 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17871 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17872 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17873 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17874 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 17875 | /* Reset eligible FCF count for new scan */ |
| 17876 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 17877 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17878 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 17879 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17880 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17881 | if (error) { |
| 17882 | if (mboxq) |
| 17883 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17884 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17885 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17886 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17887 | spin_unlock_irq(&phba->hbalock); |
| 17888 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17889 | return error; |
| 17890 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 17891 | |
| 17892 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17893 | * 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] | 17894 | * @phba: pointer to lpfc hba data structure. |
| 17895 | * @fcf_index: FCF table entry offset. |
| 17896 | * |
| 17897 | * 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] | 17898 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17899 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 17900 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17901 | * otherwise. |
| 17902 | **/ |
| 17903 | int |
| 17904 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 17905 | { |
| 17906 | int rc = 0, error; |
| 17907 | LPFC_MBOXQ_t *mboxq; |
| 17908 | |
| 17909 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17910 | if (!mboxq) { |
| 17911 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 17912 | "2763 Failed to allocate mbox for " |
| 17913 | "READ_FCF cmd\n"); |
| 17914 | error = -ENOMEM; |
| 17915 | goto fail_fcf_read; |
| 17916 | } |
| 17917 | /* Construct the read FCF record mailbox command */ |
| 17918 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 17919 | if (rc) { |
| 17920 | error = -EINVAL; |
| 17921 | goto fail_fcf_read; |
| 17922 | } |
| 17923 | /* Issue the mailbox command asynchronously */ |
| 17924 | mboxq->vport = phba->pport; |
| 17925 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 17926 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17927 | if (rc == MBX_NOT_FINISHED) |
| 17928 | error = -EIO; |
| 17929 | else |
| 17930 | error = 0; |
| 17931 | |
| 17932 | fail_fcf_read: |
| 17933 | if (error && mboxq) |
| 17934 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17935 | return error; |
| 17936 | } |
| 17937 | |
| 17938 | /** |
| 17939 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 17940 | * @phba: pointer to lpfc hba data structure. |
| 17941 | * @fcf_index: FCF table entry offset. |
| 17942 | * |
| 17943 | * 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] | 17944 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17945 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 17946 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17947 | * otherwise. |
| 17948 | **/ |
| 17949 | int |
| 17950 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 17951 | { |
| 17952 | int rc = 0, error; |
| 17953 | LPFC_MBOXQ_t *mboxq; |
| 17954 | |
| 17955 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17956 | if (!mboxq) { |
| 17957 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 17958 | "2758 Failed to allocate mbox for " |
| 17959 | "READ_FCF cmd\n"); |
| 17960 | error = -ENOMEM; |
| 17961 | goto fail_fcf_read; |
| 17962 | } |
| 17963 | /* Construct the read FCF record mailbox command */ |
| 17964 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 17965 | if (rc) { |
| 17966 | error = -EINVAL; |
| 17967 | goto fail_fcf_read; |
| 17968 | } |
| 17969 | /* Issue the mailbox command asynchronously */ |
| 17970 | mboxq->vport = phba->pport; |
| 17971 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 17972 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17973 | if (rc == MBX_NOT_FINISHED) |
| 17974 | error = -EIO; |
| 17975 | else |
| 17976 | error = 0; |
| 17977 | |
| 17978 | fail_fcf_read: |
| 17979 | if (error && mboxq) |
| 17980 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17981 | return error; |
| 17982 | } |
| 17983 | |
| 17984 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 17985 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 17986 | * phba pointer to the lpfc_hba struct for this port. |
| 17987 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 17988 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 17989 | * rr_bmask based on their priority level. Starting from the highest priority |
| 17990 | * to the lowest. The most likely FCF candidate will be in the highest |
| 17991 | * priority group. When this routine is called it searches the fcf_pri list for |
| 17992 | * next lowest priority group and repopulates the rr_bmask with only those |
| 17993 | * fcf_indexes. |
| 17994 | * returns: |
| 17995 | * 1=success 0=failure |
| 17996 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17997 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 17998 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 17999 | { |
| 18000 | uint16_t next_fcf_pri; |
| 18001 | uint16_t last_index; |
| 18002 | struct lpfc_fcf_pri *fcf_pri; |
| 18003 | int rc; |
| 18004 | int ret = 0; |
| 18005 | |
| 18006 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 18007 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18008 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 18009 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18010 | |
| 18011 | /* Verify the priority list has 2 or more entries */ |
| 18012 | spin_lock_irq(&phba->hbalock); |
| 18013 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 18014 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 18015 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18016 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 18017 | "3061 Last IDX %d\n", last_index); |
| 18018 | return 0; /* Empty rr list */ |
| 18019 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 18020 | spin_unlock_irq(&phba->hbalock); |
| 18021 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18022 | next_fcf_pri = 0; |
| 18023 | /* |
| 18024 | * Clear the rr_bmask and set all of the bits that are at this |
| 18025 | * priority. |
| 18026 | */ |
| 18027 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 18028 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 18029 | spin_lock_irq(&phba->hbalock); |
| 18030 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18031 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 18032 | continue; |
| 18033 | /* |
| 18034 | * the 1st priority that has not FLOGI failed |
| 18035 | * will be the highest. |
| 18036 | */ |
| 18037 | if (!next_fcf_pri) |
| 18038 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18039 | spin_unlock_irq(&phba->hbalock); |
| 18040 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18041 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18042 | fcf_pri->fcf_rec.fcf_index); |
| 18043 | if (rc) |
| 18044 | return 0; |
| 18045 | } |
| 18046 | spin_lock_irq(&phba->hbalock); |
| 18047 | } |
| 18048 | /* |
| 18049 | * if next_fcf_pri was not set above and the list is not empty then |
| 18050 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 18051 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18052 | */ |
| 18053 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 18054 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18055 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 18056 | /* |
| 18057 | * the 1st priority that has not FLOGI failed |
| 18058 | * will be the highest. |
| 18059 | */ |
| 18060 | if (!next_fcf_pri) |
| 18061 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18062 | spin_unlock_irq(&phba->hbalock); |
| 18063 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18064 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18065 | fcf_pri->fcf_rec.fcf_index); |
| 18066 | if (rc) |
| 18067 | return 0; |
| 18068 | } |
| 18069 | spin_lock_irq(&phba->hbalock); |
| 18070 | } |
| 18071 | } else |
| 18072 | ret = 1; |
| 18073 | spin_unlock_irq(&phba->hbalock); |
| 18074 | |
| 18075 | return ret; |
| 18076 | } |
| 18077 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18078 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 18079 | * @phba: pointer to lpfc hba data structure. |
| 18080 | * |
| 18081 | * This routine is to get the next eligible FCF record index in a round |
| 18082 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18083 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18084 | * shall be returned, otherwise, the next eligible FCF record's index |
| 18085 | * shall be returned. |
| 18086 | **/ |
| 18087 | uint16_t |
| 18088 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 18089 | { |
| 18090 | uint16_t next_fcf_index; |
| 18091 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18092 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18093 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18094 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 18095 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18096 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18097 | /* Determine the next fcf index to check */ |
| 18098 | 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] | 18099 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18100 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18101 | next_fcf_index); |
| 18102 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18103 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18104 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18105 | /* |
| 18106 | * If we have wrapped then we need to clear the bits that |
| 18107 | * have been tested so that we can detect when we should |
| 18108 | * change the priority level. |
| 18109 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18110 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18111 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18112 | } |
| 18113 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18114 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18115 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18116 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 18117 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 18118 | /* |
| 18119 | * If next fcf index is not found check if there are lower |
| 18120 | * Priority level fcf's in the fcf_priority list. |
| 18121 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 18122 | * at that level and continue the selection process. |
| 18123 | */ |
| 18124 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18125 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18126 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18127 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18128 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 18129 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18130 | else { |
| 18131 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18132 | "3063 Only FCF available idx %d, flag %x\n", |
| 18133 | next_fcf_index, |
| 18134 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 18135 | return next_fcf_index; |
| 18136 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18137 | } |
| 18138 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18139 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 18140 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18141 | LPFC_FCF_FLOGI_FAILED) { |
| 18142 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 18143 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18144 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18145 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18146 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18147 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18148 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18149 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 18150 | next_fcf_index); |
| 18151 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18152 | return next_fcf_index; |
| 18153 | } |
| 18154 | |
| 18155 | /** |
| 18156 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 18157 | * @phba: pointer to lpfc hba data structure. |
| 18158 | * |
| 18159 | * 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] | 18160 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18161 | * does not go beyond the range of the driver allocated bmask dimension |
| 18162 | * before setting the bit. |
| 18163 | * |
| 18164 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 18165 | * -EINVAL. |
| 18166 | **/ |
| 18167 | int |
| 18168 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18169 | { |
| 18170 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18171 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18172 | "2610 FCF (x%x) reached driver's book " |
| 18173 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18174 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18175 | return -EINVAL; |
| 18176 | } |
| 18177 | /* Set the eligible FCF record index bmask */ |
| 18178 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 18179 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18180 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18181 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18182 | "bmask\n", fcf_index); |
| 18183 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18184 | return 0; |
| 18185 | } |
| 18186 | |
| 18187 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18188 | * 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] | 18189 | * @phba: pointer to lpfc hba data structure. |
| 18190 | * |
| 18191 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18192 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18193 | * does not go beyond the range of the driver allocated bmask dimension |
| 18194 | * before clearing the bit. |
| 18195 | **/ |
| 18196 | void |
| 18197 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18198 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18199 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18200 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18201 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18202 | "2762 FCF (x%x) reached driver's book " |
| 18203 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18204 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18205 | return; |
| 18206 | } |
| 18207 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18208 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18209 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 18210 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18211 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 18212 | list_del_init(&fcf_pri->list); |
| 18213 | break; |
| 18214 | } |
| 18215 | } |
| 18216 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18217 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18218 | |
| 18219 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18220 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18221 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18222 | } |
| 18223 | |
| 18224 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18225 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 18226 | * @phba: pointer to lpfc hba data structure. |
| 18227 | * |
| 18228 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 18229 | * command. If the mailbox command returned failure, it will try to stop the |
| 18230 | * FCF rediscover wait timer. |
| 18231 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18232 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18233 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 18234 | { |
| 18235 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18236 | uint32_t shdr_status, shdr_add_status; |
| 18237 | |
| 18238 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18239 | |
| 18240 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 18241 | &redisc_fcf->header.cfg_shdr.response); |
| 18242 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 18243 | &redisc_fcf->header.cfg_shdr.response); |
| 18244 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18245 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18246 | "2746 Requesting for FCF rediscovery failed " |
| 18247 | "status x%x add_status x%x\n", |
| 18248 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18249 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18250 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18251 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18252 | spin_unlock_irq(&phba->hbalock); |
| 18253 | /* |
| 18254 | * CVL event triggered FCF rediscover request failed, |
| 18255 | * last resort to re-try current registered FCF entry. |
| 18256 | */ |
| 18257 | lpfc_retry_pport_discovery(phba); |
| 18258 | } else { |
| 18259 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18260 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18261 | spin_unlock_irq(&phba->hbalock); |
| 18262 | /* |
| 18263 | * DEAD FCF event triggered FCF rediscover request |
| 18264 | * failed, last resort to fail over as a link down |
| 18265 | * to FCF registration. |
| 18266 | */ |
| 18267 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 18268 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18269 | } else { |
| 18270 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18271 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18272 | /* |
| 18273 | * Start FCF rediscovery wait timer for pending FCF |
| 18274 | * before rescan FCF record table. |
| 18275 | */ |
| 18276 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18277 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18278 | |
| 18279 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18280 | } |
| 18281 | |
| 18282 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18283 | * 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] | 18284 | * @phba: pointer to lpfc hba data structure. |
| 18285 | * |
| 18286 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 18287 | * by the port. |
| 18288 | **/ |
| 18289 | int |
| 18290 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 18291 | { |
| 18292 | LPFC_MBOXQ_t *mbox; |
| 18293 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18294 | int rc, length; |
| 18295 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18296 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 18297 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 18298 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18299 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18300 | if (!mbox) { |
| 18301 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18302 | "2745 Failed to allocate mbox for " |
| 18303 | "requesting FCF rediscover.\n"); |
| 18304 | return -ENOMEM; |
| 18305 | } |
| 18306 | |
| 18307 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 18308 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 18309 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18310 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 18311 | length, LPFC_SLI4_MBX_EMBED); |
| 18312 | |
| 18313 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18314 | /* Set count to 0 for invalidating the entire FCF database */ |
| 18315 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 18316 | |
| 18317 | /* Issue the mailbox command asynchronously */ |
| 18318 | mbox->vport = phba->pport; |
| 18319 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 18320 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 18321 | |
| 18322 | if (rc == MBX_NOT_FINISHED) { |
| 18323 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18324 | return -EIO; |
| 18325 | } |
| 18326 | return 0; |
| 18327 | } |
| 18328 | |
| 18329 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18330 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 18331 | * @phba: pointer to lpfc hba data structure. |
| 18332 | * |
| 18333 | * This function is the failover routine as a last resort to the FCF DEAD |
| 18334 | * event when driver failed to perform fast FCF failover. |
| 18335 | **/ |
| 18336 | void |
| 18337 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 18338 | { |
| 18339 | uint32_t link_state; |
| 18340 | |
| 18341 | /* |
| 18342 | * Last resort as FCF DEAD event failover will treat this as |
| 18343 | * a link down, but save the link state because we don't want |
| 18344 | * it to be changed to Link Down unless it is already down. |
| 18345 | */ |
| 18346 | link_state = phba->link_state; |
| 18347 | lpfc_linkdown(phba); |
| 18348 | phba->link_state = link_state; |
| 18349 | |
| 18350 | /* Unregister FCF if no devices connected to it */ |
| 18351 | lpfc_unregister_unused_fcf(phba); |
| 18352 | } |
| 18353 | |
| 18354 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18355 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18356 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18357 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18358 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18359 | * This function gets SLI3 port configure region 23 data through memory dump |
| 18360 | * mailbox command. When it successfully retrieves data, the size of the data |
| 18361 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18362 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18363 | static uint32_t |
| 18364 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18365 | { |
| 18366 | LPFC_MBOXQ_t *pmb = NULL; |
| 18367 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18368 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18369 | int rc; |
| 18370 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18371 | if (!rgn23_data) |
| 18372 | return 0; |
| 18373 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18374 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18375 | if (!pmb) { |
| 18376 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18377 | "2600 failed to allocate mailbox memory\n"); |
| 18378 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18379 | } |
| 18380 | mb = &pmb->u.mb; |
| 18381 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18382 | do { |
| 18383 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 18384 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 18385 | |
| 18386 | if (rc != MBX_SUCCESS) { |
| 18387 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18388 | "2601 failed to read config " |
| 18389 | "region 23, rc 0x%x Status 0x%x\n", |
| 18390 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18391 | mb->un.varDmp.word_cnt = 0; |
| 18392 | } |
| 18393 | /* |
| 18394 | * dump mem may return a zero when finished or we got a |
| 18395 | * mailbox error, either way we are done. |
| 18396 | */ |
| 18397 | if (mb->un.varDmp.word_cnt == 0) |
| 18398 | break; |
| 18399 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 18400 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 18401 | |
| 18402 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18403 | rgn23_data + offset, |
| 18404 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18405 | offset += mb->un.varDmp.word_cnt; |
| 18406 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 18407 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18408 | mempool_free(pmb, phba->mbox_mem_pool); |
| 18409 | return offset; |
| 18410 | } |
| 18411 | |
| 18412 | /** |
| 18413 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 18414 | * @phba: pointer to lpfc hba data structure. |
| 18415 | * @rgn23_data: pointer to configure region 23 data. |
| 18416 | * |
| 18417 | * This function gets SLI4 port configure region 23 data through memory dump |
| 18418 | * mailbox command. When it successfully retrieves data, the size of the data |
| 18419 | * will be returned, otherwise, 0 will be returned. |
| 18420 | **/ |
| 18421 | static uint32_t |
| 18422 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 18423 | { |
| 18424 | LPFC_MBOXQ_t *mboxq = NULL; |
| 18425 | struct lpfc_dmabuf *mp = NULL; |
| 18426 | struct lpfc_mqe *mqe; |
| 18427 | uint32_t data_length = 0; |
| 18428 | int rc; |
| 18429 | |
| 18430 | if (!rgn23_data) |
| 18431 | return 0; |
| 18432 | |
| 18433 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18434 | if (!mboxq) { |
| 18435 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18436 | "3105 failed to allocate mailbox memory\n"); |
| 18437 | return 0; |
| 18438 | } |
| 18439 | |
| 18440 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 18441 | goto out; |
| 18442 | mqe = &mboxq->u.mqe; |
| 18443 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 18444 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 18445 | if (rc) |
| 18446 | goto out; |
| 18447 | data_length = mqe->un.mb_words[5]; |
| 18448 | if (data_length == 0) |
| 18449 | goto out; |
| 18450 | if (data_length > DMP_RGN23_SIZE) { |
| 18451 | data_length = 0; |
| 18452 | goto out; |
| 18453 | } |
| 18454 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 18455 | out: |
| 18456 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18457 | if (mp) { |
| 18458 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 18459 | kfree(mp); |
| 18460 | } |
| 18461 | return data_length; |
| 18462 | } |
| 18463 | |
| 18464 | /** |
| 18465 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 18466 | * @phba: pointer to lpfc hba data structure. |
| 18467 | * |
| 18468 | * This function read region 23 and parse TLV for port status to |
| 18469 | * decide if the user disaled the port. If the TLV indicates the |
| 18470 | * port is disabled, the hba_flag is set accordingly. |
| 18471 | **/ |
| 18472 | void |
| 18473 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 18474 | { |
| 18475 | uint8_t *rgn23_data = NULL; |
| 18476 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 18477 | uint32_t offset = 0; |
| 18478 | |
| 18479 | /* Get adapter Region 23 data */ |
| 18480 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 18481 | if (!rgn23_data) |
| 18482 | goto out; |
| 18483 | |
| 18484 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 18485 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 18486 | else { |
| 18487 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 18488 | &phba->sli4_hba.sli_intf); |
| 18489 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 18490 | goto out; |
| 18491 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 18492 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18493 | |
| 18494 | if (!data_size) |
| 18495 | goto out; |
| 18496 | |
| 18497 | /* Check the region signature first */ |
| 18498 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 18499 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18500 | "2619 Config region 23 has bad signature\n"); |
| 18501 | goto out; |
| 18502 | } |
| 18503 | offset += 4; |
| 18504 | |
| 18505 | /* Check the data structure version */ |
| 18506 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 18507 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18508 | "2620 Config region 23 has bad version\n"); |
| 18509 | goto out; |
| 18510 | } |
| 18511 | offset += 4; |
| 18512 | |
| 18513 | /* Parse TLV entries in the region */ |
| 18514 | while (offset < data_size) { |
| 18515 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 18516 | break; |
| 18517 | /* |
| 18518 | * If the TLV is not driver specific TLV or driver id is |
| 18519 | * not linux driver id, skip the record. |
| 18520 | */ |
| 18521 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 18522 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 18523 | (rgn23_data[offset + 3] != 0)) { |
| 18524 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 18525 | continue; |
| 18526 | } |
| 18527 | |
| 18528 | /* Driver found a driver specific TLV in the config region */ |
| 18529 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 18530 | offset += 4; |
| 18531 | tlv_offset = 0; |
| 18532 | |
| 18533 | /* |
| 18534 | * Search for configured port state sub-TLV. |
| 18535 | */ |
| 18536 | while ((offset < data_size) && |
| 18537 | (tlv_offset < sub_tlv_len)) { |
| 18538 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 18539 | offset += 4; |
| 18540 | tlv_offset += 4; |
| 18541 | break; |
| 18542 | } |
| 18543 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 18544 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 18545 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 18546 | continue; |
| 18547 | } |
| 18548 | |
| 18549 | /* This HBA contains PORT_STE configured */ |
| 18550 | if (!rgn23_data[offset + 2]) |
| 18551 | phba->hba_flag |= LINK_DISABLED; |
| 18552 | |
| 18553 | goto out; |
| 18554 | } |
| 18555 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18556 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18557 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18558 | kfree(rgn23_data); |
| 18559 | return; |
| 18560 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18561 | |
| 18562 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 18563 | * lpfc_wr_object - write an object to the firmware |
| 18564 | * @phba: HBA structure that indicates port to create a queue on. |
| 18565 | * @dmabuf_list: list of dmabufs to write to the port. |
| 18566 | * @size: the total byte value of the objects to write to the port. |
| 18567 | * @offset: the current offset to be used to start the transfer. |
| 18568 | * |
| 18569 | * This routine will create a wr_object mailbox command to send to the port. |
| 18570 | * the mailbox command will be constructed using the dma buffers described in |
| 18571 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 18572 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 18573 | * used to indicate the starting offset of the transfer and will also return |
| 18574 | * the offset after the write object mailbox has completed. @size is used to |
| 18575 | * determine the end of the object and whether the eof bit should be set. |
| 18576 | * |
| 18577 | * Return 0 is successful and offset will contain the the new offset to use |
| 18578 | * for the next write. |
| 18579 | * Return negative value for error cases. |
| 18580 | **/ |
| 18581 | int |
| 18582 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 18583 | uint32_t size, uint32_t *offset) |
| 18584 | { |
| 18585 | struct lpfc_mbx_wr_object *wr_object; |
| 18586 | LPFC_MBOXQ_t *mbox; |
| 18587 | int rc = 0, i = 0; |
| 18588 | uint32_t shdr_status, shdr_add_status; |
| 18589 | uint32_t mbox_tmo; |
| 18590 | union lpfc_sli4_cfg_shdr *shdr; |
| 18591 | struct lpfc_dmabuf *dmabuf; |
| 18592 | uint32_t written = 0; |
| 18593 | |
| 18594 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18595 | if (!mbox) |
| 18596 | return -ENOMEM; |
| 18597 | |
| 18598 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 18599 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 18600 | sizeof(struct lpfc_mbx_wr_object) - |
| 18601 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 18602 | |
| 18603 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 18604 | wr_object->u.request.write_offset = *offset; |
| 18605 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 18606 | wr_object->u.request.object_name[0] = |
| 18607 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 18608 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 18609 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 18610 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 18611 | break; |
| 18612 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 18613 | wr_object->u.request.bde[i].addrHigh = |
| 18614 | putPaddrHigh(dmabuf->phys); |
| 18615 | if (written + SLI4_PAGE_SIZE >= size) { |
| 18616 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 18617 | (size - written); |
| 18618 | written += (size - written); |
| 18619 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 18620 | } else { |
| 18621 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 18622 | SLI4_PAGE_SIZE; |
| 18623 | written += SLI4_PAGE_SIZE; |
| 18624 | } |
| 18625 | i++; |
| 18626 | } |
| 18627 | wr_object->u.request.bde_count = i; |
| 18628 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 18629 | if (!phba->sli4_hba.intr_enable) |
| 18630 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 18631 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18632 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 18633 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 18634 | } |
| 18635 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18636 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 18637 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18638 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18639 | if (rc != MBX_TIMEOUT) |
| 18640 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18641 | if (shdr_status || shdr_add_status || rc) { |
| 18642 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18643 | "3025 Write Object mailbox failed with " |
| 18644 | "status x%x add_status x%x, mbx status x%x\n", |
| 18645 | shdr_status, shdr_add_status, rc); |
| 18646 | rc = -ENXIO; |
| 18647 | } else |
| 18648 | *offset += wr_object->u.response.actual_write_length; |
| 18649 | return rc; |
| 18650 | } |
| 18651 | |
| 18652 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18653 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 18654 | * @vport: pointer to vport data structure. |
| 18655 | * |
| 18656 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 18657 | * and REG_VPI mailbox commands associated with the vport. This function |
| 18658 | * is called when driver want to restart discovery of the vport due to |
| 18659 | * a Clear Virtual Link event. |
| 18660 | **/ |
| 18661 | void |
| 18662 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 18663 | { |
| 18664 | struct lpfc_hba *phba = vport->phba; |
| 18665 | LPFC_MBOXQ_t *mb, *nextmb; |
| 18666 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18667 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18668 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 18669 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18670 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 18671 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18672 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18673 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18674 | spin_lock_irq(&phba->hbalock); |
| 18675 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 18676 | if (mb->vport != vport) |
| 18677 | continue; |
| 18678 | |
| 18679 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 18680 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 18681 | continue; |
| 18682 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18683 | list_del(&mb->list); |
| 18684 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 18685 | } |
| 18686 | /* Clean up active mailbox command with the vport */ |
| 18687 | mb = phba->sli.mbox_active; |
| 18688 | if (mb && (mb->vport == vport)) { |
| 18689 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 18690 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 18691 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 18692 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 18693 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 18694 | /* Put reference count for delayed processing */ |
| 18695 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 18696 | /* Unregister the RPI when mailbox complete */ |
| 18697 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 18698 | } |
| 18699 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 18700 | /* Cleanup any mailbox completions which are not yet processed */ |
| 18701 | do { |
| 18702 | restart_loop = 0; |
| 18703 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 18704 | /* |
| 18705 | * If this mailox is already processed or it is |
| 18706 | * for another vport ignore it. |
| 18707 | */ |
| 18708 | if ((mb->vport != vport) || |
| 18709 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 18710 | continue; |
| 18711 | |
| 18712 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 18713 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 18714 | continue; |
| 18715 | |
| 18716 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 18717 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 18718 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 18719 | /* Unregister the RPI when mailbox complete */ |
| 18720 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 18721 | restart_loop = 1; |
| 18722 | spin_unlock_irq(&phba->hbalock); |
| 18723 | spin_lock(shost->host_lock); |
| 18724 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 18725 | spin_unlock(shost->host_lock); |
| 18726 | spin_lock_irq(&phba->hbalock); |
| 18727 | break; |
| 18728 | } |
| 18729 | } |
| 18730 | } while (restart_loop); |
| 18731 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18732 | spin_unlock_irq(&phba->hbalock); |
| 18733 | |
| 18734 | /* Release the cleaned-up mailbox commands */ |
| 18735 | while (!list_empty(&mbox_cmd_list)) { |
| 18736 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18737 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 18738 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 18739 | if (mp) { |
| 18740 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 18741 | kfree(mp); |
| 18742 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18743 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18744 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18745 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 18746 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 18747 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 18748 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18749 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18750 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18751 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18752 | mempool_free(mb, phba->mbox_mem_pool); |
| 18753 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18754 | |
| 18755 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 18756 | if (act_mbx_ndlp) { |
| 18757 | spin_lock(shost->host_lock); |
| 18758 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 18759 | spin_unlock(shost->host_lock); |
| 18760 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18761 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18762 | } |
| 18763 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18764 | /** |
| 18765 | * lpfc_drain_txq - Drain the txq |
| 18766 | * @phba: Pointer to HBA context object. |
| 18767 | * |
| 18768 | * This function attempt to submit IOCBs on the txq |
| 18769 | * to the adapter. For SLI4 adapters, the txq contains |
| 18770 | * ELS IOCBs that have been deferred because the there |
| 18771 | * are no SGLs. This congestion can occur with large |
| 18772 | * vport counts during node discovery. |
| 18773 | **/ |
| 18774 | |
| 18775 | uint32_t |
| 18776 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 18777 | { |
| 18778 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18779 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 18780 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18781 | unsigned long iflags = 0; |
| 18782 | char *fail_msg = NULL; |
| 18783 | struct lpfc_sglq *sglq; |
James Smart | 2f07784 | 2016-12-19 15:07:29 -0800 | [diff] [blame] | 18784 | union lpfc_wqe128 wqe128; |
| 18785 | union lpfc_wqe *wqe = (union lpfc_wqe *) &wqe128; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 18786 | uint32_t txq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18787 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18788 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 18789 | if (unlikely(!pring)) |
| 18790 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18791 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18792 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18793 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 18794 | txq_cnt++; |
| 18795 | } |
| 18796 | |
| 18797 | if (txq_cnt > pring->txq_max) |
| 18798 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18799 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18800 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18801 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18802 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18803 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18804 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 18805 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 18806 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18807 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 18808 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18809 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18810 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 18811 | break; |
| 18812 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18813 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18814 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 18815 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18816 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18817 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18818 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18819 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18820 | |
| 18821 | /* The xri and iocb resources secured, |
| 18822 | * attempt to issue request |
| 18823 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18824 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18825 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 18826 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 18827 | fail_msg = "to convert bpl to sgl"; |
James Smart | 2f07784 | 2016-12-19 15:07:29 -0800 | [diff] [blame] | 18828 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18829 | fail_msg = "to convert iocb to wqe"; |
James Smart | 2f07784 | 2016-12-19 15:07:29 -0800 | [diff] [blame] | 18830 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18831 | fail_msg = " - Wq is full"; |
| 18832 | else |
| 18833 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 18834 | |
| 18835 | if (fail_msg) { |
| 18836 | /* Failed means we can't issue and need to cancel */ |
| 18837 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18838 | "2822 IOCB failed %s iotag 0x%x " |
| 18839 | "xri 0x%x\n", |
| 18840 | fail_msg, |
| 18841 | piocbq->iotag, piocbq->sli4_xritag); |
| 18842 | list_add_tail(&piocbq->list, &completions); |
| 18843 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18844 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18845 | } |
| 18846 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18847 | /* Cancel all the IOCBs that cannot be issued */ |
| 18848 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 18849 | IOERR_SLI_ABORTED); |
| 18850 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18851 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18852 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18853 | |
| 18854 | /** |
| 18855 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 18856 | * @phba: Pointer to HBA context object. |
| 18857 | * @pwqe: Pointer to command WQE. |
| 18858 | * @sglq: Pointer to the scatter gather queue object. |
| 18859 | * |
| 18860 | * This routine converts the bpl or bde that is in the WQE |
| 18861 | * to a sgl list for the sli4 hardware. The physical address |
| 18862 | * of the bpl/bde is converted back to a virtual address. |
| 18863 | * If the WQE contains a BPL then the list of BDE's is |
| 18864 | * converted to sli4_sge's. If the WQE contains a single |
| 18865 | * BDE then it is converted to a single sli_sge. |
| 18866 | * The WQE is still in cpu endianness so the contents of |
| 18867 | * the bpl can be used without byte swapping. |
| 18868 | * |
| 18869 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 18870 | */ |
| 18871 | static uint16_t |
| 18872 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 18873 | struct lpfc_sglq *sglq) |
| 18874 | { |
| 18875 | uint16_t xritag = NO_XRI; |
| 18876 | struct ulp_bde64 *bpl = NULL; |
| 18877 | struct ulp_bde64 bde; |
| 18878 | struct sli4_sge *sgl = NULL; |
| 18879 | struct lpfc_dmabuf *dmabuf; |
| 18880 | union lpfc_wqe *wqe; |
| 18881 | int numBdes = 0; |
| 18882 | int i = 0; |
| 18883 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 18884 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 18885 | uint32_t cmd; |
| 18886 | |
| 18887 | if (!pwqeq || !sglq) |
| 18888 | return xritag; |
| 18889 | |
| 18890 | sgl = (struct sli4_sge *)sglq->sgl; |
| 18891 | wqe = &pwqeq->wqe; |
| 18892 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 18893 | |
| 18894 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 18895 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 18896 | return sglq->sli4_xritag; |
| 18897 | numBdes = pwqeq->rsvd2; |
| 18898 | if (numBdes) { |
| 18899 | /* The addrHigh and addrLow fields within the WQE |
| 18900 | * have not been byteswapped yet so there is no |
| 18901 | * need to swap them back. |
| 18902 | */ |
| 18903 | if (pwqeq->context3) |
| 18904 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 18905 | else |
| 18906 | return xritag; |
| 18907 | |
| 18908 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 18909 | if (!bpl) |
| 18910 | return xritag; |
| 18911 | |
| 18912 | for (i = 0; i < numBdes; i++) { |
| 18913 | /* Should already be byte swapped. */ |
| 18914 | sgl->addr_hi = bpl->addrHigh; |
| 18915 | sgl->addr_lo = bpl->addrLow; |
| 18916 | |
| 18917 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 18918 | if ((i+1) == numBdes) |
| 18919 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 18920 | else |
| 18921 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 18922 | /* swap the size field back to the cpu so we |
| 18923 | * can assign it to the sgl. |
| 18924 | */ |
| 18925 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 18926 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 18927 | /* The offsets in the sgl need to be accumulated |
| 18928 | * separately for the request and reply lists. |
| 18929 | * The request is always first, the reply follows. |
| 18930 | */ |
| 18931 | switch (cmd) { |
| 18932 | case CMD_GEN_REQUEST64_WQE: |
| 18933 | /* add up the reply sg entries */ |
| 18934 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 18935 | inbound++; |
| 18936 | /* first inbound? reset the offset */ |
| 18937 | if (inbound == 1) |
| 18938 | offset = 0; |
| 18939 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 18940 | bf_set(lpfc_sli4_sge_type, sgl, |
| 18941 | LPFC_SGE_TYPE_DATA); |
| 18942 | offset += bde.tus.f.bdeSize; |
| 18943 | break; |
| 18944 | case CMD_FCP_TRSP64_WQE: |
| 18945 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 18946 | bf_set(lpfc_sli4_sge_type, sgl, |
| 18947 | LPFC_SGE_TYPE_DATA); |
| 18948 | break; |
| 18949 | case CMD_FCP_TSEND64_WQE: |
| 18950 | case CMD_FCP_TRECEIVE64_WQE: |
| 18951 | bf_set(lpfc_sli4_sge_type, sgl, |
| 18952 | bpl->tus.f.bdeFlags); |
| 18953 | if (i < 3) |
| 18954 | offset = 0; |
| 18955 | else |
| 18956 | offset += bde.tus.f.bdeSize; |
| 18957 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 18958 | break; |
| 18959 | } |
| 18960 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 18961 | bpl++; |
| 18962 | sgl++; |
| 18963 | } |
| 18964 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 18965 | /* The addrHigh and addrLow fields of the BDE have not |
| 18966 | * been byteswapped yet so they need to be swapped |
| 18967 | * before putting them in the sgl. |
| 18968 | */ |
| 18969 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 18970 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 18971 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 18972 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 18973 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 18974 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 18975 | } |
| 18976 | return sglq->sli4_xritag; |
| 18977 | } |
| 18978 | |
| 18979 | /** |
| 18980 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 18981 | * @phba: Pointer to HBA context object. |
| 18982 | * @ring_number: Base sli ring number |
| 18983 | * @pwqe: Pointer to command WQE. |
| 18984 | **/ |
| 18985 | int |
| 18986 | lpfc_sli4_issue_wqe(struct lpfc_hba *phba, uint32_t ring_number, |
| 18987 | struct lpfc_iocbq *pwqe) |
| 18988 | { |
| 18989 | union lpfc_wqe *wqe = &pwqe->wqe; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 18990 | struct lpfc_nvmet_rcv_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18991 | struct lpfc_queue *wq; |
| 18992 | struct lpfc_sglq *sglq; |
| 18993 | struct lpfc_sli_ring *pring; |
| 18994 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18995 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18996 | |
| 18997 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 18998 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 18999 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 19000 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 19001 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 19002 | if (!sglq) { |
| 19003 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19004 | return WQE_BUSY; |
| 19005 | } |
| 19006 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19007 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19008 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 19009 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19010 | return WQE_ERROR; |
| 19011 | } |
| 19012 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19013 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19014 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 19015 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19016 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19017 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19018 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19019 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19020 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19021 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19022 | return 0; |
| 19023 | } |
| 19024 | |
| 19025 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 19026 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 19027 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
| 19028 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; |
| 19029 | |
| 19030 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 19031 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; |
| 19032 | bf_set(wqe_cqid, &wqe->generic.wqe_com, |
| 19033 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19034 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19035 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19036 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19037 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19038 | } |
| 19039 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19040 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19041 | return 0; |
| 19042 | } |
| 19043 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19044 | /* NVMET requests */ |
| 19045 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 19046 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
| 19047 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; |
| 19048 | |
| 19049 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 19050 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 19051 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19052 | if (pwqe->sli4_xritag == NO_XRI) { |
| 19053 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19054 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19055 | } |
| 19056 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19057 | pwqe->sli4_xritag); |
| 19058 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; |
| 19059 | bf_set(wqe_cqid, &wqe->generic.wqe_com, |
| 19060 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19061 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19062 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19063 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19064 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19065 | } |
| 19066 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19067 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19068 | return 0; |
| 19069 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19070 | return WQE_ERROR; |
| 19071 | } |