James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 1 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2 | /******************************************************************* |
| 3 | * 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] | 4 | * Fibre Channel Host Bus Adapters. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 5 | * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * |
| 6 | * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 7 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 8 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 9 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11 | * * |
| 12 | * 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] | 13 | * modify it under the terms of version 2 of the GNU General * |
| 14 | * Public License as published by the Free Software Foundation. * |
| 15 | * This program is distributed in the hope that it will be useful. * |
| 16 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 17 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 19 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 20 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 21 | * more details, a copy of which can be found in the file COPYING * |
| 22 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 23 | *******************************************************************/ |
| 24 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | #include <linux/blkdev.h> |
| 26 | #include <linux/pci.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 30 | #include <linux/lockdep.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 32 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include <scsi/scsi_cmnd.h> |
| 34 | #include <scsi/scsi_device.h> |
| 35 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 36 | #include <scsi/scsi_transport_fc.h> |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 37 | #include <scsi/fc/fc_fs.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 38 | #include <linux/aer.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 40 | #include <linux/nvme-fc-driver.h> |
| 41 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 42 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | #include "lpfc_hw.h" |
| 44 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 45 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 46 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 49 | #include "lpfc_scsi.h" |
| 50 | #include "lpfc_nvme.h" |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 51 | #include "lpfc_nvmet.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 52 | #include "lpfc_crtn.h" |
| 53 | #include "lpfc_logmsg.h" |
| 54 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 55 | #include "lpfc_debugfs.h" |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 56 | #include "lpfc_vport.h" |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 57 | #include "lpfc_version.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | |
| 59 | /* There are only four IOCB completion types. */ |
| 60 | typedef enum _lpfc_iocb_type { |
| 61 | LPFC_UNKNOWN_IOCB, |
| 62 | LPFC_UNSOL_IOCB, |
| 63 | LPFC_SOL_IOCB, |
| 64 | LPFC_ABORT_IOCB |
| 65 | } lpfc_iocb_type; |
| 66 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 67 | |
| 68 | /* Provide function prototypes local to this module. */ |
| 69 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, |
| 70 | uint32_t); |
| 71 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 72 | uint8_t *, uint32_t *); |
| 73 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, |
| 74 | struct lpfc_iocbq *); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 75 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
| 76 | struct hbq_dmabuf *); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 77 | static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 78 | struct hbq_dmabuf *dmabuf); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 79 | 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] | 80 | struct lpfc_cqe *); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 81 | 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] | 82 | int); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 83 | static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, |
| 84 | struct lpfc_eqe *eqe, uint32_t qidx); |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 85 | static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba); |
| 86 | static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 87 | static int lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, |
| 88 | struct lpfc_sli_ring *pring, |
| 89 | struct lpfc_iocbq *cmdiocb); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 90 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 91 | static IOCB_t * |
| 92 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) |
| 93 | { |
| 94 | return &iocbq->iocb; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue |
| 99 | * @q: The Work Queue to operate on. |
| 100 | * @wqe: The work Queue Entry to put on the Work queue. |
| 101 | * |
| 102 | * This routine will copy the contents of @wqe to the next available entry on |
| 103 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 104 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 105 | * successful. If no entries are available on @q then this function will return |
| 106 | * -ENOMEM. |
| 107 | * The caller is expected to hold the hbalock when calling this routine. |
| 108 | **/ |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 109 | static int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 110 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) |
| 111 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 112 | union lpfc_wqe *temp_wqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 113 | struct lpfc_register doorbell; |
| 114 | uint32_t host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 115 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 116 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 117 | /* sanity check on queue memory */ |
| 118 | if (unlikely(!q)) |
| 119 | return -ENOMEM; |
| 120 | temp_wqe = q->qe[q->host_index].wqe; |
| 121 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 122 | /* 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] | 123 | idx = ((q->host_index + 1) % q->entry_count); |
| 124 | if (idx == q->hba_index) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 125 | q->WQ_overflow++; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 126 | return -EBUSY; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 127 | } |
| 128 | q->WQ_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 129 | /* set consumption flag every once in a while */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 130 | if (!((q->host_index + 1) % q->entry_repost)) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 131 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 132 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
| 133 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 134 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
James Smart | 6b3b3bd | 2016-12-19 15:07:30 -0800 | [diff] [blame] | 135 | /* ensure WQE bcopy flushed before doorbell write */ |
| 136 | wmb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 137 | |
| 138 | /* Update the host index before invoking device */ |
| 139 | host_index = q->host_index; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 140 | |
| 141 | q->host_index = idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 142 | |
| 143 | /* Ring Doorbell */ |
| 144 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 145 | if (q->db_format == LPFC_DB_LIST_FORMAT) { |
| 146 | bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1); |
| 147 | bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index); |
| 148 | bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id); |
| 149 | } else if (q->db_format == LPFC_DB_RING_FORMAT) { |
| 150 | bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1); |
| 151 | bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id); |
| 152 | } else { |
| 153 | return -EINVAL; |
| 154 | } |
| 155 | writel(doorbell.word0, q->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * lpfc_sli4_wq_release - Updates internal hba index for WQ |
| 162 | * @q: The Work Queue to operate on. |
| 163 | * @index: The index to advance the hba index to. |
| 164 | * |
| 165 | * This routine will update the HBA index of a queue to reflect consumption of |
| 166 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed |
| 167 | * an entry the host calls this function to update the queue's internal |
| 168 | * pointers. This routine returns the number of entries that were consumed by |
| 169 | * the HBA. |
| 170 | **/ |
| 171 | static uint32_t |
| 172 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) |
| 173 | { |
| 174 | uint32_t released = 0; |
| 175 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 176 | /* sanity check on queue memory */ |
| 177 | if (unlikely(!q)) |
| 178 | return 0; |
| 179 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 180 | if (q->hba_index == index) |
| 181 | return 0; |
| 182 | do { |
| 183 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 184 | released++; |
| 185 | } while (q->hba_index != index); |
| 186 | return released; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue |
| 191 | * @q: The Mailbox Queue to operate on. |
| 192 | * @wqe: The Mailbox Queue Entry to put on the Work queue. |
| 193 | * |
| 194 | * This routine will copy the contents of @mqe to the next available entry on |
| 195 | * the @q. This function will then ring the Work Queue Doorbell to signal the |
| 196 | * HBA to start processing the Work Queue Entry. This function returns 0 if |
| 197 | * successful. If no entries are available on @q then this function will return |
| 198 | * -ENOMEM. |
| 199 | * The caller is expected to hold the hbalock when calling this routine. |
| 200 | **/ |
| 201 | static uint32_t |
| 202 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) |
| 203 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 204 | struct lpfc_mqe *temp_mqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 205 | struct lpfc_register doorbell; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 206 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 207 | /* sanity check on queue memory */ |
| 208 | if (unlikely(!q)) |
| 209 | return -ENOMEM; |
| 210 | temp_mqe = q->qe[q->host_index].mqe; |
| 211 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 212 | /* If the host has not yet processed the next entry then we are done */ |
| 213 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) |
| 214 | return -ENOMEM; |
| 215 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); |
| 216 | /* Save off the mailbox pointer for completion */ |
| 217 | q->phba->mbox = (MAILBOX_t *)temp_mqe; |
| 218 | |
| 219 | /* Update the host index before invoking device */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 220 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 221 | |
| 222 | /* Ring Doorbell */ |
| 223 | doorbell.word0 = 0; |
| 224 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); |
| 225 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); |
| 226 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * lpfc_sli4_mq_release - Updates internal hba index for MQ |
| 232 | * @q: The Mailbox Queue to operate on. |
| 233 | * |
| 234 | * This routine will update the HBA index of a queue to reflect consumption of |
| 235 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed |
| 236 | * an entry the host calls this function to update the queue's internal |
| 237 | * pointers. This routine returns the number of entries that were consumed by |
| 238 | * the HBA. |
| 239 | **/ |
| 240 | static uint32_t |
| 241 | lpfc_sli4_mq_release(struct lpfc_queue *q) |
| 242 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 243 | /* sanity check on queue memory */ |
| 244 | if (unlikely(!q)) |
| 245 | return 0; |
| 246 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 247 | /* Clear the mailbox pointer for completion */ |
| 248 | q->phba->mbox = NULL; |
| 249 | q->hba_index = ((q->hba_index + 1) % q->entry_count); |
| 250 | return 1; |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ |
| 255 | * @q: The Event Queue to get the first valid EQE from |
| 256 | * |
| 257 | * This routine will get the first valid Event Queue Entry from @q, update |
| 258 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in |
| 259 | * the Queue (no more work to do), or the Queue is full of EQEs that have been |
| 260 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 261 | **/ |
| 262 | static struct lpfc_eqe * |
| 263 | lpfc_sli4_eq_get(struct lpfc_queue *q) |
| 264 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 265 | struct lpfc_eqe *eqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 266 | uint32_t idx; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 267 | |
| 268 | /* sanity check on queue memory */ |
| 269 | if (unlikely(!q)) |
| 270 | return NULL; |
| 271 | eqe = q->qe[q->hba_index].eqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 272 | |
| 273 | /* If the next EQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 274 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 275 | return NULL; |
| 276 | /* 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] | 277 | idx = ((q->hba_index + 1) % q->entry_count); |
| 278 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 279 | return NULL; |
| 280 | |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 281 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 282 | |
| 283 | /* |
| 284 | * insert barrier for instruction interlock : data from the hardware |
| 285 | * 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] | 286 | * upon. Speculative instructions were allowing a bcopy at the start |
| 287 | * of lpfc_sli4_fp_handle_wcqe(), which is called immediately |
| 288 | * after our return, to copy data before the valid bit check above |
| 289 | * was done. As such, some of the copied data was stale. The barrier |
| 290 | * ensures the check is before any data is copied. |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 291 | */ |
| 292 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 293 | return eqe; |
| 294 | } |
| 295 | |
| 296 | /** |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 297 | * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ |
| 298 | * @q: The Event Queue to disable interrupts |
| 299 | * |
| 300 | **/ |
| 301 | static inline void |
| 302 | lpfc_sli4_eq_clr_intr(struct lpfc_queue *q) |
| 303 | { |
| 304 | struct lpfc_register doorbell; |
| 305 | |
| 306 | doorbell.word0 = 0; |
| 307 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 308 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
| 309 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 310 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 311 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
| 312 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 313 | } |
| 314 | |
| 315 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 316 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ |
| 317 | * @q: The Event Queue that the host has completed processing for. |
| 318 | * @arm: Indicates whether the host wants to arms this CQ. |
| 319 | * |
| 320 | * This routine will mark all Event Queue Entries on @q, from the last |
| 321 | * known completed entry to the last entry that was processed, as completed |
| 322 | * by clearing the valid bit for each completion queue entry. Then it will |
| 323 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. |
| 324 | * The internal host index in the @q will be updated by this routine to indicate |
| 325 | * that the host has finished processing the entries. The @arm parameter |
| 326 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 327 | * |
| 328 | * This function will return the number of EQEs that were popped. |
| 329 | **/ |
| 330 | uint32_t |
| 331 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) |
| 332 | { |
| 333 | uint32_t released = 0; |
| 334 | struct lpfc_eqe *temp_eqe; |
| 335 | struct lpfc_register doorbell; |
| 336 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 337 | /* sanity check on queue memory */ |
| 338 | if (unlikely(!q)) |
| 339 | return 0; |
| 340 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 341 | /* while there are valid entries */ |
| 342 | while (q->hba_index != q->host_index) { |
| 343 | temp_eqe = q->qe[q->host_index].eqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 344 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 345 | released++; |
| 346 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 347 | } |
| 348 | if (unlikely(released == 0 && !arm)) |
| 349 | return 0; |
| 350 | |
| 351 | /* ring doorbell for number popped */ |
| 352 | doorbell.word0 = 0; |
| 353 | if (arm) { |
| 354 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 355 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); |
| 356 | } |
| 357 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 358 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 359 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
| 360 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); |
| 361 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 362 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 363 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
| 364 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) |
| 365 | readl(q->phba->sli4_hba.EQCQDBregaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 366 | return released; |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ |
| 371 | * @q: The Completion Queue to get the first valid CQE from |
| 372 | * |
| 373 | * This routine will get the first valid Completion Queue Entry from @q, update |
| 374 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in |
| 375 | * the Queue (no more work to do), or the Queue is full of CQEs that have been |
| 376 | * processed, but not popped back to the HBA then this routine will return NULL. |
| 377 | **/ |
| 378 | static struct lpfc_cqe * |
| 379 | lpfc_sli4_cq_get(struct lpfc_queue *q) |
| 380 | { |
| 381 | struct lpfc_cqe *cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 382 | uint32_t idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 383 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 384 | /* sanity check on queue memory */ |
| 385 | if (unlikely(!q)) |
| 386 | return NULL; |
| 387 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 388 | /* If the next CQE is not valid then we are done */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 389 | 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] | 390 | return NULL; |
| 391 | /* 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] | 392 | idx = ((q->hba_index + 1) % q->entry_count); |
| 393 | if (idx == q->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 394 | return NULL; |
| 395 | |
| 396 | cqe = q->qe[q->hba_index].cqe; |
James Smart | 027140e | 2012-08-03 12:35:44 -0400 | [diff] [blame] | 397 | q->hba_index = idx; |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 398 | |
| 399 | /* |
| 400 | * insert barrier for instruction interlock : data from the hardware |
| 401 | * 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] | 402 | * upon. Given what was seen in lpfc_sli4_cq_get() of speculative |
| 403 | * instructions allowing action on content before valid bit checked, |
| 404 | * add barrier here as well. May not be needed as "content" is a |
| 405 | * single 32-bit entity here (vs multi word structure for cq's). |
James Smart | 27f344e | 2014-05-07 17:16:46 -0400 | [diff] [blame] | 406 | */ |
| 407 | mb(); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 408 | return cqe; |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ |
| 413 | * @q: The Completion Queue that the host has completed processing for. |
| 414 | * @arm: Indicates whether the host wants to arms this CQ. |
| 415 | * |
| 416 | * This routine will mark all Completion queue entries on @q, from the last |
| 417 | * known completed entry to the last entry that was processed, as completed |
| 418 | * by clearing the valid bit for each completion queue entry. Then it will |
| 419 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. |
| 420 | * The internal host index in the @q will be updated by this routine to indicate |
| 421 | * that the host has finished processing the entries. The @arm parameter |
| 422 | * indicates that the queue should be rearmed when ringing the doorbell. |
| 423 | * |
| 424 | * This function will return the number of CQEs that were released. |
| 425 | **/ |
| 426 | uint32_t |
| 427 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) |
| 428 | { |
| 429 | uint32_t released = 0; |
| 430 | struct lpfc_cqe *temp_qe; |
| 431 | struct lpfc_register doorbell; |
| 432 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 433 | /* sanity check on queue memory */ |
| 434 | if (unlikely(!q)) |
| 435 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 436 | /* while there are valid entries */ |
| 437 | while (q->hba_index != q->host_index) { |
| 438 | temp_qe = q->qe[q->host_index].cqe; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 439 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 440 | released++; |
| 441 | q->host_index = ((q->host_index + 1) % q->entry_count); |
| 442 | } |
| 443 | if (unlikely(released == 0 && !arm)) |
| 444 | return 0; |
| 445 | |
| 446 | /* ring doorbell for number popped */ |
| 447 | doorbell.word0 = 0; |
| 448 | if (arm) |
| 449 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); |
| 450 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); |
| 451 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 452 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
| 453 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); |
| 454 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 455 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
| 456 | return released; |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue |
| 461 | * @q: The Header Receive Queue to operate on. |
| 462 | * @wqe: The Receive Queue Entry to put on the Receive queue. |
| 463 | * |
| 464 | * This routine will copy the contents of @wqe to the next available entry on |
| 465 | * the @q. This function will then ring the Receive Queue Doorbell to signal the |
| 466 | * HBA to start processing the Receive Queue Entry. This function returns the |
| 467 | * index that the rqe was copied to if successful. If no entries are available |
| 468 | * on @q then this function will return -ENOMEM. |
| 469 | * The caller is expected to hold the hbalock when calling this routine. |
| 470 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 471 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 472 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, |
| 473 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) |
| 474 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 475 | struct lpfc_rqe *temp_hrqe; |
| 476 | struct lpfc_rqe *temp_drqe; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 477 | struct lpfc_register doorbell; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 478 | int put_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 479 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 480 | /* sanity check on queue memory */ |
| 481 | if (unlikely(!hq) || unlikely(!dq)) |
| 482 | return -ENOMEM; |
Wei Yongjun | 5a25bf3 | 2012-12-02 08:33:24 -0500 | [diff] [blame] | 483 | put_index = hq->host_index; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 484 | temp_hrqe = hq->qe[put_index].rqe; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 485 | temp_drqe = dq->qe[dq->host_index].rqe; |
| 486 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 487 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
| 488 | return -EINVAL; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 489 | if (put_index != dq->host_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 490 | return -EINVAL; |
| 491 | /* If the host has not yet processed the next entry then we are done */ |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 492 | if (((put_index + 1) % hq->entry_count) == hq->hba_index) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 493 | return -EBUSY; |
| 494 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); |
| 495 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); |
| 496 | |
| 497 | /* Update the host index to point to the next slot */ |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 498 | hq->host_index = ((put_index + 1) % hq->entry_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 499 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 500 | hq->RQ_buf_posted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 501 | |
| 502 | /* Ring The Header Receive Queue Doorbell */ |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 503 | if (!(hq->host_index % hq->entry_repost)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 504 | doorbell.word0 = 0; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 505 | if (hq->db_format == LPFC_DB_RING_FORMAT) { |
| 506 | bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell, |
| 507 | hq->entry_repost); |
| 508 | bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id); |
| 509 | } else if (hq->db_format == LPFC_DB_LIST_FORMAT) { |
| 510 | bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell, |
| 511 | hq->entry_repost); |
| 512 | bf_set(lpfc_rq_db_list_fm_index, &doorbell, |
| 513 | hq->host_index); |
| 514 | bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id); |
| 515 | } else { |
| 516 | return -EINVAL; |
| 517 | } |
| 518 | writel(doorbell.word0, hq->db_regaddr); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 519 | } |
| 520 | return put_index; |
| 521 | } |
| 522 | |
| 523 | /** |
| 524 | * lpfc_sli4_rq_release - Updates internal hba index for RQ |
| 525 | * @q: The Header Receive Queue to operate on. |
| 526 | * |
| 527 | * This routine will update the HBA index of a queue to reflect consumption of |
| 528 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has |
| 529 | * consumed an entry the host calls this function to update the queue's |
| 530 | * internal pointers. This routine returns the number of entries that were |
| 531 | * consumed by the HBA. |
| 532 | **/ |
| 533 | static uint32_t |
| 534 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) |
| 535 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 536 | /* sanity check on queue memory */ |
| 537 | if (unlikely(!hq) || unlikely(!dq)) |
| 538 | return 0; |
| 539 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 540 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
| 541 | return 0; |
| 542 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); |
| 543 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); |
| 544 | return 1; |
| 545 | } |
| 546 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 547 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 548 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 549 | * @phba: Pointer to HBA context object. |
| 550 | * @pring: Pointer to driver SLI ring object. |
| 551 | * |
| 552 | * This function returns pointer to next command iocb entry |
| 553 | * in the command ring. The caller must hold hbalock to prevent |
| 554 | * other threads consume the next command iocb. |
| 555 | * SLI-2/SLI-3 provide different sized iocbs. |
| 556 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 557 | static inline IOCB_t * |
| 558 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 559 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 560 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
| 561 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 562 | } |
| 563 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 564 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 565 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 566 | * @phba: Pointer to HBA context object. |
| 567 | * @pring: Pointer to driver SLI ring object. |
| 568 | * |
| 569 | * This function returns pointer to next response iocb entry |
| 570 | * in the response ring. The caller must hold hbalock to make sure |
| 571 | * that no other thread consume the next response iocb. |
| 572 | * SLI-2/SLI-3 provide different sized iocbs. |
| 573 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 574 | static inline IOCB_t * |
| 575 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 576 | { |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 577 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
| 578 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 579 | } |
| 580 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 581 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 582 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 583 | * @phba: Pointer to HBA context object. |
| 584 | * |
| 585 | * This function is called with hbalock held. This function |
| 586 | * allocates a new driver iocb object from the iocb pool. If the |
| 587 | * allocation is successful, it returns pointer to the newly |
| 588 | * allocated iocb object else it returns NULL. |
| 589 | **/ |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 590 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 591 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 592 | { |
| 593 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; |
| 594 | struct lpfc_iocbq * iocbq = NULL; |
| 595 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 596 | lockdep_assert_held(&phba->hbalock); |
| 597 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 598 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 599 | if (iocbq) |
| 600 | phba->iocb_cnt++; |
| 601 | if (phba->iocb_cnt > phba->iocb_max) |
| 602 | phba->iocb_max = phba->iocb_cnt; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 603 | return iocbq; |
| 604 | } |
| 605 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 606 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 607 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. |
| 608 | * @phba: Pointer to HBA context object. |
| 609 | * @xritag: XRI value. |
| 610 | * |
| 611 | * This function clears the sglq pointer from the array of acive |
| 612 | * sglq's. The xritag that is passed in is used to index into the |
| 613 | * array. Before the xritag can be used it needs to be adjusted |
| 614 | * by subtracting the xribase. |
| 615 | * |
| 616 | * Returns sglq ponter = success, NULL = Failure. |
| 617 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 618 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 619 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 620 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 621 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 622 | |
| 623 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
| 624 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 625 | return sglq; |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. |
| 630 | * @phba: Pointer to HBA context object. |
| 631 | * @xritag: XRI value. |
| 632 | * |
| 633 | * This function returns the sglq pointer from the array of acive |
| 634 | * sglq's. The xritag that is passed in is used to index into the |
| 635 | * array. Before the xritag can be used it needs to be adjusted |
| 636 | * by subtracting the xribase. |
| 637 | * |
| 638 | * Returns sglq ponter = success, NULL = Failure. |
| 639 | **/ |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 640 | struct lpfc_sglq * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 641 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
| 642 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 643 | struct lpfc_sglq *sglq; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 644 | |
| 645 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 646 | return sglq; |
| 647 | } |
| 648 | |
| 649 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 650 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 651 | * @phba: Pointer to HBA context object. |
| 652 | * @xritag: xri used in this exchange. |
| 653 | * @rrq: The RRQ to be cleared. |
| 654 | * |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 655 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 656 | void |
| 657 | lpfc_clr_rrq_active(struct lpfc_hba *phba, |
| 658 | uint16_t xritag, |
| 659 | struct lpfc_node_rrq *rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 660 | { |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 661 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 662 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 663 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
| 664 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 665 | |
| 666 | /* The target DID could have been swapped (cable swap) |
| 667 | * we should use the ndlp from the findnode if it is |
| 668 | * available. |
| 669 | */ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 670 | if ((!ndlp) && rrq->ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 671 | ndlp = rrq->ndlp; |
| 672 | |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 673 | if (!ndlp) |
| 674 | goto out; |
| 675 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 676 | if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 677 | rrq->send_rrq = 0; |
| 678 | rrq->xritag = 0; |
| 679 | rrq->rrq_stop_time = 0; |
| 680 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 681 | out: |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 682 | mempool_free(rrq, phba->rrq_pool); |
| 683 | } |
| 684 | |
| 685 | /** |
| 686 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. |
| 687 | * @phba: Pointer to HBA context object. |
| 688 | * |
| 689 | * This function is called with hbalock held. This function |
| 690 | * Checks if stop_time (ratov from setting rrq active) has |
| 691 | * been reached, if it has and the send_rrq flag is set then |
| 692 | * it will call lpfc_send_rrq. If the send_rrq flag is not set |
| 693 | * then it will just call the routine to clear the rrq and |
| 694 | * free the rrq resource. |
| 695 | * The timer is set to the next rrq that is going to expire before |
| 696 | * leaving the routine. |
| 697 | * |
| 698 | **/ |
| 699 | void |
| 700 | lpfc_handle_rrq_active(struct lpfc_hba *phba) |
| 701 | { |
| 702 | struct lpfc_node_rrq *rrq; |
| 703 | struct lpfc_node_rrq *nextrrq; |
| 704 | unsigned long next_time; |
| 705 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 706 | LIST_HEAD(send_rrq); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 707 | |
| 708 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 709 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 710 | next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 711 | list_for_each_entry_safe(rrq, nextrrq, |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 712 | &phba->active_rrq_list, list) { |
| 713 | if (time_after(jiffies, rrq->rrq_stop_time)) |
| 714 | list_move(&rrq->list, &send_rrq); |
| 715 | else if (time_before(rrq->rrq_stop_time, next_time)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 716 | next_time = rrq->rrq_stop_time; |
| 717 | } |
| 718 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 719 | if ((!list_empty(&phba->active_rrq_list)) && |
| 720 | (!(phba->pport->load_flag & FC_UNLOADING))) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 721 | mod_timer(&phba->rrq_tmr, next_time); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 722 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
| 723 | list_del(&rrq->list); |
| 724 | if (!rrq->send_rrq) |
| 725 | /* this call will free the rrq */ |
| 726 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 727 | else if (lpfc_send_rrq(phba, rrq)) { |
| 728 | /* if we send the rrq then the completion handler |
| 729 | * will clear the bit in the xribitmap. |
| 730 | */ |
| 731 | lpfc_clr_rrq_active(phba, rrq->xritag, |
| 732 | rrq); |
| 733 | } |
| 734 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | /** |
| 738 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. |
| 739 | * @vport: Pointer to vport context object. |
| 740 | * @xri: The xri used in the exchange. |
| 741 | * @did: The targets DID for this exchange. |
| 742 | * |
| 743 | * returns NULL = rrq not found in the phba->active_rrq_list. |
| 744 | * rrq = rrq for this xri and target. |
| 745 | **/ |
| 746 | struct lpfc_node_rrq * |
| 747 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) |
| 748 | { |
| 749 | struct lpfc_hba *phba = vport->phba; |
| 750 | struct lpfc_node_rrq *rrq; |
| 751 | struct lpfc_node_rrq *nextrrq; |
| 752 | unsigned long iflags; |
| 753 | |
| 754 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 755 | return NULL; |
| 756 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 757 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { |
| 758 | if (rrq->vport == vport && rrq->xritag == xri && |
| 759 | rrq->nlp_DID == did){ |
| 760 | list_del(&rrq->list); |
| 761 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 762 | return rrq; |
| 763 | } |
| 764 | } |
| 765 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 766 | return NULL; |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. |
| 771 | * @vport: Pointer to vport context object. |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 772 | * @ndlp: Pointer to the lpfc_node_list structure. |
| 773 | * If ndlp is NULL Remove all active RRQs for this vport from the |
| 774 | * phba->active_rrq_list and clear the rrq. |
| 775 | * 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] | 776 | **/ |
| 777 | void |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 778 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 779 | |
| 780 | { |
| 781 | struct lpfc_hba *phba = vport->phba; |
| 782 | struct lpfc_node_rrq *rrq; |
| 783 | struct lpfc_node_rrq *nextrrq; |
| 784 | unsigned long iflags; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 785 | LIST_HEAD(rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 786 | |
| 787 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 788 | return; |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 789 | if (!ndlp) { |
| 790 | lpfc_sli4_vport_delete_els_xri_aborted(vport); |
| 791 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 792 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 793 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 794 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) |
| 795 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) |
| 796 | list_move(&rrq->list, &rrq_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 797 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 798 | |
| 799 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { |
| 800 | list_del(&rrq->list); |
| 801 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
| 802 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | /** |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 806 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 807 | * @phba: Pointer to HBA context object. |
| 808 | * @ndlp: Targets nodelist pointer for this exchange. |
| 809 | * @xritag the xri in the bitmap to test. |
| 810 | * |
| 811 | * This function is called with hbalock held. This function |
| 812 | * returns 0 = rrq not active for this xri |
| 813 | * 1 = rrq is valid for this xri. |
| 814 | **/ |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 815 | int |
| 816 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 817 | uint16_t xritag) |
| 818 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 819 | lockdep_assert_held(&phba->hbalock); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 820 | if (!ndlp) |
| 821 | return 0; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 822 | if (!ndlp->active_rrqs_xri_bitmap) |
| 823 | return 0; |
| 824 | if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 825 | return 1; |
| 826 | else |
| 827 | return 0; |
| 828 | } |
| 829 | |
| 830 | /** |
| 831 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. |
| 832 | * @phba: Pointer to HBA context object. |
| 833 | * @ndlp: nodelist pointer for this target. |
| 834 | * @xritag: xri used in this exchange. |
| 835 | * @rxid: Remote Exchange ID. |
| 836 | * @send_rrq: Flag used to determine if we should send rrq els cmd. |
| 837 | * |
| 838 | * This function takes the hbalock. |
| 839 | * The active bit is always set in the active rrq xri_bitmap even |
| 840 | * if there is no slot avaiable for the other rrq information. |
| 841 | * |
| 842 | * returns 0 rrq actived for this xri |
| 843 | * < 0 No memory or invalid ndlp. |
| 844 | **/ |
| 845 | int |
| 846 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 847 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 848 | { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 849 | unsigned long iflags; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 850 | struct lpfc_node_rrq *rrq; |
| 851 | int empty; |
| 852 | |
| 853 | if (!ndlp) |
| 854 | return -EINVAL; |
| 855 | |
| 856 | if (!phba->cfg_enable_rrq) |
| 857 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 858 | |
| 859 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 860 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 861 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 862 | goto out; |
| 863 | } |
| 864 | |
| 865 | /* |
| 866 | * set the active bit even if there is no mem available. |
| 867 | */ |
| 868 | if (NLP_CHK_FREE_REQ(ndlp)) |
| 869 | goto out; |
| 870 | |
| 871 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) |
| 872 | goto out; |
| 873 | |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 874 | if (!ndlp->active_rrqs_xri_bitmap) |
| 875 | goto out; |
| 876 | |
| 877 | if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap)) |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 878 | goto out; |
| 879 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 880 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 881 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
| 882 | if (!rrq) { |
| 883 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 884 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" |
| 885 | " DID:0x%x Send:%d\n", |
| 886 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 887 | return -EINVAL; |
| 888 | } |
James Smart | e5771b4 | 2013-03-01 16:37:14 -0500 | [diff] [blame] | 889 | if (phba->cfg_enable_rrq == 1) |
| 890 | rrq->send_rrq = send_rrq; |
| 891 | else |
| 892 | rrq->send_rrq = 0; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 893 | rrq->xritag = xritag; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 894 | rrq->rrq_stop_time = jiffies + |
| 895 | msecs_to_jiffies(1000 * (phba->fc_ratov + 1)); |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 896 | rrq->ndlp = ndlp; |
| 897 | rrq->nlp_DID = ndlp->nlp_DID; |
| 898 | rrq->vport = ndlp->vport; |
| 899 | rrq->rxid = rxid; |
James Smart | b42c07c | 2012-01-18 16:25:55 -0500 | [diff] [blame] | 900 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 901 | empty = list_empty(&phba->active_rrq_list); |
| 902 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
| 903 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 904 | if (empty) |
| 905 | lpfc_worker_wake_up(phba); |
| 906 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 907 | return 0; |
| 908 | out: |
| 909 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 910 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 911 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" |
| 912 | " DID:0x%x Send:%d\n", |
| 913 | xritag, rxid, ndlp->nlp_DID, send_rrq); |
| 914 | return -EINVAL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 918 | * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 919 | * @phba: Pointer to HBA context object. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 920 | * @piocb: Pointer to the iocbq. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 921 | * |
James Smart | dafe8ce | 2014-09-03 12:56:40 -0400 | [diff] [blame] | 922 | * This function is called with the ring lock held. This function |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 923 | * gets a new driver sglq object from the sglq list. If the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 924 | * list is not empty then it is successful, it returns pointer to the newly |
| 925 | * allocated sglq object else it returns NULL. |
| 926 | **/ |
| 927 | static struct lpfc_sglq * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 928 | __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] | 929 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 930 | 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] | 931 | struct lpfc_sglq *sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 932 | struct lpfc_sglq *start_sglq = NULL; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 933 | struct lpfc_scsi_buf *lpfc_cmd; |
| 934 | struct lpfc_nodelist *ndlp; |
| 935 | int found = 0; |
| 936 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 937 | lockdep_assert_held(&phba->hbalock); |
| 938 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 939 | if (piocbq->iocb_flag & LPFC_IO_FCP) { |
| 940 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; |
| 941 | ndlp = lpfc_cmd->rdata->pnode; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 942 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 943 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 944 | ndlp = piocbq->context_un.ndlp; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 945 | } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 946 | if (piocbq->iocb_flag & LPFC_IO_LOOPBACK) |
| 947 | ndlp = NULL; |
| 948 | else |
| 949 | ndlp = piocbq->context_un.ndlp; |
| 950 | } else { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 951 | ndlp = piocbq->context1; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 952 | } |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 953 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 954 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 955 | list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 956 | start_sglq = sglq; |
| 957 | while (!found) { |
| 958 | if (!sglq) |
James Smart | d11f54b | 2017-03-04 09:30:24 -0800 | [diff] [blame] | 959 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 960 | if (ndlp && ndlp->active_rrqs_xri_bitmap && |
| 961 | test_bit(sglq->sli4_lxritag, |
| 962 | ndlp->active_rrqs_xri_bitmap)) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 963 | /* This xri has an rrq outstanding for this DID. |
| 964 | * put it back in the list and get another xri. |
| 965 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 966 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 967 | sglq = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 968 | list_remove_head(lpfc_els_sgl_list, sglq, |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 969 | struct lpfc_sglq, list); |
| 970 | if (sglq == start_sglq) { |
James Smart | 14041bd | 2017-06-01 21:07:01 -0700 | [diff] [blame] | 971 | list_add_tail(&sglq->list, lpfc_els_sgl_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 972 | sglq = NULL; |
| 973 | break; |
| 974 | } else |
| 975 | continue; |
| 976 | } |
| 977 | sglq->ndlp = ndlp; |
| 978 | found = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 979 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 980 | sglq->state = SGL_ALLOCATED; |
| 981 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 982 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 983 | return sglq; |
| 984 | } |
| 985 | |
| 986 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 987 | * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool |
| 988 | * @phba: Pointer to HBA context object. |
| 989 | * @piocb: Pointer to the iocbq. |
| 990 | * |
| 991 | * This function is called with the sgl_list lock held. This function |
| 992 | * gets a new driver sglq object from the sglq list. If the |
| 993 | * list is not empty then it is successful, it returns pointer to the newly |
| 994 | * allocated sglq object else it returns NULL. |
| 995 | **/ |
| 996 | struct lpfc_sglq * |
| 997 | __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
| 998 | { |
| 999 | struct list_head *lpfc_nvmet_sgl_list; |
| 1000 | struct lpfc_sglq *sglq = NULL; |
| 1001 | |
| 1002 | lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list; |
| 1003 | |
| 1004 | lockdep_assert_held(&phba->sli4_hba.sgl_list_lock); |
| 1005 | |
| 1006 | list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list); |
| 1007 | if (!sglq) |
| 1008 | return NULL; |
| 1009 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
| 1010 | sglq->state = SGL_ALLOCATED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1011 | return sglq; |
| 1012 | } |
| 1013 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1014 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1015 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1016 | * @phba: Pointer to HBA context object. |
| 1017 | * |
| 1018 | * This function is called with no lock held. This function |
| 1019 | * allocates a new driver iocb object from the iocb pool. If the |
| 1020 | * allocation is successful, it returns pointer to the newly |
| 1021 | * allocated iocb object else it returns NULL. |
| 1022 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1023 | struct lpfc_iocbq * |
| 1024 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1025 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1026 | struct lpfc_iocbq * iocbq = NULL; |
| 1027 | unsigned long iflags; |
| 1028 | |
| 1029 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1030 | iocbq = __lpfc_sli_get_iocbq(phba); |
| 1031 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1032 | return iocbq; |
| 1033 | } |
| 1034 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1035 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1036 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
| 1037 | * @phba: Pointer to HBA context object. |
| 1038 | * @iocbq: Pointer to driver iocb object. |
| 1039 | * |
| 1040 | * This function is called with hbalock held to release driver |
| 1041 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1042 | * does not change for each use of the iocb object. This function |
| 1043 | * clears all other fields of the iocb object when it is freed. |
| 1044 | * The sqlq structure that holds the xritag and phys and virtual |
| 1045 | * mappings for the scatter gather list is retrieved from the |
| 1046 | * active array of sglq. The get of the sglq pointer also clears |
| 1047 | * the entry in the array. If the status of the IO indiactes that |
| 1048 | * this IO was aborted then the sglq entry it put on the |
| 1049 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the |
| 1050 | * 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] | 1051 | * entry is added to the free list (lpfc_els_sgl_list). |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1052 | **/ |
| 1053 | static void |
| 1054 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1055 | { |
| 1056 | struct lpfc_sglq *sglq; |
| 1057 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1058 | unsigned long iflag = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1059 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1060 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1061 | lockdep_assert_held(&phba->hbalock); |
| 1062 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1063 | if (iocbq->sli4_xritag == NO_XRI) |
| 1064 | sglq = NULL; |
| 1065 | else |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1066 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
| 1067 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1068 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1069 | if (sglq) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1070 | if (iocbq->iocb_flag & LPFC_IO_NVMET) { |
| 1071 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1072 | iflag); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1073 | sglq->state = SGL_FREED; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1074 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1075 | list_add_tail(&sglq->list, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1076 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 1077 | spin_unlock_irqrestore( |
| 1078 | &phba->sli4_hba.sgl_list_lock, iflag); |
| 1079 | goto out; |
| 1080 | } |
| 1081 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1082 | pring = phba->sli4_hba.els_wq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1083 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
| 1084 | (sglq->state != SGL_XRI_ABORTED)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1085 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1086 | iflag); |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 1087 | list_add(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1088 | &phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1089 | spin_unlock_irqrestore( |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1090 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1091 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1092 | spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, |
| 1093 | iflag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1094 | sglq->state = SGL_FREED; |
| 1095 | sglq->ndlp = NULL; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1096 | list_add_tail(&sglq->list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1097 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1098 | spin_unlock_irqrestore( |
| 1099 | &phba->sli4_hba.sgl_list_lock, iflag); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1100 | |
| 1101 | /* Check if TXQ queue needs to be serviced */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1102 | if (!list_empty(&pring->txq)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1103 | lpfc_worker_wake_up(phba); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1104 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1105 | } |
| 1106 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1107 | out: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1108 | /* |
| 1109 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1110 | */ |
| 1111 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1112 | iocbq->sli4_lxritag = NO_XRI; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1113 | iocbq->sli4_xritag = NO_XRI; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1114 | iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | |
| 1115 | LPFC_IO_NVME_LS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1116 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1117 | } |
| 1118 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1119 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1120 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1121 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
| 1122 | * @phba: Pointer to HBA context object. |
| 1123 | * @iocbq: Pointer to driver iocb object. |
| 1124 | * |
| 1125 | * This function is called with hbalock held to release driver |
| 1126 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1127 | * does not change for each use of the iocb object. This function |
| 1128 | * clears all other fields of the iocb object when it is freed. |
| 1129 | **/ |
| 1130 | static void |
| 1131 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1132 | { |
| 1133 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
| 1134 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1135 | lockdep_assert_held(&phba->hbalock); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1136 | |
| 1137 | /* |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1138 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1139 | */ |
| 1140 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
| 1141 | iocbq->sli4_xritag = NO_XRI; |
| 1142 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
| 1143 | } |
| 1144 | |
| 1145 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1146 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1147 | * @phba: Pointer to HBA context object. |
| 1148 | * @iocbq: Pointer to driver iocb object. |
| 1149 | * |
| 1150 | * This function is called with hbalock held to release driver |
| 1151 | * iocb object to the iocb pool. The iotag in the iocb object |
| 1152 | * does not change for each use of the iocb object. This function |
| 1153 | * clears all other fields of the iocb object when it is freed. |
| 1154 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1155 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1156 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1157 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1158 | lockdep_assert_held(&phba->hbalock); |
| 1159 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1160 | phba->__lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1161 | phba->iocb_cnt--; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1162 | } |
| 1163 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1164 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1165 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1166 | * @phba: Pointer to HBA context object. |
| 1167 | * @iocbq: Pointer to driver iocb object. |
| 1168 | * |
| 1169 | * This function is called with no lock held to release the iocb to |
| 1170 | * iocb pool. |
| 1171 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1172 | void |
| 1173 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| 1174 | { |
| 1175 | unsigned long iflags; |
| 1176 | |
| 1177 | /* |
| 1178 | * Clean all volatile data fields, preserve iotag and node struct. |
| 1179 | */ |
| 1180 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 1181 | __lpfc_sli_release_iocbq(phba, iocbq); |
| 1182 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 1183 | } |
| 1184 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1185 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1186 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. |
| 1187 | * @phba: Pointer to HBA context object. |
| 1188 | * @iocblist: List of IOCBs. |
| 1189 | * @ulpstatus: ULP status in IOCB command field. |
| 1190 | * @ulpWord4: ULP word-4 in IOCB command field. |
| 1191 | * |
| 1192 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB |
| 1193 | * on the list by invoking the complete callback function associated with the |
| 1194 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond |
| 1195 | * fields. |
| 1196 | **/ |
| 1197 | void |
| 1198 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, |
| 1199 | uint32_t ulpstatus, uint32_t ulpWord4) |
| 1200 | { |
| 1201 | struct lpfc_iocbq *piocb; |
| 1202 | |
| 1203 | while (!list_empty(iocblist)) { |
| 1204 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1205 | if (!piocb->iocb_cmpl) |
| 1206 | lpfc_sli_release_iocbq(phba, piocb); |
| 1207 | else { |
| 1208 | piocb->iocb.ulpStatus = ulpstatus; |
| 1209 | piocb->iocb.un.ulpWord[4] = ulpWord4; |
| 1210 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 1211 | } |
| 1212 | } |
| 1213 | return; |
| 1214 | } |
| 1215 | |
| 1216 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1217 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
| 1218 | * @iocb_cmnd: iocb command code. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1219 | * |
| 1220 | * This function is called by ring event handler function to get the iocb type. |
| 1221 | * This function translates the iocb command to an iocb command type used to |
| 1222 | * decide the final disposition of each completed IOCB. |
| 1223 | * The function returns |
| 1224 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb |
| 1225 | * LPFC_SOL_IOCB if it is a solicited iocb completion |
| 1226 | * LPFC_ABORT_IOCB if it is an abort iocb |
| 1227 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb |
| 1228 | * |
| 1229 | * The caller is not required to hold any lock. |
| 1230 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1231 | static lpfc_iocb_type |
| 1232 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) |
| 1233 | { |
| 1234 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; |
| 1235 | |
| 1236 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) |
| 1237 | return 0; |
| 1238 | |
| 1239 | switch (iocb_cmnd) { |
| 1240 | case CMD_XMIT_SEQUENCE_CR: |
| 1241 | case CMD_XMIT_SEQUENCE_CX: |
| 1242 | case CMD_XMIT_BCAST_CN: |
| 1243 | case CMD_XMIT_BCAST_CX: |
| 1244 | case CMD_ELS_REQUEST_CR: |
| 1245 | case CMD_ELS_REQUEST_CX: |
| 1246 | case CMD_CREATE_XRI_CR: |
| 1247 | case CMD_CREATE_XRI_CX: |
| 1248 | case CMD_GET_RPI_CN: |
| 1249 | case CMD_XMIT_ELS_RSP_CX: |
| 1250 | case CMD_GET_RPI_CR: |
| 1251 | case CMD_FCP_IWRITE_CR: |
| 1252 | case CMD_FCP_IWRITE_CX: |
| 1253 | case CMD_FCP_IREAD_CR: |
| 1254 | case CMD_FCP_IREAD_CX: |
| 1255 | case CMD_FCP_ICMND_CR: |
| 1256 | case CMD_FCP_ICMND_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1257 | case CMD_FCP_TSEND_CX: |
| 1258 | case CMD_FCP_TRSP_CX: |
| 1259 | case CMD_FCP_TRECEIVE_CX: |
| 1260 | case CMD_FCP_AUTO_TRSP_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1261 | case CMD_ADAPTER_MSG: |
| 1262 | case CMD_ADAPTER_DUMP: |
| 1263 | case CMD_XMIT_SEQUENCE64_CR: |
| 1264 | case CMD_XMIT_SEQUENCE64_CX: |
| 1265 | case CMD_XMIT_BCAST64_CN: |
| 1266 | case CMD_XMIT_BCAST64_CX: |
| 1267 | case CMD_ELS_REQUEST64_CR: |
| 1268 | case CMD_ELS_REQUEST64_CX: |
| 1269 | case CMD_FCP_IWRITE64_CR: |
| 1270 | case CMD_FCP_IWRITE64_CX: |
| 1271 | case CMD_FCP_IREAD64_CR: |
| 1272 | case CMD_FCP_IREAD64_CX: |
| 1273 | case CMD_FCP_ICMND64_CR: |
| 1274 | case CMD_FCP_ICMND64_CX: |
James Smart | f560351 | 2006-12-02 13:35:43 -0500 | [diff] [blame] | 1275 | case CMD_FCP_TSEND64_CX: |
| 1276 | case CMD_FCP_TRSP64_CX: |
| 1277 | case CMD_FCP_TRECEIVE64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1278 | case CMD_GEN_REQUEST64_CR: |
| 1279 | case CMD_GEN_REQUEST64_CX: |
| 1280 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1281 | case DSSCMD_IWRITE64_CR: |
| 1282 | case DSSCMD_IWRITE64_CX: |
| 1283 | case DSSCMD_IREAD64_CR: |
| 1284 | case DSSCMD_IREAD64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1285 | type = LPFC_SOL_IOCB; |
| 1286 | break; |
| 1287 | case CMD_ABORT_XRI_CN: |
| 1288 | case CMD_ABORT_XRI_CX: |
| 1289 | case CMD_CLOSE_XRI_CN: |
| 1290 | case CMD_CLOSE_XRI_CX: |
| 1291 | case CMD_XRI_ABORTED_CX: |
| 1292 | case CMD_ABORT_MXRI64_CN: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 1293 | case CMD_XMIT_BLS_RSP64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1294 | type = LPFC_ABORT_IOCB; |
| 1295 | break; |
| 1296 | case CMD_RCV_SEQUENCE_CX: |
| 1297 | case CMD_RCV_ELS_REQ_CX: |
| 1298 | case CMD_RCV_SEQUENCE64_CX: |
| 1299 | case CMD_RCV_ELS_REQ64_CX: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1300 | case CMD_ASYNC_STATUS: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1301 | case CMD_IOCB_RCV_SEQ64_CX: |
| 1302 | case CMD_IOCB_RCV_ELS64_CX: |
| 1303 | case CMD_IOCB_RCV_CONT64_CX: |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1304 | case CMD_IOCB_RET_XRI64_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1305 | type = LPFC_UNSOL_IOCB; |
| 1306 | break; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1307 | case CMD_IOCB_XMIT_MSEQ64_CR: |
| 1308 | case CMD_IOCB_XMIT_MSEQ64_CX: |
| 1309 | case CMD_IOCB_RCV_SEQ_LIST64_CX: |
| 1310 | case CMD_IOCB_RCV_ELS_LIST64_CX: |
| 1311 | case CMD_IOCB_CLOSE_EXTENDED_CN: |
| 1312 | case CMD_IOCB_ABORT_EXTENDED_CN: |
| 1313 | case CMD_IOCB_RET_HBQE64_CN: |
| 1314 | case CMD_IOCB_FCP_IBIDIR64_CR: |
| 1315 | case CMD_IOCB_FCP_IBIDIR64_CX: |
| 1316 | case CMD_IOCB_FCP_ITASKMGT64_CX: |
| 1317 | case CMD_IOCB_LOGENTRY_CN: |
| 1318 | case CMD_IOCB_LOGENTRY_ASYNC_CN: |
| 1319 | printk("%s - Unhandled SLI-3 Command x%x\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1320 | __func__, iocb_cmnd); |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1321 | type = LPFC_UNKNOWN_IOCB; |
| 1322 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1323 | default: |
| 1324 | type = LPFC_UNKNOWN_IOCB; |
| 1325 | break; |
| 1326 | } |
| 1327 | |
| 1328 | return type; |
| 1329 | } |
| 1330 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1331 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1332 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1333 | * @phba: Pointer to HBA context object. |
| 1334 | * |
| 1335 | * This function is called from SLI initialization code |
| 1336 | * to configure every ring of the HBA's SLI interface. The |
| 1337 | * caller is not required to hold any lock. This function issues |
| 1338 | * a config_ring mailbox command for each ring. |
| 1339 | * This function returns zero if successful else returns a negative |
| 1340 | * error code. |
| 1341 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1342 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1343 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1344 | { |
| 1345 | struct lpfc_sli *psli = &phba->sli; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1346 | LPFC_MBOXQ_t *pmb; |
| 1347 | MAILBOX_t *pmbox; |
| 1348 | int i, rc, ret = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1349 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1350 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1351 | if (!pmb) |
| 1352 | return -ENOMEM; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1353 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1354 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1355 | for (i = 0; i < psli->num_rings; i++) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1356 | lpfc_config_ring(phba, i, pmb); |
| 1357 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 1358 | if (rc != MBX_SUCCESS) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1359 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1360 | "0446 Adapter failed to init (%d), " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1361 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
| 1362 | "ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1363 | rc, pmbox->mbxCommand, |
| 1364 | pmbox->mbxStatus, i); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1365 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1366 | ret = -ENXIO; |
| 1367 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1368 | } |
| 1369 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1370 | mempool_free(pmb, phba->mbox_mem_pool); |
| 1371 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1372 | } |
| 1373 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1374 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1375 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1376 | * @phba: Pointer to HBA context object. |
| 1377 | * @pring: Pointer to driver SLI ring object. |
| 1378 | * @piocb: Pointer to the driver iocb object. |
| 1379 | * |
| 1380 | * This function is called with hbalock held. The function adds the |
| 1381 | * new iocb to txcmplq of the given ring. This function always returns |
| 1382 | * 0. If this function is called for ELS ring, this function checks if |
| 1383 | * there is a vport associated with the ELS command. This function also |
| 1384 | * starts els_tmofunc timer if this is an ELS command. |
| 1385 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1386 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1387 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1388 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1389 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1390 | lockdep_assert_held(&phba->hbalock); |
| 1391 | |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1392 | BUG_ON(!piocb); |
Johannes Thumshirn | 22466da | 2016-07-29 15:30:56 +0200 | [diff] [blame] | 1393 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1394 | list_add_tail(&piocb->list, &pring->txcmplq); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 1395 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1396 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1397 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
| 1398 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
Mauricio Faria de Oliveira | 2319f84 | 2016-11-23 10:33:19 -0200 | [diff] [blame] | 1399 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 1400 | BUG_ON(!piocb->vport); |
| 1401 | if (!(piocb->vport->load_flag & FC_UNLOADING)) |
| 1402 | mod_timer(&piocb->vport->els_tmofunc, |
| 1403 | jiffies + |
| 1404 | msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); |
| 1405 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1406 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1407 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | } |
| 1409 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1410 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1411 | * lpfc_sli_ringtx_get - Get first element of the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1412 | * @phba: Pointer to HBA context object. |
| 1413 | * @pring: Pointer to driver SLI ring object. |
| 1414 | * |
| 1415 | * This function is called with hbalock held to get next |
| 1416 | * iocb in txq of the given ring. If there is any iocb in |
| 1417 | * the txq, the function returns first iocb in the list after |
| 1418 | * removing the iocb from the list, else it returns NULL. |
| 1419 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 1420 | struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1421 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1422 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1423 | struct lpfc_iocbq *cmd_iocb; |
| 1424 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1425 | lockdep_assert_held(&phba->hbalock); |
| 1426 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1427 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1428 | return cmd_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | } |
| 1430 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1431 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1432 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1433 | * @phba: Pointer to HBA context object. |
| 1434 | * @pring: Pointer to driver SLI ring object. |
| 1435 | * |
| 1436 | * This function is called with hbalock held and the caller must post the |
| 1437 | * iocb without releasing the lock. If the caller releases the lock, |
| 1438 | * iocb slot returned by the function is not guaranteed to be available. |
| 1439 | * The function returns pointer to the next available iocb slot if there |
| 1440 | * is available slot in the ring, else it returns NULL. |
| 1441 | * If the get index of the ring is ahead of the put index, the function |
| 1442 | * will post an error attention event to the worker thread to take the |
| 1443 | * HBA to offline state. |
| 1444 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1445 | static IOCB_t * |
| 1446 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 1447 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1448 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1449 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1450 | |
| 1451 | lockdep_assert_held(&phba->hbalock); |
| 1452 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1453 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && |
| 1454 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) |
| 1455 | pring->sli.sli3.next_cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1456 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1457 | if (unlikely(pring->sli.sli3.local_getidx == |
| 1458 | pring->sli.sli3.next_cmdidx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1459 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1460 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1461 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1462 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1463 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1464 | "0315 Ring %d issue: portCmdGet %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 1465 | "is bigger than cmd ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1466 | pring->ringno, |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1467 | pring->sli.sli3.local_getidx, |
| 1468 | max_cmd_idx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1469 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1470 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | /* |
| 1472 | * All error attention handlers are posted to |
| 1473 | * worker thread |
| 1474 | */ |
| 1475 | phba->work_ha |= HA_ERATT; |
| 1476 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1477 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1478 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1479 | |
| 1480 | return NULL; |
| 1481 | } |
| 1482 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1483 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1484 | return NULL; |
| 1485 | } |
| 1486 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1487 | return lpfc_cmd_iocb(phba, pring); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1488 | } |
| 1489 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1490 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1491 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1492 | * @phba: Pointer to HBA context object. |
| 1493 | * @iocbq: Pointer to driver iocb object. |
| 1494 | * |
| 1495 | * This function gets an iotag for the iocb. If there is no unused iotag and |
| 1496 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup |
| 1497 | * array and assigns a new iotag. |
| 1498 | * The function returns the allocated iotag if successful, else returns zero. |
| 1499 | * Zero is not a valid iotag. |
| 1500 | * The caller is not required to hold any lock. |
| 1501 | **/ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1502 | uint16_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1503 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1504 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1505 | struct lpfc_iocbq **new_arr; |
| 1506 | struct lpfc_iocbq **old_arr; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1507 | size_t new_len; |
| 1508 | struct lpfc_sli *psli = &phba->sli; |
| 1509 | uint16_t iotag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1510 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1511 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1512 | iotag = psli->last_iotag; |
| 1513 | if(++iotag < psli->iocbq_lookup_len) { |
| 1514 | psli->last_iotag = iotag; |
| 1515 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1516 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1517 | iocbq->iotag = iotag; |
| 1518 | return iotag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1519 | } else if (psli->iocbq_lookup_len < (0xffff |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1520 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
| 1521 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1522 | spin_unlock_irq(&phba->hbalock); |
| 1523 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1524 | GFP_KERNEL); |
| 1525 | if (new_arr) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1526 | spin_lock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1527 | old_arr = psli->iocbq_lookup; |
| 1528 | if (new_len <= psli->iocbq_lookup_len) { |
| 1529 | /* highly unprobable case */ |
| 1530 | kfree(new_arr); |
| 1531 | iotag = psli->last_iotag; |
| 1532 | if(++iotag < psli->iocbq_lookup_len) { |
| 1533 | psli->last_iotag = iotag; |
| 1534 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1535 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1536 | iocbq->iotag = iotag; |
| 1537 | return iotag; |
| 1538 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1539 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1540 | return 0; |
| 1541 | } |
| 1542 | if (psli->iocbq_lookup) |
| 1543 | memcpy(new_arr, old_arr, |
| 1544 | ((psli->last_iotag + 1) * |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1545 | sizeof (struct lpfc_iocbq *))); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1546 | psli->iocbq_lookup = new_arr; |
| 1547 | psli->iocbq_lookup_len = new_len; |
| 1548 | psli->last_iotag = iotag; |
| 1549 | psli->iocbq_lookup[iotag] = iocbq; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1550 | spin_unlock_irq(&phba->hbalock); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1551 | iocbq->iotag = iotag; |
| 1552 | kfree(old_arr); |
| 1553 | return iotag; |
| 1554 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1555 | } else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1556 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1557 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1558 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1559 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
| 1560 | psli->last_iotag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1561 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1562 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1563 | } |
| 1564 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1565 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1566 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1567 | * @phba: Pointer to HBA context object. |
| 1568 | * @pring: Pointer to driver SLI ring object. |
| 1569 | * @iocb: Pointer to iocb slot in the ring. |
| 1570 | * @nextiocb: Pointer to driver iocb object which need to be |
| 1571 | * posted to firmware. |
| 1572 | * |
| 1573 | * This function is called with hbalock held to post a new iocb to |
| 1574 | * the firmware. This function copies the new iocb to ring iocb slot and |
| 1575 | * updates the ring pointers. It adds the new iocb to txcmplq if there is |
| 1576 | * a completion call back for this iocb else the function will free the |
| 1577 | * iocb object. |
| 1578 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1579 | static void |
| 1580 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 1581 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) |
| 1582 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1583 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1584 | /* |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1585 | * Set up an iotag |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1586 | */ |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1587 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1588 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1589 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1590 | if (pring->ringno == LPFC_ELS_RING) { |
| 1591 | lpfc_debugfs_slow_ring_trc(phba, |
| 1592 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 1593 | *(((uint32_t *) &nextiocb->iocb) + 4), |
| 1594 | *(((uint32_t *) &nextiocb->iocb) + 6), |
| 1595 | *(((uint32_t *) &nextiocb->iocb) + 7)); |
| 1596 | } |
| 1597 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1598 | /* |
| 1599 | * Issue iocb command to adapter |
| 1600 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1601 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1602 | wmb(); |
| 1603 | pring->stats.iocb_cmd++; |
| 1604 | |
| 1605 | /* |
| 1606 | * If there is no completion routine to call, we can release the |
| 1607 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, |
| 1608 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. |
| 1609 | */ |
| 1610 | if (nextiocb->iocb_cmpl) |
| 1611 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1612 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1613 | __lpfc_sli_release_iocbq(phba, nextiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1614 | |
| 1615 | /* |
| 1616 | * Let the HBA know what IOCB slot will be the next one the |
| 1617 | * driver will put a command into. |
| 1618 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1619 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
| 1620 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1621 | } |
| 1622 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1623 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1624 | * lpfc_sli_update_full_ring - Update the chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1625 | * @phba: Pointer to HBA context object. |
| 1626 | * @pring: Pointer to driver SLI ring object. |
| 1627 | * |
| 1628 | * The caller is not required to hold any lock for calling this function. |
| 1629 | * This function updates the chip attention bits for the ring to inform firmware |
| 1630 | * that there are pending work to be done for this ring and requests an |
| 1631 | * interrupt when there is space available in the ring. This function is |
| 1632 | * called when the driver is unable to post more iocbs to the ring due |
| 1633 | * to unavailability of space in the ring. |
| 1634 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1635 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1636 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1637 | { |
| 1638 | int ringno = pring->ringno; |
| 1639 | |
| 1640 | pring->flag |= LPFC_CALL_RING_AVAILABLE; |
| 1641 | |
| 1642 | wmb(); |
| 1643 | |
| 1644 | /* |
| 1645 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. |
| 1646 | * The HBA will tell us when an IOCB entry is available. |
| 1647 | */ |
| 1648 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); |
| 1649 | readl(phba->CAregaddr); /* flush */ |
| 1650 | |
| 1651 | pring->stats.iocb_cmd_full++; |
| 1652 | } |
| 1653 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1654 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1655 | * lpfc_sli_update_ring - Update chip attention register |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1656 | * @phba: Pointer to HBA context object. |
| 1657 | * @pring: Pointer to driver SLI ring object. |
| 1658 | * |
| 1659 | * This function updates the chip attention register bit for the |
| 1660 | * given ring to inform HBA that there is more work to be done |
| 1661 | * in this ring. The caller is not required to hold any lock. |
| 1662 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1663 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1664 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1665 | { |
| 1666 | int ringno = pring->ringno; |
| 1667 | |
| 1668 | /* |
| 1669 | * Tell the HBA that there is work to do in this ring. |
| 1670 | */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1671 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
| 1672 | wmb(); |
| 1673 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); |
| 1674 | readl(phba->CAregaddr); /* flush */ |
| 1675 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1676 | } |
| 1677 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1678 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1679 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1680 | * @phba: Pointer to HBA context object. |
| 1681 | * @pring: Pointer to driver SLI ring object. |
| 1682 | * |
| 1683 | * This function is called with hbalock held to post pending iocbs |
| 1684 | * in the txq to the firmware. This function is called when driver |
| 1685 | * detects space available in the ring. |
| 1686 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1688 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1689 | { |
| 1690 | IOCB_t *iocb; |
| 1691 | struct lpfc_iocbq *nextiocb; |
| 1692 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1693 | lockdep_assert_held(&phba->hbalock); |
| 1694 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1695 | /* |
| 1696 | * Check to see if: |
| 1697 | * (a) there is anything on the txq to send |
| 1698 | * (b) link is up |
| 1699 | * (c) link attention events can be processed (fcp ring only) |
| 1700 | * (d) IOCB processing is not blocked by the outstanding mbox command. |
| 1701 | */ |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1702 | |
| 1703 | if (lpfc_is_link_up(phba) && |
| 1704 | (!list_empty(&pring->txq)) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1705 | (pring->ringno != LPFC_FCP_RING || |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1706 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1707 | |
| 1708 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 1709 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) |
| 1710 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 1711 | |
| 1712 | if (iocb) |
| 1713 | lpfc_sli_update_ring(phba, pring); |
| 1714 | else |
| 1715 | lpfc_sli_update_full_ring(phba, pring); |
| 1716 | } |
| 1717 | |
| 1718 | return; |
| 1719 | } |
| 1720 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1721 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1722 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1723 | * @phba: Pointer to HBA context object. |
| 1724 | * @hbqno: HBQ number. |
| 1725 | * |
| 1726 | * This function is called with hbalock held to get the next |
| 1727 | * available slot for the given HBQ. If there is free slot |
| 1728 | * available for the HBQ it will return pointer to the next available |
| 1729 | * HBQ entry else it will return NULL. |
| 1730 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1731 | static struct lpfc_hbq_entry * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1732 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
| 1733 | { |
| 1734 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1735 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1736 | lockdep_assert_held(&phba->hbalock); |
| 1737 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1738 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && |
| 1739 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) |
| 1740 | hbqp->next_hbqPutIdx = 0; |
| 1741 | |
| 1742 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1743 | uint32_t raw_index = phba->hbq_get[hbqno]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1744 | uint32_t getidx = le32_to_cpu(raw_index); |
| 1745 | |
| 1746 | hbqp->local_hbqGetIdx = getidx; |
| 1747 | |
| 1748 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { |
| 1749 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1750 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1751 | "1802 HBQ %d: local_hbqGetIdx " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1752 | "%u is > than hbqp->entry_count %u\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1753 | hbqno, hbqp->local_hbqGetIdx, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1754 | hbqp->entry_count); |
| 1755 | |
| 1756 | phba->link_state = LPFC_HBA_ERROR; |
| 1757 | return NULL; |
| 1758 | } |
| 1759 | |
| 1760 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) |
| 1761 | return NULL; |
| 1762 | } |
| 1763 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1764 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
| 1765 | hbqp->hbqPutIdx; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1766 | } |
| 1767 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1768 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1769 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1770 | * @phba: Pointer to HBA context object. |
| 1771 | * |
| 1772 | * This function is called with no lock held to free all the |
| 1773 | * hbq buffers while uninitializing the SLI interface. It also |
| 1774 | * frees the HBQ buffers returned by the firmware but not yet |
| 1775 | * processed by the upper layers. |
| 1776 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1777 | void |
| 1778 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) |
| 1779 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1780 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 1781 | struct hbq_dmabuf *hbq_buf; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1782 | unsigned long flags; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1783 | int i, hbq_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1784 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1785 | hbq_count = lpfc_sli_hbq_count(); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1786 | /* Return all memory used by all HBQs */ |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1787 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1788 | for (i = 0; i < hbq_count; ++i) { |
| 1789 | list_for_each_entry_safe(dmabuf, next_dmabuf, |
| 1790 | &phba->hbqs[i].hbq_buffer_list, list) { |
| 1791 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
| 1792 | list_del(&hbq_buf->dbuf.list); |
| 1793 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); |
| 1794 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1795 | phba->hbqs[i].buffer_count = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1796 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1797 | |
| 1798 | /* Mark the HBQs not in use */ |
| 1799 | phba->hbq_in_use = 0; |
| 1800 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1801 | } |
| 1802 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1803 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1804 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1805 | * @phba: Pointer to HBA context object. |
| 1806 | * @hbqno: HBQ number. |
| 1807 | * @hbq_buf: Pointer to HBQ buffer. |
| 1808 | * |
| 1809 | * This function is called with the hbalock held to post a |
| 1810 | * hbq buffer to the firmware. If the function finds an empty |
| 1811 | * slot in the HBQ, it will post the buffer. The function will return |
| 1812 | * pointer to the hbq entry if it successfully post the buffer |
| 1813 | * else it will return NULL. |
| 1814 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1815 | static int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1816 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1817 | struct hbq_dmabuf *hbq_buf) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1818 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1819 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1820 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); |
| 1821 | } |
| 1822 | |
| 1823 | /** |
| 1824 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware |
| 1825 | * @phba: Pointer to HBA context object. |
| 1826 | * @hbqno: HBQ number. |
| 1827 | * @hbq_buf: Pointer to HBQ buffer. |
| 1828 | * |
| 1829 | * This function is called with the hbalock held to post a hbq buffer to the |
| 1830 | * firmware. If the function finds an empty slot in the HBQ, it will post the |
| 1831 | * buffer and place it on the hbq_buffer_list. The function will return zero if |
| 1832 | * it successfully post the buffer else it will return an error. |
| 1833 | **/ |
| 1834 | static int |
| 1835 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, |
| 1836 | struct hbq_dmabuf *hbq_buf) |
| 1837 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1838 | struct lpfc_hbq_entry *hbqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1839 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1840 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1841 | lockdep_assert_held(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1842 | /* Get next HBQ entry slot to use */ |
| 1843 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); |
| 1844 | if (hbqe) { |
| 1845 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; |
| 1846 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1847 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
| 1848 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1849 | hbqe->bde.tus.f.bdeSize = hbq_buf->total_size; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1850 | hbqe->bde.tus.f.bdeFlags = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1851 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
| 1852 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); |
| 1853 | /* Sync SLIM */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1854 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
| 1855 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1856 | /* flush */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1857 | readl(phba->hbq_put + hbqno); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1858 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1859 | return 0; |
| 1860 | } else |
| 1861 | return -ENOMEM; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1862 | } |
| 1863 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1864 | /** |
| 1865 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware |
| 1866 | * @phba: Pointer to HBA context object. |
| 1867 | * @hbqno: HBQ number. |
| 1868 | * @hbq_buf: Pointer to HBQ buffer. |
| 1869 | * |
| 1870 | * This function is called with the hbalock held to post an RQE to the SLI4 |
| 1871 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to |
| 1872 | * the hbq_buffer_list and return zero, otherwise it will return an error. |
| 1873 | **/ |
| 1874 | static int |
| 1875 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, |
| 1876 | struct hbq_dmabuf *hbq_buf) |
| 1877 | { |
| 1878 | int rc; |
| 1879 | struct lpfc_rqe hrqe; |
| 1880 | struct lpfc_rqe drqe; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1881 | struct lpfc_queue *hrq; |
| 1882 | struct lpfc_queue *drq; |
| 1883 | |
| 1884 | if (hbqno != LPFC_ELS_HBQ) |
| 1885 | return 1; |
| 1886 | hrq = phba->sli4_hba.hdr_rq; |
| 1887 | drq = phba->sli4_hba.dat_rq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1888 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 1889 | lockdep_assert_held(&phba->hbalock); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1890 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); |
| 1891 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); |
| 1892 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); |
| 1893 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1894 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1895 | if (rc < 0) |
| 1896 | return rc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1897 | hbq_buf->tag = (rc | (hbqno << 16)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 1898 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); |
| 1899 | return 0; |
| 1900 | } |
| 1901 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1902 | /* HBQ for ELS and CT traffic. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1903 | static struct lpfc_hbq_init lpfc_els_hbq = { |
| 1904 | .rn = 1, |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1905 | .entry_count = 256, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1906 | .mask_count = 0, |
| 1907 | .profile = 0, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1908 | .ring_mask = (1 << LPFC_ELS_RING), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1909 | .buffer_count = 0, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1910 | .init_count = 40, |
| 1911 | .add_count = 40, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1912 | }; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1913 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1914 | /* Array of HBQs */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1915 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1916 | &lpfc_els_hbq, |
| 1917 | }; |
| 1918 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1919 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1920 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1921 | * @phba: Pointer to HBA context object. |
| 1922 | * @hbqno: HBQ number. |
| 1923 | * @count: Number of HBQ buffers to be posted. |
| 1924 | * |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1925 | * This function is called with no lock held to post more hbq buffers to the |
| 1926 | * given HBQ. The function returns the number of HBQ buffers successfully |
| 1927 | * posted. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1928 | **/ |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 1929 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1930 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
| 1931 | { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1932 | uint32_t i, posted = 0; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1933 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1934 | struct hbq_dmabuf *hbq_buffer; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1935 | LIST_HEAD(hbq_buf_list); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1936 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1937 | return 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1938 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1939 | if ((phba->hbqs[hbqno].buffer_count + count) > |
| 1940 | lpfc_hbq_defs[hbqno]->entry_count) |
| 1941 | count = lpfc_hbq_defs[hbqno]->entry_count - |
| 1942 | phba->hbqs[hbqno].buffer_count; |
| 1943 | if (!count) |
| 1944 | return 0; |
| 1945 | /* Allocate HBQ entries */ |
| 1946 | for (i = 0; i < count; i++) { |
| 1947 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); |
| 1948 | if (!hbq_buffer) |
| 1949 | break; |
| 1950 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); |
| 1951 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1952 | /* Check whether HBQ is still in use */ |
| 1953 | spin_lock_irqsave(&phba->hbalock, flags); |
Matthew Wilcox | eafe1df | 2008-02-21 05:44:33 -0700 | [diff] [blame] | 1954 | if (!phba->hbq_in_use) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1955 | goto err; |
| 1956 | while (!list_empty(&hbq_buf_list)) { |
| 1957 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1958 | dbuf.list); |
| 1959 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
| 1960 | (hbqno << 16)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1961 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1962 | phba->hbqs[hbqno].buffer_count++; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1963 | posted++; |
| 1964 | } else |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1965 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1966 | } |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 1967 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1968 | return posted; |
| 1969 | err: |
| 1970 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1971 | while (!list_empty(&hbq_buf_list)) { |
| 1972 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, |
| 1973 | dbuf.list); |
| 1974 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
| 1975 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1976 | return 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1977 | } |
| 1978 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1979 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1980 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1981 | * @phba: Pointer to HBA context object. |
| 1982 | * @qno: HBQ number. |
| 1983 | * |
| 1984 | * This function posts more buffers to the HBQ. This function |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1985 | * is called with no lock held. The function returns the number of HBQ entries |
| 1986 | * successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1987 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1988 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1989 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1990 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 1991 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1992 | return 0; |
| 1993 | else |
| 1994 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 1995 | lpfc_hbq_defs[qno]->add_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1996 | } |
| 1997 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1998 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1999 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2000 | * @phba: Pointer to HBA context object. |
| 2001 | * @qno: HBQ queue number. |
| 2002 | * |
| 2003 | * This function is called from SLI initialization code path with |
| 2004 | * no lock held to post initial HBQ buffers to firmware. The |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2005 | * function returns the number of HBQ entries successfully allocated. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2006 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2007 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2008 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2009 | { |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2010 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2011 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2012 | lpfc_hbq_defs[qno]->entry_count); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 2013 | else |
| 2014 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, |
| 2015 | lpfc_hbq_defs[qno]->init_count); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2016 | } |
| 2017 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2018 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2019 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list |
| 2020 | * @phba: Pointer to HBA context object. |
| 2021 | * @hbqno: HBQ number. |
| 2022 | * |
| 2023 | * This function removes the first hbq buffer on an hbq list and returns a |
| 2024 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2025 | **/ |
| 2026 | static struct hbq_dmabuf * |
| 2027 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) |
| 2028 | { |
| 2029 | struct lpfc_dmabuf *d_buf; |
| 2030 | |
| 2031 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); |
| 2032 | if (!d_buf) |
| 2033 | return NULL; |
| 2034 | return container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 2035 | } |
| 2036 | |
| 2037 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2038 | * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list |
| 2039 | * @phba: Pointer to HBA context object. |
| 2040 | * @hbqno: HBQ number. |
| 2041 | * |
| 2042 | * This function removes the first RQ buffer on an RQ buffer list and returns a |
| 2043 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. |
| 2044 | **/ |
| 2045 | static struct rqb_dmabuf * |
| 2046 | lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq) |
| 2047 | { |
| 2048 | struct lpfc_dmabuf *h_buf; |
| 2049 | struct lpfc_rqb *rqbp; |
| 2050 | |
| 2051 | rqbp = hrq->rqbp; |
| 2052 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 2053 | struct lpfc_dmabuf, list); |
| 2054 | if (!h_buf) |
| 2055 | return NULL; |
| 2056 | rqbp->buffer_count--; |
| 2057 | return container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 2058 | } |
| 2059 | |
| 2060 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2061 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2062 | * @phba: Pointer to HBA context object. |
| 2063 | * @tag: Tag of the hbq buffer. |
| 2064 | * |
Sebastian Herbszt | 7189241 | 2016-04-17 13:27:27 +0200 | [diff] [blame] | 2065 | * This function searches for the hbq buffer associated with the given tag in |
| 2066 | * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer |
| 2067 | * otherwise it returns NULL. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2068 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2069 | static struct hbq_dmabuf * |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2070 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
| 2071 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2072 | struct lpfc_dmabuf *d_buf; |
| 2073 | struct hbq_dmabuf *hbq_buf; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2074 | uint32_t hbqno; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2075 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2076 | hbqno = tag >> 16; |
Jesper Juhl | a0a74e45 | 2007-08-09 20:47:15 +0200 | [diff] [blame] | 2077 | if (hbqno >= LPFC_MAX_HBQS) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2078 | return NULL; |
| 2079 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2080 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2081 | 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] | 2082 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2083 | if (hbq_buf->tag == tag) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2084 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2085 | return hbq_buf; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2086 | } |
| 2087 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2088 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2089 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2090 | "1803 Bad hbq tag. Data: x%x x%x\n", |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2091 | tag, phba->hbqs[tag >> 16].buffer_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2092 | return NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2093 | } |
| 2094 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2095 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2096 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2097 | * @phba: Pointer to HBA context object. |
| 2098 | * @hbq_buffer: Pointer to HBQ buffer. |
| 2099 | * |
| 2100 | * This function is called with hbalock. This function gives back |
| 2101 | * the hbq buffer to firmware. If the HBQ does not have space to |
| 2102 | * post the buffer, it will free the buffer. |
| 2103 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2104 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2105 | 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] | 2106 | { |
| 2107 | uint32_t hbqno; |
| 2108 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2109 | if (hbq_buffer) { |
| 2110 | hbqno = hbq_buffer->tag >> 16; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2111 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2112 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2113 | } |
| 2114 | } |
| 2115 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2116 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2117 | * 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] | 2118 | * @mbxCommand: mailbox command code. |
| 2119 | * |
| 2120 | * This function is called by the mailbox event handler function to verify |
| 2121 | * that the completed mailbox command is a legitimate mailbox command. If the |
| 2122 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN |
| 2123 | * and the mailbox event handler will take the HBA offline. |
| 2124 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | static int |
| 2126 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) |
| 2127 | { |
| 2128 | uint8_t ret; |
| 2129 | |
| 2130 | switch (mbxCommand) { |
| 2131 | case MBX_LOAD_SM: |
| 2132 | case MBX_READ_NV: |
| 2133 | case MBX_WRITE_NV: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2134 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | case MBX_RUN_BIU_DIAG: |
| 2136 | case MBX_INIT_LINK: |
| 2137 | case MBX_DOWN_LINK: |
| 2138 | case MBX_CONFIG_LINK: |
| 2139 | case MBX_CONFIG_RING: |
| 2140 | case MBX_RESET_RING: |
| 2141 | case MBX_READ_CONFIG: |
| 2142 | case MBX_READ_RCONFIG: |
| 2143 | case MBX_READ_SPARM: |
| 2144 | case MBX_READ_STATUS: |
| 2145 | case MBX_READ_RPI: |
| 2146 | case MBX_READ_XRI: |
| 2147 | case MBX_READ_REV: |
| 2148 | case MBX_READ_LNK_STAT: |
| 2149 | case MBX_REG_LOGIN: |
| 2150 | case MBX_UNREG_LOGIN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | case MBX_CLEAR_LA: |
| 2152 | case MBX_DUMP_MEMORY: |
| 2153 | case MBX_DUMP_CONTEXT: |
| 2154 | case MBX_RUN_DIAGS: |
| 2155 | case MBX_RESTART: |
| 2156 | case MBX_UPDATE_CFG: |
| 2157 | case MBX_DOWN_LOAD: |
| 2158 | case MBX_DEL_LD_ENTRY: |
| 2159 | case MBX_RUN_PROGRAM: |
| 2160 | case MBX_SET_MASK: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2161 | case MBX_SET_VARIABLE: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | case MBX_UNREG_D_ID: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2163 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2164 | case MBX_CONFIG_FARP: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 2165 | case MBX_BEACON: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | case MBX_LOAD_AREA: |
| 2167 | case MBX_RUN_BIU_DIAG64: |
| 2168 | case MBX_CONFIG_PORT: |
| 2169 | case MBX_READ_SPARM64: |
| 2170 | case MBX_READ_RPI64: |
| 2171 | case MBX_REG_LOGIN64: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2172 | case MBX_READ_TOPOLOGY: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2173 | case MBX_WRITE_WWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2174 | case MBX_SET_DEBUG: |
| 2175 | case MBX_LOAD_EXP_ROM: |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2176 | case MBX_ASYNCEVT_ENABLE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2177 | case MBX_REG_VPI: |
| 2178 | case MBX_UNREG_VPI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2179 | case MBX_HEARTBEAT: |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2180 | case MBX_PORT_CAPABILITIES: |
| 2181 | case MBX_PORT_IOV_CONTROL: |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2182 | case MBX_SLI4_CONFIG: |
| 2183 | case MBX_SLI4_REQ_FTRS: |
| 2184 | case MBX_REG_FCFI: |
| 2185 | case MBX_UNREG_FCFI: |
| 2186 | case MBX_REG_VFI: |
| 2187 | case MBX_UNREG_VFI: |
| 2188 | case MBX_INIT_VPI: |
| 2189 | case MBX_INIT_VFI: |
| 2190 | case MBX_RESUME_RPI: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2191 | case MBX_READ_EVENT_LOG_STATUS: |
| 2192 | case MBX_READ_EVENT_LOG: |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2193 | case MBX_SECURITY_MGMT: |
| 2194 | case MBX_AUTH_PORT: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 2195 | case MBX_ACCESS_VDATA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | ret = mbxCommand; |
| 2197 | break; |
| 2198 | default: |
| 2199 | ret = MBX_SHUTDOWN; |
| 2200 | break; |
| 2201 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2202 | return ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2203 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2204 | |
| 2205 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2206 | * 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] | 2207 | * @phba: Pointer to HBA context object. |
| 2208 | * @pmboxq: Pointer to mailbox command. |
| 2209 | * |
| 2210 | * This is completion handler function for mailbox commands issued from |
| 2211 | * lpfc_sli_issue_mbox_wait function. This function is called by the |
| 2212 | * mailbox event handler function with no lock held. This function |
| 2213 | * will wake up thread waiting on the wait queue pointed by context1 |
| 2214 | * of the mailbox. |
| 2215 | **/ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2216 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2217 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2218 | { |
| 2219 | wait_queue_head_t *pdone_q; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2220 | unsigned long drvr_flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2221 | |
| 2222 | /* |
| 2223 | * If pdone_q is empty, the driver thread gave up waiting and |
| 2224 | * continued running. |
| 2225 | */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2226 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2227 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
| 2229 | if (pdone_q) |
| 2230 | wake_up_interruptible(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2231 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2232 | return; |
| 2233 | } |
| 2234 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2235 | |
| 2236 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2237 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2238 | * @phba: Pointer to HBA context object. |
| 2239 | * @pmb: Pointer to mailbox object. |
| 2240 | * |
| 2241 | * This function is the default mailbox completion handler. It |
| 2242 | * frees the memory resources associated with the completed mailbox |
| 2243 | * command. If the completed command is a REG_LOGIN mailbox command, |
| 2244 | * this function will issue a UREG_LOGIN to re-claim the RPI. |
| 2245 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2246 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2247 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2248 | { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2249 | struct lpfc_vport *vport = pmb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2250 | struct lpfc_dmabuf *mp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2251 | struct lpfc_nodelist *ndlp; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2252 | struct Scsi_Host *shost; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2253 | uint16_t rpi, vpi; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2254 | int rc; |
| 2255 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2256 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2257 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | if (mp) { |
| 2259 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2260 | kfree(mp); |
| 2261 | } |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2262 | |
| 2263 | /* |
| 2264 | * If a REG_LOGIN succeeded after node is destroyed or node |
| 2265 | * is in re-discovery driver need to cleanup the RPI. |
| 2266 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2267 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2268 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
| 2269 | !pmb->u.mb.mbxStatus) { |
| 2270 | rpi = pmb->u.mb.un.varWords[0]; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2271 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2272 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
James Smart | de96e9c | 2016-03-31 14:12:27 -0700 | [diff] [blame] | 2273 | pmb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2274 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2275 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 2276 | if (rc != MBX_NOT_FINISHED) |
| 2277 | return; |
| 2278 | } |
| 2279 | |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2280 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
| 2281 | !(phba->pport->load_flag & FC_UNLOADING) && |
| 2282 | !pmb->u.mb.mbxStatus) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 2283 | shost = lpfc_shost_from_vport(vport); |
| 2284 | spin_lock_irq(shost->host_lock); |
| 2285 | vport->vpi_state |= LPFC_VPI_REGISTERED; |
| 2286 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 2287 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 2288 | } |
| 2289 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2290 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 2291 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 2292 | lpfc_nlp_put(ndlp); |
| 2293 | pmb->context2 = NULL; |
| 2294 | } |
| 2295 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 2296 | /* Check security permission status on INIT_LINK mailbox command */ |
| 2297 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && |
| 2298 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) |
| 2299 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 2300 | "2860 SLI authentication is required " |
| 2301 | "for INIT_LINK but has not done yet\n"); |
| 2302 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2303 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
| 2304 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
| 2305 | else |
| 2306 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2307 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2308 | /** |
| 2309 | * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler |
| 2310 | * @phba: Pointer to HBA context object. |
| 2311 | * @pmb: Pointer to mailbox object. |
| 2312 | * |
| 2313 | * This function is the unreg rpi mailbox completion handler. It |
| 2314 | * frees the memory resources associated with the completed mailbox |
| 2315 | * command. An additional refrenece is put on the ndlp to prevent |
| 2316 | * lpfc_nlp_release from freeing the rpi bit in the bitmask before |
| 2317 | * the unreg mailbox command completes, this routine puts the |
| 2318 | * reference back. |
| 2319 | * |
| 2320 | **/ |
| 2321 | void |
| 2322 | lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2323 | { |
| 2324 | struct lpfc_vport *vport = pmb->vport; |
| 2325 | struct lpfc_nodelist *ndlp; |
| 2326 | |
| 2327 | ndlp = pmb->context1; |
| 2328 | if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) { |
| 2329 | if (phba->sli_rev == LPFC_SLI_REV4 && |
| 2330 | (bf_get(lpfc_sli_intf_if_type, |
| 2331 | &phba->sli4_hba.sli_intf) == |
| 2332 | LPFC_SLI_INTF_IF_TYPE_2)) { |
| 2333 | if (ndlp) { |
| 2334 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 2335 | "0010 UNREG_LOGIN vpi:%x " |
| 2336 | "rpi:%x DID:%x map:%x %p\n", |
| 2337 | vport->vpi, ndlp->nlp_rpi, |
| 2338 | ndlp->nlp_DID, |
| 2339 | ndlp->nlp_usg_map, ndlp); |
James Smart | 7c5e518 | 2015-05-22 10:42:43 -0400 | [diff] [blame] | 2340 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 2341 | lpfc_nlp_put(ndlp); |
| 2342 | } |
| 2343 | } |
| 2344 | } |
| 2345 | |
| 2346 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2347 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2349 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2350 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2351 | * @phba: Pointer to HBA context object. |
| 2352 | * |
| 2353 | * This function is called with no lock held. This function processes all |
| 2354 | * the completed mailbox commands and gives it to upper layers. The interrupt |
| 2355 | * service routine processes mailbox completion interrupt and adds completed |
| 2356 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. |
| 2357 | * Worker thread call lpfc_sli_handle_mb_event, which will return the |
| 2358 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This |
| 2359 | * function returns the mailbox commands to the upper layer by calling the |
| 2360 | * completion handler function of each mailbox. |
| 2361 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2362 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2363 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2364 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2365 | MAILBOX_t *pmbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2366 | LPFC_MBOXQ_t *pmb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2367 | int rc; |
| 2368 | LIST_HEAD(cmplq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | |
| 2370 | phba->sli.slistat.mbox_event++; |
| 2371 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2372 | /* Get all completed mailboxe buffers into the cmplq */ |
| 2373 | spin_lock_irq(&phba->hbalock); |
| 2374 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); |
| 2375 | spin_unlock_irq(&phba->hbalock); |
| 2376 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2377 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2378 | do { |
| 2379 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); |
| 2380 | if (pmb == NULL) |
| 2381 | break; |
| 2382 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2383 | pmbox = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2384 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2385 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
| 2386 | if (pmb->vport) { |
| 2387 | lpfc_debugfs_disc_trc(pmb->vport, |
| 2388 | LPFC_DISC_TRC_MBOX_VPORT, |
| 2389 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", |
| 2390 | (uint32_t)pmbox->mbxCommand, |
| 2391 | pmbox->un.varWords[0], |
| 2392 | pmbox->un.varWords[1]); |
| 2393 | } |
| 2394 | else { |
| 2395 | lpfc_debugfs_disc_trc(phba->pport, |
| 2396 | LPFC_DISC_TRC_MBOX, |
| 2397 | "MBOX cmpl: cmd:x%x mb:x%x x%x", |
| 2398 | (uint32_t)pmbox->mbxCommand, |
| 2399 | pmbox->un.varWords[0], |
| 2400 | pmbox->un.varWords[1]); |
| 2401 | } |
| 2402 | } |
| 2403 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | /* |
| 2405 | * It is a fatal error if unknown mbox command completion. |
| 2406 | */ |
| 2407 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == |
| 2408 | MBX_SHUTDOWN) { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2409 | /* Unknown mailbox command compl */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2410 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2411 | "(%d):0323 Unknown Mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2412 | "x%x (x%x/x%x) Cmpl\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2413 | pmb->vport ? pmb->vport->vpi : 0, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2414 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2415 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2416 | pmb), |
| 2417 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2418 | pmb)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2419 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2420 | phba->work_hs = HS_FFER3; |
| 2421 | lpfc_handle_eratt(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2422 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2423 | } |
| 2424 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | if (pmbox->mbxStatus) { |
| 2426 | phba->sli.slistat.mbox_stat_err++; |
| 2427 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { |
| 2428 | /* Mbox cmd cmpl error - RETRYing */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2429 | lpfc_printf_log(phba, KERN_INFO, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2430 | LOG_MBOX | LOG_SLI, |
| 2431 | "(%d):0305 Mbox cmd cmpl " |
| 2432 | "error - RETRYing Data: x%x " |
| 2433 | "(x%x/x%x) x%x x%x x%x\n", |
| 2434 | pmb->vport ? pmb->vport->vpi : 0, |
| 2435 | pmbox->mbxCommand, |
| 2436 | lpfc_sli_config_mbox_subsys_get(phba, |
| 2437 | pmb), |
| 2438 | lpfc_sli_config_mbox_opcode_get(phba, |
| 2439 | pmb), |
| 2440 | pmbox->mbxStatus, |
| 2441 | pmbox->un.varWords[0], |
| 2442 | pmb->vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2443 | pmbox->mbxStatus = 0; |
| 2444 | pmbox->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2445 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2446 | if (rc != MBX_NOT_FINISHED) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2447 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2452 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2453 | "(%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] | 2454 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 2455 | "x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2456 | pmb->vport ? pmb->vport->vpi : 0, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2457 | pmbox->mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2458 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
| 2459 | lpfc_sli_config_mbox_opcode_get(phba, pmb), |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2460 | pmb->mbox_cmpl, |
| 2461 | *((uint32_t *) pmbox), |
| 2462 | pmbox->un.varWords[0], |
| 2463 | pmbox->un.varWords[1], |
| 2464 | pmbox->un.varWords[2], |
| 2465 | pmbox->un.varWords[3], |
| 2466 | pmbox->un.varWords[4], |
| 2467 | pmbox->un.varWords[5], |
| 2468 | pmbox->un.varWords[6], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2469 | pmbox->un.varWords[7], |
| 2470 | pmbox->un.varWords[8], |
| 2471 | pmbox->un.varWords[9], |
| 2472 | pmbox->un.varWords[10]); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2473 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2474 | if (pmb->mbox_cmpl) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2475 | pmb->mbox_cmpl(phba,pmb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2476 | } while (1); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2477 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2478 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2479 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2480 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2481 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2482 | * @phba: Pointer to HBA context object. |
| 2483 | * @pring: Pointer to driver SLI ring object. |
| 2484 | * @tag: buffer tag. |
| 2485 | * |
| 2486 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit |
| 2487 | * is set in the tag the buffer is posted for a particular exchange, |
| 2488 | * the function will return the buffer without replacing the buffer. |
| 2489 | * If the buffer is for unsolicited ELS or CT traffic, this function |
| 2490 | * returns the buffer and also posts another buffer to the firmware. |
| 2491 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2492 | static struct lpfc_dmabuf * |
| 2493 | lpfc_sli_get_buff(struct lpfc_hba *phba, |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2494 | struct lpfc_sli_ring *pring, |
| 2495 | uint32_t tag) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2496 | { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2497 | struct hbq_dmabuf *hbq_entry; |
| 2498 | |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2499 | if (tag & QUE_BUFTAG_BIT) |
| 2500 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 2501 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
| 2502 | if (!hbq_entry) |
| 2503 | return NULL; |
| 2504 | return &hbq_entry->dbuf; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2505 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2506 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2507 | /** |
| 2508 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence |
| 2509 | * @phba: Pointer to HBA context object. |
| 2510 | * @pring: Pointer to driver SLI ring object. |
| 2511 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. |
| 2512 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. |
| 2513 | * @fch_type: the type for the first frame of the sequence. |
| 2514 | * |
| 2515 | * This function is called with no lock held. This function uses the r_ctl and |
| 2516 | * type of the received sequence to find the correct callback function to call |
| 2517 | * to process the sequence. |
| 2518 | **/ |
| 2519 | static int |
| 2520 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2521 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, |
| 2522 | uint32_t fch_type) |
| 2523 | { |
| 2524 | int i; |
| 2525 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2526 | switch (fch_type) { |
| 2527 | case FC_TYPE_NVME: |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 2528 | lpfc_nvmet_unsol_ls_event(phba, pring, saveq); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 2529 | return 1; |
| 2530 | default: |
| 2531 | break; |
| 2532 | } |
| 2533 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2534 | /* unSolicited Responses */ |
| 2535 | if (pring->prt[0].profile) { |
| 2536 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) |
| 2537 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, |
| 2538 | saveq); |
| 2539 | return 1; |
| 2540 | } |
| 2541 | /* We must search, based on rctl / type |
| 2542 | for the right routine */ |
| 2543 | for (i = 0; i < pring->num_mask; i++) { |
| 2544 | if ((pring->prt[i].rctl == fch_r_ctl) && |
| 2545 | (pring->prt[i].type == fch_type)) { |
| 2546 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2547 | (pring->prt[i].lpfc_sli_rcv_unsol_event) |
| 2548 | (phba, pring, saveq); |
| 2549 | return 1; |
| 2550 | } |
| 2551 | } |
| 2552 | return 0; |
| 2553 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2554 | |
| 2555 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2556 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2557 | * @phba: Pointer to HBA context object. |
| 2558 | * @pring: Pointer to driver SLI ring object. |
| 2559 | * @saveq: Pointer to the unsolicited iocb. |
| 2560 | * |
| 2561 | * This function is called with no lock held by the ring event handler |
| 2562 | * when there is an unsolicited iocb posted to the response ring by the |
| 2563 | * firmware. This function gets the buffer associated with the iocbs |
| 2564 | * and calls the event handler for the ring. This function handles both |
| 2565 | * qring buffers and hbq buffers. |
| 2566 | * When the function returns 1 the caller can free the iocb object otherwise |
| 2567 | * upper layer functions will free the iocb objects. |
| 2568 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | static int |
| 2570 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 2571 | struct lpfc_iocbq *saveq) |
| 2572 | { |
| 2573 | IOCB_t * irsp; |
| 2574 | WORD5 * w5p; |
| 2575 | uint32_t Rctl, Type; |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2576 | struct lpfc_iocbq *iocbq; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2577 | struct lpfc_dmabuf *dmzbuf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2578 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2579 | irsp = &(saveq->iocb); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 2580 | |
| 2581 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { |
| 2582 | if (pring->lpfc_sli_rcv_async_status) |
| 2583 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); |
| 2584 | else |
| 2585 | lpfc_printf_log(phba, |
| 2586 | KERN_WARNING, |
| 2587 | LOG_SLI, |
| 2588 | "0316 Ring %d handler: unexpected " |
| 2589 | "ASYNC_STATUS iocb received evt_code " |
| 2590 | "0x%x\n", |
| 2591 | pring->ringno, |
| 2592 | irsp->un.asyncstat.evt_code); |
| 2593 | return 1; |
| 2594 | } |
| 2595 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2596 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
| 2597 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { |
| 2598 | if (irsp->ulpBdeCount > 0) { |
| 2599 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2600 | irsp->un.ulpWord[3]); |
| 2601 | lpfc_in_buf_free(phba, dmzbuf); |
| 2602 | } |
| 2603 | |
| 2604 | if (irsp->ulpBdeCount > 1) { |
| 2605 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2606 | irsp->unsli3.sli3Words[3]); |
| 2607 | lpfc_in_buf_free(phba, dmzbuf); |
| 2608 | } |
| 2609 | |
| 2610 | if (irsp->ulpBdeCount > 2) { |
| 2611 | dmzbuf = lpfc_sli_get_buff(phba, pring, |
| 2612 | irsp->unsli3.sli3Words[7]); |
| 2613 | lpfc_in_buf_free(phba, dmzbuf); |
| 2614 | } |
| 2615 | |
| 2616 | return 1; |
| 2617 | } |
| 2618 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2619 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2620 | if (irsp->ulpBdeCount != 0) { |
| 2621 | saveq->context2 = lpfc_sli_get_buff(phba, pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2622 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2623 | if (!saveq->context2) |
| 2624 | lpfc_printf_log(phba, |
| 2625 | KERN_ERR, |
| 2626 | LOG_SLI, |
| 2627 | "0341 Ring %d Cannot find buffer for " |
| 2628 | "an unsolicited iocb. tag 0x%x\n", |
| 2629 | pring->ringno, |
| 2630 | irsp->un.ulpWord[3]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2631 | } |
| 2632 | if (irsp->ulpBdeCount == 2) { |
| 2633 | saveq->context3 = lpfc_sli_get_buff(phba, pring, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2634 | irsp->unsli3.sli3Words[7]); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2635 | if (!saveq->context3) |
| 2636 | lpfc_printf_log(phba, |
| 2637 | KERN_ERR, |
| 2638 | LOG_SLI, |
| 2639 | "0342 Ring %d Cannot find buffer for an" |
| 2640 | " unsolicited iocb. tag 0x%x\n", |
| 2641 | pring->ringno, |
| 2642 | irsp->unsli3.sli3Words[7]); |
| 2643 | } |
| 2644 | list_for_each_entry(iocbq, &saveq->list, list) { |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2645 | irsp = &(iocbq->iocb); |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2646 | if (irsp->ulpBdeCount != 0) { |
| 2647 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, |
| 2648 | irsp->un.ulpWord[3]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2649 | if (!iocbq->context2) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2650 | lpfc_printf_log(phba, |
| 2651 | KERN_ERR, |
| 2652 | LOG_SLI, |
| 2653 | "0343 Ring %d Cannot find " |
| 2654 | "buffer for an unsolicited iocb" |
| 2655 | ". tag 0x%x\n", pring->ringno, |
| 2656 | irsp->un.ulpWord[3]); |
| 2657 | } |
| 2658 | if (irsp->ulpBdeCount == 2) { |
| 2659 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, |
| 2660 | irsp->unsli3.sli3Words[7]); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2661 | if (!iocbq->context3) |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 2662 | lpfc_printf_log(phba, |
| 2663 | KERN_ERR, |
| 2664 | LOG_SLI, |
| 2665 | "0344 Ring %d Cannot find " |
| 2666 | "buffer for an unsolicited " |
| 2667 | "iocb. tag 0x%x\n", |
| 2668 | pring->ringno, |
| 2669 | irsp->unsli3.sli3Words[7]); |
| 2670 | } |
| 2671 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2672 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2673 | if (irsp->ulpBdeCount != 0 && |
| 2674 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || |
| 2675 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { |
| 2676 | int found = 0; |
| 2677 | |
| 2678 | /* search continue save q for same XRI */ |
| 2679 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2680 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
| 2681 | saveq->iocb.unsli3.rcvsli3.ox_id) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2682 | list_add_tail(&saveq->list, &iocbq->list); |
| 2683 | found = 1; |
| 2684 | break; |
| 2685 | } |
| 2686 | } |
| 2687 | if (!found) |
| 2688 | list_add_tail(&saveq->clist, |
| 2689 | &pring->iocb_continue_saveq); |
| 2690 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { |
| 2691 | list_del_init(&iocbq->clist); |
| 2692 | saveq = iocbq; |
| 2693 | irsp = &(saveq->iocb); |
| 2694 | } else |
| 2695 | return 0; |
| 2696 | } |
| 2697 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || |
| 2698 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || |
| 2699 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2700 | Rctl = FC_RCTL_ELS_REQ; |
| 2701 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2702 | } else { |
| 2703 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); |
| 2704 | Rctl = w5p->hcsw.Rctl; |
| 2705 | Type = w5p->hcsw.Type; |
| 2706 | |
| 2707 | /* Firmware Workaround */ |
| 2708 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && |
| 2709 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || |
| 2710 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 2711 | Rctl = FC_RCTL_ELS_REQ; |
| 2712 | Type = FC_TYPE_ELS; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 2713 | w5p->hcsw.Rctl = Rctl; |
| 2714 | w5p->hcsw.Type = Type; |
| 2715 | } |
| 2716 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2717 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2718 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2719 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2720 | "0313 Ring %d handler: unexpected Rctl x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2721 | "Type x%x received\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2722 | pring->ringno, Rctl, Type); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2723 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2724 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2725 | } |
| 2726 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2727 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2728 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2729 | * @phba: Pointer to HBA context object. |
| 2730 | * @pring: Pointer to driver SLI ring object. |
| 2731 | * @prspiocb: Pointer to response iocb object. |
| 2732 | * |
| 2733 | * This function looks up the iocb_lookup table to get the command iocb |
| 2734 | * corresponding to the given response iocb using the iotag of the |
| 2735 | * response iocb. This function is called with the hbalock held. |
| 2736 | * This function returns the command iocb object if it finds the command |
| 2737 | * iocb else returns NULL. |
| 2738 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2740 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
| 2741 | struct lpfc_sli_ring *pring, |
| 2742 | struct lpfc_iocbq *prspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2743 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2744 | struct lpfc_iocbq *cmd_iocb = NULL; |
| 2745 | uint16_t iotag; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2746 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2747 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2748 | iotag = prspiocb->iocb.ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2749 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2750 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2751 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2752 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2753 | /* remove from txcmpl queue list */ |
| 2754 | list_del_init(&cmd_iocb->list); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2755 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2756 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2757 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | } |
| 2759 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2761 | "0317 iotag x%x is out of " |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2762 | "range: max iotag x%x wd0 x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2763 | iotag, phba->sli.last_iotag, |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2764 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2765 | return NULL; |
| 2766 | } |
| 2767 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2768 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2769 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag |
| 2770 | * @phba: Pointer to HBA context object. |
| 2771 | * @pring: Pointer to driver SLI ring object. |
| 2772 | * @iotag: IOCB tag. |
| 2773 | * |
| 2774 | * This function looks up the iocb_lookup table to get the command iocb |
| 2775 | * corresponding to the given iotag. This function is called with the |
| 2776 | * hbalock held. |
| 2777 | * This function returns the command iocb object if it finds the command |
| 2778 | * iocb else returns NULL. |
| 2779 | **/ |
| 2780 | static struct lpfc_iocbq * |
| 2781 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, |
| 2782 | struct lpfc_sli_ring *pring, uint16_t iotag) |
| 2783 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2784 | struct lpfc_iocbq *cmd_iocb = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2785 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 2786 | lockdep_assert_held(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2787 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { |
| 2788 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2789 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
| 2790 | /* remove from txcmpl queue list */ |
| 2791 | list_del_init(&cmd_iocb->list); |
| 2792 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 2793 | return cmd_iocb; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 2794 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2795 | } |
James Smart | 89533e9 | 2016-10-13 15:06:15 -0700 | [diff] [blame] | 2796 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2797 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2798 | "0372 iotag x%x lookup error: max iotag (x%x) " |
| 2799 | "iocb_flag x%x\n", |
| 2800 | iotag, phba->sli.last_iotag, |
| 2801 | cmd_iocb ? cmd_iocb->iocb_flag : 0xffff); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2802 | return NULL; |
| 2803 | } |
| 2804 | |
| 2805 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2806 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2807 | * @phba: Pointer to HBA context object. |
| 2808 | * @pring: Pointer to driver SLI ring object. |
| 2809 | * @saveq: Pointer to the response iocb to be processed. |
| 2810 | * |
| 2811 | * This function is called by the ring event handler for non-fcp |
| 2812 | * rings when there is a new response iocb in the response ring. |
| 2813 | * The caller is not required to hold any locks. This function |
| 2814 | * gets the command iocb associated with the response iocb and |
| 2815 | * calls the completion handler for the command iocb. If there |
| 2816 | * is no completion handler, the function will free the resources |
| 2817 | * associated with command iocb. If the response iocb is for |
| 2818 | * an already aborted command iocb, the status of the completion |
| 2819 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. |
| 2820 | * This function always returns 1. |
| 2821 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2822 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2823 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2824 | struct lpfc_iocbq *saveq) |
| 2825 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2826 | struct lpfc_iocbq *cmdiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2827 | int rc = 1; |
| 2828 | unsigned long iflag; |
| 2829 | |
| 2830 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2831 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2832 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2833 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2834 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2835 | if (cmdiocbp) { |
| 2836 | if (cmdiocbp->iocb_cmpl) { |
| 2837 | /* |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2838 | * If an ELS command failed send an event to mgmt |
| 2839 | * application. |
| 2840 | */ |
| 2841 | if (saveq->iocb.ulpStatus && |
| 2842 | (pring->ringno == LPFC_ELS_RING) && |
| 2843 | (cmdiocbp->iocb.ulpCommand == |
| 2844 | CMD_ELS_REQUEST64_CR)) |
| 2845 | lpfc_send_els_failure_event(phba, |
| 2846 | cmdiocbp, saveq); |
| 2847 | |
| 2848 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2849 | * Post all ELS completions to the worker thread. |
| 2850 | * All other are passed to the completion callback. |
| 2851 | */ |
| 2852 | if (pring->ringno == LPFC_ELS_RING) { |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2853 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 2854 | (cmdiocbp->iocb_flag & |
| 2855 | LPFC_DRIVER_ABORTED)) { |
| 2856 | spin_lock_irqsave(&phba->hbalock, |
| 2857 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2858 | cmdiocbp->iocb_flag &= |
| 2859 | ~LPFC_DRIVER_ABORTED; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2860 | spin_unlock_irqrestore(&phba->hbalock, |
| 2861 | iflag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2862 | saveq->iocb.ulpStatus = |
| 2863 | IOSTAT_LOCAL_REJECT; |
| 2864 | saveq->iocb.un.ulpWord[4] = |
| 2865 | IOERR_SLI_ABORTED; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2866 | |
| 2867 | /* Firmware could still be in progress |
| 2868 | * of DMAing payload, so don't free data |
| 2869 | * buffer till after a hbeat. |
| 2870 | */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2871 | spin_lock_irqsave(&phba->hbalock, |
| 2872 | iflag); |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2873 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 2874 | spin_unlock_irqrestore(&phba->hbalock, |
| 2875 | iflag); |
| 2876 | } |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 2877 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2878 | if (saveq->iocb_flag & |
| 2879 | LPFC_EXCHANGE_BUSY) { |
| 2880 | /* Set cmdiocb flag for the |
| 2881 | * exchange busy so sgl (xri) |
| 2882 | * will not be released until |
| 2883 | * the abort xri is received |
| 2884 | * from hba. |
| 2885 | */ |
| 2886 | spin_lock_irqsave( |
| 2887 | &phba->hbalock, iflag); |
| 2888 | cmdiocbp->iocb_flag |= |
| 2889 | LPFC_EXCHANGE_BUSY; |
| 2890 | spin_unlock_irqrestore( |
| 2891 | &phba->hbalock, iflag); |
| 2892 | } |
| 2893 | if (cmdiocbp->iocb_flag & |
| 2894 | LPFC_DRIVER_ABORTED) { |
| 2895 | /* |
| 2896 | * Clear LPFC_DRIVER_ABORTED |
| 2897 | * bit in case it was driver |
| 2898 | * initiated abort. |
| 2899 | */ |
| 2900 | spin_lock_irqsave( |
| 2901 | &phba->hbalock, iflag); |
| 2902 | cmdiocbp->iocb_flag &= |
| 2903 | ~LPFC_DRIVER_ABORTED; |
| 2904 | spin_unlock_irqrestore( |
| 2905 | &phba->hbalock, iflag); |
| 2906 | cmdiocbp->iocb.ulpStatus = |
| 2907 | IOSTAT_LOCAL_REJECT; |
| 2908 | cmdiocbp->iocb.un.ulpWord[4] = |
| 2909 | IOERR_ABORT_REQUESTED; |
| 2910 | /* |
| 2911 | * For SLI4, irsiocb contains |
| 2912 | * NO_XRI in sli_xritag, it |
| 2913 | * shall not affect releasing |
| 2914 | * sgl (xri) process. |
| 2915 | */ |
| 2916 | saveq->iocb.ulpStatus = |
| 2917 | IOSTAT_LOCAL_REJECT; |
| 2918 | saveq->iocb.un.ulpWord[4] = |
| 2919 | IOERR_SLI_ABORTED; |
| 2920 | spin_lock_irqsave( |
| 2921 | &phba->hbalock, iflag); |
| 2922 | saveq->iocb_flag |= |
| 2923 | LPFC_DELAY_MEM_FREE; |
| 2924 | spin_unlock_irqrestore( |
| 2925 | &phba->hbalock, iflag); |
| 2926 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 2927 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2928 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2929 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2930 | } else |
| 2931 | lpfc_sli_release_iocbq(phba, cmdiocbp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2932 | } else { |
| 2933 | /* |
| 2934 | * Unknown initiating command based on the response iotag. |
| 2935 | * This could be the case on the ELS ring because of |
| 2936 | * lpfc_els_abort(). |
| 2937 | */ |
| 2938 | if (pring->ringno != LPFC_ELS_RING) { |
| 2939 | /* |
| 2940 | * Ring <ringno> handler: unexpected completion IoTag |
| 2941 | * <IoTag> |
| 2942 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2943 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2944 | "0322 Ring %d handler: " |
| 2945 | "unexpected completion IoTag x%x " |
| 2946 | "Data: x%x x%x x%x x%x\n", |
| 2947 | pring->ringno, |
| 2948 | saveq->iocb.ulpIoTag, |
| 2949 | saveq->iocb.ulpStatus, |
| 2950 | saveq->iocb.un.ulpWord[4], |
| 2951 | saveq->iocb.ulpCommand, |
| 2952 | saveq->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2953 | } |
| 2954 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 2955 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2956 | return rc; |
| 2957 | } |
| 2958 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2959 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2960 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2961 | * @phba: Pointer to HBA context object. |
| 2962 | * @pring: Pointer to driver SLI ring object. |
| 2963 | * |
| 2964 | * This function is called from the iocb ring event handlers when |
| 2965 | * put pointer is ahead of the get pointer for a ring. This function signal |
| 2966 | * an error attention condition to the worker thread and the worker |
| 2967 | * thread will transition the HBA to offline state. |
| 2968 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2969 | static void |
| 2970 | 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] | 2971 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2972 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2973 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2974 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2975 | * rsp ring <portRspMax> |
| 2976 | */ |
| 2977 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2978 | "0312 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 2979 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2980 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 2981 | pring->sli.sli3.numRiocb); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2982 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2983 | phba->link_state = LPFC_HBA_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2984 | |
| 2985 | /* |
| 2986 | * All error attention handlers are posted to |
| 2987 | * worker thread |
| 2988 | */ |
| 2989 | phba->work_ha |= HA_ERATT; |
| 2990 | phba->work_hs = HS_FFER3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2991 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2992 | lpfc_worker_wake_up(phba); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2993 | |
| 2994 | return; |
| 2995 | } |
| 2996 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2997 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2998 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2999 | * @ptr: Pointer to address of HBA context object. |
| 3000 | * |
| 3001 | * This function is invoked by the Error Attention polling timer when the |
| 3002 | * timer times out. It will check the SLI Error Attention register for |
| 3003 | * possible attention events. If so, it will post an Error Attention event |
| 3004 | * and wake up worker thread to process it. Otherwise, it will set up the |
| 3005 | * Error Attention polling timer for the next poll. |
| 3006 | **/ |
| 3007 | void lpfc_poll_eratt(unsigned long ptr) |
| 3008 | { |
| 3009 | struct lpfc_hba *phba; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 3010 | uint32_t eratt = 0; |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3011 | uint64_t sli_intr, cnt; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3012 | |
| 3013 | phba = (struct lpfc_hba *)ptr; |
| 3014 | |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3015 | /* Here we will also keep track of interrupts per sec of the hba */ |
| 3016 | sli_intr = phba->sli.slistat.sli_intr; |
| 3017 | |
| 3018 | if (phba->sli.slistat.sli_prev_intr > sli_intr) |
| 3019 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + |
| 3020 | sli_intr); |
| 3021 | else |
| 3022 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); |
| 3023 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3024 | /* 64-bit integer division not supported on 32-bit x86 - use do_div */ |
| 3025 | do_div(cnt, phba->eratt_poll_interval); |
James Smart | aa6fbb7 | 2012-08-03 12:36:03 -0400 | [diff] [blame] | 3026 | phba->sli.slistat.sli_ips = cnt; |
| 3027 | |
| 3028 | phba->sli.slistat.sli_prev_intr = sli_intr; |
| 3029 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3030 | /* Check chip HA register for error event */ |
| 3031 | eratt = lpfc_sli_check_eratt(phba); |
| 3032 | |
| 3033 | if (eratt) |
| 3034 | /* Tell the worker thread there is work to do */ |
| 3035 | lpfc_worker_wake_up(phba); |
| 3036 | else |
| 3037 | /* Restart the timer for next eratt poll */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3038 | mod_timer(&phba->eratt_poll, |
| 3039 | jiffies + |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 3040 | msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3041 | return; |
| 3042 | } |
| 3043 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3044 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3045 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3046 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3047 | * @phba: Pointer to HBA context object. |
| 3048 | * @pring: Pointer to driver SLI ring object. |
| 3049 | * @mask: Host attention register mask for this ring. |
| 3050 | * |
| 3051 | * This function is called from the interrupt context when there is a ring |
| 3052 | * event for the fcp ring. The caller does not hold any lock. |
| 3053 | * 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] | 3054 | * 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] | 3055 | * LE bit set. The function will call the completion handler of the command iocb |
| 3056 | * if the response iocb indicates a completion for a command iocb or it is |
| 3057 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb |
| 3058 | * function if this is an unsolicited iocb. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3059 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3060 | * to check it explicitly. |
| 3061 | */ |
| 3062 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3063 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
| 3064 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3066 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3067 | IOCB_t *irsp = NULL; |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3068 | IOCB_t *entry = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3069 | struct lpfc_iocbq *cmdiocbq = NULL; |
| 3070 | struct lpfc_iocbq rspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3071 | uint32_t status; |
| 3072 | uint32_t portRspPut, portRspMax; |
| 3073 | int rc = 1; |
| 3074 | lpfc_iocb_type type; |
| 3075 | unsigned long iflag; |
| 3076 | uint32_t rsp_cmpl = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3077 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3078 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3079 | pring->stats.iocb_event++; |
| 3080 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3081 | /* |
| 3082 | * The next available response entry should never exceed the maximum |
| 3083 | * entries. If it does, treat it as an adapter hardware error. |
| 3084 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3085 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3086 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3087 | if (unlikely(portRspPut >= portRspMax)) { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3088 | lpfc_sli_rsp_pointers_error(phba, pring); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3089 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3090 | return 1; |
| 3091 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3092 | if (phba->fcp_ring_in_use) { |
| 3093 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3094 | return 1; |
| 3095 | } else |
| 3096 | phba->fcp_ring_in_use = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3097 | |
| 3098 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3099 | while (pring->sli.sli3.rspidx != portRspPut) { |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3100 | /* |
| 3101 | * Fetch an entry off the ring and copy it into a local data |
| 3102 | * structure. The copy involves a byte-swap since the |
| 3103 | * network byte order and pci byte orders are different. |
| 3104 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3105 | entry = lpfc_resp_iocb(phba, pring); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3106 | phba->last_completion_time = jiffies; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3107 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3108 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3109 | pring->sli.sli3.rspidx = 0; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 3110 | |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3111 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
| 3112 | (uint32_t *) &rspiocbq.iocb, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3113 | phba->iocb_rsp_size); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3114 | INIT_LIST_HEAD(&(rspiocbq.list)); |
James.Smart@Emulex.Com | 87f6eaf | 2005-06-25 10:34:13 -0400 | [diff] [blame] | 3115 | irsp = &rspiocbq.iocb; |
| 3116 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3117 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
| 3118 | pring->stats.iocb_rsp++; |
| 3119 | rsp_cmpl++; |
| 3120 | |
| 3121 | if (unlikely(irsp->ulpStatus)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3122 | /* |
| 3123 | * If resource errors reported from HBA, reduce |
| 3124 | * queuedepths of the SCSI device. |
| 3125 | */ |
| 3126 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3127 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3128 | IOERR_NO_RESOURCES)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3129 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3130 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3131 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3132 | } |
| 3133 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3134 | /* Rsp ring <ringno> error: IOCB */ |
| 3135 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3136 | "0336 Rsp Ring %d error: IOCB Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3137 | "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] | 3138 | pring->ringno, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3139 | irsp->un.ulpWord[0], |
| 3140 | irsp->un.ulpWord[1], |
| 3141 | irsp->un.ulpWord[2], |
| 3142 | irsp->un.ulpWord[3], |
| 3143 | irsp->un.ulpWord[4], |
| 3144 | irsp->un.ulpWord[5], |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3145 | *(uint32_t *)&irsp->un1, |
| 3146 | *((uint32_t *)&irsp->un1 + 1)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | switch (type) { |
| 3150 | case LPFC_ABORT_IOCB: |
| 3151 | case LPFC_SOL_IOCB: |
| 3152 | /* |
| 3153 | * Idle exchange closed via ABTS from port. No iocb |
| 3154 | * resources need to be recovered. |
| 3155 | */ |
| 3156 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3157 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3158 | "0333 IOCB cmd 0x%x" |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3159 | " processed. Skipping" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3160 | " completion\n", |
James Smart | dca9479 | 2006-08-01 07:34:08 -0400 | [diff] [blame] | 3161 | irsp->ulpCommand); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3162 | break; |
| 3163 | } |
| 3164 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 3165 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
| 3166 | &rspiocbq); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 3167 | if (unlikely(!cmdiocbq)) |
| 3168 | break; |
| 3169 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 3170 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 3171 | if (cmdiocbq->iocb_cmpl) { |
| 3172 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3173 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, |
| 3174 | &rspiocbq); |
| 3175 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3176 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3177 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3178 | case LPFC_UNSOL_IOCB: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3179 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3180 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3181 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 3182 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3183 | default: |
| 3184 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3185 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3186 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3187 | memcpy(&adaptermsg[0], (uint8_t *) irsp, |
| 3188 | MAX_MSG_DATA); |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3189 | dev_warn(&((phba->pcidev)->dev), |
| 3190 | "lpfc%d: %s\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3191 | phba->brd_no, adaptermsg); |
| 3192 | } else { |
| 3193 | /* Unknown IOCB command */ |
| 3194 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3195 | "0334 Unknown IOCB command " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3196 | "Data: x%x, x%x x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3197 | type, irsp->ulpCommand, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3198 | irsp->ulpStatus, |
| 3199 | irsp->ulpIoTag, |
| 3200 | irsp->ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3201 | } |
| 3202 | break; |
| 3203 | } |
| 3204 | |
| 3205 | /* |
| 3206 | * The response IOCB has been processed. Update the ring |
| 3207 | * pointer in SLIM. If the port response put pointer has not |
| 3208 | * been updated, sync the pgp->rspPutInx and fetch the new port |
| 3209 | * response put pointer. |
| 3210 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3211 | writel(pring->sli.sli3.rspidx, |
| 3212 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3213 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3214 | if (pring->sli.sli3.rspidx == portRspPut) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3215 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3216 | } |
| 3217 | |
| 3218 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { |
| 3219 | pring->stats.iocb_rsp_full++; |
| 3220 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3221 | writel(status, phba->CAregaddr); |
| 3222 | readl(phba->CAregaddr); |
| 3223 | } |
| 3224 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3225 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3226 | pring->stats.iocb_cmd_empty++; |
| 3227 | |
| 3228 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3229 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3230 | lpfc_sli_resume_iocb(phba, pring); |
| 3231 | |
| 3232 | if ((pring->lpfc_sli_cmd_available)) |
| 3233 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3234 | |
| 3235 | } |
| 3236 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3237 | phba->fcp_ring_in_use = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3238 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3239 | return rc; |
| 3240 | } |
| 3241 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3242 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3243 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
| 3244 | * @phba: Pointer to HBA context object. |
| 3245 | * @pring: Pointer to driver SLI ring object. |
| 3246 | * @rspiocbp: Pointer to driver response IOCB object. |
| 3247 | * |
| 3248 | * This function is called from the worker thread when there is a slow-path |
| 3249 | * response IOCB to process. This function chains all the response iocbs until |
| 3250 | * seeing the iocb with the LE bit set. The function will call |
| 3251 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a |
| 3252 | * completion of a command iocb. The function will call the |
| 3253 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. |
| 3254 | * The function frees the resources or calls the completion handler if this |
| 3255 | * iocb is an abort completion. The function returns NULL when the response |
| 3256 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise |
| 3257 | * this function shall chain the iocb on to the iocb_continueq and return the |
| 3258 | * response iocb passed in. |
| 3259 | **/ |
| 3260 | static struct lpfc_iocbq * |
| 3261 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 3262 | struct lpfc_iocbq *rspiocbp) |
| 3263 | { |
| 3264 | struct lpfc_iocbq *saveq; |
| 3265 | struct lpfc_iocbq *cmdiocbp; |
| 3266 | struct lpfc_iocbq *next_iocb; |
| 3267 | IOCB_t *irsp = NULL; |
| 3268 | uint32_t free_saveq; |
| 3269 | uint8_t iocb_cmd_type; |
| 3270 | lpfc_iocb_type type; |
| 3271 | unsigned long iflag; |
| 3272 | int rc; |
| 3273 | |
| 3274 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3275 | /* First add the response iocb to the countinueq list */ |
| 3276 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); |
| 3277 | pring->iocb_continueq_cnt++; |
| 3278 | |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 3279 | /* Now, determine whether the list is completed for processing */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3280 | irsp = &rspiocbp->iocb; |
| 3281 | if (irsp->ulpLe) { |
| 3282 | /* |
| 3283 | * By default, the driver expects to free all resources |
| 3284 | * associated with this iocb completion. |
| 3285 | */ |
| 3286 | free_saveq = 1; |
| 3287 | saveq = list_get_first(&pring->iocb_continueq, |
| 3288 | struct lpfc_iocbq, list); |
| 3289 | irsp = &(saveq->iocb); |
| 3290 | list_del_init(&pring->iocb_continueq); |
| 3291 | pring->iocb_continueq_cnt = 0; |
| 3292 | |
| 3293 | pring->stats.iocb_rsp++; |
| 3294 | |
| 3295 | /* |
| 3296 | * If resource errors reported from HBA, reduce |
| 3297 | * queuedepths of the SCSI device. |
| 3298 | */ |
| 3299 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 3300 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 3301 | IOERR_NO_RESOURCES)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3302 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3303 | phba->lpfc_rampdown_queue_depth(phba); |
| 3304 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3305 | } |
| 3306 | |
| 3307 | if (irsp->ulpStatus) { |
| 3308 | /* Rsp ring <ringno> error: IOCB */ |
| 3309 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 3310 | "0328 Rsp Ring %d error: " |
| 3311 | "IOCB Data: " |
| 3312 | "x%x x%x x%x x%x " |
| 3313 | "x%x x%x x%x x%x " |
| 3314 | "x%x x%x x%x x%x " |
| 3315 | "x%x x%x x%x x%x\n", |
| 3316 | pring->ringno, |
| 3317 | irsp->un.ulpWord[0], |
| 3318 | irsp->un.ulpWord[1], |
| 3319 | irsp->un.ulpWord[2], |
| 3320 | irsp->un.ulpWord[3], |
| 3321 | irsp->un.ulpWord[4], |
| 3322 | irsp->un.ulpWord[5], |
| 3323 | *(((uint32_t *) irsp) + 6), |
| 3324 | *(((uint32_t *) irsp) + 7), |
| 3325 | *(((uint32_t *) irsp) + 8), |
| 3326 | *(((uint32_t *) irsp) + 9), |
| 3327 | *(((uint32_t *) irsp) + 10), |
| 3328 | *(((uint32_t *) irsp) + 11), |
| 3329 | *(((uint32_t *) irsp) + 12), |
| 3330 | *(((uint32_t *) irsp) + 13), |
| 3331 | *(((uint32_t *) irsp) + 14), |
| 3332 | *(((uint32_t *) irsp) + 15)); |
| 3333 | } |
| 3334 | |
| 3335 | /* |
| 3336 | * Fetch the IOCB command type and call the correct completion |
| 3337 | * routine. Solicited and Unsolicited IOCBs on the ELS ring |
| 3338 | * get freed back to the lpfc_iocb_list by the discovery |
| 3339 | * kernel thread. |
| 3340 | */ |
| 3341 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; |
| 3342 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); |
| 3343 | switch (type) { |
| 3344 | case LPFC_SOL_IOCB: |
| 3345 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3346 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); |
| 3347 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3348 | break; |
| 3349 | |
| 3350 | case LPFC_UNSOL_IOCB: |
| 3351 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3352 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); |
| 3353 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3354 | if (!rc) |
| 3355 | free_saveq = 0; |
| 3356 | break; |
| 3357 | |
| 3358 | case LPFC_ABORT_IOCB: |
| 3359 | cmdiocbp = NULL; |
| 3360 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) |
| 3361 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, |
| 3362 | saveq); |
| 3363 | if (cmdiocbp) { |
| 3364 | /* Call the specified completion routine */ |
| 3365 | if (cmdiocbp->iocb_cmpl) { |
| 3366 | spin_unlock_irqrestore(&phba->hbalock, |
| 3367 | iflag); |
| 3368 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, |
| 3369 | saveq); |
| 3370 | spin_lock_irqsave(&phba->hbalock, |
| 3371 | iflag); |
| 3372 | } else |
| 3373 | __lpfc_sli_release_iocbq(phba, |
| 3374 | cmdiocbp); |
| 3375 | } |
| 3376 | break; |
| 3377 | |
| 3378 | case LPFC_UNKNOWN_IOCB: |
| 3379 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { |
| 3380 | char adaptermsg[LPFC_MAX_ADPTMSG]; |
| 3381 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); |
| 3382 | memcpy(&adaptermsg[0], (uint8_t *)irsp, |
| 3383 | MAX_MSG_DATA); |
| 3384 | dev_warn(&((phba->pcidev)->dev), |
| 3385 | "lpfc%d: %s\n", |
| 3386 | phba->brd_no, adaptermsg); |
| 3387 | } else { |
| 3388 | /* Unknown IOCB command */ |
| 3389 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3390 | "0335 Unknown IOCB " |
| 3391 | "command Data: x%x " |
| 3392 | "x%x x%x x%x\n", |
| 3393 | irsp->ulpCommand, |
| 3394 | irsp->ulpStatus, |
| 3395 | irsp->ulpIoTag, |
| 3396 | irsp->ulpContext); |
| 3397 | } |
| 3398 | break; |
| 3399 | } |
| 3400 | |
| 3401 | if (free_saveq) { |
| 3402 | list_for_each_entry_safe(rspiocbp, next_iocb, |
| 3403 | &saveq->list, list) { |
James Smart | 61f35bf | 2013-05-31 17:03:48 -0400 | [diff] [blame] | 3404 | list_del_init(&rspiocbp->list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3405 | __lpfc_sli_release_iocbq(phba, rspiocbp); |
| 3406 | } |
| 3407 | __lpfc_sli_release_iocbq(phba, saveq); |
| 3408 | } |
| 3409 | rspiocbp = NULL; |
| 3410 | } |
| 3411 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3412 | return rspiocbp; |
| 3413 | } |
| 3414 | |
| 3415 | /** |
| 3416 | * 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] | 3417 | * @phba: Pointer to HBA context object. |
| 3418 | * @pring: Pointer to driver SLI ring object. |
| 3419 | * @mask: Host attention register mask for this ring. |
| 3420 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3421 | * This routine wraps the actual slow_ring event process routine from the |
| 3422 | * API jump table function pointer from the lpfc_hba struct. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3423 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3424 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3425 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
| 3426 | struct lpfc_sli_ring *pring, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3427 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3428 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); |
| 3429 | } |
| 3430 | |
| 3431 | /** |
| 3432 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings |
| 3433 | * @phba: Pointer to HBA context object. |
| 3434 | * @pring: Pointer to driver SLI ring object. |
| 3435 | * @mask: Host attention register mask for this ring. |
| 3436 | * |
| 3437 | * This function is called from the worker thread when there is a ring event |
| 3438 | * for non-fcp rings. The caller does not hold any lock. The function will |
| 3439 | * remove each response iocb in the response ring and calls the handle |
| 3440 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3441 | **/ |
| 3442 | static void |
| 3443 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, |
| 3444 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3445 | { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3446 | struct lpfc_pgp *pgp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3447 | IOCB_t *entry; |
| 3448 | IOCB_t *irsp = NULL; |
| 3449 | struct lpfc_iocbq *rspiocbp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3450 | uint32_t portRspPut, portRspMax; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | unsigned long iflag; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3452 | uint32_t status; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3453 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 3454 | pgp = &phba->port_gp[pring->ringno]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3455 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3456 | pring->stats.iocb_event++; |
| 3457 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3458 | /* |
| 3459 | * The next available response entry should never exceed the maximum |
| 3460 | * entries. If it does, treat it as an adapter hardware error. |
| 3461 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3462 | portRspMax = pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3463 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3464 | if (portRspPut >= portRspMax) { |
| 3465 | /* |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3466 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3467 | * rsp ring <portRspMax> |
| 3468 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3469 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3470 | "0303 Ring %d handler: portRspPut %d " |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 3471 | "is bigger than rsp ring %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3472 | pring->ringno, portRspPut, portRspMax); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3473 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3474 | phba->link_state = LPFC_HBA_ERROR; |
| 3475 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3476 | |
| 3477 | phba->work_hs = HS_FFER3; |
| 3478 | lpfc_handle_eratt(phba); |
| 3479 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3480 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3481 | } |
| 3482 | |
| 3483 | rmb(); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3484 | while (pring->sli.sli3.rspidx != portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3485 | /* |
| 3486 | * Build a completion list and call the appropriate handler. |
| 3487 | * The process is to get the next available response iocb, get |
| 3488 | * a free iocb from the list, copy the response data into the |
| 3489 | * free iocb, insert to the continuation list, and update the |
| 3490 | * next response index to slim. This process makes response |
| 3491 | * iocb's in the ring available to DMA as fast as possible but |
| 3492 | * pays a penalty for a copy operation. Since the iocb is |
| 3493 | * only 32 bytes, this penalty is considered small relative to |
| 3494 | * the PCI reads for register values and a slim write. When |
| 3495 | * the ulpLe field is set, the entire Command has been |
| 3496 | * received. |
| 3497 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3498 | entry = lpfc_resp_iocb(phba, pring); |
| 3499 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3500 | phba->last_completion_time = jiffies; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3501 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3502 | if (rspiocbp == NULL) { |
| 3503 | printk(KERN_ERR "%s: out of buffers! Failing " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 3504 | "completion.\n", __func__); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3505 | break; |
| 3506 | } |
| 3507 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3508 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
| 3509 | phba->iocb_rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | irsp = &rspiocbp->iocb; |
| 3511 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3512 | if (++pring->sli.sli3.rspidx >= portRspMax) |
| 3513 | pring->sli.sli3.rspidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3514 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3515 | if (pring->ringno == LPFC_ELS_RING) { |
| 3516 | lpfc_debugfs_slow_ring_trc(phba, |
| 3517 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", |
| 3518 | *(((uint32_t *) irsp) + 4), |
| 3519 | *(((uint32_t *) irsp) + 6), |
| 3520 | *(((uint32_t *) irsp) + 7)); |
| 3521 | } |
| 3522 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3523 | writel(pring->sli.sli3.rspidx, |
| 3524 | &phba->host_gp[pring->ringno].rspGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3525 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3526 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3527 | /* Handle the response IOCB */ |
| 3528 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
| 3529 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3530 | |
| 3531 | /* |
| 3532 | * If the port response put pointer has not been updated, sync |
| 3533 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port |
| 3534 | * response put pointer. |
| 3535 | */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3536 | if (pring->sli.sli3.rspidx == portRspPut) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3537 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
| 3538 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3539 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3540 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3541 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3542 | /* At least one response entry has been freed */ |
| 3543 | pring->stats.iocb_rsp_full++; |
| 3544 | /* SET RxRE_RSP in Chip Att register */ |
| 3545 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); |
| 3546 | writel(status, phba->CAregaddr); |
| 3547 | readl(phba->CAregaddr); /* flush */ |
| 3548 | } |
| 3549 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { |
| 3550 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; |
| 3551 | pring->stats.iocb_cmd_empty++; |
| 3552 | |
| 3553 | /* Force update of the local copy of cmdGetInx */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 3554 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3555 | lpfc_sli_resume_iocb(phba, pring); |
| 3556 | |
| 3557 | if ((pring->lpfc_sli_cmd_available)) |
| 3558 | (pring->lpfc_sli_cmd_available) (phba, pring); |
| 3559 | |
| 3560 | } |
| 3561 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3562 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3563 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3564 | } |
| 3565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3566 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3567 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events |
| 3568 | * @phba: Pointer to HBA context object. |
| 3569 | * @pring: Pointer to driver SLI ring object. |
| 3570 | * @mask: Host attention register mask for this ring. |
| 3571 | * |
| 3572 | * This function is called from the worker thread when there is a pending |
| 3573 | * ELS response iocb on the driver internal slow-path response iocb worker |
| 3574 | * queue. The caller does not hold any lock. The function will remove each |
| 3575 | * response iocb from the response worker queue and calls the handle |
| 3576 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. |
| 3577 | **/ |
| 3578 | static void |
| 3579 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, |
| 3580 | struct lpfc_sli_ring *pring, uint32_t mask) |
| 3581 | { |
| 3582 | struct lpfc_iocbq *irspiocbq; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3583 | struct hbq_dmabuf *dmabuf; |
| 3584 | struct lpfc_cq_event *cq_event; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3585 | unsigned long iflag; |
| 3586 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3587 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3588 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 3589 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3590 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3591 | /* Get the response iocb from the head of work queue */ |
| 3592 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3593 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3594 | cq_event, struct lpfc_cq_event, list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3595 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3596 | |
| 3597 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 3598 | case CQE_CODE_COMPL_WQE: |
| 3599 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 3600 | cq_event); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 3601 | /* Translate ELS WCQE to response IOCBQ */ |
| 3602 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, |
| 3603 | irspiocbq); |
| 3604 | if (irspiocbq) |
| 3605 | lpfc_sli_sp_handle_rspiocb(phba, pring, |
| 3606 | irspiocbq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3607 | break; |
| 3608 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 3609 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 3610 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 3611 | cq_event); |
| 3612 | lpfc_sli4_handle_received_buffer(phba, dmabuf); |
| 3613 | break; |
| 3614 | default: |
| 3615 | break; |
| 3616 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 3617 | } |
| 3618 | } |
| 3619 | |
| 3620 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3621 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3622 | * @phba: Pointer to HBA context object. |
| 3623 | * @pring: Pointer to driver SLI ring object. |
| 3624 | * |
| 3625 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3626 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3627 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3628 | * the return of this function. The caller is not required to hold any locks. |
| 3629 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3630 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3631 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3632 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3633 | LIST_HEAD(completions); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3634 | struct lpfc_iocbq *iocb, *next_iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3635 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3636 | if (pring->ringno == LPFC_ELS_RING) { |
| 3637 | lpfc_fabric_abort_hba(phba); |
| 3638 | } |
| 3639 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3640 | /* Error everything on txq and txcmplq |
| 3641 | * First do the txq. |
| 3642 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3643 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3644 | spin_lock_irq(&pring->ring_lock); |
| 3645 | list_splice_init(&pring->txq, &completions); |
| 3646 | pring->txq_cnt = 0; |
| 3647 | spin_unlock_irq(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3648 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3649 | spin_lock_irq(&phba->hbalock); |
| 3650 | /* Next issue ABTS for everything on the txcmplq */ |
| 3651 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3652 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3653 | spin_unlock_irq(&phba->hbalock); |
| 3654 | } else { |
| 3655 | spin_lock_irq(&phba->hbalock); |
| 3656 | list_splice_init(&pring->txq, &completions); |
| 3657 | pring->txq_cnt = 0; |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3658 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3659 | /* Next issue ABTS for everything on the txcmplq */ |
| 3660 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3661 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 3662 | spin_unlock_irq(&phba->hbalock); |
| 3663 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3664 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 3665 | /* Cancel all the IOCBs from the completions list */ |
| 3666 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 3667 | IOERR_SLI_ABORTED); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3668 | } |
| 3669 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3670 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3671 | * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring |
| 3672 | * @phba: Pointer to HBA context object. |
| 3673 | * @pring: Pointer to driver SLI ring object. |
| 3674 | * |
| 3675 | * This function aborts all iocbs in the given ring and frees all the iocb |
| 3676 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3677 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3678 | * the return of this function. The caller is not required to hold any locks. |
| 3679 | **/ |
| 3680 | void |
| 3681 | lpfc_sli_abort_wqe_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
| 3682 | { |
| 3683 | LIST_HEAD(completions); |
| 3684 | struct lpfc_iocbq *iocb, *next_iocb; |
| 3685 | |
| 3686 | if (pring->ringno == LPFC_ELS_RING) |
| 3687 | lpfc_fabric_abort_hba(phba); |
| 3688 | |
| 3689 | spin_lock_irq(&phba->hbalock); |
| 3690 | /* Next issue ABTS for everything on the txcmplq */ |
| 3691 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
| 3692 | lpfc_sli4_abort_nvme_io(phba, pring, iocb); |
| 3693 | spin_unlock_irq(&phba->hbalock); |
| 3694 | } |
| 3695 | |
| 3696 | |
| 3697 | /** |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3698 | * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings |
| 3699 | * @phba: Pointer to HBA context object. |
| 3700 | * @pring: Pointer to driver SLI ring object. |
| 3701 | * |
| 3702 | * This function aborts all iocbs in FCP rings and frees all the iocb |
| 3703 | * objects in txq. This function issues an abort iocb for all the iocb commands |
| 3704 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before |
| 3705 | * the return of this function. The caller is not required to hold any locks. |
| 3706 | **/ |
| 3707 | void |
| 3708 | lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba) |
| 3709 | { |
| 3710 | struct lpfc_sli *psli = &phba->sli; |
| 3711 | struct lpfc_sli_ring *pring; |
| 3712 | uint32_t i; |
| 3713 | |
| 3714 | /* Look on all the FCP Rings for the iotag */ |
| 3715 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3716 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3717 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3718 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3719 | } |
| 3720 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3721 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3722 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 3723 | } |
| 3724 | } |
| 3725 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3726 | /** |
| 3727 | * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings |
| 3728 | * @phba: Pointer to HBA context object. |
| 3729 | * |
| 3730 | * This function aborts all wqes in NVME rings. This function issues an |
| 3731 | * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in |
| 3732 | * the txcmplq is not guaranteed to complete before the return of this |
| 3733 | * function. The caller is not required to hold any locks. |
| 3734 | **/ |
| 3735 | void |
| 3736 | lpfc_sli_abort_nvme_rings(struct lpfc_hba *phba) |
| 3737 | { |
| 3738 | struct lpfc_sli_ring *pring; |
| 3739 | uint32_t i; |
| 3740 | |
| 3741 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3742 | return; |
| 3743 | |
| 3744 | /* Abort all IO on each NVME ring. */ |
| 3745 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 3746 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 3747 | lpfc_sli_abort_wqe_ring(phba, pring); |
| 3748 | } |
| 3749 | } |
| 3750 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3751 | |
| 3752 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3753 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3754 | * @phba: Pointer to HBA context object. |
| 3755 | * |
| 3756 | * This function flushes all iocbs in the fcp ring and frees all the iocb |
| 3757 | * objects in txq and txcmplq. This function will not issue abort iocbs |
| 3758 | * for all the iocb commands in txcmplq, they will just be returned with |
| 3759 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3760 | * slot has been permanently disabled. |
| 3761 | **/ |
| 3762 | void |
| 3763 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) |
| 3764 | { |
| 3765 | LIST_HEAD(txq); |
| 3766 | LIST_HEAD(txcmplq); |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3767 | struct lpfc_sli *psli = &phba->sli; |
| 3768 | struct lpfc_sli_ring *pring; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3769 | uint32_t i; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3770 | |
| 3771 | spin_lock_irq(&phba->hbalock); |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 3772 | /* Indicate the I/O queues are flushed */ |
| 3773 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3774 | spin_unlock_irq(&phba->hbalock); |
| 3775 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3776 | /* Look on all the FCP Rings for the iotag */ |
| 3777 | if (phba->sli_rev >= LPFC_SLI_REV4) { |
| 3778 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3779 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3780 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3781 | spin_lock_irq(&pring->ring_lock); |
| 3782 | /* Retrieve everything on txq */ |
| 3783 | list_splice_init(&pring->txq, &txq); |
| 3784 | /* Retrieve everything on the txcmplq */ |
| 3785 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3786 | pring->txq_cnt = 0; |
| 3787 | pring->txcmplq_cnt = 0; |
| 3788 | spin_unlock_irq(&pring->ring_lock); |
| 3789 | |
| 3790 | /* Flush the txq */ |
| 3791 | lpfc_sli_cancel_iocbs(phba, &txq, |
| 3792 | IOSTAT_LOCAL_REJECT, |
| 3793 | IOERR_SLI_DOWN); |
| 3794 | /* Flush the txcmpq */ |
| 3795 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 3796 | IOSTAT_LOCAL_REJECT, |
| 3797 | IOERR_SLI_DOWN); |
| 3798 | } |
| 3799 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3800 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 3801 | |
| 3802 | spin_lock_irq(&phba->hbalock); |
| 3803 | /* Retrieve everything on txq */ |
| 3804 | list_splice_init(&pring->txq, &txq); |
| 3805 | /* Retrieve everything on the txcmplq */ |
| 3806 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3807 | pring->txq_cnt = 0; |
| 3808 | pring->txcmplq_cnt = 0; |
| 3809 | spin_unlock_irq(&phba->hbalock); |
| 3810 | |
| 3811 | /* Flush the txq */ |
| 3812 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
| 3813 | IOERR_SLI_DOWN); |
| 3814 | /* Flush the txcmpq */ |
| 3815 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
| 3816 | IOERR_SLI_DOWN); |
| 3817 | } |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3821 | * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings |
| 3822 | * @phba: Pointer to HBA context object. |
| 3823 | * |
| 3824 | * This function flushes all wqes in the nvme rings and frees all resources |
| 3825 | * in the txcmplq. This function does not issue abort wqes for the IO |
| 3826 | * commands in txcmplq, they will just be returned with |
| 3827 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI |
| 3828 | * slot has been permanently disabled. |
| 3829 | **/ |
| 3830 | void |
| 3831 | lpfc_sli_flush_nvme_rings(struct lpfc_hba *phba) |
| 3832 | { |
| 3833 | LIST_HEAD(txcmplq); |
| 3834 | struct lpfc_sli_ring *pring; |
| 3835 | uint32_t i; |
| 3836 | |
| 3837 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3838 | return; |
| 3839 | |
| 3840 | /* Hint to other driver operations that a flush is in progress. */ |
| 3841 | spin_lock_irq(&phba->hbalock); |
| 3842 | phba->hba_flag |= HBA_NVME_IOQ_FLUSH; |
| 3843 | spin_unlock_irq(&phba->hbalock); |
| 3844 | |
| 3845 | /* Cycle through all NVME rings and complete each IO with |
| 3846 | * a local driver reason code. This is a flush so no |
| 3847 | * abort exchange to FW. |
| 3848 | */ |
| 3849 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 3850 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 3851 | |
| 3852 | /* Retrieve everything on the txcmplq */ |
| 3853 | spin_lock_irq(&pring->ring_lock); |
| 3854 | list_splice_init(&pring->txcmplq, &txcmplq); |
| 3855 | pring->txcmplq_cnt = 0; |
| 3856 | spin_unlock_irq(&pring->ring_lock); |
| 3857 | |
| 3858 | /* Flush the txcmpq &&&PAE */ |
| 3859 | lpfc_sli_cancel_iocbs(phba, &txcmplq, |
| 3860 | IOSTAT_LOCAL_REJECT, |
| 3861 | IOERR_SLI_DOWN); |
| 3862 | } |
| 3863 | } |
| 3864 | |
| 3865 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3866 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3867 | * @phba: Pointer to HBA context object. |
| 3868 | * @mask: Bit mask to be checked. |
| 3869 | * |
| 3870 | * This function reads the host status register and compares |
| 3871 | * with the provided bit mask to check if HBA completed |
| 3872 | * the restart. This function will wait in a loop for the |
| 3873 | * HBA to complete restart. If the HBA does not restart within |
| 3874 | * 15 iterations, the function will reset the HBA again. The |
| 3875 | * function returns 1 when HBA fail to restart otherwise returns |
| 3876 | * zero. |
| 3877 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3878 | static int |
| 3879 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3880 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3881 | uint32_t status; |
| 3882 | int i = 0; |
| 3883 | int retval = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3884 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3885 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3886 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 3887 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3888 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3889 | /* |
| 3890 | * Check status register every 100ms for 5 retries, then every |
| 3891 | * 500ms for 5, then every 2.5 sec for 5, then reset board and |
| 3892 | * every 2.5 sec for 4. |
| 3893 | * Break our of the loop if errors occurred during init. |
| 3894 | */ |
| 3895 | while (((status & mask) != mask) && |
| 3896 | !(status & HS_FFERM) && |
| 3897 | i++ < 20) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3898 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3899 | if (i <= 5) |
| 3900 | msleep(10); |
| 3901 | else if (i <= 10) |
| 3902 | msleep(500); |
| 3903 | else |
| 3904 | msleep(2500); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3905 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3906 | if (i == 15) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3907 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3908 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3909 | lpfc_sli_brdrestart(phba); |
| 3910 | } |
| 3911 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3912 | if (lpfc_readl(phba->HSregaddr, &status)) { |
| 3913 | retval = 1; |
| 3914 | break; |
| 3915 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3916 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3917 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3918 | /* Check to see if any errors occurred during init */ |
| 3919 | if ((status & HS_FFERM) || (i >= 20)) { |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 3920 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3921 | "2751 Adapter failed to restart, " |
| 3922 | "status reg x%x, FW Data: A8 x%x AC x%x\n", |
| 3923 | status, |
| 3924 | readl(phba->MBslimaddr + 0xa8), |
| 3925 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3926 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3927 | retval = 1; |
| 3928 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3929 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 3930 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3931 | } |
| 3932 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3933 | /** |
| 3934 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status |
| 3935 | * @phba: Pointer to HBA context object. |
| 3936 | * @mask: Bit mask to be checked. |
| 3937 | * |
| 3938 | * This function checks the host status register to check if HBA is |
| 3939 | * ready. This function will wait in a loop for the HBA to be ready |
| 3940 | * If the HBA is not ready , the function will will reset the HBA PCI |
| 3941 | * function again. The function returns 1 when HBA fail to be ready |
| 3942 | * otherwise returns zero. |
| 3943 | **/ |
| 3944 | static int |
| 3945 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) |
| 3946 | { |
| 3947 | uint32_t status; |
| 3948 | int retval = 0; |
| 3949 | |
| 3950 | /* Read the HBA Host Status Register */ |
| 3951 | status = lpfc_sli4_post_status_check(phba); |
| 3952 | |
| 3953 | if (status) { |
| 3954 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
| 3955 | lpfc_sli_brdrestart(phba); |
| 3956 | status = lpfc_sli4_post_status_check(phba); |
| 3957 | } |
| 3958 | |
| 3959 | /* Check to see if any errors occurred during init */ |
| 3960 | if (status) { |
| 3961 | phba->link_state = LPFC_HBA_ERROR; |
| 3962 | retval = 1; |
| 3963 | } else |
| 3964 | phba->sli4_hba.intr_enable = 0; |
| 3965 | |
| 3966 | return retval; |
| 3967 | } |
| 3968 | |
| 3969 | /** |
| 3970 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness |
| 3971 | * @phba: Pointer to HBA context object. |
| 3972 | * @mask: Bit mask to be checked. |
| 3973 | * |
| 3974 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine |
| 3975 | * from the API jump table function pointer from the lpfc_hba struct. |
| 3976 | **/ |
| 3977 | int |
| 3978 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) |
| 3979 | { |
| 3980 | return phba->lpfc_sli_brdready(phba, mask); |
| 3981 | } |
| 3982 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3983 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
| 3984 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3985 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3986 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3987 | * @phba: Pointer to HBA context object. |
| 3988 | * |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3989 | * This function is called before resetting an HBA. This function is called |
| 3990 | * with hbalock held and requests HBA to quiesce DMAs before a reset. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3991 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3992 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3993 | { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 3994 | uint32_t __iomem *resp_buf; |
| 3995 | uint32_t __iomem *mbox_buf; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3996 | volatile uint32_t mbox; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 3997 | uint32_t hc_copy, ha_copy, resp_data; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 3998 | int i; |
| 3999 | uint8_t hdrtype; |
| 4000 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 4001 | lockdep_assert_held(&phba->hbalock); |
| 4002 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4003 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); |
| 4004 | if (hdrtype != 0x80 || |
| 4005 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && |
| 4006 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) |
| 4007 | return; |
| 4008 | |
| 4009 | /* |
| 4010 | * Tell the other part of the chip to suspend temporarily all |
| 4011 | * its DMA activity. |
| 4012 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4013 | resp_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4014 | |
| 4015 | /* Disable the error attention */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4016 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 4017 | return; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4018 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
| 4019 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4020 | phba->link_flag |= LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4021 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4022 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4023 | return; |
| 4024 | if (ha_copy & HA_ERATT) { |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4025 | /* Clear Chip error bit */ |
| 4026 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4027 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | mbox = 0; |
| 4031 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; |
| 4032 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; |
| 4033 | |
| 4034 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4035 | mbox_buf = phba->MBslimaddr; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4036 | writel(mbox, mbox_buf); |
| 4037 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4038 | for (i = 0; i < 50; i++) { |
| 4039 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4040 | return; |
| 4041 | if (resp_data != ~(BARRIER_TEST_PATTERN)) |
| 4042 | mdelay(1); |
| 4043 | else |
| 4044 | break; |
| 4045 | } |
| 4046 | resp_data = 0; |
| 4047 | if (lpfc_readl((resp_buf + 1), &resp_data)) |
| 4048 | return; |
| 4049 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4050 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4051 | phba->pport->stopped) |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4052 | goto restore_hc; |
| 4053 | else |
| 4054 | goto clear_errat; |
| 4055 | } |
| 4056 | |
| 4057 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4058 | resp_data = 0; |
| 4059 | for (i = 0; i < 500; i++) { |
| 4060 | if (lpfc_readl(resp_buf, &resp_data)) |
| 4061 | return; |
| 4062 | if (resp_data != mbox) |
| 4063 | mdelay(1); |
| 4064 | else |
| 4065 | break; |
| 4066 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4067 | |
| 4068 | clear_errat: |
| 4069 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4070 | while (++i < 500) { |
| 4071 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4072 | return; |
| 4073 | if (!(ha_copy & HA_ERATT)) |
| 4074 | mdelay(1); |
| 4075 | else |
| 4076 | break; |
| 4077 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4078 | |
| 4079 | if (readl(phba->HAregaddr) & HA_ERATT) { |
| 4080 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4081 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | restore_hc: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4085 | phba->link_flag &= ~LS_IGNORE_ERATT; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4086 | writel(hc_copy, phba->HCregaddr); |
| 4087 | readl(phba->HCregaddr); /* flush */ |
| 4088 | } |
| 4089 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4090 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4091 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4092 | * @phba: Pointer to HBA context object. |
| 4093 | * |
| 4094 | * This function issues a kill_board mailbox command and waits for |
| 4095 | * the error attention interrupt. This function is called for stopping |
| 4096 | * the firmware processing. The caller is not required to hold any |
| 4097 | * locks. This function calls lpfc_hba_down_post function to free |
| 4098 | * any pending commands after the kill. The function will return 1 when it |
| 4099 | * fails to kill the board else will return 0. |
| 4100 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4101 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4102 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4103 | { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4104 | struct lpfc_sli *psli; |
| 4105 | LPFC_MBOXQ_t *pmb; |
| 4106 | uint32_t status; |
| 4107 | uint32_t ha_copy; |
| 4108 | int retval; |
| 4109 | int i = 0; |
| 4110 | |
| 4111 | psli = &phba->sli; |
| 4112 | |
| 4113 | /* Kill HBA */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4114 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4115 | "0329 Kill HBA Data: x%x x%x\n", |
| 4116 | phba->pport->port_state, psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4117 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4118 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4119 | if (!pmb) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4120 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4121 | |
| 4122 | /* Disable the error attention */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4123 | spin_lock_irq(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4124 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 4125 | spin_unlock_irq(&phba->hbalock); |
| 4126 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4127 | return 1; |
| 4128 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4129 | status &= ~HC_ERINT_ENA; |
| 4130 | writel(status, phba->HCregaddr); |
| 4131 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4132 | phba->link_flag |= LS_IGNORE_ERATT; |
| 4133 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4134 | |
| 4135 | lpfc_kill_board(phba, pmb); |
| 4136 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 4137 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4138 | |
| 4139 | if (retval != MBX_SUCCESS) { |
| 4140 | if (retval != MBX_BUSY) |
| 4141 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4142 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4143 | "2752 KILL_BOARD command failed retval %d\n", |
| 4144 | retval); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4145 | spin_lock_irq(&phba->hbalock); |
| 4146 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4147 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4148 | return 1; |
| 4149 | } |
| 4150 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 4151 | spin_lock_irq(&phba->hbalock); |
| 4152 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 4153 | spin_unlock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4154 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4155 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4156 | |
| 4157 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error |
| 4158 | * attention every 100ms for 3 seconds. If we don't get ERATT after |
| 4159 | * 3 seconds we still set HBA_ERROR state because the status of the |
| 4160 | * board is now undefined. |
| 4161 | */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4162 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4163 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4164 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
| 4165 | mdelay(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4166 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 4167 | return 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4171 | if (ha_copy & HA_ERATT) { |
| 4172 | writel(HA_ERATT, phba->HAregaddr); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4173 | phba->pport->stopped = 1; |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4174 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4175 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4176 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4177 | psli->mbox_active = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4178 | phba->link_flag &= ~LS_IGNORE_ERATT; |
| 4179 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4180 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4181 | lpfc_hba_down_post(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4182 | phba->link_state = LPFC_HBA_ERROR; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4183 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4184 | return ha_copy & HA_ERATT ? 0 : 1; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4185 | } |
| 4186 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4187 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4188 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4189 | * @phba: Pointer to HBA context object. |
| 4190 | * |
| 4191 | * This function resets the HBA by writing HC_INITFF to the control |
| 4192 | * register. After the HBA resets, this function resets all the iocb ring |
| 4193 | * indices. This function disables PCI layer parity checking during |
| 4194 | * the reset. |
| 4195 | * This function returns 0 always. |
| 4196 | * The caller is not required to hold any locks. |
| 4197 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4198 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4199 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4200 | { |
| 4201 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4202 | struct lpfc_sli_ring *pring; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4203 | uint16_t cfg_value; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4204 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4205 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4206 | psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4207 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4208 | /* Reset HBA */ |
| 4209 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4210 | "0325 Reset HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4211 | (phba->pport) ? phba->pport->port_state : 0, |
| 4212 | psli->sli_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4213 | |
| 4214 | /* perform board reset */ |
| 4215 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4216 | phba->link_events = 0; |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4217 | if (phba->pport) { |
| 4218 | phba->pport->fc_myDID = 0; |
| 4219 | phba->pport->fc_prevDID = 0; |
| 4220 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4221 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4222 | /* Turn off parity checking and serr during the physical reset */ |
| 4223 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4224 | pci_write_config_word(phba->pcidev, PCI_COMMAND, |
| 4225 | (cfg_value & |
| 4226 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4227 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 4228 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
| 4229 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4230 | /* Now toggle INITFF bit in the Host Control Register */ |
| 4231 | writel(HC_INITFF, phba->HCregaddr); |
| 4232 | mdelay(1); |
| 4233 | readl(phba->HCregaddr); /* flush */ |
| 4234 | writel(0, phba->HCregaddr); |
| 4235 | readl(phba->HCregaddr); /* flush */ |
| 4236 | |
| 4237 | /* Restore PCI cmd register */ |
| 4238 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4239 | |
| 4240 | /* Initialize relevant SLI info */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4241 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4242 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4243 | pring->flag = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 4244 | pring->sli.sli3.rspidx = 0; |
| 4245 | pring->sli.sli3.next_cmdidx = 0; |
| 4246 | pring->sli.sli3.local_getidx = 0; |
| 4247 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4248 | pring->missbufcnt = 0; |
| 4249 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4250 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4251 | phba->link_state = LPFC_WARM_START; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4252 | return 0; |
| 4253 | } |
| 4254 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4255 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4256 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
| 4257 | * @phba: Pointer to HBA context object. |
| 4258 | * |
| 4259 | * This function resets a SLI4 HBA. This function disables PCI layer parity |
| 4260 | * checking during resets the device. The caller is not required to hold |
| 4261 | * any locks. |
| 4262 | * |
| 4263 | * This function returns 0 always. |
| 4264 | **/ |
| 4265 | int |
| 4266 | lpfc_sli4_brdreset(struct lpfc_hba *phba) |
| 4267 | { |
| 4268 | struct lpfc_sli *psli = &phba->sli; |
| 4269 | uint16_t cfg_value; |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4270 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4271 | |
| 4272 | /* Reset HBA */ |
| 4273 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4274 | "0295 Reset HBA Data: x%x x%x x%x\n", |
| 4275 | phba->pport->port_state, psli->sli_flag, |
| 4276 | phba->hba_flag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4277 | |
| 4278 | /* perform board reset */ |
| 4279 | phba->fc_eventTag = 0; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 4280 | phba->link_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4281 | phba->pport->fc_myDID = 0; |
| 4282 | phba->pport->fc_prevDID = 0; |
| 4283 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4284 | spin_lock_irq(&phba->hbalock); |
| 4285 | psli->sli_flag &= ~(LPFC_PROCESS_LA); |
| 4286 | phba->fcf.fcf_flag = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4287 | spin_unlock_irq(&phba->hbalock); |
| 4288 | |
James Smart | 0293635 | 2014-04-04 13:52:12 -0400 | [diff] [blame] | 4289 | /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */ |
| 4290 | if (phba->hba_flag & HBA_FW_DUMP_OP) { |
| 4291 | phba->hba_flag &= ~HBA_FW_DUMP_OP; |
| 4292 | return rc; |
| 4293 | } |
| 4294 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4295 | /* Now physically reset the device */ |
| 4296 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4297 | "0389 Performing PCI function reset!\n"); |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4298 | |
| 4299 | /* Turn off parity checking and serr during the physical reset */ |
| 4300 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); |
| 4301 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & |
| 4302 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
| 4303 | |
James Smart | 8831881 | 2012-09-29 11:29:29 -0400 | [diff] [blame] | 4304 | /* Perform FCoE PCI function reset before freeing queue memory */ |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4305 | rc = lpfc_pci_function_reset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4306 | |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 4307 | /* Restore PCI cmd register */ |
| 4308 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); |
| 4309 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4310 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4311 | } |
| 4312 | |
| 4313 | /** |
| 4314 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4315 | * @phba: Pointer to HBA context object. |
| 4316 | * |
| 4317 | * This function is called in the SLI initialization code path to |
| 4318 | * restart the HBA. The caller is not required to hold any lock. |
| 4319 | * This function writes MBX_RESTART mailbox command to the SLIM and |
| 4320 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post |
| 4321 | * function to free any pending commands. The function enables |
| 4322 | * POST only during the first initialization. The function returns zero. |
| 4323 | * The function does not guarantee completion of MBX_RESTART mailbox |
| 4324 | * command before the return of this function. |
| 4325 | **/ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4326 | static int |
| 4327 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4328 | { |
| 4329 | MAILBOX_t *mb; |
| 4330 | struct lpfc_sli *psli; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4331 | volatile uint32_t word0; |
| 4332 | void __iomem *to_slim; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4333 | uint32_t hba_aer_enabled; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4334 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4335 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4336 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4337 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4338 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4339 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4340 | psli = &phba->sli; |
| 4341 | |
| 4342 | /* Restart HBA */ |
| 4343 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4344 | "0337 Restart HBA Data: x%x x%x\n", |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4345 | (phba->pport) ? phba->pport->port_state : 0, |
| 4346 | psli->sli_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4347 | |
| 4348 | word0 = 0; |
| 4349 | mb = (MAILBOX_t *) &word0; |
| 4350 | mb->mbxCommand = MBX_RESTART; |
| 4351 | mb->mbxHc = 1; |
| 4352 | |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 4353 | lpfc_reset_barrier(phba); |
| 4354 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4355 | to_slim = phba->MBslimaddr; |
| 4356 | writel(*(uint32_t *) mb, to_slim); |
| 4357 | readl(to_slim); /* flush */ |
| 4358 | |
| 4359 | /* Only skip post after fc_ffinit is completed */ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4360 | if (phba->pport && phba->pport->port_state) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4361 | word0 = 1; /* This is really setting up word1 */ |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4362 | else |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4363 | word0 = 0; /* This is really setting up word1 */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 4364 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4365 | writel(*(uint32_t *) mb, to_slim); |
| 4366 | readl(to_slim); /* flush */ |
| 4367 | |
| 4368 | lpfc_sli_brdreset(phba); |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4369 | if (phba->pport) |
| 4370 | phba->pport->stopped = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4371 | phba->link_state = LPFC_INIT_START; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4372 | phba->hba_flag = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4373 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4374 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 4375 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4376 | psli->stats_start = get_seconds(); |
| 4377 | |
James Smart | eaf15d5 | 2008-12-04 22:39:29 -0500 | [diff] [blame] | 4378 | /* Give the INITFF and Post time to settle. */ |
| 4379 | mdelay(100); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4380 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4381 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4382 | if (hba_aer_enabled) |
| 4383 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4384 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4385 | lpfc_hba_down_post(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4386 | |
| 4387 | return 0; |
| 4388 | } |
| 4389 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4390 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4391 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba |
| 4392 | * @phba: Pointer to HBA context object. |
| 4393 | * |
| 4394 | * This function is called in the SLI initialization code path to restart |
| 4395 | * a SLI4 HBA. The caller is not required to hold any lock. |
| 4396 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 4397 | * free any pending commands. |
| 4398 | **/ |
| 4399 | static int |
| 4400 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) |
| 4401 | { |
| 4402 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4403 | uint32_t hba_aer_enabled; |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4404 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4405 | |
| 4406 | /* Restart HBA */ |
| 4407 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4408 | "0296 Restart HBA Data: x%x x%x\n", |
| 4409 | phba->pport->port_state, psli->sli_flag); |
| 4410 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4411 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
| 4412 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; |
| 4413 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4414 | rc = lpfc_sli4_brdreset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4415 | |
| 4416 | spin_lock_irq(&phba->hbalock); |
| 4417 | phba->pport->stopped = 0; |
| 4418 | phba->link_state = LPFC_INIT_START; |
| 4419 | phba->hba_flag = 0; |
| 4420 | spin_unlock_irq(&phba->hbalock); |
| 4421 | |
| 4422 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
| 4423 | psli->stats_start = get_seconds(); |
| 4424 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 4425 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
| 4426 | if (hba_aer_enabled) |
| 4427 | pci_disable_pcie_error_reporting(phba->pcidev); |
| 4428 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4429 | lpfc_hba_down_post(phba); |
James Smart | 569dbe8 | 2017-06-15 22:56:47 -0700 | [diff] [blame] | 4430 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4431 | |
James Smart | 27b01b8 | 2012-05-09 21:19:44 -0400 | [diff] [blame] | 4432 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4433 | } |
| 4434 | |
| 4435 | /** |
| 4436 | * lpfc_sli_brdrestart - Wrapper func for restarting hba |
| 4437 | * @phba: Pointer to HBA context object. |
| 4438 | * |
| 4439 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the |
| 4440 | * API jump table function pointer from the lpfc_hba struct. |
| 4441 | **/ |
| 4442 | int |
| 4443 | lpfc_sli_brdrestart(struct lpfc_hba *phba) |
| 4444 | { |
| 4445 | return phba->lpfc_sli_brdrestart(phba); |
| 4446 | } |
| 4447 | |
| 4448 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4449 | * 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] | 4450 | * @phba: Pointer to HBA context object. |
| 4451 | * |
| 4452 | * This function is called after a HBA restart to wait for successful |
| 4453 | * restart of the HBA. Successful restart of the HBA is indicated by |
| 4454 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 |
| 4455 | * iteration, the function will restart the HBA again. The function returns |
| 4456 | * zero if HBA successfully restarted else returns negative error code. |
| 4457 | **/ |
James Smart | 4492b73 | 2017-04-27 15:08:26 -0700 | [diff] [blame] | 4458 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4459 | lpfc_sli_chipset_init(struct lpfc_hba *phba) |
| 4460 | { |
| 4461 | uint32_t status, i = 0; |
| 4462 | |
| 4463 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4464 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4465 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4466 | |
| 4467 | /* Check status register to see what current state is */ |
| 4468 | i = 0; |
| 4469 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { |
| 4470 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4471 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
| 4472 | * retries, then every 1 sec for 50 retires for a total of |
| 4473 | * ~60 seconds before reset the board again and check every |
| 4474 | * 1 sec for 50 retries. The up to 60 seconds before the |
| 4475 | * board ready is required by the Falcon FIPS zeroization |
| 4476 | * complete, and any reset the board in between shall cause |
| 4477 | * restart of zeroization, further delay the board ready. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4478 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4479 | if (i++ >= 200) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4480 | /* Adapter failed to init, timeout, status reg |
| 4481 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4482 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4483 | "0436 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4484 | "timeout, status reg x%x, " |
| 4485 | "FW Data: A8 x%x AC x%x\n", status, |
| 4486 | readl(phba->MBslimaddr + 0xa8), |
| 4487 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4488 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4489 | return -ETIMEDOUT; |
| 4490 | } |
| 4491 | |
| 4492 | /* Check to see if any errors occurred during init */ |
| 4493 | if (status & HS_FFERM) { |
| 4494 | /* ERROR: During chipset initialization */ |
| 4495 | /* Adapter failed to init, chipset, status reg |
| 4496 | <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4497 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4498 | "0437 Adapter failed to init, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4499 | "chipset, status reg x%x, " |
| 4500 | "FW Data: A8 x%x AC x%x\n", status, |
| 4501 | readl(phba->MBslimaddr + 0xa8), |
| 4502 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4503 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4504 | return -EIO; |
| 4505 | } |
| 4506 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4507 | if (i <= 10) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4508 | msleep(10); |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4509 | else if (i <= 100) |
| 4510 | msleep(100); |
| 4511 | else |
| 4512 | msleep(1000); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4513 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 4514 | if (i == 150) { |
| 4515 | /* Do post */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4516 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4517 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4518 | } |
| 4519 | /* Read the HBA Host Status Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 4520 | if (lpfc_readl(phba->HSregaddr, &status)) |
| 4521 | return -EIO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | /* Check to see if any errors occurred during init */ |
| 4525 | if (status & HS_FFERM) { |
| 4526 | /* ERROR: During chipset initialization */ |
| 4527 | /* Adapter failed to init, chipset, status reg <status> */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4528 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4529 | "0438 Adapter failed to init, chipset, " |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4530 | "status reg x%x, " |
| 4531 | "FW Data: A8 x%x AC x%x\n", status, |
| 4532 | readl(phba->MBslimaddr + 0xa8), |
| 4533 | readl(phba->MBslimaddr + 0xac)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4534 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4535 | return -EIO; |
| 4536 | } |
| 4537 | |
| 4538 | /* Clear all interrupt enable conditions */ |
| 4539 | writel(0, phba->HCregaddr); |
| 4540 | readl(phba->HCregaddr); /* flush */ |
| 4541 | |
| 4542 | /* setup host attn register */ |
| 4543 | writel(0xffffffff, phba->HAregaddr); |
| 4544 | readl(phba->HAregaddr); /* flush */ |
| 4545 | return 0; |
| 4546 | } |
| 4547 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4548 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4549 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4550 | * |
| 4551 | * This function calculates and returns the number of HBQs required to be |
| 4552 | * configured. |
| 4553 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4554 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4555 | lpfc_sli_hbq_count(void) |
| 4556 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4557 | return ARRAY_SIZE(lpfc_hbq_defs); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4558 | } |
| 4559 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4560 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4561 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4562 | * |
| 4563 | * This function adds the number of hbq entries in every HBQ to get |
| 4564 | * the total number of hbq entries required for the HBA and returns |
| 4565 | * the total count. |
| 4566 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4567 | static int |
| 4568 | lpfc_sli_hbq_entry_count(void) |
| 4569 | { |
| 4570 | int hbq_count = lpfc_sli_hbq_count(); |
| 4571 | int count = 0; |
| 4572 | int i; |
| 4573 | |
| 4574 | for (i = 0; i < hbq_count; ++i) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4575 | count += lpfc_hbq_defs[i]->entry_count; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4576 | return count; |
| 4577 | } |
| 4578 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4579 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4580 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4581 | * |
| 4582 | * This function calculates amount of memory required for all hbq entries |
| 4583 | * to be configured and returns the total memory required. |
| 4584 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4585 | int |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4586 | lpfc_sli_hbq_size(void) |
| 4587 | { |
| 4588 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); |
| 4589 | } |
| 4590 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4591 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4592 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4593 | * @phba: Pointer to HBA context object. |
| 4594 | * |
| 4595 | * This function is called during the SLI initialization to configure |
| 4596 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4597 | * required to hold any locks. This function will return zero if successful |
| 4598 | * else it will return negative error code. |
| 4599 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4600 | static int |
| 4601 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) |
| 4602 | { |
| 4603 | int hbq_count = lpfc_sli_hbq_count(); |
| 4604 | LPFC_MBOXQ_t *pmb; |
| 4605 | MAILBOX_t *pmbox; |
| 4606 | uint32_t hbqno; |
| 4607 | uint32_t hbq_entry_index; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4608 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4609 | /* Get a Mailbox buffer to setup mailbox |
| 4610 | * commands for HBA initialization |
| 4611 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4612 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4613 | |
| 4614 | if (!pmb) |
| 4615 | return -ENOMEM; |
| 4616 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4617 | pmbox = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4618 | |
| 4619 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
| 4620 | phba->link_state = LPFC_INIT_MBX_CMDS; |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 4621 | phba->hbq_in_use = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4622 | |
| 4623 | hbq_entry_index = 0; |
| 4624 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { |
| 4625 | phba->hbqs[hbqno].next_hbqPutIdx = 0; |
| 4626 | phba->hbqs[hbqno].hbqPutIdx = 0; |
| 4627 | phba->hbqs[hbqno].local_hbqGetIdx = 0; |
| 4628 | phba->hbqs[hbqno].entry_count = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4629 | lpfc_hbq_defs[hbqno]->entry_count; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4630 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
| 4631 | hbq_entry_index, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4632 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
| 4633 | |
| 4634 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
| 4635 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, |
| 4636 | mbxStatus <status>, ring <num> */ |
| 4637 | |
| 4638 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4639 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4640 | "1805 Adapter failed to init. " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4641 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4642 | pmbox->mbxCommand, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4643 | pmbox->mbxStatus, hbqno); |
| 4644 | |
| 4645 | phba->link_state = LPFC_HBA_ERROR; |
| 4646 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4647 | return -ENXIO; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4648 | } |
| 4649 | } |
| 4650 | phba->hbq_count = hbq_count; |
| 4651 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4652 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4653 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4654 | /* Initially populate or replenish the HBQs */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4655 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
| 4656 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4657 | return 0; |
| 4658 | } |
| 4659 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4660 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4661 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA |
| 4662 | * @phba: Pointer to HBA context object. |
| 4663 | * |
| 4664 | * This function is called during the SLI initialization to configure |
| 4665 | * all the HBQs and post buffers to the HBQ. The caller is not |
| 4666 | * required to hold any locks. This function will return zero if successful |
| 4667 | * else it will return negative error code. |
| 4668 | **/ |
| 4669 | static int |
| 4670 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) |
| 4671 | { |
| 4672 | phba->hbq_in_use = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4673 | phba->hbqs[LPFC_ELS_HBQ].entry_count = |
| 4674 | lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4675 | phba->hbq_count = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4676 | lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4677 | /* Initially populate or replenish the HBQs */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 4678 | return 0; |
| 4679 | } |
| 4680 | |
| 4681 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4682 | * lpfc_sli_config_port - Issue config port mailbox command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4683 | * @phba: Pointer to HBA context object. |
| 4684 | * @sli_mode: sli mode - 2/3 |
| 4685 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4686 | * This function is called by the sli initialization code path |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4687 | * to issue config_port mailbox command. This function restarts the |
| 4688 | * HBA firmware and issues a config_port mailbox command to configure |
| 4689 | * the SLI interface in the sli mode specified by sli_mode |
| 4690 | * variable. The caller is not required to hold any locks. |
| 4691 | * The function returns 0 if successful, else returns negative error |
| 4692 | * code. |
| 4693 | **/ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4694 | int |
| 4695 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4696 | { |
| 4697 | LPFC_MBOXQ_t *pmb; |
| 4698 | uint32_t resetcount = 0, rc = 0, done = 0; |
| 4699 | |
| 4700 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4701 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4702 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4703 | return -ENOMEM; |
| 4704 | } |
| 4705 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4706 | phba->sli_rev = sli_mode; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4707 | while (resetcount < 2 && !done) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4708 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4709 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4710 | spin_unlock_irq(&phba->hbalock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4711 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4712 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4713 | rc = lpfc_sli_chipset_init(phba); |
| 4714 | if (rc) |
| 4715 | break; |
| 4716 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4717 | spin_lock_irq(&phba->hbalock); |
James Smart | 1c067a4 | 2006-08-01 07:33:52 -0400 | [diff] [blame] | 4718 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4719 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4720 | resetcount++; |
| 4721 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4722 | /* Call pre CONFIG_PORT mailbox command initialization. A |
| 4723 | * value of 0 means the call was successful. Any other |
| 4724 | * nonzero value is a failure, but if ERESTART is returned, |
| 4725 | * the driver may reset the HBA and try again. |
| 4726 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4727 | rc = lpfc_config_port_prep(phba); |
| 4728 | if (rc == -ERESTART) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4729 | phba->link_state = LPFC_LINK_UNKNOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4730 | continue; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4731 | } else if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4732 | break; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4733 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4734 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4735 | lpfc_config_port(phba, pmb); |
| 4736 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4737 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
| 4738 | LPFC_SLI3_HBQ_ENABLED | |
| 4739 | LPFC_SLI3_CRP_ENABLED | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4740 | LPFC_SLI3_BG_ENABLED | |
| 4741 | LPFC_SLI3_DSS_ENABLED); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4742 | if (rc != MBX_SUCCESS) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4743 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4744 | "0442 Adapter failed to init, mbxCmd x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4745 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4746 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4747 | spin_lock_irq(&phba->hbalock); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4748 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4749 | spin_unlock_irq(&phba->hbalock); |
| 4750 | rc = -ENXIO; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4751 | } else { |
| 4752 | /* Allow asynchronous mailbox command to go through */ |
| 4753 | spin_lock_irq(&phba->hbalock); |
| 4754 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 4755 | spin_unlock_irq(&phba->hbalock); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4756 | done = 1; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 4757 | |
| 4758 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && |
| 4759 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) |
| 4760 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 4761 | "3110 Port did not grant ASABT\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4762 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4763 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4764 | if (!done) { |
| 4765 | rc = -EINVAL; |
| 4766 | goto do_prep_failed; |
| 4767 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4768 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
| 4769 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4770 | rc = -ENXIO; |
| 4771 | goto do_prep_failed; |
| 4772 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4773 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4774 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4775 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
| 4776 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? |
| 4777 | phba->max_vpi : phba->max_vports; |
| 4778 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4779 | } else |
| 4780 | phba->max_vpi = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4781 | phba->fips_level = 0; |
| 4782 | phba->fips_spec_rev = 0; |
| 4783 | if (pmb->u.mb.un.varCfgPort.gdss) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4784 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 4785 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
| 4786 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; |
| 4787 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4788 | "2850 Security Crypto Active. FIPS x%d " |
| 4789 | "(Spec Rev: x%d)", |
| 4790 | phba->fips_level, phba->fips_spec_rev); |
| 4791 | } |
| 4792 | if (pmb->u.mb.un.varCfgPort.sec_err) { |
| 4793 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4794 | "2856 Config Port Security Crypto " |
| 4795 | "Error: x%x ", |
| 4796 | pmb->u.mb.un.varCfgPort.sec_err); |
| 4797 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4798 | if (pmb->u.mb.un.varCfgPort.gerbm) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4799 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4800 | if (pmb->u.mb.un.varCfgPort.gcrp) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4801 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 4802 | |
| 4803 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; |
| 4804 | phba->port_gp = phba->mbox->us.s3_pgp.port; |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4805 | |
| 4806 | if (phba->cfg_enable_bg) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4807 | if (pmb->u.mb.un.varCfgPort.gbg) |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4808 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 4809 | else |
| 4810 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4811 | "0443 Adapter did not grant " |
| 4812 | "BlockGuard\n"); |
| 4813 | } |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4814 | } else { |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 4815 | phba->hbq_get = NULL; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 4816 | phba->port_gp = phba->mbox->us.s2.port; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4817 | phba->max_vpi = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4818 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4819 | do_prep_failed: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4820 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4821 | return rc; |
| 4822 | } |
| 4823 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4824 | |
| 4825 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4826 | * lpfc_sli_hba_setup - SLI initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4827 | * @phba: Pointer to HBA context object. |
| 4828 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 4829 | * This function is the main SLI initialization function. This function |
| 4830 | * is called by the HBA initialization code, HBA reset code and HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4831 | * error attention handler code. Caller is not required to hold any |
| 4832 | * locks. This function issues config_port mailbox command to configure |
| 4833 | * the SLI, setup iocb rings and HBQ rings. In the end the function |
| 4834 | * calls the config_port_post function to issue init_link mailbox |
| 4835 | * command and to start the discovery. The function will return zero |
| 4836 | * if successful, else it will return negative error code. |
| 4837 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4838 | int |
| 4839 | lpfc_sli_hba_setup(struct lpfc_hba *phba) |
| 4840 | { |
| 4841 | uint32_t rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4842 | int mode = 3, i; |
| 4843 | int longs; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4844 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4845 | switch (phba->cfg_sli_mode) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4846 | case 2: |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4847 | if (phba->cfg_enable_npiv) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4848 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4849 | "1824 NPIV enabled: Override sli_mode " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4850 | "parameter (%d) to auto (0).\n", |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4851 | phba->cfg_sli_mode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4852 | break; |
| 4853 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4854 | mode = 2; |
| 4855 | break; |
| 4856 | case 0: |
| 4857 | case 3: |
| 4858 | break; |
| 4859 | default: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4860 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4861 | "1819 Unrecognized sli_mode parameter: %d.\n", |
| 4862 | phba->cfg_sli_mode); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4863 | |
| 4864 | break; |
| 4865 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 4866 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4867 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4868 | rc = lpfc_sli_config_port(phba, mode); |
| 4869 | |
James Smart | 12247e8 | 2016-07-06 12:36:09 -0700 | [diff] [blame] | 4870 | if (rc && phba->cfg_sli_mode == 3) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4871 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4872 | "1820 Unable to select SLI-3. " |
| 4873 | "Not supported by adapter.\n"); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4874 | if (rc && mode != 2) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4875 | rc = lpfc_sli_config_port(phba, 2); |
James Smart | 4597663f | 2016-07-06 12:36:01 -0700 | [diff] [blame] | 4876 | else if (rc && mode == 2) |
| 4877 | rc = lpfc_sli_config_port(phba, 3); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4878 | if (rc) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4879 | goto lpfc_sli_hba_setup_error; |
| 4880 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4881 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 4882 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 4883 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 4884 | if (!rc) { |
| 4885 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4886 | "2709 This device supports " |
| 4887 | "Advanced Error Reporting (AER)\n"); |
| 4888 | spin_lock_irq(&phba->hbalock); |
| 4889 | phba->hba_flag |= HBA_AER_ENABLED; |
| 4890 | spin_unlock_irq(&phba->hbalock); |
| 4891 | } else { |
| 4892 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 4893 | "2708 This device does not support " |
James Smart | b069d7e | 2013-05-31 17:04:36 -0400 | [diff] [blame] | 4894 | "Advanced Error Reporting (AER): %d\n", |
| 4895 | rc); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 4896 | phba->cfg_aer_support = 0; |
| 4897 | } |
| 4898 | } |
| 4899 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4900 | if (phba->sli_rev == 3) { |
| 4901 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; |
| 4902 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4903 | } else { |
| 4904 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; |
| 4905 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4906 | phba->sli3_options = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4907 | } |
| 4908 | |
| 4909 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4910 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
| 4911 | phba->sli_rev, phba->max_vpi); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4912 | rc = lpfc_sli_ring_map(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4913 | |
| 4914 | if (rc) |
| 4915 | goto lpfc_sli_hba_setup_error; |
| 4916 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 4917 | /* Initialize VPIs. */ |
| 4918 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4919 | /* |
| 4920 | * The VPI bitmask and physical ID array are allocated |
| 4921 | * and initialized once only - at driver load. A port |
| 4922 | * reset doesn't need to reinitialize this memory. |
| 4923 | */ |
| 4924 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { |
| 4925 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; |
| 4926 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), |
| 4927 | GFP_KERNEL); |
| 4928 | if (!phba->vpi_bmask) { |
| 4929 | rc = -ENOMEM; |
| 4930 | goto lpfc_sli_hba_setup_error; |
| 4931 | } |
| 4932 | |
| 4933 | phba->vpi_ids = kzalloc( |
| 4934 | (phba->max_vpi+1) * sizeof(uint16_t), |
| 4935 | GFP_KERNEL); |
| 4936 | if (!phba->vpi_ids) { |
| 4937 | kfree(phba->vpi_bmask); |
| 4938 | rc = -ENOMEM; |
| 4939 | goto lpfc_sli_hba_setup_error; |
| 4940 | } |
| 4941 | for (i = 0; i < phba->max_vpi; i++) |
| 4942 | phba->vpi_ids[i] = i; |
| 4943 | } |
| 4944 | } |
| 4945 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4946 | /* Init HBQs */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4947 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 4948 | rc = lpfc_sli_hbq_setup(phba); |
| 4949 | if (rc) |
| 4950 | goto lpfc_sli_hba_setup_error; |
| 4951 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4952 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4953 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 4954 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4955 | |
| 4956 | rc = lpfc_config_port_post(phba); |
| 4957 | if (rc) |
| 4958 | goto lpfc_sli_hba_setup_error; |
| 4959 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4960 | return rc; |
| 4961 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4962 | lpfc_sli_hba_setup_error: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4963 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 4964 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4965 | "0445 Firmware initialization failed\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4966 | return rc; |
| 4967 | } |
| 4968 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4969 | /** |
| 4970 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
| 4971 | * @phba: Pointer to HBA context object. |
| 4972 | * @mboxq: mailbox pointer. |
| 4973 | * This function issue a dump mailbox command to read config region |
| 4974 | * 23 and parse the records in the region and populate driver |
| 4975 | * data structure. |
| 4976 | **/ |
| 4977 | static int |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4978 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4979 | { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4980 | LPFC_MBOXQ_t *mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4981 | struct lpfc_dmabuf *mp; |
| 4982 | struct lpfc_mqe *mqe; |
| 4983 | uint32_t data_length; |
| 4984 | int rc; |
| 4985 | |
| 4986 | /* Program the default value of vlan_id and fc_map */ |
| 4987 | phba->valid_vlan = 0; |
| 4988 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 4989 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 4990 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 4991 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4992 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4993 | if (!mboxq) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4994 | return -ENOMEM; |
| 4995 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 4996 | mqe = &mboxq->u.mqe; |
| 4997 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { |
| 4998 | rc = -ENOMEM; |
| 4999 | goto out_free_mboxq; |
| 5000 | } |
| 5001 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5002 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 5003 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5004 | |
| 5005 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 5006 | "(%d):2571 Mailbox cmd x%x Status x%x " |
| 5007 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5008 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " |
| 5009 | "CQ: x%x x%x x%x x%x\n", |
| 5010 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 5011 | bf_get(lpfc_mqe_command, mqe), |
| 5012 | bf_get(lpfc_mqe_status, mqe), |
| 5013 | mqe->un.mb_words[0], mqe->un.mb_words[1], |
| 5014 | mqe->un.mb_words[2], mqe->un.mb_words[3], |
| 5015 | mqe->un.mb_words[4], mqe->un.mb_words[5], |
| 5016 | mqe->un.mb_words[6], mqe->un.mb_words[7], |
| 5017 | mqe->un.mb_words[8], mqe->un.mb_words[9], |
| 5018 | mqe->un.mb_words[10], mqe->un.mb_words[11], |
| 5019 | mqe->un.mb_words[12], mqe->un.mb_words[13], |
| 5020 | mqe->un.mb_words[14], mqe->un.mb_words[15], |
| 5021 | mqe->un.mb_words[16], mqe->un.mb_words[50], |
| 5022 | mboxq->mcqe.word0, |
| 5023 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 5024 | mboxq->mcqe.trailer); |
| 5025 | |
| 5026 | if (rc) { |
| 5027 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5028 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5029 | rc = -EIO; |
| 5030 | goto out_free_mboxq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5031 | } |
| 5032 | data_length = mqe->un.mb_words[5]; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 5033 | if (data_length > DMP_RGN23_SIZE) { |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5034 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5035 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5036 | rc = -EIO; |
| 5037 | goto out_free_mboxq; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 5038 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5039 | |
| 5040 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
| 5041 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 5042 | kfree(mp); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5043 | rc = 0; |
| 5044 | |
| 5045 | out_free_mboxq: |
| 5046 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5047 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | /** |
| 5051 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
| 5052 | * @phba: pointer to lpfc hba data structure. |
| 5053 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. |
| 5054 | * @vpd: pointer to the memory to hold resulting port vpd data. |
| 5055 | * @vpd_size: On input, the number of bytes allocated to @vpd. |
| 5056 | * On output, the number of data bytes in @vpd. |
| 5057 | * |
| 5058 | * This routine executes a READ_REV SLI4 mailbox command. In |
| 5059 | * addition, this routine gets the port vpd data. |
| 5060 | * |
| 5061 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5062 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 5063 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5064 | **/ |
| 5065 | static int |
| 5066 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 5067 | uint8_t *vpd, uint32_t *vpd_size) |
| 5068 | { |
| 5069 | int rc = 0; |
| 5070 | uint32_t dma_size; |
| 5071 | struct lpfc_dmabuf *dmabuf; |
| 5072 | struct lpfc_mqe *mqe; |
| 5073 | |
| 5074 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5075 | if (!dmabuf) |
| 5076 | return -ENOMEM; |
| 5077 | |
| 5078 | /* |
| 5079 | * Get a DMA buffer for the vpd data resulting from the READ_REV |
| 5080 | * mailbox command. |
| 5081 | */ |
| 5082 | dma_size = *vpd_size; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 5083 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size, |
| 5084 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5085 | if (!dmabuf->virt) { |
| 5086 | kfree(dmabuf); |
| 5087 | return -ENOMEM; |
| 5088 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5089 | |
| 5090 | /* |
| 5091 | * The SLI4 implementation of READ_REV conflicts at word1, |
| 5092 | * bits 31:16 and SLI4 adds vpd functionality not present |
| 5093 | * in SLI3. This code corrects the conflicts. |
| 5094 | */ |
| 5095 | lpfc_read_rev(phba, mboxq); |
| 5096 | mqe = &mboxq->u.mqe; |
| 5097 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); |
| 5098 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); |
| 5099 | mqe->un.read_rev.word1 &= 0x0000FFFF; |
| 5100 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); |
| 5101 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); |
| 5102 | |
| 5103 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5104 | if (rc) { |
| 5105 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5106 | dmabuf->virt, dmabuf->phys); |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 5107 | kfree(dmabuf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5108 | return -EIO; |
| 5109 | } |
| 5110 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5111 | /* |
| 5112 | * The available vpd length cannot be bigger than the |
| 5113 | * DMA buffer passed to the port. Catch the less than |
| 5114 | * case and update the caller's size. |
| 5115 | */ |
| 5116 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) |
| 5117 | *vpd_size = mqe->un.read_rev.avail_vpd_len; |
| 5118 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 5119 | memcpy(vpd, dmabuf->virt, *vpd_size); |
| 5120 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5121 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
| 5122 | dmabuf->virt, dmabuf->phys); |
| 5123 | kfree(dmabuf); |
| 5124 | return 0; |
| 5125 | } |
| 5126 | |
| 5127 | /** |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5128 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name |
| 5129 | * @phba: pointer to lpfc hba data structure. |
| 5130 | * |
| 5131 | * This routine retrieves SLI4 device physical port name this PCI function |
| 5132 | * is attached to. |
| 5133 | * |
| 5134 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5135 | * 0 - successful |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5136 | * otherwise - failed to retrieve physical port name |
| 5137 | **/ |
| 5138 | static int |
| 5139 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) |
| 5140 | { |
| 5141 | LPFC_MBOXQ_t *mboxq; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5142 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
| 5143 | struct lpfc_controller_attribute *cntl_attr; |
| 5144 | struct lpfc_mbx_get_port_name *get_port_name; |
| 5145 | void *virtaddr = NULL; |
| 5146 | uint32_t alloclen, reqlen; |
| 5147 | uint32_t shdr_status, shdr_add_status; |
| 5148 | union lpfc_sli4_cfg_shdr *shdr; |
| 5149 | char cport_name = 0; |
| 5150 | int rc; |
| 5151 | |
| 5152 | /* We assume nothing at this point */ |
| 5153 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5154 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; |
| 5155 | |
| 5156 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5157 | if (!mboxq) |
| 5158 | return -ENOMEM; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5159 | /* obtain link type and link number via READ_CONFIG */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5160 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
| 5161 | lpfc_sli4_read_config(phba); |
| 5162 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) |
| 5163 | goto retrieve_ppname; |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 5164 | |
| 5165 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ |
| 5166 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); |
| 5167 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5168 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, |
| 5169 | LPFC_SLI4_MBX_NEMBED); |
| 5170 | if (alloclen < reqlen) { |
| 5171 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5172 | "3084 Allocated DMA memory size (%d) is " |
| 5173 | "less than the requested DMA memory size " |
| 5174 | "(%d)\n", alloclen, reqlen); |
| 5175 | rc = -ENOMEM; |
| 5176 | goto out_free_mboxq; |
| 5177 | } |
| 5178 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5179 | virtaddr = mboxq->sge_array->addr[0]; |
| 5180 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; |
| 5181 | shdr = &mbx_cntl_attr->cfg_shdr; |
| 5182 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5183 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5184 | if (shdr_status || shdr_add_status || rc) { |
| 5185 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5186 | "3085 Mailbox x%x (x%x/x%x) failed, " |
| 5187 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5188 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5189 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5190 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5191 | rc, shdr_status, shdr_add_status); |
| 5192 | rc = -ENXIO; |
| 5193 | goto out_free_mboxq; |
| 5194 | } |
| 5195 | cntl_attr = &mbx_cntl_attr->cntl_attr; |
| 5196 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 5197 | phba->sli4_hba.lnk_info.lnk_tp = |
| 5198 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); |
| 5199 | phba->sli4_hba.lnk_info.lnk_no = |
| 5200 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); |
| 5201 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5202 | "3086 lnk_type:%d, lnk_numb:%d\n", |
| 5203 | phba->sli4_hba.lnk_info.lnk_tp, |
| 5204 | phba->sli4_hba.lnk_info.lnk_no); |
| 5205 | |
| 5206 | retrieve_ppname: |
| 5207 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5208 | LPFC_MBOX_OPCODE_GET_PORT_NAME, |
| 5209 | sizeof(struct lpfc_mbx_get_port_name) - |
| 5210 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 5211 | LPFC_SLI4_MBX_EMBED); |
| 5212 | get_port_name = &mboxq->u.mqe.un.get_port_name; |
| 5213 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; |
| 5214 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); |
| 5215 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, |
| 5216 | phba->sli4_hba.lnk_info.lnk_tp); |
| 5217 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 5218 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 5219 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 5220 | if (shdr_status || shdr_add_status || rc) { |
| 5221 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5222 | "3087 Mailbox x%x (x%x/x%x) failed: " |
| 5223 | "rc:x%x, status:x%x, add_status:x%x\n", |
| 5224 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 5225 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 5226 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
| 5227 | rc, shdr_status, shdr_add_status); |
| 5228 | rc = -ENXIO; |
| 5229 | goto out_free_mboxq; |
| 5230 | } |
| 5231 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5232 | case LPFC_LINK_NUMBER_0: |
| 5233 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, |
| 5234 | &get_port_name->u.response); |
| 5235 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5236 | break; |
| 5237 | case LPFC_LINK_NUMBER_1: |
| 5238 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, |
| 5239 | &get_port_name->u.response); |
| 5240 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5241 | break; |
| 5242 | case LPFC_LINK_NUMBER_2: |
| 5243 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, |
| 5244 | &get_port_name->u.response); |
| 5245 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5246 | break; |
| 5247 | case LPFC_LINK_NUMBER_3: |
| 5248 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, |
| 5249 | &get_port_name->u.response); |
| 5250 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; |
| 5251 | break; |
| 5252 | default: |
| 5253 | break; |
| 5254 | } |
| 5255 | |
| 5256 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { |
| 5257 | phba->Port[0] = cport_name; |
| 5258 | phba->Port[1] = '\0'; |
| 5259 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5260 | "3091 SLI get port name: %s\n", phba->Port); |
| 5261 | } |
| 5262 | |
| 5263 | out_free_mboxq: |
| 5264 | if (rc != MBX_TIMEOUT) { |
| 5265 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) |
| 5266 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 5267 | else |
| 5268 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 5269 | } |
| 5270 | return rc; |
| 5271 | } |
| 5272 | |
| 5273 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5274 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
| 5275 | * @phba: pointer to lpfc hba data structure. |
| 5276 | * |
| 5277 | * This routine is called to explicitly arm the SLI4 device's completion and |
| 5278 | * event queues |
| 5279 | **/ |
| 5280 | static void |
| 5281 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) |
| 5282 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5283 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5284 | |
| 5285 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); |
| 5286 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5287 | if (phba->sli4_hba.nvmels_cq) |
| 5288 | lpfc_sli4_cq_release(phba->sli4_hba.nvmels_cq, |
| 5289 | LPFC_QUEUE_REARM); |
| 5290 | |
| 5291 | if (phba->sli4_hba.fcp_cq) |
| 5292 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) |
| 5293 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[qidx], |
| 5294 | LPFC_QUEUE_REARM); |
| 5295 | |
| 5296 | if (phba->sli4_hba.nvme_cq) |
| 5297 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) |
| 5298 | lpfc_sli4_cq_release(phba->sli4_hba.nvme_cq[qidx], |
| 5299 | LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5300 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 5301 | if (phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5302 | lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM); |
| 5303 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5304 | if (phba->sli4_hba.hba_eq) |
| 5305 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) |
| 5306 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[qidx], |
| 5307 | LPFC_QUEUE_REARM); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5308 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 5309 | if (phba->nvmet_support) { |
| 5310 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) { |
| 5311 | lpfc_sli4_cq_release( |
| 5312 | phba->sli4_hba.nvmet_cqset[qidx], |
| 5313 | LPFC_QUEUE_REARM); |
| 5314 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 5315 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5316 | |
| 5317 | if (phba->cfg_fof) |
| 5318 | lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5322 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. |
| 5323 | * @phba: Pointer to HBA context object. |
| 5324 | * @type: The resource extent type. |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5325 | * @extnt_count: buffer to hold port available extent count. |
| 5326 | * @extnt_size: buffer to hold element count per extent. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5327 | * |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5328 | * This function calls the port and retrievs the number of available |
| 5329 | * extents and their size for a particular extent type. |
| 5330 | * |
| 5331 | * Returns: 0 if successful. Nonzero otherwise. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5332 | **/ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5333 | int |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5334 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
| 5335 | uint16_t *extnt_count, uint16_t *extnt_size) |
| 5336 | { |
| 5337 | int rc = 0; |
| 5338 | uint32_t length; |
| 5339 | uint32_t mbox_tmo; |
| 5340 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; |
| 5341 | LPFC_MBOXQ_t *mbox; |
| 5342 | |
| 5343 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5344 | if (!mbox) |
| 5345 | return -ENOMEM; |
| 5346 | |
| 5347 | /* Find out how many extents are available for this resource type */ |
| 5348 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - |
| 5349 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5350 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5351 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, |
| 5352 | length, LPFC_SLI4_MBX_EMBED); |
| 5353 | |
| 5354 | /* Send an extents count of 0 - the GET doesn't use it. */ |
| 5355 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5356 | LPFC_SLI4_MBX_EMBED); |
| 5357 | if (unlikely(rc)) { |
| 5358 | rc = -EIO; |
| 5359 | goto err_exit; |
| 5360 | } |
| 5361 | |
| 5362 | if (!phba->sli4_hba.intr_enable) |
| 5363 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5364 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5365 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5366 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5367 | } |
| 5368 | if (unlikely(rc)) { |
| 5369 | rc = -EIO; |
| 5370 | goto err_exit; |
| 5371 | } |
| 5372 | |
| 5373 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; |
| 5374 | if (bf_get(lpfc_mbox_hdr_status, |
| 5375 | &rsrc_info->header.cfg_shdr.response)) { |
| 5376 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5377 | "2930 Failed to get resource extents " |
| 5378 | "Status 0x%x Add'l Status 0x%x\n", |
| 5379 | bf_get(lpfc_mbox_hdr_status, |
| 5380 | &rsrc_info->header.cfg_shdr.response), |
| 5381 | bf_get(lpfc_mbox_hdr_add_status, |
| 5382 | &rsrc_info->header.cfg_shdr.response)); |
| 5383 | rc = -EIO; |
| 5384 | goto err_exit; |
| 5385 | } |
| 5386 | |
| 5387 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, |
| 5388 | &rsrc_info->u.rsp); |
| 5389 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, |
| 5390 | &rsrc_info->u.rsp); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5391 | |
| 5392 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5393 | "3162 Retrieved extents type-%d from port: count:%d, " |
| 5394 | "size:%d\n", type, *extnt_count, *extnt_size); |
| 5395 | |
| 5396 | err_exit: |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5397 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5398 | return rc; |
| 5399 | } |
| 5400 | |
| 5401 | /** |
| 5402 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. |
| 5403 | * @phba: Pointer to HBA context object. |
| 5404 | * @type: The extent type to check. |
| 5405 | * |
| 5406 | * This function reads the current available extents from the port and checks |
| 5407 | * if the extent count or extent size has changed since the last access. |
| 5408 | * Callers use this routine post port reset to understand if there is a |
| 5409 | * extent reprovisioning requirement. |
| 5410 | * |
| 5411 | * Returns: |
| 5412 | * -Error: error indicates problem. |
| 5413 | * 1: Extent count or size has changed. |
| 5414 | * 0: No changes. |
| 5415 | **/ |
| 5416 | static int |
| 5417 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) |
| 5418 | { |
| 5419 | uint16_t curr_ext_cnt, rsrc_ext_cnt; |
| 5420 | uint16_t size_diff, rsrc_ext_size; |
| 5421 | int rc = 0; |
| 5422 | struct lpfc_rsrc_blks *rsrc_entry; |
| 5423 | struct list_head *rsrc_blk_list = NULL; |
| 5424 | |
| 5425 | size_diff = 0; |
| 5426 | curr_ext_cnt = 0; |
| 5427 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5428 | &rsrc_ext_cnt, |
| 5429 | &rsrc_ext_size); |
| 5430 | if (unlikely(rc)) |
| 5431 | return -EIO; |
| 5432 | |
| 5433 | switch (type) { |
| 5434 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5435 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5436 | break; |
| 5437 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5438 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; |
| 5439 | break; |
| 5440 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5441 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5442 | break; |
| 5443 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5444 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5445 | break; |
| 5446 | default: |
| 5447 | break; |
| 5448 | } |
| 5449 | |
| 5450 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { |
| 5451 | curr_ext_cnt++; |
| 5452 | if (rsrc_entry->rsrc_size != rsrc_ext_size) |
| 5453 | size_diff++; |
| 5454 | } |
| 5455 | |
| 5456 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) |
| 5457 | rc = 1; |
| 5458 | |
| 5459 | return rc; |
| 5460 | } |
| 5461 | |
| 5462 | /** |
| 5463 | * lpfc_sli4_cfg_post_extnts - |
| 5464 | * @phba: Pointer to HBA context object. |
| 5465 | * @extnt_cnt - number of available extents. |
| 5466 | * @type - the extent type (rpi, xri, vfi, vpi). |
| 5467 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. |
| 5468 | * @mbox - pointer to the caller's allocated mailbox structure. |
| 5469 | * |
| 5470 | * This function executes the extents allocation request. It also |
| 5471 | * takes care of the amount of memory needed to allocate or get the |
| 5472 | * allocated extents. It is the caller's responsibility to evaluate |
| 5473 | * the response. |
| 5474 | * |
| 5475 | * Returns: |
| 5476 | * -Error: Error value describes the condition found. |
| 5477 | * 0: if successful |
| 5478 | **/ |
| 5479 | static int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5480 | 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] | 5481 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
| 5482 | { |
| 5483 | int rc = 0; |
| 5484 | uint32_t req_len; |
| 5485 | uint32_t emb_len; |
| 5486 | uint32_t alloc_len, mbox_tmo; |
| 5487 | |
| 5488 | /* Calculate the total requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5489 | req_len = extnt_cnt * sizeof(uint16_t); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5490 | |
| 5491 | /* |
| 5492 | * Calculate the size of an embedded mailbox. The uint32_t |
| 5493 | * accounts for extents-specific word. |
| 5494 | */ |
| 5495 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 5496 | sizeof(uint32_t); |
| 5497 | |
| 5498 | /* |
| 5499 | * Presume the allocation and response will fit into an embedded |
| 5500 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 5501 | */ |
| 5502 | *emb = LPFC_SLI4_MBX_EMBED; |
| 5503 | if (req_len > emb_len) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5504 | req_len = extnt_cnt * sizeof(uint16_t) + |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5505 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 5506 | sizeof(uint32_t); |
| 5507 | *emb = LPFC_SLI4_MBX_NEMBED; |
| 5508 | } |
| 5509 | |
| 5510 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5511 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, |
| 5512 | req_len, *emb); |
| 5513 | if (alloc_len < req_len) { |
| 5514 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 5515 | "2982 Allocated DMA memory size (x%x) is " |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5516 | "less than the requested DMA memory " |
| 5517 | "size (x%x)\n", alloc_len, req_len); |
| 5518 | return -ENOMEM; |
| 5519 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5520 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5521 | if (unlikely(rc)) |
| 5522 | return -EIO; |
| 5523 | |
| 5524 | if (!phba->sli4_hba.intr_enable) |
| 5525 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5526 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5527 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5528 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5529 | } |
| 5530 | |
| 5531 | if (unlikely(rc)) |
| 5532 | rc = -EIO; |
| 5533 | return rc; |
| 5534 | } |
| 5535 | |
| 5536 | /** |
| 5537 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. |
| 5538 | * @phba: Pointer to HBA context object. |
| 5539 | * @type: The resource extent type to allocate. |
| 5540 | * |
| 5541 | * This function allocates the number of elements for the specified |
| 5542 | * resource type. |
| 5543 | **/ |
| 5544 | static int |
| 5545 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5546 | { |
| 5547 | bool emb = false; |
| 5548 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; |
| 5549 | uint16_t rsrc_id, rsrc_start, j, k; |
| 5550 | uint16_t *ids; |
| 5551 | int i, rc; |
| 5552 | unsigned long longs; |
| 5553 | unsigned long *bmask; |
| 5554 | struct lpfc_rsrc_blks *rsrc_blks; |
| 5555 | LPFC_MBOXQ_t *mbox; |
| 5556 | uint32_t length; |
| 5557 | struct lpfc_id_range *id_array = NULL; |
| 5558 | void *virtaddr = NULL; |
| 5559 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 5560 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 5561 | struct list_head *ext_blk_list; |
| 5562 | |
| 5563 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, |
| 5564 | &rsrc_cnt, |
| 5565 | &rsrc_size); |
| 5566 | if (unlikely(rc)) |
| 5567 | return -EIO; |
| 5568 | |
| 5569 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { |
| 5570 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5571 | "3009 No available Resource Extents " |
| 5572 | "for resource type 0x%x: Count: 0x%x, " |
| 5573 | "Size 0x%x\n", type, rsrc_cnt, |
| 5574 | rsrc_size); |
| 5575 | return -ENOMEM; |
| 5576 | } |
| 5577 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5578 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
| 5579 | "2903 Post resource extents type-0x%x: " |
| 5580 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5581 | |
| 5582 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5583 | if (!mbox) |
| 5584 | return -ENOMEM; |
| 5585 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5586 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5587 | if (unlikely(rc)) { |
| 5588 | rc = -EIO; |
| 5589 | goto err_exit; |
| 5590 | } |
| 5591 | |
| 5592 | /* |
| 5593 | * Figure out where the response is located. Then get local pointers |
| 5594 | * to the response data. The port does not guarantee to respond to |
| 5595 | * all extents counts request so update the local variable with the |
| 5596 | * allocated count from the port. |
| 5597 | */ |
| 5598 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 5599 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 5600 | id_array = &rsrc_ext->u.rsp.id[0]; |
| 5601 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 5602 | } else { |
| 5603 | virtaddr = mbox->sge_array->addr[0]; |
| 5604 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 5605 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 5606 | id_array = &n_rsrc->id; |
| 5607 | } |
| 5608 | |
| 5609 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 5610 | rsrc_id_cnt = rsrc_cnt * rsrc_size; |
| 5611 | |
| 5612 | /* |
| 5613 | * Based on the resource size and count, correct the base and max |
| 5614 | * resource values. |
| 5615 | */ |
| 5616 | length = sizeof(struct lpfc_rsrc_blks); |
| 5617 | switch (type) { |
| 5618 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5619 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 5620 | sizeof(unsigned long), |
| 5621 | GFP_KERNEL); |
| 5622 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 5623 | rc = -ENOMEM; |
| 5624 | goto err_exit; |
| 5625 | } |
| 5626 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * |
| 5627 | sizeof(uint16_t), |
| 5628 | GFP_KERNEL); |
| 5629 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 5630 | kfree(phba->sli4_hba.rpi_bmask); |
| 5631 | rc = -ENOMEM; |
| 5632 | goto err_exit; |
| 5633 | } |
| 5634 | |
| 5635 | /* |
| 5636 | * The next_rpi was initialized with the maximum available |
| 5637 | * count but the port may allocate a smaller number. Catch |
| 5638 | * that case and update the next_rpi. |
| 5639 | */ |
| 5640 | phba->sli4_hba.next_rpi = rsrc_id_cnt; |
| 5641 | |
| 5642 | /* Initialize local ptrs for common extent processing later. */ |
| 5643 | bmask = phba->sli4_hba.rpi_bmask; |
| 5644 | ids = phba->sli4_hba.rpi_ids; |
| 5645 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 5646 | break; |
| 5647 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5648 | phba->vpi_bmask = kzalloc(longs * |
| 5649 | sizeof(unsigned long), |
| 5650 | GFP_KERNEL); |
| 5651 | if (unlikely(!phba->vpi_bmask)) { |
| 5652 | rc = -ENOMEM; |
| 5653 | goto err_exit; |
| 5654 | } |
| 5655 | phba->vpi_ids = kzalloc(rsrc_id_cnt * |
| 5656 | sizeof(uint16_t), |
| 5657 | GFP_KERNEL); |
| 5658 | if (unlikely(!phba->vpi_ids)) { |
| 5659 | kfree(phba->vpi_bmask); |
| 5660 | rc = -ENOMEM; |
| 5661 | goto err_exit; |
| 5662 | } |
| 5663 | |
| 5664 | /* Initialize local ptrs for common extent processing later. */ |
| 5665 | bmask = phba->vpi_bmask; |
| 5666 | ids = phba->vpi_ids; |
| 5667 | ext_blk_list = &phba->lpfc_vpi_blk_list; |
| 5668 | break; |
| 5669 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5670 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 5671 | sizeof(unsigned long), |
| 5672 | GFP_KERNEL); |
| 5673 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 5674 | rc = -ENOMEM; |
| 5675 | goto err_exit; |
| 5676 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 5677 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5678 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
| 5679 | sizeof(uint16_t), |
| 5680 | GFP_KERNEL); |
| 5681 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 5682 | kfree(phba->sli4_hba.xri_bmask); |
| 5683 | rc = -ENOMEM; |
| 5684 | goto err_exit; |
| 5685 | } |
| 5686 | |
| 5687 | /* Initialize local ptrs for common extent processing later. */ |
| 5688 | bmask = phba->sli4_hba.xri_bmask; |
| 5689 | ids = phba->sli4_hba.xri_ids; |
| 5690 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; |
| 5691 | break; |
| 5692 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5693 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 5694 | sizeof(unsigned long), |
| 5695 | GFP_KERNEL); |
| 5696 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 5697 | rc = -ENOMEM; |
| 5698 | goto err_exit; |
| 5699 | } |
| 5700 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * |
| 5701 | sizeof(uint16_t), |
| 5702 | GFP_KERNEL); |
| 5703 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 5704 | kfree(phba->sli4_hba.vfi_bmask); |
| 5705 | rc = -ENOMEM; |
| 5706 | goto err_exit; |
| 5707 | } |
| 5708 | |
| 5709 | /* Initialize local ptrs for common extent processing later. */ |
| 5710 | bmask = phba->sli4_hba.vfi_bmask; |
| 5711 | ids = phba->sli4_hba.vfi_ids; |
| 5712 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 5713 | break; |
| 5714 | default: |
| 5715 | /* Unsupported Opcode. Fail call. */ |
| 5716 | id_array = NULL; |
| 5717 | bmask = NULL; |
| 5718 | ids = NULL; |
| 5719 | ext_blk_list = NULL; |
| 5720 | goto err_exit; |
| 5721 | } |
| 5722 | |
| 5723 | /* |
| 5724 | * Complete initializing the extent configuration with the |
| 5725 | * allocated ids assigned to this function. The bitmask serves |
| 5726 | * as an index into the array and manages the available ids. The |
| 5727 | * array just stores the ids communicated to the port via the wqes. |
| 5728 | */ |
| 5729 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { |
| 5730 | if ((i % 2) == 0) |
| 5731 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, |
| 5732 | &id_array[k]); |
| 5733 | else |
| 5734 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, |
| 5735 | &id_array[k]); |
| 5736 | |
| 5737 | rsrc_blks = kzalloc(length, GFP_KERNEL); |
| 5738 | if (unlikely(!rsrc_blks)) { |
| 5739 | rc = -ENOMEM; |
| 5740 | kfree(bmask); |
| 5741 | kfree(ids); |
| 5742 | goto err_exit; |
| 5743 | } |
| 5744 | rsrc_blks->rsrc_start = rsrc_id; |
| 5745 | rsrc_blks->rsrc_size = rsrc_size; |
| 5746 | list_add_tail(&rsrc_blks->list, ext_blk_list); |
| 5747 | rsrc_start = rsrc_id; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5748 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5749 | phba->sli4_hba.scsi_xri_start = rsrc_start + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5750 | lpfc_sli4_get_iocb_cnt(phba); |
| 5751 | phba->sli4_hba.nvme_xri_start = |
| 5752 | phba->sli4_hba.scsi_xri_start + |
| 5753 | phba->sli4_hba.scsi_xri_max; |
| 5754 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5755 | |
| 5756 | while (rsrc_id < (rsrc_start + rsrc_size)) { |
| 5757 | ids[j] = rsrc_id; |
| 5758 | rsrc_id++; |
| 5759 | j++; |
| 5760 | } |
| 5761 | /* Entire word processed. Get next word.*/ |
| 5762 | if ((i % 2) == 1) |
| 5763 | k++; |
| 5764 | } |
| 5765 | err_exit: |
| 5766 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 5767 | return rc; |
| 5768 | } |
| 5769 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5770 | |
| 5771 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5772 | /** |
| 5773 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. |
| 5774 | * @phba: Pointer to HBA context object. |
| 5775 | * @type: the extent's type. |
| 5776 | * |
| 5777 | * This function deallocates all extents of a particular resource type. |
| 5778 | * SLI4 does not allow for deallocating a particular extent range. It |
| 5779 | * is the caller's responsibility to release all kernel memory resources. |
| 5780 | **/ |
| 5781 | static int |
| 5782 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) |
| 5783 | { |
| 5784 | int rc; |
| 5785 | uint32_t length, mbox_tmo = 0; |
| 5786 | LPFC_MBOXQ_t *mbox; |
| 5787 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; |
| 5788 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; |
| 5789 | |
| 5790 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5791 | if (!mbox) |
| 5792 | return -ENOMEM; |
| 5793 | |
| 5794 | /* |
| 5795 | * This function sends an embedded mailbox because it only sends the |
| 5796 | * the resource type. All extents of this type are released by the |
| 5797 | * port. |
| 5798 | */ |
| 5799 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - |
| 5800 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 5801 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5802 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, |
| 5803 | length, LPFC_SLI4_MBX_EMBED); |
| 5804 | |
| 5805 | /* Send an extents count of 0 - the dealloc doesn't use it. */ |
| 5806 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, |
| 5807 | LPFC_SLI4_MBX_EMBED); |
| 5808 | if (unlikely(rc)) { |
| 5809 | rc = -EIO; |
| 5810 | goto out_free_mbox; |
| 5811 | } |
| 5812 | if (!phba->sli4_hba.intr_enable) |
| 5813 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 5814 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 5815 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5816 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 5817 | } |
| 5818 | if (unlikely(rc)) { |
| 5819 | rc = -EIO; |
| 5820 | goto out_free_mbox; |
| 5821 | } |
| 5822 | |
| 5823 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; |
| 5824 | if (bf_get(lpfc_mbox_hdr_status, |
| 5825 | &dealloc_rsrc->header.cfg_shdr.response)) { |
| 5826 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 5827 | "2919 Failed to release resource extents " |
| 5828 | "for type %d - Status 0x%x Add'l Status 0x%x. " |
| 5829 | "Resource memory not released.\n", |
| 5830 | type, |
| 5831 | bf_get(lpfc_mbox_hdr_status, |
| 5832 | &dealloc_rsrc->header.cfg_shdr.response), |
| 5833 | bf_get(lpfc_mbox_hdr_add_status, |
| 5834 | &dealloc_rsrc->header.cfg_shdr.response)); |
| 5835 | rc = -EIO; |
| 5836 | goto out_free_mbox; |
| 5837 | } |
| 5838 | |
| 5839 | /* Release kernel memory resources for the specific type. */ |
| 5840 | switch (type) { |
| 5841 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 5842 | kfree(phba->vpi_bmask); |
| 5843 | kfree(phba->vpi_ids); |
| 5844 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5845 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5846 | &phba->lpfc_vpi_blk_list, list) { |
| 5847 | list_del_init(&rsrc_blk->list); |
| 5848 | kfree(rsrc_blk); |
| 5849 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 5850 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5851 | break; |
| 5852 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 5853 | kfree(phba->sli4_hba.xri_bmask); |
| 5854 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5855 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5856 | &phba->sli4_hba.lpfc_xri_blk_list, list) { |
| 5857 | list_del_init(&rsrc_blk->list); |
| 5858 | kfree(rsrc_blk); |
| 5859 | } |
| 5860 | break; |
| 5861 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 5862 | kfree(phba->sli4_hba.vfi_bmask); |
| 5863 | kfree(phba->sli4_hba.vfi_ids); |
| 5864 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5865 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5866 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { |
| 5867 | list_del_init(&rsrc_blk->list); |
| 5868 | kfree(rsrc_blk); |
| 5869 | } |
| 5870 | break; |
| 5871 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 5872 | /* RPI bitmask and physical id array are cleaned up earlier. */ |
| 5873 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
| 5874 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { |
| 5875 | list_del_init(&rsrc_blk->list); |
| 5876 | kfree(rsrc_blk); |
| 5877 | } |
| 5878 | break; |
| 5879 | default: |
| 5880 | break; |
| 5881 | } |
| 5882 | |
| 5883 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 5884 | |
| 5885 | out_free_mbox: |
| 5886 | mempool_free(mbox, phba->mbox_mem_pool); |
| 5887 | return rc; |
| 5888 | } |
| 5889 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 5890 | static void |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5891 | lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox, |
| 5892 | uint32_t feature) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5893 | { |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5894 | uint32_t len; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5895 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5896 | len = sizeof(struct lpfc_mbx_set_feature) - |
| 5897 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 5898 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 5899 | LPFC_MBOX_OPCODE_SET_FEATURES, len, |
| 5900 | LPFC_SLI4_MBX_EMBED); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5901 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5902 | switch (feature) { |
| 5903 | case LPFC_SET_UE_RECOVERY: |
| 5904 | bf_set(lpfc_mbx_set_feature_UER, |
| 5905 | &mbox->u.mqe.un.set_feature, 1); |
| 5906 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY; |
| 5907 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 5908 | break; |
| 5909 | case LPFC_SET_MDS_DIAGS: |
| 5910 | bf_set(lpfc_mbx_set_feature_mds, |
| 5911 | &mbox->u.mqe.un.set_feature, 1); |
| 5912 | bf_set(lpfc_mbx_set_feature_mds_deep_loopbk, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 5913 | &mbox->u.mqe.un.set_feature, 1); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5914 | mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS; |
| 5915 | mbox->u.mqe.un.set_feature.param_len = 8; |
| 5916 | break; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5917 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5918 | |
| 5919 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 5920 | } |
| 5921 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5922 | /** |
| 5923 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. |
| 5924 | * @phba: Pointer to HBA context object. |
| 5925 | * |
| 5926 | * This function allocates all SLI4 resource identifiers. |
| 5927 | **/ |
| 5928 | int |
| 5929 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) |
| 5930 | { |
| 5931 | int i, rc, error = 0; |
| 5932 | uint16_t count, base; |
| 5933 | unsigned long longs; |
| 5934 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 5935 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 5936 | 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] | 5937 | if (phba->sli4_hba.extents_in_use) { |
| 5938 | /* |
| 5939 | * The port supports resource extents. The XRI, VPI, VFI, RPI |
| 5940 | * resource extent count must be read and allocated before |
| 5941 | * provisioning the resource id arrays. |
| 5942 | */ |
| 5943 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
| 5944 | LPFC_IDX_RSRC_RDY) { |
| 5945 | /* |
| 5946 | * Extent-based resources are set - the driver could |
| 5947 | * be in a port reset. Figure out if any corrective |
| 5948 | * actions need to be taken. |
| 5949 | */ |
| 5950 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5951 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5952 | if (rc != 0) |
| 5953 | error++; |
| 5954 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5955 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5956 | if (rc != 0) |
| 5957 | error++; |
| 5958 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5959 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5960 | if (rc != 0) |
| 5961 | error++; |
| 5962 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, |
| 5963 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5964 | if (rc != 0) |
| 5965 | error++; |
| 5966 | |
| 5967 | /* |
| 5968 | * It's possible that the number of resources |
| 5969 | * provided to this port instance changed between |
| 5970 | * resets. Detect this condition and reallocate |
| 5971 | * resources. Otherwise, there is no action. |
| 5972 | */ |
| 5973 | if (error) { |
| 5974 | lpfc_printf_log(phba, KERN_INFO, |
| 5975 | LOG_MBOX | LOG_INIT, |
| 5976 | "2931 Detected extent resource " |
| 5977 | "change. Reallocating all " |
| 5978 | "extents.\n"); |
| 5979 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5980 | LPFC_RSC_TYPE_FCOE_VFI); |
| 5981 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5982 | LPFC_RSC_TYPE_FCOE_VPI); |
| 5983 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5984 | LPFC_RSC_TYPE_FCOE_XRI); |
| 5985 | rc = lpfc_sli4_dealloc_extent(phba, |
| 5986 | LPFC_RSC_TYPE_FCOE_RPI); |
| 5987 | } else |
| 5988 | return 0; |
| 5989 | } |
| 5990 | |
| 5991 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 5992 | if (unlikely(rc)) |
| 5993 | goto err_exit; |
| 5994 | |
| 5995 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 5996 | if (unlikely(rc)) |
| 5997 | goto err_exit; |
| 5998 | |
| 5999 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6000 | if (unlikely(rc)) |
| 6001 | goto err_exit; |
| 6002 | |
| 6003 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6004 | if (unlikely(rc)) |
| 6005 | goto err_exit; |
| 6006 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6007 | LPFC_IDX_RSRC_RDY); |
| 6008 | return rc; |
| 6009 | } else { |
| 6010 | /* |
| 6011 | * The port does not support resource extents. The XRI, VPI, |
| 6012 | * VFI, RPI resource ids were determined from READ_CONFIG. |
| 6013 | * Just allocate the bitmasks and provision the resource id |
| 6014 | * arrays. If a port reset is active, the resources don't |
| 6015 | * need any action - just exit. |
| 6016 | */ |
| 6017 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6018 | LPFC_IDX_RSRC_RDY) { |
| 6019 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6020 | lpfc_sli4_remove_rpis(phba); |
| 6021 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6022 | /* RPIs. */ |
| 6023 | count = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6024 | if (count <= 0) { |
| 6025 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6026 | "3279 Invalid provisioning of " |
| 6027 | "rpi:%d\n", count); |
| 6028 | rc = -EINVAL; |
| 6029 | goto err_exit; |
| 6030 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6031 | base = phba->sli4_hba.max_cfg_param.rpi_base; |
| 6032 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6033 | phba->sli4_hba.rpi_bmask = kzalloc(longs * |
| 6034 | sizeof(unsigned long), |
| 6035 | GFP_KERNEL); |
| 6036 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { |
| 6037 | rc = -ENOMEM; |
| 6038 | goto err_exit; |
| 6039 | } |
| 6040 | phba->sli4_hba.rpi_ids = kzalloc(count * |
| 6041 | sizeof(uint16_t), |
| 6042 | GFP_KERNEL); |
| 6043 | if (unlikely(!phba->sli4_hba.rpi_ids)) { |
| 6044 | rc = -ENOMEM; |
| 6045 | goto free_rpi_bmask; |
| 6046 | } |
| 6047 | |
| 6048 | for (i = 0; i < count; i++) |
| 6049 | phba->sli4_hba.rpi_ids[i] = base + i; |
| 6050 | |
| 6051 | /* VPIs. */ |
| 6052 | count = phba->sli4_hba.max_cfg_param.max_vpi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6053 | if (count <= 0) { |
| 6054 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6055 | "3280 Invalid provisioning of " |
| 6056 | "vpi:%d\n", count); |
| 6057 | rc = -EINVAL; |
| 6058 | goto free_rpi_ids; |
| 6059 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6060 | base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 6061 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6062 | phba->vpi_bmask = kzalloc(longs * |
| 6063 | sizeof(unsigned long), |
| 6064 | GFP_KERNEL); |
| 6065 | if (unlikely(!phba->vpi_bmask)) { |
| 6066 | rc = -ENOMEM; |
| 6067 | goto free_rpi_ids; |
| 6068 | } |
| 6069 | phba->vpi_ids = kzalloc(count * |
| 6070 | sizeof(uint16_t), |
| 6071 | GFP_KERNEL); |
| 6072 | if (unlikely(!phba->vpi_ids)) { |
| 6073 | rc = -ENOMEM; |
| 6074 | goto free_vpi_bmask; |
| 6075 | } |
| 6076 | |
| 6077 | for (i = 0; i < count; i++) |
| 6078 | phba->vpi_ids[i] = base + i; |
| 6079 | |
| 6080 | /* XRIs. */ |
| 6081 | count = phba->sli4_hba.max_cfg_param.max_xri; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6082 | if (count <= 0) { |
| 6083 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6084 | "3281 Invalid provisioning of " |
| 6085 | "xri:%d\n", count); |
| 6086 | rc = -EINVAL; |
| 6087 | goto free_vpi_ids; |
| 6088 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6089 | base = phba->sli4_hba.max_cfg_param.xri_base; |
| 6090 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6091 | phba->sli4_hba.xri_bmask = kzalloc(longs * |
| 6092 | sizeof(unsigned long), |
| 6093 | GFP_KERNEL); |
| 6094 | if (unlikely(!phba->sli4_hba.xri_bmask)) { |
| 6095 | rc = -ENOMEM; |
| 6096 | goto free_vpi_ids; |
| 6097 | } |
James Smart | 41899be | 2012-03-01 22:34:19 -0500 | [diff] [blame] | 6098 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6099 | phba->sli4_hba.xri_ids = kzalloc(count * |
| 6100 | sizeof(uint16_t), |
| 6101 | GFP_KERNEL); |
| 6102 | if (unlikely(!phba->sli4_hba.xri_ids)) { |
| 6103 | rc = -ENOMEM; |
| 6104 | goto free_xri_bmask; |
| 6105 | } |
| 6106 | |
| 6107 | for (i = 0; i < count; i++) |
| 6108 | phba->sli4_hba.xri_ids[i] = base + i; |
| 6109 | |
| 6110 | /* VFIs. */ |
| 6111 | count = phba->sli4_hba.max_cfg_param.max_vfi; |
James Smart | 0a630c2 | 2013-01-03 15:44:09 -0500 | [diff] [blame] | 6112 | if (count <= 0) { |
| 6113 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6114 | "3282 Invalid provisioning of " |
| 6115 | "vfi:%d\n", count); |
| 6116 | rc = -EINVAL; |
| 6117 | goto free_xri_ids; |
| 6118 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6119 | base = phba->sli4_hba.max_cfg_param.vfi_base; |
| 6120 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; |
| 6121 | phba->sli4_hba.vfi_bmask = kzalloc(longs * |
| 6122 | sizeof(unsigned long), |
| 6123 | GFP_KERNEL); |
| 6124 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { |
| 6125 | rc = -ENOMEM; |
| 6126 | goto free_xri_ids; |
| 6127 | } |
| 6128 | phba->sli4_hba.vfi_ids = kzalloc(count * |
| 6129 | sizeof(uint16_t), |
| 6130 | GFP_KERNEL); |
| 6131 | if (unlikely(!phba->sli4_hba.vfi_ids)) { |
| 6132 | rc = -ENOMEM; |
| 6133 | goto free_vfi_bmask; |
| 6134 | } |
| 6135 | |
| 6136 | for (i = 0; i < count; i++) |
| 6137 | phba->sli4_hba.vfi_ids[i] = base + i; |
| 6138 | |
| 6139 | /* |
| 6140 | * Mark all resources ready. An HBA reset doesn't need |
| 6141 | * to reset the initialization. |
| 6142 | */ |
| 6143 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 6144 | LPFC_IDX_RSRC_RDY); |
| 6145 | return 0; |
| 6146 | } |
| 6147 | |
| 6148 | free_vfi_bmask: |
| 6149 | kfree(phba->sli4_hba.vfi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6150 | phba->sli4_hba.vfi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6151 | free_xri_ids: |
| 6152 | kfree(phba->sli4_hba.xri_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6153 | phba->sli4_hba.xri_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6154 | free_xri_bmask: |
| 6155 | kfree(phba->sli4_hba.xri_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6156 | phba->sli4_hba.xri_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6157 | free_vpi_ids: |
| 6158 | kfree(phba->vpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6159 | phba->vpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6160 | free_vpi_bmask: |
| 6161 | kfree(phba->vpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6162 | phba->vpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6163 | free_rpi_ids: |
| 6164 | kfree(phba->sli4_hba.rpi_ids); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6165 | phba->sli4_hba.rpi_ids = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6166 | free_rpi_bmask: |
| 6167 | kfree(phba->sli4_hba.rpi_bmask); |
Roberto Sassu | cd60be4 | 2017-01-11 11:06:42 +0100 | [diff] [blame] | 6168 | phba->sli4_hba.rpi_bmask = NULL; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6169 | err_exit: |
| 6170 | return rc; |
| 6171 | } |
| 6172 | |
| 6173 | /** |
| 6174 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. |
| 6175 | * @phba: Pointer to HBA context object. |
| 6176 | * |
| 6177 | * This function allocates the number of elements for the specified |
| 6178 | * resource type. |
| 6179 | **/ |
| 6180 | int |
| 6181 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) |
| 6182 | { |
| 6183 | if (phba->sli4_hba.extents_in_use) { |
| 6184 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); |
| 6185 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); |
| 6186 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); |
| 6187 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); |
| 6188 | } else { |
| 6189 | kfree(phba->vpi_bmask); |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 6190 | phba->sli4_hba.max_cfg_param.vpi_used = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6191 | kfree(phba->vpi_ids); |
| 6192 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6193 | kfree(phba->sli4_hba.xri_bmask); |
| 6194 | kfree(phba->sli4_hba.xri_ids); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6195 | kfree(phba->sli4_hba.vfi_bmask); |
| 6196 | kfree(phba->sli4_hba.vfi_ids); |
| 6197 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6198 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
| 6199 | } |
| 6200 | |
| 6201 | return 0; |
| 6202 | } |
| 6203 | |
| 6204 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6205 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. |
| 6206 | * @phba: Pointer to HBA context object. |
| 6207 | * @type: The resource extent type. |
| 6208 | * @extnt_count: buffer to hold port extent count response |
| 6209 | * @extnt_size: buffer to hold port extent size response. |
| 6210 | * |
| 6211 | * This function calls the port to read the host allocated extents |
| 6212 | * for a particular type. |
| 6213 | **/ |
| 6214 | int |
| 6215 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, |
| 6216 | uint16_t *extnt_cnt, uint16_t *extnt_size) |
| 6217 | { |
| 6218 | bool emb; |
| 6219 | int rc = 0; |
| 6220 | uint16_t curr_blks = 0; |
| 6221 | uint32_t req_len, emb_len; |
| 6222 | uint32_t alloc_len, mbox_tmo; |
| 6223 | struct list_head *blk_list_head; |
| 6224 | struct lpfc_rsrc_blks *rsrc_blk; |
| 6225 | LPFC_MBOXQ_t *mbox; |
| 6226 | void *virtaddr = NULL; |
| 6227 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; |
| 6228 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; |
| 6229 | union lpfc_sli4_cfg_shdr *shdr; |
| 6230 | |
| 6231 | switch (type) { |
| 6232 | case LPFC_RSC_TYPE_FCOE_VPI: |
| 6233 | blk_list_head = &phba->lpfc_vpi_blk_list; |
| 6234 | break; |
| 6235 | case LPFC_RSC_TYPE_FCOE_XRI: |
| 6236 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; |
| 6237 | break; |
| 6238 | case LPFC_RSC_TYPE_FCOE_VFI: |
| 6239 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; |
| 6240 | break; |
| 6241 | case LPFC_RSC_TYPE_FCOE_RPI: |
| 6242 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; |
| 6243 | break; |
| 6244 | default: |
| 6245 | return -EIO; |
| 6246 | } |
| 6247 | |
| 6248 | /* Count the number of extents currently allocatd for this type. */ |
| 6249 | list_for_each_entry(rsrc_blk, blk_list_head, list) { |
| 6250 | if (curr_blks == 0) { |
| 6251 | /* |
| 6252 | * The GET_ALLOCATED mailbox does not return the size, |
| 6253 | * just the count. The size should be just the size |
| 6254 | * stored in the current allocated block and all sizes |
| 6255 | * for an extent type are the same so set the return |
| 6256 | * value now. |
| 6257 | */ |
| 6258 | *extnt_size = rsrc_blk->rsrc_size; |
| 6259 | } |
| 6260 | curr_blks++; |
| 6261 | } |
| 6262 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6263 | /* |
| 6264 | * Calculate the size of an embedded mailbox. The uint32_t |
| 6265 | * accounts for extents-specific word. |
| 6266 | */ |
| 6267 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - |
| 6268 | sizeof(uint32_t); |
| 6269 | |
| 6270 | /* |
| 6271 | * Presume the allocation and response will fit into an embedded |
| 6272 | * mailbox. If not true, reconfigure to a non-embedded mailbox. |
| 6273 | */ |
| 6274 | emb = LPFC_SLI4_MBX_EMBED; |
| 6275 | req_len = emb_len; |
| 6276 | if (req_len > emb_len) { |
| 6277 | req_len = curr_blks * sizeof(uint16_t) + |
| 6278 | sizeof(union lpfc_sli4_cfg_shdr) + |
| 6279 | sizeof(uint32_t); |
| 6280 | emb = LPFC_SLI4_MBX_NEMBED; |
| 6281 | } |
| 6282 | |
| 6283 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6284 | if (!mbox) |
| 6285 | return -ENOMEM; |
| 6286 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); |
| 6287 | |
| 6288 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6289 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, |
| 6290 | req_len, emb); |
| 6291 | if (alloc_len < req_len) { |
| 6292 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6293 | "2983 Allocated DMA memory size (x%x) is " |
| 6294 | "less than the requested DMA memory " |
| 6295 | "size (x%x)\n", alloc_len, req_len); |
| 6296 | rc = -ENOMEM; |
| 6297 | goto err_exit; |
| 6298 | } |
| 6299 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); |
| 6300 | if (unlikely(rc)) { |
| 6301 | rc = -EIO; |
| 6302 | goto err_exit; |
| 6303 | } |
| 6304 | |
| 6305 | if (!phba->sli4_hba.intr_enable) |
| 6306 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 6307 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 6308 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 6309 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 6310 | } |
| 6311 | |
| 6312 | if (unlikely(rc)) { |
| 6313 | rc = -EIO; |
| 6314 | goto err_exit; |
| 6315 | } |
| 6316 | |
| 6317 | /* |
| 6318 | * Figure out where the response is located. Then get local pointers |
| 6319 | * to the response data. The port does not guarantee to respond to |
| 6320 | * all extents counts request so update the local variable with the |
| 6321 | * allocated count from the port. |
| 6322 | */ |
| 6323 | if (emb == LPFC_SLI4_MBX_EMBED) { |
| 6324 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; |
| 6325 | shdr = &rsrc_ext->header.cfg_shdr; |
| 6326 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); |
| 6327 | } else { |
| 6328 | virtaddr = mbox->sge_array->addr[0]; |
| 6329 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 6330 | shdr = &n_rsrc->cfg_shdr; |
| 6331 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); |
| 6332 | } |
| 6333 | |
| 6334 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { |
| 6335 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, |
| 6336 | "2984 Failed to read allocated resources " |
| 6337 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", |
| 6338 | type, |
| 6339 | bf_get(lpfc_mbox_hdr_status, &shdr->response), |
| 6340 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); |
| 6341 | rc = -EIO; |
| 6342 | goto err_exit; |
| 6343 | } |
| 6344 | err_exit: |
| 6345 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 6346 | return rc; |
| 6347 | } |
| 6348 | |
| 6349 | /** |
James Smart | 0ef6996 | 2017-04-21 16:04:50 -0700 | [diff] [blame] | 6350 | * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6351 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6352 | * @pring: Pointer to driver SLI ring object. |
| 6353 | * @sgl_list: linked link of sgl buffers to post |
| 6354 | * @cnt: number of linked list buffers |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6355 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6356 | * This routine walks the list of buffers that have been allocated and |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6357 | * repost them to the port by using SGL block post. This is needed after a |
| 6358 | * pci_function_reset/warm_start or start. It attempts to construct blocks |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6359 | * of buffer sgls which contains contiguous xris and uses the non-embedded |
| 6360 | * 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] | 6361 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post |
| 6362 | * mailbox command for posting. |
| 6363 | * |
| 6364 | * Returns: 0 = success, non-zero failure. |
| 6365 | **/ |
| 6366 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6367 | lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba, |
| 6368 | struct list_head *sgl_list, int cnt) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6369 | { |
| 6370 | struct lpfc_sglq *sglq_entry = NULL; |
| 6371 | struct lpfc_sglq *sglq_entry_next = NULL; |
| 6372 | struct lpfc_sglq *sglq_entry_first = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6373 | int status, total_cnt; |
| 6374 | int post_cnt = 0, num_posted = 0, block_cnt = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6375 | int last_xritag = NO_XRI; |
| 6376 | LIST_HEAD(prep_sgl_list); |
| 6377 | LIST_HEAD(blck_sgl_list); |
| 6378 | LIST_HEAD(allc_sgl_list); |
| 6379 | LIST_HEAD(post_sgl_list); |
| 6380 | LIST_HEAD(free_sgl_list); |
| 6381 | |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6382 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6383 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6384 | list_splice_init(sgl_list, &allc_sgl_list); |
| 6385 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6386 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6387 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6388 | total_cnt = cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6389 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 6390 | &allc_sgl_list, list) { |
| 6391 | list_del_init(&sglq_entry->list); |
| 6392 | block_cnt++; |
| 6393 | if ((last_xritag != NO_XRI) && |
| 6394 | (sglq_entry->sli4_xritag != last_xritag + 1)) { |
| 6395 | /* a hole in xri block, form a sgl posting block */ |
| 6396 | list_splice_init(&prep_sgl_list, &blck_sgl_list); |
| 6397 | post_cnt = block_cnt - 1; |
| 6398 | /* prepare list for next posting block */ |
| 6399 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6400 | block_cnt = 1; |
| 6401 | } else { |
| 6402 | /* prepare list for next posting block */ |
| 6403 | list_add_tail(&sglq_entry->list, &prep_sgl_list); |
| 6404 | /* enough sgls for non-embed sgl mbox command */ |
| 6405 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { |
| 6406 | list_splice_init(&prep_sgl_list, |
| 6407 | &blck_sgl_list); |
| 6408 | post_cnt = block_cnt; |
| 6409 | block_cnt = 0; |
| 6410 | } |
| 6411 | } |
| 6412 | num_posted++; |
| 6413 | |
| 6414 | /* keep track of last sgl's xritag */ |
| 6415 | last_xritag = sglq_entry->sli4_xritag; |
| 6416 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6417 | /* end of repost sgl list condition for buffers */ |
| 6418 | if (num_posted == total_cnt) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6419 | if (post_cnt == 0) { |
| 6420 | list_splice_init(&prep_sgl_list, |
| 6421 | &blck_sgl_list); |
| 6422 | post_cnt = block_cnt; |
| 6423 | } else if (block_cnt == 1) { |
| 6424 | status = lpfc_sli4_post_sgl(phba, |
| 6425 | sglq_entry->phys, 0, |
| 6426 | sglq_entry->sli4_xritag); |
| 6427 | if (!status) { |
| 6428 | /* successful, put sgl to posted list */ |
| 6429 | list_add_tail(&sglq_entry->list, |
| 6430 | &post_sgl_list); |
| 6431 | } else { |
| 6432 | /* Failure, put sgl to free list */ |
| 6433 | lpfc_printf_log(phba, KERN_WARNING, |
| 6434 | LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6435 | "3159 Failed to post " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6436 | "sgl, xritag:x%x\n", |
| 6437 | sglq_entry->sli4_xritag); |
| 6438 | list_add_tail(&sglq_entry->list, |
| 6439 | &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6440 | total_cnt--; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6441 | } |
| 6442 | } |
| 6443 | } |
| 6444 | |
| 6445 | /* continue until a nembed page worth of sgls */ |
| 6446 | if (post_cnt == 0) |
| 6447 | continue; |
| 6448 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6449 | /* post the buffer list sgls as a block */ |
| 6450 | status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list, |
| 6451 | post_cnt); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6452 | |
| 6453 | if (!status) { |
| 6454 | /* success, put sgl list to posted sgl list */ |
| 6455 | list_splice_init(&blck_sgl_list, &post_sgl_list); |
| 6456 | } else { |
| 6457 | /* Failure, put sgl list to free sgl list */ |
| 6458 | sglq_entry_first = list_first_entry(&blck_sgl_list, |
| 6459 | struct lpfc_sglq, |
| 6460 | list); |
| 6461 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6462 | "3160 Failed to post sgl-list, " |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6463 | "xritag:x%x-x%x\n", |
| 6464 | sglq_entry_first->sli4_xritag, |
| 6465 | (sglq_entry_first->sli4_xritag + |
| 6466 | post_cnt - 1)); |
| 6467 | list_splice_init(&blck_sgl_list, &free_sgl_list); |
James Smart | 711ea88 | 2013-04-17 20:18:29 -0400 | [diff] [blame] | 6468 | total_cnt -= post_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6469 | } |
| 6470 | |
| 6471 | /* don't reset xirtag due to hole in xri block */ |
| 6472 | if (block_cnt == 0) |
| 6473 | last_xritag = NO_XRI; |
| 6474 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6475 | /* reset sgl post count for next round of posting */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6476 | post_cnt = 0; |
| 6477 | } |
| 6478 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6479 | /* free the sgls failed to post */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6480 | lpfc_free_sgl_list(phba, &free_sgl_list); |
| 6481 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6482 | /* push sgls posted to the available list */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6483 | if (!list_empty(&post_sgl_list)) { |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6484 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6485 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6486 | list_splice_init(&post_sgl_list, sgl_list); |
| 6487 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 6488 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6489 | } else { |
| 6490 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6491 | "3161 Failure to post sgl to port.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6492 | return -EIO; |
| 6493 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6494 | |
| 6495 | /* return the number of XRIs actually posted */ |
| 6496 | return total_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6497 | } |
| 6498 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6499 | void |
| 6500 | lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 6501 | { |
| 6502 | uint32_t len; |
| 6503 | |
| 6504 | len = sizeof(struct lpfc_mbx_set_host_data) - |
| 6505 | sizeof(struct lpfc_sli4_cfg_mhdr); |
| 6506 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 6507 | LPFC_MBOX_OPCODE_SET_HOST_DATA, len, |
| 6508 | LPFC_SLI4_MBX_EMBED); |
| 6509 | |
| 6510 | 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] | 6511 | mbox->u.mqe.un.set_host_data.param_len = |
| 6512 | LPFC_HOST_OS_DRIVER_VERSION_SIZE; |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6513 | snprintf(mbox->u.mqe.un.set_host_data.data, |
| 6514 | LPFC_HOST_OS_DRIVER_VERSION_SIZE, |
| 6515 | "Linux %s v"LPFC_DRIVER_VERSION, |
| 6516 | (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC"); |
| 6517 | } |
| 6518 | |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6519 | int |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6520 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6521 | struct lpfc_queue *drq, int count, int idx) |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6522 | { |
| 6523 | int rc, i; |
| 6524 | struct lpfc_rqe hrqe; |
| 6525 | struct lpfc_rqe drqe; |
| 6526 | struct lpfc_rqb *rqbp; |
| 6527 | struct rqb_dmabuf *rqb_buffer; |
| 6528 | LIST_HEAD(rqb_buf_list); |
| 6529 | |
| 6530 | rqbp = hrq->rqbp; |
| 6531 | for (i = 0; i < count; i++) { |
| 6532 | /* IF RQ is already full, don't bother */ |
| 6533 | if (rqbp->buffer_count + i >= rqbp->entry_count - 1) |
| 6534 | break; |
| 6535 | rqb_buffer = rqbp->rqb_alloc_buffer(phba); |
| 6536 | if (!rqb_buffer) |
| 6537 | break; |
| 6538 | rqb_buffer->hrq = hrq; |
| 6539 | rqb_buffer->drq = drq; |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6540 | rqb_buffer->idx = idx; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6541 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); |
| 6542 | } |
| 6543 | while (!list_empty(&rqb_buf_list)) { |
| 6544 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, |
| 6545 | hbuf.list); |
| 6546 | |
| 6547 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); |
| 6548 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); |
| 6549 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); |
| 6550 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); |
| 6551 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); |
| 6552 | if (rc < 0) { |
| 6553 | rqbp->rqb_free_buffer(phba, rqb_buffer); |
| 6554 | } else { |
| 6555 | list_add_tail(&rqb_buffer->hbuf.list, |
| 6556 | &rqbp->rqb_buffer_list); |
| 6557 | rqbp->buffer_count++; |
| 6558 | } |
| 6559 | } |
| 6560 | return 1; |
| 6561 | } |
| 6562 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6563 | /** |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 6564 | * lpfc_sli4_hba_setup - SLI4 device initialization PCI function |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6565 | * @phba: Pointer to HBA context object. |
| 6566 | * |
Masahiro Yamada | 183b802 | 2017-02-27 14:29:20 -0800 | [diff] [blame] | 6567 | * This function is the main SLI4 device initialization PCI function. This |
| 6568 | * function is called by the HBA initialization code, HBA reset code and |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6569 | * HBA error attention handler code. Caller is not required to hold any |
| 6570 | * locks. |
| 6571 | **/ |
| 6572 | int |
| 6573 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) |
| 6574 | { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6575 | int rc, i, cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6576 | LPFC_MBOXQ_t *mboxq; |
| 6577 | struct lpfc_mqe *mqe; |
| 6578 | uint8_t *vpd; |
| 6579 | uint32_t vpd_size; |
| 6580 | uint32_t ftr_rsp = 0; |
| 6581 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); |
| 6582 | struct lpfc_vport *vport = phba->pport; |
| 6583 | struct lpfc_dmabuf *mp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6584 | struct lpfc_rqb *rqbp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6585 | |
| 6586 | /* Perform a PCI function reset to start from clean */ |
| 6587 | rc = lpfc_pci_function_reset(phba); |
| 6588 | if (unlikely(rc)) |
| 6589 | return -ENODEV; |
| 6590 | |
| 6591 | /* Check the HBA Host Status Register for readyness */ |
| 6592 | rc = lpfc_sli4_post_status_check(phba); |
| 6593 | if (unlikely(rc)) |
| 6594 | return -ENODEV; |
| 6595 | else { |
| 6596 | spin_lock_irq(&phba->hbalock); |
| 6597 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; |
| 6598 | spin_unlock_irq(&phba->hbalock); |
| 6599 | } |
| 6600 | |
| 6601 | /* |
| 6602 | * Allocate a single mailbox container for initializing the |
| 6603 | * port. |
| 6604 | */ |
| 6605 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6606 | if (!mboxq) |
| 6607 | return -ENOMEM; |
| 6608 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6609 | /* Issue READ_REV to collect vpd and FW information. */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6610 | vpd_size = SLI4_PAGE_SIZE; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6611 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
| 6612 | if (!vpd) { |
| 6613 | rc = -ENOMEM; |
| 6614 | goto out_free_mbox; |
| 6615 | } |
| 6616 | |
| 6617 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6618 | if (unlikely(rc)) { |
| 6619 | kfree(vpd); |
| 6620 | goto out_free_mbox; |
| 6621 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6622 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6623 | mqe = &mboxq->u.mqe; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6624 | 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] | 6625 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6626 | phba->hba_flag |= HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6627 | phba->fcp_embed_io = 0; /* SLI4 FC support only */ |
| 6628 | } else { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6629 | phba->hba_flag &= ~HBA_FCOE_MODE; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 6630 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6631 | |
| 6632 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == |
| 6633 | LPFC_DCBX_CEE_MODE) |
| 6634 | phba->hba_flag |= HBA_FIP_SUPPORT; |
| 6635 | else |
| 6636 | phba->hba_flag &= ~HBA_FIP_SUPPORT; |
| 6637 | |
James Smart | 4f2e66c | 2012-05-09 21:17:07 -0400 | [diff] [blame] | 6638 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
| 6639 | |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 6640 | if (phba->sli_rev != LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6641 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6642 | "0376 READ_REV Error. SLI Level %d " |
| 6643 | "FCoE enabled %d\n", |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6644 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6645 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6646 | kfree(vpd); |
| 6647 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6648 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6649 | |
| 6650 | /* |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6651 | * Continue initialization with default values even if driver failed |
| 6652 | * to read FCoE param config regions, only read parameters if the |
| 6653 | * board is FCoE |
| 6654 | */ |
| 6655 | if (phba->hba_flag & HBA_FCOE_MODE && |
| 6656 | lpfc_sli4_read_fcoe_params(phba)) |
| 6657 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
| 6658 | "2570 Failed to read FCoE parameters\n"); |
| 6659 | |
| 6660 | /* |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 6661 | * Retrieve sli4 device physical port name, failure of doing it |
| 6662 | * is considered as non-fatal. |
| 6663 | */ |
| 6664 | rc = lpfc_sli4_retrieve_pport_name(phba); |
| 6665 | if (!rc) |
| 6666 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6667 | "3080 Successful retrieving SLI4 device " |
| 6668 | "physical port name: %s.\n", phba->Port); |
| 6669 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6670 | /* |
| 6671 | * Evaluate the read rev and vpd data. Populate the driver |
| 6672 | * state with the results. If this routine fails, the failure |
| 6673 | * is not fatal as the driver will use generic values. |
| 6674 | */ |
| 6675 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); |
| 6676 | if (unlikely(!rc)) { |
| 6677 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6678 | "0377 Error %d parsing vpd. " |
| 6679 | "Using defaults.\n", rc); |
| 6680 | rc = 0; |
| 6681 | } |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6682 | kfree(vpd); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6683 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 6684 | /* Save information as VPD data */ |
| 6685 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; |
| 6686 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; |
| 6687 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; |
| 6688 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, |
| 6689 | &mqe->un.read_rev); |
| 6690 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, |
| 6691 | &mqe->un.read_rev); |
| 6692 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, |
| 6693 | &mqe->un.read_rev); |
| 6694 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, |
| 6695 | &mqe->un.read_rev); |
| 6696 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; |
| 6697 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); |
| 6698 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; |
| 6699 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); |
| 6700 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; |
| 6701 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); |
| 6702 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 6703 | "(%d):0380 READ_REV Status x%x " |
| 6704 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", |
| 6705 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 6706 | bf_get(lpfc_mqe_status, mqe), |
| 6707 | phba->vpd.rev.opFwName, |
| 6708 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, |
| 6709 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6710 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6711 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 6712 | rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3); |
| 6713 | if (phba->pport->cfg_lun_queue_depth > rc) { |
| 6714 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6715 | "3362 LUN queue depth changed from %d to %d\n", |
| 6716 | phba->pport->cfg_lun_queue_depth, rc); |
| 6717 | phba->pport->cfg_lun_queue_depth = rc; |
| 6718 | } |
| 6719 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6720 | 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] | 6721 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6722 | lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY); |
| 6723 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6724 | if (rc == MBX_SUCCESS) { |
| 6725 | phba->hba_flag |= HBA_RECOVERABLE_UE; |
| 6726 | /* Set 1Sec interval to detect UE */ |
| 6727 | phba->eratt_poll_interval = 1; |
| 6728 | phba->sli4_hba.ue_to_sr = bf_get( |
| 6729 | lpfc_mbx_set_feature_UESR, |
| 6730 | &mboxq->u.mqe.un.set_feature); |
| 6731 | phba->sli4_hba.ue_to_rp = bf_get( |
| 6732 | lpfc_mbx_set_feature_UERP, |
| 6733 | &mboxq->u.mqe.un.set_feature); |
| 6734 | } |
| 6735 | } |
| 6736 | |
| 6737 | if (phba->cfg_enable_mds_diags && phba->mds_diags_support) { |
| 6738 | /* Enable MDS Diagnostics only if the SLI Port supports it */ |
| 6739 | lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS); |
| 6740 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6741 | if (rc != MBX_SUCCESS) |
| 6742 | phba->mds_diags_support = 0; |
| 6743 | } |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 6744 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6745 | /* |
| 6746 | * Discover the port's supported feature set and match it against the |
| 6747 | * hosts requests. |
| 6748 | */ |
| 6749 | lpfc_request_features(phba, mboxq); |
| 6750 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6751 | if (unlikely(rc)) { |
| 6752 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6753 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6754 | } |
| 6755 | |
| 6756 | /* |
| 6757 | * The port must support FCP initiator mode as this is the |
| 6758 | * only mode running in the host. |
| 6759 | */ |
| 6760 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { |
| 6761 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6762 | "0378 No support for fcpi mode.\n"); |
| 6763 | ftr_rsp++; |
| 6764 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6765 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
| 6766 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; |
| 6767 | else |
| 6768 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6769 | /* |
| 6770 | * If the port cannot support the host's requested features |
| 6771 | * then turn off the global config parameters to disable the |
| 6772 | * feature in the driver. This is not a fatal error. |
| 6773 | */ |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 6774 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
| 6775 | if (phba->cfg_enable_bg) { |
| 6776 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) |
| 6777 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
| 6778 | else |
| 6779 | ftr_rsp++; |
| 6780 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6781 | |
| 6782 | if (phba->max_vpi && phba->cfg_enable_npiv && |
| 6783 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6784 | ftr_rsp++; |
| 6785 | |
| 6786 | if (ftr_rsp) { |
| 6787 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6788 | "0379 Feature Mismatch Data: x%08x %08x " |
| 6789 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, |
| 6790 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, |
| 6791 | phba->cfg_enable_npiv, phba->max_vpi); |
| 6792 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) |
| 6793 | phba->cfg_enable_bg = 0; |
| 6794 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) |
| 6795 | phba->cfg_enable_npiv = 0; |
| 6796 | } |
| 6797 | |
| 6798 | /* These SLI3 features are assumed in SLI4 */ |
| 6799 | spin_lock_irq(&phba->hbalock); |
| 6800 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); |
| 6801 | spin_unlock_irq(&phba->hbalock); |
| 6802 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6803 | /* |
| 6804 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent |
| 6805 | * calls depends on these resources to complete port setup. |
| 6806 | */ |
| 6807 | rc = lpfc_sli4_alloc_resource_identifiers(phba); |
| 6808 | if (rc) { |
| 6809 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6810 | "2920 Failed to alloc Resource IDs " |
| 6811 | "rc = x%x\n", rc); |
| 6812 | goto out_free_mbox; |
| 6813 | } |
| 6814 | |
James Smart | 61bda8f | 2016-10-13 15:06:05 -0700 | [diff] [blame] | 6815 | lpfc_set_host_data(phba, mboxq); |
| 6816 | |
| 6817 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6818 | if (rc) { |
| 6819 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 6820 | "2134 Failed to set host os driver version %x", |
| 6821 | rc); |
| 6822 | } |
| 6823 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6824 | /* Read the port's service parameters. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6825 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
| 6826 | if (rc) { |
| 6827 | phba->link_state = LPFC_HBA_ERROR; |
| 6828 | rc = -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6829 | goto out_free_mbox; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 6830 | } |
| 6831 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6832 | mboxq->vport = vport; |
| 6833 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6834 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 6835 | if (rc == MBX_SUCCESS) { |
| 6836 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); |
| 6837 | rc = 0; |
| 6838 | } |
| 6839 | |
| 6840 | /* |
| 6841 | * This memory was allocated by the lpfc_read_sparam routine. Release |
| 6842 | * it to the mbuf pool. |
| 6843 | */ |
| 6844 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 6845 | kfree(mp); |
| 6846 | mboxq->context1 = NULL; |
| 6847 | if (unlikely(rc)) { |
| 6848 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6849 | "0382 READ_SPARAM command failed " |
| 6850 | "status %d, mbxStatus x%x\n", |
| 6851 | rc, bf_get(lpfc_mqe_status, mqe)); |
| 6852 | phba->link_state = LPFC_HBA_ERROR; |
| 6853 | rc = -EIO; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6854 | goto out_free_mbox; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6855 | } |
| 6856 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6857 | lpfc_update_vport_wwn(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6858 | |
| 6859 | /* Update the fc_host data structures with new wwn. */ |
| 6860 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 6861 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
| 6862 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6863 | /* Create all the SLI4 queues */ |
| 6864 | rc = lpfc_sli4_queue_create(phba); |
| 6865 | if (rc) { |
| 6866 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6867 | "3089 Failed to allocate queues\n"); |
| 6868 | rc = -ENODEV; |
| 6869 | goto out_free_mbox; |
| 6870 | } |
| 6871 | /* Set up all the queues to the device */ |
| 6872 | rc = lpfc_sli4_queue_setup(phba); |
| 6873 | if (unlikely(rc)) { |
| 6874 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6875 | "0381 Error %d during queue setup.\n ", rc); |
| 6876 | goto out_stop_timers; |
| 6877 | } |
| 6878 | /* Initialize the driver internal SLI layer lists. */ |
| 6879 | lpfc_sli4_setup(phba); |
| 6880 | lpfc_sli4_queue_init(phba); |
| 6881 | |
| 6882 | /* update host els xri-sgl sizes and mappings */ |
| 6883 | rc = lpfc_sli4_els_sgl_update(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6884 | if (unlikely(rc)) { |
| 6885 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6886 | "1400 Failed to update xri-sgl size and " |
| 6887 | "mapping: %d\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6888 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6889 | } |
| 6890 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6891 | /* register the els sgl pool to the port */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6892 | rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list, |
| 6893 | phba->sli4_hba.els_xri_cnt); |
| 6894 | if (unlikely(rc < 0)) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6895 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6896 | "0582 Error %d during els sgl post " |
| 6897 | "operation\n", rc); |
| 6898 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6899 | goto out_destroy_queue; |
| 6900 | } |
| 6901 | phba->sli4_hba.els_xri_cnt = rc; |
| 6902 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6903 | if (phba->nvmet_support) { |
| 6904 | /* update host nvmet xri-sgl sizes and mappings */ |
| 6905 | rc = lpfc_sli4_nvmet_sgl_update(phba); |
| 6906 | if (unlikely(rc)) { |
| 6907 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6908 | "6308 Failed to update nvmet-sgl size " |
| 6909 | "and mapping: %d\n", rc); |
| 6910 | goto out_destroy_queue; |
| 6911 | } |
| 6912 | |
| 6913 | /* register the nvmet sgl pool to the port */ |
| 6914 | rc = lpfc_sli4_repost_sgl_list( |
| 6915 | phba, |
| 6916 | &phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 6917 | phba->sli4_hba.nvmet_xri_cnt); |
| 6918 | if (unlikely(rc < 0)) { |
| 6919 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6920 | "3117 Error %d during nvmet " |
| 6921 | "sgl post\n", rc); |
| 6922 | rc = -ENODEV; |
| 6923 | goto out_destroy_queue; |
| 6924 | } |
| 6925 | phba->sli4_hba.nvmet_xri_cnt = rc; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6926 | |
| 6927 | cnt = phba->cfg_iocb_cnt * 1024; |
| 6928 | /* We need 1 iocbq for every SGL, for IO processing */ |
| 6929 | cnt += phba->sli4_hba.nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6930 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6931 | /* update host scsi xri-sgl sizes and mappings */ |
| 6932 | rc = lpfc_sli4_scsi_sgl_update(phba); |
| 6933 | if (unlikely(rc)) { |
| 6934 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6935 | "6309 Failed to update scsi-sgl size " |
| 6936 | "and mapping: %d\n", rc); |
| 6937 | goto out_destroy_queue; |
| 6938 | } |
| 6939 | |
| 6940 | /* update host nvme xri-sgl sizes and mappings */ |
| 6941 | rc = lpfc_sli4_nvme_sgl_update(phba); |
| 6942 | if (unlikely(rc)) { |
| 6943 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6944 | "6082 Failed to update nvme-sgl size " |
| 6945 | "and mapping: %d\n", rc); |
| 6946 | goto out_destroy_queue; |
| 6947 | } |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6948 | |
| 6949 | cnt = phba->cfg_iocb_cnt * 1024; |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6950 | } |
| 6951 | |
| 6952 | if (!phba->sli.iocbq_lookup) { |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6953 | /* Initialize and populate the iocb list per host */ |
| 6954 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6955 | "2821 initialize iocb list %d total %d\n", |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6956 | phba->cfg_iocb_cnt, cnt); |
| 6957 | rc = lpfc_init_iocb_list(phba, cnt); |
| 6958 | if (rc) { |
| 6959 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6960 | "1413 Failed to init iocb list.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6961 | goto out_destroy_queue; |
| 6962 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6963 | } |
| 6964 | |
James Smart | 11e644e | 2017-06-15 22:56:48 -0700 | [diff] [blame] | 6965 | if (phba->nvmet_support) |
| 6966 | lpfc_nvmet_create_targetport(phba); |
| 6967 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6968 | if (phba->nvmet_support && phba->cfg_nvmet_mrq) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6969 | /* Post initial buffers to all RQs created */ |
| 6970 | for (i = 0; i < phba->cfg_nvmet_mrq; i++) { |
| 6971 | rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp; |
| 6972 | INIT_LIST_HEAD(&rqbp->rqb_buffer_list); |
| 6973 | rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc; |
| 6974 | rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 6975 | rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6976 | rqbp->buffer_count = 0; |
| 6977 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6978 | lpfc_post_rq_buffer( |
| 6979 | phba, phba->sli4_hba.nvmet_mrq_hdr[i], |
| 6980 | phba->sli4_hba.nvmet_mrq_data[i], |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6981 | LPFC_NVMET_RQE_DEF_COUNT, i); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 6982 | } |
| 6983 | } |
| 6984 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6985 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 6986 | /* register the allocated scsi sgl pool to the port */ |
| 6987 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
| 6988 | if (unlikely(rc)) { |
| 6989 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6990 | "0383 Error %d during scsi sgl post " |
| 6991 | "operation\n", rc); |
| 6992 | /* Some Scsi buffers were moved to abort scsi list */ |
| 6993 | /* A pci function reset will repost them */ |
| 6994 | rc = -ENODEV; |
| 6995 | goto out_destroy_queue; |
| 6996 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6997 | } |
| 6998 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 6999 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 7000 | (phba->nvmet_support == 0)) { |
| 7001 | |
| 7002 | /* register the allocated nvme sgl pool to the port */ |
| 7003 | rc = lpfc_repost_nvme_sgl_list(phba); |
| 7004 | if (unlikely(rc)) { |
| 7005 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7006 | "6116 Error %d during nvme sgl post " |
| 7007 | "operation\n", rc); |
| 7008 | /* Some NVME buffers were moved to abort nvme list */ |
| 7009 | /* A pci function reset will repost them */ |
| 7010 | rc = -ENODEV; |
| 7011 | goto out_destroy_queue; |
| 7012 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7013 | } |
| 7014 | |
| 7015 | /* Post the rpi header region to the device. */ |
| 7016 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); |
| 7017 | if (unlikely(rc)) { |
| 7018 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7019 | "0393 Error %d during rpi post operation\n", |
| 7020 | rc); |
| 7021 | rc = -ENODEV; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7022 | goto out_destroy_queue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7023 | } |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7024 | lpfc_sli4_node_prep(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7025 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7026 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7027 | if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7028 | /* |
| 7029 | * The FC Port needs to register FCFI (index 0) |
| 7030 | */ |
| 7031 | lpfc_reg_fcfi(phba, mboxq); |
| 7032 | mboxq->vport = phba->pport; |
| 7033 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7034 | if (rc != MBX_SUCCESS) |
| 7035 | goto out_unset_queue; |
| 7036 | rc = 0; |
| 7037 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, |
| 7038 | &mboxq->u.mqe.un.reg_fcfi); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7039 | } else { |
| 7040 | /* We are a NVME Target mode with MRQ > 1 */ |
| 7041 | |
| 7042 | /* First register the FCFI */ |
| 7043 | lpfc_reg_fcfi_mrq(phba, mboxq, 0); |
| 7044 | mboxq->vport = phba->pport; |
| 7045 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7046 | if (rc != MBX_SUCCESS) |
| 7047 | goto out_unset_queue; |
| 7048 | rc = 0; |
| 7049 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi, |
| 7050 | &mboxq->u.mqe.un.reg_fcfi_mrq); |
| 7051 | |
| 7052 | /* Next register the MRQs */ |
| 7053 | lpfc_reg_fcfi_mrq(phba, mboxq, 1); |
| 7054 | mboxq->vport = phba->pport; |
| 7055 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7056 | if (rc != MBX_SUCCESS) |
| 7057 | goto out_unset_queue; |
| 7058 | rc = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7059 | } |
| 7060 | /* Check if the port is configured to be disabled */ |
| 7061 | lpfc_sli_read_link_ste(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7062 | } |
| 7063 | |
| 7064 | /* Arm the CQs and then EQs on device */ |
| 7065 | lpfc_sli4_arm_cqeq_intr(phba); |
| 7066 | |
| 7067 | /* Indicate device interrupt mode */ |
| 7068 | phba->sli4_hba.intr_enable = 1; |
| 7069 | |
| 7070 | /* Allow asynchronous mailbox command to go through */ |
| 7071 | spin_lock_irq(&phba->hbalock); |
| 7072 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7073 | spin_unlock_irq(&phba->hbalock); |
| 7074 | |
| 7075 | /* Post receive buffers to the device */ |
| 7076 | lpfc_sli4_rb_setup(phba); |
| 7077 | |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 7078 | /* Reset HBA FCF states after HBA reset */ |
| 7079 | phba->fcf.fcf_flag = 0; |
| 7080 | phba->fcf.current_rec.flag = 0; |
| 7081 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7082 | /* Start the ELS watchdog timer */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 7083 | mod_timer(&vport->els_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7084 | jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7085 | |
| 7086 | /* Start heart beat timer */ |
| 7087 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7088 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7089 | phba->hb_outstanding = 0; |
| 7090 | phba->last_completion_time = jiffies; |
| 7091 | |
| 7092 | /* Start error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7093 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7094 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7095 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7096 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
| 7097 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { |
| 7098 | rc = pci_enable_pcie_error_reporting(phba->pcidev); |
| 7099 | if (!rc) { |
| 7100 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7101 | "2829 This device supports " |
| 7102 | "Advanced Error Reporting (AER)\n"); |
| 7103 | spin_lock_irq(&phba->hbalock); |
| 7104 | phba->hba_flag |= HBA_AER_ENABLED; |
| 7105 | spin_unlock_irq(&phba->hbalock); |
| 7106 | } else { |
| 7107 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7108 | "2830 This device does not support " |
| 7109 | "Advanced Error Reporting (AER)\n"); |
| 7110 | phba->cfg_aer_support = 0; |
| 7111 | } |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7112 | rc = 0; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 7113 | } |
| 7114 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7115 | /* |
| 7116 | * The port is ready, set the host's link state to LINK_DOWN |
| 7117 | * in preparation for link interrupts. |
| 7118 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7119 | spin_lock_irq(&phba->hbalock); |
| 7120 | phba->link_state = LPFC_LINK_DOWN; |
| 7121 | spin_unlock_irq(&phba->hbalock); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 7122 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
| 7123 | (phba->hba_flag & LINK_DISABLED)) { |
| 7124 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7125 | "3103 Adapter Link is disabled.\n"); |
| 7126 | lpfc_down_link(phba, mboxq); |
| 7127 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7128 | if (rc != MBX_SUCCESS) { |
| 7129 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, |
| 7130 | "3104 Adapter failed to issue " |
| 7131 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); |
| 7132 | goto out_unset_queue; |
| 7133 | } |
| 7134 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 7135 | /* don't perform init_link on SLI4 FC port loopback test */ |
| 7136 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 7137 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 7138 | if (rc) |
| 7139 | goto out_unset_queue; |
| 7140 | } |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7141 | } |
| 7142 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7143 | return rc; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 7144 | out_unset_queue: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7145 | /* Unset all the queues set up in this routine when error out */ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7146 | lpfc_sli4_queue_unset(phba); |
| 7147 | out_destroy_queue: |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7148 | lpfc_free_iocb_list(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7149 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7150 | out_stop_timers: |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7151 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7152 | out_free_mbox: |
| 7153 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7154 | return rc; |
| 7155 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7156 | |
| 7157 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7158 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7159 | * @ptr: context object - pointer to hba structure. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7160 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7161 | * This is the callback function for mailbox timer. The mailbox |
| 7162 | * timer is armed when a new mailbox command is issued and the timer |
| 7163 | * is deleted when the mailbox complete. The function is called by |
| 7164 | * the kernel timer code when a mailbox does not complete within |
| 7165 | * expected time. This function wakes up the worker thread to |
| 7166 | * process the mailbox timeout and returns. All the processing is |
| 7167 | * done by the worker thread function lpfc_mbox_timeout_handler. |
| 7168 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7169 | void |
| 7170 | lpfc_mbox_timeout(unsigned long ptr) |
| 7171 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7172 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7173 | unsigned long iflag; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7174 | uint32_t tmo_posted; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7175 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7176 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7177 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7178 | if (!tmo_posted) |
| 7179 | phba->pport->work_port_events |= WORKER_MBOX_TMO; |
| 7180 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 7181 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 7182 | if (!tmo_posted) |
| 7183 | lpfc_worker_wake_up(phba); |
| 7184 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7185 | } |
| 7186 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7187 | /** |
| 7188 | * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions |
| 7189 | * are pending |
| 7190 | * @phba: Pointer to HBA context object. |
| 7191 | * |
| 7192 | * This function checks if any mailbox completions are present on the mailbox |
| 7193 | * completion queue. |
| 7194 | **/ |
Nicholas Krause | 3bb11fc | 2015-08-31 16:48:13 -0400 | [diff] [blame] | 7195 | static bool |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7196 | lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba) |
| 7197 | { |
| 7198 | |
| 7199 | uint32_t idx; |
| 7200 | struct lpfc_queue *mcq; |
| 7201 | struct lpfc_mcqe *mcqe; |
| 7202 | bool pending_completions = false; |
| 7203 | |
| 7204 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7205 | return false; |
| 7206 | |
| 7207 | /* Check for completions on mailbox completion queue */ |
| 7208 | |
| 7209 | mcq = phba->sli4_hba.mbx_cq; |
| 7210 | idx = mcq->hba_index; |
| 7211 | while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) { |
| 7212 | mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe; |
| 7213 | if (bf_get_le32(lpfc_trailer_completed, mcqe) && |
| 7214 | (!bf_get_le32(lpfc_trailer_async, mcqe))) { |
| 7215 | pending_completions = true; |
| 7216 | break; |
| 7217 | } |
| 7218 | idx = (idx + 1) % mcq->entry_count; |
| 7219 | if (mcq->hba_index == idx) |
| 7220 | break; |
| 7221 | } |
| 7222 | return pending_completions; |
| 7223 | |
| 7224 | } |
| 7225 | |
| 7226 | /** |
| 7227 | * lpfc_sli4_process_missed_mbox_completions - process mbox completions |
| 7228 | * that were missed. |
| 7229 | * @phba: Pointer to HBA context object. |
| 7230 | * |
| 7231 | * For sli4, it is possible to miss an interrupt. As such mbox completions |
| 7232 | * maybe missed causing erroneous mailbox timeouts to occur. This function |
| 7233 | * checks to see if mbox completions are on the mailbox completion queue |
| 7234 | * and will process all the completions associated with the eq for the |
| 7235 | * mailbox completion queue. |
| 7236 | **/ |
| 7237 | bool |
| 7238 | lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba) |
| 7239 | { |
| 7240 | |
| 7241 | uint32_t eqidx; |
| 7242 | struct lpfc_queue *fpeq = NULL; |
| 7243 | struct lpfc_eqe *eqe; |
| 7244 | bool mbox_pending; |
| 7245 | |
| 7246 | if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4)) |
| 7247 | return false; |
| 7248 | |
| 7249 | /* Find the eq associated with the mcq */ |
| 7250 | |
| 7251 | if (phba->sli4_hba.hba_eq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7252 | for (eqidx = 0; eqidx < phba->io_channel_irqs; eqidx++) |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7253 | if (phba->sli4_hba.hba_eq[eqidx]->queue_id == |
| 7254 | phba->sli4_hba.mbx_cq->assoc_qid) { |
| 7255 | fpeq = phba->sli4_hba.hba_eq[eqidx]; |
| 7256 | break; |
| 7257 | } |
| 7258 | if (!fpeq) |
| 7259 | return false; |
| 7260 | |
| 7261 | /* Turn off interrupts from this EQ */ |
| 7262 | |
| 7263 | lpfc_sli4_eq_clr_intr(fpeq); |
| 7264 | |
| 7265 | /* Check to see if a mbox completion is pending */ |
| 7266 | |
| 7267 | mbox_pending = lpfc_sli4_mbox_completions_pending(phba); |
| 7268 | |
| 7269 | /* |
| 7270 | * If a mbox completion is pending, process all the events on EQ |
| 7271 | * associated with the mbox completion queue (this could include |
| 7272 | * mailbox commands, async events, els commands, receive queue data |
| 7273 | * and fcp commands) |
| 7274 | */ |
| 7275 | |
| 7276 | if (mbox_pending) |
| 7277 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 7278 | lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx); |
| 7279 | fpeq->EQ_processed++; |
| 7280 | } |
| 7281 | |
| 7282 | /* Always clear and re-arm the EQ */ |
| 7283 | |
| 7284 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 7285 | |
| 7286 | return mbox_pending; |
| 7287 | |
| 7288 | } |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7289 | |
| 7290 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7291 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7292 | * @phba: Pointer to HBA context object. |
| 7293 | * |
| 7294 | * This function is called from worker thread when a mailbox command times out. |
| 7295 | * The caller is not required to hold any locks. This function will reset the |
| 7296 | * HBA and recover all the pending commands. |
| 7297 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7298 | void |
| 7299 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
| 7300 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7301 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7302 | MAILBOX_t *mb = NULL; |
| 7303 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7304 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7305 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7306 | /* If the mailbox completed, process the completion and return */ |
| 7307 | if (lpfc_sli4_process_missed_mbox_completions(phba)) |
| 7308 | return; |
| 7309 | |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 7310 | if (pmbox != NULL) |
| 7311 | mb = &pmbox->u.mb; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7312 | /* Check the pmbox pointer first. There is a race condition |
| 7313 | * between the mbox timeout handler getting executed in the |
| 7314 | * worklist and the mailbox actually completing. When this |
| 7315 | * race condition occurs, the mbox_active will be NULL. |
| 7316 | */ |
| 7317 | spin_lock_irq(&phba->hbalock); |
| 7318 | if (pmbox == NULL) { |
| 7319 | lpfc_printf_log(phba, KERN_WARNING, |
| 7320 | LOG_MBOX | LOG_SLI, |
| 7321 | "0353 Active Mailbox cleared - mailbox timeout " |
| 7322 | "exiting\n"); |
| 7323 | spin_unlock_irq(&phba->hbalock); |
| 7324 | return; |
| 7325 | } |
| 7326 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7327 | /* Mbox cmd <mbxCommand> timeout */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7328 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7329 | "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] | 7330 | mb->mbxCommand, |
| 7331 | phba->pport->port_state, |
| 7332 | phba->sli.sli_flag, |
| 7333 | phba->sli.mbox_active); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7334 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7335 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7336 | /* Setting state unknown so lpfc_sli_abort_iocb_ring |
| 7337 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7338 | * it to fail all outstanding SCSI IO. |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7339 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7340 | spin_lock_irq(&phba->pport->work_port_lock); |
| 7341 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 7342 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 7343 | spin_lock_irq(&phba->hbalock); |
| 7344 | phba->link_state = LPFC_LINK_UNKNOWN; |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 7345 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7346 | spin_unlock_irq(&phba->hbalock); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7347 | |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 7348 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 7349 | |
| 7350 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 7351 | "0345 Resetting board due to mailbox timeout\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7352 | |
| 7353 | /* Reset the HBA device */ |
| 7354 | lpfc_reset_hba(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7355 | } |
| 7356 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7357 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7358 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7359 | * @phba: Pointer to HBA context object. |
| 7360 | * @pmbox: Pointer to mailbox object. |
| 7361 | * @flag: Flag indicating how the mailbox need to be processed. |
| 7362 | * |
| 7363 | * This function is called by discovery code and HBA management code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7364 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
| 7365 | * function gets the hbalock to protect the data structures. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7366 | * The mailbox command can be submitted in polling mode, in which case |
| 7367 | * this function will wait in a polling loop for the completion of the |
| 7368 | * mailbox. |
| 7369 | * If the mailbox is submitted in no_wait mode (not polling) the |
| 7370 | * function will submit the command and returns immediately without waiting |
| 7371 | * for the mailbox completion. The no_wait is supported only when HBA |
| 7372 | * is in SLI2/SLI3 mode - interrupts are enabled. |
| 7373 | * The SLI interface allows only one mailbox pending at a time. If the |
| 7374 | * mailbox is issued in polling mode and there is already a mailbox |
| 7375 | * pending, then the function will return an error. If the mailbox is issued |
| 7376 | * in NO_WAIT mode and there is a mailbox pending already, the function |
| 7377 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. |
| 7378 | * The sli layer owns the mailbox object until the completion of mailbox |
| 7379 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other |
| 7380 | * return codes the caller owns the mailbox command after the return of |
| 7381 | * the function. |
| 7382 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7383 | static int |
| 7384 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
| 7385 | uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7386 | { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7387 | MAILBOX_t *mbx; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7388 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7389 | uint32_t status, evtctr; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7390 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7391 | int i; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7392 | unsigned long timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7393 | unsigned long drvr_flag = 0; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7394 | uint32_t word0, ldata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7395 | void __iomem *to_slim; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7396 | int processing_queue = 0; |
| 7397 | |
| 7398 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7399 | if (!pmbox) { |
James Smart | 8568a4d | 2009-07-19 10:01:16 -0400 | [diff] [blame] | 7400 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7401 | /* processing mbox queue from intr_handler */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7402 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7403 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7404 | return MBX_SUCCESS; |
| 7405 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7406 | processing_queue = 1; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7407 | pmbox = lpfc_mbox_get(phba); |
| 7408 | if (!pmbox) { |
| 7409 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7410 | return MBX_SUCCESS; |
| 7411 | } |
| 7412 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7413 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7414 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7415 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7416 | if(!pmbox->vport) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7417 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7418 | lpfc_printf_log(phba, KERN_ERR, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7419 | LOG_MBOX | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7420 | "1806 Mbox x%x failed. No vport\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7421 | pmbox->u.mb.mbxCommand); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7422 | dump_stack(); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7423 | goto out_not_finished; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7424 | } |
| 7425 | } |
| 7426 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7427 | /* If the PCI channel is in offline state, do not post mbox. */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7428 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
| 7429 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7430 | goto out_not_finished; |
| 7431 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 7432 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 7433 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 7434 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 7435 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7436 | goto out_not_finished; |
| 7437 | } |
| 7438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7439 | psli = &phba->sli; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7440 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7441 | mbx = &pmbox->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7442 | status = MBX_SUCCESS; |
| 7443 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7444 | if (phba->link_state == LPFC_HBA_ERROR) { |
| 7445 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7446 | |
| 7447 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7448 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7449 | "(%d):0311 Mailbox command x%x cannot " |
| 7450 | "issue Data: x%x x%x\n", |
| 7451 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7452 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7453 | goto out_not_finished; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7454 | } |
| 7455 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7456 | if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7457 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || |
| 7458 | !(hc_copy & HC_MBINT_ENA)) { |
| 7459 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7460 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7461 | "(%d):2528 Mailbox command x%x cannot " |
| 7462 | "issue Data: x%x x%x\n", |
| 7463 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7464 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7465 | goto out_not_finished; |
| 7466 | } |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 7467 | } |
| 7468 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7469 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7470 | /* Polling for a mbox command when another one is already active |
| 7471 | * is not allowed in SLI. Also, the driver must have established |
| 7472 | * SLI2 mode to queue and process multiple mbox commands. |
| 7473 | */ |
| 7474 | |
| 7475 | if (flag & MBX_POLL) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7476 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7477 | |
| 7478 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7479 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7480 | "(%d):2529 Mailbox command x%x " |
| 7481 | "cannot issue Data: x%x x%x\n", |
| 7482 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7483 | pmbox->u.mb.mbxCommand, |
| 7484 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7485 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7486 | } |
| 7487 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7488 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7489 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7490 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7491 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7492 | "(%d):2530 Mailbox command x%x " |
| 7493 | "cannot issue Data: x%x x%x\n", |
| 7494 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7495 | pmbox->u.mb.mbxCommand, |
| 7496 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7497 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7498 | } |
| 7499 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7500 | /* Another mailbox command is still being processed, queue this |
| 7501 | * command to be processed later. |
| 7502 | */ |
| 7503 | lpfc_mbox_put(phba, pmbox); |
| 7504 | |
| 7505 | /* Mbox cmd issue - BUSY */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7506 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7507 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7508 | "x%x x%x x%x x%x\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7509 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 7510 | mbx->mbxCommand, |
| 7511 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7512 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7513 | |
| 7514 | psli->slistat.mbox_busy++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7515 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7516 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7517 | if (pmbox->vport) { |
| 7518 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7519 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7520 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7521 | (uint32_t)mbx->mbxCommand, |
| 7522 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7523 | } |
| 7524 | else { |
| 7525 | lpfc_debugfs_disc_trc(phba->pport, |
| 7526 | LPFC_DISC_TRC_MBOX, |
| 7527 | "MBOX Bsy: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7528 | (uint32_t)mbx->mbxCommand, |
| 7529 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7530 | } |
| 7531 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7532 | return MBX_BUSY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7533 | } |
| 7534 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7535 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7536 | |
| 7537 | /* If we are not polling, we MUST be in SLI2 mode */ |
| 7538 | if (flag != MBX_POLL) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7539 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7540 | (mbx->mbxCommand != MBX_KILL_BOARD)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7541 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7542 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7543 | /* Mbox command <mbxCommand> cannot issue */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7544 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 7545 | "(%d):2531 Mailbox command x%x " |
| 7546 | "cannot issue Data: x%x x%x\n", |
| 7547 | pmbox->vport ? pmbox->vport->vpi : 0, |
| 7548 | pmbox->u.mb.mbxCommand, |
| 7549 | psli->sli_flag, flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7550 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7551 | } |
| 7552 | /* timeout active mbox command */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 7553 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7554 | 1000); |
| 7555 | mod_timer(&psli->mbox_tmo, jiffies + timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7556 | } |
| 7557 | |
| 7558 | /* Mailbox cmd <cmd> issue */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 7559 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7560 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7561 | "x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 7562 | pmbox->vport ? pmbox->vport->vpi : 0, |
James Smart | e92974f | 2017-06-01 21:07:06 -0700 | [diff] [blame] | 7563 | mbx->mbxCommand, |
| 7564 | phba->pport ? phba->pport->port_state : 0xff, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 7565 | psli->sli_flag, flag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7566 | |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7567 | if (mbx->mbxCommand != MBX_HEARTBEAT) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7568 | if (pmbox->vport) { |
| 7569 | lpfc_debugfs_disc_trc(pmbox->vport, |
| 7570 | LPFC_DISC_TRC_MBOX_VPORT, |
| 7571 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7572 | (uint32_t)mbx->mbxCommand, |
| 7573 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7574 | } |
| 7575 | else { |
| 7576 | lpfc_debugfs_disc_trc(phba->pport, |
| 7577 | LPFC_DISC_TRC_MBOX, |
| 7578 | "MBOX Send: cmd:x%x mb:x%x x%x", |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7579 | (uint32_t)mbx->mbxCommand, |
| 7580 | mbx->un.varWords[0], mbx->un.varWords[1]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7581 | } |
| 7582 | } |
| 7583 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7584 | psli->slistat.mbox_cmd++; |
| 7585 | evtctr = psli->slistat.mbox_event; |
| 7586 | |
| 7587 | /* next set own bit for the adapter and copy over command word */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7588 | mbx->mbxOwner = OWN_CHIP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7589 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7590 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7591 | /* Populate mbox extension offset word. */ |
| 7592 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7593 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7594 | = (uint8_t *)phba->mbox_ext |
| 7595 | - (uint8_t *)phba->mbox; |
| 7596 | } |
| 7597 | |
| 7598 | /* Copy the mailbox extension data */ |
| 7599 | if (pmbox->in_ext_byte_len && pmbox->context2) { |
| 7600 | lpfc_sli_pcimem_bcopy(pmbox->context2, |
| 7601 | (uint8_t *)phba->mbox_ext, |
| 7602 | pmbox->in_ext_byte_len); |
| 7603 | } |
| 7604 | /* Copy command data to host SLIM area */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7605 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7606 | } else { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7607 | /* Populate mbox extension offset word. */ |
| 7608 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7609 | *(((uint32_t *)mbx) + pmbox->mbox_offset_word) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7610 | = MAILBOX_HBA_EXT_OFFSET; |
| 7611 | |
| 7612 | /* Copy the mailbox extension data */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7613 | if (pmbox->in_ext_byte_len && pmbox->context2) |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7614 | lpfc_memcpy_to_slim(phba->MBslimaddr + |
| 7615 | MAILBOX_HBA_EXT_OFFSET, |
| 7616 | pmbox->context2, pmbox->in_ext_byte_len); |
| 7617 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7618 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7619 | /* copy command data into host mbox for cmpl */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7620 | lpfc_sli_pcimem_bcopy(mbx, phba->mbox, |
| 7621 | MAILBOX_CMD_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7622 | |
| 7623 | /* First copy mbox command data to HBA SLIM, skip past first |
| 7624 | word */ |
| 7625 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7626 | lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0], |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7627 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); |
| 7628 | |
| 7629 | /* Next copy over first word, with mbxOwner set */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7630 | ldata = *((uint32_t *)mbx); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7631 | to_slim = phba->MBslimaddr; |
| 7632 | writel(ldata, to_slim); |
| 7633 | readl(to_slim); /* flush */ |
| 7634 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7635 | if (mbx->mbxCommand == MBX_CONFIG_PORT) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7636 | /* switch over to host mailbox */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7637 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7638 | } |
| 7639 | |
| 7640 | wmb(); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7641 | |
| 7642 | switch (flag) { |
| 7643 | case MBX_NOWAIT: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7644 | /* Set up reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7645 | psli->mbox_active = pmbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7646 | /* Interrupt board to do it */ |
| 7647 | writel(CA_MBATT, phba->CAregaddr); |
| 7648 | readl(phba->CAregaddr); /* flush */ |
| 7649 | /* Don't wait for it to finish, just return */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7650 | break; |
| 7651 | |
| 7652 | case MBX_POLL: |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7653 | /* Set up null reference to mailbox command */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7654 | psli->mbox_active = NULL; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7655 | /* Interrupt board to do it */ |
| 7656 | writel(CA_MBATT, phba->CAregaddr); |
| 7657 | readl(phba->CAregaddr); /* flush */ |
| 7658 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7659 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7660 | /* First read mbox status word */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7661 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7662 | word0 = le32_to_cpu(word0); |
| 7663 | } else { |
| 7664 | /* First read mbox status word */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7665 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
| 7666 | spin_unlock_irqrestore(&phba->hbalock, |
| 7667 | drvr_flag); |
| 7668 | goto out_not_finished; |
| 7669 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7673 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7674 | spin_unlock_irqrestore(&phba->hbalock, |
| 7675 | drvr_flag); |
| 7676 | goto out_not_finished; |
| 7677 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7678 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
| 7679 | 1000) + jiffies; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7680 | i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7681 | /* Wait for command to complete */ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 7682 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
| 7683 | (!(ha_copy & HA_MBATT) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7684 | (phba->link_state > LPFC_WARM_START))) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7685 | if (time_after(jiffies, timeout)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7686 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7687 | spin_unlock_irqrestore(&phba->hbalock, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7688 | drvr_flag); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7689 | goto out_not_finished; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7690 | } |
| 7691 | |
| 7692 | /* Check if we took a mbox interrupt while we were |
| 7693 | polling */ |
| 7694 | if (((word0 & OWN_CHIP) != OWN_CHIP) |
| 7695 | && (evtctr != psli->slistat.mbox_event)) |
| 7696 | break; |
| 7697 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 7698 | if (i++ > 10) { |
| 7699 | spin_unlock_irqrestore(&phba->hbalock, |
| 7700 | drvr_flag); |
| 7701 | msleep(1); |
| 7702 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 7703 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7704 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7705 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7706 | /* First copy command data */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7707 | word0 = *((uint32_t *)phba->mbox); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7708 | word0 = le32_to_cpu(word0); |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7709 | if (mbx->mbxCommand == MBX_CONFIG_PORT) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7710 | MAILBOX_t *slimmb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7711 | uint32_t slimword0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7712 | /* Check real SLIM for any errors */ |
| 7713 | slimword0 = readl(phba->MBslimaddr); |
| 7714 | slimmb = (MAILBOX_t *) & slimword0; |
| 7715 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
| 7716 | && slimmb->mbxStatus) { |
| 7717 | psli->sli_flag &= |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7718 | ~LPFC_SLI_ACTIVE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7719 | word0 = slimword0; |
| 7720 | } |
| 7721 | } |
| 7722 | } else { |
| 7723 | /* First copy command data */ |
| 7724 | word0 = readl(phba->MBslimaddr); |
| 7725 | } |
| 7726 | /* Read the HBA Host Attention Register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7727 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
| 7728 | spin_unlock_irqrestore(&phba->hbalock, |
| 7729 | drvr_flag); |
| 7730 | goto out_not_finished; |
| 7731 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7732 | } |
| 7733 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7734 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7735 | /* copy results back to user */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7736 | lpfc_sli_pcimem_bcopy(phba->mbox, mbx, |
| 7737 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7738 | /* Copy the mailbox extension data */ |
| 7739 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7740 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, |
| 7741 | pmbox->context2, |
| 7742 | pmbox->out_ext_byte_len); |
| 7743 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7744 | } else { |
| 7745 | /* First copy command data */ |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7746 | lpfc_memcpy_from_slim(mbx, phba->MBslimaddr, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7747 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7748 | /* Copy the mailbox extension data */ |
| 7749 | if (pmbox->out_ext_byte_len && pmbox->context2) { |
| 7750 | lpfc_memcpy_from_slim(pmbox->context2, |
| 7751 | phba->MBslimaddr + |
| 7752 | MAILBOX_HBA_EXT_OFFSET, |
| 7753 | pmbox->out_ext_byte_len); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7754 | } |
| 7755 | } |
| 7756 | |
| 7757 | writel(HA_MBATT, phba->HAregaddr); |
| 7758 | readl(phba->HAregaddr); /* flush */ |
| 7759 | |
| 7760 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
Randy Dunlap | bf07bde | 2013-02-22 10:23:54 -0800 | [diff] [blame] | 7761 | status = mbx->mbxStatus; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7762 | } |
| 7763 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7764 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 7765 | return status; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7766 | |
| 7767 | out_not_finished: |
| 7768 | if (processing_queue) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7769 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 7770 | lpfc_mbox_cmpl_put(phba, pmbox); |
| 7771 | } |
| 7772 | return MBX_NOT_FINISHED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7773 | } |
| 7774 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7775 | /** |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7776 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command |
| 7777 | * @phba: Pointer to HBA context object. |
| 7778 | * |
| 7779 | * The function blocks the posting of SLI4 asynchronous mailbox commands from |
| 7780 | * the driver internal pending mailbox queue. It will then try to wait out the |
| 7781 | * possible outstanding mailbox command before return. |
| 7782 | * |
| 7783 | * Returns: |
| 7784 | * 0 - the outstanding mailbox command completed; otherwise, the wait for |
| 7785 | * the outstanding mailbox command timed out. |
| 7786 | **/ |
| 7787 | static int |
| 7788 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) |
| 7789 | { |
| 7790 | struct lpfc_sli *psli = &phba->sli; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7791 | int rc = 0; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7792 | unsigned long timeout = 0; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7793 | |
| 7794 | /* Mark the asynchronous mailbox command posting as blocked */ |
| 7795 | spin_lock_irq(&phba->hbalock); |
| 7796 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7797 | /* Determine how long we might wait for the active mailbox |
| 7798 | * command to be gracefully completed by firmware. |
| 7799 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7800 | if (phba->sli.mbox_active) |
| 7801 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 7802 | phba->sli.mbox_active) * |
| 7803 | 1000) + jiffies; |
| 7804 | spin_unlock_irq(&phba->hbalock); |
| 7805 | |
James Smart | e8d3c3b | 2013-10-10 12:21:30 -0400 | [diff] [blame] | 7806 | /* Make sure the mailbox is really active */ |
| 7807 | if (timeout) |
| 7808 | lpfc_sli4_process_missed_mbox_completions(phba); |
| 7809 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 7810 | /* Wait for the outstnading mailbox command to complete */ |
| 7811 | while (phba->sli.mbox_active) { |
| 7812 | /* Check active mailbox complete status every 2ms */ |
| 7813 | msleep(2); |
| 7814 | if (time_after(jiffies, timeout)) { |
| 7815 | /* Timeout, marked the outstanding cmd not complete */ |
| 7816 | rc = 1; |
| 7817 | break; |
| 7818 | } |
| 7819 | } |
| 7820 | |
| 7821 | /* Can not cleanly block async mailbox command, fails it */ |
| 7822 | if (rc) { |
| 7823 | spin_lock_irq(&phba->hbalock); |
| 7824 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7825 | spin_unlock_irq(&phba->hbalock); |
| 7826 | } |
| 7827 | return rc; |
| 7828 | } |
| 7829 | |
| 7830 | /** |
| 7831 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command |
| 7832 | * @phba: Pointer to HBA context object. |
| 7833 | * |
| 7834 | * The function unblocks and resume posting of SLI4 asynchronous mailbox |
| 7835 | * commands from the driver internal pending mailbox queue. It makes sure |
| 7836 | * that there is no outstanding mailbox command before resuming posting |
| 7837 | * asynchronous mailbox commands. If, for any reason, there is outstanding |
| 7838 | * mailbox command, it will try to wait it out before resuming asynchronous |
| 7839 | * mailbox command posting. |
| 7840 | **/ |
| 7841 | static void |
| 7842 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) |
| 7843 | { |
| 7844 | struct lpfc_sli *psli = &phba->sli; |
| 7845 | |
| 7846 | spin_lock_irq(&phba->hbalock); |
| 7847 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 7848 | /* Asynchronous mailbox posting is not blocked, do nothing */ |
| 7849 | spin_unlock_irq(&phba->hbalock); |
| 7850 | return; |
| 7851 | } |
| 7852 | |
| 7853 | /* Outstanding synchronous mailbox command is guaranteed to be done, |
| 7854 | * successful or timeout, after timing-out the outstanding mailbox |
| 7855 | * command shall always be removed, so just unblock posting async |
| 7856 | * mailbox command and resume |
| 7857 | */ |
| 7858 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; |
| 7859 | spin_unlock_irq(&phba->hbalock); |
| 7860 | |
| 7861 | /* wake up worker thread to post asynchronlous mailbox command */ |
| 7862 | lpfc_worker_wake_up(phba); |
| 7863 | } |
| 7864 | |
| 7865 | /** |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7866 | * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready |
| 7867 | * @phba: Pointer to HBA context object. |
| 7868 | * @mboxq: Pointer to mailbox object. |
| 7869 | * |
| 7870 | * The function waits for the bootstrap mailbox register ready bit from |
| 7871 | * port for twice the regular mailbox command timeout value. |
| 7872 | * |
| 7873 | * 0 - no timeout on waiting for bootstrap mailbox register ready. |
| 7874 | * MBXERR_ERROR - wait for bootstrap mailbox register timed out. |
| 7875 | **/ |
| 7876 | static int |
| 7877 | lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7878 | { |
| 7879 | uint32_t db_ready; |
| 7880 | unsigned long timeout; |
| 7881 | struct lpfc_register bmbx_reg; |
| 7882 | |
| 7883 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
| 7884 | * 1000) + jiffies; |
| 7885 | |
| 7886 | do { |
| 7887 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); |
| 7888 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); |
| 7889 | if (!db_ready) |
| 7890 | msleep(2); |
| 7891 | |
| 7892 | if (time_after(jiffies, timeout)) |
| 7893 | return MBXERR_ERROR; |
| 7894 | } while (!db_ready); |
| 7895 | |
| 7896 | return 0; |
| 7897 | } |
| 7898 | |
| 7899 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7900 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox |
| 7901 | * @phba: Pointer to HBA context object. |
| 7902 | * @mboxq: Pointer to mailbox object. |
| 7903 | * |
| 7904 | * The function posts a mailbox to the port. The mailbox is expected |
| 7905 | * to be comletely filled in and ready for the port to operate on it. |
| 7906 | * This routine executes a synchronous completion operation on the |
| 7907 | * mailbox by polling for its completion. |
| 7908 | * |
| 7909 | * The caller must not be holding any locks when calling this routine. |
| 7910 | * |
| 7911 | * Returns: |
| 7912 | * MBX_SUCCESS - mailbox posted successfully |
| 7913 | * Any of the MBX error values. |
| 7914 | **/ |
| 7915 | static int |
| 7916 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 7917 | { |
| 7918 | int rc = MBX_SUCCESS; |
| 7919 | unsigned long iflag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7920 | uint32_t mcqe_status; |
| 7921 | uint32_t mbx_cmnd; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7922 | struct lpfc_sli *psli = &phba->sli; |
| 7923 | struct lpfc_mqe *mb = &mboxq->u.mqe; |
| 7924 | struct lpfc_bmbx_create *mbox_rgn; |
| 7925 | struct dma_address *dma_address; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7926 | |
| 7927 | /* |
| 7928 | * Only one mailbox can be active to the bootstrap mailbox region |
| 7929 | * at a time and there is no queueing provided. |
| 7930 | */ |
| 7931 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 7932 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 7933 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7934 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7935 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7936 | "cannot issue Data: x%x x%x\n", |
| 7937 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 7938 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 7939 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 7940 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7941 | psli->sli_flag, MBX_POLL); |
| 7942 | return MBXERR_ERROR; |
| 7943 | } |
| 7944 | /* The server grabs the token and owns it until release */ |
| 7945 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 7946 | phba->sli.mbox_active = mboxq; |
| 7947 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 7948 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7949 | /* wait for bootstrap mbox register for readyness */ |
| 7950 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7951 | if (rc) |
| 7952 | goto exit; |
| 7953 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7954 | /* |
| 7955 | * Initialize the bootstrap memory region to avoid stale data areas |
| 7956 | * in the mailbox post. Then copy the caller's mailbox contents to |
| 7957 | * the bmbx mailbox region. |
| 7958 | */ |
| 7959 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); |
| 7960 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); |
| 7961 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, |
| 7962 | sizeof(struct lpfc_mqe)); |
| 7963 | |
| 7964 | /* Post the high mailbox dma address to the port and wait for ready. */ |
| 7965 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7966 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); |
| 7967 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7968 | /* wait for bootstrap mbox register for hi-address write done */ |
| 7969 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7970 | if (rc) |
| 7971 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7972 | |
| 7973 | /* Post the low mailbox dma address to the port. */ |
| 7974 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7975 | |
James Smart | 2d843ed | 2012-09-29 11:29:06 -0400 | [diff] [blame] | 7976 | /* wait for bootstrap mbox register for low address write done */ |
| 7977 | rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq); |
| 7978 | if (rc) |
| 7979 | goto exit; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7980 | |
| 7981 | /* |
| 7982 | * Read the CQ to ensure the mailbox has completed. |
| 7983 | * If so, update the mailbox status so that the upper layers |
| 7984 | * can complete the request normally. |
| 7985 | */ |
| 7986 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, |
| 7987 | sizeof(struct lpfc_mqe)); |
| 7988 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; |
| 7989 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, |
| 7990 | sizeof(struct lpfc_mcqe)); |
| 7991 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7992 | /* |
| 7993 | * When the CQE status indicates a failure and the mailbox status |
| 7994 | * indicates success then copy the CQE status into the mailbox status |
| 7995 | * (and prefix it with x4000). |
| 7996 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7997 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7998 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
| 7999 | bf_set(lpfc_mqe_status, mb, |
| 8000 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8001 | rc = MBXERR_ERROR; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8002 | } else |
| 8003 | lpfc_sli4_swap_str(phba, mboxq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8004 | |
| 8005 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8006 | "(%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] | 8007 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
| 8008 | " 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] | 8009 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
| 8010 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8011 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8012 | bf_get(lpfc_mqe_status, mb), |
| 8013 | mb->un.mb_words[0], mb->un.mb_words[1], |
| 8014 | mb->un.mb_words[2], mb->un.mb_words[3], |
| 8015 | mb->un.mb_words[4], mb->un.mb_words[5], |
| 8016 | mb->un.mb_words[6], mb->un.mb_words[7], |
| 8017 | mb->un.mb_words[8], mb->un.mb_words[9], |
| 8018 | mb->un.mb_words[10], mb->un.mb_words[11], |
| 8019 | mb->un.mb_words[12], mboxq->mcqe.word0, |
| 8020 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, |
| 8021 | mboxq->mcqe.trailer); |
| 8022 | exit: |
| 8023 | /* We are holding the token, no needed for lock when release */ |
| 8024 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 8025 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8026 | phba->sli.mbox_active = NULL; |
| 8027 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 8028 | return rc; |
| 8029 | } |
| 8030 | |
| 8031 | /** |
| 8032 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware |
| 8033 | * @phba: Pointer to HBA context object. |
| 8034 | * @pmbox: Pointer to mailbox object. |
| 8035 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8036 | * |
| 8037 | * This function is called by discovery code and HBA management code to submit |
| 8038 | * a mailbox command to firmware with SLI-4 interface spec. |
| 8039 | * |
| 8040 | * Return codes the caller owns the mailbox command after the return of the |
| 8041 | * function. |
| 8042 | **/ |
| 8043 | static int |
| 8044 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, |
| 8045 | uint32_t flag) |
| 8046 | { |
| 8047 | struct lpfc_sli *psli = &phba->sli; |
| 8048 | unsigned long iflags; |
| 8049 | int rc; |
| 8050 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 8051 | /* dump from issue mailbox command if setup */ |
| 8052 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); |
| 8053 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8054 | rc = lpfc_mbox_dev_check(phba); |
| 8055 | if (unlikely(rc)) { |
| 8056 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8057 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8058 | "cannot issue Data: x%x x%x\n", |
| 8059 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8060 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8061 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8062 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 8063 | psli->sli_flag, flag); |
| 8064 | goto out_not_finished; |
| 8065 | } |
| 8066 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8067 | /* Detect polling mode and jump to a handler */ |
| 8068 | if (!phba->sli4_hba.intr_enable) { |
| 8069 | if (flag == MBX_POLL) |
| 8070 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8071 | else |
| 8072 | rc = -EIO; |
| 8073 | if (rc != MBX_SUCCESS) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8074 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8075 | "(%d):2541 Mailbox command x%x " |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8076 | "(x%x/x%x) failure: " |
| 8077 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8078 | "Data: x%x x%x\n,", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8079 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8080 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8081 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8082 | mboxq), |
| 8083 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8084 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8085 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8086 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8087 | bf_get(lpfc_mcqe_ext_status, |
| 8088 | &mboxq->mcqe), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8089 | psli->sli_flag, flag); |
| 8090 | return rc; |
| 8091 | } else if (flag == MBX_POLL) { |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8092 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
| 8093 | "(%d):2542 Try to issue mailbox command " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8094 | "x%x (x%x/x%x) synchronously ahead of async" |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8095 | "mailbox command queue: x%x x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8096 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8097 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8098 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8099 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8100 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8101 | /* Try to block the asynchronous mailbox posting */ |
| 8102 | rc = lpfc_sli4_async_mbox_block(phba); |
| 8103 | if (!rc) { |
| 8104 | /* Successfully blocked, now issue sync mbox cmd */ |
| 8105 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); |
| 8106 | if (rc != MBX_SUCCESS) |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8107 | lpfc_printf_log(phba, KERN_WARNING, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8108 | LOG_MBOX | LOG_SLI, |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8109 | "(%d):2597 Sync Mailbox command " |
| 8110 | "x%x (x%x/x%x) failure: " |
| 8111 | "mqe_sta: x%x mcqe_sta: x%x/x%x " |
| 8112 | "Data: x%x x%x\n,", |
| 8113 | mboxq->vport ? mboxq->vport->vpi : 0, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8114 | mboxq->u.mb.mbxCommand, |
| 8115 | lpfc_sli_config_mbox_subsys_get(phba, |
| 8116 | mboxq), |
| 8117 | lpfc_sli_config_mbox_opcode_get(phba, |
| 8118 | mboxq), |
James Smart | cc459f1 | 2012-05-09 21:18:30 -0400 | [diff] [blame] | 8119 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
| 8120 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), |
| 8121 | bf_get(lpfc_mcqe_ext_status, |
| 8122 | &mboxq->mcqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8123 | psli->sli_flag, flag); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8124 | /* Unblock the async mailbox posting afterward */ |
| 8125 | lpfc_sli4_async_mbox_unblock(phba); |
| 8126 | } |
| 8127 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8128 | } |
| 8129 | |
| 8130 | /* Now, interrupt mode asynchrous mailbox command */ |
| 8131 | rc = lpfc_mbox_cmd_check(phba, mboxq); |
| 8132 | if (rc) { |
| 8133 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8134 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8135 | "cannot issue Data: x%x x%x\n", |
| 8136 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8137 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8138 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8139 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8140 | psli->sli_flag, flag); |
| 8141 | goto out_not_finished; |
| 8142 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8143 | |
| 8144 | /* Put the mailbox command to the driver internal FIFO */ |
| 8145 | psli->slistat.mbox_busy++; |
| 8146 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8147 | lpfc_mbox_put(phba, mboxq); |
| 8148 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8149 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
| 8150 | "(%d):0354 Mbox cmd issue - Enqueue Data: " |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8151 | "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] | 8152 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
| 8153 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8154 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8155 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8156 | phba->pport->port_state, |
| 8157 | psli->sli_flag, MBX_NOWAIT); |
| 8158 | /* Wake up worker thread to transport mailbox command from head */ |
| 8159 | lpfc_worker_wake_up(phba); |
| 8160 | |
| 8161 | return MBX_BUSY; |
| 8162 | |
| 8163 | out_not_finished: |
| 8164 | return MBX_NOT_FINISHED; |
| 8165 | } |
| 8166 | |
| 8167 | /** |
| 8168 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device |
| 8169 | * @phba: Pointer to HBA context object. |
| 8170 | * |
| 8171 | * This function is called by worker thread to send a mailbox command to |
| 8172 | * SLI4 HBA firmware. |
| 8173 | * |
| 8174 | **/ |
| 8175 | int |
| 8176 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) |
| 8177 | { |
| 8178 | struct lpfc_sli *psli = &phba->sli; |
| 8179 | LPFC_MBOXQ_t *mboxq; |
| 8180 | int rc = MBX_SUCCESS; |
| 8181 | unsigned long iflags; |
| 8182 | struct lpfc_mqe *mqe; |
| 8183 | uint32_t mbx_cmnd; |
| 8184 | |
| 8185 | /* Check interrupt mode before post async mailbox command */ |
| 8186 | if (unlikely(!phba->sli4_hba.intr_enable)) |
| 8187 | return MBX_NOT_FINISHED; |
| 8188 | |
| 8189 | /* Check for mailbox command service token */ |
| 8190 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 8191 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
| 8192 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8193 | return MBX_NOT_FINISHED; |
| 8194 | } |
| 8195 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 8196 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8197 | return MBX_NOT_FINISHED; |
| 8198 | } |
| 8199 | if (unlikely(phba->sli.mbox_active)) { |
| 8200 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8201 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 8202 | "0384 There is pending active mailbox cmd\n"); |
| 8203 | return MBX_NOT_FINISHED; |
| 8204 | } |
| 8205 | /* Take the mailbox command service token */ |
| 8206 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
| 8207 | |
| 8208 | /* Get the next mailbox command from head of queue */ |
| 8209 | mboxq = lpfc_mbox_get(phba); |
| 8210 | |
| 8211 | /* If no more mailbox command waiting for post, we're done */ |
| 8212 | if (!mboxq) { |
| 8213 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8214 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8215 | return MBX_SUCCESS; |
| 8216 | } |
| 8217 | phba->sli.mbox_active = mboxq; |
| 8218 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8219 | |
| 8220 | /* Check device readiness for posting mailbox command */ |
| 8221 | rc = lpfc_mbox_dev_check(phba); |
| 8222 | if (unlikely(rc)) |
| 8223 | /* Driver clean routine will clean up pending mailbox */ |
| 8224 | goto out_not_finished; |
| 8225 | |
| 8226 | /* Prepare the mbox command to be posted */ |
| 8227 | mqe = &mboxq->u.mqe; |
| 8228 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); |
| 8229 | |
| 8230 | /* Start timer for the mbox_tmo and log some mailbox post messages */ |
| 8231 | mod_timer(&psli->mbox_tmo, (jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 8232 | msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq)))); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8233 | |
| 8234 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8235 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8236 | "x%x x%x\n", |
| 8237 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8238 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8239 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8240 | phba->pport->port_state, psli->sli_flag); |
| 8241 | |
| 8242 | if (mbx_cmnd != MBX_HEARTBEAT) { |
| 8243 | if (mboxq->vport) { |
| 8244 | lpfc_debugfs_disc_trc(mboxq->vport, |
| 8245 | LPFC_DISC_TRC_MBOX_VPORT, |
| 8246 | "MBOX Send vport: cmd:x%x mb:x%x x%x", |
| 8247 | mbx_cmnd, mqe->un.mb_words[0], |
| 8248 | mqe->un.mb_words[1]); |
| 8249 | } else { |
| 8250 | lpfc_debugfs_disc_trc(phba->pport, |
| 8251 | LPFC_DISC_TRC_MBOX, |
| 8252 | "MBOX Send: cmd:x%x mb:x%x x%x", |
| 8253 | mbx_cmnd, mqe->un.mb_words[0], |
| 8254 | mqe->un.mb_words[1]); |
| 8255 | } |
| 8256 | } |
| 8257 | psli->slistat.mbox_cmd++; |
| 8258 | |
| 8259 | /* Post the mailbox command to the port */ |
| 8260 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); |
| 8261 | if (rc != MBX_SUCCESS) { |
| 8262 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8263 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8264 | "cannot issue Data: x%x x%x\n", |
| 8265 | mboxq->vport ? mboxq->vport->vpi : 0, |
| 8266 | mboxq->u.mb.mbxCommand, |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 8267 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
| 8268 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8269 | psli->sli_flag, MBX_NOWAIT); |
| 8270 | goto out_not_finished; |
| 8271 | } |
| 8272 | |
| 8273 | return rc; |
| 8274 | |
| 8275 | out_not_finished: |
| 8276 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 8277 | if (phba->sli.mbox_active) { |
| 8278 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 8279 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 8280 | /* Release the token */ |
| 8281 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 8282 | phba->sli.mbox_active = NULL; |
| 8283 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8284 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 8285 | |
| 8286 | return MBX_NOT_FINISHED; |
| 8287 | } |
| 8288 | |
| 8289 | /** |
| 8290 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command |
| 8291 | * @phba: Pointer to HBA context object. |
| 8292 | * @pmbox: Pointer to mailbox object. |
| 8293 | * @flag: Flag indicating how the mailbox need to be processed. |
| 8294 | * |
| 8295 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from |
| 8296 | * the API jump table function pointer from the lpfc_hba struct. |
| 8297 | * |
| 8298 | * Return codes the caller owns the mailbox command after the return of the |
| 8299 | * function. |
| 8300 | **/ |
| 8301 | int |
| 8302 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) |
| 8303 | { |
| 8304 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); |
| 8305 | } |
| 8306 | |
| 8307 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8308 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8309 | * @phba: The hba struct for which this call is being executed. |
| 8310 | * @dev_grp: The HBA PCI-Device group number. |
| 8311 | * |
| 8312 | * This routine sets up the mbox interface API function jump table in @phba |
| 8313 | * struct. |
| 8314 | * Returns: 0 - success, -ENODEV - failure. |
| 8315 | **/ |
| 8316 | int |
| 8317 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8318 | { |
| 8319 | |
| 8320 | switch (dev_grp) { |
| 8321 | case LPFC_PCI_DEV_LP: |
| 8322 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; |
| 8323 | phba->lpfc_sli_handle_slow_ring_event = |
| 8324 | lpfc_sli_handle_slow_ring_event_s3; |
| 8325 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; |
| 8326 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; |
| 8327 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; |
| 8328 | break; |
| 8329 | case LPFC_PCI_DEV_OC: |
| 8330 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; |
| 8331 | phba->lpfc_sli_handle_slow_ring_event = |
| 8332 | lpfc_sli_handle_slow_ring_event_s4; |
| 8333 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; |
| 8334 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; |
| 8335 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; |
| 8336 | break; |
| 8337 | default: |
| 8338 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8339 | "1420 Invalid HBA PCI-device group: 0x%x\n", |
| 8340 | dev_grp); |
| 8341 | return -ENODEV; |
| 8342 | break; |
| 8343 | } |
| 8344 | return 0; |
| 8345 | } |
| 8346 | |
| 8347 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8348 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8349 | * @phba: Pointer to HBA context object. |
| 8350 | * @pring: Pointer to driver SLI ring object. |
| 8351 | * @piocb: Pointer to address of newly added command iocb. |
| 8352 | * |
| 8353 | * This function is called with hbalock held to add a command |
| 8354 | * iocb to the txq when SLI layer cannot submit the command iocb |
| 8355 | * to the ring. |
| 8356 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 8357 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8358 | __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] | 8359 | struct lpfc_iocbq *piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8360 | { |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8361 | lockdep_assert_held(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8362 | /* Insert the caller's iocb in the txq tail for later processing. */ |
| 8363 | list_add_tail(&piocb->list, &pring->txq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8364 | } |
| 8365 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8366 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 8367 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8368 | * @phba: Pointer to HBA context object. |
| 8369 | * @pring: Pointer to driver SLI ring object. |
| 8370 | * @piocb: Pointer to address of newly added command iocb. |
| 8371 | * |
| 8372 | * This function is called with hbalock held before a new |
| 8373 | * iocb is submitted to the firmware. This function checks |
| 8374 | * txq to flush the iocbs in txq to Firmware before |
| 8375 | * submitting new iocbs to the Firmware. |
| 8376 | * If there are iocbs in the txq which need to be submitted |
| 8377 | * to firmware, lpfc_sli_next_iocb returns the first element |
| 8378 | * of the txq after dequeuing it from txq. |
| 8379 | * If there is no iocb in the txq then the function will return |
| 8380 | * *piocb and *piocb is set to NULL. Caller needs to check |
| 8381 | * *piocb to find if there are more commands in the txq. |
| 8382 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8383 | static struct lpfc_iocbq * |
| 8384 | 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] | 8385 | struct lpfc_iocbq **piocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8386 | { |
| 8387 | struct lpfc_iocbq * nextiocb; |
| 8388 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8389 | lockdep_assert_held(&phba->hbalock); |
| 8390 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8391 | nextiocb = lpfc_sli_ringtx_get(phba, pring); |
| 8392 | if (!nextiocb) { |
| 8393 | nextiocb = *piocb; |
| 8394 | *piocb = NULL; |
| 8395 | } |
| 8396 | |
| 8397 | return nextiocb; |
| 8398 | } |
| 8399 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8400 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8401 | * __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] | 8402 | * @phba: Pointer to HBA context object. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8403 | * @ring_number: SLI ring number to issue iocb on. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8404 | * @piocb: Pointer to command iocb. |
| 8405 | * @flag: Flag indicating if this command can be put into txq. |
| 8406 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8407 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
| 8408 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
| 8409 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
| 8410 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
| 8411 | * this function allows only iocbs for posting buffers. This function finds |
| 8412 | * next available slot in the command ring and posts the command to the |
| 8413 | * available slot and writes the port attention register to request HBA start |
| 8414 | * processing new iocb. If there is no slot available in the ring and |
| 8415 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
| 8416 | * the function returns IOCB_BUSY. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8417 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8418 | * This function is called with hbalock held. The function will return success |
| 8419 | * after it successfully submit the iocb to firmware or after adding to the |
| 8420 | * txq. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8421 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 8422 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8423 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8424 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 8425 | { |
| 8426 | struct lpfc_iocbq *nextiocb; |
| 8427 | IOCB_t *iocb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8428 | struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8429 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 8430 | lockdep_assert_held(&phba->hbalock); |
| 8431 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8432 | if (piocb->iocb_cmpl && (!piocb->vport) && |
| 8433 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
| 8434 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { |
| 8435 | lpfc_printf_log(phba, KERN_ERR, |
| 8436 | LOG_SLI | LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 8437 | "1807 IOCB x%x failed. No vport\n", |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8438 | piocb->iocb.ulpCommand); |
| 8439 | dump_stack(); |
| 8440 | return IOCB_ERROR; |
| 8441 | } |
| 8442 | |
| 8443 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 8444 | /* If the PCI channel is in offline state, do not post iocbs. */ |
| 8445 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 8446 | return IOCB_ERROR; |
| 8447 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 8448 | /* If HBA has a deferred error attention, fail the iocb. */ |
| 8449 | if (unlikely(phba->hba_flag & DEFER_ERATT)) |
| 8450 | return IOCB_ERROR; |
| 8451 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8452 | /* |
| 8453 | * We should never get an IOCB if we are in a < LINK_DOWN state |
| 8454 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8455 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8456 | return IOCB_ERROR; |
| 8457 | |
| 8458 | /* |
| 8459 | * Check to see if we are blocking IOCB processing because of a |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8460 | * outstanding event. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8461 | */ |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 8462 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8463 | goto iocb_busy; |
| 8464 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8465 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8466 | /* |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8467 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8468 | * can be issued if the link is not up. |
| 8469 | */ |
| 8470 | switch (piocb->iocb.ulpCommand) { |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8471 | case CMD_GEN_REQUEST64_CR: |
| 8472 | case CMD_GEN_REQUEST64_CX: |
| 8473 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || |
| 8474 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 8475 | FC_RCTL_DD_UNSOL_CMD) || |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 8476 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
| 8477 | MENLO_TRANSPORT_TYPE)) |
| 8478 | |
| 8479 | goto iocb_busy; |
| 8480 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8481 | case CMD_QUE_RING_BUF_CN: |
| 8482 | case CMD_QUE_RING_BUF64_CN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8483 | /* |
| 8484 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring |
| 8485 | * completion, iocb_cmpl MUST be 0. |
| 8486 | */ |
| 8487 | if (piocb->iocb_cmpl) |
| 8488 | piocb->iocb_cmpl = NULL; |
| 8489 | /*FALLTHROUGH*/ |
| 8490 | case CMD_CREATE_XRI_CR: |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 8491 | case CMD_CLOSE_XRI_CN: |
| 8492 | case CMD_CLOSE_XRI_CX: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8493 | break; |
| 8494 | default: |
| 8495 | goto iocb_busy; |
| 8496 | } |
| 8497 | |
| 8498 | /* |
| 8499 | * For FCP commands, we must be in a state where we can process link |
| 8500 | * attention events. |
| 8501 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8502 | } else if (unlikely(pring->ringno == LPFC_FCP_RING && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8503 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8504 | goto iocb_busy; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8505 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8506 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8507 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
| 8508 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) |
| 8509 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); |
| 8510 | |
| 8511 | if (iocb) |
| 8512 | lpfc_sli_update_ring(phba, pring); |
| 8513 | else |
| 8514 | lpfc_sli_update_full_ring(phba, pring); |
| 8515 | |
| 8516 | if (!piocb) |
| 8517 | return IOCB_SUCCESS; |
| 8518 | |
| 8519 | goto out_busy; |
| 8520 | |
| 8521 | iocb_busy: |
| 8522 | pring->stats.iocb_cmd_delay++; |
| 8523 | |
| 8524 | out_busy: |
| 8525 | |
| 8526 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 8527 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8528 | return IOCB_SUCCESS; |
| 8529 | } |
| 8530 | |
| 8531 | return IOCB_BUSY; |
| 8532 | } |
| 8533 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8534 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8535 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
| 8536 | * @phba: Pointer to HBA context object. |
| 8537 | * @piocb: Pointer to command iocb. |
| 8538 | * @sglq: Pointer to the scatter gather queue object. |
| 8539 | * |
| 8540 | * This routine converts the bpl or bde that is in the IOCB |
| 8541 | * to a sgl list for the sli4 hardware. The physical address |
| 8542 | * of the bpl/bde is converted back to a virtual address. |
| 8543 | * If the IOCB contains a BPL then the list of BDE's is |
| 8544 | * converted to sli4_sge's. If the IOCB contains a single |
| 8545 | * BDE then it is converted to a single sli_sge. |
| 8546 | * The IOCB is still in cpu endianess so the contents of |
| 8547 | * the bpl can be used without byte swapping. |
| 8548 | * |
| 8549 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 8550 | **/ |
| 8551 | static uint16_t |
| 8552 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 8553 | struct lpfc_sglq *sglq) |
| 8554 | { |
| 8555 | uint16_t xritag = NO_XRI; |
| 8556 | struct ulp_bde64 *bpl = NULL; |
| 8557 | struct ulp_bde64 bde; |
| 8558 | struct sli4_sge *sgl = NULL; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8559 | struct lpfc_dmabuf *dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8560 | IOCB_t *icmd; |
| 8561 | int numBdes = 0; |
| 8562 | int i = 0; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8563 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 8564 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8565 | |
| 8566 | if (!piocbq || !sglq) |
| 8567 | return xritag; |
| 8568 | |
| 8569 | sgl = (struct sli4_sge *)sglq->sgl; |
| 8570 | icmd = &piocbq->iocb; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8571 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
| 8572 | return sglq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8573 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
| 8574 | numBdes = icmd->un.genreq64.bdl.bdeSize / |
| 8575 | sizeof(struct ulp_bde64); |
| 8576 | /* The addrHigh and addrLow fields within the IOCB |
| 8577 | * have not been byteswapped yet so there is no |
| 8578 | * need to swap them back. |
| 8579 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8580 | if (piocbq->context3) |
| 8581 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; |
| 8582 | else |
| 8583 | return xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8584 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8585 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8586 | if (!bpl) |
| 8587 | return xritag; |
| 8588 | |
| 8589 | for (i = 0; i < numBdes; i++) { |
| 8590 | /* Should already be byte swapped. */ |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8591 | sgl->addr_hi = bpl->addrHigh; |
| 8592 | sgl->addr_lo = bpl->addrLow; |
| 8593 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8594 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8595 | if ((i+1) == numBdes) |
| 8596 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8597 | else |
| 8598 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8599 | /* swap the size field back to the cpu so we |
| 8600 | * can assign it to the sgl. |
| 8601 | */ |
| 8602 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 8603 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8604 | /* The offsets in the sgl need to be accumulated |
| 8605 | * separately for the request and reply lists. |
| 8606 | * The request is always first, the reply follows. |
| 8607 | */ |
| 8608 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { |
| 8609 | /* add up the reply sg entries */ |
| 8610 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 8611 | inbound++; |
| 8612 | /* first inbound? reset the offset */ |
| 8613 | if (inbound == 1) |
| 8614 | offset = 0; |
| 8615 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 8616 | bf_set(lpfc_sli4_sge_type, sgl, |
| 8617 | LPFC_SGE_TYPE_DATA); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 8618 | offset += bde.tus.f.bdeSize; |
| 8619 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 8620 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8621 | bpl++; |
| 8622 | sgl++; |
| 8623 | } |
| 8624 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { |
| 8625 | /* The addrHigh and addrLow fields of the BDE have not |
| 8626 | * been byteswapped yet so they need to be swapped |
| 8627 | * before putting them in the sgl. |
| 8628 | */ |
| 8629 | sgl->addr_hi = |
| 8630 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); |
| 8631 | sgl->addr_lo = |
| 8632 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8633 | sgl->word2 = le32_to_cpu(sgl->word2); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8634 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 8635 | sgl->word2 = cpu_to_le32(sgl->word2); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8636 | sgl->sge_len = |
| 8637 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8638 | } |
| 8639 | return sglq->sli4_xritag; |
| 8640 | } |
| 8641 | |
| 8642 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8643 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
| 8644 | * @phba: Pointer to HBA context object. |
| 8645 | * @piocb: Pointer to command iocb. |
| 8646 | * @wqe: Pointer to the work queue entry. |
| 8647 | * |
| 8648 | * This routine converts the iocb command to its Work Queue Entry |
| 8649 | * equivalent. The wqe pointer should not have any fields set when |
| 8650 | * this routine is called because it will memcpy over them. |
| 8651 | * This routine does not set the CQ_ID or the WQEC bits in the |
| 8652 | * wqe. |
| 8653 | * |
| 8654 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
| 8655 | **/ |
| 8656 | static int |
| 8657 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
| 8658 | union lpfc_wqe *wqe) |
| 8659 | { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8660 | uint32_t xmit_len = 0, total_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8661 | uint8_t ct = 0; |
| 8662 | uint32_t fip; |
| 8663 | uint32_t abort_tag; |
| 8664 | uint8_t command_type = ELS_COMMAND_NON_FIP; |
| 8665 | uint8_t cmnd; |
| 8666 | uint16_t xritag; |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 8667 | uint16_t abrt_iotag; |
| 8668 | struct lpfc_iocbq *abrtiocbq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8669 | struct ulp_bde64 *bpl = NULL; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8670 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8671 | int numBdes, i; |
| 8672 | struct ulp_bde64 bde; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 8673 | struct lpfc_nodelist *ndlp; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8674 | uint32_t *pcmd; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8675 | uint32_t if_type; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8676 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 8677 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8678 | /* The fcp commands will set command type */ |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8679 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8680 | command_type = FCP_COMMAND; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8681 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 8682 | command_type = ELS_COMMAND_FIP; |
| 8683 | else |
| 8684 | command_type = ELS_COMMAND_NON_FIP; |
| 8685 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8686 | if (phba->fcp_embed_io) |
| 8687 | memset(wqe, 0, sizeof(union lpfc_wqe128)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8688 | /* Some of the fields are in the right position already */ |
| 8689 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 8690 | if (iocbq->iocb.ulpCommand != CMD_SEND_FRAME) { |
| 8691 | /* The ct field has moved so reset */ |
| 8692 | wqe->generic.wqe_com.word7 = 0; |
| 8693 | wqe->generic.wqe_com.word10 = 0; |
| 8694 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8695 | |
| 8696 | abort_tag = (uint32_t) iocbq->iotag; |
| 8697 | xritag = iocbq->sli4_xritag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8698 | /* words0-2 bpl convert bde */ |
| 8699 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8700 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 8701 | sizeof(struct ulp_bde64); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8702 | bpl = (struct ulp_bde64 *) |
| 8703 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; |
| 8704 | if (!bpl) |
| 8705 | return IOCB_ERROR; |
| 8706 | |
| 8707 | /* Should already be byte swapped. */ |
| 8708 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); |
| 8709 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); |
| 8710 | /* swap the size field back to the cpu so we |
| 8711 | * can assign it to the sgl. |
| 8712 | */ |
| 8713 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8714 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
| 8715 | total_len = 0; |
| 8716 | for (i = 0; i < numBdes; i++) { |
| 8717 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 8718 | total_len += bde.tus.f.bdeSize; |
| 8719 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8720 | } else |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8721 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8722 | |
| 8723 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
| 8724 | cmnd = iocbq->iocb.ulpCommand; |
| 8725 | |
| 8726 | switch (iocbq->iocb.ulpCommand) { |
| 8727 | case CMD_ELS_REQUEST64_CR: |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 8728 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
| 8729 | ndlp = iocbq->context_un.ndlp; |
| 8730 | else |
| 8731 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8732 | if (!iocbq->iocb.ulpLe) { |
| 8733 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 8734 | "2007 Only Limited Edition cmd Format" |
| 8735 | " supported 0x%x\n", |
| 8736 | iocbq->iocb.ulpCommand); |
| 8737 | return IOCB_ERROR; |
| 8738 | } |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8739 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8740 | wqe->els_req.payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8741 | /* Els_reguest64 has a TMO */ |
| 8742 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, |
| 8743 | iocbq->iocb.ulpTimeout); |
| 8744 | /* Need a VF for word 4 set the vf bit*/ |
| 8745 | bf_set(els_req64_vf, &wqe->els_req, 0); |
| 8746 | /* And a VFID for word 12 */ |
| 8747 | bf_set(els_req64_vfid, &wqe->els_req, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8748 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8749 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8750 | iocbq->iocb.ulpContext); |
| 8751 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); |
| 8752 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8753 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8754 | if (command_type == ELS_COMMAND_FIP) |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8755 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
| 8756 | >> LPFC_FIP_ELS_ID_SHIFT); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8757 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 8758 | iocbq->context2)->virt); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8759 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8760 | &phba->sli4_hba.sli_intf); |
| 8761 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8762 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 8763 | *pcmd == ELS_CMD_SCR || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 8764 | *pcmd == ELS_CMD_FDISC || |
James Smart | bdcd2b9 | 2012-03-01 22:33:52 -0500 | [diff] [blame] | 8765 | *pcmd == ELS_CMD_LOGO || |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8766 | *pcmd == ELS_CMD_PLOGI)) { |
| 8767 | bf_set(els_req64_sp, &wqe->els_req, 1); |
| 8768 | bf_set(els_req64_sid, &wqe->els_req, |
| 8769 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 8770 | if ((*pcmd == ELS_CMD_FLOGI) && |
| 8771 | !(phba->fc_topology == |
| 8772 | LPFC_TOPOLOGY_LOOP)) |
| 8773 | bf_set(els_req64_sid, &wqe->els_req, 0); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8774 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
| 8775 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
James Smart | a7dd9c0 | 2012-05-09 21:16:50 -0400 | [diff] [blame] | 8776 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 8777 | } else if (pcmd && iocbq->context1) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8778 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
| 8779 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
| 8780 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
| 8781 | } |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 8782 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8783 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
| 8784 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8785 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
| 8786 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); |
| 8787 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); |
| 8788 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); |
| 8789 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 8790 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 8791 | wqe->els_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8792 | break; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8793 | case CMD_XMIT_SEQUENCE64_CX: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8794 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
| 8795 | iocbq->iocb.un.ulpWord[3]); |
| 8796 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8797 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8798 | /* The entire sequence is transmitted for this IOCB */ |
| 8799 | xmit_len = total_len; |
| 8800 | cmnd = CMD_XMIT_SEQUENCE64_CR; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8801 | if (phba->link_flag & LS_LOOPBACK_MODE) |
| 8802 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8803 | case CMD_XMIT_SEQUENCE64_CR: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8804 | /* word3 iocb=io_tag32 wqe=reserved */ |
| 8805 | wqe->xmit_sequence.rsvd3 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8806 | /* word4 relative_offset memcpy */ |
| 8807 | /* word5 r_ctl/df_ctl memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8808 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
| 8809 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); |
| 8810 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, |
| 8811 | LPFC_WQE_IOD_WRITE); |
| 8812 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, |
| 8813 | LPFC_WQE_LENLOC_WORD12); |
| 8814 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8815 | wqe->xmit_sequence.xmit_len = xmit_len; |
| 8816 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8817 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8818 | case CMD_XMIT_BCAST64_CN: |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8819 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
| 8820 | wqe->xmit_bcast64.seq_payload_len = xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8821 | /* word4 iocb=rsvd wqe=rsvd */ |
| 8822 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ |
| 8823 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8824 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8825 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8826 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
| 8827 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8828 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, |
| 8829 | LPFC_WQE_LENLOC_WORD3); |
| 8830 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8831 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8832 | case CMD_FCP_IWRITE64_CR: |
| 8833 | command_type = FCP_COMMAND_DATA_OUT; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8834 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8835 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8836 | bf_set(payload_offset_len, &wqe->fcp_iwrite, |
| 8837 | xmit_len + sizeof(struct fcp_rsp)); |
| 8838 | bf_set(cmd_buff_len, &wqe->fcp_iwrite, |
| 8839 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8840 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8841 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8842 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, |
| 8843 | iocbq->iocb.ulpFCP2Rcvy); |
| 8844 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); |
| 8845 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8846 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8847 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, |
| 8848 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8849 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8850 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8851 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8852 | bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8853 | bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1); |
| 8854 | if (iocbq->priority) { |
| 8855 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8856 | (iocbq->priority << 1)); |
| 8857 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8858 | bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com, |
| 8859 | (phba->cfg_XLanePriority << 1)); |
| 8860 | } |
| 8861 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8862 | /* Note, word 10 is already initialized to 0 */ |
| 8863 | |
| 8864 | if (phba->fcp_embed_io) { |
| 8865 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8866 | struct sli4_sge *sgl; |
| 8867 | union lpfc_wqe128 *wqe128; |
| 8868 | struct fcp_cmnd *fcp_cmnd; |
| 8869 | uint32_t *ptr; |
| 8870 | |
| 8871 | /* 128 byte wqe support here */ |
| 8872 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8873 | |
| 8874 | lpfc_cmd = iocbq->context1; |
| 8875 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8876 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8877 | |
| 8878 | /* Word 0-2 - FCP_CMND */ |
| 8879 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8880 | BUFF_TYPE_BDE_IMMED; |
| 8881 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8882 | wqe128->generic.bde.addrHigh = 0; |
| 8883 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8884 | |
| 8885 | bf_set(wqe_wqes, &wqe128->fcp_iwrite.wqe_com, 1); |
| 8886 | |
| 8887 | /* Word 22-29 FCP CMND Payload */ |
| 8888 | ptr = &wqe128->words[22]; |
| 8889 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8890 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8891 | break; |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8892 | case CMD_FCP_IREAD64_CR: |
| 8893 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8894 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8895 | bf_set(payload_offset_len, &wqe->fcp_iread, |
| 8896 | xmit_len + sizeof(struct fcp_rsp)); |
| 8897 | bf_set(cmd_buff_len, &wqe->fcp_iread, |
| 8898 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8899 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
| 8900 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ |
| 8901 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, |
| 8902 | iocbq->iocb.ulpFCP2Rcvy); |
| 8903 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 8904 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8905 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
| 8906 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, |
| 8907 | LPFC_WQE_LENLOC_WORD4); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8908 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 8909 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8910 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8911 | bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8912 | bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1); |
| 8913 | if (iocbq->priority) { |
| 8914 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8915 | (iocbq->priority << 1)); |
| 8916 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8917 | bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com, |
| 8918 | (phba->cfg_XLanePriority << 1)); |
| 8919 | } |
| 8920 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8921 | /* Note, word 10 is already initialized to 0 */ |
| 8922 | |
| 8923 | if (phba->fcp_embed_io) { |
| 8924 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8925 | struct sli4_sge *sgl; |
| 8926 | union lpfc_wqe128 *wqe128; |
| 8927 | struct fcp_cmnd *fcp_cmnd; |
| 8928 | uint32_t *ptr; |
| 8929 | |
| 8930 | /* 128 byte wqe support here */ |
| 8931 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8932 | |
| 8933 | lpfc_cmd = iocbq->context1; |
| 8934 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8935 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8936 | |
| 8937 | /* Word 0-2 - FCP_CMND */ |
| 8938 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8939 | BUFF_TYPE_BDE_IMMED; |
| 8940 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8941 | wqe128->generic.bde.addrHigh = 0; |
| 8942 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 8943 | |
| 8944 | bf_set(wqe_wqes, &wqe128->fcp_iread.wqe_com, 1); |
| 8945 | |
| 8946 | /* Word 22-29 FCP CMND Payload */ |
| 8947 | ptr = &wqe128->words[22]; |
| 8948 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 8949 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 8950 | break; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8951 | case CMD_FCP_ICMND64_CR: |
James Smart | 0ba4b21 | 2013-10-10 12:22:38 -0400 | [diff] [blame] | 8952 | /* word3 iocb=iotag wqe=payload_offset_len */ |
| 8953 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ |
| 8954 | bf_set(payload_offset_len, &wqe->fcp_icmd, |
| 8955 | xmit_len + sizeof(struct fcp_rsp)); |
| 8956 | bf_set(cmd_buff_len, &wqe->fcp_icmd, |
| 8957 | 0); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8958 | /* word3 iocb=IO_TAG wqe=reserved */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8959 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 8960 | /* Always open the exchange */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 8961 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); |
| 8962 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); |
| 8963 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); |
| 8964 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, |
| 8965 | LPFC_WQE_LENLOC_NONE); |
James Smart | 2a94aea | 2012-09-29 11:30:31 -0400 | [diff] [blame] | 8966 | bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com, |
| 8967 | iocbq->iocb.ulpFCP2Rcvy); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8968 | if (iocbq->iocb_flag & LPFC_IO_OAS) { |
| 8969 | bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1); |
James Smart | c92c841 | 2016-07-06 12:36:05 -0700 | [diff] [blame] | 8970 | bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1); |
| 8971 | if (iocbq->priority) { |
| 8972 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 8973 | (iocbq->priority << 1)); |
| 8974 | } else { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8975 | bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com, |
| 8976 | (phba->cfg_XLanePriority << 1)); |
| 8977 | } |
| 8978 | } |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 8979 | /* Note, word 10 is already initialized to 0 */ |
| 8980 | |
| 8981 | if (phba->fcp_embed_io) { |
| 8982 | struct lpfc_scsi_buf *lpfc_cmd; |
| 8983 | struct sli4_sge *sgl; |
| 8984 | union lpfc_wqe128 *wqe128; |
| 8985 | struct fcp_cmnd *fcp_cmnd; |
| 8986 | uint32_t *ptr; |
| 8987 | |
| 8988 | /* 128 byte wqe support here */ |
| 8989 | wqe128 = (union lpfc_wqe128 *)wqe; |
| 8990 | |
| 8991 | lpfc_cmd = iocbq->context1; |
| 8992 | sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl; |
| 8993 | fcp_cmnd = lpfc_cmd->fcp_cmnd; |
| 8994 | |
| 8995 | /* Word 0-2 - FCP_CMND */ |
| 8996 | wqe128->generic.bde.tus.f.bdeFlags = |
| 8997 | BUFF_TYPE_BDE_IMMED; |
| 8998 | wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len; |
| 8999 | wqe128->generic.bde.addrHigh = 0; |
| 9000 | wqe128->generic.bde.addrLow = 88; /* Word 22 */ |
| 9001 | |
| 9002 | bf_set(wqe_wqes, &wqe128->fcp_icmd.wqe_com, 1); |
| 9003 | |
| 9004 | /* Word 22-29 FCP CMND Payload */ |
| 9005 | ptr = &wqe128->words[22]; |
| 9006 | memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd)); |
| 9007 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9008 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9009 | case CMD_GEN_REQUEST64_CR: |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9010 | /* For this command calculate the xmit length of the |
| 9011 | * request bde. |
| 9012 | */ |
| 9013 | xmit_len = 0; |
| 9014 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
| 9015 | sizeof(struct ulp_bde64); |
| 9016 | for (i = 0; i < numBdes; i++) { |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9017 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9018 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 9019 | break; |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 9020 | xmit_len += bde.tus.f.bdeSize; |
| 9021 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9022 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
| 9023 | wqe->gen_req.request_payload_len = xmit_len; |
| 9024 | /* word4 iocb=parameter wqe=relative_offset memcpy */ |
| 9025 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9026 | /* word6 context tag copied in memcpy */ |
| 9027 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { |
| 9028 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
| 9029 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9030 | "2015 Invalid CT %x command 0x%x\n", |
| 9031 | ct, iocbq->iocb.ulpCommand); |
| 9032 | return IOCB_ERROR; |
| 9033 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9034 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
| 9035 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); |
| 9036 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); |
| 9037 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); |
| 9038 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); |
| 9039 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); |
| 9040 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 9041 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 9042 | wqe->gen_req.max_response_payload_len = total_len - xmit_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9043 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9044 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9045 | case CMD_XMIT_ELS_RSP64_CX: |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 9046 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9047 | /* words0-2 BDE memcpy */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9048 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
| 9049 | wqe->xmit_els_rsp.response_payload_len = xmit_len; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9050 | /* word4 */ |
| 9051 | wqe->xmit_els_rsp.word4 = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9052 | /* word5 iocb=rsvd wge=did */ |
| 9053 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9054 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
| 9055 | |
| 9056 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9057 | &phba->sli4_hba.sli_intf); |
| 9058 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 9059 | if (iocbq->vport->fc_flag & FC_PT2PT) { |
| 9060 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9061 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
| 9062 | iocbq->vport->fc_myDID); |
| 9063 | if (iocbq->vport->fc_myDID == Fabric_DID) { |
| 9064 | bf_set(wqe_els_did, |
| 9065 | &wqe->xmit_els_rsp.wqe_dest, 0); |
| 9066 | } |
| 9067 | } |
| 9068 | } |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9069 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
| 9070 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9071 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); |
| 9072 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9073 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9074 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9075 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9076 | phba->vpi_ids[iocbq->vport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9077 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9078 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); |
| 9079 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9080 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, |
| 9081 | LPFC_WQE_LENLOC_WORD3); |
| 9082 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9083 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
| 9084 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9085 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
| 9086 | iocbq->context2)->virt); |
| 9087 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9088 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
| 9089 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9090 | iocbq->vport->fc_myDID); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 9091 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
| 9092 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9093 | phba->vpi_ids[phba->pport->vpi]); |
| 9094 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9095 | command_type = OTHER_COMMAND; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9096 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9097 | case CMD_CLOSE_XRI_CN: |
| 9098 | case CMD_ABORT_XRI_CN: |
| 9099 | case CMD_ABORT_XRI_CX: |
| 9100 | /* words 0-2 memcpy should be 0 rserved */ |
| 9101 | /* port will send abts */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9102 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
| 9103 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { |
| 9104 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; |
| 9105 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; |
| 9106 | } else |
| 9107 | fip = 0; |
| 9108 | |
| 9109 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9110 | /* |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 9111 | * The link is down, or the command was ELS_FIP |
| 9112 | * so the fw does not need to send abts |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9113 | * on the wire. |
| 9114 | */ |
| 9115 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); |
| 9116 | else |
| 9117 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); |
| 9118 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9119 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
| 9120 | wqe->abort_cmd.rsrvd5 = 0; |
| 9121 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9122 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
| 9123 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9124 | /* |
| 9125 | * The abort handler will send us CMD_ABORT_XRI_CN or |
| 9126 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX |
| 9127 | */ |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9128 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 9129 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); |
| 9130 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, |
| 9131 | LPFC_WQE_LENLOC_NONE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9132 | cmnd = CMD_ABORT_XRI_CX; |
| 9133 | command_type = OTHER_COMMAND; |
| 9134 | xritag = 0; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9135 | break; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9136 | case CMD_XMIT_BLS_RSP64_CX: |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9137 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9138 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9139 | * we re-construct this WQE here based on information in |
| 9140 | * iocbq from scratch. |
| 9141 | */ |
| 9142 | memset(wqe, 0, sizeof(union lpfc_wqe)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9143 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9144 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9145 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
| 9146 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9147 | LPFC_ABTS_UNSOL_INT) { |
| 9148 | /* ABTS sent by initiator to CT exchange, the |
| 9149 | * RX_ID field will be filled with the newly |
| 9150 | * allocated responder XRI. |
| 9151 | */ |
| 9152 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
| 9153 | iocbq->sli4_xritag); |
| 9154 | } else { |
| 9155 | /* ABTS sent by responder to CT exchange, the |
| 9156 | * RX_ID field will be filled with the responder |
| 9157 | * RX_ID from ABTS. |
| 9158 | */ |
| 9159 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9160 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9161 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9162 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
| 9163 | 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] | 9164 | |
| 9165 | /* Use CT=VPI */ |
| 9166 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, |
| 9167 | ndlp->nlp_DID); |
| 9168 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, |
| 9169 | iocbq->iocb.ulpContext); |
| 9170 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9171 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9172 | phba->vpi_ids[phba->pport->vpi]); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9173 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
| 9174 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, |
| 9175 | LPFC_WQE_LENLOC_NONE); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9176 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
| 9177 | command_type = OTHER_COMMAND; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 9178 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
| 9179 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, |
| 9180 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); |
| 9181 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, |
| 9182 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); |
| 9183 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, |
| 9184 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); |
| 9185 | } |
| 9186 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9187 | break; |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 9188 | case CMD_SEND_FRAME: |
| 9189 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9190 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9191 | return 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9192 | case CMD_XRI_ABORTED_CX: |
| 9193 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9194 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
| 9195 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ |
| 9196 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ |
| 9197 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ |
| 9198 | default: |
| 9199 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 9200 | "2014 Invalid command 0x%x\n", |
| 9201 | iocbq->iocb.ulpCommand); |
| 9202 | return IOCB_ERROR; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 9203 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9204 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9205 | |
James Smart | 8012cc3 | 2012-10-31 14:44:49 -0400 | [diff] [blame] | 9206 | if (iocbq->iocb_flag & LPFC_IO_DIF_PASS) |
| 9207 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU); |
| 9208 | else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP) |
| 9209 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP); |
| 9210 | else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT) |
| 9211 | bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT); |
| 9212 | iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP | |
| 9213 | LPFC_IO_DIF_INSERT); |
James Smart | f0d9bcc | 2010-10-22 11:07:09 -0400 | [diff] [blame] | 9214 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
| 9215 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); |
| 9216 | wqe->generic.wqe_com.abort_tag = abort_tag; |
| 9217 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); |
| 9218 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); |
| 9219 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); |
| 9220 | 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] | 9221 | return 0; |
| 9222 | } |
| 9223 | |
| 9224 | /** |
| 9225 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb |
| 9226 | * @phba: Pointer to HBA context object. |
| 9227 | * @ring_number: SLI ring number to issue iocb on. |
| 9228 | * @piocb: Pointer to command iocb. |
| 9229 | * @flag: Flag indicating if this command can be put into txq. |
| 9230 | * |
| 9231 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue |
| 9232 | * an iocb command to an HBA with SLI-4 interface spec. |
| 9233 | * |
| 9234 | * This function is called with hbalock held. The function will return success |
| 9235 | * after it successfully submit the iocb to firmware or after adding to the |
| 9236 | * txq. |
| 9237 | **/ |
| 9238 | static int |
| 9239 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, |
| 9240 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9241 | { |
| 9242 | struct lpfc_sglq *sglq; |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9243 | union lpfc_wqe *wqe; |
| 9244 | union lpfc_wqe128 wqe128; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9245 | struct lpfc_queue *wq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9246 | struct lpfc_sli_ring *pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9247 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9248 | /* Get the WQ */ |
| 9249 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
| 9250 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
| 9251 | if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS))) |
| 9252 | wq = phba->sli4_hba.fcp_wq[piocb->hba_wqidx]; |
| 9253 | else |
| 9254 | wq = phba->sli4_hba.oas_wq; |
| 9255 | } else { |
| 9256 | wq = phba->sli4_hba.els_wq; |
| 9257 | } |
| 9258 | |
| 9259 | /* Get corresponding ring */ |
| 9260 | pring = wq->pring; |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 9261 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9262 | /* |
| 9263 | * The WQE can be either 64 or 128 bytes, |
| 9264 | * so allocate space on the stack assuming the largest. |
| 9265 | */ |
| 9266 | wqe = (union lpfc_wqe *)&wqe128; |
| 9267 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9268 | lockdep_assert_held(&phba->hbalock); |
| 9269 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9270 | if (piocb->sli4_xritag == NO_XRI) { |
| 9271 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9272 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9273 | sglq = NULL; |
| 9274 | else { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 9275 | if (!list_empty(&pring->txq)) { |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9276 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9277 | __lpfc_sli_ringtx_put(phba, |
| 9278 | pring, piocb); |
| 9279 | return IOCB_SUCCESS; |
| 9280 | } else { |
| 9281 | return IOCB_BUSY; |
| 9282 | } |
| 9283 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9284 | sglq = __lpfc_sli_get_els_sglq(phba, piocb); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9285 | if (!sglq) { |
| 9286 | if (!(flag & SLI_IOCB_RET_IOCB)) { |
| 9287 | __lpfc_sli_ringtx_put(phba, |
| 9288 | pring, |
| 9289 | piocb); |
| 9290 | return IOCB_SUCCESS; |
| 9291 | } else |
| 9292 | return IOCB_BUSY; |
| 9293 | } |
| 9294 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9295 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9296 | } else if (piocb->iocb_flag & LPFC_IO_FCP) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9297 | /* These IO's already have an XRI and a mapped sgl. */ |
| 9298 | sglq = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9299 | else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9300 | /* |
| 9301 | * This is a continuation of a commandi,(CX) so this |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9302 | * sglq is on the active list |
| 9303 | */ |
James Smart | edccdc1 | 2013-01-03 15:43:45 -0500 | [diff] [blame] | 9304 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9305 | if (!sglq) |
| 9306 | return IOCB_ERROR; |
| 9307 | } |
| 9308 | |
| 9309 | if (sglq) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9310 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9311 | piocb->sli4_xritag = sglq->sli4_xritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9312 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9313 | return IOCB_ERROR; |
| 9314 | } |
| 9315 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9316 | if (lpfc_sli4_iocb2wqe(phba, piocb, wqe)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9317 | return IOCB_ERROR; |
| 9318 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9319 | if (lpfc_sli4_wq_put(wq, wqe)) |
| 9320 | return IOCB_ERROR; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9321 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); |
| 9322 | |
| 9323 | return 0; |
| 9324 | } |
| 9325 | |
| 9326 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9327 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb |
| 9328 | * |
| 9329 | * This routine wraps the actual lockless version for issusing IOCB function |
| 9330 | * pointer from the lpfc_hba struct. |
| 9331 | * |
| 9332 | * Return codes: |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 9333 | * IOCB_ERROR - Error |
| 9334 | * IOCB_SUCCESS - Success |
| 9335 | * IOCB_BUSY - Busy |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9336 | **/ |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 9337 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9338 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
| 9339 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9340 | { |
| 9341 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9342 | } |
| 9343 | |
| 9344 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9345 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9346 | * @phba: The hba struct for which this call is being executed. |
| 9347 | * @dev_grp: The HBA PCI-Device group number. |
| 9348 | * |
| 9349 | * This routine sets up the SLI interface API function jump table in @phba |
| 9350 | * struct. |
| 9351 | * Returns: 0 - success, -ENODEV - failure. |
| 9352 | **/ |
| 9353 | int |
| 9354 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 9355 | { |
| 9356 | |
| 9357 | switch (dev_grp) { |
| 9358 | case LPFC_PCI_DEV_LP: |
| 9359 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; |
| 9360 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; |
| 9361 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 9362 | case LPFC_PCI_DEV_OC: |
| 9363 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; |
| 9364 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; |
| 9365 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9366 | default: |
| 9367 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9368 | "1419 Invalid HBA PCI-device group: 0x%x\n", |
| 9369 | dev_grp); |
| 9370 | return -ENODEV; |
| 9371 | break; |
| 9372 | } |
| 9373 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; |
| 9374 | return 0; |
| 9375 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9376 | |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9377 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9378 | * lpfc_sli4_calc_ring - Calculates which ring to use |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9379 | * @phba: Pointer to HBA context object. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9380 | * @piocb: Pointer to command iocb. |
| 9381 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9382 | * For SLI4 only, FCP IO can deferred to one fo many WQs, based on |
| 9383 | * hba_wqidx, thus we need to calculate the corresponding ring. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9384 | * 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] | 9385 | * aborting, we use command's hba_wqidx. |
James Smart | a1efe16 | 2015-05-21 13:55:20 -0400 | [diff] [blame] | 9386 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9387 | struct lpfc_sli_ring * |
| 9388 | lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9389 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9390 | if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9391 | if (!(phba->cfg_fof) || |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9392 | (!(piocb->iocb_flag & LPFC_IO_FOF))) { |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9393 | if (unlikely(!phba->sli4_hba.fcp_wq)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9394 | return NULL; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9395 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9396 | * for abort iocb hba_wqidx should already |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9397 | * be setup based on what work queue we used. |
| 9398 | */ |
Dick Kennedy | 8e036a9 | 2017-09-29 17:34:35 -0700 | [diff] [blame^] | 9399 | if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9400 | piocb->hba_wqidx = |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9401 | lpfc_sli4_scmd_to_wqidx_distr(phba, |
| 9402 | piocb->context1); |
Dick Kennedy | 8e036a9 | 2017-09-29 17:34:35 -0700 | [diff] [blame^] | 9403 | piocb->hba_wqidx = piocb->hba_wqidx % |
| 9404 | phba->cfg_fcp_io_channel; |
| 9405 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9406 | return phba->sli4_hba.fcp_wq[piocb->hba_wqidx]->pring; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 9407 | } else { |
| 9408 | if (unlikely(!phba->sli4_hba.oas_wq)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9409 | return NULL; |
| 9410 | piocb->hba_wqidx = 0; |
| 9411 | return phba->sli4_hba.oas_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9412 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9413 | } else { |
| 9414 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 9415 | return NULL; |
| 9416 | piocb->hba_wqidx = 0; |
| 9417 | return phba->sli4_hba.els_wq->pring; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9418 | } |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9419 | } |
| 9420 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9421 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9422 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9423 | * @phba: Pointer to HBA context object. |
| 9424 | * @pring: Pointer to driver SLI ring object. |
| 9425 | * @piocb: Pointer to command iocb. |
| 9426 | * @flag: Flag indicating if this command can be put into txq. |
| 9427 | * |
| 9428 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb |
| 9429 | * function. This function gets the hbalock and calls |
| 9430 | * __lpfc_sli_issue_iocb function and will return the error returned |
| 9431 | * by __lpfc_sli_issue_iocb function. This wrapper is used by |
| 9432 | * functions which do not hold hbalock. |
| 9433 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9434 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9435 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9436 | struct lpfc_iocbq *piocb, uint32_t flag) |
| 9437 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9438 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9439 | struct lpfc_sli_ring *pring; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9440 | struct lpfc_queue *fpeq; |
| 9441 | struct lpfc_eqe *eqe; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9442 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9443 | int rc, idx; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9444 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9445 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9446 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 9447 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9448 | return IOCB_ERROR; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9449 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9450 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 9451 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9452 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9453 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9454 | if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9455 | idx = piocb->hba_wqidx; |
| 9456 | hba_eq_hdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9457 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9458 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) { |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9459 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9460 | /* Get associated EQ with this index */ |
| 9461 | fpeq = phba->sli4_hba.hba_eq[idx]; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9462 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9463 | /* Turn off interrupts from this EQ */ |
| 9464 | lpfc_sli4_eq_clr_intr(fpeq); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9465 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9466 | /* |
| 9467 | * Process all the events on FCP EQ |
| 9468 | */ |
| 9469 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
| 9470 | lpfc_sli4_hba_handle_eqe(phba, |
| 9471 | eqe, idx); |
| 9472 | fpeq->EQ_processed++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9473 | } |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 9474 | |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 9475 | /* Always clear and re-arm the EQ */ |
| 9476 | lpfc_sli4_eq_release(fpeq, |
| 9477 | LPFC_QUEUE_REARM); |
| 9478 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9479 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9480 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9481 | } else { |
| 9482 | /* For now, SLI2/3 will still use hbalock */ |
| 9483 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9484 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
| 9485 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9486 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9487 | return rc; |
| 9488 | } |
| 9489 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9490 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9491 | * lpfc_extra_ring_setup - Extra ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9492 | * @phba: Pointer to HBA context object. |
| 9493 | * |
| 9494 | * This function is called while driver attaches with the |
| 9495 | * HBA to setup the extra ring. The extra ring is used |
| 9496 | * only when driver needs to support target mode functionality |
| 9497 | * or IP over FC functionalities. |
| 9498 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9499 | * This function is called with no lock held. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9500 | **/ |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9501 | static int |
| 9502 | lpfc_extra_ring_setup( struct lpfc_hba *phba) |
| 9503 | { |
| 9504 | struct lpfc_sli *psli; |
| 9505 | struct lpfc_sli_ring *pring; |
| 9506 | |
| 9507 | psli = &phba->sli; |
| 9508 | |
| 9509 | /* Adjust cmd/rsp ring iocb entries more evenly */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9510 | |
| 9511 | /* Take some away from the FCP ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9512 | pring = &psli->sli3_ring[LPFC_FCP_RING]; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9513 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9514 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9515 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9516 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9517 | |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9518 | /* and give them to the extra ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9519 | pring = &psli->sli3_ring[LPFC_EXTRA_RING]; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9520 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9521 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9522 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9523 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9524 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9525 | |
| 9526 | /* Setup default profile for this ring */ |
| 9527 | pring->iotag_max = 4096; |
| 9528 | pring->num_mask = 1; |
| 9529 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9530 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
| 9531 | pring->prt[0].type = phba->cfg_multi_ring_type; |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9532 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
| 9533 | return 0; |
| 9534 | } |
| 9535 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9536 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. |
| 9537 | * @phba: Pointer to HBA context object. |
| 9538 | * @iocbq: Pointer to iocb object. |
| 9539 | * |
| 9540 | * The async_event handler calls this routine when it receives |
| 9541 | * an ASYNC_STATUS_CN event from the port. The port generates |
| 9542 | * this event when an Abort Sequence request to an rport fails |
| 9543 | * twice in succession. The abort could be originated by the |
| 9544 | * driver or by the port. The ABTS could have been for an ELS |
| 9545 | * or FCP IO. The port only generates this event when an ABTS |
| 9546 | * fails to complete after one retry. |
| 9547 | */ |
| 9548 | static void |
| 9549 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, |
| 9550 | struct lpfc_iocbq *iocbq) |
| 9551 | { |
| 9552 | struct lpfc_nodelist *ndlp = NULL; |
| 9553 | uint16_t rpi = 0, vpi = 0; |
| 9554 | struct lpfc_vport *vport = NULL; |
| 9555 | |
| 9556 | /* The rpi in the ulpContext is vport-sensitive. */ |
| 9557 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; |
| 9558 | rpi = iocbq->iocb.ulpContext; |
| 9559 | |
| 9560 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9561 | "3092 Port generated ABTS async event " |
| 9562 | "on vpi %d rpi %d status 0x%x\n", |
| 9563 | vpi, rpi, iocbq->iocb.ulpStatus); |
| 9564 | |
| 9565 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 9566 | if (!vport) |
| 9567 | goto err_exit; |
| 9568 | ndlp = lpfc_findnode_rpi(vport, rpi); |
| 9569 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 9570 | goto err_exit; |
| 9571 | |
| 9572 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) |
| 9573 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9574 | return; |
| 9575 | |
| 9576 | err_exit: |
| 9577 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9578 | "3095 Event Context not found, no " |
| 9579 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", |
| 9580 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, |
| 9581 | vpi, rpi); |
| 9582 | } |
| 9583 | |
| 9584 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. |
| 9585 | * @phba: pointer to HBA context object. |
| 9586 | * @ndlp: nodelist pointer for the impacted rport. |
| 9587 | * @axri: pointer to the wcqe containing the failed exchange. |
| 9588 | * |
| 9589 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the |
| 9590 | * port. The port generates this event when an abort exchange request to an |
| 9591 | * rport fails twice in succession with no reply. The abort could be originated |
| 9592 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. |
| 9593 | */ |
| 9594 | void |
| 9595 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, |
| 9596 | struct lpfc_nodelist *ndlp, |
| 9597 | struct sli4_wcqe_xri_aborted *axri) |
| 9598 | { |
| 9599 | struct lpfc_vport *vport; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9600 | uint32_t ext_status = 0; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9601 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9602 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9603 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9604 | "3115 Node Context not found, driver " |
| 9605 | "ignoring abts err event\n"); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 9606 | return; |
| 9607 | } |
| 9608 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9609 | vport = ndlp->vport; |
| 9610 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9611 | "3116 Port generated FCP XRI ABORT event on " |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9612 | "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] | 9613 | ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi], |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9614 | bf_get(lpfc_wcqe_xa_xri, axri), |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9615 | bf_get(lpfc_wcqe_xa_status, axri), |
| 9616 | axri->parameter); |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9617 | |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9618 | /* |
| 9619 | * Catch the ABTS protocol failure case. Older OCe FW releases returned |
| 9620 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and |
| 9621 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. |
| 9622 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 9623 | ext_status = axri->parameter & IOERR_PARAM_MASK; |
James Smart | 5c1db2a | 2012-03-01 22:34:36 -0500 | [diff] [blame] | 9624 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && |
| 9625 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9626 | lpfc_sli_abts_recover_port(vport, ndlp); |
| 9627 | } |
| 9628 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9629 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 9630 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9631 | * @phba: Pointer to HBA context object. |
| 9632 | * @pring: Pointer to driver SLI ring object. |
| 9633 | * @iocbq: Pointer to iocb object. |
| 9634 | * |
| 9635 | * This function is called by the slow ring event handler |
| 9636 | * function when there is an ASYNC event iocb in the ring. |
| 9637 | * This function is called with no lock held. |
| 9638 | * Currently this function handles only temperature related |
| 9639 | * ASYNC events. The function decodes the temperature sensor |
| 9640 | * event message and posts events for the management applications. |
| 9641 | **/ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9642 | static void |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9643 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
| 9644 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) |
| 9645 | { |
| 9646 | IOCB_t *icmd; |
| 9647 | uint16_t evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9648 | struct temp_event temp_event_data; |
| 9649 | struct Scsi_Host *shost; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9650 | uint32_t *iocb_w; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9651 | |
| 9652 | icmd = &iocbq->iocb; |
| 9653 | evt_code = icmd->un.asyncstat.evt_code; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9654 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9655 | switch (evt_code) { |
| 9656 | case ASYNC_TEMP_WARN: |
| 9657 | case ASYNC_TEMP_SAFE: |
| 9658 | temp_event_data.data = (uint32_t) icmd->ulpContext; |
| 9659 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 9660 | if (evt_code == ASYNC_TEMP_WARN) { |
| 9661 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 9662 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9663 | "0347 Adapter is very hot, please take " |
| 9664 | "corrective action. temperature : %d Celsius\n", |
| 9665 | (uint32_t) icmd->ulpContext); |
| 9666 | } else { |
| 9667 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 9668 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, |
| 9669 | "0340 Adapter temperature is OK now. " |
| 9670 | "temperature : %d Celsius\n", |
| 9671 | (uint32_t) icmd->ulpContext); |
| 9672 | } |
| 9673 | |
| 9674 | /* Send temperature change event to applications */ |
| 9675 | shost = lpfc_shost_from_vport(phba->pport); |
| 9676 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 9677 | sizeof(temp_event_data), (char *) &temp_event_data, |
| 9678 | LPFC_NL_VENDOR_ID); |
| 9679 | break; |
| 9680 | case ASYNC_STATUS_CN: |
| 9681 | lpfc_sli_abts_err_handler(phba, iocbq); |
| 9682 | break; |
| 9683 | default: |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9684 | iocb_w = (uint32_t *) icmd; |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9685 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 9686 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 9687 | " evt_code 0x%x\n" |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9688 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
| 9689 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" |
| 9690 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" |
| 9691 | "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] | 9692 | pring->ringno, icmd->un.asyncstat.evt_code, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 9693 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
| 9694 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], |
| 9695 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], |
| 9696 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); |
| 9697 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 9698 | break; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9699 | } |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9700 | } |
| 9701 | |
| 9702 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9703 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9704 | * lpfc_sli4_setup - SLI ring setup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9705 | * @phba: Pointer to HBA context object. |
| 9706 | * |
| 9707 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 9708 | * number of iocbs per ring and iotags. This function is |
| 9709 | * called while driver attach to the HBA and before the |
| 9710 | * interrupts are enabled. So there is no need for locking. |
| 9711 | * |
| 9712 | * This function always returns 0. |
| 9713 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9714 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9715 | lpfc_sli4_setup(struct lpfc_hba *phba) |
| 9716 | { |
| 9717 | struct lpfc_sli_ring *pring; |
| 9718 | |
| 9719 | pring = phba->sli4_hba.els_wq->pring; |
| 9720 | pring->num_mask = LPFC_MAX_RING_MASK; |
| 9721 | pring->prt[0].profile = 0; /* Mask 0 */ |
| 9722 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9723 | pring->prt[0].type = FC_TYPE_ELS; |
| 9724 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
| 9725 | lpfc_els_unsol_event; |
| 9726 | pring->prt[1].profile = 0; /* Mask 1 */ |
| 9727 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9728 | pring->prt[1].type = FC_TYPE_ELS; |
| 9729 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
| 9730 | lpfc_els_unsol_event; |
| 9731 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9732 | /* NameServer Inquiry */ |
| 9733 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| 9734 | /* NameServer */ |
| 9735 | pring->prt[2].type = FC_TYPE_CT; |
| 9736 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
| 9737 | lpfc_ct_unsol_event; |
| 9738 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 9739 | /* NameServer response */ |
| 9740 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| 9741 | /* NameServer */ |
| 9742 | pring->prt[3].type = FC_TYPE_CT; |
| 9743 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
| 9744 | lpfc_ct_unsol_event; |
| 9745 | return 0; |
| 9746 | } |
| 9747 | |
| 9748 | /** |
| 9749 | * lpfc_sli_setup - SLI ring setup function |
| 9750 | * @phba: Pointer to HBA context object. |
| 9751 | * |
| 9752 | * lpfc_sli_setup sets up rings of the SLI interface with |
| 9753 | * number of iocbs per ring and iotags. This function is |
| 9754 | * called while driver attach to the HBA and before the |
| 9755 | * interrupts are enabled. So there is no need for locking. |
| 9756 | * |
| 9757 | * This function always returns 0. SLI3 only. |
| 9758 | **/ |
| 9759 | int |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9760 | lpfc_sli_setup(struct lpfc_hba *phba) |
| 9761 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9762 | int i, totiocbsize = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9763 | struct lpfc_sli *psli = &phba->sli; |
| 9764 | struct lpfc_sli_ring *pring; |
| 9765 | |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 9766 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9767 | psli->sli_flag = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9768 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9769 | psli->iocbq_lookup = NULL; |
| 9770 | psli->iocbq_lookup_len = 0; |
| 9771 | psli->last_iotag = 0; |
| 9772 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9773 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9774 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9775 | switch (i) { |
| 9776 | case LPFC_FCP_RING: /* ring 0 - FCP */ |
| 9777 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9778 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
| 9779 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; |
| 9780 | pring->sli.sli3.numCiocb += |
| 9781 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
| 9782 | pring->sli.sli3.numRiocb += |
| 9783 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; |
| 9784 | pring->sli.sli3.numCiocb += |
| 9785 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
| 9786 | pring->sli.sli3.numRiocb += |
| 9787 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; |
| 9788 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9789 | SLI3_IOCB_CMD_SIZE : |
| 9790 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9791 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9792 | SLI3_IOCB_RSP_SIZE : |
| 9793 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9794 | pring->iotag_ctr = 0; |
| 9795 | pring->iotag_max = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9796 | (phba->cfg_hba_queue_depth * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9797 | pring->fast_iotag = pring->iotag_max; |
| 9798 | pring->num_mask = 0; |
| 9799 | break; |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 9800 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9801 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9802 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
| 9803 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; |
| 9804 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9805 | SLI3_IOCB_CMD_SIZE : |
| 9806 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9807 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9808 | SLI3_IOCB_RSP_SIZE : |
| 9809 | SLI2_IOCB_RSP_SIZE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9810 | pring->iotag_max = phba->cfg_hba_queue_depth; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9811 | pring->num_mask = 0; |
| 9812 | break; |
| 9813 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ |
| 9814 | /* numCiocb and numRiocb are used in config_port */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9815 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
| 9816 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; |
| 9817 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9818 | SLI3_IOCB_CMD_SIZE : |
| 9819 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9820 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9821 | SLI3_IOCB_RSP_SIZE : |
| 9822 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9823 | pring->fast_iotag = 0; |
| 9824 | pring->iotag_ctr = 0; |
| 9825 | pring->iotag_max = 4096; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 9826 | pring->lpfc_sli_rcv_async_status = |
| 9827 | lpfc_sli_async_event_handler; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 9828 | pring->num_mask = LPFC_MAX_RING_MASK; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9829 | pring->prt[0].profile = 0; /* Mask 0 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9830 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
| 9831 | pring->prt[0].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9832 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9833 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9834 | pring->prt[1].profile = 0; /* Mask 1 */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9835 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
| 9836 | pring->prt[1].type = FC_TYPE_ELS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9837 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9838 | lpfc_els_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9839 | pring->prt[2].profile = 0; /* Mask 2 */ |
| 9840 | /* NameServer Inquiry */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9841 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9842 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9843 | pring->prt[2].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9844 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9845 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9846 | pring->prt[3].profile = 0; /* Mask 3 */ |
| 9847 | /* NameServer response */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9848 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9849 | /* NameServer */ |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 9850 | pring->prt[3].type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9851 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9852 | lpfc_ct_unsol_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9853 | break; |
| 9854 | } |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9855 | totiocbsize += (pring->sli.sli3.numCiocb * |
| 9856 | pring->sli.sli3.sizeCiocb) + |
| 9857 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9858 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 9859 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9860 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 9861 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
| 9862 | "SLI2 SLIM Data: x%x x%lx\n", |
| 9863 | phba->brd_no, totiocbsize, |
| 9864 | (unsigned long) MAX_SLIM_IOCB_SIZE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9865 | } |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 9866 | if (phba->cfg_multi_ring_support == 2) |
| 9867 | lpfc_extra_ring_setup(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9868 | |
| 9869 | return 0; |
| 9870 | } |
| 9871 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9872 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9873 | * lpfc_sli4_queue_init - Queue initialization function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9874 | * @phba: Pointer to HBA context object. |
| 9875 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9876 | * 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] | 9877 | * ring. This function also initializes ring indices of each ring. |
| 9878 | * This function is called during the initialization of the SLI |
| 9879 | * interface of an HBA. |
| 9880 | * This function is called with no lock held and always returns |
| 9881 | * 1. |
| 9882 | **/ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9883 | void |
| 9884 | lpfc_sli4_queue_init(struct lpfc_hba *phba) |
| 9885 | { |
| 9886 | struct lpfc_sli *psli; |
| 9887 | struct lpfc_sli_ring *pring; |
| 9888 | int i; |
| 9889 | |
| 9890 | psli = &phba->sli; |
| 9891 | spin_lock_irq(&phba->hbalock); |
| 9892 | INIT_LIST_HEAD(&psli->mboxq); |
| 9893 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| 9894 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 9895 | for (i = 0; i < phba->cfg_fcp_io_channel; i++) { |
| 9896 | pring = phba->sli4_hba.fcp_wq[i]->pring; |
| 9897 | pring->flag = 0; |
| 9898 | pring->ringno = LPFC_FCP_RING; |
| 9899 | INIT_LIST_HEAD(&pring->txq); |
| 9900 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9901 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9902 | spin_lock_init(&pring->ring_lock); |
| 9903 | } |
| 9904 | for (i = 0; i < phba->cfg_nvme_io_channel; i++) { |
| 9905 | pring = phba->sli4_hba.nvme_wq[i]->pring; |
| 9906 | pring->flag = 0; |
| 9907 | pring->ringno = LPFC_FCP_RING; |
| 9908 | INIT_LIST_HEAD(&pring->txq); |
| 9909 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9910 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9911 | spin_lock_init(&pring->ring_lock); |
| 9912 | } |
| 9913 | pring = phba->sli4_hba.els_wq->pring; |
| 9914 | pring->flag = 0; |
| 9915 | pring->ringno = LPFC_ELS_RING; |
| 9916 | INIT_LIST_HEAD(&pring->txq); |
| 9917 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9918 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9919 | spin_lock_init(&pring->ring_lock); |
| 9920 | |
| 9921 | if (phba->cfg_nvme_io_channel) { |
| 9922 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 9923 | pring->flag = 0; |
| 9924 | pring->ringno = LPFC_ELS_RING; |
| 9925 | INIT_LIST_HEAD(&pring->txq); |
| 9926 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9927 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9928 | spin_lock_init(&pring->ring_lock); |
| 9929 | } |
| 9930 | |
| 9931 | if (phba->cfg_fof) { |
| 9932 | pring = phba->sli4_hba.oas_wq->pring; |
| 9933 | pring->flag = 0; |
| 9934 | pring->ringno = LPFC_FCP_RING; |
| 9935 | INIT_LIST_HEAD(&pring->txq); |
| 9936 | INIT_LIST_HEAD(&pring->txcmplq); |
| 9937 | INIT_LIST_HEAD(&pring->iocb_continueq); |
| 9938 | spin_lock_init(&pring->ring_lock); |
| 9939 | } |
| 9940 | |
| 9941 | spin_unlock_irq(&phba->hbalock); |
| 9942 | } |
| 9943 | |
| 9944 | /** |
| 9945 | * lpfc_sli_queue_init - Queue initialization function |
| 9946 | * @phba: Pointer to HBA context object. |
| 9947 | * |
| 9948 | * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each |
| 9949 | * ring. This function also initializes ring indices of each ring. |
| 9950 | * This function is called during the initialization of the SLI |
| 9951 | * interface of an HBA. |
| 9952 | * This function is called with no lock held and always returns |
| 9953 | * 1. |
| 9954 | **/ |
| 9955 | void |
| 9956 | lpfc_sli_queue_init(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9957 | { |
| 9958 | struct lpfc_sli *psli; |
| 9959 | struct lpfc_sli_ring *pring; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 9960 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9961 | |
| 9962 | psli = &phba->sli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9963 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9964 | INIT_LIST_HEAD(&psli->mboxq); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 9965 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9966 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
| 9967 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9968 | pring = &psli->sli3_ring[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9969 | pring->ringno = i; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9970 | pring->sli.sli3.next_cmdidx = 0; |
| 9971 | pring->sli.sli3.local_getidx = 0; |
| 9972 | pring->sli.sli3.cmdidx = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9973 | INIT_LIST_HEAD(&pring->iocb_continueq); |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 9974 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9975 | INIT_LIST_HEAD(&pring->postbufq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9976 | pring->flag = 0; |
| 9977 | INIT_LIST_HEAD(&pring->txq); |
| 9978 | INIT_LIST_HEAD(&pring->txcmplq); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 9979 | spin_lock_init(&pring->ring_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9980 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9981 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9982 | } |
| 9983 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9984 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 9985 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system |
| 9986 | * @phba: Pointer to HBA context object. |
| 9987 | * |
| 9988 | * This routine flushes the mailbox command subsystem. It will unconditionally |
| 9989 | * flush all the mailbox commands in the three possible stages in the mailbox |
| 9990 | * command sub-system: pending mailbox command queue; the outstanding mailbox |
| 9991 | * command; and completed mailbox command queue. It is caller's responsibility |
| 9992 | * to make sure that the driver is in the proper state to flush the mailbox |
| 9993 | * command sub-system. Namely, the posting of mailbox commands into the |
| 9994 | * pending mailbox command queue from the various clients must be stopped; |
| 9995 | * either the HBA is in a state that it will never works on the outstanding |
| 9996 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding |
| 9997 | * mailbox command has been completed. |
| 9998 | **/ |
| 9999 | static void |
| 10000 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) |
| 10001 | { |
| 10002 | LIST_HEAD(completions); |
| 10003 | struct lpfc_sli *psli = &phba->sli; |
| 10004 | LPFC_MBOXQ_t *pmb; |
| 10005 | unsigned long iflag; |
| 10006 | |
| 10007 | /* Flush all the mailbox commands in the mbox system */ |
| 10008 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 10009 | /* The pending mailbox command queue */ |
| 10010 | list_splice_init(&phba->sli.mboxq, &completions); |
| 10011 | /* The outstanding active mailbox command */ |
| 10012 | if (psli->mbox_active) { |
| 10013 | list_add_tail(&psli->mbox_active->list, &completions); |
| 10014 | psli->mbox_active = NULL; |
| 10015 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10016 | } |
| 10017 | /* The completed mailbox command queue */ |
| 10018 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); |
| 10019 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 10020 | |
| 10021 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ |
| 10022 | while (!list_empty(&completions)) { |
| 10023 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); |
| 10024 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10025 | if (pmb->mbox_cmpl) |
| 10026 | pmb->mbox_cmpl(phba, pmb); |
| 10027 | } |
| 10028 | } |
| 10029 | |
| 10030 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10031 | * lpfc_sli_host_down - Vport cleanup function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10032 | * @vport: Pointer to virtual port object. |
| 10033 | * |
| 10034 | * lpfc_sli_host_down is called to clean up the resources |
| 10035 | * associated with a vport before destroying virtual |
| 10036 | * port data structures. |
| 10037 | * This function does following operations: |
| 10038 | * - Free discovery resources associated with this virtual |
| 10039 | * port. |
| 10040 | * - Free iocbs associated with this virtual port in |
| 10041 | * the txq. |
| 10042 | * - Send abort for all iocb commands associated with this |
| 10043 | * vport in txcmplq. |
| 10044 | * |
| 10045 | * This function is called with no lock held and always returns 1. |
| 10046 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10047 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10048 | lpfc_sli_host_down(struct lpfc_vport *vport) |
| 10049 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10050 | LIST_HEAD(completions); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10051 | struct lpfc_hba *phba = vport->phba; |
| 10052 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10053 | struct lpfc_queue *qp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10054 | struct lpfc_sli_ring *pring; |
| 10055 | struct lpfc_iocbq *iocb, *next_iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10056 | int i; |
| 10057 | unsigned long flags = 0; |
| 10058 | uint16_t prev_pring_flag; |
| 10059 | |
| 10060 | lpfc_cleanup_discovery_resources(vport); |
| 10061 | |
| 10062 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10063 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10064 | /* |
| 10065 | * Error everything on the txq since these iocbs |
| 10066 | * have not been given to the FW yet. |
| 10067 | * Also issue ABTS for everything on the txcmplq |
| 10068 | */ |
| 10069 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10070 | for (i = 0; i < psli->num_rings; i++) { |
| 10071 | pring = &psli->sli3_ring[i]; |
| 10072 | prev_pring_flag = pring->flag; |
| 10073 | /* Only slow rings */ |
| 10074 | if (pring->ringno == LPFC_ELS_RING) { |
| 10075 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10076 | /* Set the lpfc data pending flag */ |
| 10077 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10078 | } |
| 10079 | list_for_each_entry_safe(iocb, next_iocb, |
| 10080 | &pring->txq, list) { |
| 10081 | if (iocb->vport != vport) |
| 10082 | continue; |
| 10083 | list_move_tail(&iocb->list, &completions); |
| 10084 | } |
| 10085 | list_for_each_entry_safe(iocb, next_iocb, |
| 10086 | &pring->txcmplq, list) { |
| 10087 | if (iocb->vport != vport) |
| 10088 | continue; |
| 10089 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10090 | } |
| 10091 | pring->flag = prev_pring_flag; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10092 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10093 | } else { |
| 10094 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10095 | pring = qp->pring; |
| 10096 | if (!pring) |
| 10097 | continue; |
| 10098 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10099 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10100 | /* Set the lpfc data pending flag */ |
| 10101 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10102 | } |
| 10103 | prev_pring_flag = pring->flag; |
| 10104 | spin_lock_irq(&pring->ring_lock); |
| 10105 | list_for_each_entry_safe(iocb, next_iocb, |
| 10106 | &pring->txq, list) { |
| 10107 | if (iocb->vport != vport) |
| 10108 | continue; |
| 10109 | list_move_tail(&iocb->list, &completions); |
| 10110 | } |
| 10111 | spin_unlock_irq(&pring->ring_lock); |
| 10112 | list_for_each_entry_safe(iocb, next_iocb, |
| 10113 | &pring->txcmplq, list) { |
| 10114 | if (iocb->vport != vport) |
| 10115 | continue; |
| 10116 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| 10117 | } |
| 10118 | pring->flag = prev_pring_flag; |
| 10119 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10120 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10121 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10122 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10123 | /* Cancel all the IOCBs from the completions list */ |
| 10124 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10125 | IOERR_SLI_DOWN); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10126 | return 1; |
| 10127 | } |
| 10128 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10129 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10130 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10131 | * @phba: Pointer to HBA context object. |
| 10132 | * |
| 10133 | * This function cleans up all iocb, buffers, mailbox commands |
| 10134 | * while shutting down the HBA. This function is called with no |
| 10135 | * lock held and always returns 1. |
| 10136 | * This function does the following to cleanup driver resources: |
| 10137 | * - Free discovery resources for each virtual port |
| 10138 | * - Cleanup any pending fabric iocbs |
| 10139 | * - Iterate through the iocb txq and free each entry |
| 10140 | * in the list. |
| 10141 | * - Free up any buffer posted to the HBA |
| 10142 | * - Free mailbox commands in the mailbox queue. |
| 10143 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10144 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10145 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10146 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10147 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10148 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10149 | struct lpfc_queue *qp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10150 | struct lpfc_sli_ring *pring; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10151 | struct lpfc_dmabuf *buf_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10152 | unsigned long flags = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 10153 | int i; |
| 10154 | |
| 10155 | /* Shutdown the mailbox command sub-system */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10156 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10157 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10158 | lpfc_hba_down_prep(phba); |
| 10159 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10160 | lpfc_fabric_abort_hba(phba); |
| 10161 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10162 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10163 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10164 | /* |
| 10165 | * Error everything on the txq since these iocbs |
| 10166 | * have not been given to the FW yet. |
| 10167 | */ |
| 10168 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10169 | for (i = 0; i < psli->num_rings; i++) { |
| 10170 | pring = &psli->sli3_ring[i]; |
| 10171 | /* Only slow rings */ |
| 10172 | if (pring->ringno == LPFC_ELS_RING) { |
| 10173 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10174 | /* Set the lpfc data pending flag */ |
| 10175 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10176 | } |
| 10177 | list_splice_init(&pring->txq, &completions); |
| 10178 | } |
| 10179 | } else { |
| 10180 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10181 | pring = qp->pring; |
| 10182 | if (!pring) |
| 10183 | continue; |
| 10184 | spin_lock_irq(&pring->ring_lock); |
| 10185 | list_splice_init(&pring->txq, &completions); |
| 10186 | spin_unlock_irq(&pring->ring_lock); |
| 10187 | if (pring == phba->sli4_hba.els_wq->pring) { |
| 10188 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
| 10189 | /* Set the lpfc data pending flag */ |
| 10190 | set_bit(LPFC_DATA_READY, &phba->data_flags); |
| 10191 | } |
| 10192 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10193 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10194 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10195 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10196 | /* Cancel all the IOCBs from the completions list */ |
| 10197 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 10198 | IOERR_SLI_DOWN); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 10199 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 10200 | spin_lock_irqsave(&phba->hbalock, flags); |
| 10201 | list_splice_init(&phba->elsbuf, &completions); |
| 10202 | phba->elsbuf_cnt = 0; |
| 10203 | phba->elsbuf_prev_cnt = 0; |
| 10204 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 10205 | |
| 10206 | while (!list_empty(&completions)) { |
| 10207 | list_remove_head(&completions, buf_ptr, |
| 10208 | struct lpfc_dmabuf, list); |
| 10209 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 10210 | kfree(buf_ptr); |
| 10211 | } |
| 10212 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10213 | /* Return any active mbox cmds */ |
| 10214 | del_timer_sync(&psli->mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10215 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10216 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10217 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10218 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10219 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10220 | return 1; |
| 10221 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10222 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10223 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10224 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10225 | * @srcp: Source memory pointer. |
| 10226 | * @destp: Destination memory pointer. |
| 10227 | * @cnt: Number of words required to be copied. |
| 10228 | * |
| 10229 | * This function is used for copying data between driver memory |
| 10230 | * and the SLI memory. This function also changes the endianness |
| 10231 | * of each word if native endianness is different from SLI |
| 10232 | * endianness. This function can be called with or without |
| 10233 | * lock. |
| 10234 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10235 | void |
| 10236 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10237 | { |
| 10238 | uint32_t *src = srcp; |
| 10239 | uint32_t *dest = destp; |
| 10240 | uint32_t ldata; |
| 10241 | int i; |
| 10242 | |
| 10243 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { |
| 10244 | ldata = *src; |
| 10245 | ldata = le32_to_cpu(ldata); |
| 10246 | *dest = ldata; |
| 10247 | src++; |
| 10248 | dest++; |
| 10249 | } |
| 10250 | } |
| 10251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10252 | |
| 10253 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 10254 | * lpfc_sli_bemem_bcopy - SLI memory copy function |
| 10255 | * @srcp: Source memory pointer. |
| 10256 | * @destp: Destination memory pointer. |
| 10257 | * @cnt: Number of words required to be copied. |
| 10258 | * |
| 10259 | * This function is used for copying data between a data structure |
| 10260 | * with big endian representation to local endianness. |
| 10261 | * This function can be called with or without lock. |
| 10262 | **/ |
| 10263 | void |
| 10264 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) |
| 10265 | { |
| 10266 | uint32_t *src = srcp; |
| 10267 | uint32_t *dest = destp; |
| 10268 | uint32_t ldata; |
| 10269 | int i; |
| 10270 | |
| 10271 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { |
| 10272 | ldata = *src; |
| 10273 | ldata = be32_to_cpu(ldata); |
| 10274 | *dest = ldata; |
| 10275 | src++; |
| 10276 | dest++; |
| 10277 | } |
| 10278 | } |
| 10279 | |
| 10280 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10281 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10282 | * @phba: Pointer to HBA context object. |
| 10283 | * @pring: Pointer to driver SLI ring object. |
| 10284 | * @mp: Pointer to driver buffer object. |
| 10285 | * |
| 10286 | * This function is called with no lock held. |
| 10287 | * It always return zero after adding the buffer to the postbufq |
| 10288 | * buffer list. |
| 10289 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10290 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10291 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10292 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10293 | { |
| 10294 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up |
| 10295 | later */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10296 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10297 | list_add_tail(&mp->list, &pring->postbufq); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10298 | pring->postbufq_cnt++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10299 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10300 | return 0; |
| 10301 | } |
| 10302 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10303 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10304 | * 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] | 10305 | * @phba: Pointer to HBA context object. |
| 10306 | * |
| 10307 | * When HBQ is enabled, buffers are searched based on tags. This function |
| 10308 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The |
| 10309 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag |
| 10310 | * does not conflict with tags of buffer posted for unsolicited events. |
| 10311 | * The function returns the allocated tag. The function is called with |
| 10312 | * no locks held. |
| 10313 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10314 | uint32_t |
| 10315 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) |
| 10316 | { |
| 10317 | spin_lock_irq(&phba->hbalock); |
| 10318 | phba->buffer_tag_count++; |
| 10319 | /* |
| 10320 | * Always set the QUE_BUFTAG_BIT to distiguish between |
| 10321 | * a tag assigned by HBQ. |
| 10322 | */ |
| 10323 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; |
| 10324 | spin_unlock_irq(&phba->hbalock); |
| 10325 | return phba->buffer_tag_count; |
| 10326 | } |
| 10327 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10328 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10329 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10330 | * @phba: Pointer to HBA context object. |
| 10331 | * @pring: Pointer to driver SLI ring object. |
| 10332 | * @tag: Buffer tag. |
| 10333 | * |
| 10334 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq |
| 10335 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX |
| 10336 | * iocb is posted to the response ring with the tag of the buffer. |
| 10337 | * This function searches the pring->postbufq list using the tag |
| 10338 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX |
| 10339 | * iocb. If the buffer is found then lpfc_dmabuf object of the |
| 10340 | * buffer is returned to the caller else NULL is returned. |
| 10341 | * This function is called with no lock held. |
| 10342 | **/ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10343 | struct lpfc_dmabuf * |
| 10344 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10345 | uint32_t tag) |
| 10346 | { |
| 10347 | struct lpfc_dmabuf *mp, *next_mp; |
| 10348 | struct list_head *slp = &pring->postbufq; |
| 10349 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10350 | /* Search postbufq, from the beginning, looking for a match on tag */ |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10351 | spin_lock_irq(&phba->hbalock); |
| 10352 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10353 | if (mp->buffer_tag == tag) { |
| 10354 | list_del_init(&mp->list); |
| 10355 | pring->postbufq_cnt--; |
| 10356 | spin_unlock_irq(&phba->hbalock); |
| 10357 | return mp; |
| 10358 | } |
| 10359 | } |
| 10360 | |
| 10361 | spin_unlock_irq(&phba->hbalock); |
| 10362 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10363 | "0402 Cannot find virtual addr for buffer tag on " |
James Smart | 76bb24e | 2007-10-27 13:38:00 -0400 | [diff] [blame] | 10364 | "ring %d Data x%lx x%p x%p x%x\n", |
| 10365 | pring->ringno, (unsigned long) tag, |
| 10366 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10367 | |
| 10368 | return NULL; |
| 10369 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10370 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10371 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10372 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10373 | * @phba: Pointer to HBA context object. |
| 10374 | * @pring: Pointer to driver SLI ring object. |
| 10375 | * @phys: DMA address of the buffer. |
| 10376 | * |
| 10377 | * This function searches the buffer list using the dma_address |
| 10378 | * of unsolicited event to find the driver's lpfc_dmabuf object |
| 10379 | * corresponding to the dma_address. The function returns the |
| 10380 | * lpfc_dmabuf object if a buffer is found else it returns NULL. |
| 10381 | * This function is called by the ct and els unsolicited event |
| 10382 | * handlers to get the buffer associated with the unsolicited |
| 10383 | * event. |
| 10384 | * |
| 10385 | * This function is called with no lock held. |
| 10386 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10387 | struct lpfc_dmabuf * |
| 10388 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10389 | dma_addr_t phys) |
| 10390 | { |
| 10391 | struct lpfc_dmabuf *mp, *next_mp; |
| 10392 | struct list_head *slp = &pring->postbufq; |
| 10393 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10394 | /* Search postbufq, from the beginning, looking for a match on phys */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10395 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10396 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 10397 | if (mp->phys == phys) { |
| 10398 | list_del_init(&mp->list); |
| 10399 | pring->postbufq_cnt--; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10400 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10401 | return mp; |
| 10402 | } |
| 10403 | } |
| 10404 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10405 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10406 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10407 | "0410 Cannot find virtual addr for mapped buf on " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10408 | "ring %d Data x%llx x%p x%p x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10409 | pring->ringno, (unsigned long long)phys, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10410 | slp->next, slp->prev, pring->postbufq_cnt); |
| 10411 | return NULL; |
| 10412 | } |
| 10413 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10414 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10415 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10416 | * @phba: Pointer to HBA context object. |
| 10417 | * @cmdiocb: Pointer to driver command iocb object. |
| 10418 | * @rspiocb: Pointer to driver response iocb object. |
| 10419 | * |
| 10420 | * This function is the completion handler for the abort iocbs for |
| 10421 | * ELS commands. This function is called from the ELS ring event |
| 10422 | * handler with no lock held. This function frees memory resources |
| 10423 | * associated with the abort iocb. |
| 10424 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10425 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10426 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10427 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10428 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10429 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10430 | uint16_t abort_iotag, abort_context; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10431 | struct lpfc_iocbq *abort_iocb = NULL; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10432 | |
| 10433 | if (irsp->ulpStatus) { |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10434 | |
| 10435 | /* |
| 10436 | * Assume that the port already completed and returned, or |
| 10437 | * will return the iocb. Just Log the message. |
| 10438 | */ |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10439 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
| 10440 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; |
| 10441 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10442 | spin_lock_irq(&phba->hbalock); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10443 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 10444 | if (abort_iotag != 0 && |
| 10445 | abort_iotag <= phba->sli.last_iotag) |
| 10446 | abort_iocb = |
| 10447 | phba->sli.iocbq_lookup[abort_iotag]; |
| 10448 | } else |
| 10449 | /* For sli4 the abort_tag is the XRI, |
| 10450 | * so the abort routine puts the iotag of the iocb |
| 10451 | * being aborted in the context field of the abort |
| 10452 | * IOCB. |
| 10453 | */ |
| 10454 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10455 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10456 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
| 10457 | "0327 Cannot abort els iocb %p " |
| 10458 | "with tag %x context %x, abort status %x, " |
| 10459 | "abort code %x\n", |
| 10460 | abort_iocb, abort_iotag, abort_context, |
| 10461 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10462 | |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 10463 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 10464 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10465 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10466 | return; |
| 10467 | } |
| 10468 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10469 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10470 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10471 | * @phba: Pointer to HBA context object. |
| 10472 | * @cmdiocb: Pointer to driver command iocb object. |
| 10473 | * @rspiocb: Pointer to driver response iocb object. |
| 10474 | * |
| 10475 | * The function is called from SLI ring event handler with no |
| 10476 | * lock held. This function is the completion handler for ELS commands |
| 10477 | * which are aborted. The function frees memory resources used for |
| 10478 | * the aborted ELS commands. |
| 10479 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10480 | static void |
| 10481 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10482 | struct lpfc_iocbq *rspiocb) |
| 10483 | { |
| 10484 | IOCB_t *irsp = &rspiocb->iocb; |
| 10485 | |
| 10486 | /* ELS cmd tag <ulpIoTag> completes */ |
| 10487 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10488 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10489 | "x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10490 | irsp->ulpIoTag, irsp->ulpStatus, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10491 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10492 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
| 10493 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 10494 | else |
| 10495 | lpfc_els_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10496 | return; |
| 10497 | } |
| 10498 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10499 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10500 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10501 | * @phba: Pointer to HBA context object. |
| 10502 | * @pring: Pointer to driver SLI ring object. |
| 10503 | * @cmdiocb: Pointer to driver command iocb object. |
| 10504 | * |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10505 | * This function issues an abort iocb for the provided command iocb down to |
| 10506 | * the port. Other than the case the outstanding command iocb is an abort |
| 10507 | * request, this function issues abort out unconditionally. This function is |
| 10508 | * called with hbalock held. The function returns 0 when it fails due to |
| 10509 | * memory allocation failure or when the command iocb is an abort request. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10510 | **/ |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10511 | static int |
| 10512 | 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] | 10513 | struct lpfc_iocbq *cmdiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10514 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10515 | struct lpfc_vport *vport = cmdiocb->vport; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10516 | struct lpfc_iocbq *abtsiocbp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10517 | IOCB_t *icmd = NULL; |
| 10518 | IOCB_t *iabt = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10519 | int retval; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10520 | unsigned long iflags; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10521 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10522 | lockdep_assert_held(&phba->hbalock); |
| 10523 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10524 | /* |
| 10525 | * There are certain command types we don't want to abort. And we |
| 10526 | * don't want to abort commands that are already in the process of |
| 10527 | * being aborted. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10528 | */ |
| 10529 | icmd = &cmdiocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10530 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10531 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 10532 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10533 | return 0; |
| 10534 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10535 | /* issue ABTS for this IOCB based on iotag */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 10536 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10537 | if (abtsiocbp == NULL) |
| 10538 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10539 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10540 | /* This signals the response to set the correct status |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10541 | * before calling the completion handler |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10542 | */ |
| 10543 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10544 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10545 | iabt = &abtsiocbp->iocb; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10546 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10547 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10548 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10549 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 10550 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
| 10551 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10552 | else |
| 10553 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10554 | iabt->ulpLe = 1; |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10555 | iabt->ulpClass = icmd->ulpClass; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10556 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10557 | /* 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] | 10558 | abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 10559 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
| 10560 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10561 | if (cmdiocb->iocb_flag & LPFC_IO_FOF) |
| 10562 | abtsiocbp->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 10563 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10564 | if (phba->link_state >= LPFC_LINK_UP) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10565 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
| 10566 | else |
| 10567 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; |
| 10568 | |
| 10569 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
James Smart | e6c6acc | 2016-12-19 15:07:23 -0800 | [diff] [blame] | 10570 | abtsiocbp->vport = vport; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 10571 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10572 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
| 10573 | "0339 Abort xri x%x, original iotag x%x, " |
| 10574 | "abort cmd iotag x%x\n", |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10575 | iabt->un.acxri.abortIoTag, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 10576 | iabt->un.acxri.abortContextTag, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 10577 | abtsiocbp->iotag); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10578 | |
| 10579 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10580 | pring = lpfc_sli4_calc_ring(phba, abtsiocbp); |
| 10581 | if (unlikely(pring == NULL)) |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 10582 | return 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 10583 | /* Note: both hbalock and ring_lock need to be set here */ |
| 10584 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 10585 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10586 | abtsiocbp, 0); |
| 10587 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 10588 | } else { |
| 10589 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 10590 | abtsiocbp, 0); |
| 10591 | } |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10592 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 10593 | if (retval) |
| 10594 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10595 | |
| 10596 | /* |
| 10597 | * Caller to this routine should check for IOCB_ERROR |
| 10598 | * and handle it properly. This routine no longer removes |
| 10599 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
| 10600 | */ |
| 10601 | return retval; |
| 10602 | } |
| 10603 | |
| 10604 | /** |
| 10605 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
| 10606 | * @phba: Pointer to HBA context object. |
| 10607 | * @pring: Pointer to driver SLI ring object. |
| 10608 | * @cmdiocb: Pointer to driver command iocb object. |
| 10609 | * |
| 10610 | * This function issues an abort iocb for the provided command iocb. In case |
| 10611 | * of unloading, the abort iocb will not be issued to commands on the ELS |
| 10612 | * ring. Instead, the callback function shall be changed to those commands |
| 10613 | * so that nothing happens when them finishes. This function is called with |
| 10614 | * hbalock held. The function returns 0 when the command iocb is an abort |
| 10615 | * request. |
| 10616 | **/ |
| 10617 | int |
| 10618 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10619 | struct lpfc_iocbq *cmdiocb) |
| 10620 | { |
| 10621 | struct lpfc_vport *vport = cmdiocb->vport; |
| 10622 | int retval = IOCB_ERROR; |
| 10623 | IOCB_t *icmd = NULL; |
| 10624 | |
Johannes Thumshirn | 1c2ba47 | 2016-01-20 16:22:22 +0100 | [diff] [blame] | 10625 | lockdep_assert_held(&phba->hbalock); |
| 10626 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10627 | /* |
| 10628 | * There are certain command types we don't want to abort. And we |
| 10629 | * don't want to abort commands that are already in the process of |
| 10630 | * being aborted. |
| 10631 | */ |
| 10632 | icmd = &cmdiocb->iocb; |
| 10633 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
| 10634 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 10635 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 10636 | return 0; |
| 10637 | |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 10638 | if (!pring) { |
| 10639 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 10640 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10641 | else |
| 10642 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10643 | goto abort_iotag_exit; |
| 10644 | } |
| 10645 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10646 | /* |
| 10647 | * If we're unloading, don't abort iocb on the ELS ring, but change |
| 10648 | * the callback so that nothing happens when it finishes. |
| 10649 | */ |
| 10650 | if ((vport->load_flag & FC_UNLOADING) && |
| 10651 | (pring->ringno == LPFC_ELS_RING)) { |
| 10652 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
| 10653 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10654 | else |
| 10655 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; |
| 10656 | goto abort_iotag_exit; |
| 10657 | } |
| 10658 | |
| 10659 | /* Now, we try to issue the abort to the cmdiocb out */ |
| 10660 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); |
| 10661 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10662 | abort_iotag_exit: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10663 | /* |
| 10664 | * Caller to this routine should check for IOCB_ERROR |
| 10665 | * and handle it properly. This routine no longer removes |
| 10666 | * iocb off txcmplq and call compl in case of IOCB_ERROR. |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 10667 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10668 | return retval; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10669 | } |
| 10670 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10671 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10672 | * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb |
| 10673 | * @phba: Pointer to HBA context object. |
| 10674 | * @pring: Pointer to driver SLI ring object. |
| 10675 | * @cmdiocb: Pointer to driver command iocb object. |
| 10676 | * |
| 10677 | * This function issues an abort iocb for the provided command iocb down to |
| 10678 | * the port. Other than the case the outstanding command iocb is an abort |
| 10679 | * request, this function issues abort out unconditionally. This function is |
| 10680 | * called with hbalock held. The function returns 0 when it fails due to |
| 10681 | * memory allocation failure or when the command iocb is an abort request. |
| 10682 | **/ |
| 10683 | static int |
| 10684 | lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 10685 | struct lpfc_iocbq *cmdiocb) |
| 10686 | { |
| 10687 | struct lpfc_vport *vport = cmdiocb->vport; |
| 10688 | struct lpfc_iocbq *abtsiocbp; |
| 10689 | union lpfc_wqe *abts_wqe; |
| 10690 | int retval; |
| 10691 | |
| 10692 | /* |
| 10693 | * There are certain command types we don't want to abort. And we |
| 10694 | * don't want to abort commands that are already in the process of |
| 10695 | * being aborted. |
| 10696 | */ |
| 10697 | if (cmdiocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 10698 | cmdiocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN || |
| 10699 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) |
| 10700 | return 0; |
| 10701 | |
| 10702 | /* issue ABTS for this io based on iotag */ |
| 10703 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
| 10704 | if (abtsiocbp == NULL) |
| 10705 | return 0; |
| 10706 | |
| 10707 | /* This signals the response to set the correct status |
| 10708 | * before calling the completion handler |
| 10709 | */ |
| 10710 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10711 | |
| 10712 | /* Complete prepping the abort wqe and issue to the FW. */ |
| 10713 | abts_wqe = &abtsiocbp->wqe; |
| 10714 | bf_set(abort_cmd_ia, &abts_wqe->abort_cmd, 0); |
| 10715 | bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG); |
| 10716 | |
| 10717 | /* Explicitly set reserved fields to zero.*/ |
| 10718 | abts_wqe->abort_cmd.rsrvd4 = 0; |
| 10719 | abts_wqe->abort_cmd.rsrvd5 = 0; |
| 10720 | |
| 10721 | /* WQE Common - word 6. Context is XRI tag. Set 0. */ |
| 10722 | bf_set(wqe_xri_tag, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10723 | bf_set(wqe_ctxt_tag, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10724 | |
| 10725 | /* word 7 */ |
| 10726 | bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0); |
| 10727 | bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
| 10728 | bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com, |
| 10729 | cmdiocb->iocb.ulpClass); |
| 10730 | |
| 10731 | /* word 8 - tell the FW to abort the IO associated with this |
| 10732 | * outstanding exchange ID. |
| 10733 | */ |
| 10734 | abts_wqe->abort_cmd.wqe_com.abort_tag = cmdiocb->sli4_xritag; |
| 10735 | |
| 10736 | /* word 9 - this is the iotag for the abts_wqe completion. */ |
| 10737 | bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com, |
| 10738 | abtsiocbp->iotag); |
| 10739 | |
| 10740 | /* word 10 */ |
| 10741 | bf_set(wqe_wqid, &abts_wqe->abort_cmd.wqe_com, cmdiocb->hba_wqidx); |
| 10742 | bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1); |
| 10743 | bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE); |
| 10744 | |
| 10745 | /* word 11 */ |
| 10746 | bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND); |
| 10747 | bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1); |
| 10748 | bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); |
| 10749 | |
| 10750 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
| 10751 | abtsiocbp->iocb_flag |= LPFC_IO_NVME; |
| 10752 | abtsiocbp->vport = vport; |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 10753 | abtsiocbp->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10754 | retval = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abtsiocbp); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 10755 | if (retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10756 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 10757 | "6147 Failed abts issue_wqe with status x%x " |
| 10758 | "for oxid x%x\n", |
| 10759 | retval, cmdiocb->sli4_xritag); |
| 10760 | lpfc_sli_release_iocbq(phba, abtsiocbp); |
| 10761 | return retval; |
| 10762 | } |
| 10763 | |
| 10764 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME, |
| 10765 | "6148 Drv Abort NVME Request Issued for " |
| 10766 | "ox_id x%x on reqtag x%x\n", |
| 10767 | cmdiocb->sli4_xritag, |
| 10768 | abtsiocbp->iotag); |
| 10769 | |
| 10770 | return retval; |
| 10771 | } |
| 10772 | |
| 10773 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10774 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. |
| 10775 | * @phba: pointer to lpfc HBA data structure. |
| 10776 | * |
| 10777 | * This routine will abort all pending and outstanding iocbs to an HBA. |
| 10778 | **/ |
| 10779 | void |
| 10780 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) |
| 10781 | { |
| 10782 | struct lpfc_sli *psli = &phba->sli; |
| 10783 | struct lpfc_sli_ring *pring; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10784 | struct lpfc_queue *qp = NULL; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10785 | int i; |
| 10786 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10787 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 10788 | for (i = 0; i < psli->num_rings; i++) { |
| 10789 | pring = &psli->sli3_ring[i]; |
| 10790 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 10791 | } |
| 10792 | return; |
| 10793 | } |
| 10794 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 10795 | pring = qp->pring; |
| 10796 | if (!pring) |
| 10797 | continue; |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 10798 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10799 | } |
| 10800 | } |
| 10801 | |
| 10802 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10803 | * 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] | 10804 | * @iocbq: Pointer to driver iocb object. |
| 10805 | * @vport: Pointer to driver virtual port object. |
| 10806 | * @tgt_id: SCSI ID of the target. |
| 10807 | * @lun_id: LUN ID of the scsi device. |
| 10808 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST |
| 10809 | * |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10810 | * 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] | 10811 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
| 10812 | * 0 if the filtering criteria is met for the given iocb and will return |
| 10813 | * 1 if the filtering criteria is not met. |
| 10814 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the |
| 10815 | * given iocb is for the SCSI device specified by vport, tgt_id and |
| 10816 | * lun_id parameter. |
| 10817 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the |
| 10818 | * given iocb is for the SCSI target specified by vport and tgt_id |
| 10819 | * parameters. |
| 10820 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the |
| 10821 | * given iocb is for the SCSI host associated with the given vport. |
| 10822 | * This function is called with no locks held. |
| 10823 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10824 | static int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10825 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
| 10826 | uint16_t tgt_id, uint64_t lun_id, |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10827 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10828 | { |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10829 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10830 | int rc = 1; |
| 10831 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10832 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
| 10833 | return rc; |
| 10834 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10835 | if (iocbq->vport != vport) |
| 10836 | return rc; |
| 10837 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10838 | 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] | 10839 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10840 | if (lpfc_cmd->pCmd == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10841 | return rc; |
| 10842 | |
| 10843 | switch (ctx_cmd) { |
| 10844 | case LPFC_CTX_LUN: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10845 | if ((lpfc_cmd->rdata->pnode) && |
| 10846 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && |
| 10847 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10848 | rc = 0; |
| 10849 | break; |
| 10850 | case LPFC_CTX_TGT: |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 10851 | if ((lpfc_cmd->rdata->pnode) && |
| 10852 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10853 | rc = 0; |
| 10854 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10855 | case LPFC_CTX_HOST: |
| 10856 | rc = 0; |
| 10857 | break; |
| 10858 | default: |
| 10859 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 10860 | __func__, ctx_cmd); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10861 | break; |
| 10862 | } |
| 10863 | |
| 10864 | return rc; |
| 10865 | } |
| 10866 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10867 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10868 | * 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] | 10869 | * @vport: Pointer to virtual port. |
| 10870 | * @tgt_id: SCSI ID of the target. |
| 10871 | * @lun_id: LUN ID of the scsi device. |
| 10872 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10873 | * |
| 10874 | * This function returns number of FCP commands pending for the vport. |
| 10875 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP |
| 10876 | * commands pending on the vport associated with SCSI device specified |
| 10877 | * by tgt_id and lun_id parameters. |
| 10878 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP |
| 10879 | * commands pending on the vport associated with SCSI target specified |
| 10880 | * by tgt_id parameter. |
| 10881 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP |
| 10882 | * commands pending on the vport. |
| 10883 | * This function returns the number of iocbs which satisfy the filter. |
| 10884 | * This function is called without any lock held. |
| 10885 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10886 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10887 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
| 10888 | lpfc_ctx_cmd ctx_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10889 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10890 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10891 | struct lpfc_iocbq *iocbq; |
| 10892 | int sum, i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10893 | |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 10894 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10895 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
| 10896 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10897 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10898 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
| 10899 | ctx_cmd) == 0) |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10900 | sum++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10901 | } |
Johannes Thumshirn | 3197900 | 2016-07-18 16:06:03 +0200 | [diff] [blame] | 10902 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10903 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10904 | return sum; |
| 10905 | } |
| 10906 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10907 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10908 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10909 | * @phba: Pointer to HBA context object |
| 10910 | * @cmdiocb: Pointer to command iocb object. |
| 10911 | * @rspiocb: Pointer to response iocb object. |
| 10912 | * |
| 10913 | * This function is called when an aborted FCP iocb completes. This |
| 10914 | * function is called by the ring event handler with no lock held. |
| 10915 | * This function frees the iocb. |
| 10916 | **/ |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10917 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10918 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 10919 | struct lpfc_iocbq *rspiocb) |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10920 | { |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10921 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 8e668af | 2013-05-31 17:04:28 -0400 | [diff] [blame] | 10922 | "3096 ABORT_XRI_CN completing on rpi x%x " |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 10923 | "original iotag x%x, abort cmd iotag x%x " |
| 10924 | "status 0x%x, reason 0x%x\n", |
| 10925 | cmdiocb->iocb.un.acxri.abortContextTag, |
| 10926 | cmdiocb->iocb.un.acxri.abortIoTag, |
| 10927 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, |
| 10928 | rspiocb->iocb.un.ulpWord[4]); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 10929 | lpfc_sli_release_iocbq(phba, cmdiocb); |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 10930 | return; |
| 10931 | } |
| 10932 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10933 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 10934 | * 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] | 10935 | * @vport: Pointer to virtual port. |
| 10936 | * @pring: Pointer to driver SLI ring object. |
| 10937 | * @tgt_id: SCSI ID of the target. |
| 10938 | * @lun_id: LUN ID of the scsi device. |
| 10939 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 10940 | * |
| 10941 | * This function sends an abort command for every SCSI command |
| 10942 | * associated with the given virtual port pending on the ring |
| 10943 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 10944 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 10945 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 10946 | * parameters |
| 10947 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 10948 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 10949 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 10950 | * FCP iocbs associated with virtual port. |
| 10951 | * This function returns number of iocbs it failed to abort. |
| 10952 | * This function is called with no locks held. |
| 10953 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10954 | int |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10955 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 10956 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10957 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10958 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10959 | struct lpfc_iocbq *iocbq; |
| 10960 | struct lpfc_iocbq *abtsiocb; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 10961 | struct lpfc_sli_ring *pring_s4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10962 | IOCB_t *cmd = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10963 | int errcnt = 0, ret_val = 0; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10964 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10965 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10966 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 10967 | iocbq = phba->sli.iocbq_lookup[i]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10968 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10969 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10970 | abort_cmd) != 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10971 | continue; |
| 10972 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10973 | /* |
| 10974 | * If the iocbq is already being aborted, don't take a second |
| 10975 | * action, but do count it. |
| 10976 | */ |
| 10977 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 10978 | continue; |
| 10979 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10980 | /* issue ABTS for this IOCB based on iotag */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10981 | abtsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10982 | if (abtsiocb == NULL) { |
| 10983 | errcnt++; |
| 10984 | continue; |
| 10985 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10986 | |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10987 | /* indicate the IO is being aborted by the driver. */ |
| 10988 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 10989 | |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 10990 | cmd = &iocbq->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10991 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 10992 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10993 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 10994 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; |
| 10995 | else |
| 10996 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10997 | abtsiocb->iocb.ulpLe = 1; |
| 10998 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
James Smart | afbd8d8 | 2013-09-06 12:22:13 -0400 | [diff] [blame] | 10999 | abtsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11000 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11001 | /* 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] | 11002 | abtsiocb->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 11003 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11004 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11005 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11006 | abtsiocb->iocb_flag |= LPFC_IO_FOF; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 11007 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11008 | if (lpfc_is_link_up(phba)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11009 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11010 | else |
| 11011 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11012 | |
James.Smart@Emulex.Com | 5eb95af | 2005-06-25 10:34:30 -0400 | [diff] [blame] | 11013 | /* Setup callback routine and issue the command. */ |
| 11014 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
James Smart | ecbb227 | 2017-06-01 21:07:04 -0700 | [diff] [blame] | 11015 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11016 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11017 | if (!pring_s4) |
| 11018 | continue; |
| 11019 | ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11020 | abtsiocb, 0); |
| 11021 | } else |
| 11022 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11023 | abtsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11024 | if (ret_val == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 11025 | lpfc_sli_release_iocbq(phba, abtsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11026 | errcnt++; |
| 11027 | continue; |
| 11028 | } |
| 11029 | } |
| 11030 | |
| 11031 | return errcnt; |
| 11032 | } |
| 11033 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11034 | /** |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11035 | * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN |
| 11036 | * @vport: Pointer to virtual port. |
| 11037 | * @pring: Pointer to driver SLI ring object. |
| 11038 | * @tgt_id: SCSI ID of the target. |
| 11039 | * @lun_id: LUN ID of the scsi device. |
| 11040 | * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. |
| 11041 | * |
| 11042 | * This function sends an abort command for every SCSI command |
| 11043 | * associated with the given virtual port pending on the ring |
| 11044 | * filtered by lpfc_sli_validate_fcp_iocb function. |
| 11045 | * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the |
| 11046 | * FCP iocbs associated with lun specified by tgt_id and lun_id |
| 11047 | * parameters |
| 11048 | * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the |
| 11049 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. |
| 11050 | * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all |
| 11051 | * FCP iocbs associated with virtual port. |
| 11052 | * This function returns number of iocbs it aborted . |
| 11053 | * This function is called with no locks held right after a taskmgmt |
| 11054 | * command is sent. |
| 11055 | **/ |
| 11056 | int |
| 11057 | lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
| 11058 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd) |
| 11059 | { |
| 11060 | struct lpfc_hba *phba = vport->phba; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11061 | struct lpfc_scsi_buf *lpfc_cmd; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11062 | struct lpfc_iocbq *abtsiocbq; |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11063 | struct lpfc_nodelist *ndlp; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11064 | struct lpfc_iocbq *iocbq; |
| 11065 | IOCB_t *icmd; |
| 11066 | int sum, i, ret_val; |
| 11067 | unsigned long iflags; |
| 11068 | struct lpfc_sli_ring *pring_s4; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11069 | |
| 11070 | spin_lock_irq(&phba->hbalock); |
| 11071 | |
| 11072 | /* all I/Os are in process of being flushed */ |
| 11073 | if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) { |
| 11074 | spin_unlock_irq(&phba->hbalock); |
| 11075 | return 0; |
| 11076 | } |
| 11077 | sum = 0; |
| 11078 | |
| 11079 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
| 11080 | iocbq = phba->sli.iocbq_lookup[i]; |
| 11081 | |
| 11082 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
| 11083 | cmd) != 0) |
| 11084 | continue; |
| 11085 | |
| 11086 | /* |
| 11087 | * If the iocbq is already being aborted, don't take a second |
| 11088 | * action, but do count it. |
| 11089 | */ |
| 11090 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) |
| 11091 | continue; |
| 11092 | |
| 11093 | /* issue ABTS for this IOCB based on iotag */ |
| 11094 | abtsiocbq = __lpfc_sli_get_iocbq(phba); |
| 11095 | if (abtsiocbq == NULL) |
| 11096 | continue; |
| 11097 | |
| 11098 | icmd = &iocbq->iocb; |
| 11099 | abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
| 11100 | abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext; |
| 11101 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 11102 | abtsiocbq->iocb.un.acxri.abortIoTag = |
| 11103 | iocbq->sli4_xritag; |
| 11104 | else |
| 11105 | abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag; |
| 11106 | abtsiocbq->iocb.ulpLe = 1; |
| 11107 | abtsiocbq->iocb.ulpClass = icmd->ulpClass; |
| 11108 | abtsiocbq->vport = vport; |
| 11109 | |
| 11110 | /* 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] | 11111 | abtsiocbq->hba_wqidx = iocbq->hba_wqidx; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11112 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
| 11113 | abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
James Smart | 9bd2bff5 | 2014-09-03 12:57:30 -0400 | [diff] [blame] | 11114 | if (iocbq->iocb_flag & LPFC_IO_FOF) |
| 11115 | abtsiocbq->iocb_flag |= LPFC_IO_FOF; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11116 | |
James Smart | 8c50d25 | 2014-09-03 12:58:16 -0400 | [diff] [blame] | 11117 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
| 11118 | ndlp = lpfc_cmd->rdata->pnode; |
| 11119 | |
| 11120 | if (lpfc_is_link_up(phba) && |
| 11121 | (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE)) |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11122 | abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
| 11123 | else |
| 11124 | abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN; |
| 11125 | |
| 11126 | /* Setup callback routine and issue the command. */ |
| 11127 | abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
| 11128 | |
| 11129 | /* |
| 11130 | * Indicate the IO is being aborted by the driver and set |
| 11131 | * the caller's flag into the aborted IO. |
| 11132 | */ |
| 11133 | iocbq->iocb_flag |= LPFC_DRIVER_ABORTED; |
| 11134 | |
| 11135 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11136 | pring_s4 = lpfc_sli4_calc_ring(phba, iocbq); |
| 11137 | if (pring_s4 == NULL) |
| 11138 | continue; |
James Smart | 98912dda | 2014-04-04 13:52:31 -0400 | [diff] [blame] | 11139 | /* Note: both hbalock and ring_lock must be set here */ |
| 11140 | spin_lock_irqsave(&pring_s4->ring_lock, iflags); |
| 11141 | ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno, |
| 11142 | abtsiocbq, 0); |
| 11143 | spin_unlock_irqrestore(&pring_s4->ring_lock, iflags); |
| 11144 | } else { |
| 11145 | ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno, |
| 11146 | abtsiocbq, 0); |
| 11147 | } |
| 11148 | |
| 11149 | |
| 11150 | if (ret_val == IOCB_ERROR) |
| 11151 | __lpfc_sli_release_iocbq(phba, abtsiocbq); |
| 11152 | else |
| 11153 | sum++; |
| 11154 | } |
| 11155 | spin_unlock_irq(&phba->hbalock); |
| 11156 | return sum; |
| 11157 | } |
| 11158 | |
| 11159 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11160 | * 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] | 11161 | * @phba: Pointer to HBA context object. |
| 11162 | * @cmdiocbq: Pointer to command iocb. |
| 11163 | * @rspiocbq: Pointer to response iocb. |
| 11164 | * |
| 11165 | * This function is the completion handler for iocbs issued using |
| 11166 | * lpfc_sli_issue_iocb_wait function. This function is called by the |
| 11167 | * ring event handler function without any lock held. This function |
| 11168 | * can be called from both worker thread context and interrupt |
| 11169 | * context. This function also can be called from other thread which |
| 11170 | * cleans up the SLI layer objects. |
| 11171 | * This function copy the contents of the response iocb to the |
| 11172 | * response iocb memory object provided by the caller of |
| 11173 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 11174 | * sleeps for the iocb completion. |
| 11175 | **/ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11176 | static void |
| 11177 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, |
| 11178 | struct lpfc_iocbq *cmdiocbq, |
| 11179 | struct lpfc_iocbq *rspiocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11180 | { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11181 | wait_queue_head_t *pdone_q; |
| 11182 | unsigned long iflags; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11183 | struct lpfc_scsi_buf *lpfc_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11184 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11185 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11186 | if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) { |
| 11187 | |
| 11188 | /* |
| 11189 | * A time out has occurred for the iocb. If a time out |
| 11190 | * completion handler has been supplied, call it. Otherwise, |
| 11191 | * just free the iocbq. |
| 11192 | */ |
| 11193 | |
| 11194 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11195 | cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl; |
| 11196 | cmdiocbq->wait_iocb_cmpl = NULL; |
| 11197 | if (cmdiocbq->iocb_cmpl) |
| 11198 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL); |
| 11199 | else |
| 11200 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 11201 | return; |
| 11202 | } |
| 11203 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11204 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
| 11205 | if (cmdiocbq->context2 && rspiocbq) |
| 11206 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, |
| 11207 | &rspiocbq->iocb, sizeof(IOCB_t)); |
| 11208 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 11209 | /* Set the exchange busy flag for task management commands */ |
| 11210 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && |
| 11211 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { |
| 11212 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, |
| 11213 | cur_iocbq); |
| 11214 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; |
| 11215 | } |
| 11216 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11217 | pdone_q = cmdiocbq->context_un.wait_queue; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11218 | if (pdone_q) |
| 11219 | wake_up(pdone_q); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11220 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11221 | return; |
| 11222 | } |
| 11223 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11224 | /** |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11225 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. |
| 11226 | * @phba: Pointer to HBA context object.. |
| 11227 | * @piocbq: Pointer to command iocb. |
| 11228 | * @flag: Flag to test. |
| 11229 | * |
| 11230 | * This routine grabs the hbalock and then test the iocb_flag to |
| 11231 | * see if the passed in flag is set. |
| 11232 | * Returns: |
| 11233 | * 1 if flag is set. |
| 11234 | * 0 if flag is not set. |
| 11235 | **/ |
| 11236 | static int |
| 11237 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, |
| 11238 | struct lpfc_iocbq *piocbq, uint32_t flag) |
| 11239 | { |
| 11240 | unsigned long iflags; |
| 11241 | int ret; |
| 11242 | |
| 11243 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11244 | ret = piocbq->iocb_flag & flag; |
| 11245 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11246 | return ret; |
| 11247 | |
| 11248 | } |
| 11249 | |
| 11250 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11251 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11252 | * @phba: Pointer to HBA context object.. |
| 11253 | * @pring: Pointer to sli ring. |
| 11254 | * @piocb: Pointer to command iocb. |
| 11255 | * @prspiocbq: Pointer to response iocb. |
| 11256 | * @timeout: Timeout in number of seconds. |
| 11257 | * |
| 11258 | * This function issues the iocb to firmware and waits for the |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11259 | * iocb to complete. The iocb_cmpl field of the shall be used |
| 11260 | * to handle iocbs which time out. If the field is NULL, the |
| 11261 | * function shall free the iocbq structure. If more clean up is |
| 11262 | * needed, the caller is expected to provide a completion function |
| 11263 | * that will provide the needed clean up. If the iocb command is |
| 11264 | * not completed within timeout seconds, the function will either |
| 11265 | * free the iocbq structure (if iocb_cmpl == NULL) or execute the |
| 11266 | * completion function set in the iocb_cmpl field and then return |
| 11267 | * a status of IOCB_TIMEDOUT. The caller should not free the iocb |
| 11268 | * resources if this function returns IOCB_TIMEDOUT. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11269 | * The function waits for the iocb completion using an |
| 11270 | * non-interruptible wait. |
| 11271 | * This function will sleep while waiting for iocb completion. |
| 11272 | * So, this function should not be called from any context which |
| 11273 | * does not allow sleeping. Due to the same reason, this function |
| 11274 | * cannot be called with interrupt disabled. |
| 11275 | * This function assumes that the iocb completions occur while |
| 11276 | * this function sleep. So, this function cannot be called from |
| 11277 | * the thread which process iocb completion for this ring. |
| 11278 | * This function clears the iocb_flag of the iocb object before |
| 11279 | * issuing the iocb and the iocb completion handler sets this |
| 11280 | * flag and wakes this thread when the iocb completes. |
| 11281 | * The contents of the response iocb will be copied to prspiocbq |
| 11282 | * by the completion handler when the command completes. |
| 11283 | * This function returns IOCB_SUCCESS when success. |
| 11284 | * This function is called with no lock held. |
| 11285 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11286 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11287 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11288 | uint32_t ring_number, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11289 | struct lpfc_iocbq *piocb, |
| 11290 | struct lpfc_iocbq *prspiocbq, |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11291 | uint32_t timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11292 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11293 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11294 | long timeleft, timeout_req = 0; |
| 11295 | int retval = IOCB_SUCCESS; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11296 | uint32_t creg_val; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11297 | struct lpfc_iocbq *iocb; |
| 11298 | int txq_cnt = 0; |
| 11299 | int txcmplq_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11300 | struct lpfc_sli_ring *pring; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11301 | unsigned long iflags; |
| 11302 | bool iocb_completed = true; |
| 11303 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11304 | if (phba->sli_rev >= LPFC_SLI_REV4) |
| 11305 | pring = lpfc_sli4_calc_ring(phba, piocb); |
| 11306 | else |
| 11307 | pring = &phba->sli.sli3_ring[ring_number]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11308 | /* |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11309 | * If the caller has provided a response iocbq buffer, then context2 |
| 11310 | * is NULL or its an error. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11311 | */ |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11312 | if (prspiocbq) { |
| 11313 | if (piocb->context2) |
| 11314 | return IOCB_ERROR; |
| 11315 | piocb->context2 = prspiocbq; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11316 | } |
| 11317 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11318 | piocb->wait_iocb_cmpl = piocb->iocb_cmpl; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11319 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
| 11320 | piocb->context_un.wait_queue = &done_q; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11321 | piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11322 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11323 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11324 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11325 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11326 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 11327 | writel(creg_val, phba->HCregaddr); |
| 11328 | readl(phba->HCregaddr); /* flush */ |
| 11329 | } |
| 11330 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11331 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
| 11332 | SLI_IOCB_RET_IOCB); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11333 | if (retval == IOCB_SUCCESS) { |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11334 | timeout_req = msecs_to_jiffies(timeout * 1000); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11335 | timeleft = wait_event_timeout(done_q, |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 11336 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11337 | timeout_req); |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11338 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11339 | if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11340 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 11341 | /* |
| 11342 | * IOCB timed out. Inform the wake iocb wait |
| 11343 | * completion function and set local status |
| 11344 | */ |
| 11345 | |
| 11346 | iocb_completed = false; |
| 11347 | piocb->iocb_flag |= LPFC_IO_WAKE_TMO; |
| 11348 | } |
| 11349 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11350 | if (iocb_completed) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11351 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11352 | "0331 IOCB wake signaled\n"); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 11353 | /* Note: we are not indicating if the IOCB has a success |
| 11354 | * status or not - that's for the caller to check. |
| 11355 | * IOCB_SUCCESS means just that the command was sent and |
| 11356 | * completed. Not that it completed successfully. |
| 11357 | * */ |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11358 | } else if (timeleft == 0) { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11359 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11360 | "0338 IOCB wait timeout error - no " |
| 11361 | "wake response Data x%x\n", timeout); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11362 | retval = IOCB_TIMEDOUT; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11363 | } else { |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11364 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11365 | "0330 IOCB wake NOT set, " |
| 11366 | "Data x%x x%lx\n", |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11367 | timeout, (timeleft / jiffies)); |
| 11368 | retval = IOCB_TIMEDOUT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11369 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11370 | } else if (retval == IOCB_BUSY) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 11371 | if (phba->cfg_log_verbose & LOG_SLI) { |
| 11372 | list_for_each_entry(iocb, &pring->txq, list) { |
| 11373 | txq_cnt++; |
| 11374 | } |
| 11375 | list_for_each_entry(iocb, &pring->txcmplq, list) { |
| 11376 | txcmplq_cnt++; |
| 11377 | } |
| 11378 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 11379 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", |
| 11380 | phba->iocb_cnt, txq_cnt, txcmplq_cnt); |
| 11381 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 11382 | return retval; |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11383 | } else { |
| 11384 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 11385 | "0332 IOCB wait issue failed, Data x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11386 | retval); |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11387 | retval = IOCB_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11388 | } |
| 11389 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11390 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11391 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
| 11392 | return IOCB_ERROR; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 11393 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 11394 | writel(creg_val, phba->HCregaddr); |
| 11395 | readl(phba->HCregaddr); /* flush */ |
| 11396 | } |
| 11397 | |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11398 | if (prspiocbq) |
| 11399 | piocb->context2 = NULL; |
| 11400 | |
| 11401 | piocb->context_un.wait_queue = NULL; |
| 11402 | piocb->iocb_cmpl = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11403 | return retval; |
| 11404 | } |
James.Smart@Emulex.Com | 6887692 | 2005-10-28 20:29:47 -0400 | [diff] [blame] | 11405 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11406 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11407 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11408 | * @phba: Pointer to HBA context object. |
| 11409 | * @pmboxq: Pointer to driver mailbox object. |
| 11410 | * @timeout: Timeout in number of seconds. |
| 11411 | * |
| 11412 | * This function issues the mailbox to firmware and waits for the |
| 11413 | * mailbox command to complete. If the mailbox command is not |
| 11414 | * completed within timeout seconds, it returns MBX_TIMEOUT. |
| 11415 | * The function waits for the mailbox completion using an |
| 11416 | * interruptible wait. If the thread is woken up due to a |
| 11417 | * signal, MBX_TIMEOUT error is returned to the caller. Caller |
| 11418 | * should not free the mailbox resources, if this function returns |
| 11419 | * MBX_TIMEOUT. |
| 11420 | * This function will sleep while waiting for mailbox completion. |
| 11421 | * So, this function should not be called from any context which |
| 11422 | * does not allow sleeping. Due to the same reason, this function |
| 11423 | * cannot be called with interrupt disabled. |
| 11424 | * This function assumes that the mailbox completion occurs while |
| 11425 | * this function sleep. So, this function cannot be called from |
| 11426 | * the worker thread which processes mailbox completion. |
| 11427 | * This function is called in the context of HBA management |
| 11428 | * applications. |
| 11429 | * This function returns MBX_SUCCESS when successful. |
| 11430 | * This function is called with no lock held. |
| 11431 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11432 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11433 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11434 | uint32_t timeout) |
| 11435 | { |
Peter Zijlstra | 7259f0d | 2006-10-29 22:46:36 -0800 | [diff] [blame] | 11436 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11437 | MAILBOX_t *mb = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11438 | int retval; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11439 | unsigned long flag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11440 | |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11441 | /* The caller might set context1 for extended buffer */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 11442 | if (pmboxq->context1) |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11443 | mb = (MAILBOX_t *)pmboxq->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11444 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 11445 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11446 | /* setup wake call as IOCB callback */ |
| 11447 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; |
| 11448 | /* setup context field to pass wait_queue pointer to wake function */ |
| 11449 | pmboxq->context1 = &done_q; |
| 11450 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11451 | /* now issue the command */ |
| 11452 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11453 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11454 | wait_event_interruptible_timeout(done_q, |
| 11455 | pmboxq->mbox_flag & LPFC_MBX_WAKE, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 11456 | msecs_to_jiffies(timeout * 1000)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11457 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11458 | spin_lock_irqsave(&phba->hbalock, flag); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11459 | /* restore the possible extended buffer for free resource */ |
| 11460 | pmboxq->context1 = (uint8_t *)mb; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11461 | /* |
| 11462 | * if LPFC_MBX_WAKE flag is set the mailbox is completed |
| 11463 | * else do not free the resources. |
| 11464 | */ |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 11465 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11466 | retval = MBX_SUCCESS; |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 11467 | } else { |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 11468 | retval = MBX_TIMEOUT; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11469 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 11470 | } |
| 11471 | spin_unlock_irqrestore(&phba->hbalock, flag); |
James Smart | b230b8a2 | 2013-05-31 17:05:27 -0400 | [diff] [blame] | 11472 | } else { |
| 11473 | /* restore the possible extended buffer for free resource */ |
| 11474 | pmboxq->context1 = (uint8_t *)mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11475 | } |
| 11476 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11477 | return retval; |
| 11478 | } |
| 11479 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11480 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11481 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11482 | * @phba: Pointer to HBA context. |
| 11483 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11484 | * This function is called to shutdown the driver's mailbox sub-system. |
| 11485 | * It first marks the mailbox sub-system is in a block state to prevent |
| 11486 | * the asynchronous mailbox command from issued off the pending mailbox |
| 11487 | * command queue. If the mailbox command sub-system shutdown is due to |
| 11488 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
| 11489 | * the mailbox sub-system flush routine to forcefully bring down the |
| 11490 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
| 11491 | * as with offline or HBA function reset), this routine will wait for the |
| 11492 | * outstanding mailbox command to complete before invoking the mailbox |
| 11493 | * sub-system flush routine to gracefully bring down mailbox sub-system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11494 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11495 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11496 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11497 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11498 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11499 | unsigned long timeout; |
| 11500 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11501 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 11502 | /* delay 100ms for port state */ |
| 11503 | msleep(100); |
| 11504 | lpfc_sli_mbox_sys_flush(phba); |
| 11505 | return; |
| 11506 | } |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11507 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 11508 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11509 | spin_lock_irq(&phba->hbalock); |
| 11510 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11511 | |
| 11512 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11513 | /* Determine how long we might wait for the active mailbox |
| 11514 | * command to be gracefully completed by firmware. |
| 11515 | */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 11516 | if (phba->sli.mbox_active) |
| 11517 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 11518 | phba->sli.mbox_active) * |
| 11519 | 1000) + jiffies; |
| 11520 | spin_unlock_irq(&phba->hbalock); |
| 11521 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11522 | while (phba->sli.mbox_active) { |
| 11523 | /* Check active mailbox complete status every 2ms */ |
| 11524 | msleep(2); |
| 11525 | if (time_after(jiffies, timeout)) |
| 11526 | /* Timeout, let the mailbox flush routine to |
| 11527 | * forcefully release active mailbox command |
| 11528 | */ |
| 11529 | break; |
| 11530 | } |
James Smart | d7069f0 | 2012-03-01 22:36:29 -0500 | [diff] [blame] | 11531 | } else |
| 11532 | spin_unlock_irq(&phba->hbalock); |
| 11533 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11534 | lpfc_sli_mbox_sys_flush(phba); |
| 11535 | } |
| 11536 | |
| 11537 | /** |
| 11538 | * lpfc_sli_eratt_read - read sli-3 error attention events |
| 11539 | * @phba: Pointer to HBA context. |
| 11540 | * |
| 11541 | * This function is called to read the SLI3 device error attention registers |
| 11542 | * for possible error attention events. The caller must hold the hostlock |
| 11543 | * with spin_lock_irq(). |
| 11544 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11545 | * 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] | 11546 | * Register and returns 0 otherwise. |
| 11547 | **/ |
| 11548 | static int |
| 11549 | lpfc_sli_eratt_read(struct lpfc_hba *phba) |
| 11550 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 11551 | uint32_t ha_copy; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11552 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11553 | /* Read chip Host Attention (HA) register */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11554 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11555 | goto unplug_err; |
| 11556 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11557 | if (ha_copy & HA_ERATT) { |
| 11558 | /* Read host status register to retrieve error event */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11559 | if (lpfc_sli_read_hs(phba)) |
| 11560 | goto unplug_err; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11561 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11562 | /* Check if there is a deferred error condition is active */ |
| 11563 | if ((HS_FFER1 & phba->work_hs) && |
| 11564 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 11565 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11566 | phba->hba_flag |= DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11567 | /* Clear all interrupt enable conditions */ |
| 11568 | writel(0, phba->HCregaddr); |
| 11569 | readl(phba->HCregaddr); |
| 11570 | } |
| 11571 | |
| 11572 | /* Set the driver HA work bitmap */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11573 | phba->work_ha |= HA_ERATT; |
| 11574 | /* Indicate polling handles this ERATT */ |
| 11575 | phba->hba_flag |= HBA_ERATT_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11576 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11577 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11578 | return 0; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11579 | |
| 11580 | unplug_err: |
| 11581 | /* Set the driver HS work bitmap */ |
| 11582 | phba->work_hs |= UNPLUG_ERR; |
| 11583 | /* Set the driver HA work bitmap */ |
| 11584 | phba->work_ha |= HA_ERATT; |
| 11585 | /* Indicate polling handles this ERATT */ |
| 11586 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11587 | return 1; |
James Smart | b4c0265 | 2006-07-06 15:50:43 -0400 | [diff] [blame] | 11588 | } |
| 11589 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11590 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11591 | * lpfc_sli4_eratt_read - read sli-4 error attention events |
| 11592 | * @phba: Pointer to HBA context. |
| 11593 | * |
| 11594 | * This function is called to read the SLI4 device error attention registers |
| 11595 | * for possible error attention events. The caller must hold the hostlock |
| 11596 | * with spin_lock_irq(). |
| 11597 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11598 | * 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] | 11599 | * Register and returns 0 otherwise. |
| 11600 | **/ |
| 11601 | static int |
| 11602 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) |
| 11603 | { |
| 11604 | uint32_t uerr_sta_hi, uerr_sta_lo; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11605 | uint32_t if_type, portsmphr; |
| 11606 | struct lpfc_register portstat_reg; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11607 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11608 | /* |
| 11609 | * For now, use the SLI4 device internal unrecoverable error |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11610 | * registers for error attention. This can be changed later. |
| 11611 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11612 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 11613 | switch (if_type) { |
| 11614 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11615 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 11616 | &uerr_sta_lo) || |
| 11617 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, |
| 11618 | &uerr_sta_hi)) { |
| 11619 | phba->work_hs |= UNPLUG_ERR; |
| 11620 | phba->work_ha |= HA_ERATT; |
| 11621 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11622 | return 1; |
| 11623 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11624 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
| 11625 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { |
| 11626 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11627 | "1423 HBA Unrecoverable error: " |
| 11628 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " |
| 11629 | "ue_mask_lo_reg=0x%x, " |
| 11630 | "ue_mask_hi_reg=0x%x\n", |
| 11631 | uerr_sta_lo, uerr_sta_hi, |
| 11632 | phba->sli4_hba.ue_mask_lo, |
| 11633 | phba->sli4_hba.ue_mask_hi); |
| 11634 | phba->work_status[0] = uerr_sta_lo; |
| 11635 | phba->work_status[1] = uerr_sta_hi; |
| 11636 | phba->work_ha |= HA_ERATT; |
| 11637 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11638 | return 1; |
| 11639 | } |
| 11640 | break; |
| 11641 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11642 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 11643 | &portstat_reg.word0) || |
| 11644 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 11645 | &portsmphr)){ |
| 11646 | phba->work_hs |= UNPLUG_ERR; |
| 11647 | phba->work_ha |= HA_ERATT; |
| 11648 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11649 | return 1; |
| 11650 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11651 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
| 11652 | phba->work_status[0] = |
| 11653 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 11654 | phba->work_status[1] = |
| 11655 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 11656 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11657 | "2885 Port Status Event: " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11658 | "port status reg 0x%x, " |
| 11659 | "port smphr reg 0x%x, " |
| 11660 | "error 1=0x%x, error 2=0x%x\n", |
| 11661 | portstat_reg.word0, |
| 11662 | portsmphr, |
| 11663 | phba->work_status[0], |
| 11664 | phba->work_status[1]); |
| 11665 | phba->work_ha |= HA_ERATT; |
| 11666 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11667 | return 1; |
| 11668 | } |
| 11669 | break; |
| 11670 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 11671 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11672 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11673 | "2886 HBA Error Attention on unsupported " |
| 11674 | "if type %d.", if_type); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11675 | return 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11676 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11677 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11678 | return 0; |
| 11679 | } |
| 11680 | |
| 11681 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 11682 | * lpfc_sli_check_eratt - check error attention events |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11683 | * @phba: Pointer to HBA context. |
| 11684 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11685 | * 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] | 11686 | * error attention register bit for error attention events. |
| 11687 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11688 | * 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] | 11689 | * Register and returns 0 otherwise. |
| 11690 | **/ |
| 11691 | int |
| 11692 | lpfc_sli_check_eratt(struct lpfc_hba *phba) |
| 11693 | { |
| 11694 | uint32_t ha_copy; |
| 11695 | |
| 11696 | /* If somebody is waiting to handle an eratt, don't process it |
| 11697 | * here. The brdkill function will do this. |
| 11698 | */ |
| 11699 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11700 | return 0; |
| 11701 | |
| 11702 | /* Check if interrupt handler handles this ERATT */ |
| 11703 | spin_lock_irq(&phba->hbalock); |
| 11704 | if (phba->hba_flag & HBA_ERATT_HANDLED) { |
| 11705 | /* Interrupt handler has handled ERATT */ |
| 11706 | spin_unlock_irq(&phba->hbalock); |
| 11707 | return 0; |
| 11708 | } |
| 11709 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11710 | /* |
| 11711 | * If there is deferred error attention, do not check for error |
| 11712 | * attention |
| 11713 | */ |
| 11714 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
| 11715 | spin_unlock_irq(&phba->hbalock); |
| 11716 | return 0; |
| 11717 | } |
| 11718 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11719 | /* If PCI channel is offline, don't process it */ |
| 11720 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11721 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11722 | return 0; |
| 11723 | } |
| 11724 | |
| 11725 | switch (phba->sli_rev) { |
| 11726 | case LPFC_SLI_REV2: |
| 11727 | case LPFC_SLI_REV3: |
| 11728 | /* Read chip Host Attention (HA) register */ |
| 11729 | ha_copy = lpfc_sli_eratt_read(phba); |
| 11730 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11731 | case LPFC_SLI_REV4: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11732 | /* Read device Uncoverable Error (UERR) registers */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11733 | ha_copy = lpfc_sli4_eratt_read(phba); |
| 11734 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11735 | default: |
| 11736 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11737 | "0299 Invalid SLI revision (%d)\n", |
| 11738 | phba->sli_rev); |
| 11739 | ha_copy = 0; |
| 11740 | break; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11741 | } |
| 11742 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11743 | |
| 11744 | return ha_copy; |
| 11745 | } |
| 11746 | |
| 11747 | /** |
| 11748 | * lpfc_intr_state_check - Check device state for interrupt handling |
| 11749 | * @phba: Pointer to HBA context. |
| 11750 | * |
| 11751 | * This inline routine checks whether a device or its PCI slot is in a state |
| 11752 | * that the interrupt should be handled. |
| 11753 | * |
| 11754 | * This function returns 0 if the device or the PCI slot is in a state that |
| 11755 | * interrupt should be handled, otherwise -EIO. |
| 11756 | */ |
| 11757 | static inline int |
| 11758 | lpfc_intr_state_check(struct lpfc_hba *phba) |
| 11759 | { |
| 11760 | /* If the pci channel is offline, ignore all the interrupts */ |
| 11761 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 11762 | return -EIO; |
| 11763 | |
| 11764 | /* Update device level interrupt statistics */ |
| 11765 | phba->sli.slistat.sli_intr++; |
| 11766 | |
| 11767 | /* Ignore all interrupts during initialization. */ |
| 11768 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
| 11769 | return -EIO; |
| 11770 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11771 | return 0; |
| 11772 | } |
| 11773 | |
| 11774 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11775 | * 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] | 11776 | * @irq: Interrupt number. |
| 11777 | * @dev_id: The device context pointer. |
| 11778 | * |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11779 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11780 | * service routine when device with SLI-3 interface spec is enabled with |
| 11781 | * MSI-X multi-message interrupt mode and there are slow-path events in |
| 11782 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
| 11783 | * interrupt mode, this function is called as part of the device-level |
| 11784 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
| 11785 | * is undergoing initialization, the interrupt handler will not process |
| 11786 | * the interrupt. The link attention and ELS ring attention events are |
| 11787 | * handled by the worker thread. The interrupt handler signals the worker |
| 11788 | * thread and returns for these events. This function is called without |
| 11789 | * 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] | 11790 | * structures. |
| 11791 | * |
| 11792 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 11793 | * returns IRQ_NONE. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11794 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11795 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11796 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11797 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 11798 | struct lpfc_hba *phba; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11799 | uint32_t ha_copy, hc_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11800 | uint32_t work_ha_copy; |
| 11801 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11802 | unsigned long iflag; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11803 | uint32_t control; |
| 11804 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11805 | MAILBOX_t *mbox, *pmbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11806 | struct lpfc_vport *vport; |
| 11807 | struct lpfc_nodelist *ndlp; |
| 11808 | struct lpfc_dmabuf *mp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11809 | LPFC_MBOXQ_t *pmb; |
| 11810 | int rc; |
| 11811 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11812 | /* |
| 11813 | * Get the driver's phba structure from the dev_id and |
| 11814 | * assume the HBA is not interrupting. |
| 11815 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11816 | phba = (struct lpfc_hba *)dev_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11817 | |
| 11818 | if (unlikely(!phba)) |
| 11819 | return IRQ_NONE; |
| 11820 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11821 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11822 | * Stuff needs to be attented to when this function is invoked as an |
| 11823 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11824 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11825 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11826 | /* Check device state for handling interrupt */ |
| 11827 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11828 | return IRQ_NONE; |
| 11829 | /* Need to read HA REG for slow-path events */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11830 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11831 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 11832 | goto unplug_error; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11833 | /* If somebody is waiting to handle an eratt don't process it |
| 11834 | * here. The brdkill function will do this. |
| 11835 | */ |
| 11836 | if (phba->link_flag & LS_IGNORE_ERATT) |
| 11837 | ha_copy &= ~HA_ERATT; |
| 11838 | /* Check the need for handling ERATT in interrupt handler */ |
| 11839 | if (ha_copy & HA_ERATT) { |
| 11840 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 11841 | /* ERATT polling has handled ERATT */ |
| 11842 | ha_copy &= ~HA_ERATT; |
| 11843 | else |
| 11844 | /* Indicate interrupt handler handles ERATT */ |
| 11845 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 11846 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11847 | |
| 11848 | /* |
| 11849 | * If there is deferred error attention, do not check for any |
| 11850 | * interrupt. |
| 11851 | */ |
| 11852 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11853 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11854 | return IRQ_NONE; |
| 11855 | } |
| 11856 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11857 | /* Clear up only attention source related to slow-path */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11858 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
| 11859 | goto unplug_error; |
| 11860 | |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11861 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
| 11862 | HC_LAINT_ENA | HC_ERINT_ENA), |
| 11863 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11864 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
| 11865 | phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 11866 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11867 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11868 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11869 | } else |
| 11870 | ha_copy = phba->ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11871 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11872 | work_ha_copy = ha_copy & phba->work_ha_mask; |
| 11873 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11874 | if (work_ha_copy) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11875 | if (work_ha_copy & HA_LATT) { |
| 11876 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { |
| 11877 | /* |
| 11878 | * Turn off Link Attention interrupts |
| 11879 | * until CLEAR_LA done |
| 11880 | */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11881 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11882 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11883 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11884 | goto unplug_error; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11885 | control &= ~HC_LAINT_ENA; |
| 11886 | writel(control, phba->HCregaddr); |
| 11887 | readl(phba->HCregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11888 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11889 | } |
| 11890 | else |
| 11891 | work_ha_copy &= ~HA_LATT; |
| 11892 | } |
| 11893 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11894 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11895 | /* |
| 11896 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is |
| 11897 | * the only slow ring. |
| 11898 | */ |
| 11899 | status = (work_ha_copy & |
| 11900 | (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 11901 | status >>= (4*LPFC_ELS_RING); |
| 11902 | if (status & HA_RXMASK) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11903 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11904 | if (lpfc_readl(phba->HCregaddr, &control)) |
| 11905 | goto unplug_error; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11906 | |
| 11907 | lpfc_debugfs_slow_ring_trc(phba, |
| 11908 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", |
| 11909 | control, status, |
| 11910 | (uint32_t)phba->sli.slistat.sli_intr); |
| 11911 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11912 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11913 | lpfc_debugfs_slow_ring_trc(phba, |
| 11914 | "ISR Disable ring:" |
| 11915 | "pwork:x%x hawork:x%x wait:x%x", |
| 11916 | phba->work_ha, work_ha_copy, |
| 11917 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11918 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11919 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11920 | control &= |
| 11921 | ~(HC_R0INT_ENA << LPFC_ELS_RING); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11922 | writel(control, phba->HCregaddr); |
| 11923 | readl(phba->HCregaddr); /* flush */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11924 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11925 | else { |
| 11926 | lpfc_debugfs_slow_ring_trc(phba, |
| 11927 | "ISR slow ring: pwork:" |
| 11928 | "x%x hawork:x%x wait:x%x", |
| 11929 | phba->work_ha, work_ha_copy, |
| 11930 | (uint32_t)((unsigned long) |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 11931 | &phba->work_waitq)); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 11932 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11933 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 11934 | } |
| 11935 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11936 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11937 | if (work_ha_copy & HA_ERATT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 11938 | if (lpfc_sli_read_hs(phba)) |
| 11939 | goto unplug_error; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11940 | /* |
| 11941 | * Check if there is a deferred error condition |
| 11942 | * is active |
| 11943 | */ |
| 11944 | if ((HS_FFER1 & phba->work_hs) && |
| 11945 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 11946 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
| 11947 | phba->work_hs)) { |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 11948 | phba->hba_flag |= DEFER_ERATT; |
| 11949 | /* Clear all interrupt enable conditions */ |
| 11950 | writel(0, phba->HCregaddr); |
| 11951 | readl(phba->HCregaddr); |
| 11952 | } |
| 11953 | } |
| 11954 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 11955 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11956 | pmb = phba->sli.mbox_active; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 11957 | pmbox = &pmb->u.mb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 11958 | mbox = phba->mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11959 | vport = pmb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11960 | |
| 11961 | /* First check out the status word */ |
| 11962 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); |
| 11963 | if (pmbox->mbxOwner != OWN_HOST) { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11964 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11965 | /* |
| 11966 | * Stray Mailbox Interrupt, mbxCommand <cmd> |
| 11967 | * mbxStatus <status> |
| 11968 | */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11969 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11970 | LOG_SLI, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11971 | "(%d):0304 Stray Mailbox " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11972 | "Interrupt mbxCommand x%x " |
| 11973 | "mbxStatus x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 11974 | (vport ? vport->vpi : 0), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11975 | pmbox->mbxCommand, |
| 11976 | pmbox->mbxStatus); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11977 | /* clear mailbox attention bit */ |
| 11978 | work_ha_copy &= ~HA_MBATT; |
| 11979 | } else { |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 11980 | phba->sli.mbox_active = NULL; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11981 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11982 | phba->last_completion_time = jiffies; |
| 11983 | del_timer(&phba->sli.mbox_tmo); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11984 | if (pmb->mbox_cmpl) { |
| 11985 | lpfc_sli_pcimem_bcopy(mbox, pmbox, |
| 11986 | MAILBOX_CMD_SIZE); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 11987 | if (pmb->out_ext_byte_len && |
| 11988 | pmb->context2) |
| 11989 | lpfc_sli_pcimem_bcopy( |
| 11990 | phba->mbox_ext, |
| 11991 | pmb->context2, |
| 11992 | pmb->out_ext_byte_len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 11993 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 11994 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 11995 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 11996 | |
| 11997 | lpfc_debugfs_disc_trc(vport, |
| 11998 | LPFC_DISC_TRC_MBOX_VPORT, |
| 11999 | "MBOX dflt rpi: : " |
| 12000 | "status:x%x rpi:x%x", |
| 12001 | (uint32_t)pmbox->mbxStatus, |
| 12002 | pmbox->un.varWords[0], 0); |
| 12003 | |
| 12004 | if (!pmbox->mbxStatus) { |
| 12005 | mp = (struct lpfc_dmabuf *) |
| 12006 | (pmb->context1); |
| 12007 | ndlp = (struct lpfc_nodelist *) |
| 12008 | pmb->context2; |
| 12009 | |
| 12010 | /* Reg_LOGIN of dflt RPI was |
| 12011 | * successful. new lets get |
| 12012 | * rid of the RPI using the |
| 12013 | * same mbox buffer. |
| 12014 | */ |
| 12015 | lpfc_unreg_login(phba, |
| 12016 | vport->vpi, |
| 12017 | pmbox->un.varWords[0], |
| 12018 | pmb); |
| 12019 | pmb->mbox_cmpl = |
| 12020 | lpfc_mbx_cmpl_dflt_rpi; |
| 12021 | pmb->context1 = mp; |
| 12022 | pmb->context2 = ndlp; |
| 12023 | pmb->vport = vport; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12024 | rc = lpfc_sli_issue_mbox(phba, |
| 12025 | pmb, |
| 12026 | MBX_NOWAIT); |
| 12027 | if (rc != MBX_BUSY) |
| 12028 | lpfc_printf_log(phba, |
| 12029 | KERN_ERR, |
| 12030 | LOG_MBOX | LOG_SLI, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 12031 | "0350 rc should have" |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12032 | "been MBX_BUSY\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12033 | if (rc != MBX_NOT_FINISHED) |
| 12034 | goto send_current_mbox; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12035 | } |
| 12036 | } |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12037 | spin_lock_irqsave( |
| 12038 | &phba->pport->work_port_lock, |
| 12039 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12040 | phba->pport->work_port_events &= |
| 12041 | ~WORKER_MBOX_TMO; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12042 | spin_unlock_irqrestore( |
| 12043 | &phba->pport->work_port_lock, |
| 12044 | iflag); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 12045 | lpfc_mbox_cmpl_put(phba, pmb); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12046 | } |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 12047 | } else |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12048 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12049 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12050 | if ((work_ha_copy & HA_MBATT) && |
| 12051 | (phba->sli.mbox_active == NULL)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12052 | send_current_mbox: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12053 | /* Process next mailbox command if there is one */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 12054 | do { |
| 12055 | rc = lpfc_sli_issue_mbox(phba, NULL, |
| 12056 | MBX_NOWAIT); |
| 12057 | } while (rc == MBX_NOT_FINISHED); |
| 12058 | if (rc != MBX_SUCCESS) |
| 12059 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12060 | LOG_SLI, "0349 rc should be " |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12061 | "MBX_SUCCESS\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12062 | } |
| 12063 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12064 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12065 | phba->work_ha |= work_ha_copy; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12066 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 12067 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12068 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12069 | return IRQ_HANDLED; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12070 | unplug_error: |
| 12071 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 12072 | return IRQ_HANDLED; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12073 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12074 | } /* lpfc_sli_sp_intr_handler */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12075 | |
| 12076 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12077 | * 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] | 12078 | * @irq: Interrupt number. |
| 12079 | * @dev_id: The device context pointer. |
| 12080 | * |
| 12081 | * This function is directly called from the PCI layer as an interrupt |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12082 | * service routine when device with SLI-3 interface spec is enabled with |
| 12083 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 12084 | * ring event in the HBA. However, when the device is enabled with either |
| 12085 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 12086 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 12087 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 12088 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 12089 | * the intrrupt context. This function is called without any lock held. |
| 12090 | * It gets the hbalock to access and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12091 | * |
| 12092 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 12093 | * returns IRQ_NONE. |
| 12094 | **/ |
| 12095 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12096 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12097 | { |
| 12098 | struct lpfc_hba *phba; |
| 12099 | uint32_t ha_copy; |
| 12100 | unsigned long status; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12101 | unsigned long iflag; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12102 | struct lpfc_sli_ring *pring; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12103 | |
| 12104 | /* Get the driver's phba structure from the dev_id and |
| 12105 | * assume the HBA is not interrupting. |
| 12106 | */ |
| 12107 | phba = (struct lpfc_hba *) dev_id; |
| 12108 | |
| 12109 | if (unlikely(!phba)) |
| 12110 | return IRQ_NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12111 | |
| 12112 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12113 | * Stuff needs to be attented to when this function is invoked as an |
| 12114 | * individual interrupt handler in MSI-X multi-message interrupt mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12115 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12116 | if (phba->intr_type == MSIX) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12117 | /* Check device state for handling interrupt */ |
| 12118 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12119 | return IRQ_NONE; |
| 12120 | /* Need to read HA REG for FCP ring and other ring events */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12121 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
| 12122 | return IRQ_HANDLED; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12123 | /* Clear up only attention source related to fast-path */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12124 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12125 | /* |
| 12126 | * If there is deferred error attention, do not check for |
| 12127 | * any interrupt. |
| 12128 | */ |
| 12129 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12130 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12131 | return IRQ_NONE; |
| 12132 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12133 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
| 12134 | phba->HAregaddr); |
| 12135 | readl(phba->HAregaddr); /* flush */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12136 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12137 | } else |
| 12138 | ha_copy = phba->ha_copy; |
| 12139 | |
| 12140 | /* |
| 12141 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
| 12142 | */ |
| 12143 | ha_copy &= ~(phba->work_ha_mask); |
| 12144 | |
| 12145 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12146 | status >>= (4*LPFC_FCP_RING); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12147 | pring = &phba->sli.sli3_ring[LPFC_FCP_RING]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12148 | if (status & HA_RXMASK) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12149 | lpfc_sli_handle_fast_ring_event(phba, pring, status); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12150 | |
| 12151 | if (phba->cfg_multi_ring_support == 2) { |
| 12152 | /* |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12153 | * Process all events on extra ring. Take the optimized path |
| 12154 | * for extra ring IO. |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12155 | */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12156 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12157 | status >>= (4*LPFC_EXTRA_RING); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12158 | if (status & HA_RXMASK) { |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12159 | lpfc_sli_handle_fast_ring_event(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12160 | &phba->sli.sli3_ring[LPFC_EXTRA_RING], |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 12161 | status); |
| 12162 | } |
| 12163 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12164 | return IRQ_HANDLED; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12165 | } /* lpfc_sli_fp_intr_handler */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12166 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12167 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12168 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12169 | * @irq: Interrupt number. |
| 12170 | * @dev_id: The device context pointer. |
| 12171 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12172 | * This function is the HBA device-level interrupt handler to device with |
| 12173 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
| 12174 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
| 12175 | * requires driver attention. This function invokes the slow-path interrupt |
| 12176 | * attention handling function and fast-path interrupt attention handling |
| 12177 | * function in turn to process the relevant HBA attention events. This |
| 12178 | * function is called without any lock held. It gets the hbalock to access |
| 12179 | * and update SLI data structures. |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12180 | * |
| 12181 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 12182 | * returns IRQ_NONE. |
| 12183 | **/ |
| 12184 | irqreturn_t |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12185 | lpfc_sli_intr_handler(int irq, void *dev_id) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12186 | { |
| 12187 | struct lpfc_hba *phba; |
| 12188 | irqreturn_t sp_irq_rc, fp_irq_rc; |
| 12189 | unsigned long status1, status2; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12190 | uint32_t hc_copy; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12191 | |
| 12192 | /* |
| 12193 | * Get the driver's phba structure from the dev_id and |
| 12194 | * assume the HBA is not interrupting. |
| 12195 | */ |
| 12196 | phba = (struct lpfc_hba *) dev_id; |
| 12197 | |
| 12198 | if (unlikely(!phba)) |
| 12199 | return IRQ_NONE; |
| 12200 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12201 | /* Check device state for handling interrupt */ |
| 12202 | if (lpfc_intr_state_check(phba)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12203 | return IRQ_NONE; |
| 12204 | |
| 12205 | spin_lock(&phba->hbalock); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12206 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
| 12207 | spin_unlock(&phba->hbalock); |
| 12208 | return IRQ_HANDLED; |
| 12209 | } |
| 12210 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12211 | if (unlikely(!phba->ha_copy)) { |
| 12212 | spin_unlock(&phba->hbalock); |
| 12213 | return IRQ_NONE; |
| 12214 | } else if (phba->ha_copy & HA_ERATT) { |
| 12215 | if (phba->hba_flag & HBA_ERATT_HANDLED) |
| 12216 | /* ERATT polling has handled ERATT */ |
| 12217 | phba->ha_copy &= ~HA_ERATT; |
| 12218 | else |
| 12219 | /* Indicate interrupt handler handles ERATT */ |
| 12220 | phba->hba_flag |= HBA_ERATT_HANDLED; |
| 12221 | } |
| 12222 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12223 | /* |
| 12224 | * If there is deferred error attention, do not check for any interrupt. |
| 12225 | */ |
| 12226 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 12227 | spin_unlock(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12228 | return IRQ_NONE; |
| 12229 | } |
| 12230 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12231 | /* Clear attention sources except link and error attentions */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 12232 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
| 12233 | spin_unlock(&phba->hbalock); |
| 12234 | return IRQ_HANDLED; |
| 12235 | } |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12236 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
| 12237 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), |
| 12238 | phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12239 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 12240 | writel(hc_copy, phba->HCregaddr); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12241 | readl(phba->HAregaddr); /* flush */ |
| 12242 | spin_unlock(&phba->hbalock); |
| 12243 | |
| 12244 | /* |
| 12245 | * Invokes slow-path host attention interrupt handling as appropriate. |
| 12246 | */ |
| 12247 | |
| 12248 | /* status of events with mailbox and link attention */ |
| 12249 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); |
| 12250 | |
| 12251 | /* status of events with ELS ring */ |
| 12252 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); |
| 12253 | status2 >>= (4*LPFC_ELS_RING); |
| 12254 | |
| 12255 | if (status1 || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12256 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12257 | else |
| 12258 | sp_irq_rc = IRQ_NONE; |
| 12259 | |
| 12260 | /* |
| 12261 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 12262 | */ |
| 12263 | |
| 12264 | /* status of events with FCP ring */ |
| 12265 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); |
| 12266 | status1 >>= (4*LPFC_FCP_RING); |
| 12267 | |
| 12268 | /* status of events with extra ring */ |
| 12269 | if (phba->cfg_multi_ring_support == 2) { |
| 12270 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
| 12271 | status2 >>= (4*LPFC_EXTRA_RING); |
| 12272 | } else |
| 12273 | status2 = 0; |
| 12274 | |
| 12275 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12276 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 12277 | else |
| 12278 | fp_irq_rc = IRQ_NONE; |
| 12279 | |
| 12280 | /* Return device-level interrupt handling status */ |
| 12281 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12282 | } /* lpfc_sli_intr_handler */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12283 | |
| 12284 | /** |
| 12285 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event |
| 12286 | * @phba: pointer to lpfc hba data structure. |
| 12287 | * |
| 12288 | * This routine is invoked by the worker thread to process all the pending |
| 12289 | * SLI4 FCP abort XRI events. |
| 12290 | **/ |
| 12291 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12292 | { |
| 12293 | struct lpfc_cq_event *cq_event; |
| 12294 | |
| 12295 | /* First, declare the fcp xri abort event has been handled */ |
| 12296 | spin_lock_irq(&phba->hbalock); |
| 12297 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; |
| 12298 | spin_unlock_irq(&phba->hbalock); |
| 12299 | /* Now, handle all the fcp xri abort events */ |
| 12300 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { |
| 12301 | /* Get the first event from the head of the event queue */ |
| 12302 | spin_lock_irq(&phba->hbalock); |
| 12303 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 12304 | cq_event, struct lpfc_cq_event, list); |
| 12305 | spin_unlock_irq(&phba->hbalock); |
| 12306 | /* Notify aborted XRI for FCP work queue */ |
| 12307 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12308 | /* Free the event processed back to the free pool */ |
| 12309 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12310 | } |
| 12311 | } |
| 12312 | |
| 12313 | /** |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 12314 | * lpfc_sli4_nvme_xri_abort_event_proc - Process nvme xri abort event |
| 12315 | * @phba: pointer to lpfc hba data structure. |
| 12316 | * |
| 12317 | * This routine is invoked by the worker thread to process all the pending |
| 12318 | * SLI4 NVME abort XRI events. |
| 12319 | **/ |
| 12320 | void lpfc_sli4_nvme_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12321 | { |
| 12322 | struct lpfc_cq_event *cq_event; |
| 12323 | |
| 12324 | /* First, declare the fcp xri abort event has been handled */ |
| 12325 | spin_lock_irq(&phba->hbalock); |
| 12326 | phba->hba_flag &= ~NVME_XRI_ABORT_EVENT; |
| 12327 | spin_unlock_irq(&phba->hbalock); |
| 12328 | /* Now, handle all the fcp xri abort events */ |
| 12329 | while (!list_empty(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue)) { |
| 12330 | /* Get the first event from the head of the event queue */ |
| 12331 | spin_lock_irq(&phba->hbalock); |
| 12332 | list_remove_head(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue, |
| 12333 | cq_event, struct lpfc_cq_event, list); |
| 12334 | spin_unlock_irq(&phba->hbalock); |
| 12335 | /* Notify aborted XRI for NVME work queue */ |
| 12336 | if (phba->nvmet_support) { |
| 12337 | lpfc_sli4_nvmet_xri_aborted(phba, |
| 12338 | &cq_event->cqe.wcqe_axri); |
| 12339 | } else { |
| 12340 | lpfc_sli4_nvme_xri_aborted(phba, |
| 12341 | &cq_event->cqe.wcqe_axri); |
| 12342 | } |
| 12343 | /* Free the event processed back to the free pool */ |
| 12344 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12345 | } |
| 12346 | } |
| 12347 | |
| 12348 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12349 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event |
| 12350 | * @phba: pointer to lpfc hba data structure. |
| 12351 | * |
| 12352 | * This routine is invoked by the worker thread to process all the pending |
| 12353 | * SLI4 els abort xri events. |
| 12354 | **/ |
| 12355 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) |
| 12356 | { |
| 12357 | struct lpfc_cq_event *cq_event; |
| 12358 | |
| 12359 | /* First, declare the els xri abort event has been handled */ |
| 12360 | spin_lock_irq(&phba->hbalock); |
| 12361 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; |
| 12362 | spin_unlock_irq(&phba->hbalock); |
| 12363 | /* Now, handle all the els xri abort events */ |
| 12364 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { |
| 12365 | /* Get the first event from the head of the event queue */ |
| 12366 | spin_lock_irq(&phba->hbalock); |
| 12367 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 12368 | cq_event, struct lpfc_cq_event, list); |
| 12369 | spin_unlock_irq(&phba->hbalock); |
| 12370 | /* Notify aborted XRI for ELS work queue */ |
| 12371 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); |
| 12372 | /* Free the event processed back to the free pool */ |
| 12373 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 12374 | } |
| 12375 | } |
| 12376 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12377 | /** |
| 12378 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn |
| 12379 | * @phba: pointer to lpfc hba data structure |
| 12380 | * @pIocbIn: pointer to the rspiocbq |
| 12381 | * @pIocbOut: pointer to the cmdiocbq |
| 12382 | * @wcqe: pointer to the complete wcqe |
| 12383 | * |
| 12384 | * This routine transfers the fields of a command iocbq to a response iocbq |
| 12385 | * by copying all the IOCB fields from command iocbq and transferring the |
| 12386 | * completion status information from the complete wcqe. |
| 12387 | **/ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12388 | static void |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12389 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
| 12390 | struct lpfc_iocbq *pIocbIn, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12391 | struct lpfc_iocbq *pIocbOut, |
| 12392 | struct lpfc_wcqe_complete *wcqe) |
| 12393 | { |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12394 | int numBdes, i; |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12395 | unsigned long iflags; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12396 | uint32_t status, max_response; |
| 12397 | struct lpfc_dmabuf *dmabuf; |
| 12398 | struct ulp_bde64 *bpl, bde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12399 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
| 12400 | |
| 12401 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, |
| 12402 | sizeof(struct lpfc_iocbq) - offset); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12403 | /* Map WCQE parameters into irspiocb parameters */ |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12404 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
| 12405 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12406 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
| 12407 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) |
| 12408 | pIocbIn->iocb.un.fcpi.fcpi_parm = |
| 12409 | pIocbOut->iocb.un.fcpi.fcpi_parm - |
| 12410 | wcqe->total_data_placed; |
| 12411 | else |
| 12412 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12413 | else { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12414 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
James Smart | af22741 | 2013-10-10 12:23:10 -0400 | [diff] [blame] | 12415 | switch (pIocbOut->iocb.ulpCommand) { |
| 12416 | case CMD_ELS_REQUEST64_CR: |
| 12417 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12418 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12419 | bde.tus.w = le32_to_cpu(bpl[1].tus.w); |
| 12420 | max_response = bde.tus.f.bdeSize; |
| 12421 | break; |
| 12422 | case CMD_GEN_REQUEST64_CR: |
| 12423 | max_response = 0; |
| 12424 | if (!pIocbOut->context3) |
| 12425 | break; |
| 12426 | numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/ |
| 12427 | sizeof(struct ulp_bde64); |
| 12428 | dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3; |
| 12429 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 12430 | for (i = 0; i < numBdes; i++) { |
| 12431 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
| 12432 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
| 12433 | max_response += bde.tus.f.bdeSize; |
| 12434 | } |
| 12435 | break; |
| 12436 | default: |
| 12437 | max_response = wcqe->total_data_placed; |
| 12438 | break; |
| 12439 | } |
| 12440 | if (max_response < wcqe->total_data_placed) |
| 12441 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response; |
| 12442 | else |
| 12443 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = |
| 12444 | wcqe->total_data_placed; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 12445 | } |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12446 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 12447 | /* Convert BG errors for completion status */ |
| 12448 | if (status == CQE_STATUS_DI_ERROR) { |
| 12449 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
| 12450 | |
| 12451 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) |
| 12452 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; |
| 12453 | else |
| 12454 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; |
| 12455 | |
| 12456 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; |
| 12457 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ |
| 12458 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12459 | BGS_GUARD_ERR_MASK; |
| 12460 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ |
| 12461 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12462 | BGS_APPTAG_ERR_MASK; |
| 12463 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ |
| 12464 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12465 | BGS_REFTAG_ERR_MASK; |
| 12466 | |
| 12467 | /* Check to see if there was any good data before the error */ |
| 12468 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { |
| 12469 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12470 | BGS_HI_WATER_MARK_PRESENT_MASK; |
| 12471 | pIocbIn->iocb.unsli3.sli3_bg.bghm = |
| 12472 | wcqe->total_data_placed; |
| 12473 | } |
| 12474 | |
| 12475 | /* |
| 12476 | * Set ALL the error bits to indicate we don't know what |
| 12477 | * type of error it is. |
| 12478 | */ |
| 12479 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) |
| 12480 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= |
| 12481 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | |
| 12482 | BGS_GUARD_ERR_MASK); |
| 12483 | } |
| 12484 | |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12485 | /* Pick up HBA exchange busy condition */ |
| 12486 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { |
| 12487 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12488 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; |
| 12489 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12490 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12491 | } |
| 12492 | |
| 12493 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12494 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe |
| 12495 | * @phba: Pointer to HBA context object. |
| 12496 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12497 | * |
| 12498 | * This routine handles an ELS work-queue completion event and construct |
| 12499 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common |
| 12500 | * discovery engine to handle. |
| 12501 | * |
| 12502 | * Return: Pointer to the receive IOCBQ, NULL otherwise. |
| 12503 | **/ |
| 12504 | static struct lpfc_iocbq * |
| 12505 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, |
| 12506 | struct lpfc_iocbq *irspiocbq) |
| 12507 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12508 | struct lpfc_sli_ring *pring; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12509 | struct lpfc_iocbq *cmdiocbq; |
| 12510 | struct lpfc_wcqe_complete *wcqe; |
| 12511 | unsigned long iflags; |
| 12512 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12513 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 12514 | if (unlikely(!pring)) |
| 12515 | return NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12516 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12517 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 12518 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12519 | pring->stats.iocb_event++; |
| 12520 | /* Look up the ELS command IOCB and create pseudo response IOCB */ |
| 12521 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 12522 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12523 | if (unlikely(!cmdiocbq)) { |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12524 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12525 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12526 | "0386 ELS complete with no corresponding " |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12527 | "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n", |
| 12528 | wcqe->word0, wcqe->total_data_placed, |
| 12529 | wcqe->parameter, wcqe->word3); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12530 | lpfc_sli_release_iocbq(phba, irspiocbq); |
| 12531 | return NULL; |
| 12532 | } |
| 12533 | |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 12534 | /* Put the iocb back on the txcmplq */ |
| 12535 | lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq); |
| 12536 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 12537 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12538 | /* Fake the irspiocbq and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 12539 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12540 | |
| 12541 | return irspiocbq; |
| 12542 | } |
| 12543 | |
| 12544 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12545 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event |
| 12546 | * @phba: Pointer to HBA context object. |
| 12547 | * @cqe: Pointer to mailbox completion queue entry. |
| 12548 | * |
| 12549 | * This routine process a mailbox completion queue entry with asynchrous |
| 12550 | * event. |
| 12551 | * |
| 12552 | * Return: true if work posted to worker thread, otherwise false. |
| 12553 | **/ |
| 12554 | static bool |
| 12555 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 12556 | { |
| 12557 | struct lpfc_cq_event *cq_event; |
| 12558 | unsigned long iflags; |
| 12559 | |
| 12560 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 12561 | "0392 Async Event: word0:x%x, word1:x%x, " |
| 12562 | "word2:x%x, word3:x%x\n", mcqe->word0, |
| 12563 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); |
| 12564 | |
| 12565 | /* Allocate a new internal CQ_EVENT entry */ |
| 12566 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 12567 | if (!cq_event) { |
| 12568 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12569 | "0394 Failed to allocate CQ_EVENT entry\n"); |
| 12570 | return false; |
| 12571 | } |
| 12572 | |
| 12573 | /* Move the CQE into an asynchronous event entry */ |
| 12574 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); |
| 12575 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12576 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); |
| 12577 | /* Set the async event flag */ |
| 12578 | phba->hba_flag |= ASYNC_EVENT; |
| 12579 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12580 | |
| 12581 | return true; |
| 12582 | } |
| 12583 | |
| 12584 | /** |
| 12585 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event |
| 12586 | * @phba: Pointer to HBA context object. |
| 12587 | * @cqe: Pointer to mailbox completion queue entry. |
| 12588 | * |
| 12589 | * This routine process a mailbox completion queue entry with mailbox |
| 12590 | * completion event. |
| 12591 | * |
| 12592 | * Return: true if work posted to worker thread, otherwise false. |
| 12593 | **/ |
| 12594 | static bool |
| 12595 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) |
| 12596 | { |
| 12597 | uint32_t mcqe_status; |
| 12598 | MAILBOX_t *mbox, *pmbox; |
| 12599 | struct lpfc_mqe *mqe; |
| 12600 | struct lpfc_vport *vport; |
| 12601 | struct lpfc_nodelist *ndlp; |
| 12602 | struct lpfc_dmabuf *mp; |
| 12603 | unsigned long iflags; |
| 12604 | LPFC_MBOXQ_t *pmb; |
| 12605 | bool workposted = false; |
| 12606 | int rc; |
| 12607 | |
| 12608 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ |
| 12609 | if (!bf_get(lpfc_trailer_completed, mcqe)) |
| 12610 | goto out_no_mqe_complete; |
| 12611 | |
| 12612 | /* Get the reference to the active mbox command */ |
| 12613 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12614 | pmb = phba->sli.mbox_active; |
| 12615 | if (unlikely(!pmb)) { |
| 12616 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 12617 | "1832 No pending MBOX command to handle\n"); |
| 12618 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12619 | goto out_no_mqe_complete; |
| 12620 | } |
| 12621 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12622 | mqe = &pmb->u.mqe; |
| 12623 | pmbox = (MAILBOX_t *)&pmb->u.mqe; |
| 12624 | mbox = phba->mbox; |
| 12625 | vport = pmb->vport; |
| 12626 | |
| 12627 | /* Reset heartbeat timer */ |
| 12628 | phba->last_completion_time = jiffies; |
| 12629 | del_timer(&phba->sli.mbox_tmo); |
| 12630 | |
| 12631 | /* Move mbox data to caller's mailbox region, do endian swapping */ |
| 12632 | if (pmb->mbox_cmpl && mbox) |
| 12633 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12634 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 12635 | /* |
| 12636 | * For mcqe errors, conditionally move a modified error code to |
| 12637 | * the mbox so that the error will not be missed. |
| 12638 | */ |
| 12639 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); |
| 12640 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
| 12641 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) |
| 12642 | bf_set(lpfc_mqe_status, mqe, |
| 12643 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); |
| 12644 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 12645 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
| 12646 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; |
| 12647 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, |
| 12648 | "MBOX dflt rpi: status:x%x rpi:x%x", |
| 12649 | mcqe_status, |
| 12650 | pmbox->un.varWords[0], 0); |
| 12651 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { |
| 12652 | mp = (struct lpfc_dmabuf *)(pmb->context1); |
| 12653 | ndlp = (struct lpfc_nodelist *)pmb->context2; |
| 12654 | /* Reg_LOGIN of dflt RPI was successful. Now lets get |
| 12655 | * RID of the PPI using the same mbox buffer. |
| 12656 | */ |
| 12657 | lpfc_unreg_login(phba, vport->vpi, |
| 12658 | pmbox->un.varWords[0], pmb); |
| 12659 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 12660 | pmb->context1 = mp; |
| 12661 | pmb->context2 = ndlp; |
| 12662 | pmb->vport = vport; |
| 12663 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 12664 | if (rc != MBX_BUSY) |
| 12665 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
| 12666 | LOG_SLI, "0385 rc should " |
| 12667 | "have been MBX_BUSY\n"); |
| 12668 | if (rc != MBX_NOT_FINISHED) |
| 12669 | goto send_current_mbox; |
| 12670 | } |
| 12671 | } |
| 12672 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 12673 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
| 12674 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 12675 | |
| 12676 | /* There is mailbox completion work to do */ |
| 12677 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12678 | __lpfc_mbox_cmpl_put(phba, pmb); |
| 12679 | phba->work_ha |= HA_MBATT; |
| 12680 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12681 | workposted = true; |
| 12682 | |
| 12683 | send_current_mbox: |
| 12684 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12685 | /* Release the mailbox command posting token */ |
| 12686 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 12687 | /* Setting active mailbox pointer need to be in sync to flag clear */ |
| 12688 | phba->sli.mbox_active = NULL; |
| 12689 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12690 | /* Wake up worker thread to post the next pending mailbox command */ |
| 12691 | lpfc_worker_wake_up(phba); |
| 12692 | out_no_mqe_complete: |
| 12693 | if (bf_get(lpfc_trailer_consumed, mcqe)) |
| 12694 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); |
| 12695 | return workposted; |
| 12696 | } |
| 12697 | |
| 12698 | /** |
| 12699 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry |
| 12700 | * @phba: Pointer to HBA context object. |
| 12701 | * @cqe: Pointer to mailbox completion queue entry. |
| 12702 | * |
| 12703 | * This routine process a mailbox completion queue entry, it invokes the |
| 12704 | * proper mailbox complete handling or asynchrous event handling routine |
| 12705 | * according to the MCQE's async bit. |
| 12706 | * |
| 12707 | * Return: true if work posted to worker thread, otherwise false. |
| 12708 | **/ |
| 12709 | static bool |
| 12710 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) |
| 12711 | { |
| 12712 | struct lpfc_mcqe mcqe; |
| 12713 | bool workposted; |
| 12714 | |
| 12715 | /* Copy the mailbox MCQE and convert endian order as needed */ |
| 12716 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); |
| 12717 | |
| 12718 | /* Invoke the proper event handling routine */ |
| 12719 | if (!bf_get(lpfc_trailer_async, &mcqe)) |
| 12720 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); |
| 12721 | else |
| 12722 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); |
| 12723 | return workposted; |
| 12724 | } |
| 12725 | |
| 12726 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12727 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event |
| 12728 | * @phba: Pointer to HBA context object. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12729 | * @cq: Pointer to associated CQ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12730 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12731 | * |
| 12732 | * This routine handles an ELS work-queue completion event. |
| 12733 | * |
| 12734 | * Return: true if work posted to worker thread, otherwise false. |
| 12735 | **/ |
| 12736 | static bool |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12737 | 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] | 12738 | struct lpfc_wcqe_complete *wcqe) |
| 12739 | { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12740 | struct lpfc_iocbq *irspiocbq; |
| 12741 | unsigned long iflags; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12742 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12743 | int txq_cnt = 0; |
| 12744 | int txcmplq_cnt = 0; |
| 12745 | int fcp_txcmplq_cnt = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12746 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12747 | /* Get an irspiocbq for later ELS response processing use */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12748 | irspiocbq = lpfc_sli_get_iocbq(phba); |
| 12749 | if (!irspiocbq) { |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12750 | if (!list_empty(&pring->txq)) |
| 12751 | txq_cnt++; |
| 12752 | if (!list_empty(&pring->txcmplq)) |
| 12753 | txcmplq_cnt++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12754 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 12755 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
| 12756 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 12757 | txq_cnt, phba->iocb_cnt, |
| 12758 | fcp_txcmplq_cnt, |
| 12759 | txcmplq_cnt); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12760 | return false; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12761 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12762 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12763 | /* Save off the slow-path queue event for work thread to process */ |
| 12764 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12765 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12766 | list_add_tail(&irspiocbq->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12767 | &phba->sli4_hba.sp_queue_event); |
| 12768 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12769 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12770 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12771 | return true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12772 | } |
| 12773 | |
| 12774 | /** |
| 12775 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event |
| 12776 | * @phba: Pointer to HBA context object. |
| 12777 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12778 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 12779 | * This routine handles slow-path WQ entry consumed event by invoking the |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12780 | * proper WQ release routine to the slow-path WQ. |
| 12781 | **/ |
| 12782 | static void |
| 12783 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, |
| 12784 | struct lpfc_wcqe_release *wcqe) |
| 12785 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12786 | /* sanity check on queue memory */ |
| 12787 | if (unlikely(!phba->sli4_hba.els_wq)) |
| 12788 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12789 | /* Check for the slow-path ELS work queue */ |
| 12790 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) |
| 12791 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, |
| 12792 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 12793 | else |
| 12794 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 12795 | "2579 Slow-path wqe consume event carries " |
| 12796 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", |
| 12797 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), |
| 12798 | phba->sli4_hba.els_wq->queue_id); |
| 12799 | } |
| 12800 | |
| 12801 | /** |
| 12802 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event |
| 12803 | * @phba: Pointer to HBA context object. |
| 12804 | * @cq: Pointer to a WQ completion queue. |
| 12805 | * @wcqe: Pointer to work-queue completion queue entry. |
| 12806 | * |
| 12807 | * This routine handles an XRI abort event. |
| 12808 | * |
| 12809 | * Return: true if work posted to worker thread, otherwise false. |
| 12810 | **/ |
| 12811 | static bool |
| 12812 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, |
| 12813 | struct lpfc_queue *cq, |
| 12814 | struct sli4_wcqe_xri_aborted *wcqe) |
| 12815 | { |
| 12816 | bool workposted = false; |
| 12817 | struct lpfc_cq_event *cq_event; |
| 12818 | unsigned long iflags; |
| 12819 | |
| 12820 | /* Allocate a new internal CQ_EVENT entry */ |
| 12821 | cq_event = lpfc_sli4_cq_event_alloc(phba); |
| 12822 | if (!cq_event) { |
| 12823 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12824 | "0602 Failed to allocate CQ_EVENT entry\n"); |
| 12825 | return false; |
| 12826 | } |
| 12827 | |
| 12828 | /* Move the CQE into the proper xri abort event list */ |
| 12829 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); |
| 12830 | switch (cq->subtype) { |
| 12831 | case LPFC_FCP: |
| 12832 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12833 | list_add_tail(&cq_event->list, |
| 12834 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 12835 | /* Set the fcp xri abort event flag */ |
| 12836 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; |
| 12837 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12838 | workposted = true; |
| 12839 | break; |
| 12840 | case LPFC_ELS: |
| 12841 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12842 | list_add_tail(&cq_event->list, |
| 12843 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 12844 | /* Set the els xri abort event flag */ |
| 12845 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; |
| 12846 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12847 | workposted = true; |
| 12848 | break; |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 12849 | case LPFC_NVME: |
| 12850 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12851 | list_add_tail(&cq_event->list, |
| 12852 | &phba->sli4_hba.sp_nvme_xri_aborted_work_queue); |
| 12853 | /* Set the nvme xri abort event flag */ |
| 12854 | phba->hba_flag |= NVME_XRI_ABORT_EVENT; |
| 12855 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12856 | workposted = true; |
| 12857 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12858 | default: |
| 12859 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 318083a | 2017-03-04 09:30:30 -0800 | [diff] [blame] | 12860 | "0603 Invalid CQ subtype %d: " |
| 12861 | "%08x %08x %08x %08x\n", |
| 12862 | cq->subtype, wcqe->word0, wcqe->parameter, |
| 12863 | wcqe->word2, wcqe->word3); |
| 12864 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12865 | workposted = false; |
| 12866 | break; |
| 12867 | } |
| 12868 | return workposted; |
| 12869 | } |
| 12870 | |
| 12871 | /** |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12872 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12873 | * @phba: Pointer to HBA context object. |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12874 | * @rcqe: Pointer to receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12875 | * |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12876 | * This routine process a receive-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12877 | * |
| 12878 | * Return: true if work posted to worker thread, otherwise false. |
| 12879 | **/ |
| 12880 | static bool |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12881 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
| 12882 | { |
| 12883 | bool workposted = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12884 | struct fc_frame_header *fc_hdr; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12885 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; |
| 12886 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 12887 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12888 | struct hbq_dmabuf *dma_buf; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12889 | uint32_t status, rq_id; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12890 | unsigned long iflags; |
| 12891 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 12892 | /* sanity check on queue memory */ |
| 12893 | if (unlikely(!hrq) || unlikely(!drq)) |
| 12894 | return workposted; |
| 12895 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 12896 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 12897 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 12898 | else |
| 12899 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 12900 | if (rq_id != hrq->queue_id) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12901 | goto out; |
| 12902 | |
| 12903 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 12904 | switch (status) { |
| 12905 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 12906 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 12907 | "2537 Receive Frame Truncated!!\n"); |
| 12908 | case FC_STATUS_RQ_SUCCESS: |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 12909 | lpfc_sli4_rq_release(hrq, drq); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12910 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12911 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); |
| 12912 | if (!dma_buf) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12913 | hrq->RQ_no_buf_found++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12914 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12915 | goto out; |
| 12916 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12917 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 12918 | hrq->RQ_buf_posted--; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12919 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12920 | |
| 12921 | /* If a NVME LS event (type 0x28), treat it as Fast path */ |
| 12922 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 12923 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12924 | /* save off the frame for the word thread to process */ |
| 12925 | list_add_tail(&dma_buf->cq_event.list, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12926 | &phba->sli4_hba.sp_queue_event); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12927 | /* Frame received */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12928 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12929 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12930 | workposted = true; |
| 12931 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12932 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 12933 | if (phba->nvmet_support) { |
| 12934 | tgtp = phba->targetport->private; |
| 12935 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 12936 | "6402 RQE Error x%x, posted %d err_cnt " |
| 12937 | "%d: %x %x %x\n", |
| 12938 | status, hrq->RQ_buf_posted, |
| 12939 | hrq->RQ_no_posted_buf, |
| 12940 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 12941 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 12942 | atomic_read(&tgtp->xmt_fcp_release)); |
| 12943 | } |
| 12944 | /* fallthrough */ |
| 12945 | |
| 12946 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 12947 | hrq->RQ_no_posted_buf++; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12948 | /* Post more buffers if possible */ |
| 12949 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 12950 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; |
| 12951 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 12952 | workposted = true; |
| 12953 | break; |
| 12954 | } |
| 12955 | out: |
| 12956 | return workposted; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12957 | } |
| 12958 | |
| 12959 | /** |
| 12960 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry |
| 12961 | * @phba: Pointer to HBA context object. |
| 12962 | * @cq: Pointer to the completion queue. |
| 12963 | * @wcqe: Pointer to a completion queue entry. |
| 12964 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 12965 | * 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] | 12966 | * entry. |
| 12967 | * |
| 12968 | * Return: true if work posted to worker thread, otherwise false. |
| 12969 | **/ |
| 12970 | static bool |
| 12971 | 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] | 12972 | struct lpfc_cqe *cqe) |
| 12973 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12974 | struct lpfc_cqe cqevt; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12975 | bool workposted = false; |
| 12976 | |
| 12977 | /* Copy the work queue CQE and convert endian order if needed */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12978 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12979 | |
| 12980 | /* Check and process for different type of WCQE and dispatch */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12981 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12982 | case CQE_CODE_COMPL_WQE: |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12983 | /* Process the WQ/RQ complete event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12984 | phba->last_completion_time = jiffies; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 12985 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12986 | (struct lpfc_wcqe_complete *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12987 | break; |
| 12988 | case CQE_CODE_RELEASE_WQE: |
| 12989 | /* Process the WQ release event */ |
| 12990 | lpfc_sli4_sp_handle_rel_wcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12991 | (struct lpfc_wcqe_release *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12992 | break; |
| 12993 | case CQE_CODE_XRI_ABORTED: |
| 12994 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 12995 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12996 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 12997 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 12998 | break; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 12999 | case CQE_CODE_RECEIVE: |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 13000 | case CQE_CODE_RECEIVE_V1: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13001 | /* Process the RQ event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13002 | phba->last_completion_time = jiffies; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13003 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13004 | (struct lpfc_rcqe *)&cqevt); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 13005 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13006 | default: |
| 13007 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13008 | "0388 Not a valid WCQE code: x%x\n", |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 13009 | bf_get(lpfc_cqe_code, &cqevt)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13010 | break; |
| 13011 | } |
| 13012 | return workposted; |
| 13013 | } |
| 13014 | |
| 13015 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13016 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry |
| 13017 | * @phba: Pointer to HBA context object. |
| 13018 | * @eqe: Pointer to fast-path event queue entry. |
| 13019 | * |
| 13020 | * This routine process a event queue entry from the slow-path event queue. |
| 13021 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13022 | * completion event on a completion queue, if not, an error shall be logged |
| 13023 | * and just return. Otherwise, it will get to the corresponding completion |
| 13024 | * queue and process all the entries on that completion queue, rearm the |
| 13025 | * completion queue, and then return. |
| 13026 | * |
| 13027 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13028 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13029 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13030 | struct lpfc_queue *speq) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13031 | { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13032 | struct lpfc_queue *cq = NULL, *childq; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13033 | uint16_t cqid; |
| 13034 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13035 | /* Get the reference to the corresponding CQ */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13036 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13037 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13038 | list_for_each_entry(childq, &speq->child_list, list) { |
| 13039 | if (childq->queue_id == cqid) { |
| 13040 | cq = childq; |
| 13041 | break; |
| 13042 | } |
| 13043 | } |
| 13044 | if (unlikely(!cq)) { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13045 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13046 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13047 | "0365 Slow-path CQ identifier " |
| 13048 | "(%d) does not exist\n", cqid); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13049 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13050 | } |
| 13051 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13052 | /* Save EQ associated with this CQ */ |
| 13053 | cq->assoc_qp = speq; |
| 13054 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13055 | if (!queue_work(phba->wq, &cq->spwork)) |
| 13056 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13057 | "0390 Cannot schedule soft IRQ " |
| 13058 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13059 | cqid, cq->queue_id, smp_processor_id()); |
| 13060 | } |
| 13061 | |
| 13062 | /** |
| 13063 | * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry |
| 13064 | * @phba: Pointer to HBA context object. |
| 13065 | * |
| 13066 | * This routine process a event queue entry from the slow-path event queue. |
| 13067 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13068 | * completion event on a completion queue, if not, an error shall be logged |
| 13069 | * and just return. Otherwise, it will get to the corresponding completion |
| 13070 | * queue and process all the entries on that completion queue, rearm the |
| 13071 | * completion queue, and then return. |
| 13072 | * |
| 13073 | **/ |
| 13074 | static void |
| 13075 | lpfc_sli4_sp_process_cq(struct work_struct *work) |
| 13076 | { |
| 13077 | struct lpfc_queue *cq = |
| 13078 | container_of(work, struct lpfc_queue, spwork); |
| 13079 | struct lpfc_hba *phba = cq->phba; |
| 13080 | struct lpfc_cqe *cqe; |
| 13081 | bool workposted = false; |
| 13082 | int ccount = 0; |
| 13083 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13084 | /* Process all the entries to the CQ */ |
| 13085 | switch (cq->type) { |
| 13086 | case LPFC_MCQ: |
| 13087 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
| 13088 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13089 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13090 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13091 | cq->CQ_mbox++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13092 | } |
| 13093 | break; |
| 13094 | case LPFC_WCQ: |
| 13095 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13096 | if (cq->subtype == LPFC_FCP || |
| 13097 | cq->subtype == LPFC_NVME) { |
| 13098 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13099 | if (phba->ktime_on) |
| 13100 | cq->isr_timestamp = ktime_get_ns(); |
| 13101 | else |
| 13102 | cq->isr_timestamp = 0; |
| 13103 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13104 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13105 | cqe); |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13106 | } else { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13107 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, |
| 13108 | cqe); |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13109 | } |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13110 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13111 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13112 | } |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13113 | |
| 13114 | /* Track the max number of CQEs processed in 1 EQ */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13115 | if (ccount > cq->CQ_max_cqe) |
| 13116 | cq->CQ_max_cqe = ccount; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13117 | break; |
| 13118 | default: |
| 13119 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13120 | "0370 Invalid completion queue type (%d)\n", |
| 13121 | cq->type); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13122 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13123 | } |
| 13124 | |
| 13125 | /* Catch the no cq entry condition, log an error */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13126 | if (unlikely(ccount == 0)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13127 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13128 | "0371 No entry from the CQ: identifier " |
| 13129 | "(x%x), type (%d)\n", cq->queue_id, cq->type); |
| 13130 | |
| 13131 | /* In any case, flash and re-arm the RCQ */ |
| 13132 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 13133 | |
| 13134 | /* wake up worker thread if there are works to be done */ |
| 13135 | if (workposted) |
| 13136 | lpfc_worker_wake_up(phba); |
| 13137 | } |
| 13138 | |
| 13139 | /** |
| 13140 | * 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] | 13141 | * @phba: Pointer to HBA context object. |
| 13142 | * @cq: Pointer to associated CQ |
| 13143 | * @wcqe: Pointer to work-queue completion queue entry. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13144 | * |
| 13145 | * This routine process a fast-path work queue completion entry from fast-path |
| 13146 | * event queue for FCP command response completion. |
| 13147 | **/ |
| 13148 | static void |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13149 | 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] | 13150 | struct lpfc_wcqe_complete *wcqe) |
| 13151 | { |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 13152 | struct lpfc_sli_ring *pring = cq->pring; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13153 | struct lpfc_iocbq *cmdiocbq; |
| 13154 | struct lpfc_iocbq irspiocbq; |
| 13155 | unsigned long iflags; |
| 13156 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13157 | /* Check for response status */ |
| 13158 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { |
| 13159 | /* If resource errors reported from HBA, reduce queue |
| 13160 | * depth of the SCSI device. |
| 13161 | */ |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13162 | if (((bf_get(lpfc_wcqe_c_status, wcqe) == |
| 13163 | IOSTAT_LOCAL_REJECT)) && |
| 13164 | ((wcqe->parameter & IOERR_PARAM_MASK) == |
| 13165 | IOERR_NO_RESOURCES)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13166 | phba->lpfc_rampdown_queue_depth(phba); |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 13167 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13168 | /* Log the error status */ |
| 13169 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13170 | "0373 FCP complete error: status=x%x, " |
| 13171 | "hw_status=x%x, total_data_specified=%d, " |
| 13172 | "parameter=x%x, word3=x%x\n", |
| 13173 | bf_get(lpfc_wcqe_c_status, wcqe), |
| 13174 | bf_get(lpfc_wcqe_c_hw_status, wcqe), |
| 13175 | wcqe->total_data_placed, wcqe->parameter, |
| 13176 | wcqe->word3); |
| 13177 | } |
| 13178 | |
| 13179 | /* Look up the FCP command IOCB and create pseudo response IOCB */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13180 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 13181 | pring->stats.iocb_event++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13182 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
| 13183 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 13184 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13185 | if (unlikely(!cmdiocbq)) { |
| 13186 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13187 | "0374 FCP complete with no corresponding " |
| 13188 | "cmdiocb: iotag (%d)\n", |
| 13189 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13190 | return; |
| 13191 | } |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13192 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13193 | cmdiocbq->isr_timestamp = cq->isr_timestamp; |
| 13194 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13195 | if (cmdiocbq->iocb_cmpl == NULL) { |
| 13196 | if (cmdiocbq->wqe_cmpl) { |
| 13197 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13198 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13199 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13200 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13201 | } |
| 13202 | |
| 13203 | /* Pass the cmd_iocb and the wcqe to the upper layer */ |
| 13204 | (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe); |
| 13205 | return; |
| 13206 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13207 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13208 | "0375 FCP cmdiocb not callback function " |
| 13209 | "iotag: (%d)\n", |
| 13210 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); |
| 13211 | return; |
| 13212 | } |
| 13213 | |
| 13214 | /* Fake the irspiocb and copy necessary response information */ |
James Smart | 341af10 | 2010-01-26 23:07:37 -0500 | [diff] [blame] | 13215 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13216 | |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 13217 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
| 13218 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13219 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
| 13220 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13221 | } |
| 13222 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13223 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
| 13224 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); |
| 13225 | } |
| 13226 | |
| 13227 | /** |
| 13228 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event |
| 13229 | * @phba: Pointer to HBA context object. |
| 13230 | * @cq: Pointer to completion queue. |
| 13231 | * @wcqe: Pointer to work-queue completion queue entry. |
| 13232 | * |
Masahiro Yamada | 3f8b6fb | 2017-02-27 14:29:25 -0800 | [diff] [blame] | 13233 | * 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] | 13234 | * proper WQ release routine to the slow-path WQ. |
| 13235 | **/ |
| 13236 | static void |
| 13237 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13238 | struct lpfc_wcqe_release *wcqe) |
| 13239 | { |
| 13240 | struct lpfc_queue *childwq; |
| 13241 | bool wqid_matched = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13242 | uint16_t hba_wqid; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13243 | |
| 13244 | /* Check for fast-path FCP work queue release */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13245 | hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13246 | list_for_each_entry(childwq, &cq->child_list, list) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13247 | if (childwq->queue_id == hba_wqid) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13248 | lpfc_sli4_wq_release(childwq, |
| 13249 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); |
| 13250 | wqid_matched = true; |
| 13251 | break; |
| 13252 | } |
| 13253 | } |
| 13254 | /* Report warning log message if no match found */ |
| 13255 | if (wqid_matched != true) |
| 13256 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13257 | "2580 Fast-path wqe consume event carries " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13258 | "miss-matched qid: wcqe-qid=x%x\n", hba_wqid); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13259 | } |
| 13260 | |
| 13261 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13262 | * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry |
| 13263 | * @phba: Pointer to HBA context object. |
| 13264 | * @rcqe: Pointer to receive-queue completion queue entry. |
| 13265 | * |
| 13266 | * This routine process a receive-queue completion queue entry. |
| 13267 | * |
| 13268 | * Return: true if work posted to worker thread, otherwise false. |
| 13269 | **/ |
| 13270 | static bool |
| 13271 | lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 13272 | struct lpfc_rcqe *rcqe) |
| 13273 | { |
| 13274 | bool workposted = false; |
| 13275 | struct lpfc_queue *hrq; |
| 13276 | struct lpfc_queue *drq; |
| 13277 | struct rqb_dmabuf *dma_buf; |
| 13278 | struct fc_frame_header *fc_hdr; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13279 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13280 | uint32_t status, rq_id; |
| 13281 | unsigned long iflags; |
| 13282 | uint32_t fctl, idx; |
| 13283 | |
| 13284 | if ((phba->nvmet_support == 0) || |
| 13285 | (phba->sli4_hba.nvmet_cqset == NULL)) |
| 13286 | return workposted; |
| 13287 | |
| 13288 | idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13289 | hrq = phba->sli4_hba.nvmet_mrq_hdr[idx]; |
| 13290 | drq = phba->sli4_hba.nvmet_mrq_data[idx]; |
| 13291 | |
| 13292 | /* sanity check on queue memory */ |
| 13293 | if (unlikely(!hrq) || unlikely(!drq)) |
| 13294 | return workposted; |
| 13295 | |
| 13296 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
| 13297 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); |
| 13298 | else |
| 13299 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); |
| 13300 | |
| 13301 | if ((phba->nvmet_support == 0) || |
| 13302 | (rq_id != hrq->queue_id)) |
| 13303 | return workposted; |
| 13304 | |
| 13305 | status = bf_get(lpfc_rcqe_status, rcqe); |
| 13306 | switch (status) { |
| 13307 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: |
| 13308 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13309 | "6126 Receive Frame Truncated!!\n"); |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 13310 | /* Drop thru */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13311 | case FC_STATUS_RQ_SUCCESS: |
| 13312 | lpfc_sli4_rq_release(hrq, drq); |
| 13313 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 13314 | dma_buf = lpfc_sli_rqbuf_get(phba, hrq); |
| 13315 | if (!dma_buf) { |
| 13316 | hrq->RQ_no_buf_found++; |
| 13317 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13318 | goto out; |
| 13319 | } |
| 13320 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 13321 | hrq->RQ_rcv_buf++; |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13322 | hrq->RQ_buf_posted--; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13323 | fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt; |
| 13324 | |
| 13325 | /* Just some basic sanity checks on FCP Command frame */ |
| 13326 | fctl = (fc_hdr->fh_f_ctl[0] << 16 | |
| 13327 | fc_hdr->fh_f_ctl[1] << 8 | |
| 13328 | fc_hdr->fh_f_ctl[2]); |
| 13329 | if (((fctl & |
| 13330 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) != |
| 13331 | (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) || |
| 13332 | (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */ |
| 13333 | goto drop; |
| 13334 | |
| 13335 | if (fc_hdr->fh_type == FC_TYPE_FCP) { |
| 13336 | dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 13337 | lpfc_nvmet_unsol_fcp_event( |
Dick Kennedy | 66d7ce9 | 2017-08-23 16:55:42 -0700 | [diff] [blame] | 13338 | phba, idx, dma_buf, |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13339 | cq->isr_timestamp); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13340 | return false; |
| 13341 | } |
| 13342 | drop: |
| 13343 | lpfc_in_buf_free(phba, &dma_buf->dbuf); |
| 13344 | break; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13345 | case FC_STATUS_INSUFF_BUF_FRM_DISC: |
James Smart | 547077a | 2017-05-15 15:20:40 -0700 | [diff] [blame] | 13346 | if (phba->nvmet_support) { |
| 13347 | tgtp = phba->targetport->private; |
| 13348 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME, |
| 13349 | "6401 RQE Error x%x, posted %d err_cnt " |
| 13350 | "%d: %x %x %x\n", |
| 13351 | status, hrq->RQ_buf_posted, |
| 13352 | hrq->RQ_no_posted_buf, |
| 13353 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
| 13354 | atomic_read(&tgtp->rcv_fcp_cmd_out), |
| 13355 | atomic_read(&tgtp->xmt_fcp_release)); |
| 13356 | } |
| 13357 | /* fallthrough */ |
| 13358 | |
| 13359 | case FC_STATUS_INSUFF_BUF_NEED_BUF: |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13360 | hrq->RQ_no_posted_buf++; |
| 13361 | /* Post more buffers if possible */ |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13362 | break; |
| 13363 | } |
| 13364 | out: |
| 13365 | return workposted; |
| 13366 | } |
| 13367 | |
| 13368 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13369 | * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13370 | * @cq: Pointer to the completion queue. |
| 13371 | * @eqe: Pointer to fast-path completion queue entry. |
| 13372 | * |
| 13373 | * This routine process a fast-path work queue completion entry from fast-path |
| 13374 | * event queue for FCP command response completion. |
| 13375 | **/ |
| 13376 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13377 | 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] | 13378 | struct lpfc_cqe *cqe) |
| 13379 | { |
| 13380 | struct lpfc_wcqe_release wcqe; |
| 13381 | bool workposted = false; |
| 13382 | |
| 13383 | /* Copy the work queue CQE and convert endian order if needed */ |
| 13384 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); |
| 13385 | |
| 13386 | /* Check and process for different type of WCQE and dispatch */ |
| 13387 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { |
| 13388 | case CQE_CODE_COMPL_WQE: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13389 | case CQE_CODE_NVME_ERSP: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13390 | cq->CQ_wq++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13391 | /* Process the WQ complete event */ |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 13392 | phba->last_completion_time = jiffies; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13393 | if ((cq->subtype == LPFC_FCP) || (cq->subtype == LPFC_NVME)) |
| 13394 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
| 13395 | (struct lpfc_wcqe_complete *)&wcqe); |
| 13396 | if (cq->subtype == LPFC_NVME_LS) |
| 13397 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13398 | (struct lpfc_wcqe_complete *)&wcqe); |
| 13399 | break; |
| 13400 | case CQE_CODE_RELEASE_WQE: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13401 | cq->CQ_release_wqe++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13402 | /* Process the WQ release event */ |
| 13403 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, |
| 13404 | (struct lpfc_wcqe_release *)&wcqe); |
| 13405 | break; |
| 13406 | case CQE_CODE_XRI_ABORTED: |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13407 | cq->CQ_xri_aborted++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13408 | /* Process the WQ XRI abort event */ |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 13409 | phba->last_completion_time = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13410 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
| 13411 | (struct sli4_wcqe_xri_aborted *)&wcqe); |
| 13412 | break; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13413 | case CQE_CODE_RECEIVE_V1: |
| 13414 | case CQE_CODE_RECEIVE: |
| 13415 | phba->last_completion_time = jiffies; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13416 | if (cq->subtype == LPFC_NVMET) { |
| 13417 | workposted = lpfc_sli4_nvmet_handle_rcqe( |
| 13418 | phba, cq, (struct lpfc_rcqe *)&wcqe); |
| 13419 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13420 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13421 | default: |
| 13422 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13423 | "0144 Not a valid CQE code: x%x\n", |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13424 | bf_get(lpfc_wcqe_c_code, &wcqe)); |
| 13425 | break; |
| 13426 | } |
| 13427 | return workposted; |
| 13428 | } |
| 13429 | |
| 13430 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13431 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13432 | * @phba: Pointer to HBA context object. |
| 13433 | * @eqe: Pointer to fast-path event queue entry. |
| 13434 | * |
| 13435 | * This routine process a event queue entry from the fast-path event queue. |
| 13436 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13437 | * completion event on a completion queue, if not, an error shall be logged |
| 13438 | * and just return. Otherwise, it will get to the corresponding completion |
| 13439 | * queue and process all the entries on the completion queue, rearm the |
| 13440 | * completion queue, and then return. |
| 13441 | **/ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13442 | static void |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13443 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
| 13444 | uint32_t qidx) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13445 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13446 | struct lpfc_queue *cq = NULL; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13447 | uint16_t cqid, id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13448 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13449 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13450 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13451 | "0366 Not a valid completion " |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13452 | "event: majorcode=x%x, minorcode=x%x\n", |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13453 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 13454 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13455 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13456 | } |
| 13457 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13458 | /* Get the reference to the corresponding CQ */ |
| 13459 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 13460 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13461 | if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) { |
| 13462 | id = phba->sli4_hba.nvmet_cqset[0]->queue_id; |
| 13463 | if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) { |
| 13464 | /* Process NVMET unsol rcv */ |
| 13465 | cq = phba->sli4_hba.nvmet_cqset[cqid - id]; |
| 13466 | goto process_cq; |
| 13467 | } |
| 13468 | } |
| 13469 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13470 | if (phba->sli4_hba.nvme_cq_map && |
| 13471 | (cqid == phba->sli4_hba.nvme_cq_map[qidx])) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 13472 | /* Process NVME / NVMET command completion */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13473 | cq = phba->sli4_hba.nvme_cq[qidx]; |
| 13474 | goto process_cq; |
| 13475 | } |
| 13476 | |
| 13477 | if (phba->sli4_hba.fcp_cq_map && |
| 13478 | (cqid == phba->sli4_hba.fcp_cq_map[qidx])) { |
| 13479 | /* Process FCP command completion */ |
| 13480 | cq = phba->sli4_hba.fcp_cq[qidx]; |
| 13481 | goto process_cq; |
| 13482 | } |
| 13483 | |
| 13484 | if (phba->sli4_hba.nvmels_cq && |
| 13485 | (cqid == phba->sli4_hba.nvmels_cq->queue_id)) { |
| 13486 | /* Process NVME unsol rcv */ |
| 13487 | cq = phba->sli4_hba.nvmels_cq; |
| 13488 | } |
| 13489 | |
| 13490 | /* Otherwise this is a Slow path event */ |
| 13491 | if (cq == NULL) { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13492 | lpfc_sli4_sp_handle_eqe(phba, eqe, phba->sli4_hba.hba_eq[qidx]); |
| 13493 | return; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13494 | } |
| 13495 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13496 | process_cq: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13497 | if (unlikely(cqid != cq->queue_id)) { |
| 13498 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13499 | "0368 Miss-matched fast-path completion " |
| 13500 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", |
| 13501 | cqid, cq->queue_id); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13502 | return; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13503 | } |
| 13504 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13505 | /* Save EQ associated with this CQ */ |
| 13506 | cq->assoc_qp = phba->sli4_hba.hba_eq[qidx]; |
| 13507 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13508 | if (!queue_work(phba->wq, &cq->irqwork)) |
| 13509 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13510 | "0363 Cannot schedule soft IRQ " |
| 13511 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13512 | cqid, cq->queue_id, smp_processor_id()); |
| 13513 | } |
| 13514 | |
| 13515 | /** |
| 13516 | * lpfc_sli4_hba_process_cq - Process a fast-path event queue entry |
| 13517 | * @phba: Pointer to HBA context object. |
| 13518 | * @eqe: Pointer to fast-path event queue entry. |
| 13519 | * |
| 13520 | * This routine process a event queue entry from the fast-path event queue. |
| 13521 | * It will check the MajorCode and MinorCode to determine this is for a |
| 13522 | * completion event on a completion queue, if not, an error shall be logged |
| 13523 | * and just return. Otherwise, it will get to the corresponding completion |
| 13524 | * queue and process all the entries on the completion queue, rearm the |
| 13525 | * completion queue, and then return. |
| 13526 | **/ |
| 13527 | static void |
| 13528 | lpfc_sli4_hba_process_cq(struct work_struct *work) |
| 13529 | { |
| 13530 | struct lpfc_queue *cq = |
| 13531 | container_of(work, struct lpfc_queue, irqwork); |
| 13532 | struct lpfc_hba *phba = cq->phba; |
| 13533 | struct lpfc_cqe *cqe; |
| 13534 | bool workposted = false; |
| 13535 | int ccount = 0; |
| 13536 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13537 | /* Process all the entries to the CQ */ |
| 13538 | while ((cqe = lpfc_sli4_cq_get(cq))) { |
Dick Kennedy | c8a4ce0 | 2017-09-29 17:34:33 -0700 | [diff] [blame] | 13539 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 13540 | if (phba->ktime_on) |
| 13541 | cq->isr_timestamp = ktime_get_ns(); |
| 13542 | else |
| 13543 | cq->isr_timestamp = 0; |
| 13544 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13545 | workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, cqe); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13546 | if (!(++ccount % cq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13547 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13548 | } |
| 13549 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13550 | /* Track the max number of CQEs processed in 1 EQ */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13551 | if (ccount > cq->CQ_max_cqe) |
| 13552 | cq->CQ_max_cqe = ccount; |
| 13553 | cq->assoc_qp->EQ_cqe_cnt += ccount; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13554 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13555 | /* Catch the no cq entry condition */ |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13556 | if (unlikely(ccount == 0)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13557 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13558 | "0369 No entry from fast-path completion " |
| 13559 | "queue fcpcqid=%d\n", cq->queue_id); |
| 13560 | |
| 13561 | /* In any case, flash and re-arm the CQ */ |
| 13562 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); |
| 13563 | |
| 13564 | /* wake up worker thread if there are works to be done */ |
| 13565 | if (workposted) |
| 13566 | lpfc_worker_wake_up(phba); |
| 13567 | } |
| 13568 | |
| 13569 | static void |
| 13570 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 13571 | { |
| 13572 | struct lpfc_eqe *eqe; |
| 13573 | |
| 13574 | /* walk all the EQ entries and drop on the floor */ |
| 13575 | while ((eqe = lpfc_sli4_eq_get(eq))) |
| 13576 | ; |
| 13577 | |
| 13578 | /* Clear and re-arm the EQ */ |
| 13579 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 13580 | } |
| 13581 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13582 | |
| 13583 | /** |
| 13584 | * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue |
| 13585 | * entry |
| 13586 | * @phba: Pointer to HBA context object. |
| 13587 | * @eqe: Pointer to fast-path event queue entry. |
| 13588 | * |
| 13589 | * This routine process a event queue entry from the Flash Optimized Fabric |
| 13590 | * event queue. It will check the MajorCode and MinorCode to determine this |
| 13591 | * is for a completion event on a completion queue, if not, an error shall be |
| 13592 | * logged and just return. Otherwise, it will get to the corresponding |
| 13593 | * completion queue and process all the entries on the completion queue, rearm |
| 13594 | * the completion queue, and then return. |
| 13595 | **/ |
| 13596 | static void |
| 13597 | lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) |
| 13598 | { |
| 13599 | struct lpfc_queue *cq; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13600 | uint16_t cqid; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13601 | |
| 13602 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
| 13603 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13604 | "9147 Not a valid completion " |
| 13605 | "event: majorcode=x%x, minorcode=x%x\n", |
| 13606 | bf_get_le32(lpfc_eqe_major_code, eqe), |
| 13607 | bf_get_le32(lpfc_eqe_minor_code, eqe)); |
| 13608 | return; |
| 13609 | } |
| 13610 | |
| 13611 | /* Get the reference to the corresponding CQ */ |
| 13612 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
| 13613 | |
| 13614 | /* Next check for OAS */ |
| 13615 | cq = phba->sli4_hba.oas_cq; |
| 13616 | if (unlikely(!cq)) { |
| 13617 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 13618 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13619 | "9148 OAS completion queue " |
| 13620 | "does not exist\n"); |
| 13621 | return; |
| 13622 | } |
| 13623 | |
| 13624 | if (unlikely(cqid != cq->queue_id)) { |
| 13625 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13626 | "9149 Miss-matched fast-path compl " |
| 13627 | "queue id: eqcqid=%d, fcpcqid=%d\n", |
| 13628 | cqid, cq->queue_id); |
| 13629 | return; |
| 13630 | } |
| 13631 | |
James Smart | d41b65b | 2017-06-15 22:56:41 -0700 | [diff] [blame] | 13632 | /* Save EQ associated with this CQ */ |
| 13633 | cq->assoc_qp = phba->sli4_hba.fof_eq; |
| 13634 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13635 | /* CQ work will be processed on CPU affinitized to this IRQ */ |
| 13636 | if (!queue_work(phba->wq, &cq->irqwork)) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13637 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13638 | "0367 Cannot schedule soft IRQ " |
| 13639 | "for CQ eqcqid=%d, cqid=%d on CPU %d\n", |
| 13640 | cqid, cq->queue_id, smp_processor_id()); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13641 | } |
| 13642 | |
| 13643 | /** |
| 13644 | * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device |
| 13645 | * @irq: Interrupt number. |
| 13646 | * @dev_id: The device context pointer. |
| 13647 | * |
| 13648 | * This function is directly called from the PCI layer as an interrupt |
| 13649 | * service routine when device with SLI-4 interface spec is enabled with |
| 13650 | * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric |
| 13651 | * IOCB ring event in the HBA. However, when the device is enabled with either |
| 13652 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 13653 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 13654 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 13655 | * process the interrupt. The Flash Optimized Fabric ring event are handled in |
| 13656 | * the intrrupt context. This function is called without any lock held. |
| 13657 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 13658 | * the EQ to CQ are one-to-one map such that the EQ index is |
| 13659 | * equal to that of CQ index. |
| 13660 | * |
| 13661 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 13662 | * returns IRQ_NONE. |
| 13663 | **/ |
| 13664 | irqreturn_t |
| 13665 | lpfc_sli4_fof_intr_handler(int irq, void *dev_id) |
| 13666 | { |
| 13667 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13668 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13669 | struct lpfc_queue *eq; |
| 13670 | struct lpfc_eqe *eqe; |
| 13671 | unsigned long iflag; |
| 13672 | int ecount = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13673 | |
| 13674 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13675 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 13676 | phba = hba_eq_hdl->phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13677 | |
| 13678 | if (unlikely(!phba)) |
| 13679 | return IRQ_NONE; |
| 13680 | |
| 13681 | /* Get to the EQ struct associated with this vector */ |
| 13682 | eq = phba->sli4_hba.fof_eq; |
| 13683 | if (unlikely(!eq)) |
| 13684 | return IRQ_NONE; |
| 13685 | |
| 13686 | /* Check device state for handling interrupt */ |
| 13687 | if (unlikely(lpfc_intr_state_check(phba))) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13688 | /* Check again for link_state with lock held */ |
| 13689 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 13690 | if (phba->link_state < LPFC_LINK_DOWN) |
| 13691 | /* Flush, clear interrupt, and rearm the EQ */ |
| 13692 | lpfc_sli4_eq_flush(phba, eq); |
| 13693 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 13694 | return IRQ_NONE; |
| 13695 | } |
| 13696 | |
| 13697 | /* |
| 13698 | * Process all the event on FCP fast-path EQ |
| 13699 | */ |
| 13700 | while ((eqe = lpfc_sli4_eq_get(eq))) { |
| 13701 | lpfc_sli4_fof_handle_eqe(phba, eqe); |
| 13702 | if (!(++ecount % eq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13703 | break; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13704 | eq->EQ_processed++; |
| 13705 | } |
| 13706 | |
| 13707 | /* Track the max number of EQEs processed in 1 intr */ |
| 13708 | if (ecount > eq->EQ_max_eqe) |
| 13709 | eq->EQ_max_eqe = ecount; |
| 13710 | |
| 13711 | |
| 13712 | if (unlikely(ecount == 0)) { |
| 13713 | eq->EQ_no_entry++; |
| 13714 | |
| 13715 | if (phba->intr_type == MSIX) |
| 13716 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 13717 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13718 | "9145 MSI-X interrupt with no EQE\n"); |
| 13719 | else { |
| 13720 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 13721 | "9146 ISR interrupt with no EQE\n"); |
| 13722 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 13723 | return IRQ_NONE; |
| 13724 | } |
| 13725 | } |
| 13726 | /* Always clear and re-arm the fast-path EQ */ |
| 13727 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); |
| 13728 | return IRQ_HANDLED; |
| 13729 | } |
| 13730 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13731 | /** |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13732 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13733 | * @irq: Interrupt number. |
| 13734 | * @dev_id: The device context pointer. |
| 13735 | * |
| 13736 | * This function is directly called from the PCI layer as an interrupt |
| 13737 | * service routine when device with SLI-4 interface spec is enabled with |
| 13738 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
| 13739 | * ring event in the HBA. However, when the device is enabled with either |
| 13740 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
| 13741 | * device-level interrupt handler. When the PCI slot is in error recovery |
| 13742 | * or the HBA is undergoing initialization, the interrupt handler will not |
| 13743 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
| 13744 | * the intrrupt context. This function is called without any lock held. |
| 13745 | * It gets the hbalock to access and update SLI data structures. Note that, |
| 13746 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is |
| 13747 | * equal to that of FCP CQ index. |
| 13748 | * |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13749 | * The link attention and ELS ring attention events are handled |
| 13750 | * by the worker thread. The interrupt handler signals the worker thread |
| 13751 | * and returns for these events. This function is called without any lock |
| 13752 | * held. It gets the hbalock to access and update SLI data structures. |
| 13753 | * |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13754 | * This function returns IRQ_HANDLED when interrupt is handled else it |
| 13755 | * returns IRQ_NONE. |
| 13756 | **/ |
| 13757 | irqreturn_t |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13758 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13759 | { |
| 13760 | struct lpfc_hba *phba; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13761 | struct lpfc_hba_eq_hdl *hba_eq_hdl; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13762 | struct lpfc_queue *fpeq; |
| 13763 | struct lpfc_eqe *eqe; |
| 13764 | unsigned long iflag; |
| 13765 | int ecount = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13766 | int hba_eqidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13767 | |
| 13768 | /* Get the driver's phba structure from the dev_id */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13769 | hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id; |
| 13770 | phba = hba_eq_hdl->phba; |
| 13771 | hba_eqidx = hba_eq_hdl->idx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13772 | |
| 13773 | if (unlikely(!phba)) |
| 13774 | return IRQ_NONE; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13775 | if (unlikely(!phba->sli4_hba.hba_eq)) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 13776 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13777 | |
| 13778 | /* Get to the EQ struct associated with this vector */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13779 | fpeq = phba->sli4_hba.hba_eq[hba_eqidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 13780 | if (unlikely(!fpeq)) |
| 13781 | return IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13782 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13783 | if (lpfc_fcp_look_ahead) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13784 | if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13785 | lpfc_sli4_eq_clr_intr(fpeq); |
| 13786 | else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13787 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13788 | return IRQ_NONE; |
| 13789 | } |
| 13790 | } |
| 13791 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13792 | /* Check device state for handling interrupt */ |
| 13793 | if (unlikely(lpfc_intr_state_check(phba))) { |
| 13794 | /* Check again for link_state with lock held */ |
| 13795 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 13796 | if (phba->link_state < LPFC_LINK_DOWN) |
| 13797 | /* Flush, clear interrupt, and rearm the EQ */ |
| 13798 | lpfc_sli4_eq_flush(phba, fpeq); |
| 13799 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13800 | if (lpfc_fcp_look_ahead) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13801 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13802 | return IRQ_NONE; |
| 13803 | } |
| 13804 | |
| 13805 | /* |
| 13806 | * Process all the event on FCP fast-path EQ |
| 13807 | */ |
| 13808 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13809 | lpfc_sli4_hba_handle_eqe(phba, eqe, hba_eqidx); |
| 13810 | if (!(++ecount % fpeq->entry_repost)) |
James Smart | 7869da1 | 2017-05-15 15:20:43 -0700 | [diff] [blame] | 13811 | break; |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13812 | fpeq->EQ_processed++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13813 | } |
| 13814 | |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13815 | /* Track the max number of EQEs processed in 1 intr */ |
| 13816 | if (ecount > fpeq->EQ_max_eqe) |
| 13817 | fpeq->EQ_max_eqe = ecount; |
| 13818 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13819 | /* Always clear and re-arm the fast-path EQ */ |
| 13820 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); |
| 13821 | |
| 13822 | if (unlikely(ecount == 0)) { |
James Smart | b84daac | 2012-08-03 12:35:13 -0400 | [diff] [blame] | 13823 | fpeq->EQ_no_entry++; |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13824 | |
| 13825 | if (lpfc_fcp_look_ahead) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13826 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13827 | return IRQ_NONE; |
| 13828 | } |
| 13829 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13830 | if (phba->intr_type == MSIX) |
| 13831 | /* MSI-X treated interrupt served as no EQ share INT */ |
| 13832 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 13833 | "0358 MSI-X interrupt with no EQE\n"); |
| 13834 | else |
| 13835 | /* Non MSI-X treated on interrupt as EQ share INT */ |
| 13836 | return IRQ_NONE; |
| 13837 | } |
| 13838 | |
James Smart | ba20c85 | 2012-08-03 12:36:52 -0400 | [diff] [blame] | 13839 | if (lpfc_fcp_look_ahead) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13840 | atomic_inc(&hba_eq_hdl->hba_eq_in_use); |
| 13841 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13842 | return IRQ_HANDLED; |
| 13843 | } /* lpfc_sli4_fp_intr_handler */ |
| 13844 | |
| 13845 | /** |
| 13846 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device |
| 13847 | * @irq: Interrupt number. |
| 13848 | * @dev_id: The device context pointer. |
| 13849 | * |
| 13850 | * This function is the device-level interrupt handler to device with SLI-4 |
| 13851 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ |
| 13852 | * interrupt mode is enabled and there is an event in the HBA which requires |
| 13853 | * driver attention. This function invokes the slow-path interrupt attention |
| 13854 | * handling function and fast-path interrupt attention handling function in |
| 13855 | * turn to process the relevant HBA attention events. This function is called |
| 13856 | * without any lock held. It gets the hbalock to access and update SLI data |
| 13857 | * structures. |
| 13858 | * |
| 13859 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
| 13860 | * returns IRQ_NONE. |
| 13861 | **/ |
| 13862 | irqreturn_t |
| 13863 | lpfc_sli4_intr_handler(int irq, void *dev_id) |
| 13864 | { |
| 13865 | struct lpfc_hba *phba; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13866 | irqreturn_t hba_irq_rc; |
| 13867 | bool hba_handled = false; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13868 | int qidx; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13869 | |
| 13870 | /* Get the driver's phba structure from the dev_id */ |
| 13871 | phba = (struct lpfc_hba *)dev_id; |
| 13872 | |
| 13873 | if (unlikely(!phba)) |
| 13874 | return IRQ_NONE; |
| 13875 | |
| 13876 | /* |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13877 | * Invoke fast-path host attention interrupt handling as appropriate. |
| 13878 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13879 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13880 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13881 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13882 | if (hba_irq_rc == IRQ_HANDLED) |
| 13883 | hba_handled |= true; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13884 | } |
| 13885 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13886 | if (phba->cfg_fof) { |
| 13887 | hba_irq_rc = lpfc_sli4_fof_intr_handler(irq, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13888 | &phba->sli4_hba.hba_eq_hdl[qidx]); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13889 | if (hba_irq_rc == IRQ_HANDLED) |
| 13890 | hba_handled |= true; |
| 13891 | } |
| 13892 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13893 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13894 | } /* lpfc_sli4_intr_handler */ |
| 13895 | |
| 13896 | /** |
| 13897 | * lpfc_sli4_queue_free - free a queue structure and associated memory |
| 13898 | * @queue: The queue structure to free. |
| 13899 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 13900 | * This function frees a queue structure and the DMAable memory used for |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13901 | * the host resident queue. This function must be called after destroying the |
| 13902 | * queue on the HBA. |
| 13903 | **/ |
| 13904 | void |
| 13905 | lpfc_sli4_queue_free(struct lpfc_queue *queue) |
| 13906 | { |
| 13907 | struct lpfc_dmabuf *dmabuf; |
| 13908 | |
| 13909 | if (!queue) |
| 13910 | return; |
| 13911 | |
| 13912 | while (!list_empty(&queue->page_list)) { |
| 13913 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, |
| 13914 | list); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 13915 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13916 | dmabuf->virt, dmabuf->phys); |
| 13917 | kfree(dmabuf); |
| 13918 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13919 | if (queue->rqbp) { |
| 13920 | lpfc_free_rq_buffer(queue->phba, queue); |
| 13921 | kfree(queue->rqbp); |
| 13922 | } |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 13923 | |
| 13924 | if (!list_empty(&queue->wq_list)) |
| 13925 | list_del(&queue->wq_list); |
| 13926 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13927 | kfree(queue); |
| 13928 | return; |
| 13929 | } |
| 13930 | |
| 13931 | /** |
| 13932 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure |
| 13933 | * @phba: The HBA that this queue is being created on. |
| 13934 | * @entry_size: The size of each queue entry for this queue. |
| 13935 | * @entry count: The number of entries that this queue will handle. |
| 13936 | * |
| 13937 | * This function allocates a queue structure and the DMAable memory used for |
| 13938 | * the host resident queue. This function must be called before creating the |
| 13939 | * queue on the HBA. |
| 13940 | **/ |
| 13941 | struct lpfc_queue * |
| 13942 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, |
| 13943 | uint32_t entry_count) |
| 13944 | { |
| 13945 | struct lpfc_queue *queue; |
| 13946 | struct lpfc_dmabuf *dmabuf; |
| 13947 | int x, total_qe_count; |
| 13948 | void *dma_pointer; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13949 | 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] | 13950 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13951 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 13952 | hw_page_size = SLI4_PAGE_SIZE; |
| 13953 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13954 | queue = kzalloc(sizeof(struct lpfc_queue) + |
| 13955 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); |
| 13956 | if (!queue) |
| 13957 | return NULL; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13958 | queue->page_count = (ALIGN(entry_size * entry_count, |
| 13959 | hw_page_size))/hw_page_size; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13960 | |
| 13961 | /* If needed, Adjust page count to match the max the adapter supports */ |
| 13962 | if (queue->page_count > phba->sli4_hba.pc_sli4_params.wqpcnt) |
| 13963 | queue->page_count = phba->sli4_hba.pc_sli4_params.wqpcnt; |
| 13964 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13965 | INIT_LIST_HEAD(&queue->list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13966 | INIT_LIST_HEAD(&queue->wq_list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13967 | INIT_LIST_HEAD(&queue->page_list); |
| 13968 | INIT_LIST_HEAD(&queue->child_list); |
| 13969 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { |
| 13970 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 13971 | if (!dmabuf) |
| 13972 | goto out_fail; |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 13973 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 13974 | hw_page_size, &dmabuf->phys, |
| 13975 | GFP_KERNEL); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13976 | if (!dmabuf->virt) { |
| 13977 | kfree(dmabuf); |
| 13978 | goto out_fail; |
| 13979 | } |
| 13980 | dmabuf->buffer_tag = x; |
| 13981 | list_add_tail(&dmabuf->list, &queue->page_list); |
| 13982 | /* initialize queue's entry array */ |
| 13983 | dma_pointer = dmabuf->virt; |
| 13984 | for (; total_qe_count < entry_count && |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 13985 | dma_pointer < (hw_page_size + dmabuf->virt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13986 | total_qe_count++, dma_pointer += entry_size) { |
| 13987 | queue->qe[total_qe_count].address = dma_pointer; |
| 13988 | } |
| 13989 | } |
| 13990 | queue->entry_size = entry_size; |
| 13991 | queue->entry_count = entry_count; |
| 13992 | queue->phba = phba; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 13993 | INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq); |
| 13994 | INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13995 | |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 13996 | /* entry_repost will be set during q creation */ |
| 13997 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 13998 | return queue; |
| 13999 | out_fail: |
| 14000 | lpfc_sli4_queue_free(queue); |
| 14001 | return NULL; |
| 14002 | } |
| 14003 | |
| 14004 | /** |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14005 | * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory |
| 14006 | * @phba: HBA structure that indicates port to create a queue on. |
| 14007 | * @pci_barset: PCI BAR set flag. |
| 14008 | * |
| 14009 | * This function shall perform iomap of the specified PCI BAR address to host |
| 14010 | * memory address if not already done so and return it. The returned host |
| 14011 | * memory address can be NULL. |
| 14012 | */ |
| 14013 | static void __iomem * |
| 14014 | lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset) |
| 14015 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14016 | if (!phba->pcidev) |
| 14017 | return NULL; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14018 | |
| 14019 | switch (pci_barset) { |
| 14020 | case WQ_PCI_BAR_0_AND_1: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14021 | return phba->pci_bar0_memmap_p; |
| 14022 | case WQ_PCI_BAR_2_AND_3: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14023 | return phba->pci_bar2_memmap_p; |
| 14024 | case WQ_PCI_BAR_4_AND_5: |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14025 | return phba->pci_bar4_memmap_p; |
| 14026 | default: |
| 14027 | break; |
| 14028 | } |
| 14029 | return NULL; |
| 14030 | } |
| 14031 | |
| 14032 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14033 | * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on FCP EQs |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14034 | * @phba: HBA structure that indicates port to create a queue on. |
| 14035 | * @startq: The starting FCP EQ to modify |
| 14036 | * |
| 14037 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 14038 | * The command allows up to LPFC_MAX_EQ_DELAY_EQID_CNT EQ ID's to be |
| 14039 | * updated in one mailbox command. |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14040 | * |
| 14041 | * The @phba struct is used to send mailbox command to HBA. The @startq |
| 14042 | * is used to get the starting FCP EQ to change. |
| 14043 | * This function is asynchronous and will wait for the mailbox |
| 14044 | * command to finish before continuing. |
| 14045 | * |
| 14046 | * On success this function will return a zero. If unable to allocate enough |
| 14047 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14048 | * fails this function will return -ENXIO. |
| 14049 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14050 | int |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14051 | lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq, |
| 14052 | uint32_t numq, uint32_t imax) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14053 | { |
| 14054 | struct lpfc_mbx_modify_eq_delay *eq_delay; |
| 14055 | LPFC_MBOXQ_t *mbox; |
| 14056 | struct lpfc_queue *eq; |
| 14057 | int cnt, rc, length, status = 0; |
| 14058 | uint32_t shdr_status, shdr_add_status; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14059 | uint32_t result, val; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14060 | int qidx; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14061 | union lpfc_sli4_cfg_shdr *shdr; |
| 14062 | uint16_t dmult; |
| 14063 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14064 | if (startq >= phba->io_channel_irqs) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14065 | return 0; |
| 14066 | |
| 14067 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14068 | if (!mbox) |
| 14069 | return -ENOMEM; |
| 14070 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - |
| 14071 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14072 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14073 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, |
| 14074 | length, LPFC_SLI4_MBX_EMBED); |
| 14075 | eq_delay = &mbox->u.mqe.un.eq_delay; |
| 14076 | |
| 14077 | /* Calculate delay multiper from maximum interrupt per second */ |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14078 | result = imax / phba->io_channel_irqs; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14079 | if (result > LPFC_DMULT_CONST || result == 0) |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14080 | dmult = 0; |
| 14081 | else |
| 14082 | dmult = LPFC_DMULT_CONST/result - 1; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14083 | if (dmult > LPFC_DMULT_MAX) |
| 14084 | dmult = LPFC_DMULT_MAX; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14085 | |
| 14086 | cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14087 | for (qidx = startq; qidx < phba->io_channel_irqs; qidx++) { |
| 14088 | eq = phba->sli4_hba.hba_eq[qidx]; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14089 | if (!eq) |
| 14090 | continue; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14091 | eq->q_mode = imax; |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14092 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; |
| 14093 | eq_delay->u.request.eq[cnt].phase = 0; |
| 14094 | eq_delay->u.request.eq[cnt].delay_multi = dmult; |
| 14095 | cnt++; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 14096 | |
| 14097 | /* q_mode is only used for auto_imax */ |
| 14098 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 14099 | /* Use EQ Delay Register method for q_mode */ |
| 14100 | |
| 14101 | /* Convert for EQ Delay register */ |
| 14102 | val = phba->cfg_fcp_imax; |
| 14103 | if (val) { |
| 14104 | /* First, interrupts per sec per EQ */ |
| 14105 | val = phba->cfg_fcp_imax / |
| 14106 | phba->io_channel_irqs; |
| 14107 | |
| 14108 | /* us delay between each interrupt */ |
| 14109 | val = LPFC_SEC_TO_USEC / val; |
| 14110 | } |
| 14111 | eq->q_mode = val; |
| 14112 | } else { |
| 14113 | eq->q_mode = imax; |
| 14114 | } |
| 14115 | |
| 14116 | if (cnt >= numq) |
James Smart | 173edbb | 2012-06-12 13:54:50 -0400 | [diff] [blame] | 14117 | break; |
| 14118 | } |
| 14119 | eq_delay->u.request.num_eq = cnt; |
| 14120 | |
| 14121 | mbox->vport = phba->pport; |
| 14122 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14123 | mbox->context1 = NULL; |
| 14124 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14125 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; |
| 14126 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14127 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14128 | if (shdr_status || shdr_add_status || rc) { |
| 14129 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14130 | "2512 MODIFY_EQ_DELAY mailbox failed with " |
| 14131 | "status x%x add_status x%x, mbx status x%x\n", |
| 14132 | shdr_status, shdr_add_status, rc); |
| 14133 | status = -ENXIO; |
| 14134 | } |
| 14135 | mempool_free(mbox, phba->mbox_mem_pool); |
| 14136 | return status; |
| 14137 | } |
| 14138 | |
| 14139 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14140 | * lpfc_eq_create - Create an Event Queue on the HBA |
| 14141 | * @phba: HBA structure that indicates port to create a queue on. |
| 14142 | * @eq: The queue structure to use to create the event queue. |
| 14143 | * @imax: The maximum interrupt per second limit. |
| 14144 | * |
| 14145 | * This function creates an event queue, as detailed in @eq, on a port, |
| 14146 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. |
| 14147 | * |
| 14148 | * The @phba struct is used to send mailbox command to HBA. The @eq struct |
| 14149 | * is used to get the entry count and entry size that are necessary to |
| 14150 | * determine the number of pages to allocate and use for this queue. This |
| 14151 | * function will send the EQ_CREATE mailbox command to the HBA to setup the |
| 14152 | * event queue. This function is asynchronous and will wait for the mailbox |
| 14153 | * command to finish before continuing. |
| 14154 | * |
| 14155 | * 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] | 14156 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14157 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14158 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14159 | int |
James Smart | ee02006 | 2012-09-29 11:28:52 -0400 | [diff] [blame] | 14160 | 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] | 14161 | { |
| 14162 | struct lpfc_mbx_eq_create *eq_create; |
| 14163 | LPFC_MBOXQ_t *mbox; |
| 14164 | int rc, length, status = 0; |
| 14165 | struct lpfc_dmabuf *dmabuf; |
| 14166 | uint32_t shdr_status, shdr_add_status; |
| 14167 | union lpfc_sli4_cfg_shdr *shdr; |
| 14168 | uint16_t dmult; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14169 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14170 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14171 | /* sanity check on queue memory */ |
| 14172 | if (!eq) |
| 14173 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14174 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14175 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14176 | |
| 14177 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14178 | if (!mbox) |
| 14179 | return -ENOMEM; |
| 14180 | length = (sizeof(struct lpfc_mbx_eq_create) - |
| 14181 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14182 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14183 | LPFC_MBOX_OPCODE_EQ_CREATE, |
| 14184 | length, LPFC_SLI4_MBX_EMBED); |
| 14185 | eq_create = &mbox->u.mqe.un.eq_create; |
| 14186 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, |
| 14187 | eq->page_count); |
| 14188 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, |
| 14189 | LPFC_EQE_SIZE); |
| 14190 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 14191 | /* don't setup delay multiplier using EQ_CREATE */ |
| 14192 | dmult = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14193 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, |
| 14194 | dmult); |
| 14195 | switch (eq->entry_count) { |
| 14196 | default: |
| 14197 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14198 | "0360 Unsupported EQ count. (%d)\n", |
| 14199 | eq->entry_count); |
| 14200 | if (eq->entry_count < 256) |
| 14201 | return -EINVAL; |
| 14202 | /* otherwise default to smallest count (drop through) */ |
| 14203 | case 256: |
| 14204 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14205 | LPFC_EQ_CNT_256); |
| 14206 | break; |
| 14207 | case 512: |
| 14208 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14209 | LPFC_EQ_CNT_512); |
| 14210 | break; |
| 14211 | case 1024: |
| 14212 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14213 | LPFC_EQ_CNT_1024); |
| 14214 | break; |
| 14215 | case 2048: |
| 14216 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14217 | LPFC_EQ_CNT_2048); |
| 14218 | break; |
| 14219 | case 4096: |
| 14220 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, |
| 14221 | LPFC_EQ_CNT_4096); |
| 14222 | break; |
| 14223 | } |
| 14224 | list_for_each_entry(dmabuf, &eq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14225 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14226 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14227 | putPaddrLow(dmabuf->phys); |
| 14228 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14229 | putPaddrHigh(dmabuf->phys); |
| 14230 | } |
| 14231 | mbox->vport = phba->pport; |
| 14232 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 14233 | mbox->context1 = NULL; |
| 14234 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14235 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; |
| 14236 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14237 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14238 | if (shdr_status || shdr_add_status || rc) { |
| 14239 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14240 | "2500 EQ_CREATE mailbox failed with " |
| 14241 | "status x%x add_status x%x, mbx status x%x\n", |
| 14242 | shdr_status, shdr_add_status, rc); |
| 14243 | status = -ENXIO; |
| 14244 | } |
| 14245 | eq->type = LPFC_EQ; |
| 14246 | eq->subtype = LPFC_NONE; |
| 14247 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); |
| 14248 | if (eq->queue_id == 0xFFFF) |
| 14249 | status = -ENXIO; |
| 14250 | eq->host_index = 0; |
| 14251 | eq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14252 | eq->entry_repost = LPFC_EQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14253 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14254 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14255 | return status; |
| 14256 | } |
| 14257 | |
| 14258 | /** |
| 14259 | * lpfc_cq_create - Create a Completion Queue on the HBA |
| 14260 | * @phba: HBA structure that indicates port to create a queue on. |
| 14261 | * @cq: The queue structure to use to create the completion queue. |
| 14262 | * @eq: The event queue to bind this completion queue to. |
| 14263 | * |
| 14264 | * This function creates a completion queue, as detailed in @wq, on a port, |
| 14265 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. |
| 14266 | * |
| 14267 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14268 | * is used to get the entry count and entry size that are necessary to |
| 14269 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14270 | * is used to indicate which event queue to bind this completion queue to. This |
| 14271 | * function will send the CQ_CREATE mailbox command to the HBA to setup the |
| 14272 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14273 | * command to finish before continuing. |
| 14274 | * |
| 14275 | * 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] | 14276 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14277 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14278 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14279 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14280 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, |
| 14281 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) |
| 14282 | { |
| 14283 | struct lpfc_mbx_cq_create *cq_create; |
| 14284 | struct lpfc_dmabuf *dmabuf; |
| 14285 | LPFC_MBOXQ_t *mbox; |
| 14286 | int rc, length, status = 0; |
| 14287 | uint32_t shdr_status, shdr_add_status; |
| 14288 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14289 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14290 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14291 | /* sanity check on queue memory */ |
| 14292 | if (!cq || !eq) |
| 14293 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14294 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14295 | hw_page_size = SLI4_PAGE_SIZE; |
| 14296 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14297 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14298 | if (!mbox) |
| 14299 | return -ENOMEM; |
| 14300 | length = (sizeof(struct lpfc_mbx_cq_create) - |
| 14301 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14302 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14303 | LPFC_MBOX_OPCODE_CQ_CREATE, |
| 14304 | length, LPFC_SLI4_MBX_EMBED); |
| 14305 | cq_create = &mbox->u.mqe.un.cq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14306 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14307 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
| 14308 | cq->page_count); |
| 14309 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); |
| 14310 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14311 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14312 | phba->sli4_hba.pc_sli4_params.cqv); |
| 14313 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 14314 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
| 14315 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14316 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
| 14317 | eq->queue_id); |
| 14318 | } else { |
| 14319 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, |
| 14320 | eq->queue_id); |
| 14321 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14322 | switch (cq->entry_count) { |
| 14323 | default: |
| 14324 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14325 | "0361 Unsupported CQ count: " |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14326 | "entry cnt %d sz %d pg cnt %d\n", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14327 | cq->entry_count, cq->entry_size, |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14328 | cq->page_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14329 | if (cq->entry_count < 256) { |
| 14330 | status = -EINVAL; |
| 14331 | goto out; |
| 14332 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14333 | /* otherwise default to smallest count (drop through) */ |
| 14334 | case 256: |
| 14335 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14336 | LPFC_CQ_CNT_256); |
| 14337 | break; |
| 14338 | case 512: |
| 14339 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14340 | LPFC_CQ_CNT_512); |
| 14341 | break; |
| 14342 | case 1024: |
| 14343 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, |
| 14344 | LPFC_CQ_CNT_1024); |
| 14345 | break; |
| 14346 | } |
| 14347 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14348 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14349 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14350 | putPaddrLow(dmabuf->phys); |
| 14351 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 14352 | putPaddrHigh(dmabuf->phys); |
| 14353 | } |
| 14354 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14355 | |
| 14356 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14357 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14358 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14359 | if (shdr_status || shdr_add_status || rc) { |
| 14360 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14361 | "2501 CQ_CREATE mailbox failed with " |
| 14362 | "status x%x add_status x%x, mbx status x%x\n", |
| 14363 | shdr_status, shdr_add_status, rc); |
| 14364 | status = -ENXIO; |
| 14365 | goto out; |
| 14366 | } |
| 14367 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); |
| 14368 | if (cq->queue_id == 0xFFFF) { |
| 14369 | status = -ENXIO; |
| 14370 | goto out; |
| 14371 | } |
| 14372 | /* link the cq onto the parent eq child list */ |
| 14373 | list_add_tail(&cq->list, &eq->child_list); |
| 14374 | /* Set up completion queue's type and subtype */ |
| 14375 | cq->type = type; |
| 14376 | cq->subtype = subtype; |
| 14377 | 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] | 14378 | cq->assoc_qid = eq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14379 | cq->host_index = 0; |
| 14380 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14381 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14382 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14383 | out: |
| 14384 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14385 | return status; |
| 14386 | } |
| 14387 | |
| 14388 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14389 | * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ |
| 14390 | * @phba: HBA structure that indicates port to create a queue on. |
| 14391 | * @cqp: The queue structure array to use to create the completion queues. |
| 14392 | * @eqp: The event queue array to bind these completion queues to. |
| 14393 | * |
| 14394 | * This function creates a set of completion queue, s to support MRQ |
| 14395 | * as detailed in @cqp, on a port, |
| 14396 | * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA. |
| 14397 | * |
| 14398 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14399 | * is used to get the entry count and entry size that are necessary to |
| 14400 | * determine the number of pages to allocate and use for this queue. The @eq |
| 14401 | * is used to indicate which event queue to bind this completion queue to. This |
| 14402 | * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the |
| 14403 | * completion queue. This function is asynchronous and will wait for the mailbox |
| 14404 | * command to finish before continuing. |
| 14405 | * |
| 14406 | * On success this function will return a zero. If unable to allocate enough |
| 14407 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14408 | * fails this function will return -ENXIO. |
| 14409 | **/ |
| 14410 | int |
| 14411 | lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp, |
| 14412 | struct lpfc_queue **eqp, uint32_t type, uint32_t subtype) |
| 14413 | { |
| 14414 | struct lpfc_queue *cq; |
| 14415 | struct lpfc_queue *eq; |
| 14416 | struct lpfc_mbx_cq_create_set *cq_set; |
| 14417 | struct lpfc_dmabuf *dmabuf; |
| 14418 | LPFC_MBOXQ_t *mbox; |
| 14419 | int rc, length, alloclen, status = 0; |
| 14420 | int cnt, idx, numcq, page_idx = 0; |
| 14421 | uint32_t shdr_status, shdr_add_status; |
| 14422 | union lpfc_sli4_cfg_shdr *shdr; |
| 14423 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 14424 | |
| 14425 | /* sanity check on queue memory */ |
| 14426 | numcq = phba->cfg_nvmet_mrq; |
| 14427 | if (!cqp || !eqp || !numcq) |
| 14428 | return -ENODEV; |
| 14429 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14430 | hw_page_size = SLI4_PAGE_SIZE; |
| 14431 | |
| 14432 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14433 | if (!mbox) |
| 14434 | return -ENOMEM; |
| 14435 | |
| 14436 | length = sizeof(struct lpfc_mbx_cq_create_set); |
| 14437 | length += ((numcq * cqp[0]->page_count) * |
| 14438 | sizeof(struct dma_address)); |
| 14439 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14440 | LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length, |
| 14441 | LPFC_SLI4_MBX_NEMBED); |
| 14442 | if (alloclen < length) { |
| 14443 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14444 | "3098 Allocated DMA memory size (%d) is " |
| 14445 | "less than the requested DMA memory size " |
| 14446 | "(%d)\n", alloclen, length); |
| 14447 | status = -ENOMEM; |
| 14448 | goto out; |
| 14449 | } |
| 14450 | cq_set = mbox->sge_array->addr[0]; |
| 14451 | shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr; |
| 14452 | bf_set(lpfc_mbox_hdr_version, &shdr->request, 0); |
| 14453 | |
| 14454 | for (idx = 0; idx < numcq; idx++) { |
| 14455 | cq = cqp[idx]; |
| 14456 | eq = eqp[idx]; |
| 14457 | if (!cq || !eq) { |
| 14458 | status = -ENOMEM; |
| 14459 | goto out; |
| 14460 | } |
| 14461 | |
| 14462 | switch (idx) { |
| 14463 | case 0: |
| 14464 | bf_set(lpfc_mbx_cq_create_set_page_size, |
| 14465 | &cq_set->u.request, |
| 14466 | (hw_page_size / SLI4_PAGE_SIZE)); |
| 14467 | bf_set(lpfc_mbx_cq_create_set_num_pages, |
| 14468 | &cq_set->u.request, cq->page_count); |
| 14469 | bf_set(lpfc_mbx_cq_create_set_evt, |
| 14470 | &cq_set->u.request, 1); |
| 14471 | bf_set(lpfc_mbx_cq_create_set_valid, |
| 14472 | &cq_set->u.request, 1); |
| 14473 | bf_set(lpfc_mbx_cq_create_set_cqe_size, |
| 14474 | &cq_set->u.request, 0); |
| 14475 | bf_set(lpfc_mbx_cq_create_set_num_cq, |
| 14476 | &cq_set->u.request, numcq); |
| 14477 | switch (cq->entry_count) { |
| 14478 | default: |
| 14479 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14480 | "3118 Bad CQ count. (%d)\n", |
| 14481 | cq->entry_count); |
| 14482 | if (cq->entry_count < 256) { |
| 14483 | status = -EINVAL; |
| 14484 | goto out; |
| 14485 | } |
| 14486 | /* otherwise default to smallest (drop thru) */ |
| 14487 | case 256: |
| 14488 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14489 | &cq_set->u.request, LPFC_CQ_CNT_256); |
| 14490 | break; |
| 14491 | case 512: |
| 14492 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14493 | &cq_set->u.request, LPFC_CQ_CNT_512); |
| 14494 | break; |
| 14495 | case 1024: |
| 14496 | bf_set(lpfc_mbx_cq_create_set_cqe_cnt, |
| 14497 | &cq_set->u.request, LPFC_CQ_CNT_1024); |
| 14498 | break; |
| 14499 | } |
| 14500 | bf_set(lpfc_mbx_cq_create_set_eq_id0, |
| 14501 | &cq_set->u.request, eq->queue_id); |
| 14502 | break; |
| 14503 | case 1: |
| 14504 | bf_set(lpfc_mbx_cq_create_set_eq_id1, |
| 14505 | &cq_set->u.request, eq->queue_id); |
| 14506 | break; |
| 14507 | case 2: |
| 14508 | bf_set(lpfc_mbx_cq_create_set_eq_id2, |
| 14509 | &cq_set->u.request, eq->queue_id); |
| 14510 | break; |
| 14511 | case 3: |
| 14512 | bf_set(lpfc_mbx_cq_create_set_eq_id3, |
| 14513 | &cq_set->u.request, eq->queue_id); |
| 14514 | break; |
| 14515 | case 4: |
| 14516 | bf_set(lpfc_mbx_cq_create_set_eq_id4, |
| 14517 | &cq_set->u.request, eq->queue_id); |
| 14518 | break; |
| 14519 | case 5: |
| 14520 | bf_set(lpfc_mbx_cq_create_set_eq_id5, |
| 14521 | &cq_set->u.request, eq->queue_id); |
| 14522 | break; |
| 14523 | case 6: |
| 14524 | bf_set(lpfc_mbx_cq_create_set_eq_id6, |
| 14525 | &cq_set->u.request, eq->queue_id); |
| 14526 | break; |
| 14527 | case 7: |
| 14528 | bf_set(lpfc_mbx_cq_create_set_eq_id7, |
| 14529 | &cq_set->u.request, eq->queue_id); |
| 14530 | break; |
| 14531 | case 8: |
| 14532 | bf_set(lpfc_mbx_cq_create_set_eq_id8, |
| 14533 | &cq_set->u.request, eq->queue_id); |
| 14534 | break; |
| 14535 | case 9: |
| 14536 | bf_set(lpfc_mbx_cq_create_set_eq_id9, |
| 14537 | &cq_set->u.request, eq->queue_id); |
| 14538 | break; |
| 14539 | case 10: |
| 14540 | bf_set(lpfc_mbx_cq_create_set_eq_id10, |
| 14541 | &cq_set->u.request, eq->queue_id); |
| 14542 | break; |
| 14543 | case 11: |
| 14544 | bf_set(lpfc_mbx_cq_create_set_eq_id11, |
| 14545 | &cq_set->u.request, eq->queue_id); |
| 14546 | break; |
| 14547 | case 12: |
| 14548 | bf_set(lpfc_mbx_cq_create_set_eq_id12, |
| 14549 | &cq_set->u.request, eq->queue_id); |
| 14550 | break; |
| 14551 | case 13: |
| 14552 | bf_set(lpfc_mbx_cq_create_set_eq_id13, |
| 14553 | &cq_set->u.request, eq->queue_id); |
| 14554 | break; |
| 14555 | case 14: |
| 14556 | bf_set(lpfc_mbx_cq_create_set_eq_id14, |
| 14557 | &cq_set->u.request, eq->queue_id); |
| 14558 | break; |
| 14559 | case 15: |
| 14560 | bf_set(lpfc_mbx_cq_create_set_eq_id15, |
| 14561 | &cq_set->u.request, eq->queue_id); |
| 14562 | break; |
| 14563 | } |
| 14564 | |
| 14565 | /* link the cq onto the parent eq child list */ |
| 14566 | list_add_tail(&cq->list, &eq->child_list); |
| 14567 | /* Set up completion queue's type and subtype */ |
| 14568 | cq->type = type; |
| 14569 | cq->subtype = subtype; |
| 14570 | cq->assoc_qid = eq->queue_id; |
| 14571 | cq->host_index = 0; |
| 14572 | cq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14573 | cq->entry_repost = LPFC_CQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14574 | |
| 14575 | rc = 0; |
| 14576 | list_for_each_entry(dmabuf, &cq->page_list, list) { |
| 14577 | memset(dmabuf->virt, 0, hw_page_size); |
| 14578 | cnt = page_idx + dmabuf->buffer_tag; |
| 14579 | cq_set->u.request.page[cnt].addr_lo = |
| 14580 | putPaddrLow(dmabuf->phys); |
| 14581 | cq_set->u.request.page[cnt].addr_hi = |
| 14582 | putPaddrHigh(dmabuf->phys); |
| 14583 | rc++; |
| 14584 | } |
| 14585 | page_idx += rc; |
| 14586 | } |
| 14587 | |
| 14588 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14589 | |
| 14590 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 14591 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14592 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14593 | if (shdr_status || shdr_add_status || rc) { |
| 14594 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14595 | "3119 CQ_CREATE_SET mailbox failed with " |
| 14596 | "status x%x add_status x%x, mbx status x%x\n", |
| 14597 | shdr_status, shdr_add_status, rc); |
| 14598 | status = -ENXIO; |
| 14599 | goto out; |
| 14600 | } |
| 14601 | rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response); |
| 14602 | if (rc == 0xFFFF) { |
| 14603 | status = -ENXIO; |
| 14604 | goto out; |
| 14605 | } |
| 14606 | |
| 14607 | for (idx = 0; idx < numcq; idx++) { |
| 14608 | cq = cqp[idx]; |
| 14609 | cq->queue_id = rc + idx; |
| 14610 | } |
| 14611 | |
| 14612 | out: |
| 14613 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 14614 | return status; |
| 14615 | } |
| 14616 | |
| 14617 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14618 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14619 | * @phba: HBA structure that indicates port to create a queue on. |
| 14620 | * @mq: The queue structure to use to create the mailbox queue. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14621 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t |
| 14622 | * @cq: The completion queue to associate with this cq. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14623 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14624 | * This function provides failback (fb) functionality when the |
| 14625 | * mq_create_ext fails on older FW generations. It's purpose is identical |
| 14626 | * to mq_create_ext otherwise. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14627 | * |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14628 | * This routine cannot fail as all attributes were previously accessed and |
| 14629 | * initialized in mq_create_ext. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14630 | **/ |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14631 | static void |
| 14632 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 14633 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14634 | { |
| 14635 | struct lpfc_mbx_mq_create *mq_create; |
| 14636 | struct lpfc_dmabuf *dmabuf; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14637 | int length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14638 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14639 | length = (sizeof(struct lpfc_mbx_mq_create) - |
| 14640 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14641 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14642 | LPFC_MBOX_OPCODE_MQ_CREATE, |
| 14643 | length, LPFC_SLI4_MBX_EMBED); |
| 14644 | mq_create = &mbox->u.mqe.un.mq_create; |
| 14645 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14646 | mq->page_count); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14647 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14648 | cq->queue_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14649 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); |
| 14650 | switch (mq->entry_count) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14651 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14652 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14653 | LPFC_MQ_RING_SIZE_16); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14654 | break; |
| 14655 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14656 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14657 | LPFC_MQ_RING_SIZE_32); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14658 | break; |
| 14659 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14660 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14661 | LPFC_MQ_RING_SIZE_64); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14662 | break; |
| 14663 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14664 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
| 14665 | LPFC_MQ_RING_SIZE_128); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14666 | break; |
| 14667 | } |
| 14668 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
| 14669 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14670 | putPaddrLow(dmabuf->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14671 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14672 | putPaddrHigh(dmabuf->phys); |
| 14673 | } |
| 14674 | } |
| 14675 | |
| 14676 | /** |
| 14677 | * lpfc_mq_create - Create a mailbox Queue on the HBA |
| 14678 | * @phba: HBA structure that indicates port to create a queue on. |
| 14679 | * @mq: The queue structure to use to create the mailbox queue. |
| 14680 | * @cq: The completion queue to associate with this cq. |
| 14681 | * @subtype: The queue's subtype. |
| 14682 | * |
| 14683 | * This function creates a mailbox queue, as detailed in @mq, on a port, |
| 14684 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. |
| 14685 | * |
| 14686 | * The @phba struct is used to send mailbox command to HBA. The @cq struct |
| 14687 | * is used to get the entry count and entry size that are necessary to |
| 14688 | * determine the number of pages to allocate and use for this queue. This |
| 14689 | * function will send the MQ_CREATE mailbox command to the HBA to setup the |
| 14690 | * mailbox queue. This function is asynchronous and will wait for the mailbox |
| 14691 | * command to finish before continuing. |
| 14692 | * |
| 14693 | * 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] | 14694 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14695 | * fails this function will return -ENXIO. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14696 | **/ |
| 14697 | int32_t |
| 14698 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
| 14699 | struct lpfc_queue *cq, uint32_t subtype) |
| 14700 | { |
| 14701 | struct lpfc_mbx_mq_create *mq_create; |
| 14702 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
| 14703 | struct lpfc_dmabuf *dmabuf; |
| 14704 | LPFC_MBOXQ_t *mbox; |
| 14705 | int rc, length, status = 0; |
| 14706 | uint32_t shdr_status, shdr_add_status; |
| 14707 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14708 | 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] | 14709 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14710 | /* sanity check on queue memory */ |
| 14711 | if (!mq || !cq) |
| 14712 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14713 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14714 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14715 | |
| 14716 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14717 | if (!mbox) |
| 14718 | return -ENOMEM; |
| 14719 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
| 14720 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14721 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 14722 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
| 14723 | length, LPFC_SLI4_MBX_EMBED); |
| 14724 | |
| 14725 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14726 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 14727 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
| 14728 | &mq_create_ext->u.request, mq->page_count); |
| 14729 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, |
| 14730 | &mq_create_ext->u.request, 1); |
| 14731 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14732 | &mq_create_ext->u.request, 1); |
| 14733 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, |
| 14734 | &mq_create_ext->u.request, 1); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 14735 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
| 14736 | &mq_create_ext->u.request, 1); |
| 14737 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, |
| 14738 | &mq_create_ext->u.request, 1); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14739 | 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] | 14740 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14741 | phba->sli4_hba.pc_sli4_params.mqv); |
| 14742 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) |
| 14743 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, |
| 14744 | cq->queue_id); |
| 14745 | else |
| 14746 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, |
| 14747 | cq->queue_id); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14748 | switch (mq->entry_count) { |
| 14749 | default: |
| 14750 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 14751 | "0362 Unsupported MQ count. (%d)\n", |
| 14752 | mq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 14753 | if (mq->entry_count < 16) { |
| 14754 | status = -EINVAL; |
| 14755 | goto out; |
| 14756 | } |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14757 | /* otherwise default to smallest count (drop through) */ |
| 14758 | case 16: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14759 | bf_set(lpfc_mq_context_ring_size, |
| 14760 | &mq_create_ext->u.request.context, |
| 14761 | LPFC_MQ_RING_SIZE_16); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14762 | break; |
| 14763 | case 32: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14764 | bf_set(lpfc_mq_context_ring_size, |
| 14765 | &mq_create_ext->u.request.context, |
| 14766 | LPFC_MQ_RING_SIZE_32); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14767 | break; |
| 14768 | case 64: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14769 | bf_set(lpfc_mq_context_ring_size, |
| 14770 | &mq_create_ext->u.request.context, |
| 14771 | LPFC_MQ_RING_SIZE_64); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14772 | break; |
| 14773 | case 128: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14774 | bf_set(lpfc_mq_context_ring_size, |
| 14775 | &mq_create_ext->u.request.context, |
| 14776 | LPFC_MQ_RING_SIZE_128); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14777 | break; |
| 14778 | } |
| 14779 | list_for_each_entry(dmabuf, &mq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14780 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14781 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 14782 | putPaddrLow(dmabuf->phys); |
| 14783 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14784 | putPaddrHigh(dmabuf->phys); |
| 14785 | } |
| 14786 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 14787 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 14788 | &mq_create_ext->u.response); |
| 14789 | if (rc != MBX_SUCCESS) { |
| 14790 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 14791 | "2795 MQ_CREATE_EXT failed with " |
| 14792 | "status x%x. Failback to MQ_CREATE.\n", |
| 14793 | rc); |
| 14794 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); |
| 14795 | mq_create = &mbox->u.mqe.un.mq_create; |
| 14796 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14797 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; |
| 14798 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
| 14799 | &mq_create->u.response); |
| 14800 | } |
| 14801 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14802 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14803 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14804 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14805 | if (shdr_status || shdr_add_status || rc) { |
| 14806 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14807 | "2502 MQ_CREATE mailbox failed with " |
| 14808 | "status x%x add_status x%x, mbx status x%x\n", |
| 14809 | shdr_status, shdr_add_status, rc); |
| 14810 | status = -ENXIO; |
| 14811 | goto out; |
| 14812 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14813 | if (mq->queue_id == 0xFFFF) { |
| 14814 | status = -ENXIO; |
| 14815 | goto out; |
| 14816 | } |
| 14817 | mq->type = LPFC_MQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 14818 | mq->assoc_qid = cq->queue_id; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14819 | mq->subtype = subtype; |
| 14820 | mq->host_index = 0; |
| 14821 | mq->hba_index = 0; |
James Smart | 64eb4dc | 2017-05-15 15:20:49 -0700 | [diff] [blame] | 14822 | mq->entry_repost = LPFC_MQ_REPOST; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14823 | |
| 14824 | /* link the mq onto the parent cq child list */ |
| 14825 | list_add_tail(&mq->list, &cq->child_list); |
| 14826 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 14827 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 14828 | return status; |
| 14829 | } |
| 14830 | |
| 14831 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14832 | * lpfc_wq_create - Create a Work Queue on the HBA |
| 14833 | * @phba: HBA structure that indicates port to create a queue on. |
| 14834 | * @wq: The queue structure to use to create the work queue. |
| 14835 | * @cq: The completion queue to bind this work queue to. |
| 14836 | * @subtype: The subtype of the work queue indicating its functionality. |
| 14837 | * |
| 14838 | * This function creates a work queue, as detailed in @wq, on a port, described |
| 14839 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. |
| 14840 | * |
| 14841 | * The @phba struct is used to send mailbox command to HBA. The @wq struct |
| 14842 | * is used to get the entry count and entry size that are necessary to |
| 14843 | * determine the number of pages to allocate and use for this queue. The @cq |
| 14844 | * is used to indicate which completion queue to bind this work queue to. This |
| 14845 | * function will send the WQ_CREATE mailbox command to the HBA to setup the |
| 14846 | * work queue. This function is asynchronous and will wait for the mailbox |
| 14847 | * command to finish before continuing. |
| 14848 | * |
| 14849 | * 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] | 14850 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 14851 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14852 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 14853 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14854 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, |
| 14855 | struct lpfc_queue *cq, uint32_t subtype) |
| 14856 | { |
| 14857 | struct lpfc_mbx_wq_create *wq_create; |
| 14858 | struct lpfc_dmabuf *dmabuf; |
| 14859 | LPFC_MBOXQ_t *mbox; |
| 14860 | int rc, length, status = 0; |
| 14861 | uint32_t shdr_status, shdr_add_status; |
| 14862 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14863 | 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] | 14864 | struct dma_address *page; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14865 | void __iomem *bar_memmap_p; |
| 14866 | uint32_t db_offset; |
| 14867 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14868 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 14869 | /* sanity check on queue memory */ |
| 14870 | if (!wq || !cq) |
| 14871 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14872 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 14873 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14874 | |
| 14875 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 14876 | if (!mbox) |
| 14877 | return -ENOMEM; |
| 14878 | length = (sizeof(struct lpfc_mbx_wq_create) - |
| 14879 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 14880 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 14881 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, |
| 14882 | length, LPFC_SLI4_MBX_EMBED); |
| 14883 | wq_create = &mbox->u.mqe.un.wq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14884 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14885 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
| 14886 | wq->page_count); |
| 14887 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, |
| 14888 | cq->queue_id); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14889 | |
| 14890 | /* wqv is the earliest version supported, NOT the latest */ |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14891 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14892 | phba->sli4_hba.pc_sli4_params.wqv); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14893 | |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14894 | switch (phba->sli4_hba.pc_sli4_params.wqv) { |
| 14895 | case LPFC_Q_CREATE_VERSION_0: |
| 14896 | switch (wq->entry_size) { |
| 14897 | default: |
| 14898 | case 64: |
| 14899 | /* Nothing to do, version 0 ONLY supports 64 byte */ |
| 14900 | page = wq_create->u.request.page; |
| 14901 | break; |
| 14902 | case 128: |
| 14903 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 14904 | LPFC_WQ_SZ128_SUPPORT)) { |
| 14905 | status = -ERANGE; |
| 14906 | goto out; |
| 14907 | } |
| 14908 | /* If we get here the HBA MUST also support V1 and |
| 14909 | * we MUST use it |
| 14910 | */ |
| 14911 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14912 | LPFC_Q_CREATE_VERSION_1); |
| 14913 | |
| 14914 | bf_set(lpfc_mbx_wq_create_wqe_count, |
| 14915 | &wq_create->u.request_1, wq->entry_count); |
| 14916 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 14917 | &wq_create->u.request_1, |
| 14918 | LPFC_WQ_WQE_SIZE_128); |
| 14919 | bf_set(lpfc_mbx_wq_create_page_size, |
| 14920 | &wq_create->u.request_1, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 14921 | LPFC_WQ_PAGE_SIZE_4096); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14922 | page = wq_create->u.request_1.page; |
| 14923 | break; |
| 14924 | } |
| 14925 | break; |
| 14926 | case LPFC_Q_CREATE_VERSION_1: |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14927 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, |
| 14928 | wq->entry_count); |
James Smart | 3f247de | 2017-04-21 16:04:56 -0700 | [diff] [blame] | 14929 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 14930 | LPFC_Q_CREATE_VERSION_1); |
| 14931 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14932 | switch (wq->entry_size) { |
| 14933 | default: |
| 14934 | case 64: |
| 14935 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 14936 | &wq_create->u.request_1, |
| 14937 | LPFC_WQ_WQE_SIZE_64); |
| 14938 | break; |
| 14939 | case 128: |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14940 | if (!(phba->sli4_hba.pc_sli4_params.wqsize & |
| 14941 | LPFC_WQ_SZ128_SUPPORT)) { |
| 14942 | status = -ERANGE; |
| 14943 | goto out; |
| 14944 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14945 | bf_set(lpfc_mbx_wq_create_wqe_size, |
| 14946 | &wq_create->u.request_1, |
| 14947 | LPFC_WQ_WQE_SIZE_128); |
| 14948 | break; |
| 14949 | } |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 14950 | bf_set(lpfc_mbx_wq_create_page_size, |
| 14951 | &wq_create->u.request_1, |
| 14952 | LPFC_WQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14953 | page = wq_create->u.request_1.page; |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14954 | break; |
| 14955 | default: |
| 14956 | status = -ERANGE; |
| 14957 | goto out; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14958 | } |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 14959 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14960 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 14961 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 14962 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
| 14963 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14964 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14965 | |
| 14966 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 14967 | bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1); |
| 14968 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14969 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 14970 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 14971 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 14972 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 14973 | if (shdr_status || shdr_add_status || rc) { |
| 14974 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14975 | "2503 WQ_CREATE mailbox failed with " |
| 14976 | "status x%x add_status x%x, mbx status x%x\n", |
| 14977 | shdr_status, shdr_add_status, rc); |
| 14978 | status = -ENXIO; |
| 14979 | goto out; |
| 14980 | } |
| 14981 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); |
| 14982 | if (wq->queue_id == 0xFFFF) { |
| 14983 | status = -ENXIO; |
| 14984 | goto out; |
| 14985 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 14986 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 14987 | wq->db_format = bf_get(lpfc_mbx_wq_create_db_format, |
| 14988 | &wq_create->u.response); |
| 14989 | if ((wq->db_format != LPFC_DB_LIST_FORMAT) && |
| 14990 | (wq->db_format != LPFC_DB_RING_FORMAT)) { |
| 14991 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14992 | "3265 WQ[%d] doorbell format not " |
| 14993 | "supported: x%x\n", wq->queue_id, |
| 14994 | wq->db_format); |
| 14995 | status = -EINVAL; |
| 14996 | goto out; |
| 14997 | } |
| 14998 | pci_barset = bf_get(lpfc_mbx_wq_create_bar_set, |
| 14999 | &wq_create->u.response); |
| 15000 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15001 | if (!bar_memmap_p) { |
| 15002 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15003 | "3263 WQ[%d] failed to memmap pci " |
| 15004 | "barset:x%x\n", wq->queue_id, |
| 15005 | pci_barset); |
| 15006 | status = -ENOMEM; |
| 15007 | goto out; |
| 15008 | } |
| 15009 | db_offset = wq_create->u.response.doorbell_offset; |
| 15010 | if ((db_offset != LPFC_ULP0_WQ_DOORBELL) && |
| 15011 | (db_offset != LPFC_ULP1_WQ_DOORBELL)) { |
| 15012 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15013 | "3252 WQ[%d] doorbell offset not " |
| 15014 | "supported: x%x\n", wq->queue_id, |
| 15015 | db_offset); |
| 15016 | status = -EINVAL; |
| 15017 | goto out; |
| 15018 | } |
| 15019 | wq->db_regaddr = bar_memmap_p + db_offset; |
| 15020 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15021 | "3264 WQ[%d]: barset:x%x, offset:x%x, " |
| 15022 | "format:x%x\n", wq->queue_id, pci_barset, |
| 15023 | db_offset, wq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15024 | } else { |
| 15025 | wq->db_format = LPFC_DB_LIST_FORMAT; |
| 15026 | wq->db_regaddr = phba->sli4_hba.WQDBregaddr; |
| 15027 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15028 | wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
| 15029 | if (wq->pring == NULL) { |
| 15030 | status = -ENOMEM; |
| 15031 | goto out; |
| 15032 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15033 | wq->type = LPFC_WQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15034 | wq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15035 | wq->subtype = subtype; |
| 15036 | wq->host_index = 0; |
| 15037 | wq->hba_index = 0; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 15038 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15039 | |
| 15040 | /* link the wq onto the parent cq child list */ |
| 15041 | list_add_tail(&wq->list, &cq->child_list); |
| 15042 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15043 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15044 | return status; |
| 15045 | } |
| 15046 | |
| 15047 | /** |
| 15048 | * lpfc_rq_create - Create a Receive Queue on the HBA |
| 15049 | * @phba: HBA structure that indicates port to create a queue on. |
| 15050 | * @hrq: The queue structure to use to create the header receive queue. |
| 15051 | * @drq: The queue structure to use to create the data receive queue. |
| 15052 | * @cq: The completion queue to bind this work queue to. |
| 15053 | * |
| 15054 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15055 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15056 | * to the HBA. |
| 15057 | * |
| 15058 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15059 | * struct is used to get the entry count that is necessary to determine the |
| 15060 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15061 | * completion queue to bind received buffers that are posted to these queues to. |
| 15062 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15063 | * receive queue pair. This function is asynchronous and will wait for the |
| 15064 | * mailbox command to finish before continuing. |
| 15065 | * |
| 15066 | * 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] | 15067 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15068 | * fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15069 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15070 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15071 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15072 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) |
| 15073 | { |
| 15074 | struct lpfc_mbx_rq_create *rq_create; |
| 15075 | struct lpfc_dmabuf *dmabuf; |
| 15076 | LPFC_MBOXQ_t *mbox; |
| 15077 | int rc, length, status = 0; |
| 15078 | uint32_t shdr_status, shdr_add_status; |
| 15079 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15080 | 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] | 15081 | void __iomem *bar_memmap_p; |
| 15082 | uint32_t db_offset; |
| 15083 | uint16_t pci_barset; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15084 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15085 | /* sanity check on queue memory */ |
| 15086 | if (!hrq || !drq || !cq) |
| 15087 | return -ENODEV; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15088 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15089 | hw_page_size = SLI4_PAGE_SIZE; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15090 | |
| 15091 | if (hrq->entry_count != drq->entry_count) |
| 15092 | return -EINVAL; |
| 15093 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15094 | if (!mbox) |
| 15095 | return -ENOMEM; |
| 15096 | length = (sizeof(struct lpfc_mbx_rq_create) - |
| 15097 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15098 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15099 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15100 | length, LPFC_SLI4_MBX_EMBED); |
| 15101 | rq_create = &mbox->u.mqe.un.rq_create; |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15102 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15103 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15104 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15105 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15106 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15107 | &rq_create->u.request.context, |
| 15108 | hrq->entry_count); |
| 15109 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15110 | bf_set(lpfc_rq_context_rqe_size, |
| 15111 | &rq_create->u.request.context, |
| 15112 | LPFC_RQE_SIZE_8); |
| 15113 | bf_set(lpfc_rq_context_page_size, |
| 15114 | &rq_create->u.request.context, |
James Smart | 8ea73db | 2017-02-12 13:52:25 -0800 | [diff] [blame] | 15115 | LPFC_RQ_PAGE_SIZE_4096); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15116 | } else { |
| 15117 | switch (hrq->entry_count) { |
| 15118 | default: |
| 15119 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15120 | "2535 Unsupported RQ count. (%d)\n", |
| 15121 | hrq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15122 | if (hrq->entry_count < 512) { |
| 15123 | status = -EINVAL; |
| 15124 | goto out; |
| 15125 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15126 | /* otherwise default to smallest count (drop through) */ |
| 15127 | case 512: |
| 15128 | bf_set(lpfc_rq_context_rqe_count, |
| 15129 | &rq_create->u.request.context, |
| 15130 | LPFC_RQ_RING_SIZE_512); |
| 15131 | break; |
| 15132 | case 1024: |
| 15133 | bf_set(lpfc_rq_context_rqe_count, |
| 15134 | &rq_create->u.request.context, |
| 15135 | LPFC_RQ_RING_SIZE_1024); |
| 15136 | break; |
| 15137 | case 2048: |
| 15138 | bf_set(lpfc_rq_context_rqe_count, |
| 15139 | &rq_create->u.request.context, |
| 15140 | LPFC_RQ_RING_SIZE_2048); |
| 15141 | break; |
| 15142 | case 4096: |
| 15143 | bf_set(lpfc_rq_context_rqe_count, |
| 15144 | &rq_create->u.request.context, |
| 15145 | LPFC_RQ_RING_SIZE_4096); |
| 15146 | break; |
| 15147 | } |
| 15148 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, |
| 15149 | LPFC_HDR_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15150 | } |
| 15151 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15152 | cq->queue_id); |
| 15153 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15154 | hrq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15155 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 15156 | memset(dmabuf->virt, 0, hw_page_size); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15157 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15158 | putPaddrLow(dmabuf->phys); |
| 15159 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15160 | putPaddrHigh(dmabuf->phys); |
| 15161 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15162 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15163 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
| 15164 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15165 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15166 | /* The IOCTL status is embedded in the mailbox subheader. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15167 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15168 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15169 | if (shdr_status || shdr_add_status || rc) { |
| 15170 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15171 | "2504 RQ_CREATE mailbox failed with " |
| 15172 | "status x%x add_status x%x, mbx status x%x\n", |
| 15173 | shdr_status, shdr_add_status, rc); |
| 15174 | status = -ENXIO; |
| 15175 | goto out; |
| 15176 | } |
| 15177 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15178 | if (hrq->queue_id == 0xFFFF) { |
| 15179 | status = -ENXIO; |
| 15180 | goto out; |
| 15181 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15182 | |
| 15183 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) { |
| 15184 | hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format, |
| 15185 | &rq_create->u.response); |
| 15186 | if ((hrq->db_format != LPFC_DB_LIST_FORMAT) && |
| 15187 | (hrq->db_format != LPFC_DB_RING_FORMAT)) { |
| 15188 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15189 | "3262 RQ [%d] doorbell format not " |
| 15190 | "supported: x%x\n", hrq->queue_id, |
| 15191 | hrq->db_format); |
| 15192 | status = -EINVAL; |
| 15193 | goto out; |
| 15194 | } |
| 15195 | |
| 15196 | pci_barset = bf_get(lpfc_mbx_rq_create_bar_set, |
| 15197 | &rq_create->u.response); |
| 15198 | bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset); |
| 15199 | if (!bar_memmap_p) { |
| 15200 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15201 | "3269 RQ[%d] failed to memmap pci " |
| 15202 | "barset:x%x\n", hrq->queue_id, |
| 15203 | pci_barset); |
| 15204 | status = -ENOMEM; |
| 15205 | goto out; |
| 15206 | } |
| 15207 | |
| 15208 | db_offset = rq_create->u.response.doorbell_offset; |
| 15209 | if ((db_offset != LPFC_ULP0_RQ_DOORBELL) && |
| 15210 | (db_offset != LPFC_ULP1_RQ_DOORBELL)) { |
| 15211 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15212 | "3270 RQ[%d] doorbell offset not " |
| 15213 | "supported: x%x\n", hrq->queue_id, |
| 15214 | db_offset); |
| 15215 | status = -EINVAL; |
| 15216 | goto out; |
| 15217 | } |
| 15218 | hrq->db_regaddr = bar_memmap_p + db_offset; |
| 15219 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | a22e7db | 2013-04-17 20:16:37 -0400 | [diff] [blame] | 15220 | "3266 RQ[qid:%d]: barset:x%x, offset:x%x, " |
| 15221 | "format:x%x\n", hrq->queue_id, pci_barset, |
| 15222 | db_offset, hrq->db_format); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15223 | } else { |
| 15224 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15225 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15226 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15227 | hrq->type = LPFC_HRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15228 | hrq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15229 | hrq->subtype = subtype; |
| 15230 | hrq->host_index = 0; |
| 15231 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15232 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15233 | |
| 15234 | /* now create the data queue */ |
| 15235 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15236 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, |
| 15237 | length, LPFC_SLI4_MBX_EMBED); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15238 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
| 15239 | phba->sli4_hba.pc_sli4_params.rqv); |
| 15240 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { |
| 15241 | bf_set(lpfc_rq_context_rqe_count_1, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15242 | &rq_create->u.request.context, hrq->entry_count); |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15243 | if (subtype == LPFC_NVMET) |
| 15244 | rq_create->u.request.context.buffer_size = |
| 15245 | LPFC_NVMET_DATA_BUF_SIZE; |
| 15246 | else |
| 15247 | rq_create->u.request.context.buffer_size = |
| 15248 | LPFC_DATA_BUF_SIZE; |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 15249 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
| 15250 | LPFC_RQE_SIZE_8); |
| 15251 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, |
| 15252 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15253 | } else { |
| 15254 | switch (drq->entry_count) { |
| 15255 | default: |
| 15256 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15257 | "2536 Unsupported RQ count. (%d)\n", |
| 15258 | drq->entry_count); |
James Smart | 4f4c186 | 2012-06-12 13:54:02 -0400 | [diff] [blame] | 15259 | if (drq->entry_count < 512) { |
| 15260 | status = -EINVAL; |
| 15261 | goto out; |
| 15262 | } |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 15263 | /* otherwise default to smallest count (drop through) */ |
| 15264 | case 512: |
| 15265 | bf_set(lpfc_rq_context_rqe_count, |
| 15266 | &rq_create->u.request.context, |
| 15267 | LPFC_RQ_RING_SIZE_512); |
| 15268 | break; |
| 15269 | case 1024: |
| 15270 | bf_set(lpfc_rq_context_rqe_count, |
| 15271 | &rq_create->u.request.context, |
| 15272 | LPFC_RQ_RING_SIZE_1024); |
| 15273 | break; |
| 15274 | case 2048: |
| 15275 | bf_set(lpfc_rq_context_rqe_count, |
| 15276 | &rq_create->u.request.context, |
| 15277 | LPFC_RQ_RING_SIZE_2048); |
| 15278 | break; |
| 15279 | case 4096: |
| 15280 | bf_set(lpfc_rq_context_rqe_count, |
| 15281 | &rq_create->u.request.context, |
| 15282 | LPFC_RQ_RING_SIZE_4096); |
| 15283 | break; |
| 15284 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15285 | if (subtype == LPFC_NVMET) |
| 15286 | bf_set(lpfc_rq_context_buf_size, |
| 15287 | &rq_create->u.request.context, |
| 15288 | LPFC_NVMET_DATA_BUF_SIZE); |
| 15289 | else |
| 15290 | bf_set(lpfc_rq_context_buf_size, |
| 15291 | &rq_create->u.request.context, |
| 15292 | LPFC_DATA_BUF_SIZE); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15293 | } |
| 15294 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, |
| 15295 | cq->queue_id); |
| 15296 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, |
| 15297 | drq->page_count); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15298 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15299 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
| 15300 | putPaddrLow(dmabuf->phys); |
| 15301 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = |
| 15302 | putPaddrHigh(dmabuf->phys); |
| 15303 | } |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 15304 | if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) |
| 15305 | bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15306 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15307 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15308 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
| 15309 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15310 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15311 | if (shdr_status || shdr_add_status || rc) { |
| 15312 | status = -ENXIO; |
| 15313 | goto out; |
| 15314 | } |
| 15315 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15316 | if (drq->queue_id == 0xFFFF) { |
| 15317 | status = -ENXIO; |
| 15318 | goto out; |
| 15319 | } |
| 15320 | drq->type = LPFC_DRQ; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 15321 | drq->assoc_qid = cq->queue_id; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15322 | drq->subtype = subtype; |
| 15323 | drq->host_index = 0; |
| 15324 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15325 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15326 | |
| 15327 | /* link the header and data RQs onto the parent cq child list */ |
| 15328 | list_add_tail(&hrq->list, &cq->child_list); |
| 15329 | list_add_tail(&drq->list, &cq->child_list); |
| 15330 | |
| 15331 | out: |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15332 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15333 | return status; |
| 15334 | } |
| 15335 | |
| 15336 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15337 | * lpfc_mrq_create - Create MRQ Receive Queues on the HBA |
| 15338 | * @phba: HBA structure that indicates port to create a queue on. |
| 15339 | * @hrqp: The queue structure array to use to create the header receive queues. |
| 15340 | * @drqp: The queue structure array to use to create the data receive queues. |
| 15341 | * @cqp: The completion queue array to bind these receive queues to. |
| 15342 | * |
| 15343 | * This function creates a receive buffer queue pair , as detailed in @hrq and |
| 15344 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command |
| 15345 | * to the HBA. |
| 15346 | * |
| 15347 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq |
| 15348 | * struct is used to get the entry count that is necessary to determine the |
| 15349 | * number of pages to use for this queue. The @cq is used to indicate which |
| 15350 | * completion queue to bind received buffers that are posted to these queues to. |
| 15351 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the |
| 15352 | * receive queue pair. This function is asynchronous and will wait for the |
| 15353 | * mailbox command to finish before continuing. |
| 15354 | * |
| 15355 | * On success this function will return a zero. If unable to allocate enough |
| 15356 | * memory this function will return -ENOMEM. If the queue create mailbox command |
| 15357 | * fails this function will return -ENXIO. |
| 15358 | **/ |
| 15359 | int |
| 15360 | lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp, |
| 15361 | struct lpfc_queue **drqp, struct lpfc_queue **cqp, |
| 15362 | uint32_t subtype) |
| 15363 | { |
| 15364 | struct lpfc_queue *hrq, *drq, *cq; |
| 15365 | struct lpfc_mbx_rq_create_v2 *rq_create; |
| 15366 | struct lpfc_dmabuf *dmabuf; |
| 15367 | LPFC_MBOXQ_t *mbox; |
| 15368 | int rc, length, alloclen, status = 0; |
| 15369 | int cnt, idx, numrq, page_idx = 0; |
| 15370 | uint32_t shdr_status, shdr_add_status; |
| 15371 | union lpfc_sli4_cfg_shdr *shdr; |
| 15372 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
| 15373 | |
| 15374 | numrq = phba->cfg_nvmet_mrq; |
| 15375 | /* sanity check on array memory */ |
| 15376 | if (!hrqp || !drqp || !cqp || !numrq) |
| 15377 | return -ENODEV; |
| 15378 | if (!phba->sli4_hba.pc_sli4_params.supported) |
| 15379 | hw_page_size = SLI4_PAGE_SIZE; |
| 15380 | |
| 15381 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15382 | if (!mbox) |
| 15383 | return -ENOMEM; |
| 15384 | |
| 15385 | length = sizeof(struct lpfc_mbx_rq_create_v2); |
| 15386 | length += ((2 * numrq * hrqp[0]->page_count) * |
| 15387 | sizeof(struct dma_address)); |
| 15388 | |
| 15389 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15390 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length, |
| 15391 | LPFC_SLI4_MBX_NEMBED); |
| 15392 | if (alloclen < length) { |
| 15393 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15394 | "3099 Allocated DMA memory size (%d) is " |
| 15395 | "less than the requested DMA memory size " |
| 15396 | "(%d)\n", alloclen, length); |
| 15397 | status = -ENOMEM; |
| 15398 | goto out; |
| 15399 | } |
| 15400 | |
| 15401 | |
| 15402 | |
| 15403 | rq_create = mbox->sge_array->addr[0]; |
| 15404 | shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr; |
| 15405 | |
| 15406 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2); |
| 15407 | cnt = 0; |
| 15408 | |
| 15409 | for (idx = 0; idx < numrq; idx++) { |
| 15410 | hrq = hrqp[idx]; |
| 15411 | drq = drqp[idx]; |
| 15412 | cq = cqp[idx]; |
| 15413 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15414 | /* sanity check on queue memory */ |
| 15415 | if (!hrq || !drq || !cq) { |
| 15416 | status = -ENODEV; |
| 15417 | goto out; |
| 15418 | } |
| 15419 | |
James Smart | 7aabe84 | 2017-03-04 09:30:22 -0800 | [diff] [blame] | 15420 | if (hrq->entry_count != drq->entry_count) { |
| 15421 | status = -EINVAL; |
| 15422 | goto out; |
| 15423 | } |
| 15424 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15425 | if (idx == 0) { |
| 15426 | bf_set(lpfc_mbx_rq_create_num_pages, |
| 15427 | &rq_create->u.request, |
| 15428 | hrq->page_count); |
| 15429 | bf_set(lpfc_mbx_rq_create_rq_cnt, |
| 15430 | &rq_create->u.request, (numrq * 2)); |
| 15431 | bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request, |
| 15432 | 1); |
| 15433 | bf_set(lpfc_rq_context_base_cq, |
| 15434 | &rq_create->u.request.context, |
| 15435 | cq->queue_id); |
| 15436 | bf_set(lpfc_rq_context_data_size, |
| 15437 | &rq_create->u.request.context, |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 15438 | LPFC_NVMET_DATA_BUF_SIZE); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15439 | bf_set(lpfc_rq_context_hdr_size, |
| 15440 | &rq_create->u.request.context, |
| 15441 | LPFC_HDR_BUF_SIZE); |
| 15442 | bf_set(lpfc_rq_context_rqe_count_1, |
| 15443 | &rq_create->u.request.context, |
| 15444 | hrq->entry_count); |
| 15445 | bf_set(lpfc_rq_context_rqe_size, |
| 15446 | &rq_create->u.request.context, |
| 15447 | LPFC_RQE_SIZE_8); |
| 15448 | bf_set(lpfc_rq_context_page_size, |
| 15449 | &rq_create->u.request.context, |
| 15450 | (PAGE_SIZE/SLI4_PAGE_SIZE)); |
| 15451 | } |
| 15452 | rc = 0; |
| 15453 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
| 15454 | memset(dmabuf->virt, 0, hw_page_size); |
| 15455 | cnt = page_idx + dmabuf->buffer_tag; |
| 15456 | rq_create->u.request.page[cnt].addr_lo = |
| 15457 | putPaddrLow(dmabuf->phys); |
| 15458 | rq_create->u.request.page[cnt].addr_hi = |
| 15459 | putPaddrHigh(dmabuf->phys); |
| 15460 | rc++; |
| 15461 | } |
| 15462 | page_idx += rc; |
| 15463 | |
| 15464 | rc = 0; |
| 15465 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
| 15466 | memset(dmabuf->virt, 0, hw_page_size); |
| 15467 | cnt = page_idx + dmabuf->buffer_tag; |
| 15468 | rq_create->u.request.page[cnt].addr_lo = |
| 15469 | putPaddrLow(dmabuf->phys); |
| 15470 | rq_create->u.request.page[cnt].addr_hi = |
| 15471 | putPaddrHigh(dmabuf->phys); |
| 15472 | rc++; |
| 15473 | } |
| 15474 | page_idx += rc; |
| 15475 | |
| 15476 | hrq->db_format = LPFC_DB_RING_FORMAT; |
| 15477 | hrq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15478 | hrq->type = LPFC_HRQ; |
| 15479 | hrq->assoc_qid = cq->queue_id; |
| 15480 | hrq->subtype = subtype; |
| 15481 | hrq->host_index = 0; |
| 15482 | hrq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15483 | hrq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15484 | |
| 15485 | drq->db_format = LPFC_DB_RING_FORMAT; |
| 15486 | drq->db_regaddr = phba->sli4_hba.RQDBregaddr; |
| 15487 | drq->type = LPFC_DRQ; |
| 15488 | drq->assoc_qid = cq->queue_id; |
| 15489 | drq->subtype = subtype; |
| 15490 | drq->host_index = 0; |
| 15491 | drq->hba_index = 0; |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 15492 | drq->entry_repost = LPFC_RQ_REPOST; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 15493 | |
| 15494 | list_add_tail(&hrq->list, &cq->child_list); |
| 15495 | list_add_tail(&drq->list, &cq->child_list); |
| 15496 | } |
| 15497 | |
| 15498 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 15499 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15500 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15501 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15502 | if (shdr_status || shdr_add_status || rc) { |
| 15503 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15504 | "3120 RQ_CREATE mailbox failed with " |
| 15505 | "status x%x add_status x%x, mbx status x%x\n", |
| 15506 | shdr_status, shdr_add_status, rc); |
| 15507 | status = -ENXIO; |
| 15508 | goto out; |
| 15509 | } |
| 15510 | rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); |
| 15511 | if (rc == 0xFFFF) { |
| 15512 | status = -ENXIO; |
| 15513 | goto out; |
| 15514 | } |
| 15515 | |
| 15516 | /* Initialize all RQs with associated queue id */ |
| 15517 | for (idx = 0; idx < numrq; idx++) { |
| 15518 | hrq = hrqp[idx]; |
| 15519 | hrq->queue_id = rc + (2 * idx); |
| 15520 | drq = drqp[idx]; |
| 15521 | drq->queue_id = rc + (2 * idx) + 1; |
| 15522 | } |
| 15523 | |
| 15524 | out: |
| 15525 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 15526 | return status; |
| 15527 | } |
| 15528 | |
| 15529 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15530 | * lpfc_eq_destroy - Destroy an event Queue on the HBA |
| 15531 | * @eq: The queue structure associated with the queue to destroy. |
| 15532 | * |
| 15533 | * This function destroys a queue, as detailed in @eq by sending an mailbox |
| 15534 | * command, specific to the type of queue, to the HBA. |
| 15535 | * |
| 15536 | * The @eq struct is used to get the queue ID of the queue to destroy. |
| 15537 | * |
| 15538 | * 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] | 15539 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15540 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15541 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15542 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) |
| 15543 | { |
| 15544 | LPFC_MBOXQ_t *mbox; |
| 15545 | int rc, length, status = 0; |
| 15546 | uint32_t shdr_status, shdr_add_status; |
| 15547 | union lpfc_sli4_cfg_shdr *shdr; |
| 15548 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15549 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15550 | if (!eq) |
| 15551 | return -ENODEV; |
| 15552 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15553 | if (!mbox) |
| 15554 | return -ENOMEM; |
| 15555 | length = (sizeof(struct lpfc_mbx_eq_destroy) - |
| 15556 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15557 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15558 | LPFC_MBOX_OPCODE_EQ_DESTROY, |
| 15559 | length, LPFC_SLI4_MBX_EMBED); |
| 15560 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, |
| 15561 | eq->queue_id); |
| 15562 | mbox->vport = eq->phba->pport; |
| 15563 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15564 | |
| 15565 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); |
| 15566 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15567 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15568 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; |
| 15569 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15570 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15571 | if (shdr_status || shdr_add_status || rc) { |
| 15572 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15573 | "2505 EQ_DESTROY mailbox failed with " |
| 15574 | "status x%x add_status x%x, mbx status x%x\n", |
| 15575 | shdr_status, shdr_add_status, rc); |
| 15576 | status = -ENXIO; |
| 15577 | } |
| 15578 | |
| 15579 | /* Remove eq from any list */ |
| 15580 | list_del_init(&eq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15581 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15582 | return status; |
| 15583 | } |
| 15584 | |
| 15585 | /** |
| 15586 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA |
| 15587 | * @cq: The queue structure associated with the queue to destroy. |
| 15588 | * |
| 15589 | * This function destroys a queue, as detailed in @cq by sending an mailbox |
| 15590 | * command, specific to the type of queue, to the HBA. |
| 15591 | * |
| 15592 | * The @cq struct is used to get the queue ID of the queue to destroy. |
| 15593 | * |
| 15594 | * 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] | 15595 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15596 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15597 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15598 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) |
| 15599 | { |
| 15600 | LPFC_MBOXQ_t *mbox; |
| 15601 | int rc, length, status = 0; |
| 15602 | uint32_t shdr_status, shdr_add_status; |
| 15603 | union lpfc_sli4_cfg_shdr *shdr; |
| 15604 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15605 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15606 | if (!cq) |
| 15607 | return -ENODEV; |
| 15608 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15609 | if (!mbox) |
| 15610 | return -ENOMEM; |
| 15611 | length = (sizeof(struct lpfc_mbx_cq_destroy) - |
| 15612 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15613 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15614 | LPFC_MBOX_OPCODE_CQ_DESTROY, |
| 15615 | length, LPFC_SLI4_MBX_EMBED); |
| 15616 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, |
| 15617 | cq->queue_id); |
| 15618 | mbox->vport = cq->phba->pport; |
| 15619 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15620 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); |
| 15621 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15622 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15623 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; |
| 15624 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15625 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15626 | if (shdr_status || shdr_add_status || rc) { |
| 15627 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15628 | "2506 CQ_DESTROY mailbox failed with " |
| 15629 | "status x%x add_status x%x, mbx status x%x\n", |
| 15630 | shdr_status, shdr_add_status, rc); |
| 15631 | status = -ENXIO; |
| 15632 | } |
| 15633 | /* Remove cq from any list */ |
| 15634 | list_del_init(&cq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15635 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15636 | return status; |
| 15637 | } |
| 15638 | |
| 15639 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15640 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA |
| 15641 | * @qm: The queue structure associated with the queue to destroy. |
| 15642 | * |
| 15643 | * This function destroys a queue, as detailed in @mq by sending an mailbox |
| 15644 | * command, specific to the type of queue, to the HBA. |
| 15645 | * |
| 15646 | * The @mq struct is used to get the queue ID of the queue to destroy. |
| 15647 | * |
| 15648 | * 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] | 15649 | * command fails this function will return -ENXIO. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15650 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15651 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15652 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) |
| 15653 | { |
| 15654 | LPFC_MBOXQ_t *mbox; |
| 15655 | int rc, length, status = 0; |
| 15656 | uint32_t shdr_status, shdr_add_status; |
| 15657 | union lpfc_sli4_cfg_shdr *shdr; |
| 15658 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15659 | /* sanity check on queue memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15660 | if (!mq) |
| 15661 | return -ENODEV; |
| 15662 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15663 | if (!mbox) |
| 15664 | return -ENOMEM; |
| 15665 | length = (sizeof(struct lpfc_mbx_mq_destroy) - |
| 15666 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15667 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 15668 | LPFC_MBOX_OPCODE_MQ_DESTROY, |
| 15669 | length, LPFC_SLI4_MBX_EMBED); |
| 15670 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, |
| 15671 | mq->queue_id); |
| 15672 | mbox->vport = mq->phba->pport; |
| 15673 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15674 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); |
| 15675 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15676 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15677 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; |
| 15678 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15679 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15680 | if (shdr_status || shdr_add_status || rc) { |
| 15681 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15682 | "2507 MQ_DESTROY mailbox failed with " |
| 15683 | "status x%x add_status x%x, mbx status x%x\n", |
| 15684 | shdr_status, shdr_add_status, rc); |
| 15685 | status = -ENXIO; |
| 15686 | } |
| 15687 | /* Remove mq from any list */ |
| 15688 | list_del_init(&mq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15689 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 15690 | return status; |
| 15691 | } |
| 15692 | |
| 15693 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15694 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA |
| 15695 | * @wq: The queue structure associated with the queue to destroy. |
| 15696 | * |
| 15697 | * This function destroys a queue, as detailed in @wq by sending an mailbox |
| 15698 | * command, specific to the type of queue, to the HBA. |
| 15699 | * |
| 15700 | * The @wq struct is used to get the queue ID of the queue to destroy. |
| 15701 | * |
| 15702 | * 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] | 15703 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15704 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15705 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15706 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) |
| 15707 | { |
| 15708 | LPFC_MBOXQ_t *mbox; |
| 15709 | int rc, length, status = 0; |
| 15710 | uint32_t shdr_status, shdr_add_status; |
| 15711 | union lpfc_sli4_cfg_shdr *shdr; |
| 15712 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15713 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15714 | if (!wq) |
| 15715 | return -ENODEV; |
| 15716 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15717 | if (!mbox) |
| 15718 | return -ENOMEM; |
| 15719 | length = (sizeof(struct lpfc_mbx_wq_destroy) - |
| 15720 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 15721 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15722 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, |
| 15723 | length, LPFC_SLI4_MBX_EMBED); |
| 15724 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, |
| 15725 | wq->queue_id); |
| 15726 | mbox->vport = wq->phba->pport; |
| 15727 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15728 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); |
| 15729 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15730 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; |
| 15731 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15732 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15733 | if (shdr_status || shdr_add_status || rc) { |
| 15734 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15735 | "2508 WQ_DESTROY mailbox failed with " |
| 15736 | "status x%x add_status x%x, mbx status x%x\n", |
| 15737 | shdr_status, shdr_add_status, rc); |
| 15738 | status = -ENXIO; |
| 15739 | } |
| 15740 | /* Remove wq from any list */ |
| 15741 | list_del_init(&wq->list); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 15742 | kfree(wq->pring); |
| 15743 | wq->pring = NULL; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15744 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15745 | return status; |
| 15746 | } |
| 15747 | |
| 15748 | /** |
| 15749 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA |
| 15750 | * @rq: The queue structure associated with the queue to destroy. |
| 15751 | * |
| 15752 | * This function destroys a queue, as detailed in @rq by sending an mailbox |
| 15753 | * command, specific to the type of queue, to the HBA. |
| 15754 | * |
| 15755 | * The @rq struct is used to get the queue ID of the queue to destroy. |
| 15756 | * |
| 15757 | * 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] | 15758 | * command fails this function will return -ENXIO. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15759 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 15760 | int |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15761 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, |
| 15762 | struct lpfc_queue *drq) |
| 15763 | { |
| 15764 | LPFC_MBOXQ_t *mbox; |
| 15765 | int rc, length, status = 0; |
| 15766 | uint32_t shdr_status, shdr_add_status; |
| 15767 | union lpfc_sli4_cfg_shdr *shdr; |
| 15768 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 15769 | /* sanity check on queue memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15770 | if (!hrq || !drq) |
| 15771 | return -ENODEV; |
| 15772 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); |
| 15773 | if (!mbox) |
| 15774 | return -ENOMEM; |
| 15775 | length = (sizeof(struct lpfc_mbx_rq_destroy) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 15776 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15777 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15778 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, |
| 15779 | length, LPFC_SLI4_MBX_EMBED); |
| 15780 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 15781 | hrq->queue_id); |
| 15782 | mbox->vport = hrq->phba->pport; |
| 15783 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 15784 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); |
| 15785 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15786 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15787 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 15788 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15789 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15790 | if (shdr_status || shdr_add_status || rc) { |
| 15791 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15792 | "2509 RQ_DESTROY mailbox failed with " |
| 15793 | "status x%x add_status x%x, mbx status x%x\n", |
| 15794 | shdr_status, shdr_add_status, rc); |
| 15795 | if (rc != MBX_TIMEOUT) |
| 15796 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
| 15797 | return -ENXIO; |
| 15798 | } |
| 15799 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, |
| 15800 | drq->queue_id); |
| 15801 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); |
| 15802 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 15803 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; |
| 15804 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15805 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15806 | if (shdr_status || shdr_add_status || rc) { |
| 15807 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15808 | "2510 RQ_DESTROY mailbox failed with " |
| 15809 | "status x%x add_status x%x, mbx status x%x\n", |
| 15810 | shdr_status, shdr_add_status, rc); |
| 15811 | status = -ENXIO; |
| 15812 | } |
| 15813 | list_del_init(&hrq->list); |
| 15814 | list_del_init(&drq->list); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15815 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15816 | return status; |
| 15817 | } |
| 15818 | |
| 15819 | /** |
| 15820 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA |
| 15821 | * @phba: The virtual port for which this call being executed. |
| 15822 | * @pdma_phys_addr0: Physical address of the 1st SGL page. |
| 15823 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. |
| 15824 | * @xritag: the xritag that ties this io to the SGL pages. |
| 15825 | * |
| 15826 | * This routine will post the sgl pages for the IO that has the xritag |
| 15827 | * that is in the iocbq structure. The xritag is assigned during iocbq |
| 15828 | * creation and persists for as long as the driver is loaded. |
| 15829 | * if the caller has fewer than 256 scatter gather segments to map then |
| 15830 | * pdma_phys_addr1 should be 0. |
| 15831 | * If the caller needs to map more than 256 scatter gather segment then |
| 15832 | * pdma_phys_addr1 should be a valid physical address. |
| 15833 | * physical address for SGLs must be 64 byte aligned. |
| 15834 | * If you are going to map 2 SGL's then the first one must have 256 entries |
| 15835 | * the second sgl can have between 1 and 256 entries. |
| 15836 | * |
| 15837 | * Return codes: |
| 15838 | * 0 - Success |
| 15839 | * -ENXIO, -ENOMEM - Failure |
| 15840 | **/ |
| 15841 | int |
| 15842 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, |
| 15843 | dma_addr_t pdma_phys_addr0, |
| 15844 | dma_addr_t pdma_phys_addr1, |
| 15845 | uint16_t xritag) |
| 15846 | { |
| 15847 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; |
| 15848 | LPFC_MBOXQ_t *mbox; |
| 15849 | int rc; |
| 15850 | uint32_t shdr_status, shdr_add_status; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15851 | uint32_t mbox_tmo; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15852 | union lpfc_sli4_cfg_shdr *shdr; |
| 15853 | |
| 15854 | if (xritag == NO_XRI) { |
| 15855 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 15856 | "0364 Invalid param:\n"); |
| 15857 | return -EINVAL; |
| 15858 | } |
| 15859 | |
| 15860 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 15861 | if (!mbox) |
| 15862 | return -ENOMEM; |
| 15863 | |
| 15864 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 15865 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, |
| 15866 | sizeof(struct lpfc_mbx_post_sgl_pages) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 15867 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15868 | |
| 15869 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) |
| 15870 | &mbox->u.mqe.un.post_sgl_pages; |
| 15871 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); |
| 15872 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); |
| 15873 | |
| 15874 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = |
| 15875 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); |
| 15876 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = |
| 15877 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); |
| 15878 | |
| 15879 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = |
| 15880 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); |
| 15881 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = |
| 15882 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); |
| 15883 | if (!phba->sli4_hba.intr_enable) |
| 15884 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15885 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 15886 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15887 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 15888 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15889 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 15890 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; |
| 15891 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 15892 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 15893 | if (rc != MBX_TIMEOUT) |
| 15894 | mempool_free(mbox, phba->mbox_mem_pool); |
| 15895 | if (shdr_status || shdr_add_status || rc) { |
| 15896 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 15897 | "2511 POST_SGL mailbox failed with " |
| 15898 | "status x%x add_status x%x, mbx status x%x\n", |
| 15899 | shdr_status, shdr_add_status, rc); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15900 | } |
| 15901 | return 0; |
| 15902 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15903 | |
| 15904 | /** |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 15905 | * 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] | 15906 | * @phba: pointer to lpfc hba data structure. |
| 15907 | * |
| 15908 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 15909 | * HBA consistent with the SLI-4 interface spec. This routine |
| 15910 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 15911 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15912 | * |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 15913 | * Returns |
| 15914 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
| 15915 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 15916 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 15917 | static uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15918 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) |
| 15919 | { |
| 15920 | unsigned long xri; |
| 15921 | |
| 15922 | /* |
| 15923 | * Fetch the next logical xri. Because this index is logical, |
| 15924 | * the driver starts at 0 each time. |
| 15925 | */ |
| 15926 | spin_lock_irq(&phba->hbalock); |
| 15927 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, |
| 15928 | phba->sli4_hba.max_cfg_param.max_xri, 0); |
| 15929 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { |
| 15930 | spin_unlock_irq(&phba->hbalock); |
| 15931 | return NO_XRI; |
| 15932 | } else { |
| 15933 | set_bit(xri, phba->sli4_hba.xri_bmask); |
| 15934 | phba->sli4_hba.max_cfg_param.xri_used++; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15935 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15936 | spin_unlock_irq(&phba->hbalock); |
| 15937 | return xri; |
| 15938 | } |
| 15939 | |
| 15940 | /** |
| 15941 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 15942 | * @phba: pointer to lpfc hba data structure. |
| 15943 | * |
| 15944 | * This routine is invoked to release an xri to the pool of |
| 15945 | * available rpis maintained by the driver. |
| 15946 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 15947 | static void |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15948 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 15949 | { |
| 15950 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15951 | phba->sli4_hba.max_cfg_param.xri_used--; |
| 15952 | } |
| 15953 | } |
| 15954 | |
| 15955 | /** |
| 15956 | * lpfc_sli4_free_xri - Release an xri for reuse. |
| 15957 | * @phba: pointer to lpfc hba data structure. |
| 15958 | * |
| 15959 | * This routine is invoked to release an xri to the pool of |
| 15960 | * available rpis maintained by the driver. |
| 15961 | **/ |
| 15962 | void |
| 15963 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) |
| 15964 | { |
| 15965 | spin_lock_irq(&phba->hbalock); |
| 15966 | __lpfc_sli4_free_xri(phba, xri); |
| 15967 | spin_unlock_irq(&phba->hbalock); |
| 15968 | } |
| 15969 | |
| 15970 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15971 | * lpfc_sli4_next_xritag - Get an xritag for the io |
| 15972 | * @phba: Pointer to HBA context object. |
| 15973 | * |
| 15974 | * This function gets an xritag for the iocb. If there is no unused xritag |
| 15975 | * it will return 0xffff. |
| 15976 | * The function returns the allocated xritag if successful, else returns zero. |
| 15977 | * Zero is not a valid xritag. |
| 15978 | * The caller is not required to hold any lock. |
| 15979 | **/ |
| 15980 | uint16_t |
| 15981 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) |
| 15982 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15983 | uint16_t xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15984 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 15985 | xri_index = lpfc_sli4_alloc_xri(phba); |
James Smart | 8137805 | 2012-05-09 21:17:37 -0400 | [diff] [blame] | 15986 | if (xri_index == NO_XRI) |
| 15987 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 15988 | "2004 Failed to allocate XRI.last XRITAG is %d" |
| 15989 | " Max XRI is %d, Used XRI is %d\n", |
| 15990 | xri_index, |
| 15991 | phba->sli4_hba.max_cfg_param.max_xri, |
| 15992 | phba->sli4_hba.max_cfg_param.xri_used); |
| 15993 | return xri_index; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 15994 | } |
| 15995 | |
| 15996 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 15997 | * 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] | 15998 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 15999 | * @post_sgl_list: pointer to els sgl entry list. |
| 16000 | * @count: number of els sgl entries on the list. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16001 | * |
| 16002 | * This routine is invoked to post a block of driver's sgl pages to the |
| 16003 | * HBA using non-embedded mailbox command. No Lock is held. This routine |
| 16004 | * is only called when the driver is loading and after all IO has been |
| 16005 | * stopped. |
| 16006 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16007 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16008 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16009 | struct list_head *post_sgl_list, |
| 16010 | int post_cnt) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16011 | { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16012 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16013 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16014 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16015 | void *viraddr; |
| 16016 | LPFC_MBOXQ_t *mbox; |
| 16017 | uint32_t reqlen, alloclen, pg_pairs; |
| 16018 | uint32_t mbox_tmo; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16019 | uint16_t xritag_start = 0; |
| 16020 | int rc = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16021 | uint32_t shdr_status, shdr_add_status; |
| 16022 | union lpfc_sli4_cfg_shdr *shdr; |
| 16023 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16024 | reqlen = post_cnt * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16025 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16026 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16027 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16028 | "2559 Block sgl registration required DMA " |
| 16029 | "size (%d) great than a page\n", reqlen); |
| 16030 | return -ENOMEM; |
| 16031 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16032 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16033 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16034 | if (!mbox) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16035 | return -ENOMEM; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16036 | |
| 16037 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16038 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16039 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16040 | LPFC_SLI4_MBX_NEMBED); |
| 16041 | |
| 16042 | if (alloclen < reqlen) { |
| 16043 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16044 | "0285 Allocated DMA memory size (%d) is " |
| 16045 | "less than the requested DMA memory " |
| 16046 | "size (%d)\n", alloclen, reqlen); |
| 16047 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16048 | return -ENOMEM; |
| 16049 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16050 | /* Set up the SGL pages in the non-embedded DMA pages */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16051 | viraddr = mbox->sge_array->addr[0]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16052 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16053 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16054 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16055 | pg_pairs = 0; |
| 16056 | 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] | 16057 | /* Set up the sge entry */ |
| 16058 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16059 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); |
| 16060 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16061 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); |
| 16062 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16063 | cpu_to_le32(putPaddrLow(0)); |
| 16064 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16065 | cpu_to_le32(putPaddrHigh(0)); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16066 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16067 | /* Keep the first xritag on the list */ |
| 16068 | if (pg_pairs == 0) |
| 16069 | xritag_start = sglq_entry->sli4_xritag; |
| 16070 | sgl_pg_pairs++; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16071 | pg_pairs++; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16072 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16073 | |
| 16074 | /* Complete initialization and perform endian conversion. */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16075 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16076 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16077 | sgl->word0 = cpu_to_le32(sgl->word0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16078 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16079 | if (!phba->sli4_hba.intr_enable) |
| 16080 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16081 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16082 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16083 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16084 | } |
| 16085 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16086 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16087 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16088 | if (rc != MBX_TIMEOUT) |
| 16089 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16090 | if (shdr_status || shdr_add_status || rc) { |
| 16091 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16092 | "2513 POST_SGL_BLOCK mailbox command failed " |
| 16093 | "status x%x add_status x%x mbx status x%x\n", |
| 16094 | shdr_status, shdr_add_status, rc); |
| 16095 | rc = -ENXIO; |
| 16096 | } |
| 16097 | return rc; |
| 16098 | } |
| 16099 | |
| 16100 | /** |
| 16101 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware |
| 16102 | * @phba: pointer to lpfc hba data structure. |
| 16103 | * @sblist: pointer to scsi buffer list. |
| 16104 | * @count: number of scsi buffers on the list. |
| 16105 | * |
| 16106 | * This routine is invoked to post a block of @count scsi sgl pages from a |
| 16107 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. |
| 16108 | * No Lock is held. |
| 16109 | * |
| 16110 | **/ |
| 16111 | int |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16112 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
| 16113 | struct list_head *sblist, |
| 16114 | int count) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16115 | { |
| 16116 | struct lpfc_scsi_buf *psb; |
| 16117 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
| 16118 | struct sgl_page_pairs *sgl_pg_pairs; |
| 16119 | void *viraddr; |
| 16120 | LPFC_MBOXQ_t *mbox; |
| 16121 | uint32_t reqlen, alloclen, pg_pairs; |
| 16122 | uint32_t mbox_tmo; |
| 16123 | uint16_t xritag_start = 0; |
| 16124 | int rc = 0; |
| 16125 | uint32_t shdr_status, shdr_add_status; |
| 16126 | dma_addr_t pdma_phys_bpl1; |
| 16127 | union lpfc_sli4_cfg_shdr *shdr; |
| 16128 | |
| 16129 | /* Calculate the requested length of the dma memory */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 16130 | reqlen = count * sizeof(struct sgl_page_pairs) + |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16131 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 16132 | if (reqlen > SLI4_PAGE_SIZE) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16133 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 16134 | "0217 Block sgl registration required DMA " |
| 16135 | "size (%d) great than a page\n", reqlen); |
| 16136 | return -ENOMEM; |
| 16137 | } |
| 16138 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 16139 | if (!mbox) { |
| 16140 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16141 | "0283 Failed to allocate mbox cmd memory\n"); |
| 16142 | return -ENOMEM; |
| 16143 | } |
| 16144 | |
| 16145 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 16146 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 16147 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, |
| 16148 | LPFC_SLI4_MBX_NEMBED); |
| 16149 | |
| 16150 | if (alloclen < reqlen) { |
| 16151 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 16152 | "2561 Allocated DMA memory size (%d) is " |
| 16153 | "less than the requested DMA memory " |
| 16154 | "size (%d)\n", alloclen, reqlen); |
| 16155 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16156 | return -ENOMEM; |
| 16157 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16158 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16159 | /* Get the first SGE entry from the non-embedded DMA memory */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16160 | viraddr = mbox->sge_array->addr[0]; |
| 16161 | |
| 16162 | /* Set up the SGL pages in the non-embedded DMA pages */ |
| 16163 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
| 16164 | sgl_pg_pairs = &sgl->sgl_pg_pairs; |
| 16165 | |
| 16166 | pg_pairs = 0; |
| 16167 | list_for_each_entry(psb, sblist, list) { |
| 16168 | /* Set up the sge entry */ |
| 16169 | sgl_pg_pairs->sgl_pg0_addr_lo = |
| 16170 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); |
| 16171 | sgl_pg_pairs->sgl_pg0_addr_hi = |
| 16172 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); |
| 16173 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) |
| 16174 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; |
| 16175 | else |
| 16176 | pdma_phys_bpl1 = 0; |
| 16177 | sgl_pg_pairs->sgl_pg1_addr_lo = |
| 16178 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); |
| 16179 | sgl_pg_pairs->sgl_pg1_addr_hi = |
| 16180 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); |
| 16181 | /* Keep the first xritag on the list */ |
| 16182 | if (pg_pairs == 0) |
| 16183 | xritag_start = psb->cur_iocbq.sli4_xritag; |
| 16184 | sgl_pg_pairs++; |
| 16185 | pg_pairs++; |
| 16186 | } |
| 16187 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
| 16188 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); |
| 16189 | /* Perform endian conversion if necessary */ |
| 16190 | sgl->word0 = cpu_to_le32(sgl->word0); |
| 16191 | |
| 16192 | if (!phba->sli4_hba.intr_enable) |
| 16193 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 16194 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 16195 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16196 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 16197 | } |
| 16198 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; |
| 16199 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 16200 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 16201 | if (rc != MBX_TIMEOUT) |
| 16202 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 16203 | if (shdr_status || shdr_add_status || rc) { |
| 16204 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16205 | "2564 POST_SGL_BLOCK mailbox command failed " |
| 16206 | "status x%x add_status x%x mbx status x%x\n", |
| 16207 | shdr_status, shdr_add_status, rc); |
| 16208 | rc = -ENXIO; |
| 16209 | } |
| 16210 | return rc; |
| 16211 | } |
| 16212 | |
| 16213 | /** |
| 16214 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle |
| 16215 | * @phba: pointer to lpfc_hba struct that the frame was received on |
| 16216 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16217 | * |
| 16218 | * This function checks the fields in the @fc_hdr to see if the FC frame is a |
| 16219 | * valid type of frame that the LPFC driver will handle. This function will |
| 16220 | * return a zero if the frame is a valid frame or a non zero value when the |
| 16221 | * frame does not pass the check. |
| 16222 | **/ |
| 16223 | static int |
| 16224 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) |
| 16225 | { |
Tomas Henzl | 474ffb7 | 2010-12-22 16:52:40 +0100 | [diff] [blame] | 16226 | /* make rctl_names static to save stack space */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16227 | struct fc_vft_header *fc_vft_hdr; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16228 | uint32_t *header = (uint32_t *) fc_hdr; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16229 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16230 | #define FC_RCTL_MDS_DIAGS 0xF4 |
| 16231 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16232 | switch (fc_hdr->fh_r_ctl) { |
| 16233 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ |
| 16234 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ |
| 16235 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ |
| 16236 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ |
| 16237 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ |
| 16238 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ |
| 16239 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ |
| 16240 | case FC_RCTL_DD_CMD_STATUS: /* command status */ |
| 16241 | case FC_RCTL_ELS_REQ: /* extended link services request */ |
| 16242 | case FC_RCTL_ELS_REP: /* extended link services reply */ |
| 16243 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ |
| 16244 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ |
| 16245 | case FC_RCTL_BA_NOP: /* basic link service NOP */ |
| 16246 | case FC_RCTL_BA_ABTS: /* basic link service abort */ |
| 16247 | case FC_RCTL_BA_RMC: /* remove connection */ |
| 16248 | case FC_RCTL_BA_ACC: /* basic accept */ |
| 16249 | case FC_RCTL_BA_RJT: /* basic reject */ |
| 16250 | case FC_RCTL_BA_PRMT: |
| 16251 | case FC_RCTL_ACK_1: /* acknowledge_1 */ |
| 16252 | case FC_RCTL_ACK_0: /* acknowledge_0 */ |
| 16253 | case FC_RCTL_P_RJT: /* port reject */ |
| 16254 | case FC_RCTL_F_RJT: /* fabric reject */ |
| 16255 | case FC_RCTL_P_BSY: /* port busy */ |
| 16256 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ |
| 16257 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ |
| 16258 | case FC_RCTL_LCR: /* link credit reset */ |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16259 | case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */ |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16260 | case FC_RCTL_END: /* end */ |
| 16261 | break; |
| 16262 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ |
| 16263 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16264 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; |
| 16265 | return lpfc_fc_frame_check(phba, fc_hdr); |
| 16266 | default: |
| 16267 | goto drop; |
| 16268 | } |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16269 | |
| 16270 | #define FC_TYPE_VENDOR_UNIQUE 0xFF |
| 16271 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16272 | switch (fc_hdr->fh_type) { |
| 16273 | case FC_TYPE_BLS: |
| 16274 | case FC_TYPE_ELS: |
| 16275 | case FC_TYPE_FCP: |
| 16276 | case FC_TYPE_CT: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16277 | case FC_TYPE_NVME: |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 16278 | case FC_TYPE_VENDOR_UNIQUE: |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16279 | break; |
| 16280 | case FC_TYPE_IP: |
| 16281 | case FC_TYPE_ILS: |
| 16282 | default: |
| 16283 | goto drop; |
| 16284 | } |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16285 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16286 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16287 | "2538 Received frame rctl:x%x, type:x%x, " |
James Smart | 88f43a0 | 2013-04-17 20:19:44 -0400 | [diff] [blame] | 16288 | "frame Data:%08x %08x %08x %08x %08x %08x %08x\n", |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16289 | fc_hdr->fh_r_ctl, fc_hdr->fh_type, |
| 16290 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), |
| 16291 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), |
| 16292 | be32_to_cpu(header[4]), be32_to_cpu(header[5]), |
| 16293 | be32_to_cpu(header[6])); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16294 | return 0; |
| 16295 | drop: |
| 16296 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
James Smart | 78e1d20 | 2017-06-01 21:07:09 -0700 | [diff] [blame] | 16297 | "2539 Dropped frame rctl:x%x type:x%x\n", |
| 16298 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16299 | return 1; |
| 16300 | } |
| 16301 | |
| 16302 | /** |
| 16303 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame |
| 16304 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16305 | * |
| 16306 | * This function processes the FC header to retrieve the VFI from the VF |
| 16307 | * header, if one exists. This function will return the VFI if one exists |
| 16308 | * or 0 if no VSAN Header exists. |
| 16309 | **/ |
| 16310 | static uint32_t |
| 16311 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) |
| 16312 | { |
| 16313 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; |
| 16314 | |
| 16315 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) |
| 16316 | return 0; |
| 16317 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); |
| 16318 | } |
| 16319 | |
| 16320 | /** |
| 16321 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to |
| 16322 | * @phba: Pointer to the HBA structure to search for the vport on |
| 16323 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) |
| 16324 | * @fcfi: The FC Fabric ID that the frame came from |
| 16325 | * |
| 16326 | * This function searches the @phba for a vport that matches the content of the |
| 16327 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the |
| 16328 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function |
| 16329 | * returns the matching vport pointer or NULL if unable to match frame to a |
| 16330 | * vport. |
| 16331 | **/ |
| 16332 | static struct lpfc_vport * |
| 16333 | 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] | 16334 | uint16_t fcfi, uint32_t did) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16335 | { |
| 16336 | struct lpfc_vport **vports; |
| 16337 | struct lpfc_vport *vport = NULL; |
| 16338 | int i; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16339 | |
James Smart | bf08611 | 2011-08-21 21:48:13 -0400 | [diff] [blame] | 16340 | if (did == Fabric_DID) |
| 16341 | return phba->pport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16342 | if ((phba->pport->fc_flag & FC_PT2PT) && |
| 16343 | !(phba->link_state == LPFC_HBA_READY)) |
| 16344 | return phba->pport; |
| 16345 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16346 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16347 | if (vports != NULL) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16348 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 16349 | if (phba->fcf.fcfi == fcfi && |
| 16350 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && |
| 16351 | vports[i]->fc_myDID == did) { |
| 16352 | vport = vports[i]; |
| 16353 | break; |
| 16354 | } |
| 16355 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16356 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16357 | lpfc_destroy_vport_work_array(phba, vports); |
| 16358 | return vport; |
| 16359 | } |
| 16360 | |
| 16361 | /** |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16362 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp |
| 16363 | * @vport: The vport to work on. |
| 16364 | * |
| 16365 | * This function updates the receive sequence time stamp for this vport. The |
| 16366 | * receive sequence time stamp indicates the time that the last frame of the |
| 16367 | * the sequence that has been idle for the longest amount of time was received. |
| 16368 | * the driver uses this time stamp to indicate if any received sequences have |
| 16369 | * timed out. |
| 16370 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16371 | static void |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16372 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) |
| 16373 | { |
| 16374 | struct lpfc_dmabuf *h_buf; |
| 16375 | struct hbq_dmabuf *dmabuf = NULL; |
| 16376 | |
| 16377 | /* get the oldest sequence on the rcv list */ |
| 16378 | h_buf = list_get_first(&vport->rcv_buffer_list, |
| 16379 | struct lpfc_dmabuf, list); |
| 16380 | if (!h_buf) |
| 16381 | return; |
| 16382 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16383 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; |
| 16384 | } |
| 16385 | |
| 16386 | /** |
| 16387 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. |
| 16388 | * @vport: The vport that the received sequences were sent to. |
| 16389 | * |
| 16390 | * This function cleans up all outstanding received sequences. This is called |
| 16391 | * by the driver when a link event or user action invalidates all the received |
| 16392 | * sequences. |
| 16393 | **/ |
| 16394 | void |
| 16395 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) |
| 16396 | { |
| 16397 | struct lpfc_dmabuf *h_buf, *hnext; |
| 16398 | struct lpfc_dmabuf *d_buf, *dnext; |
| 16399 | struct hbq_dmabuf *dmabuf = NULL; |
| 16400 | |
| 16401 | /* start with the oldest sequence on the rcv list */ |
| 16402 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 16403 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16404 | list_del_init(&dmabuf->hbuf.list); |
| 16405 | list_for_each_entry_safe(d_buf, dnext, |
| 16406 | &dmabuf->dbuf.list, list) { |
| 16407 | list_del_init(&d_buf->list); |
| 16408 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16409 | } |
| 16410 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 16411 | } |
| 16412 | } |
| 16413 | |
| 16414 | /** |
| 16415 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. |
| 16416 | * @vport: The vport that the received sequences were sent to. |
| 16417 | * |
| 16418 | * This function determines whether any received sequences have timed out by |
| 16419 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp |
| 16420 | * indicates that there is at least one timed out sequence this routine will |
| 16421 | * go through the received sequences one at a time from most inactive to most |
| 16422 | * active to determine which ones need to be cleaned up. Once it has determined |
| 16423 | * that a sequence needs to be cleaned up it will simply free up the resources |
| 16424 | * without sending an abort. |
| 16425 | **/ |
| 16426 | void |
| 16427 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) |
| 16428 | { |
| 16429 | struct lpfc_dmabuf *h_buf, *hnext; |
| 16430 | struct lpfc_dmabuf *d_buf, *dnext; |
| 16431 | struct hbq_dmabuf *dmabuf = NULL; |
| 16432 | unsigned long timeout; |
| 16433 | int abort_count = 0; |
| 16434 | |
| 16435 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 16436 | vport->rcv_buffer_time_stamp); |
| 16437 | if (list_empty(&vport->rcv_buffer_list) || |
| 16438 | time_before(jiffies, timeout)) |
| 16439 | return; |
| 16440 | /* start with the oldest sequence on the rcv list */ |
| 16441 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { |
| 16442 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16443 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + |
| 16444 | dmabuf->time_stamp); |
| 16445 | if (time_before(jiffies, timeout)) |
| 16446 | break; |
| 16447 | abort_count++; |
| 16448 | list_del_init(&dmabuf->hbuf.list); |
| 16449 | list_for_each_entry_safe(d_buf, dnext, |
| 16450 | &dmabuf->dbuf.list, list) { |
| 16451 | list_del_init(&d_buf->list); |
| 16452 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16453 | } |
| 16454 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); |
| 16455 | } |
| 16456 | if (abort_count) |
| 16457 | lpfc_update_rcv_time_stamp(vport); |
| 16458 | } |
| 16459 | |
| 16460 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16461 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences |
| 16462 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame |
| 16463 | * |
| 16464 | * This function searches through the existing incomplete sequences that have |
| 16465 | * been sent to this @vport. If the frame matches one of the incomplete |
| 16466 | * sequences then the dbuf in the @dmabuf is added to the list of frames that |
| 16467 | * make up that sequence. If no sequence is found that matches this frame then |
| 16468 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list |
| 16469 | * This function returns a pointer to the first dmabuf in the sequence list that |
| 16470 | * the frame was linked to. |
| 16471 | **/ |
| 16472 | static struct hbq_dmabuf * |
| 16473 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 16474 | { |
| 16475 | struct fc_frame_header *new_hdr; |
| 16476 | struct fc_frame_header *temp_hdr; |
| 16477 | struct lpfc_dmabuf *d_buf; |
| 16478 | struct lpfc_dmabuf *h_buf; |
| 16479 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 16480 | struct hbq_dmabuf *temp_dmabuf = NULL; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16481 | uint8_t found = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16482 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16483 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16484 | dmabuf->time_stamp = jiffies; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16485 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16486 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16487 | /* Use the hdr_buf to find the sequence that this frame belongs to */ |
| 16488 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 16489 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 16490 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 16491 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 16492 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 16493 | continue; |
| 16494 | /* found a pending sequence that matches this frame */ |
| 16495 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16496 | break; |
| 16497 | } |
| 16498 | if (!seq_dmabuf) { |
| 16499 | /* |
| 16500 | * This indicates first frame received for this sequence. |
| 16501 | * Queue the buffer on the vport's rcv_buffer_list. |
| 16502 | */ |
| 16503 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16504 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16505 | return dmabuf; |
| 16506 | } |
| 16507 | temp_hdr = seq_dmabuf->hbuf.virt; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16508 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
| 16509 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 16510 | list_del_init(&seq_dmabuf->hbuf.list); |
| 16511 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 16512 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16513 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16514 | return dmabuf; |
| 16515 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16516 | /* move this sequence to the tail to indicate a young sequence */ |
| 16517 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); |
| 16518 | seq_dmabuf->time_stamp = jiffies; |
| 16519 | lpfc_update_rcv_time_stamp(vport); |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16520 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
| 16521 | temp_hdr = dmabuf->hbuf.virt; |
| 16522 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); |
| 16523 | return seq_dmabuf; |
| 16524 | } |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16525 | /* find the correct place in the sequence to insert this frame */ |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16526 | d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list); |
| 16527 | while (!found) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16528 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 16529 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; |
| 16530 | /* |
| 16531 | * If the frame's sequence count is greater than the frame on |
| 16532 | * the list then insert the frame right after this frame |
| 16533 | */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16534 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
| 16535 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16536 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16537 | found = 1; |
| 16538 | break; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16539 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16540 | |
| 16541 | if (&d_buf->list == &seq_dmabuf->dbuf.list) |
| 16542 | break; |
| 16543 | d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16544 | } |
James Smart | 4360ca9 | 2015-12-16 18:12:04 -0500 | [diff] [blame] | 16545 | |
| 16546 | if (found) |
| 16547 | return seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16548 | return NULL; |
| 16549 | } |
| 16550 | |
| 16551 | /** |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16552 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence |
| 16553 | * @vport: pointer to a vitural port |
| 16554 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16555 | * |
| 16556 | * This function tries to abort from the partially assembed sequence, described |
| 16557 | * by the information from basic abbort @dmabuf. It checks to see whether such |
| 16558 | * partially assembled sequence held by the driver. If so, it shall free up all |
| 16559 | * the frames from the partially assembled sequence. |
| 16560 | * |
| 16561 | * Return |
| 16562 | * true -- if there is matching partially assembled sequence present and all |
| 16563 | * the frames freed with the sequence; |
| 16564 | * false -- if there is no matching partially assembled sequence present so |
| 16565 | * nothing got aborted in the lower layer driver |
| 16566 | **/ |
| 16567 | static bool |
| 16568 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, |
| 16569 | struct hbq_dmabuf *dmabuf) |
| 16570 | { |
| 16571 | struct fc_frame_header *new_hdr; |
| 16572 | struct fc_frame_header *temp_hdr; |
| 16573 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; |
| 16574 | struct hbq_dmabuf *seq_dmabuf = NULL; |
| 16575 | |
| 16576 | /* Use the hdr_buf to find the sequence that matches this frame */ |
| 16577 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
| 16578 | INIT_LIST_HEAD(&dmabuf->hbuf.list); |
| 16579 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 16580 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { |
| 16581 | temp_hdr = (struct fc_frame_header *)h_buf->virt; |
| 16582 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || |
| 16583 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || |
| 16584 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) |
| 16585 | continue; |
| 16586 | /* found a pending sequence that matches this frame */ |
| 16587 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); |
| 16588 | break; |
| 16589 | } |
| 16590 | |
| 16591 | /* Free up all the frames from the partially assembled sequence */ |
| 16592 | if (seq_dmabuf) { |
| 16593 | list_for_each_entry_safe(d_buf, n_buf, |
| 16594 | &seq_dmabuf->dbuf.list, list) { |
| 16595 | list_del_init(&d_buf->list); |
| 16596 | lpfc_in_buf_free(vport->phba, d_buf); |
| 16597 | } |
| 16598 | return true; |
| 16599 | } |
| 16600 | return false; |
| 16601 | } |
| 16602 | |
| 16603 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16604 | * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp |
| 16605 | * @vport: pointer to a vitural port |
| 16606 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16607 | * |
| 16608 | * This function tries to abort from the assembed sequence from upper level |
| 16609 | * protocol, described by the information from basic abbort @dmabuf. It |
| 16610 | * checks to see whether such pending context exists at upper level protocol. |
| 16611 | * If so, it shall clean up the pending context. |
| 16612 | * |
| 16613 | * Return |
| 16614 | * true -- if there is matching pending context of the sequence cleaned |
| 16615 | * at ulp; |
| 16616 | * false -- if there is no matching pending context of the sequence present |
| 16617 | * at ulp. |
| 16618 | **/ |
| 16619 | static bool |
| 16620 | lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) |
| 16621 | { |
| 16622 | struct lpfc_hba *phba = vport->phba; |
| 16623 | int handled; |
| 16624 | |
| 16625 | /* Accepting abort at ulp with SLI4 only */ |
| 16626 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 16627 | return false; |
| 16628 | |
| 16629 | /* Register all caring upper level protocols to attend abort */ |
| 16630 | handled = lpfc_ct_handle_unsol_abort(phba, dmabuf); |
| 16631 | if (handled) |
| 16632 | return true; |
| 16633 | |
| 16634 | return false; |
| 16635 | } |
| 16636 | |
| 16637 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16638 | * 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] | 16639 | * @phba: Pointer to HBA context object. |
| 16640 | * @cmd_iocbq: pointer to the command iocbq structure. |
| 16641 | * @rsp_iocbq: pointer to the response iocbq structure. |
| 16642 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16643 | * This function handles the sequence abort response iocb command complete |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16644 | * event. It properly releases the memory allocated to the sequence abort |
| 16645 | * accept iocb. |
| 16646 | **/ |
| 16647 | static void |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16648 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16649 | struct lpfc_iocbq *cmd_iocbq, |
| 16650 | struct lpfc_iocbq *rsp_iocbq) |
| 16651 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16652 | struct lpfc_nodelist *ndlp; |
| 16653 | |
| 16654 | if (cmd_iocbq) { |
| 16655 | ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1; |
| 16656 | lpfc_nlp_put(ndlp); |
| 16657 | lpfc_nlp_not_used(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16658 | lpfc_sli_release_iocbq(phba, cmd_iocbq); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16659 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 16660 | |
| 16661 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ |
| 16662 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) |
| 16663 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 16664 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", |
| 16665 | rsp_iocbq->iocb.ulpStatus, |
| 16666 | rsp_iocbq->iocb.un.ulpWord[4]); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16667 | } |
| 16668 | |
| 16669 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16670 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. |
| 16671 | * @phba: Pointer to HBA context object. |
| 16672 | * @xri: xri id in transaction. |
| 16673 | * |
| 16674 | * This function validates the xri maps to the known range of XRIs allocated an |
| 16675 | * used by the driver. |
| 16676 | **/ |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16677 | uint16_t |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16678 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
| 16679 | uint16_t xri) |
| 16680 | { |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 16681 | uint16_t i; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16682 | |
| 16683 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { |
| 16684 | if (xri == phba->sli4_hba.xri_ids[i]) |
| 16685 | return i; |
| 16686 | } |
| 16687 | return NO_XRI; |
| 16688 | } |
| 16689 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16690 | /** |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16691 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16692 | * @phba: Pointer to HBA context object. |
| 16693 | * @fc_hdr: pointer to a FC frame header. |
| 16694 | * |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16695 | * This function sends a basic response to a previous unsol sequence abort |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16696 | * event after aborting the sequence handling. |
| 16697 | **/ |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 16698 | void |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16699 | lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport, |
| 16700 | struct fc_frame_header *fc_hdr, bool aborted) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16701 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16702 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16703 | struct lpfc_iocbq *ctiocb = NULL; |
| 16704 | struct lpfc_nodelist *ndlp; |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 16705 | uint16_t oxid, rxid, xri, lxri; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16706 | uint32_t sid, fctl; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16707 | IOCB_t *icmd; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16708 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16709 | |
| 16710 | if (!lpfc_is_link_up(phba)) |
| 16711 | return; |
| 16712 | |
| 16713 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
| 16714 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16715 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16716 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16717 | ndlp = lpfc_findnode_did(vport, sid); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16718 | if (!ndlp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 16719 | ndlp = lpfc_nlp_init(vport, sid); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16720 | if (!ndlp) { |
| 16721 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 16722 | "1268 Failed to allocate ndlp for " |
| 16723 | "oxid:x%x SID:x%x\n", oxid, sid); |
| 16724 | return; |
| 16725 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16726 | /* Put ndlp onto pport node list */ |
| 16727 | lpfc_enqueue_node(vport, ndlp); |
| 16728 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 16729 | /* re-setup ndlp without removing from node list */ |
| 16730 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 16731 | if (!ndlp) { |
| 16732 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, |
| 16733 | "3275 Failed to active ndlp found " |
| 16734 | "for oxid:x%x SID:x%x\n", oxid, sid); |
| 16735 | return; |
| 16736 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16737 | } |
| 16738 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16739 | /* Allocate buffer for rsp iocb */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16740 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 16741 | if (!ctiocb) |
| 16742 | return; |
| 16743 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16744 | /* Extract the F_CTL field from FC_HDR */ |
| 16745 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); |
| 16746 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16747 | icmd = &ctiocb->iocb; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16748 | icmd->un.xseq64.bdl.bdeSize = 0; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16749 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16750 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 16751 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; |
| 16752 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; |
| 16753 | |
| 16754 | /* Fill in the rest of iocb fields */ |
| 16755 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; |
| 16756 | icmd->ulpBdeCount = 0; |
| 16757 | icmd->ulpLe = 1; |
| 16758 | icmd->ulpClass = CLASS3; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16759 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16760 | ctiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16761 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16762 | ctiocb->iocb_cmpl = NULL; |
| 16763 | ctiocb->vport = phba->pport; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16764 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 16765 | ctiocb->sli4_lxritag = NO_XRI; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16766 | ctiocb->sli4_xritag = NO_XRI; |
| 16767 | |
James Smart | ee0f4fe | 2012-05-09 21:19:14 -0400 | [diff] [blame] | 16768 | if (fctl & FC_FC_EX_CTX) |
| 16769 | /* Exchange responder sent the abort so we |
| 16770 | * own the oxid. |
| 16771 | */ |
| 16772 | xri = oxid; |
| 16773 | else |
| 16774 | xri = rxid; |
| 16775 | lxri = lpfc_sli4_xri_inrange(phba, xri); |
| 16776 | if (lxri != NO_XRI) |
| 16777 | lpfc_set_rrq_active(phba, ndlp, lxri, |
| 16778 | (xri == oxid) ? rxid : oxid, 0); |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16779 | /* For BA_ABTS from exchange responder, if the logical xri with |
| 16780 | * the oxid maps to the FCP XRI range, the port no longer has |
| 16781 | * that exchange context, send a BLS_RJT. Override the IOCB for |
| 16782 | * a BA_RJT. |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16783 | */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16784 | if ((fctl & FC_FC_EX_CTX) && |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16785 | (lxri > lpfc_sli4_get_iocb_cnt(phba))) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16786 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 16787 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 16788 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 16789 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 16790 | } |
| 16791 | |
| 16792 | /* If BA_ABTS failed to abort a partially assembled receive sequence, |
| 16793 | * the driver no longer has that exchange, send a BLS_RJT. Override |
| 16794 | * the IOCB for a BA_RJT. |
| 16795 | */ |
| 16796 | if (aborted == false) { |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16797 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; |
| 16798 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); |
| 16799 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); |
| 16800 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); |
| 16801 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16802 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16803 | if (fctl & FC_FC_EX_CTX) { |
| 16804 | /* ABTS sent by responder to CT exchange, construction |
| 16805 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG |
| 16806 | * field and RX_ID from ABTS for RX_ID field. |
| 16807 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16808 | 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] | 16809 | } else { |
| 16810 | /* ABTS sent by initiator to CT exchange, construction |
| 16811 | * 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] | 16812 | * XRI_TAG field. |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16813 | */ |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16814 | 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] | 16815 | } |
James Smart | f09c3ac | 2012-03-01 22:33:29 -0500 | [diff] [blame] | 16816 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16817 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16818 | |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16819 | /* Xmit CT abts response on exchange <xid> */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16820 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 16821 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
| 16822 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16823 | |
| 16824 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 16825 | if (rc == IOCB_ERROR) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16826 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 16827 | "2925 Failed to issue CT ABTS RSP x%x on " |
| 16828 | "xri x%x, Data x%x\n", |
| 16829 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, |
| 16830 | phba->link_state); |
| 16831 | lpfc_nlp_put(ndlp); |
| 16832 | ctiocb->context1 = NULL; |
James Smart | 546fc85 | 2011-03-11 16:06:29 -0500 | [diff] [blame] | 16833 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 16834 | } |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16835 | } |
| 16836 | |
| 16837 | /** |
| 16838 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event |
| 16839 | * @vport: Pointer to the vport on which this sequence was received |
| 16840 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16841 | * |
| 16842 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited |
| 16843 | * receive sequence is only partially assembed by the driver, it shall abort |
| 16844 | * the partially assembled frames for the sequence. Otherwise, if the |
| 16845 | * unsolicited receive sequence has been completely assembled and passed to |
| 16846 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the |
| 16847 | * unsolicited sequence has been aborted. After that, it will issue a basic |
| 16848 | * accept to accept the abort. |
| 16849 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 16850 | static void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16851 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, |
| 16852 | struct hbq_dmabuf *dmabuf) |
| 16853 | { |
| 16854 | struct lpfc_hba *phba = vport->phba; |
| 16855 | struct fc_frame_header fc_hdr; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16856 | uint32_t fctl; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16857 | bool aborted; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16858 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16859 | /* Make a copy of fc_hdr before the dmabuf being released */ |
| 16860 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16861 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16862 | |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16863 | if (fctl & FC_FC_EX_CTX) { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16864 | /* ABTS by responder to exchange, no cleanup needed */ |
| 16865 | aborted = true; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16866 | } else { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16867 | /* ABTS by initiator to exchange, need to do cleanup */ |
| 16868 | aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf); |
| 16869 | if (aborted == false) |
| 16870 | aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 16871 | } |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16872 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 16873 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 16874 | if (phba->nvmet_support) { |
| 16875 | lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr); |
| 16876 | return; |
| 16877 | } |
| 16878 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 16879 | /* Respond with BA_ACC or BA_RJT accordingly */ |
| 16880 | lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16881 | } |
| 16882 | |
| 16883 | /** |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16884 | * lpfc_seq_complete - Indicates if a sequence is complete |
| 16885 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16886 | * |
| 16887 | * This function checks the sequence, starting with the frame described by |
| 16888 | * @dmabuf, to see if all the frames associated with this sequence are present. |
| 16889 | * the frames associated with this sequence are linked to the @dmabuf using the |
| 16890 | * dbuf list. This function looks for two major things. 1) That the first frame |
| 16891 | * has a sequence count of zero. 2) There is a frame with last frame of sequence |
| 16892 | * set. 3) That there are no holes in the sequence count. The function will |
| 16893 | * return 1 when the sequence is complete, otherwise it will return 0. |
| 16894 | **/ |
| 16895 | static int |
| 16896 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) |
| 16897 | { |
| 16898 | struct fc_frame_header *hdr; |
| 16899 | struct lpfc_dmabuf *d_buf; |
| 16900 | struct hbq_dmabuf *seq_dmabuf; |
| 16901 | uint32_t fctl; |
| 16902 | int seq_count = 0; |
| 16903 | |
| 16904 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 16905 | /* make sure first fame of sequence has a sequence count of zero */ |
| 16906 | if (hdr->fh_seq_cnt != seq_count) |
| 16907 | return 0; |
| 16908 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 16909 | hdr->fh_f_ctl[1] << 8 | |
| 16910 | hdr->fh_f_ctl[2]); |
| 16911 | /* If last frame of sequence we can return success. */ |
| 16912 | if (fctl & FC_FC_END_SEQ) |
| 16913 | return 1; |
| 16914 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { |
| 16915 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 16916 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 16917 | /* If there is a hole in the sequence count then fail. */ |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16918 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16919 | return 0; |
| 16920 | fctl = (hdr->fh_f_ctl[0] << 16 | |
| 16921 | hdr->fh_f_ctl[1] << 8 | |
| 16922 | hdr->fh_f_ctl[2]); |
| 16923 | /* If last frame of sequence we can return success. */ |
| 16924 | if (fctl & FC_FC_END_SEQ) |
| 16925 | return 1; |
| 16926 | } |
| 16927 | return 0; |
| 16928 | } |
| 16929 | |
| 16930 | /** |
| 16931 | * lpfc_prep_seq - Prep sequence for ULP processing |
| 16932 | * @vport: Pointer to the vport on which this sequence was received |
| 16933 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 16934 | * |
| 16935 | * This function takes a sequence, described by a list of frames, and creates |
| 16936 | * a list of iocbq structures to describe the sequence. This iocbq list will be |
| 16937 | * used to issue to the generic unsolicited sequence handler. This routine |
| 16938 | * returns a pointer to the first iocbq in the list. If the function is unable |
| 16939 | * to allocate an iocbq then it throw out the received frames that were not |
| 16940 | * able to be described and return a pointer to the first iocbq. If unable to |
| 16941 | * allocate any iocbqs (including the first) this function will return NULL. |
| 16942 | **/ |
| 16943 | static struct lpfc_iocbq * |
| 16944 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) |
| 16945 | { |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16946 | struct hbq_dmabuf *hbq_buf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16947 | struct lpfc_dmabuf *d_buf, *n_buf; |
| 16948 | struct lpfc_iocbq *first_iocbq, *iocbq; |
| 16949 | struct fc_frame_header *fc_hdr; |
| 16950 | uint32_t sid; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16951 | uint32_t len, tot_len; |
James Smart | eeead81 | 2009-12-21 17:01:23 -0500 | [diff] [blame] | 16952 | struct ulp_bde64 *pbde; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16953 | |
| 16954 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 16955 | /* remove from receive buffer list */ |
| 16956 | list_del_init(&seq_dmabuf->hbuf.list); |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 16957 | lpfc_update_rcv_time_stamp(vport); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16958 | /* get the Remote Port's SID */ |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 16959 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16960 | tot_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16961 | /* Get an iocbq struct to fill in. */ |
| 16962 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 16963 | if (first_iocbq) { |
| 16964 | /* Initialize the first IOCB. */ |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 16965 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16966 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 16967 | first_iocbq->vport = vport; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 16968 | |
| 16969 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ |
| 16970 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { |
| 16971 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; |
| 16972 | first_iocbq->iocb.un.rcvels.parmRo = |
| 16973 | sli4_did_from_fc_hdr(fc_hdr); |
| 16974 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; |
| 16975 | } else |
| 16976 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16977 | first_iocbq->iocb.ulpContext = NO_XRI; |
| 16978 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = |
| 16979 | be16_to_cpu(fc_hdr->fh_ox_id); |
| 16980 | /* iocbq is prepped for internal consumption. Physical vpi. */ |
| 16981 | first_iocbq->iocb.unsli3.rcvsli3.vpi = |
| 16982 | vport->phba->vpi_ids[vport->vpi]; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16983 | /* put the first buffer into the first IOCBq */ |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 16984 | tot_len = bf_get(lpfc_rcqe_length, |
| 16985 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
| 16986 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16987 | first_iocbq->context2 = &seq_dmabuf->dbuf; |
| 16988 | first_iocbq->context3 = NULL; |
| 16989 | first_iocbq->iocb.ulpBdeCount = 1; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 16990 | if (tot_len > LPFC_DATA_BUF_SIZE) |
| 16991 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16992 | LPFC_DATA_BUF_SIZE; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 16993 | else |
| 16994 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len; |
| 16995 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16996 | first_iocbq->iocb.un.rcvels.remoteID = sid; |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 16997 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 16998 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 16999 | } |
| 17000 | iocbq = first_iocbq; |
| 17001 | /* |
| 17002 | * Each IOCBq can have two Buffers assigned, so go through the list |
| 17003 | * of buffers for this sequence and save two buffers in each IOCBq |
| 17004 | */ |
| 17005 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { |
| 17006 | if (!iocbq) { |
| 17007 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17008 | continue; |
| 17009 | } |
| 17010 | if (!iocbq->context3) { |
| 17011 | iocbq->context3 = d_buf; |
| 17012 | iocbq->iocb.ulpBdeCount++; |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17013 | /* We need to get the size out of the right CQE */ |
| 17014 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17015 | len = bf_get(lpfc_rcqe_length, |
| 17016 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17017 | pbde = (struct ulp_bde64 *) |
| 17018 | &iocbq->iocb.unsli3.sli3Words[4]; |
| 17019 | if (len > LPFC_DATA_BUF_SIZE) |
| 17020 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; |
| 17021 | else |
| 17022 | pbde->tus.f.bdeSize = len; |
| 17023 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17024 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; |
| 17025 | tot_len += len; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17026 | } else { |
| 17027 | iocbq = lpfc_sli_get_iocbq(vport->phba); |
| 17028 | if (!iocbq) { |
| 17029 | if (first_iocbq) { |
| 17030 | first_iocbq->iocb.ulpStatus = |
| 17031 | IOSTAT_FCP_RSP_ERROR; |
| 17032 | first_iocbq->iocb.un.ulpWord[4] = |
| 17033 | IOERR_NO_RESOURCES; |
| 17034 | } |
| 17035 | lpfc_in_buf_free(vport->phba, d_buf); |
| 17036 | continue; |
| 17037 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17038 | /* We need to get the size out of the right CQE */ |
| 17039 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 17040 | len = bf_get(lpfc_rcqe_length, |
| 17041 | &hbq_buf->cq_event.cqe.rcqe_cmpl); |
James Smart | 48a5a66 | 2013-07-15 18:32:28 -0400 | [diff] [blame] | 17042 | iocbq->context2 = d_buf; |
| 17043 | iocbq->context3 = NULL; |
| 17044 | iocbq->iocb.ulpBdeCount = 1; |
| 17045 | if (len > LPFC_DATA_BUF_SIZE) |
| 17046 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = |
| 17047 | LPFC_DATA_BUF_SIZE; |
| 17048 | else |
| 17049 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = len; |
| 17050 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17051 | tot_len += len; |
| 17052 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
| 17053 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17054 | iocbq->iocb.un.rcvels.remoteID = sid; |
| 17055 | list_add_tail(&iocbq->list, &first_iocbq->list); |
| 17056 | } |
| 17057 | } |
| 17058 | return first_iocbq; |
| 17059 | } |
| 17060 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17061 | static void |
| 17062 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, |
| 17063 | struct hbq_dmabuf *seq_dmabuf) |
| 17064 | { |
| 17065 | struct fc_frame_header *fc_hdr; |
| 17066 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; |
| 17067 | struct lpfc_hba *phba = vport->phba; |
| 17068 | |
| 17069 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; |
| 17070 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); |
| 17071 | if (!iocbq) { |
| 17072 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17073 | "2707 Ring %d handler: Failed to allocate " |
| 17074 | "iocb Rctl x%x Type x%x received\n", |
| 17075 | LPFC_ELS_RING, |
| 17076 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17077 | return; |
| 17078 | } |
| 17079 | if (!lpfc_complete_unsol_iocb(phba, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17080 | phba->sli4_hba.els_wq->pring, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17081 | iocbq, fc_hdr->fh_r_ctl, |
| 17082 | fc_hdr->fh_type)) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17083 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17084 | "2540 Ring %d handler: unexpected Rctl " |
| 17085 | "x%x Type x%x received\n", |
| 17086 | LPFC_ELS_RING, |
| 17087 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); |
| 17088 | |
| 17089 | /* Free iocb created in lpfc_prep_seq */ |
| 17090 | list_for_each_entry_safe(curr_iocb, next_iocb, |
| 17091 | &iocbq->list, list) { |
| 17092 | list_del_init(&curr_iocb->list); |
| 17093 | lpfc_sli_release_iocbq(phba, curr_iocb); |
| 17094 | } |
| 17095 | lpfc_sli_release_iocbq(phba, iocbq); |
| 17096 | } |
| 17097 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17098 | static void |
| 17099 | lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 17100 | struct lpfc_iocbq *rspiocb) |
| 17101 | { |
| 17102 | struct lpfc_dmabuf *pcmd = cmdiocb->context2; |
| 17103 | |
| 17104 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17105 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17106 | kfree(pcmd); |
| 17107 | lpfc_sli_release_iocbq(phba, cmdiocb); |
| 17108 | } |
| 17109 | |
| 17110 | static void |
| 17111 | lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport, |
| 17112 | struct hbq_dmabuf *dmabuf) |
| 17113 | { |
| 17114 | struct fc_frame_header *fc_hdr; |
| 17115 | struct lpfc_hba *phba = vport->phba; |
| 17116 | struct lpfc_iocbq *iocbq = NULL; |
| 17117 | union lpfc_wqe *wqe; |
| 17118 | struct lpfc_dmabuf *pcmd = NULL; |
| 17119 | uint32_t frame_len; |
| 17120 | int rc; |
| 17121 | |
| 17122 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
| 17123 | frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17124 | |
| 17125 | /* Send the received frame back */ |
| 17126 | iocbq = lpfc_sli_get_iocbq(phba); |
| 17127 | if (!iocbq) |
| 17128 | goto exit; |
| 17129 | |
| 17130 | /* Allocate buffer for command payload */ |
| 17131 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 17132 | if (pcmd) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17133 | pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL, |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17134 | &pcmd->phys); |
| 17135 | if (!pcmd || !pcmd->virt) |
| 17136 | goto exit; |
| 17137 | |
| 17138 | INIT_LIST_HEAD(&pcmd->list); |
| 17139 | |
| 17140 | /* copyin the payload */ |
| 17141 | memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len); |
| 17142 | |
| 17143 | /* fill in BDE's for command */ |
| 17144 | iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys); |
| 17145 | iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys); |
| 17146 | iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64; |
| 17147 | iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len; |
| 17148 | |
| 17149 | iocbq->context2 = pcmd; |
| 17150 | iocbq->vport = vport; |
| 17151 | iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK; |
| 17152 | iocbq->iocb_flag |= LPFC_USE_FCPWQIDX; |
| 17153 | |
| 17154 | /* |
| 17155 | * Setup rest of the iocb as though it were a WQE |
| 17156 | * Build the SEND_FRAME WQE |
| 17157 | */ |
| 17158 | wqe = (union lpfc_wqe *)&iocbq->iocb; |
| 17159 | |
| 17160 | wqe->send_frame.frame_len = frame_len; |
| 17161 | wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr)); |
| 17162 | wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1)); |
| 17163 | wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2)); |
| 17164 | wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3)); |
| 17165 | wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4)); |
| 17166 | wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5)); |
| 17167 | |
| 17168 | iocbq->iocb.ulpCommand = CMD_SEND_FRAME; |
| 17169 | iocbq->iocb.ulpLe = 1; |
| 17170 | iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl; |
| 17171 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0); |
| 17172 | if (rc == IOCB_ERROR) |
| 17173 | goto exit; |
| 17174 | |
| 17175 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17176 | return; |
| 17177 | |
| 17178 | exit: |
| 17179 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 17180 | "2023 Unable to process MDS loopback frame\n"); |
| 17181 | if (pcmd && pcmd->virt) |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 17182 | dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17183 | kfree(pcmd); |
Dick Kennedy | 401bb41 | 2017-09-29 17:34:28 -0700 | [diff] [blame] | 17184 | if (iocbq) |
| 17185 | lpfc_sli_release_iocbq(phba, iocbq); |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17186 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17187 | } |
| 17188 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17189 | /** |
| 17190 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware |
| 17191 | * @phba: Pointer to HBA context object. |
| 17192 | * |
| 17193 | * This function is called with no lock held. This function processes all |
| 17194 | * the received buffers and gives it to upper layers when a received buffer |
| 17195 | * indicates that it is the final frame in the sequence. The interrupt |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17196 | * service routine processes received buffers at interrupt contexts. |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17197 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the |
| 17198 | * appropriate receive function when the final frame in a sequence is received. |
| 17199 | **/ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17200 | void |
| 17201 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, |
| 17202 | struct hbq_dmabuf *dmabuf) |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17203 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17204 | struct hbq_dmabuf *seq_dmabuf; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17205 | struct fc_frame_header *fc_hdr; |
| 17206 | struct lpfc_vport *vport; |
| 17207 | uint32_t fcfi; |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17208 | uint32_t did; |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17209 | |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17210 | /* Process each received buffer */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17211 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17212 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17213 | /* check to see if this a valid type of frame */ |
| 17214 | if (lpfc_fc_frame_check(phba, fc_hdr)) { |
| 17215 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17216 | return; |
| 17217 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 17218 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 17219 | if ((bf_get(lpfc_cqe_code, |
| 17220 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) |
| 17221 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, |
| 17222 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
| 17223 | else |
| 17224 | fcfi = bf_get(lpfc_rcqe_fcf_id, |
| 17225 | &dmabuf->cq_event.cqe.rcqe_cmpl); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17226 | |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 17227 | if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) { |
| 17228 | vport = phba->pport; |
| 17229 | /* Handle MDS Loopback frames */ |
| 17230 | lpfc_sli4_handle_mds_loopback(vport, dmabuf); |
| 17231 | return; |
| 17232 | } |
| 17233 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 17234 | /* d_id this frame is directed to */ |
| 17235 | did = sli4_did_from_fc_hdr(fc_hdr); |
| 17236 | |
| 17237 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did); |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17238 | if (!vport) { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17239 | /* throw out the frame */ |
| 17240 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17241 | return; |
| 17242 | } |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17243 | |
James Smart | 939723a | 2012-05-09 21:19:03 -0400 | [diff] [blame] | 17244 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ |
| 17245 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && |
| 17246 | (did != Fabric_DID)) { |
| 17247 | /* |
| 17248 | * Throw out the frame if we are not pt2pt. |
| 17249 | * The pt2pt protocol allows for discovery frames |
| 17250 | * to be received without a registered VPI. |
| 17251 | */ |
| 17252 | if (!(vport->fc_flag & FC_PT2PT) || |
| 17253 | (phba->link_state == LPFC_HBA_READY)) { |
| 17254 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17255 | return; |
| 17256 | } |
| 17257 | } |
| 17258 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17259 | /* Handle the basic abort sequence (BA_ABTS) event */ |
| 17260 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { |
| 17261 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); |
| 17262 | return; |
| 17263 | } |
| 17264 | |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17265 | /* Link this frame */ |
| 17266 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); |
| 17267 | if (!seq_dmabuf) { |
| 17268 | /* unable to add frame to vport - throw it out */ |
| 17269 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 17270 | return; |
| 17271 | } |
| 17272 | /* If not last frame in sequence continue processing frames. */ |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17273 | if (!lpfc_seq_complete(seq_dmabuf)) |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17274 | return; |
James Smart | def9c7a | 2009-12-21 17:02:28 -0500 | [diff] [blame] | 17275 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 17276 | /* Send the complete sequence to the upper layer protocol */ |
| 17277 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); |
James Smart | 4f77451 | 2009-05-22 14:52:35 -0400 | [diff] [blame] | 17278 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17279 | |
| 17280 | /** |
| 17281 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port |
| 17282 | * @phba: pointer to lpfc hba data structure. |
| 17283 | * |
| 17284 | * This routine is invoked to post rpi header templates to the |
| 17285 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17286 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17287 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17288 | * |
| 17289 | * This routine does not require any locks. It's usage is expected |
| 17290 | * to be driver load or reset recovery when the driver is |
| 17291 | * sequential. |
| 17292 | * |
| 17293 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17294 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17295 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17296 | * When this error occurs, the driver is not guaranteed |
| 17297 | * to have any rpi regions posted to the device and |
| 17298 | * must either attempt to repost the regions or take a |
| 17299 | * fatal error. |
| 17300 | **/ |
| 17301 | int |
| 17302 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) |
| 17303 | { |
| 17304 | struct lpfc_rpi_hdr *rpi_page; |
| 17305 | uint32_t rc = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17306 | uint16_t lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17307 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17308 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 17309 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 17310 | goto exit; |
| 17311 | if (phba->sli4_hba.extents_in_use) |
| 17312 | return -EIO; |
| 17313 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17314 | 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] | 17315 | /* |
| 17316 | * Assign the rpi headers a physical rpi only if the driver |
| 17317 | * has not initialized those resources. A port reset only |
| 17318 | * needs the headers posted. |
| 17319 | */ |
| 17320 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != |
| 17321 | LPFC_RPI_RSRC_RDY) |
| 17322 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
| 17323 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17324 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
| 17325 | if (rc != MBX_SUCCESS) { |
| 17326 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17327 | "2008 Error %d posting all rpi " |
| 17328 | "headers\n", rc); |
| 17329 | rc = -EIO; |
| 17330 | break; |
| 17331 | } |
| 17332 | } |
| 17333 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17334 | exit: |
| 17335 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, |
| 17336 | LPFC_RPI_RSRC_RDY); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17337 | return rc; |
| 17338 | } |
| 17339 | |
| 17340 | /** |
| 17341 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port |
| 17342 | * @phba: pointer to lpfc hba data structure. |
| 17343 | * @rpi_page: pointer to the rpi memory region. |
| 17344 | * |
| 17345 | * This routine is invoked to post a single rpi header to the |
| 17346 | * HBA consistent with the SLI-4 interface spec. This memory region |
| 17347 | * maps up to 64 rpi context regions. |
| 17348 | * |
| 17349 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17350 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 17351 | * -ENOMEM - No available memory |
| 17352 | * -EIO - The mailbox failed to complete successfully. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17353 | **/ |
| 17354 | int |
| 17355 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) |
| 17356 | { |
| 17357 | LPFC_MBOXQ_t *mboxq; |
| 17358 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; |
| 17359 | uint32_t rc = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17360 | uint32_t shdr_status, shdr_add_status; |
| 17361 | union lpfc_sli4_cfg_shdr *shdr; |
| 17362 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17363 | /* SLI4 ports that support extents do not require RPI headers. */ |
| 17364 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 17365 | return rc; |
| 17366 | if (phba->sli4_hba.extents_in_use) |
| 17367 | return -EIO; |
| 17368 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17369 | /* The port is notified of the header region via a mailbox command. */ |
| 17370 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17371 | if (!mboxq) { |
| 17372 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17373 | "2001 Unable to allocate memory for issuing " |
| 17374 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 17375 | return -ENOMEM; |
| 17376 | } |
| 17377 | |
| 17378 | /* Post all rpi memory regions to the port. */ |
| 17379 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17380 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17381 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, |
| 17382 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 17383 | sizeof(struct lpfc_sli4_cfg_mhdr), |
| 17384 | LPFC_SLI4_MBX_EMBED); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17385 | |
| 17386 | |
| 17387 | /* Post the physical rpi to the port for this rpi header. */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17388 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
| 17389 | rpi_page->start_rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17390 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
| 17391 | hdr_tmpl, rpi_page->page_count); |
| 17392 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17393 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
| 17394 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 17395 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17396 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
| 17397 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17398 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17399 | if (rc != MBX_TIMEOUT) |
| 17400 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 17401 | if (shdr_status || shdr_add_status || rc) { |
| 17402 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17403 | "2514 POST_RPI_HDR mailbox failed with " |
| 17404 | "status x%x add_status x%x, mbx status x%x\n", |
| 17405 | shdr_status, shdr_add_status, rc); |
| 17406 | rc = -ENXIO; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 17407 | } else { |
| 17408 | /* |
| 17409 | * The next_rpi stores the next logical module-64 rpi value used |
| 17410 | * to post physical rpis in subsequent rpi postings. |
| 17411 | */ |
| 17412 | spin_lock_irq(&phba->hbalock); |
| 17413 | phba->sli4_hba.next_rpi = rpi_page->next_rpi; |
| 17414 | spin_unlock_irq(&phba->hbalock); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17415 | } |
| 17416 | return rc; |
| 17417 | } |
| 17418 | |
| 17419 | /** |
| 17420 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range |
| 17421 | * @phba: pointer to lpfc hba data structure. |
| 17422 | * |
| 17423 | * This routine is invoked to post rpi header templates to the |
| 17424 | * HBA consistent with the SLI-4 interface spec. This routine |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 17425 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
| 17426 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17427 | * |
| 17428 | * Returns |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 17429 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17430 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
| 17431 | **/ |
| 17432 | int |
| 17433 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) |
| 17434 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17435 | unsigned long rpi; |
| 17436 | uint16_t max_rpi, rpi_limit; |
| 17437 | uint16_t rpi_remaining, lrpi = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17438 | struct lpfc_rpi_hdr *rpi_hdr; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17439 | unsigned long iflag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17440 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17441 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17442 | * Fetch the next logical rpi. Because this index is logical, |
| 17443 | * the driver starts at 0 each time. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17444 | */ |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17445 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 17446 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; |
| 17447 | rpi_limit = phba->sli4_hba.next_rpi; |
| 17448 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17449 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
| 17450 | if (rpi >= rpi_limit) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17451 | rpi = LPFC_RPI_ALLOC_ERROR; |
| 17452 | else { |
| 17453 | set_bit(rpi, phba->sli4_hba.rpi_bmask); |
| 17454 | phba->sli4_hba.max_cfg_param.rpi_used++; |
| 17455 | phba->sli4_hba.rpi_count++; |
| 17456 | } |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 17457 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 17458 | "0001 rpi:%x max:%x lim:%x\n", |
| 17459 | (int) rpi, max_rpi, rpi_limit); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17460 | |
| 17461 | /* |
| 17462 | * 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] | 17463 | * has been exhausted. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17464 | */ |
| 17465 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && |
| 17466 | (phba->sli4_hba.rpi_count >= max_rpi)) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17467 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17468 | return rpi; |
| 17469 | } |
| 17470 | |
| 17471 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17472 | * RPI header postings are not required for SLI4 ports capable of |
| 17473 | * extents. |
| 17474 | */ |
| 17475 | if (!phba->sli4_hba.rpi_hdrs_in_use) { |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17476 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17477 | return rpi; |
| 17478 | } |
| 17479 | |
| 17480 | /* |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17481 | * If the driver is running low on rpi resources, allocate another |
| 17482 | * page now. Note that the next_rpi value is used because |
| 17483 | * it represents how many are actually in use whereas max_rpi notes |
| 17484 | * how many are supported max by the device. |
| 17485 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17486 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
James Smart | 4902b38 | 2013-10-10 12:20:35 -0400 | [diff] [blame] | 17487 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17488 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { |
| 17489 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 17490 | if (!rpi_hdr) { |
| 17491 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17492 | "2002 Error Could not grow rpi " |
| 17493 | "count\n"); |
| 17494 | } else { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17495 | lrpi = rpi_hdr->start_rpi; |
| 17496 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17497 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
| 17498 | } |
| 17499 | } |
| 17500 | |
| 17501 | return rpi; |
| 17502 | } |
| 17503 | |
| 17504 | /** |
| 17505 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 17506 | * @phba: pointer to lpfc hba data structure. |
| 17507 | * |
| 17508 | * This routine is invoked to release an rpi to the pool of |
| 17509 | * available rpis maintained by the driver. |
| 17510 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17511 | static void |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 17512 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 17513 | { |
| 17514 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { |
| 17515 | phba->sli4_hba.rpi_count--; |
| 17516 | phba->sli4_hba.max_cfg_param.rpi_used--; |
| 17517 | } |
| 17518 | } |
| 17519 | |
| 17520 | /** |
| 17521 | * lpfc_sli4_free_rpi - Release an rpi for reuse. |
| 17522 | * @phba: pointer to lpfc hba data structure. |
| 17523 | * |
| 17524 | * This routine is invoked to release an rpi to the pool of |
| 17525 | * available rpis maintained by the driver. |
| 17526 | **/ |
| 17527 | void |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17528 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) |
| 17529 | { |
| 17530 | spin_lock_irq(&phba->hbalock); |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 17531 | __lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17532 | spin_unlock_irq(&phba->hbalock); |
| 17533 | } |
| 17534 | |
| 17535 | /** |
| 17536 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region |
| 17537 | * @phba: pointer to lpfc hba data structure. |
| 17538 | * |
| 17539 | * This routine is invoked to remove the memory region that |
| 17540 | * provided rpi via a bitmask. |
| 17541 | **/ |
| 17542 | void |
| 17543 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) |
| 17544 | { |
| 17545 | kfree(phba->sli4_hba.rpi_bmask); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 17546 | kfree(phba->sli4_hba.rpi_ids); |
| 17547 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17548 | } |
| 17549 | |
| 17550 | /** |
| 17551 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region |
| 17552 | * @phba: pointer to lpfc hba data structure. |
| 17553 | * |
| 17554 | * This routine is invoked to remove the memory region that |
| 17555 | * provided rpi via a bitmask. |
| 17556 | **/ |
| 17557 | int |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17558 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
| 17559 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17560 | { |
| 17561 | LPFC_MBOXQ_t *mboxq; |
| 17562 | struct lpfc_hba *phba = ndlp->phba; |
| 17563 | int rc; |
| 17564 | |
| 17565 | /* The port is notified of the header region via a mailbox command. */ |
| 17566 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17567 | if (!mboxq) |
| 17568 | return -ENOMEM; |
| 17569 | |
| 17570 | /* Post all rpi memory regions to the port. */ |
| 17571 | lpfc_resume_rpi(mboxq, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17572 | if (cmpl) { |
| 17573 | mboxq->mbox_cmpl = cmpl; |
| 17574 | mboxq->context1 = arg; |
| 17575 | mboxq->context2 = ndlp; |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 17576 | } else |
| 17577 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 17578 | mboxq->vport = ndlp->vport; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17579 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17580 | if (rc == MBX_NOT_FINISHED) { |
| 17581 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 17582 | "2010 Resume RPI Mailbox failed " |
| 17583 | "status %d, mbxStatus x%x\n", rc, |
| 17584 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 17585 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 17586 | return -EIO; |
| 17587 | } |
| 17588 | return 0; |
| 17589 | } |
| 17590 | |
| 17591 | /** |
| 17592 | * lpfc_sli4_init_vpi - Initialize a vpi with the port |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17593 | * @vport: Pointer to the vport for which the vpi is being initialized |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17594 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17595 | * This routine is invoked to activate a vpi with the port. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17596 | * |
| 17597 | * Returns: |
| 17598 | * 0 success |
| 17599 | * -Evalue otherwise |
| 17600 | **/ |
| 17601 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17602 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17603 | { |
| 17604 | LPFC_MBOXQ_t *mboxq; |
| 17605 | int rc = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17606 | int retval = MBX_SUCCESS; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17607 | uint32_t mbox_tmo; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17608 | struct lpfc_hba *phba = vport->phba; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17609 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17610 | if (!mboxq) |
| 17611 | return -ENOMEM; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17612 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 17613 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17614 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17615 | if (rc != MBX_SUCCESS) { |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17616 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17617 | "2022 INIT VPI Mailbox failed " |
| 17618 | "status %d, mbxStatus x%x\n", rc, |
| 17619 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17620 | retval = -EIO; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17621 | } |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17622 | if (rc != MBX_TIMEOUT) |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 17623 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 17624 | |
| 17625 | return retval; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17626 | } |
| 17627 | |
| 17628 | /** |
| 17629 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. |
| 17630 | * @phba: pointer to lpfc hba data structure. |
| 17631 | * @mboxq: Pointer to mailbox object. |
| 17632 | * |
| 17633 | * This routine is invoked to manually add a single FCF record. The caller |
| 17634 | * must pass a completely initialized FCF_Record. This routine takes |
| 17635 | * care of the nonembedded mailbox operations. |
| 17636 | **/ |
| 17637 | static void |
| 17638 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 17639 | { |
| 17640 | void *virt_addr; |
| 17641 | union lpfc_sli4_cfg_shdr *shdr; |
| 17642 | uint32_t shdr_status, shdr_add_status; |
| 17643 | |
| 17644 | virt_addr = mboxq->sge_array->addr[0]; |
| 17645 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 17646 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; |
| 17647 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 17648 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 17649 | |
| 17650 | if ((shdr_status || shdr_add_status) && |
| 17651 | (shdr_status != STATUS_FCF_IN_USE)) |
| 17652 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17653 | "2558 ADD_FCF_RECORD mailbox failed with " |
| 17654 | "status x%x add_status x%x\n", |
| 17655 | shdr_status, shdr_add_status); |
| 17656 | |
| 17657 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17658 | } |
| 17659 | |
| 17660 | /** |
| 17661 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. |
| 17662 | * @phba: pointer to lpfc hba data structure. |
| 17663 | * @fcf_record: pointer to the initialized fcf record to add. |
| 17664 | * |
| 17665 | * This routine is invoked to manually add a single FCF record. The caller |
| 17666 | * must pass a completely initialized FCF_Record. This routine takes |
| 17667 | * care of the nonembedded mailbox operations. |
| 17668 | **/ |
| 17669 | int |
| 17670 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) |
| 17671 | { |
| 17672 | int rc = 0; |
| 17673 | LPFC_MBOXQ_t *mboxq; |
| 17674 | uint8_t *bytep; |
| 17675 | void *virt_addr; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17676 | struct lpfc_mbx_sge sge; |
| 17677 | uint32_t alloc_len, req_len; |
| 17678 | uint32_t fcfindex; |
| 17679 | |
| 17680 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17681 | if (!mboxq) { |
| 17682 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17683 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); |
| 17684 | return -ENOMEM; |
| 17685 | } |
| 17686 | |
| 17687 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + |
| 17688 | sizeof(uint32_t); |
| 17689 | |
| 17690 | /* Allocate DMA memory and set up the non-embedded mailbox command */ |
| 17691 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 17692 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, |
| 17693 | req_len, LPFC_SLI4_MBX_NEMBED); |
| 17694 | if (alloc_len < req_len) { |
| 17695 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17696 | "2523 Allocated DMA memory size (x%x) is " |
| 17697 | "less than the requested DMA memory " |
| 17698 | "size (x%x)\n", alloc_len, req_len); |
| 17699 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17700 | return -ENOMEM; |
| 17701 | } |
| 17702 | |
| 17703 | /* |
| 17704 | * Get the first SGE entry from the non-embedded DMA memory. This |
| 17705 | * routine only uses a single SGE. |
| 17706 | */ |
| 17707 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17708 | virt_addr = mboxq->sge_array->addr[0]; |
| 17709 | /* |
| 17710 | * Configure the FCF record for FCFI 0. This is the driver's |
| 17711 | * hardcoded default and gets used in nonFIP mode. |
| 17712 | */ |
| 17713 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); |
| 17714 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 17715 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); |
| 17716 | |
| 17717 | /* |
| 17718 | * Copy the fcf_index and the FCF Record Data. The data starts after |
| 17719 | * the FCoE header plus word10. The data copy needs to be endian |
| 17720 | * correct. |
| 17721 | */ |
| 17722 | bytep += sizeof(uint32_t); |
| 17723 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); |
| 17724 | mboxq->vport = phba->pport; |
| 17725 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; |
| 17726 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17727 | if (rc == MBX_NOT_FINISHED) { |
| 17728 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17729 | "2515 ADD_FCF_RECORD mailbox failed with " |
| 17730 | "status 0x%x\n", rc); |
| 17731 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17732 | rc = -EIO; |
| 17733 | } else |
| 17734 | rc = 0; |
| 17735 | |
| 17736 | return rc; |
| 17737 | } |
| 17738 | |
| 17739 | /** |
| 17740 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. |
| 17741 | * @phba: pointer to lpfc hba data structure. |
| 17742 | * @fcf_record: pointer to the fcf record to write the default data. |
| 17743 | * @fcf_index: FCF table entry index. |
| 17744 | * |
| 17745 | * This routine is invoked to build the driver's default FCF record. The |
| 17746 | * values used are hardcoded. This routine handles memory initialization. |
| 17747 | * |
| 17748 | **/ |
| 17749 | void |
| 17750 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, |
| 17751 | struct fcf_record *fcf_record, |
| 17752 | uint16_t fcf_index) |
| 17753 | { |
| 17754 | memset(fcf_record, 0, sizeof(struct fcf_record)); |
| 17755 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; |
| 17756 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; |
| 17757 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; |
| 17758 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); |
| 17759 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); |
| 17760 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); |
| 17761 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); |
| 17762 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); |
| 17763 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); |
| 17764 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); |
| 17765 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); |
| 17766 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); |
| 17767 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 17768 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17769 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
| 17770 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, |
| 17771 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); |
| 17772 | /* Set the VLAN bit map */ |
| 17773 | if (phba->valid_vlan) { |
| 17774 | fcf_record->vlan_bitmap[phba->vlan_id / 8] |
| 17775 | = 1 << (phba->vlan_id % 8); |
| 17776 | } |
| 17777 | } |
| 17778 | |
| 17779 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17780 | * 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] | 17781 | * @phba: pointer to lpfc hba data structure. |
| 17782 | * @fcf_index: FCF table entry offset. |
| 17783 | * |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17784 | * This routine is invoked to scan the entire FCF table by reading FCF |
| 17785 | * record and processing it one at a time starting from the @fcf_index |
| 17786 | * for initial FCF discovery or fast FCF failover rediscovery. |
| 17787 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 17788 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17789 | * otherwise. |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17790 | **/ |
| 17791 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17792 | 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] | 17793 | { |
| 17794 | int rc = 0, error; |
| 17795 | LPFC_MBOXQ_t *mboxq; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17796 | |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 17797 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 17798 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17799 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17800 | if (!mboxq) { |
| 17801 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 17802 | "2000 Failed to allocate mbox for " |
| 17803 | "READ_FCF cmd\n"); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17804 | error = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17805 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17806 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17807 | /* Construct the read FCF record mailbox command */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17808 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17809 | if (rc) { |
| 17810 | error = -EINVAL; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17811 | goto fail_fcf_scan; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17812 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17813 | /* Issue the mailbox command asynchronously */ |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17814 | mboxq->vport = phba->pport; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17815 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17816 | |
| 17817 | spin_lock_irq(&phba->hbalock); |
| 17818 | phba->hba_flag |= FCF_TS_INPROG; |
| 17819 | spin_unlock_irq(&phba->hbalock); |
| 17820 | |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17821 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17822 | if (rc == MBX_NOT_FINISHED) |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17823 | error = -EIO; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 17824 | else { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 17825 | /* Reset eligible FCF count for new scan */ |
| 17826 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 17827 | phba->fcf.eligible_fcf_cnt = 0; |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17828 | error = 0; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 17829 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17830 | fail_fcf_scan: |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17831 | if (error) { |
| 17832 | if (mboxq) |
| 17833 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17834 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17835 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17836 | phba->hba_flag &= ~FCF_TS_INPROG; |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 17837 | spin_unlock_irq(&phba->hbalock); |
| 17838 | } |
James Smart | 6fb120a | 2009-05-22 14:52:59 -0400 | [diff] [blame] | 17839 | return error; |
| 17840 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 17841 | |
| 17842 | /** |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 17843 | * 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] | 17844 | * @phba: pointer to lpfc hba data structure. |
| 17845 | * @fcf_index: FCF table entry offset. |
| 17846 | * |
| 17847 | * 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] | 17848 | * and to use it for FLOGI roundrobin FCF failover. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17849 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 17850 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17851 | * otherwise. |
| 17852 | **/ |
| 17853 | int |
| 17854 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 17855 | { |
| 17856 | int rc = 0, error; |
| 17857 | LPFC_MBOXQ_t *mboxq; |
| 17858 | |
| 17859 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17860 | if (!mboxq) { |
| 17861 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 17862 | "2763 Failed to allocate mbox for " |
| 17863 | "READ_FCF cmd\n"); |
| 17864 | error = -ENOMEM; |
| 17865 | goto fail_fcf_read; |
| 17866 | } |
| 17867 | /* Construct the read FCF record mailbox command */ |
| 17868 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 17869 | if (rc) { |
| 17870 | error = -EINVAL; |
| 17871 | goto fail_fcf_read; |
| 17872 | } |
| 17873 | /* Issue the mailbox command asynchronously */ |
| 17874 | mboxq->vport = phba->pport; |
| 17875 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; |
| 17876 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17877 | if (rc == MBX_NOT_FINISHED) |
| 17878 | error = -EIO; |
| 17879 | else |
| 17880 | error = 0; |
| 17881 | |
| 17882 | fail_fcf_read: |
| 17883 | if (error && mboxq) |
| 17884 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17885 | return error; |
| 17886 | } |
| 17887 | |
| 17888 | /** |
| 17889 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. |
| 17890 | * @phba: pointer to lpfc hba data structure. |
| 17891 | * @fcf_index: FCF table entry offset. |
| 17892 | * |
| 17893 | * 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] | 17894 | * determine whether it's eligible for FLOGI roundrobin failover list. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17895 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 17896 | * Return 0 if the mailbox command is submitted successfully, none 0 |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 17897 | * otherwise. |
| 17898 | **/ |
| 17899 | int |
| 17900 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
| 17901 | { |
| 17902 | int rc = 0, error; |
| 17903 | LPFC_MBOXQ_t *mboxq; |
| 17904 | |
| 17905 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 17906 | if (!mboxq) { |
| 17907 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, |
| 17908 | "2758 Failed to allocate mbox for " |
| 17909 | "READ_FCF cmd\n"); |
| 17910 | error = -ENOMEM; |
| 17911 | goto fail_fcf_read; |
| 17912 | } |
| 17913 | /* Construct the read FCF record mailbox command */ |
| 17914 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
| 17915 | if (rc) { |
| 17916 | error = -EINVAL; |
| 17917 | goto fail_fcf_read; |
| 17918 | } |
| 17919 | /* Issue the mailbox command asynchronously */ |
| 17920 | mboxq->vport = phba->pport; |
| 17921 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; |
| 17922 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
| 17923 | if (rc == MBX_NOT_FINISHED) |
| 17924 | error = -EIO; |
| 17925 | else |
| 17926 | error = 0; |
| 17927 | |
| 17928 | fail_fcf_read: |
| 17929 | if (error && mboxq) |
| 17930 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 17931 | return error; |
| 17932 | } |
| 17933 | |
| 17934 | /** |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 17935 | * lpfc_check_next_fcf_pri_level |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 17936 | * phba pointer to the lpfc_hba struct for this port. |
| 17937 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get |
| 17938 | * routine when the rr_bmask is empty. The FCF indecies are put into the |
| 17939 | * rr_bmask based on their priority level. Starting from the highest priority |
| 17940 | * to the lowest. The most likely FCF candidate will be in the highest |
| 17941 | * priority group. When this routine is called it searches the fcf_pri list for |
| 17942 | * next lowest priority group and repopulates the rr_bmask with only those |
| 17943 | * fcf_indexes. |
| 17944 | * returns: |
| 17945 | * 1=success 0=failure |
| 17946 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 17947 | static int |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 17948 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) |
| 17949 | { |
| 17950 | uint16_t next_fcf_pri; |
| 17951 | uint16_t last_index; |
| 17952 | struct lpfc_fcf_pri *fcf_pri; |
| 17953 | int rc; |
| 17954 | int ret = 0; |
| 17955 | |
| 17956 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, |
| 17957 | LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 17958 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
| 17959 | "3060 Last IDX %d\n", last_index); |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 17960 | |
| 17961 | /* Verify the priority list has 2 or more entries */ |
| 17962 | spin_lock_irq(&phba->hbalock); |
| 17963 | if (list_empty(&phba->fcf.fcf_pri_list) || |
| 17964 | list_is_singular(&phba->fcf.fcf_pri_list)) { |
| 17965 | spin_unlock_irq(&phba->hbalock); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 17966 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
| 17967 | "3061 Last IDX %d\n", last_index); |
| 17968 | return 0; /* Empty rr list */ |
| 17969 | } |
James Smart | 2562669 | 2013-03-01 16:36:54 -0500 | [diff] [blame] | 17970 | spin_unlock_irq(&phba->hbalock); |
| 17971 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 17972 | next_fcf_pri = 0; |
| 17973 | /* |
| 17974 | * Clear the rr_bmask and set all of the bits that are at this |
| 17975 | * priority. |
| 17976 | */ |
| 17977 | memset(phba->fcf.fcf_rr_bmask, 0, |
| 17978 | sizeof(*phba->fcf.fcf_rr_bmask)); |
| 17979 | spin_lock_irq(&phba->hbalock); |
| 17980 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 17981 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) |
| 17982 | continue; |
| 17983 | /* |
| 17984 | * the 1st priority that has not FLOGI failed |
| 17985 | * will be the highest. |
| 17986 | */ |
| 17987 | if (!next_fcf_pri) |
| 17988 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 17989 | spin_unlock_irq(&phba->hbalock); |
| 17990 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 17991 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 17992 | fcf_pri->fcf_rec.fcf_index); |
| 17993 | if (rc) |
| 17994 | return 0; |
| 17995 | } |
| 17996 | spin_lock_irq(&phba->hbalock); |
| 17997 | } |
| 17998 | /* |
| 17999 | * if next_fcf_pri was not set above and the list is not empty then |
| 18000 | * we have failed flogis on all of them. So reset flogi failed |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 18001 | * and start at the beginning. |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18002 | */ |
| 18003 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { |
| 18004 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { |
| 18005 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; |
| 18006 | /* |
| 18007 | * the 1st priority that has not FLOGI failed |
| 18008 | * will be the highest. |
| 18009 | */ |
| 18010 | if (!next_fcf_pri) |
| 18011 | next_fcf_pri = fcf_pri->fcf_rec.priority; |
| 18012 | spin_unlock_irq(&phba->hbalock); |
| 18013 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { |
| 18014 | rc = lpfc_sli4_fcf_rr_index_set(phba, |
| 18015 | fcf_pri->fcf_rec.fcf_index); |
| 18016 | if (rc) |
| 18017 | return 0; |
| 18018 | } |
| 18019 | spin_lock_irq(&phba->hbalock); |
| 18020 | } |
| 18021 | } else |
| 18022 | ret = 1; |
| 18023 | spin_unlock_irq(&phba->hbalock); |
| 18024 | |
| 18025 | return ret; |
| 18026 | } |
| 18027 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18028 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index |
| 18029 | * @phba: pointer to lpfc hba data structure. |
| 18030 | * |
| 18031 | * This routine is to get the next eligible FCF record index in a round |
| 18032 | * robin fashion. If the next eligible FCF record index equals to the |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18033 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18034 | * shall be returned, otherwise, the next eligible FCF record's index |
| 18035 | * shall be returned. |
| 18036 | **/ |
| 18037 | uint16_t |
| 18038 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) |
| 18039 | { |
| 18040 | uint16_t next_fcf_index; |
| 18041 | |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18042 | initial_priority: |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18043 | /* Search start from next bit of currently registered FCF index */ |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18044 | next_fcf_index = phba->fcf.current_rec.fcf_indx; |
| 18045 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18046 | next_priority: |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18047 | /* Determine the next fcf index to check */ |
| 18048 | 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] | 18049 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18050 | LPFC_SLI4_FCF_TBL_INDX_MAX, |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18051 | next_fcf_index); |
| 18052 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18053 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18054 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18055 | /* |
| 18056 | * If we have wrapped then we need to clear the bits that |
| 18057 | * have been tested so that we can detect when we should |
| 18058 | * change the priority level. |
| 18059 | */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18060 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
| 18061 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18062 | } |
| 18063 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18064 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18065 | /* Check roundrobin failover list empty condition */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18066 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
| 18067 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { |
| 18068 | /* |
| 18069 | * If next fcf index is not found check if there are lower |
| 18070 | * Priority level fcf's in the fcf_priority list. |
| 18071 | * Set up the rr_bmask with all of the avaiable fcf bits |
| 18072 | * at that level and continue the selection process. |
| 18073 | */ |
| 18074 | if (lpfc_check_next_fcf_pri_level(phba)) |
James Smart | 421c662 | 2013-01-03 15:44:16 -0500 | [diff] [blame] | 18075 | goto initial_priority; |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18076 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18077 | "2844 No roundrobin failover FCF available\n"); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18078 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
| 18079 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18080 | else { |
| 18081 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
| 18082 | "3063 Only FCF available idx %d, flag %x\n", |
| 18083 | next_fcf_index, |
| 18084 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); |
| 18085 | return next_fcf_index; |
| 18086 | } |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18087 | } |
| 18088 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18089 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
| 18090 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18091 | LPFC_FCF_FLOGI_FAILED) { |
| 18092 | if (list_is_singular(&phba->fcf.fcf_pri_list)) |
| 18093 | return LPFC_FCOE_FCF_NEXT_NONE; |
| 18094 | |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18095 | goto next_priority; |
James Smart | f5cb530 | 2015-12-16 18:11:52 -0500 | [diff] [blame] | 18096 | } |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18097 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18098 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18099 | "2845 Get next roundrobin failover FCF (x%x)\n", |
| 18100 | next_fcf_index); |
| 18101 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18102 | return next_fcf_index; |
| 18103 | } |
| 18104 | |
| 18105 | /** |
| 18106 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index |
| 18107 | * @phba: pointer to lpfc hba data structure. |
| 18108 | * |
| 18109 | * 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] | 18110 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18111 | * does not go beyond the range of the driver allocated bmask dimension |
| 18112 | * before setting the bit. |
| 18113 | * |
| 18114 | * Returns 0 if the index bit successfully set, otherwise, it returns |
| 18115 | * -EINVAL. |
| 18116 | **/ |
| 18117 | int |
| 18118 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18119 | { |
| 18120 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18121 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18122 | "2610 FCF (x%x) reached driver's book " |
| 18123 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18124 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18125 | return -EINVAL; |
| 18126 | } |
| 18127 | /* Set the eligible FCF record index bmask */ |
| 18128 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
| 18129 | |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18130 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18131 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18132 | "bmask\n", fcf_index); |
| 18133 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18134 | return 0; |
| 18135 | } |
| 18136 | |
| 18137 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18138 | * 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] | 18139 | * @phba: pointer to lpfc hba data structure. |
| 18140 | * |
| 18141 | * This routine clears the FCF record index from the eligible bmask for |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18142 | * roundrobin failover search. It checks to make sure that the index |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18143 | * does not go beyond the range of the driver allocated bmask dimension |
| 18144 | * before clearing the bit. |
| 18145 | **/ |
| 18146 | void |
| 18147 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) |
| 18148 | { |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18149 | struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18150 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
| 18151 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18152 | "2762 FCF (x%x) reached driver's book " |
| 18153 | "keeping dimension:x%x\n", |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18154 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
| 18155 | return; |
| 18156 | } |
| 18157 | /* Clear the eligible FCF record index bmask */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18158 | spin_lock_irq(&phba->hbalock); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 18159 | list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list, |
| 18160 | list) { |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 18161 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { |
| 18162 | list_del_init(&fcf_pri->list); |
| 18163 | break; |
| 18164 | } |
| 18165 | } |
| 18166 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18167 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18168 | |
| 18169 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18170 | "2791 Clear FCF (x%x) from roundrobin failover " |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18171 | "bmask\n", fcf_index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18172 | } |
| 18173 | |
| 18174 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18175 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table |
| 18176 | * @phba: pointer to lpfc hba data structure. |
| 18177 | * |
| 18178 | * This routine is the completion routine for the rediscover FCF table mailbox |
| 18179 | * command. If the mailbox command returned failure, it will try to stop the |
| 18180 | * FCF rediscover wait timer. |
| 18181 | **/ |
Rashika Kheria | 5d8b816 | 2014-09-03 12:55:04 -0400 | [diff] [blame] | 18182 | static void |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18183 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 18184 | { |
| 18185 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18186 | uint32_t shdr_status, shdr_add_status; |
| 18187 | |
| 18188 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18189 | |
| 18190 | shdr_status = bf_get(lpfc_mbox_hdr_status, |
| 18191 | &redisc_fcf->header.cfg_shdr.response); |
| 18192 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 18193 | &redisc_fcf->header.cfg_shdr.response); |
| 18194 | if (shdr_status || shdr_add_status) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18195 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18196 | "2746 Requesting for FCF rediscovery failed " |
| 18197 | "status x%x add_status x%x\n", |
| 18198 | shdr_status, shdr_add_status); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18199 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18200 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18201 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18202 | spin_unlock_irq(&phba->hbalock); |
| 18203 | /* |
| 18204 | * CVL event triggered FCF rediscover request failed, |
| 18205 | * last resort to re-try current registered FCF entry. |
| 18206 | */ |
| 18207 | lpfc_retry_pport_discovery(phba); |
| 18208 | } else { |
| 18209 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18210 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18211 | spin_unlock_irq(&phba->hbalock); |
| 18212 | /* |
| 18213 | * DEAD FCF event triggered FCF rediscover request |
| 18214 | * failed, last resort to fail over as a link down |
| 18215 | * to FCF registration. |
| 18216 | */ |
| 18217 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 18218 | } |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18219 | } else { |
| 18220 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 18221 | "2775 Start FCF rediscover quiescent timer\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18222 | /* |
| 18223 | * Start FCF rediscovery wait timer for pending FCF |
| 18224 | * before rescan FCF record table. |
| 18225 | */ |
| 18226 | lpfc_fcf_redisc_wait_start_timer(phba); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18227 | } |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18228 | |
| 18229 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18230 | } |
| 18231 | |
| 18232 | /** |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 18233 | * 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] | 18234 | * @phba: pointer to lpfc hba data structure. |
| 18235 | * |
| 18236 | * This routine is invoked to request for rediscovery of the entire FCF table |
| 18237 | * by the port. |
| 18238 | **/ |
| 18239 | int |
| 18240 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) |
| 18241 | { |
| 18242 | LPFC_MBOXQ_t *mbox; |
| 18243 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; |
| 18244 | int rc, length; |
| 18245 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 18246 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
| 18247 | lpfc_cancel_all_vport_retry_delay_timer(phba); |
| 18248 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 18249 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18250 | if (!mbox) { |
| 18251 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18252 | "2745 Failed to allocate mbox for " |
| 18253 | "requesting FCF rediscover.\n"); |
| 18254 | return -ENOMEM; |
| 18255 | } |
| 18256 | |
| 18257 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - |
| 18258 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 18259 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 18260 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, |
| 18261 | length, LPFC_SLI4_MBX_EMBED); |
| 18262 | |
| 18263 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; |
| 18264 | /* Set count to 0 for invalidating the entire FCF database */ |
| 18265 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); |
| 18266 | |
| 18267 | /* Issue the mailbox command asynchronously */ |
| 18268 | mbox->vport = phba->pport; |
| 18269 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; |
| 18270 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 18271 | |
| 18272 | if (rc == MBX_NOT_FINISHED) { |
| 18273 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18274 | return -EIO; |
| 18275 | } |
| 18276 | return 0; |
| 18277 | } |
| 18278 | |
| 18279 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 18280 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event |
| 18281 | * @phba: pointer to lpfc hba data structure. |
| 18282 | * |
| 18283 | * This function is the failover routine as a last resort to the FCF DEAD |
| 18284 | * event when driver failed to perform fast FCF failover. |
| 18285 | **/ |
| 18286 | void |
| 18287 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) |
| 18288 | { |
| 18289 | uint32_t link_state; |
| 18290 | |
| 18291 | /* |
| 18292 | * Last resort as FCF DEAD event failover will treat this as |
| 18293 | * a link down, but save the link state because we don't want |
| 18294 | * it to be changed to Link Down unless it is already down. |
| 18295 | */ |
| 18296 | link_state = phba->link_state; |
| 18297 | lpfc_linkdown(phba); |
| 18298 | phba->link_state = link_state; |
| 18299 | |
| 18300 | /* Unregister FCF if no devices connected to it */ |
| 18301 | lpfc_unregister_unused_fcf(phba); |
| 18302 | } |
| 18303 | |
| 18304 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18305 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18306 | * @phba: pointer to lpfc hba data structure. |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18307 | * @rgn23_data: pointer to configure region 23 data. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18308 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18309 | * This function gets SLI3 port configure region 23 data through memory dump |
| 18310 | * mailbox command. When it successfully retrieves data, the size of the data |
| 18311 | * will be returned, otherwise, 0 will be returned. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18312 | **/ |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18313 | static uint32_t |
| 18314 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18315 | { |
| 18316 | LPFC_MBOXQ_t *pmb = NULL; |
| 18317 | MAILBOX_t *mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18318 | uint32_t offset = 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18319 | int rc; |
| 18320 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18321 | if (!rgn23_data) |
| 18322 | return 0; |
| 18323 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18324 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18325 | if (!pmb) { |
| 18326 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18327 | "2600 failed to allocate mailbox memory\n"); |
| 18328 | return 0; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18329 | } |
| 18330 | mb = &pmb->u.mb; |
| 18331 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18332 | do { |
| 18333 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); |
| 18334 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 18335 | |
| 18336 | if (rc != MBX_SUCCESS) { |
| 18337 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18338 | "2601 failed to read config " |
| 18339 | "region 23, rc 0x%x Status 0x%x\n", |
| 18340 | rc, mb->mbxStatus); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18341 | mb->un.varDmp.word_cnt = 0; |
| 18342 | } |
| 18343 | /* |
| 18344 | * dump mem may return a zero when finished or we got a |
| 18345 | * mailbox error, either way we are done. |
| 18346 | */ |
| 18347 | if (mb->un.varDmp.word_cnt == 0) |
| 18348 | break; |
| 18349 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) |
| 18350 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; |
| 18351 | |
| 18352 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18353 | rgn23_data + offset, |
| 18354 | mb->un.varDmp.word_cnt); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18355 | offset += mb->un.varDmp.word_cnt; |
| 18356 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); |
| 18357 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18358 | mempool_free(pmb, phba->mbox_mem_pool); |
| 18359 | return offset; |
| 18360 | } |
| 18361 | |
| 18362 | /** |
| 18363 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. |
| 18364 | * @phba: pointer to lpfc hba data structure. |
| 18365 | * @rgn23_data: pointer to configure region 23 data. |
| 18366 | * |
| 18367 | * This function gets SLI4 port configure region 23 data through memory dump |
| 18368 | * mailbox command. When it successfully retrieves data, the size of the data |
| 18369 | * will be returned, otherwise, 0 will be returned. |
| 18370 | **/ |
| 18371 | static uint32_t |
| 18372 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) |
| 18373 | { |
| 18374 | LPFC_MBOXQ_t *mboxq = NULL; |
| 18375 | struct lpfc_dmabuf *mp = NULL; |
| 18376 | struct lpfc_mqe *mqe; |
| 18377 | uint32_t data_length = 0; |
| 18378 | int rc; |
| 18379 | |
| 18380 | if (!rgn23_data) |
| 18381 | return 0; |
| 18382 | |
| 18383 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18384 | if (!mboxq) { |
| 18385 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18386 | "3105 failed to allocate mailbox memory\n"); |
| 18387 | return 0; |
| 18388 | } |
| 18389 | |
| 18390 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) |
| 18391 | goto out; |
| 18392 | mqe = &mboxq->u.mqe; |
| 18393 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
| 18394 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 18395 | if (rc) |
| 18396 | goto out; |
| 18397 | data_length = mqe->un.mb_words[5]; |
| 18398 | if (data_length == 0) |
| 18399 | goto out; |
| 18400 | if (data_length > DMP_RGN23_SIZE) { |
| 18401 | data_length = 0; |
| 18402 | goto out; |
| 18403 | } |
| 18404 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); |
| 18405 | out: |
| 18406 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 18407 | if (mp) { |
| 18408 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 18409 | kfree(mp); |
| 18410 | } |
| 18411 | return data_length; |
| 18412 | } |
| 18413 | |
| 18414 | /** |
| 18415 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. |
| 18416 | * @phba: pointer to lpfc hba data structure. |
| 18417 | * |
| 18418 | * This function read region 23 and parse TLV for port status to |
| 18419 | * decide if the user disaled the port. If the TLV indicates the |
| 18420 | * port is disabled, the hba_flag is set accordingly. |
| 18421 | **/ |
| 18422 | void |
| 18423 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) |
| 18424 | { |
| 18425 | uint8_t *rgn23_data = NULL; |
| 18426 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; |
| 18427 | uint32_t offset = 0; |
| 18428 | |
| 18429 | /* Get adapter Region 23 data */ |
| 18430 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); |
| 18431 | if (!rgn23_data) |
| 18432 | goto out; |
| 18433 | |
| 18434 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 18435 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); |
| 18436 | else { |
| 18437 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 18438 | &phba->sli4_hba.sli_intf); |
| 18439 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) |
| 18440 | goto out; |
| 18441 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); |
| 18442 | } |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18443 | |
| 18444 | if (!data_size) |
| 18445 | goto out; |
| 18446 | |
| 18447 | /* Check the region signature first */ |
| 18448 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { |
| 18449 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18450 | "2619 Config region 23 has bad signature\n"); |
| 18451 | goto out; |
| 18452 | } |
| 18453 | offset += 4; |
| 18454 | |
| 18455 | /* Check the data structure version */ |
| 18456 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { |
| 18457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18458 | "2620 Config region 23 has bad version\n"); |
| 18459 | goto out; |
| 18460 | } |
| 18461 | offset += 4; |
| 18462 | |
| 18463 | /* Parse TLV entries in the region */ |
| 18464 | while (offset < data_size) { |
| 18465 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) |
| 18466 | break; |
| 18467 | /* |
| 18468 | * If the TLV is not driver specific TLV or driver id is |
| 18469 | * not linux driver id, skip the record. |
| 18470 | */ |
| 18471 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || |
| 18472 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || |
| 18473 | (rgn23_data[offset + 3] != 0)) { |
| 18474 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 18475 | continue; |
| 18476 | } |
| 18477 | |
| 18478 | /* Driver found a driver specific TLV in the config region */ |
| 18479 | sub_tlv_len = rgn23_data[offset + 1] * 4; |
| 18480 | offset += 4; |
| 18481 | tlv_offset = 0; |
| 18482 | |
| 18483 | /* |
| 18484 | * Search for configured port state sub-TLV. |
| 18485 | */ |
| 18486 | while ((offset < data_size) && |
| 18487 | (tlv_offset < sub_tlv_len)) { |
| 18488 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { |
| 18489 | offset += 4; |
| 18490 | tlv_offset += 4; |
| 18491 | break; |
| 18492 | } |
| 18493 | if (rgn23_data[offset] != PORT_STE_TYPE) { |
| 18494 | offset += rgn23_data[offset + 1] * 4 + 4; |
| 18495 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; |
| 18496 | continue; |
| 18497 | } |
| 18498 | |
| 18499 | /* This HBA contains PORT_STE configured */ |
| 18500 | if (!rgn23_data[offset + 2]) |
| 18501 | phba->hba_flag |= LINK_DISABLED; |
| 18502 | |
| 18503 | goto out; |
| 18504 | } |
| 18505 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 18506 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18507 | out: |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 18508 | kfree(rgn23_data); |
| 18509 | return; |
| 18510 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18511 | |
| 18512 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 18513 | * lpfc_wr_object - write an object to the firmware |
| 18514 | * @phba: HBA structure that indicates port to create a queue on. |
| 18515 | * @dmabuf_list: list of dmabufs to write to the port. |
| 18516 | * @size: the total byte value of the objects to write to the port. |
| 18517 | * @offset: the current offset to be used to start the transfer. |
| 18518 | * |
| 18519 | * This routine will create a wr_object mailbox command to send to the port. |
| 18520 | * the mailbox command will be constructed using the dma buffers described in |
| 18521 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many |
| 18522 | * BDEs that the imbedded mailbox can support. The @offset variable will be |
| 18523 | * used to indicate the starting offset of the transfer and will also return |
| 18524 | * the offset after the write object mailbox has completed. @size is used to |
| 18525 | * determine the end of the object and whether the eof bit should be set. |
| 18526 | * |
| 18527 | * Return 0 is successful and offset will contain the the new offset to use |
| 18528 | * for the next write. |
| 18529 | * Return negative value for error cases. |
| 18530 | **/ |
| 18531 | int |
| 18532 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, |
| 18533 | uint32_t size, uint32_t *offset) |
| 18534 | { |
| 18535 | struct lpfc_mbx_wr_object *wr_object; |
| 18536 | LPFC_MBOXQ_t *mbox; |
| 18537 | int rc = 0, i = 0; |
| 18538 | uint32_t shdr_status, shdr_add_status; |
| 18539 | uint32_t mbox_tmo; |
| 18540 | union lpfc_sli4_cfg_shdr *shdr; |
| 18541 | struct lpfc_dmabuf *dmabuf; |
| 18542 | uint32_t written = 0; |
| 18543 | |
| 18544 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 18545 | if (!mbox) |
| 18546 | return -ENOMEM; |
| 18547 | |
| 18548 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 18549 | LPFC_MBOX_OPCODE_WRITE_OBJECT, |
| 18550 | sizeof(struct lpfc_mbx_wr_object) - |
| 18551 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
| 18552 | |
| 18553 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; |
| 18554 | wr_object->u.request.write_offset = *offset; |
| 18555 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); |
| 18556 | wr_object->u.request.object_name[0] = |
| 18557 | cpu_to_le32(wr_object->u.request.object_name[0]); |
| 18558 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); |
| 18559 | list_for_each_entry(dmabuf, dmabuf_list, list) { |
| 18560 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) |
| 18561 | break; |
| 18562 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); |
| 18563 | wr_object->u.request.bde[i].addrHigh = |
| 18564 | putPaddrHigh(dmabuf->phys); |
| 18565 | if (written + SLI4_PAGE_SIZE >= size) { |
| 18566 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 18567 | (size - written); |
| 18568 | written += (size - written); |
| 18569 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); |
| 18570 | } else { |
| 18571 | wr_object->u.request.bde[i].tus.f.bdeSize = |
| 18572 | SLI4_PAGE_SIZE; |
| 18573 | written += SLI4_PAGE_SIZE; |
| 18574 | } |
| 18575 | i++; |
| 18576 | } |
| 18577 | wr_object->u.request.bde_count = i; |
| 18578 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); |
| 18579 | if (!phba->sli4_hba.intr_enable) |
| 18580 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); |
| 18581 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 18582 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 18583 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
| 18584 | } |
| 18585 | /* The IOCTL status is embedded in the mailbox subheader. */ |
| 18586 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; |
| 18587 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 18588 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 18589 | if (rc != MBX_TIMEOUT) |
| 18590 | mempool_free(mbox, phba->mbox_mem_pool); |
| 18591 | if (shdr_status || shdr_add_status || rc) { |
| 18592 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 18593 | "3025 Write Object mailbox failed with " |
| 18594 | "status x%x add_status x%x, mbx status x%x\n", |
| 18595 | shdr_status, shdr_add_status, rc); |
| 18596 | rc = -ENXIO; |
| 18597 | } else |
| 18598 | *offset += wr_object->u.response.actual_write_length; |
| 18599 | return rc; |
| 18600 | } |
| 18601 | |
| 18602 | /** |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18603 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. |
| 18604 | * @vport: pointer to vport data structure. |
| 18605 | * |
| 18606 | * This function iterate through the mailboxq and clean up all REG_LOGIN |
| 18607 | * and REG_VPI mailbox commands associated with the vport. This function |
| 18608 | * is called when driver want to restart discovery of the vport due to |
| 18609 | * a Clear Virtual Link event. |
| 18610 | **/ |
| 18611 | void |
| 18612 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) |
| 18613 | { |
| 18614 | struct lpfc_hba *phba = vport->phba; |
| 18615 | LPFC_MBOXQ_t *mb, *nextmb; |
| 18616 | struct lpfc_dmabuf *mp; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18617 | struct lpfc_nodelist *ndlp; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18618 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 18619 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18620 | LIST_HEAD(mbox_cmd_list); |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 18621 | uint8_t restart_loop; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18622 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18623 | /* Clean up internally queued mailbox commands with the vport */ |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18624 | spin_lock_irq(&phba->hbalock); |
| 18625 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
| 18626 | if (mb->vport != vport) |
| 18627 | continue; |
| 18628 | |
| 18629 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 18630 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 18631 | continue; |
| 18632 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18633 | list_del(&mb->list); |
| 18634 | list_add_tail(&mb->list, &mbox_cmd_list); |
| 18635 | } |
| 18636 | /* Clean up active mailbox command with the vport */ |
| 18637 | mb = phba->sli.mbox_active; |
| 18638 | if (mb && (mb->vport == vport)) { |
| 18639 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || |
| 18640 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) |
| 18641 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 18642 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 18643 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; |
| 18644 | /* Put reference count for delayed processing */ |
| 18645 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); |
| 18646 | /* Unregister the RPI when mailbox complete */ |
| 18647 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 18648 | } |
| 18649 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 18650 | /* Cleanup any mailbox completions which are not yet processed */ |
| 18651 | do { |
| 18652 | restart_loop = 0; |
| 18653 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { |
| 18654 | /* |
| 18655 | * If this mailox is already processed or it is |
| 18656 | * for another vport ignore it. |
| 18657 | */ |
| 18658 | if ((mb->vport != vport) || |
| 18659 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) |
| 18660 | continue; |
| 18661 | |
| 18662 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && |
| 18663 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) |
| 18664 | continue; |
| 18665 | |
| 18666 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 18667 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 18668 | ndlp = (struct lpfc_nodelist *)mb->context2; |
| 18669 | /* Unregister the RPI when mailbox complete */ |
| 18670 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 18671 | restart_loop = 1; |
| 18672 | spin_unlock_irq(&phba->hbalock); |
| 18673 | spin_lock(shost->host_lock); |
| 18674 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 18675 | spin_unlock(shost->host_lock); |
| 18676 | spin_lock_irq(&phba->hbalock); |
| 18677 | break; |
| 18678 | } |
| 18679 | } |
| 18680 | } while (restart_loop); |
| 18681 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18682 | spin_unlock_irq(&phba->hbalock); |
| 18683 | |
| 18684 | /* Release the cleaned-up mailbox commands */ |
| 18685 | while (!list_empty(&mbox_cmd_list)) { |
| 18686 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18687 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
| 18688 | mp = (struct lpfc_dmabuf *) (mb->context1); |
| 18689 | if (mp) { |
| 18690 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 18691 | kfree(mp); |
| 18692 | } |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18693 | ndlp = (struct lpfc_nodelist *) mb->context2; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18694 | mb->context2 = NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18695 | if (ndlp) { |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 18696 | spin_lock(shost->host_lock); |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 18697 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
Dan Carpenter | ec21b3b | 2010-08-08 00:15:17 +0200 | [diff] [blame] | 18698 | spin_unlock(shost->host_lock); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18699 | lpfc_nlp_put(ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 18700 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18701 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18702 | mempool_free(mb, phba->mbox_mem_pool); |
| 18703 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 18704 | |
| 18705 | /* Release the ndlp with the cleaned-up active mailbox command */ |
| 18706 | if (act_mbx_ndlp) { |
| 18707 | spin_lock(shost->host_lock); |
| 18708 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
| 18709 | spin_unlock(shost->host_lock); |
| 18710 | lpfc_nlp_put(act_mbx_ndlp); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18711 | } |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 18712 | } |
| 18713 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18714 | /** |
| 18715 | * lpfc_drain_txq - Drain the txq |
| 18716 | * @phba: Pointer to HBA context object. |
| 18717 | * |
| 18718 | * This function attempt to submit IOCBs on the txq |
| 18719 | * to the adapter. For SLI4 adapters, the txq contains |
| 18720 | * ELS IOCBs that have been deferred because the there |
| 18721 | * are no SGLs. This congestion can occur with large |
| 18722 | * vport counts during node discovery. |
| 18723 | **/ |
| 18724 | |
| 18725 | uint32_t |
| 18726 | lpfc_drain_txq(struct lpfc_hba *phba) |
| 18727 | { |
| 18728 | LIST_HEAD(completions); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18729 | struct lpfc_sli_ring *pring; |
Daeseok Youn | 2e70637 | 2014-02-21 09:03:32 +0900 | [diff] [blame] | 18730 | struct lpfc_iocbq *piocbq = NULL; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18731 | unsigned long iflags = 0; |
| 18732 | char *fail_msg = NULL; |
| 18733 | struct lpfc_sglq *sglq; |
James Smart | 2f07784 | 2016-12-19 15:07:29 -0800 | [diff] [blame] | 18734 | union lpfc_wqe128 wqe128; |
| 18735 | union lpfc_wqe *wqe = (union lpfc_wqe *) &wqe128; |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 18736 | uint32_t txq_cnt = 0; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18737 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18738 | pring = lpfc_phba_elsring(phba); |
Dick Kennedy | 1234a6d | 2017-09-29 17:34:29 -0700 | [diff] [blame] | 18739 | if (unlikely(!pring)) |
| 18740 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18741 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18742 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18743 | list_for_each_entry(piocbq, &pring->txq, list) { |
| 18744 | txq_cnt++; |
| 18745 | } |
| 18746 | |
| 18747 | if (txq_cnt > pring->txq_max) |
| 18748 | pring->txq_max = txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18749 | |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18750 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18751 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18752 | while (!list_empty(&pring->txq)) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18753 | spin_lock_irqsave(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18754 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 18755 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 18756 | if (!piocbq) { |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18757 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 18758 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18759 | "2823 txq empty and txq_cnt is %d\n ", |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18760 | txq_cnt); |
James Smart | a629852 | 2012-06-12 13:54:11 -0400 | [diff] [blame] | 18761 | break; |
| 18762 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18763 | sglq = __lpfc_sli_get_els_sglq(phba, piocbq); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18764 | if (!sglq) { |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 18765 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18766 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18767 | break; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18768 | } |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18769 | txq_cnt--; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18770 | |
| 18771 | /* The xri and iocb resources secured, |
| 18772 | * attempt to issue request |
| 18773 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 18774 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18775 | piocbq->sli4_xritag = sglq->sli4_xritag; |
| 18776 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) |
| 18777 | fail_msg = "to convert bpl to sgl"; |
James Smart | 2f07784 | 2016-12-19 15:07:29 -0800 | [diff] [blame] | 18778 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18779 | fail_msg = "to convert iocb to wqe"; |
James Smart | 2f07784 | 2016-12-19 15:07:29 -0800 | [diff] [blame] | 18780 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, wqe)) |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18781 | fail_msg = " - Wq is full"; |
| 18782 | else |
| 18783 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); |
| 18784 | |
| 18785 | if (fail_msg) { |
| 18786 | /* Failed means we can't issue and need to cancel */ |
| 18787 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 18788 | "2822 IOCB failed %s iotag 0x%x " |
| 18789 | "xri 0x%x\n", |
| 18790 | fail_msg, |
| 18791 | piocbq->iotag, piocbq->sli4_xritag); |
| 18792 | list_add_tail(&piocbq->list, &completions); |
| 18793 | } |
James Smart | 398d81c | 2013-05-31 17:04:19 -0400 | [diff] [blame] | 18794 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18795 | } |
| 18796 | |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18797 | /* Cancel all the IOCBs that cannot be issued */ |
| 18798 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, |
| 18799 | IOERR_SLI_ABORTED); |
| 18800 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 18801 | return txq_cnt; |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 18802 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18803 | |
| 18804 | /** |
| 18805 | * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl. |
| 18806 | * @phba: Pointer to HBA context object. |
| 18807 | * @pwqe: Pointer to command WQE. |
| 18808 | * @sglq: Pointer to the scatter gather queue object. |
| 18809 | * |
| 18810 | * This routine converts the bpl or bde that is in the WQE |
| 18811 | * to a sgl list for the sli4 hardware. The physical address |
| 18812 | * of the bpl/bde is converted back to a virtual address. |
| 18813 | * If the WQE contains a BPL then the list of BDE's is |
| 18814 | * converted to sli4_sge's. If the WQE contains a single |
| 18815 | * BDE then it is converted to a single sli_sge. |
| 18816 | * The WQE is still in cpu endianness so the contents of |
| 18817 | * the bpl can be used without byte swapping. |
| 18818 | * |
| 18819 | * Returns valid XRI = Success, NO_XRI = Failure. |
| 18820 | */ |
| 18821 | static uint16_t |
| 18822 | lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq, |
| 18823 | struct lpfc_sglq *sglq) |
| 18824 | { |
| 18825 | uint16_t xritag = NO_XRI; |
| 18826 | struct ulp_bde64 *bpl = NULL; |
| 18827 | struct ulp_bde64 bde; |
| 18828 | struct sli4_sge *sgl = NULL; |
| 18829 | struct lpfc_dmabuf *dmabuf; |
| 18830 | union lpfc_wqe *wqe; |
| 18831 | int numBdes = 0; |
| 18832 | int i = 0; |
| 18833 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
| 18834 | int inbound = 0; /* number of sg reply entries inbound from firmware */ |
| 18835 | uint32_t cmd; |
| 18836 | |
| 18837 | if (!pwqeq || !sglq) |
| 18838 | return xritag; |
| 18839 | |
| 18840 | sgl = (struct sli4_sge *)sglq->sgl; |
| 18841 | wqe = &pwqeq->wqe; |
| 18842 | pwqeq->iocb.ulpIoTag = pwqeq->iotag; |
| 18843 | |
| 18844 | cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com); |
| 18845 | if (cmd == CMD_XMIT_BLS_RSP64_WQE) |
| 18846 | return sglq->sli4_xritag; |
| 18847 | numBdes = pwqeq->rsvd2; |
| 18848 | if (numBdes) { |
| 18849 | /* The addrHigh and addrLow fields within the WQE |
| 18850 | * have not been byteswapped yet so there is no |
| 18851 | * need to swap them back. |
| 18852 | */ |
| 18853 | if (pwqeq->context3) |
| 18854 | dmabuf = (struct lpfc_dmabuf *)pwqeq->context3; |
| 18855 | else |
| 18856 | return xritag; |
| 18857 | |
| 18858 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
| 18859 | if (!bpl) |
| 18860 | return xritag; |
| 18861 | |
| 18862 | for (i = 0; i < numBdes; i++) { |
| 18863 | /* Should already be byte swapped. */ |
| 18864 | sgl->addr_hi = bpl->addrHigh; |
| 18865 | sgl->addr_lo = bpl->addrLow; |
| 18866 | |
| 18867 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 18868 | if ((i+1) == numBdes) |
| 18869 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 18870 | else |
| 18871 | bf_set(lpfc_sli4_sge_last, sgl, 0); |
| 18872 | /* swap the size field back to the cpu so we |
| 18873 | * can assign it to the sgl. |
| 18874 | */ |
| 18875 | bde.tus.w = le32_to_cpu(bpl->tus.w); |
| 18876 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); |
| 18877 | /* The offsets in the sgl need to be accumulated |
| 18878 | * separately for the request and reply lists. |
| 18879 | * The request is always first, the reply follows. |
| 18880 | */ |
| 18881 | switch (cmd) { |
| 18882 | case CMD_GEN_REQUEST64_WQE: |
| 18883 | /* add up the reply sg entries */ |
| 18884 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) |
| 18885 | inbound++; |
| 18886 | /* first inbound? reset the offset */ |
| 18887 | if (inbound == 1) |
| 18888 | offset = 0; |
| 18889 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 18890 | bf_set(lpfc_sli4_sge_type, sgl, |
| 18891 | LPFC_SGE_TYPE_DATA); |
| 18892 | offset += bde.tus.f.bdeSize; |
| 18893 | break; |
| 18894 | case CMD_FCP_TRSP64_WQE: |
| 18895 | bf_set(lpfc_sli4_sge_offset, sgl, 0); |
| 18896 | bf_set(lpfc_sli4_sge_type, sgl, |
| 18897 | LPFC_SGE_TYPE_DATA); |
| 18898 | break; |
| 18899 | case CMD_FCP_TSEND64_WQE: |
| 18900 | case CMD_FCP_TRECEIVE64_WQE: |
| 18901 | bf_set(lpfc_sli4_sge_type, sgl, |
| 18902 | bpl->tus.f.bdeFlags); |
| 18903 | if (i < 3) |
| 18904 | offset = 0; |
| 18905 | else |
| 18906 | offset += bde.tus.f.bdeSize; |
| 18907 | bf_set(lpfc_sli4_sge_offset, sgl, offset); |
| 18908 | break; |
| 18909 | } |
| 18910 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 18911 | bpl++; |
| 18912 | sgl++; |
| 18913 | } |
| 18914 | } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) { |
| 18915 | /* The addrHigh and addrLow fields of the BDE have not |
| 18916 | * been byteswapped yet so they need to be swapped |
| 18917 | * before putting them in the sgl. |
| 18918 | */ |
| 18919 | sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh); |
| 18920 | sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow); |
| 18921 | sgl->word2 = le32_to_cpu(sgl->word2); |
| 18922 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
| 18923 | sgl->word2 = cpu_to_le32(sgl->word2); |
| 18924 | sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize); |
| 18925 | } |
| 18926 | return sglq->sli4_xritag; |
| 18927 | } |
| 18928 | |
| 18929 | /** |
| 18930 | * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE) |
| 18931 | * @phba: Pointer to HBA context object. |
| 18932 | * @ring_number: Base sli ring number |
| 18933 | * @pwqe: Pointer to command WQE. |
| 18934 | **/ |
| 18935 | int |
| 18936 | lpfc_sli4_issue_wqe(struct lpfc_hba *phba, uint32_t ring_number, |
| 18937 | struct lpfc_iocbq *pwqe) |
| 18938 | { |
| 18939 | union lpfc_wqe *wqe = &pwqe->wqe; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 18940 | struct lpfc_nvmet_rcv_ctx *ctxp; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18941 | struct lpfc_queue *wq; |
| 18942 | struct lpfc_sglq *sglq; |
| 18943 | struct lpfc_sli_ring *pring; |
| 18944 | unsigned long iflags; |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18945 | uint32_t ret = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18946 | |
| 18947 | /* NVME_LS and NVME_LS ABTS requests. */ |
| 18948 | if (pwqe->iocb_flag & LPFC_IO_NVME_LS) { |
| 18949 | pring = phba->sli4_hba.nvmels_wq->pring; |
| 18950 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 18951 | sglq = __lpfc_sli_get_els_sglq(phba, pwqe); |
| 18952 | if (!sglq) { |
| 18953 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 18954 | return WQE_BUSY; |
| 18955 | } |
| 18956 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 18957 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 18958 | if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) { |
| 18959 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 18960 | return WQE_ERROR; |
| 18961 | } |
| 18962 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 18963 | pwqe->sli4_xritag); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18964 | ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe); |
| 18965 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18966 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18967 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18968 | } |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18969 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18970 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 18971 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 18972 | return 0; |
| 18973 | } |
| 18974 | |
| 18975 | /* NVME_FCREQ and NVME_ABTS requests */ |
| 18976 | if (pwqe->iocb_flag & LPFC_IO_NVME) { |
| 18977 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
| 18978 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; |
| 18979 | |
| 18980 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 18981 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; |
| 18982 | bf_set(wqe_cqid, &wqe->generic.wqe_com, |
| 18983 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18984 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 18985 | if (ret) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18986 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 18987 | return ret; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 18988 | } |
| 18989 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 18990 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 18991 | return 0; |
| 18992 | } |
| 18993 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 18994 | /* NVMET requests */ |
| 18995 | if (pwqe->iocb_flag & LPFC_IO_NVMET) { |
| 18996 | /* Get the IO distribution (hba_wqidx) for WQ assignment. */ |
| 18997 | pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring; |
| 18998 | |
| 18999 | spin_lock_irqsave(&pring->ring_lock, iflags); |
| 19000 | ctxp = pwqe->context2; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 19001 | sglq = ctxp->ctxbuf->sglq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19002 | if (pwqe->sli4_xritag == NO_XRI) { |
| 19003 | pwqe->sli4_lxritag = sglq->sli4_lxritag; |
| 19004 | pwqe->sli4_xritag = sglq->sli4_xritag; |
| 19005 | } |
| 19006 | bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com, |
| 19007 | pwqe->sli4_xritag); |
| 19008 | wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]; |
| 19009 | bf_set(wqe_cqid, &wqe->generic.wqe_com, |
| 19010 | phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19011 | ret = lpfc_sli4_wq_put(wq, wqe); |
| 19012 | if (ret) { |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19013 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
Dick Kennedy | cd22d60 | 2017-08-23 16:55:35 -0700 | [diff] [blame] | 19014 | return ret; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 19015 | } |
| 19016 | lpfc_sli_ringtxcmpl_put(phba, pring, pwqe); |
| 19017 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
| 19018 | return 0; |
| 19019 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 19020 | return WQE_ERROR; |
| 19021 | } |