Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. |
| 3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you may redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 16 | * SOFTWARE. |
| 17 | */ |
| 18 | #include <linux/mempool.h> |
| 19 | #include <linux/errno.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/workqueue.h> |
| 22 | #include <linux/pci.h> |
| 23 | #include <linux/scatterlist.h> |
| 24 | #include <linux/skbuff.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/if_ether.h> |
| 27 | #include <linux/if_vlan.h> |
| 28 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/gfp.h> |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 30 | #include <scsi/scsi.h> |
| 31 | #include <scsi/scsi_host.h> |
| 32 | #include <scsi/scsi_device.h> |
| 33 | #include <scsi/scsi_cmnd.h> |
| 34 | #include <scsi/scsi_tcq.h> |
| 35 | #include <scsi/fc/fc_els.h> |
| 36 | #include <scsi/fc/fc_fcoe.h> |
| 37 | #include <scsi/libfc.h> |
| 38 | #include <scsi/fc_frame.h> |
| 39 | #include "fnic_io.h" |
| 40 | #include "fnic.h" |
| 41 | |
| 42 | const char *fnic_state_str[] = { |
| 43 | [FNIC_IN_FC_MODE] = "FNIC_IN_FC_MODE", |
| 44 | [FNIC_IN_FC_TRANS_ETH_MODE] = "FNIC_IN_FC_TRANS_ETH_MODE", |
| 45 | [FNIC_IN_ETH_MODE] = "FNIC_IN_ETH_MODE", |
| 46 | [FNIC_IN_ETH_TRANS_FC_MODE] = "FNIC_IN_ETH_TRANS_FC_MODE", |
| 47 | }; |
| 48 | |
| 49 | static const char *fnic_ioreq_state_str[] = { |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 50 | [FNIC_IOREQ_NOT_INITED] = "FNIC_IOREQ_NOT_INITED", |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 51 | [FNIC_IOREQ_CMD_PENDING] = "FNIC_IOREQ_CMD_PENDING", |
| 52 | [FNIC_IOREQ_ABTS_PENDING] = "FNIC_IOREQ_ABTS_PENDING", |
| 53 | [FNIC_IOREQ_ABTS_COMPLETE] = "FNIC_IOREQ_ABTS_COMPLETE", |
| 54 | [FNIC_IOREQ_CMD_COMPLETE] = "FNIC_IOREQ_CMD_COMPLETE", |
| 55 | }; |
| 56 | |
| 57 | static const char *fcpio_status_str[] = { |
| 58 | [FCPIO_SUCCESS] = "FCPIO_SUCCESS", /*0x0*/ |
| 59 | [FCPIO_INVALID_HEADER] = "FCPIO_INVALID_HEADER", |
| 60 | [FCPIO_OUT_OF_RESOURCE] = "FCPIO_OUT_OF_RESOURCE", |
| 61 | [FCPIO_INVALID_PARAM] = "FCPIO_INVALID_PARAM]", |
| 62 | [FCPIO_REQ_NOT_SUPPORTED] = "FCPIO_REQ_NOT_SUPPORTED", |
| 63 | [FCPIO_IO_NOT_FOUND] = "FCPIO_IO_NOT_FOUND", |
| 64 | [FCPIO_ABORTED] = "FCPIO_ABORTED", /*0x41*/ |
| 65 | [FCPIO_TIMEOUT] = "FCPIO_TIMEOUT", |
| 66 | [FCPIO_SGL_INVALID] = "FCPIO_SGL_INVALID", |
| 67 | [FCPIO_MSS_INVALID] = "FCPIO_MSS_INVALID", |
| 68 | [FCPIO_DATA_CNT_MISMATCH] = "FCPIO_DATA_CNT_MISMATCH", |
| 69 | [FCPIO_FW_ERR] = "FCPIO_FW_ERR", |
| 70 | [FCPIO_ITMF_REJECTED] = "FCPIO_ITMF_REJECTED", |
| 71 | [FCPIO_ITMF_FAILED] = "FCPIO_ITMF_FAILED", |
| 72 | [FCPIO_ITMF_INCORRECT_LUN] = "FCPIO_ITMF_INCORRECT_LUN", |
| 73 | [FCPIO_CMND_REJECTED] = "FCPIO_CMND_REJECTED", |
| 74 | [FCPIO_NO_PATH_AVAIL] = "FCPIO_NO_PATH_AVAIL", |
| 75 | [FCPIO_PATH_FAILED] = "FCPIO_PATH_FAILED", |
| 76 | [FCPIO_LUNMAP_CHNG_PEND] = "FCPIO_LUNHMAP_CHNG_PEND", |
| 77 | }; |
| 78 | |
| 79 | const char *fnic_state_to_str(unsigned int state) |
| 80 | { |
| 81 | if (state >= ARRAY_SIZE(fnic_state_str) || !fnic_state_str[state]) |
| 82 | return "unknown"; |
| 83 | |
| 84 | return fnic_state_str[state]; |
| 85 | } |
| 86 | |
| 87 | static const char *fnic_ioreq_state_to_str(unsigned int state) |
| 88 | { |
| 89 | if (state >= ARRAY_SIZE(fnic_ioreq_state_str) || |
| 90 | !fnic_ioreq_state_str[state]) |
| 91 | return "unknown"; |
| 92 | |
| 93 | return fnic_ioreq_state_str[state]; |
| 94 | } |
| 95 | |
| 96 | static const char *fnic_fcpio_status_to_str(unsigned int status) |
| 97 | { |
| 98 | if (status >= ARRAY_SIZE(fcpio_status_str) || !fcpio_status_str[status]) |
| 99 | return "unknown"; |
| 100 | |
| 101 | return fcpio_status_str[status]; |
| 102 | } |
| 103 | |
| 104 | static void fnic_cleanup_io(struct fnic *fnic, int exclude_id); |
| 105 | |
| 106 | static inline spinlock_t *fnic_io_lock_hash(struct fnic *fnic, |
| 107 | struct scsi_cmnd *sc) |
| 108 | { |
| 109 | u32 hash = sc->request->tag & (FNIC_IO_LOCKS - 1); |
| 110 | |
| 111 | return &fnic->io_req_lock[hash]; |
| 112 | } |
| 113 | |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 114 | static inline spinlock_t *fnic_io_lock_tag(struct fnic *fnic, |
| 115 | int tag) |
| 116 | { |
| 117 | return &fnic->io_req_lock[tag & (FNIC_IO_LOCKS - 1)]; |
| 118 | } |
| 119 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 120 | /* |
| 121 | * Unmap the data buffer and sense buffer for an io_req, |
| 122 | * also unmap and free the device-private scatter/gather list. |
| 123 | */ |
| 124 | static void fnic_release_ioreq_buf(struct fnic *fnic, |
| 125 | struct fnic_io_req *io_req, |
| 126 | struct scsi_cmnd *sc) |
| 127 | { |
| 128 | if (io_req->sgl_list_pa) |
| 129 | pci_unmap_single(fnic->pdev, io_req->sgl_list_pa, |
| 130 | sizeof(io_req->sgl_list[0]) * io_req->sgl_cnt, |
| 131 | PCI_DMA_TODEVICE); |
| 132 | scsi_dma_unmap(sc); |
| 133 | |
| 134 | if (io_req->sgl_cnt) |
| 135 | mempool_free(io_req->sgl_list_alloc, |
| 136 | fnic->io_sgl_pool[io_req->sgl_type]); |
| 137 | if (io_req->sense_buf_pa) |
| 138 | pci_unmap_single(fnic->pdev, io_req->sense_buf_pa, |
| 139 | SCSI_SENSE_BUFFERSIZE, PCI_DMA_FROMDEVICE); |
| 140 | } |
| 141 | |
| 142 | /* Free up Copy Wq descriptors. Called with copy_wq lock held */ |
| 143 | static int free_wq_copy_descs(struct fnic *fnic, struct vnic_wq_copy *wq) |
| 144 | { |
| 145 | /* if no Ack received from firmware, then nothing to clean */ |
| 146 | if (!fnic->fw_ack_recd[0]) |
| 147 | return 1; |
| 148 | |
| 149 | /* |
| 150 | * Update desc_available count based on number of freed descriptors |
| 151 | * Account for wraparound |
| 152 | */ |
| 153 | if (wq->to_clean_index <= fnic->fw_ack_index[0]) |
| 154 | wq->ring.desc_avail += (fnic->fw_ack_index[0] |
| 155 | - wq->to_clean_index + 1); |
| 156 | else |
| 157 | wq->ring.desc_avail += (wq->ring.desc_count |
| 158 | - wq->to_clean_index |
| 159 | + fnic->fw_ack_index[0] + 1); |
| 160 | |
| 161 | /* |
| 162 | * just bump clean index to ack_index+1 accounting for wraparound |
| 163 | * this will essentially free up all descriptors between |
| 164 | * to_clean_index and fw_ack_index, both inclusive |
| 165 | */ |
| 166 | wq->to_clean_index = |
| 167 | (fnic->fw_ack_index[0] + 1) % wq->ring.desc_count; |
| 168 | |
| 169 | /* we have processed the acks received so far */ |
| 170 | fnic->fw_ack_recd[0] = 0; |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 175 | /** |
| 176 | * __fnic_set_state_flags |
| 177 | * Sets/Clears bits in fnic's state_flags |
| 178 | **/ |
| 179 | void |
| 180 | __fnic_set_state_flags(struct fnic *fnic, unsigned long st_flags, |
| 181 | unsigned long clearbits) |
| 182 | { |
| 183 | struct Scsi_Host *host = fnic->lport->host; |
| 184 | int sh_locked = spin_is_locked(host->host_lock); |
| 185 | unsigned long flags = 0; |
| 186 | |
| 187 | if (!sh_locked) |
| 188 | spin_lock_irqsave(host->host_lock, flags); |
| 189 | |
| 190 | if (clearbits) |
| 191 | fnic->state_flags &= ~st_flags; |
| 192 | else |
| 193 | fnic->state_flags |= st_flags; |
| 194 | |
| 195 | if (!sh_locked) |
| 196 | spin_unlock_irqrestore(host->host_lock, flags); |
| 197 | |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 202 | /* |
| 203 | * fnic_fw_reset_handler |
| 204 | * Routine to send reset msg to fw |
| 205 | */ |
| 206 | int fnic_fw_reset_handler(struct fnic *fnic) |
| 207 | { |
| 208 | struct vnic_wq_copy *wq = &fnic->wq_copy[0]; |
| 209 | int ret = 0; |
| 210 | unsigned long flags; |
| 211 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 212 | /* indicate fwreset to io path */ |
| 213 | fnic_set_state_flags(fnic, FNIC_FLAGS_FWRESET); |
| 214 | |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 215 | skb_queue_purge(&fnic->frame_queue); |
| 216 | skb_queue_purge(&fnic->tx_queue); |
| 217 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 218 | /* wait for io cmpl */ |
| 219 | while (atomic_read(&fnic->in_flight)) |
| 220 | schedule_timeout(msecs_to_jiffies(1)); |
| 221 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 222 | spin_lock_irqsave(&fnic->wq_copy_lock[0], flags); |
| 223 | |
| 224 | if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0]) |
| 225 | free_wq_copy_descs(fnic, wq); |
| 226 | |
| 227 | if (!vnic_wq_copy_desc_avail(wq)) |
| 228 | ret = -EAGAIN; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 229 | else { |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 230 | fnic_queue_wq_copy_desc_fw_reset(wq, SCSI_NO_TAG); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 231 | atomic64_inc(&fnic->fnic_stats.fw_stats.active_fw_reqs); |
| 232 | if (atomic64_read(&fnic->fnic_stats.fw_stats.active_fw_reqs) > |
| 233 | atomic64_read(&fnic->fnic_stats.fw_stats.max_fw_reqs)) |
| 234 | atomic64_set(&fnic->fnic_stats.fw_stats.max_fw_reqs, |
| 235 | atomic64_read( |
| 236 | &fnic->fnic_stats.fw_stats.active_fw_reqs)); |
| 237 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 238 | |
| 239 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags); |
| 240 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 241 | if (!ret) { |
| 242 | atomic64_inc(&fnic->fnic_stats.reset_stats.fw_resets); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 243 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 244 | "Issued fw reset\n"); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 245 | } else { |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 246 | fnic_clear_state_flags(fnic, FNIC_FLAGS_FWRESET); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 247 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 248 | "Failed to issue fw reset\n"); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 249 | } |
| 250 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 251 | return ret; |
| 252 | } |
| 253 | |
| 254 | |
| 255 | /* |
| 256 | * fnic_flogi_reg_handler |
| 257 | * Routine to send flogi register msg to fw |
| 258 | */ |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 259 | int fnic_flogi_reg_handler(struct fnic *fnic, u32 fc_id) |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 260 | { |
| 261 | struct vnic_wq_copy *wq = &fnic->wq_copy[0]; |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 262 | enum fcpio_flogi_reg_format_type format; |
| 263 | struct fc_lport *lp = fnic->lport; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 264 | u8 gw_mac[ETH_ALEN]; |
| 265 | int ret = 0; |
| 266 | unsigned long flags; |
| 267 | |
| 268 | spin_lock_irqsave(&fnic->wq_copy_lock[0], flags); |
| 269 | |
| 270 | if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0]) |
| 271 | free_wq_copy_descs(fnic, wq); |
| 272 | |
| 273 | if (!vnic_wq_copy_desc_avail(wq)) { |
| 274 | ret = -EAGAIN; |
| 275 | goto flogi_reg_ioreq_end; |
| 276 | } |
| 277 | |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 278 | if (fnic->ctlr.map_dest) { |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 279 | memset(gw_mac, 0xff, ETH_ALEN); |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 280 | format = FCPIO_FLOGI_REG_DEF_DEST; |
| 281 | } else { |
| 282 | memcpy(gw_mac, fnic->ctlr.dest_addr, ETH_ALEN); |
| 283 | format = FCPIO_FLOGI_REG_GW_DEST; |
| 284 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 285 | |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 286 | if ((fnic->config.flags & VFCF_FIP_CAPABLE) && !fnic->ctlr.map_dest) { |
| 287 | fnic_queue_wq_copy_desc_fip_reg(wq, SCSI_NO_TAG, |
| 288 | fc_id, gw_mac, |
| 289 | fnic->data_src_addr, |
| 290 | lp->r_a_tov, lp->e_d_tov); |
| 291 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 292 | "FLOGI FIP reg issued fcid %x src %pM dest %pM\n", |
| 293 | fc_id, fnic->data_src_addr, gw_mac); |
| 294 | } else { |
| 295 | fnic_queue_wq_copy_desc_flogi_reg(wq, SCSI_NO_TAG, |
| 296 | format, fc_id, gw_mac); |
| 297 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 298 | "FLOGI reg issued fcid %x map %d dest %pM\n", |
| 299 | fc_id, fnic->ctlr.map_dest, gw_mac); |
| 300 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 301 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 302 | atomic64_inc(&fnic->fnic_stats.fw_stats.active_fw_reqs); |
| 303 | if (atomic64_read(&fnic->fnic_stats.fw_stats.active_fw_reqs) > |
| 304 | atomic64_read(&fnic->fnic_stats.fw_stats.max_fw_reqs)) |
| 305 | atomic64_set(&fnic->fnic_stats.fw_stats.max_fw_reqs, |
| 306 | atomic64_read(&fnic->fnic_stats.fw_stats.active_fw_reqs)); |
| 307 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 308 | flogi_reg_ioreq_end: |
| 309 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 310 | return ret; |
| 311 | } |
| 312 | |
| 313 | /* |
| 314 | * fnic_queue_wq_copy_desc |
| 315 | * Routine to enqueue a wq copy desc |
| 316 | */ |
| 317 | static inline int fnic_queue_wq_copy_desc(struct fnic *fnic, |
| 318 | struct vnic_wq_copy *wq, |
| 319 | struct fnic_io_req *io_req, |
| 320 | struct scsi_cmnd *sc, |
Roel Kluin | 87a2d34 | 2009-06-23 01:06:40 +0200 | [diff] [blame] | 321 | int sg_count) |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 322 | { |
| 323 | struct scatterlist *sg; |
| 324 | struct fc_rport *rport = starget_to_rport(scsi_target(sc->device)); |
| 325 | struct fc_rport_libfc_priv *rp = rport->dd_data; |
| 326 | struct host_sg_desc *desc; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 327 | struct misc_stats *misc_stats = &fnic->fnic_stats.misc_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 328 | unsigned int i; |
| 329 | unsigned long intr_flags; |
| 330 | int flags; |
| 331 | u8 exch_flags; |
| 332 | struct scsi_lun fc_lun; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 333 | |
| 334 | if (sg_count) { |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 335 | /* For each SGE, create a device desc entry */ |
| 336 | desc = io_req->sgl_list; |
| 337 | for_each_sg(scsi_sglist(sc), sg, sg_count, i) { |
| 338 | desc->addr = cpu_to_le64(sg_dma_address(sg)); |
| 339 | desc->len = cpu_to_le32(sg_dma_len(sg)); |
| 340 | desc->_resvd = 0; |
| 341 | desc++; |
| 342 | } |
| 343 | |
| 344 | io_req->sgl_list_pa = pci_map_single |
| 345 | (fnic->pdev, |
| 346 | io_req->sgl_list, |
| 347 | sizeof(io_req->sgl_list[0]) * sg_count, |
| 348 | PCI_DMA_TODEVICE); |
| 349 | } |
| 350 | |
| 351 | io_req->sense_buf_pa = pci_map_single(fnic->pdev, |
| 352 | sc->sense_buffer, |
| 353 | SCSI_SENSE_BUFFERSIZE, |
| 354 | PCI_DMA_FROMDEVICE); |
| 355 | |
| 356 | int_to_scsilun(sc->device->lun, &fc_lun); |
| 357 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 358 | /* Enqueue the descriptor in the Copy WQ */ |
| 359 | spin_lock_irqsave(&fnic->wq_copy_lock[0], intr_flags); |
| 360 | |
| 361 | if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0]) |
| 362 | free_wq_copy_descs(fnic, wq); |
| 363 | |
| 364 | if (unlikely(!vnic_wq_copy_desc_avail(wq))) { |
| 365 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], intr_flags); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 366 | FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, |
| 367 | "fnic_queue_wq_copy_desc failure - no descriptors\n"); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 368 | atomic64_inc(&misc_stats->io_cpwq_alloc_failures); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 369 | return SCSI_MLQUEUE_HOST_BUSY; |
| 370 | } |
| 371 | |
| 372 | flags = 0; |
| 373 | if (sc->sc_data_direction == DMA_FROM_DEVICE) |
| 374 | flags = FCPIO_ICMND_RDDATA; |
| 375 | else if (sc->sc_data_direction == DMA_TO_DEVICE) |
| 376 | flags = FCPIO_ICMND_WRDATA; |
| 377 | |
| 378 | exch_flags = 0; |
| 379 | if ((fnic->config.flags & VFCF_FCP_SEQ_LVL_ERR) && |
| 380 | (rp->flags & FC_RP_FLAGS_RETRY)) |
| 381 | exch_flags |= FCPIO_ICMND_SRFLAG_RETRY; |
| 382 | |
| 383 | fnic_queue_wq_copy_desc_icmnd_16(wq, sc->request->tag, |
| 384 | 0, exch_flags, io_req->sgl_cnt, |
| 385 | SCSI_SENSE_BUFFERSIZE, |
| 386 | io_req->sgl_list_pa, |
| 387 | io_req->sense_buf_pa, |
| 388 | 0, /* scsi cmd ref, always 0 */ |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame^] | 389 | FCPIO_ICMND_PTA_SIMPLE, |
| 390 | /* scsi pri and tag */ |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 391 | flags, /* command flags */ |
Abhijeet Joglekar | 4b53662 | 2009-10-21 16:28:25 -0700 | [diff] [blame] | 392 | sc->cmnd, sc->cmd_len, |
| 393 | scsi_bufflen(sc), |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 394 | fc_lun.scsi_lun, io_req->port_id, |
| 395 | rport->maxframe_size, rp->r_a_tov, |
| 396 | rp->e_d_tov); |
| 397 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 398 | atomic64_inc(&fnic->fnic_stats.fw_stats.active_fw_reqs); |
| 399 | if (atomic64_read(&fnic->fnic_stats.fw_stats.active_fw_reqs) > |
| 400 | atomic64_read(&fnic->fnic_stats.fw_stats.max_fw_reqs)) |
| 401 | atomic64_set(&fnic->fnic_stats.fw_stats.max_fw_reqs, |
| 402 | atomic64_read(&fnic->fnic_stats.fw_stats.active_fw_reqs)); |
| 403 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 404 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], intr_flags); |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | /* |
| 409 | * fnic_queuecommand |
| 410 | * Routine to send a scsi cdb |
| 411 | * Called with host_lock held and interrupts disabled. |
| 412 | */ |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 413 | static int fnic_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *)) |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 414 | { |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 415 | struct fc_lport *lp = shost_priv(sc->device->host); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 416 | struct fc_rport *rport; |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 417 | struct fnic_io_req *io_req = NULL; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 418 | struct fnic *fnic = lport_priv(lp); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 419 | struct fnic_stats *fnic_stats = &fnic->fnic_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 420 | struct vnic_wq_copy *wq; |
| 421 | int ret; |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 422 | u64 cmd_trace; |
| 423 | int sg_count = 0; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 424 | unsigned long flags; |
| 425 | unsigned long ptr; |
| 426 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 427 | if (unlikely(fnic_chk_state_flags_locked(fnic, FNIC_FLAGS_IO_BLOCKED))) |
| 428 | return SCSI_MLQUEUE_HOST_BUSY; |
| 429 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 430 | rport = starget_to_rport(scsi_target(sc->device)); |
| 431 | ret = fc_remote_port_chkready(rport); |
| 432 | if (ret) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 433 | atomic64_inc(&fnic_stats->misc_stats.rport_not_ready); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 434 | sc->result = ret; |
| 435 | done(sc); |
| 436 | return 0; |
| 437 | } |
| 438 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 439 | if (lp->state != LPORT_ST_READY || !(lp->link_up)) |
| 440 | return SCSI_MLQUEUE_HOST_BUSY; |
| 441 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 442 | atomic_inc(&fnic->in_flight); |
| 443 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 444 | /* |
| 445 | * Release host lock, use driver resource specific locks from here. |
| 446 | * Don't re-enable interrupts in case they were disabled prior to the |
| 447 | * caller disabling them. |
| 448 | */ |
| 449 | spin_unlock(lp->host->host_lock); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 450 | CMD_STATE(sc) = FNIC_IOREQ_NOT_INITED; |
| 451 | CMD_FLAGS(sc) = FNIC_NO_FLAGS; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 452 | |
| 453 | /* Get a new io_req for this SCSI IO */ |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 454 | io_req = mempool_alloc(fnic->io_req_pool, GFP_ATOMIC); |
| 455 | if (!io_req) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 456 | atomic64_inc(&fnic_stats->io_stats.alloc_failures); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 457 | ret = SCSI_MLQUEUE_HOST_BUSY; |
| 458 | goto out; |
| 459 | } |
| 460 | memset(io_req, 0, sizeof(*io_req)); |
| 461 | |
| 462 | /* Map the data buffer */ |
| 463 | sg_count = scsi_dma_map(sc); |
| 464 | if (sg_count < 0) { |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 465 | FNIC_TRACE(fnic_queuecommand, sc->device->host->host_no, |
| 466 | sc->request->tag, sc, 0, sc->cmnd[0], |
| 467 | sg_count, CMD_STATE(sc)); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 468 | mempool_free(io_req, fnic->io_req_pool); |
| 469 | goto out; |
| 470 | } |
| 471 | |
| 472 | /* Determine the type of scatter/gather list we need */ |
| 473 | io_req->sgl_cnt = sg_count; |
| 474 | io_req->sgl_type = FNIC_SGL_CACHE_DFLT; |
| 475 | if (sg_count > FNIC_DFLT_SG_DESC_CNT) |
| 476 | io_req->sgl_type = FNIC_SGL_CACHE_MAX; |
| 477 | |
| 478 | if (sg_count) { |
| 479 | io_req->sgl_list = |
| 480 | mempool_alloc(fnic->io_sgl_pool[io_req->sgl_type], |
Abhijeet Joglekar | 0c79c74 | 2011-06-13 21:21:01 -0700 | [diff] [blame] | 481 | GFP_ATOMIC); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 482 | if (!io_req->sgl_list) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 483 | atomic64_inc(&fnic_stats->io_stats.alloc_failures); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 484 | ret = SCSI_MLQUEUE_HOST_BUSY; |
| 485 | scsi_dma_unmap(sc); |
| 486 | mempool_free(io_req, fnic->io_req_pool); |
| 487 | goto out; |
| 488 | } |
| 489 | |
| 490 | /* Cache sgl list allocated address before alignment */ |
| 491 | io_req->sgl_list_alloc = io_req->sgl_list; |
| 492 | ptr = (unsigned long) io_req->sgl_list; |
| 493 | if (ptr % FNIC_SG_DESC_ALIGN) { |
| 494 | io_req->sgl_list = (struct host_sg_desc *) |
| 495 | (((unsigned long) ptr |
| 496 | + FNIC_SG_DESC_ALIGN - 1) |
| 497 | & ~(FNIC_SG_DESC_ALIGN - 1)); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /* initialize rest of io_req */ |
| 502 | io_req->port_id = rport->port_id; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 503 | io_req->start_time = jiffies; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 504 | CMD_STATE(sc) = FNIC_IOREQ_CMD_PENDING; |
| 505 | CMD_SP(sc) = (char *)io_req; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 506 | CMD_FLAGS(sc) |= FNIC_IO_INITIALIZED; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 507 | sc->scsi_done = done; |
| 508 | |
| 509 | /* create copy wq desc and enqueue it */ |
| 510 | wq = &fnic->wq_copy[0]; |
| 511 | ret = fnic_queue_wq_copy_desc(fnic, wq, io_req, sc, sg_count); |
| 512 | if (ret) { |
| 513 | /* |
| 514 | * In case another thread cancelled the request, |
| 515 | * refetch the pointer under the lock. |
| 516 | */ |
| 517 | spinlock_t *io_lock = fnic_io_lock_hash(fnic, sc); |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 518 | FNIC_TRACE(fnic_queuecommand, sc->device->host->host_no, |
| 519 | sc->request->tag, sc, 0, 0, 0, |
| 520 | (((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 521 | spin_lock_irqsave(io_lock, flags); |
| 522 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 523 | CMD_SP(sc) = NULL; |
| 524 | CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE; |
| 525 | spin_unlock_irqrestore(io_lock, flags); |
| 526 | if (io_req) { |
| 527 | fnic_release_ioreq_buf(fnic, io_req, sc); |
| 528 | mempool_free(io_req, fnic->io_req_pool); |
| 529 | } |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 530 | } else { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 531 | atomic64_inc(&fnic_stats->io_stats.active_ios); |
| 532 | atomic64_inc(&fnic_stats->io_stats.num_ios); |
| 533 | if (atomic64_read(&fnic_stats->io_stats.active_ios) > |
| 534 | atomic64_read(&fnic_stats->io_stats.max_active_ios)) |
| 535 | atomic64_set(&fnic_stats->io_stats.max_active_ios, |
| 536 | atomic64_read(&fnic_stats->io_stats.active_ios)); |
| 537 | |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 538 | /* REVISIT: Use per IO lock in the final code */ |
| 539 | CMD_FLAGS(sc) |= FNIC_IO_ISSUED; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 540 | } |
| 541 | out: |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 542 | cmd_trace = ((u64)sc->cmnd[0] << 56 | (u64)sc->cmnd[7] << 40 | |
| 543 | (u64)sc->cmnd[8] << 32 | (u64)sc->cmnd[2] << 24 | |
| 544 | (u64)sc->cmnd[3] << 16 | (u64)sc->cmnd[4] << 8 | |
| 545 | sc->cmnd[5]); |
| 546 | |
| 547 | FNIC_TRACE(fnic_queuecommand, sc->device->host->host_no, |
| 548 | sc->request->tag, sc, io_req, |
| 549 | sg_count, cmd_trace, |
| 550 | (((u64)CMD_FLAGS(sc) >> 32) | CMD_STATE(sc))); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 551 | atomic_dec(&fnic->in_flight); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 552 | /* acquire host lock before returning to SCSI */ |
| 553 | spin_lock(lp->host->host_lock); |
| 554 | return ret; |
| 555 | } |
| 556 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 557 | DEF_SCSI_QCMD(fnic_queuecommand) |
| 558 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 559 | /* |
| 560 | * fnic_fcpio_fw_reset_cmpl_handler |
| 561 | * Routine to handle fw reset completion |
| 562 | */ |
| 563 | static int fnic_fcpio_fw_reset_cmpl_handler(struct fnic *fnic, |
| 564 | struct fcpio_fw_req *desc) |
| 565 | { |
| 566 | u8 type; |
| 567 | u8 hdr_status; |
| 568 | struct fcpio_tag tag; |
| 569 | int ret = 0; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 570 | unsigned long flags; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 571 | struct reset_stats *reset_stats = &fnic->fnic_stats.reset_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 572 | |
| 573 | fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag); |
| 574 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 575 | atomic64_inc(&reset_stats->fw_reset_completions); |
| 576 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 577 | /* Clean up all outstanding io requests */ |
| 578 | fnic_cleanup_io(fnic, SCSI_NO_TAG); |
| 579 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 580 | atomic64_set(&fnic->fnic_stats.fw_stats.active_fw_reqs, 0); |
| 581 | atomic64_set(&fnic->fnic_stats.io_stats.active_ios, 0); |
| 582 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 583 | spin_lock_irqsave(&fnic->fnic_lock, flags); |
| 584 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 585 | /* fnic should be in FC_TRANS_ETH_MODE */ |
| 586 | if (fnic->state == FNIC_IN_FC_TRANS_ETH_MODE) { |
| 587 | /* Check status of reset completion */ |
| 588 | if (!hdr_status) { |
| 589 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 590 | "reset cmpl success\n"); |
| 591 | /* Ready to send flogi out */ |
| 592 | fnic->state = FNIC_IN_ETH_MODE; |
| 593 | } else { |
| 594 | FNIC_SCSI_DBG(KERN_DEBUG, |
| 595 | fnic->lport->host, |
| 596 | "fnic fw_reset : failed %s\n", |
| 597 | fnic_fcpio_status_to_str(hdr_status)); |
| 598 | |
| 599 | /* |
| 600 | * Unable to change to eth mode, cannot send out flogi |
| 601 | * Change state to fc mode, so that subsequent Flogi |
| 602 | * requests from libFC will cause more attempts to |
| 603 | * reset the firmware. Free the cached flogi |
| 604 | */ |
| 605 | fnic->state = FNIC_IN_FC_MODE; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 606 | atomic64_inc(&reset_stats->fw_reset_failures); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 607 | ret = -1; |
| 608 | } |
| 609 | } else { |
| 610 | FNIC_SCSI_DBG(KERN_DEBUG, |
| 611 | fnic->lport->host, |
| 612 | "Unexpected state %s while processing" |
| 613 | " reset cmpl\n", fnic_state_to_str(fnic->state)); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 614 | atomic64_inc(&reset_stats->fw_reset_failures); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 615 | ret = -1; |
| 616 | } |
| 617 | |
| 618 | /* Thread removing device blocks till firmware reset is complete */ |
| 619 | if (fnic->remove_wait) |
| 620 | complete(fnic->remove_wait); |
| 621 | |
| 622 | /* |
| 623 | * If fnic is being removed, or fw reset failed |
| 624 | * free the flogi frame. Else, send it out |
| 625 | */ |
| 626 | if (fnic->remove_wait || ret) { |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 627 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 628 | skb_queue_purge(&fnic->tx_queue); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 629 | goto reset_cmpl_handler_end; |
| 630 | } |
| 631 | |
| 632 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
| 633 | |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 634 | fnic_flush_tx(fnic); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 635 | |
| 636 | reset_cmpl_handler_end: |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 637 | fnic_clear_state_flags(fnic, FNIC_FLAGS_FWRESET); |
| 638 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 639 | return ret; |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | * fnic_fcpio_flogi_reg_cmpl_handler |
| 644 | * Routine to handle flogi register completion |
| 645 | */ |
| 646 | static int fnic_fcpio_flogi_reg_cmpl_handler(struct fnic *fnic, |
| 647 | struct fcpio_fw_req *desc) |
| 648 | { |
| 649 | u8 type; |
| 650 | u8 hdr_status; |
| 651 | struct fcpio_tag tag; |
| 652 | int ret = 0; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 653 | unsigned long flags; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 654 | |
| 655 | fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag); |
| 656 | |
| 657 | /* Update fnic state based on status of flogi reg completion */ |
| 658 | spin_lock_irqsave(&fnic->fnic_lock, flags); |
| 659 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 660 | if (fnic->state == FNIC_IN_ETH_TRANS_FC_MODE) { |
| 661 | |
| 662 | /* Check flogi registration completion status */ |
| 663 | if (!hdr_status) { |
| 664 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 665 | "flog reg succeeded\n"); |
| 666 | fnic->state = FNIC_IN_FC_MODE; |
| 667 | } else { |
| 668 | FNIC_SCSI_DBG(KERN_DEBUG, |
| 669 | fnic->lport->host, |
| 670 | "fnic flogi reg :failed %s\n", |
| 671 | fnic_fcpio_status_to_str(hdr_status)); |
| 672 | fnic->state = FNIC_IN_ETH_MODE; |
| 673 | ret = -1; |
| 674 | } |
| 675 | } else { |
| 676 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 677 | "Unexpected fnic state %s while" |
| 678 | " processing flogi reg completion\n", |
| 679 | fnic_state_to_str(fnic->state)); |
| 680 | ret = -1; |
| 681 | } |
| 682 | |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 683 | if (!ret) { |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 684 | if (fnic->stop_rx_link_events) { |
| 685 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
| 686 | goto reg_cmpl_handler_end; |
| 687 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 688 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
| 689 | |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 690 | fnic_flush_tx(fnic); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 691 | queue_work(fnic_event_queue, &fnic->frame_work); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 692 | } else { |
| 693 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | reg_cmpl_handler_end: |
| 697 | return ret; |
| 698 | } |
| 699 | |
| 700 | static inline int is_ack_index_in_range(struct vnic_wq_copy *wq, |
| 701 | u16 request_out) |
| 702 | { |
| 703 | if (wq->to_clean_index <= wq->to_use_index) { |
| 704 | /* out of range, stale request_out index */ |
| 705 | if (request_out < wq->to_clean_index || |
| 706 | request_out >= wq->to_use_index) |
| 707 | return 0; |
| 708 | } else { |
| 709 | /* out of range, stale request_out index */ |
| 710 | if (request_out < wq->to_clean_index && |
| 711 | request_out >= wq->to_use_index) |
| 712 | return 0; |
| 713 | } |
| 714 | /* request_out index is in range */ |
| 715 | return 1; |
| 716 | } |
| 717 | |
| 718 | |
| 719 | /* |
| 720 | * Mark that ack received and store the Ack index. If there are multiple |
| 721 | * acks received before Tx thread cleans it up, the latest value will be |
| 722 | * used which is correct behavior. This state should be in the copy Wq |
| 723 | * instead of in the fnic |
| 724 | */ |
| 725 | static inline void fnic_fcpio_ack_handler(struct fnic *fnic, |
| 726 | unsigned int cq_index, |
| 727 | struct fcpio_fw_req *desc) |
| 728 | { |
| 729 | struct vnic_wq_copy *wq; |
| 730 | u16 request_out = desc->u.ack.request_out; |
| 731 | unsigned long flags; |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 732 | u64 *ox_id_tag = (u64 *)(void *)desc; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 733 | |
| 734 | /* mark the ack state */ |
| 735 | wq = &fnic->wq_copy[cq_index - fnic->raw_wq_count - fnic->rq_count]; |
| 736 | spin_lock_irqsave(&fnic->wq_copy_lock[0], flags); |
| 737 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 738 | fnic->fnic_stats.misc_stats.last_ack_time = jiffies; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 739 | if (is_ack_index_in_range(wq, request_out)) { |
| 740 | fnic->fw_ack_index[0] = request_out; |
| 741 | fnic->fw_ack_recd[0] = 1; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 742 | } else |
| 743 | atomic64_inc( |
| 744 | &fnic->fnic_stats.misc_stats.ack_index_out_of_range); |
| 745 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 746 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags); |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 747 | FNIC_TRACE(fnic_fcpio_ack_handler, |
| 748 | fnic->lport->host->host_no, 0, 0, ox_id_tag[2], ox_id_tag[3], |
| 749 | ox_id_tag[4], ox_id_tag[5]); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | /* |
| 753 | * fnic_fcpio_icmnd_cmpl_handler |
| 754 | * Routine to handle icmnd completions |
| 755 | */ |
| 756 | static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic, |
| 757 | struct fcpio_fw_req *desc) |
| 758 | { |
| 759 | u8 type; |
| 760 | u8 hdr_status; |
| 761 | struct fcpio_tag tag; |
| 762 | u32 id; |
| 763 | u64 xfer_len = 0; |
| 764 | struct fcpio_icmnd_cmpl *icmnd_cmpl; |
| 765 | struct fnic_io_req *io_req; |
| 766 | struct scsi_cmnd *sc; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 767 | struct fnic_stats *fnic_stats = &fnic->fnic_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 768 | unsigned long flags; |
| 769 | spinlock_t *io_lock; |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 770 | u64 cmd_trace; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 771 | unsigned long start_time; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 772 | |
| 773 | /* Decode the cmpl description to get the io_req id */ |
| 774 | fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag); |
| 775 | fcpio_tag_id_dec(&tag, &id); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 776 | icmnd_cmpl = &desc->u.icmnd_cmpl; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 777 | |
Hiral Patel | fc85799 | 2013-09-09 13:31:51 -0700 | [diff] [blame] | 778 | if (id >= fnic->fnic_max_tag_id) { |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 779 | shost_printk(KERN_ERR, fnic->lport->host, |
| 780 | "Tag out of range tag %x hdr status = %s\n", |
| 781 | id, fnic_fcpio_status_to_str(hdr_status)); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 782 | return; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 783 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 784 | |
| 785 | sc = scsi_host_find_tag(fnic->lport->host, id); |
| 786 | WARN_ON_ONCE(!sc); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 787 | if (!sc) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 788 | atomic64_inc(&fnic_stats->io_stats.sc_null); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 789 | shost_printk(KERN_ERR, fnic->lport->host, |
| 790 | "icmnd_cmpl sc is null - " |
| 791 | "hdr status = %s tag = 0x%x desc = 0x%p\n", |
| 792 | fnic_fcpio_status_to_str(hdr_status), id, desc); |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 793 | FNIC_TRACE(fnic_fcpio_icmnd_cmpl_handler, |
| 794 | fnic->lport->host->host_no, id, |
| 795 | ((u64)icmnd_cmpl->_resvd0[1] << 16 | |
| 796 | (u64)icmnd_cmpl->_resvd0[0]), |
| 797 | ((u64)hdr_status << 16 | |
| 798 | (u64)icmnd_cmpl->scsi_status << 8 | |
| 799 | (u64)icmnd_cmpl->flags), desc, |
| 800 | (u64)icmnd_cmpl->residual, 0); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 801 | return; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 802 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 803 | |
| 804 | io_lock = fnic_io_lock_hash(fnic, sc); |
| 805 | spin_lock_irqsave(io_lock, flags); |
| 806 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 807 | WARN_ON_ONCE(!io_req); |
| 808 | if (!io_req) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 809 | atomic64_inc(&fnic_stats->io_stats.ioreq_null); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 810 | CMD_FLAGS(sc) |= FNIC_IO_REQ_NULL; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 811 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 812 | shost_printk(KERN_ERR, fnic->lport->host, |
| 813 | "icmnd_cmpl io_req is null - " |
| 814 | "hdr status = %s tag = 0x%x sc 0x%p\n", |
| 815 | fnic_fcpio_status_to_str(hdr_status), id, sc); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 816 | return; |
| 817 | } |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 818 | start_time = io_req->start_time; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 819 | |
| 820 | /* firmware completed the io */ |
| 821 | io_req->io_completed = 1; |
| 822 | |
| 823 | /* |
| 824 | * if SCSI-ML has already issued abort on this command, |
| 825 | * ignore completion of the IO. The abts path will clean it up |
| 826 | */ |
| 827 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { |
| 828 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 829 | CMD_FLAGS(sc) |= FNIC_IO_ABTS_PENDING; |
| 830 | switch (hdr_status) { |
| 831 | case FCPIO_SUCCESS: |
| 832 | CMD_FLAGS(sc) |= FNIC_IO_DONE; |
| 833 | FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, |
| 834 | "icmnd_cmpl ABTS pending hdr status = %s " |
| 835 | "sc 0x%p scsi_status %x residual %d\n", |
| 836 | fnic_fcpio_status_to_str(hdr_status), sc, |
| 837 | icmnd_cmpl->scsi_status, |
| 838 | icmnd_cmpl->residual); |
| 839 | break; |
| 840 | case FCPIO_ABORTED: |
| 841 | CMD_FLAGS(sc) |= FNIC_IO_ABORTED; |
| 842 | break; |
| 843 | default: |
| 844 | FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, |
| 845 | "icmnd_cmpl abts pending " |
| 846 | "hdr status = %s tag = 0x%x sc = 0x%p\n", |
| 847 | fnic_fcpio_status_to_str(hdr_status), |
| 848 | id, sc); |
| 849 | break; |
| 850 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 851 | return; |
| 852 | } |
| 853 | |
| 854 | /* Mark the IO as complete */ |
| 855 | CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE; |
| 856 | |
| 857 | icmnd_cmpl = &desc->u.icmnd_cmpl; |
| 858 | |
| 859 | switch (hdr_status) { |
| 860 | case FCPIO_SUCCESS: |
| 861 | sc->result = (DID_OK << 16) | icmnd_cmpl->scsi_status; |
| 862 | xfer_len = scsi_bufflen(sc); |
| 863 | scsi_set_resid(sc, icmnd_cmpl->residual); |
| 864 | |
| 865 | if (icmnd_cmpl->flags & FCPIO_ICMND_CMPL_RESID_UNDER) |
| 866 | xfer_len -= icmnd_cmpl->residual; |
| 867 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 868 | if (icmnd_cmpl->scsi_status == SAM_STAT_TASK_SET_FULL) |
| 869 | atomic64_inc(&fnic_stats->misc_stats.queue_fulls); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 870 | break; |
| 871 | |
| 872 | case FCPIO_TIMEOUT: /* request was timed out */ |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 873 | atomic64_inc(&fnic_stats->misc_stats.fcpio_timeout); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 874 | sc->result = (DID_TIME_OUT << 16) | icmnd_cmpl->scsi_status; |
| 875 | break; |
| 876 | |
| 877 | case FCPIO_ABORTED: /* request was aborted */ |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 878 | atomic64_inc(&fnic_stats->misc_stats.fcpio_aborted); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 879 | sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status; |
| 880 | break; |
| 881 | |
| 882 | case FCPIO_DATA_CNT_MISMATCH: /* recv/sent more/less data than exp. */ |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 883 | atomic64_inc(&fnic_stats->misc_stats.data_count_mismatch); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 884 | scsi_set_resid(sc, icmnd_cmpl->residual); |
| 885 | sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status; |
| 886 | break; |
| 887 | |
| 888 | case FCPIO_OUT_OF_RESOURCE: /* out of resources to complete request */ |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 889 | atomic64_inc(&fnic_stats->fw_stats.fw_out_of_resources); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 890 | sc->result = (DID_REQUEUE << 16) | icmnd_cmpl->scsi_status; |
| 891 | break; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 892 | |
| 893 | case FCPIO_IO_NOT_FOUND: /* requested I/O was not found */ |
| 894 | atomic64_inc(&fnic_stats->io_stats.io_not_found); |
| 895 | sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status; |
| 896 | break; |
| 897 | |
| 898 | case FCPIO_SGL_INVALID: /* request was aborted due to sgl error */ |
| 899 | atomic64_inc(&fnic_stats->misc_stats.sgl_invalid); |
| 900 | sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status; |
| 901 | break; |
| 902 | |
| 903 | case FCPIO_FW_ERR: /* request was terminated due fw error */ |
| 904 | atomic64_inc(&fnic_stats->fw_stats.io_fw_errs); |
| 905 | sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status; |
| 906 | break; |
| 907 | |
| 908 | case FCPIO_MSS_INVALID: /* request was aborted due to mss error */ |
| 909 | atomic64_inc(&fnic_stats->misc_stats.mss_invalid); |
| 910 | sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status; |
| 911 | break; |
| 912 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 913 | case FCPIO_INVALID_HEADER: /* header contains invalid data */ |
| 914 | case FCPIO_INVALID_PARAM: /* some parameter in request invalid */ |
| 915 | case FCPIO_REQ_NOT_SUPPORTED:/* request type is not supported */ |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 916 | default: |
| 917 | shost_printk(KERN_ERR, fnic->lport->host, "hdr status = %s\n", |
| 918 | fnic_fcpio_status_to_str(hdr_status)); |
| 919 | sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status; |
| 920 | break; |
| 921 | } |
| 922 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 923 | if (hdr_status != FCPIO_SUCCESS) { |
| 924 | atomic64_inc(&fnic_stats->io_stats.io_failures); |
| 925 | shost_printk(KERN_ERR, fnic->lport->host, "hdr status = %s\n", |
| 926 | fnic_fcpio_status_to_str(hdr_status)); |
| 927 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 928 | /* Break link with the SCSI command */ |
| 929 | CMD_SP(sc) = NULL; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 930 | CMD_FLAGS(sc) |= FNIC_IO_DONE; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 931 | |
| 932 | spin_unlock_irqrestore(io_lock, flags); |
| 933 | |
| 934 | fnic_release_ioreq_buf(fnic, io_req, sc); |
| 935 | |
| 936 | mempool_free(io_req, fnic->io_req_pool); |
| 937 | |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 938 | cmd_trace = ((u64)hdr_status << 56) | |
| 939 | (u64)icmnd_cmpl->scsi_status << 48 | |
| 940 | (u64)icmnd_cmpl->flags << 40 | (u64)sc->cmnd[0] << 32 | |
| 941 | (u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[3] << 16 | |
| 942 | (u64)sc->cmnd[4] << 8 | sc->cmnd[5]; |
| 943 | |
| 944 | FNIC_TRACE(fnic_fcpio_icmnd_cmpl_handler, |
| 945 | sc->device->host->host_no, id, sc, |
| 946 | ((u64)icmnd_cmpl->_resvd0[1] << 56 | |
| 947 | (u64)icmnd_cmpl->_resvd0[0] << 48 | |
| 948 | jiffies_to_msecs(jiffies - start_time)), |
| 949 | desc, cmd_trace, |
| 950 | (((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); |
| 951 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 952 | if (sc->sc_data_direction == DMA_FROM_DEVICE) { |
| 953 | fnic->lport->host_stats.fcp_input_requests++; |
| 954 | fnic->fcp_input_bytes += xfer_len; |
| 955 | } else if (sc->sc_data_direction == DMA_TO_DEVICE) { |
| 956 | fnic->lport->host_stats.fcp_output_requests++; |
| 957 | fnic->fcp_output_bytes += xfer_len; |
| 958 | } else |
| 959 | fnic->lport->host_stats.fcp_control_requests++; |
| 960 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 961 | atomic64_dec(&fnic_stats->io_stats.active_ios); |
| 962 | if (atomic64_read(&fnic->io_cmpl_skip)) |
| 963 | atomic64_dec(&fnic->io_cmpl_skip); |
| 964 | else |
| 965 | atomic64_inc(&fnic_stats->io_stats.io_completions); |
| 966 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 967 | /* Call SCSI completion function to complete the IO */ |
| 968 | if (sc->scsi_done) |
| 969 | sc->scsi_done(sc); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | /* fnic_fcpio_itmf_cmpl_handler |
| 973 | * Routine to handle itmf completions |
| 974 | */ |
| 975 | static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, |
| 976 | struct fcpio_fw_req *desc) |
| 977 | { |
| 978 | u8 type; |
| 979 | u8 hdr_status; |
| 980 | struct fcpio_tag tag; |
| 981 | u32 id; |
| 982 | struct scsi_cmnd *sc; |
| 983 | struct fnic_io_req *io_req; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 984 | struct fnic_stats *fnic_stats = &fnic->fnic_stats; |
| 985 | struct abort_stats *abts_stats = &fnic->fnic_stats.abts_stats; |
| 986 | struct terminate_stats *term_stats = &fnic->fnic_stats.term_stats; |
| 987 | struct misc_stats *misc_stats = &fnic->fnic_stats.misc_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 988 | unsigned long flags; |
| 989 | spinlock_t *io_lock; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 990 | unsigned long start_time; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 991 | |
| 992 | fcpio_header_dec(&desc->hdr, &type, &hdr_status, &tag); |
| 993 | fcpio_tag_id_dec(&tag, &id); |
| 994 | |
Hiral Patel | fc85799 | 2013-09-09 13:31:51 -0700 | [diff] [blame] | 995 | if ((id & FNIC_TAG_MASK) >= fnic->fnic_max_tag_id) { |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 996 | shost_printk(KERN_ERR, fnic->lport->host, |
| 997 | "Tag out of range tag %x hdr status = %s\n", |
| 998 | id, fnic_fcpio_status_to_str(hdr_status)); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 999 | return; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1000 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1001 | |
| 1002 | sc = scsi_host_find_tag(fnic->lport->host, id & FNIC_TAG_MASK); |
| 1003 | WARN_ON_ONCE(!sc); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1004 | if (!sc) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1005 | atomic64_inc(&fnic_stats->io_stats.sc_null); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1006 | shost_printk(KERN_ERR, fnic->lport->host, |
| 1007 | "itmf_cmpl sc is null - hdr status = %s tag = 0x%x\n", |
| 1008 | fnic_fcpio_status_to_str(hdr_status), id); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1009 | return; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1010 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1011 | io_lock = fnic_io_lock_hash(fnic, sc); |
| 1012 | spin_lock_irqsave(io_lock, flags); |
| 1013 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 1014 | WARN_ON_ONCE(!io_req); |
| 1015 | if (!io_req) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1016 | atomic64_inc(&fnic_stats->io_stats.ioreq_null); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1017 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1018 | CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_REQ_NULL; |
| 1019 | shost_printk(KERN_ERR, fnic->lport->host, |
| 1020 | "itmf_cmpl io_req is null - " |
| 1021 | "hdr status = %s tag = 0x%x sc 0x%p\n", |
| 1022 | fnic_fcpio_status_to_str(hdr_status), id, sc); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1023 | return; |
| 1024 | } |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1025 | start_time = io_req->start_time; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1026 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1027 | if ((id & FNIC_TAG_ABORT) && (id & FNIC_TAG_DEV_RST)) { |
| 1028 | /* Abort and terminate completion of device reset req */ |
| 1029 | /* REVISIT : Add asserts about various flags */ |
| 1030 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1031 | "dev reset abts cmpl recd. id %x status %s\n", |
| 1032 | id, fnic_fcpio_status_to_str(hdr_status)); |
| 1033 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_COMPLETE; |
| 1034 | CMD_ABTS_STATUS(sc) = hdr_status; |
| 1035 | CMD_FLAGS(sc) |= FNIC_DEV_RST_DONE; |
| 1036 | if (io_req->abts_done) |
| 1037 | complete(io_req->abts_done); |
| 1038 | spin_unlock_irqrestore(io_lock, flags); |
| 1039 | } else if (id & FNIC_TAG_ABORT) { |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1040 | /* Completion of abort cmd */ |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1041 | switch (hdr_status) { |
| 1042 | case FCPIO_SUCCESS: |
| 1043 | break; |
| 1044 | case FCPIO_TIMEOUT: |
| 1045 | if (CMD_FLAGS(sc) & FNIC_IO_ABTS_ISSUED) |
| 1046 | atomic64_inc(&abts_stats->abort_fw_timeouts); |
| 1047 | else |
| 1048 | atomic64_inc( |
| 1049 | &term_stats->terminate_fw_timeouts); |
| 1050 | break; |
| 1051 | case FCPIO_IO_NOT_FOUND: |
| 1052 | if (CMD_FLAGS(sc) & FNIC_IO_ABTS_ISSUED) |
| 1053 | atomic64_inc(&abts_stats->abort_io_not_found); |
| 1054 | else |
| 1055 | atomic64_inc( |
| 1056 | &term_stats->terminate_io_not_found); |
| 1057 | break; |
| 1058 | default: |
| 1059 | if (CMD_FLAGS(sc) & FNIC_IO_ABTS_ISSUED) |
| 1060 | atomic64_inc(&abts_stats->abort_failures); |
| 1061 | else |
| 1062 | atomic64_inc( |
| 1063 | &term_stats->terminate_failures); |
| 1064 | break; |
| 1065 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1066 | if (CMD_STATE(sc) != FNIC_IOREQ_ABTS_PENDING) { |
| 1067 | /* This is a late completion. Ignore it */ |
| 1068 | spin_unlock_irqrestore(io_lock, flags); |
| 1069 | return; |
| 1070 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1071 | CMD_ABTS_STATUS(sc) = hdr_status; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1072 | CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_DONE; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1073 | |
| 1074 | atomic64_dec(&fnic_stats->io_stats.active_ios); |
| 1075 | if (atomic64_read(&fnic->io_cmpl_skip)) |
| 1076 | atomic64_dec(&fnic->io_cmpl_skip); |
| 1077 | else |
| 1078 | atomic64_inc(&fnic_stats->io_stats.io_completions); |
| 1079 | |
| 1080 | if (!(CMD_FLAGS(sc) & (FNIC_IO_ABORTED | FNIC_IO_DONE))) |
| 1081 | atomic64_inc(&misc_stats->no_icmnd_itmf_cmpls); |
| 1082 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1083 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1084 | "abts cmpl recd. id %d status %s\n", |
| 1085 | (int)(id & FNIC_TAG_MASK), |
| 1086 | fnic_fcpio_status_to_str(hdr_status)); |
| 1087 | |
| 1088 | /* |
| 1089 | * If scsi_eh thread is blocked waiting for abts to complete, |
| 1090 | * signal completion to it. IO will be cleaned in the thread |
| 1091 | * else clean it in this context |
| 1092 | */ |
| 1093 | if (io_req->abts_done) { |
| 1094 | complete(io_req->abts_done); |
| 1095 | spin_unlock_irqrestore(io_lock, flags); |
| 1096 | } else { |
| 1097 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1098 | "abts cmpl, completing IO\n"); |
| 1099 | CMD_SP(sc) = NULL; |
| 1100 | sc->result = (DID_ERROR << 16); |
| 1101 | |
| 1102 | spin_unlock_irqrestore(io_lock, flags); |
| 1103 | |
| 1104 | fnic_release_ioreq_buf(fnic, io_req, sc); |
| 1105 | mempool_free(io_req, fnic->io_req_pool); |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 1106 | if (sc->scsi_done) { |
| 1107 | FNIC_TRACE(fnic_fcpio_itmf_cmpl_handler, |
| 1108 | sc->device->host->host_no, id, |
| 1109 | sc, |
| 1110 | jiffies_to_msecs(jiffies - start_time), |
| 1111 | desc, |
| 1112 | (((u64)hdr_status << 40) | |
| 1113 | (u64)sc->cmnd[0] << 32 | |
| 1114 | (u64)sc->cmnd[2] << 24 | |
| 1115 | (u64)sc->cmnd[3] << 16 | |
| 1116 | (u64)sc->cmnd[4] << 8 | sc->cmnd[5]), |
| 1117 | (((u64)CMD_FLAGS(sc) << 32) | |
| 1118 | CMD_STATE(sc))); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1119 | sc->scsi_done(sc); |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 1120 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | } else if (id & FNIC_TAG_DEV_RST) { |
| 1124 | /* Completion of device reset */ |
| 1125 | CMD_LR_STATUS(sc) = hdr_status; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1126 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { |
| 1127 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1128 | CMD_FLAGS(sc) |= FNIC_DEV_RST_ABTS_PENDING; |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 1129 | FNIC_TRACE(fnic_fcpio_itmf_cmpl_handler, |
| 1130 | sc->device->host->host_no, id, sc, |
| 1131 | jiffies_to_msecs(jiffies - start_time), |
| 1132 | desc, 0, |
| 1133 | (((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1134 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1135 | "Terminate pending " |
| 1136 | "dev reset cmpl recd. id %d status %s\n", |
| 1137 | (int)(id & FNIC_TAG_MASK), |
| 1138 | fnic_fcpio_status_to_str(hdr_status)); |
| 1139 | return; |
| 1140 | } |
| 1141 | if (CMD_FLAGS(sc) & FNIC_DEV_RST_TIMED_OUT) { |
| 1142 | /* Need to wait for terminate completion */ |
| 1143 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 1144 | FNIC_TRACE(fnic_fcpio_itmf_cmpl_handler, |
| 1145 | sc->device->host->host_no, id, sc, |
| 1146 | jiffies_to_msecs(jiffies - start_time), |
| 1147 | desc, 0, |
| 1148 | (((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1149 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1150 | "dev reset cmpl recd after time out. " |
| 1151 | "id %d status %s\n", |
| 1152 | (int)(id & FNIC_TAG_MASK), |
| 1153 | fnic_fcpio_status_to_str(hdr_status)); |
| 1154 | return; |
| 1155 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1156 | CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1157 | CMD_FLAGS(sc) |= FNIC_DEV_RST_DONE; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1158 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1159 | "dev reset cmpl recd. id %d status %s\n", |
| 1160 | (int)(id & FNIC_TAG_MASK), |
| 1161 | fnic_fcpio_status_to_str(hdr_status)); |
| 1162 | if (io_req->dr_done) |
| 1163 | complete(io_req->dr_done); |
| 1164 | spin_unlock_irqrestore(io_lock, flags); |
| 1165 | |
| 1166 | } else { |
| 1167 | shost_printk(KERN_ERR, fnic->lport->host, |
| 1168 | "Unexpected itmf io state %s tag %x\n", |
| 1169 | fnic_ioreq_state_to_str(CMD_STATE(sc)), id); |
| 1170 | spin_unlock_irqrestore(io_lock, flags); |
| 1171 | } |
| 1172 | |
| 1173 | } |
| 1174 | |
| 1175 | /* |
| 1176 | * fnic_fcpio_cmpl_handler |
| 1177 | * Routine to service the cq for wq_copy |
| 1178 | */ |
| 1179 | static int fnic_fcpio_cmpl_handler(struct vnic_dev *vdev, |
| 1180 | unsigned int cq_index, |
| 1181 | struct fcpio_fw_req *desc) |
| 1182 | { |
| 1183 | struct fnic *fnic = vnic_dev_priv(vdev); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1184 | |
| 1185 | switch (desc->hdr.type) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1186 | case FCPIO_ICMND_CMPL: /* fw completed a command */ |
| 1187 | case FCPIO_ITMF_CMPL: /* fw completed itmf (abort cmd, lun reset)*/ |
| 1188 | case FCPIO_FLOGI_REG_CMPL: /* fw completed flogi_reg */ |
| 1189 | case FCPIO_FLOGI_FIP_REG_CMPL: /* fw completed flogi_fip_reg */ |
| 1190 | case FCPIO_RESET_CMPL: /* fw completed reset */ |
| 1191 | atomic64_dec(&fnic->fnic_stats.fw_stats.active_fw_reqs); |
| 1192 | break; |
| 1193 | default: |
| 1194 | break; |
| 1195 | } |
| 1196 | |
| 1197 | switch (desc->hdr.type) { |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1198 | case FCPIO_ACK: /* fw copied copy wq desc to its queue */ |
| 1199 | fnic_fcpio_ack_handler(fnic, cq_index, desc); |
| 1200 | break; |
| 1201 | |
| 1202 | case FCPIO_ICMND_CMPL: /* fw completed a command */ |
| 1203 | fnic_fcpio_icmnd_cmpl_handler(fnic, desc); |
| 1204 | break; |
| 1205 | |
| 1206 | case FCPIO_ITMF_CMPL: /* fw completed itmf (abort cmd, lun reset)*/ |
| 1207 | fnic_fcpio_itmf_cmpl_handler(fnic, desc); |
| 1208 | break; |
| 1209 | |
| 1210 | case FCPIO_FLOGI_REG_CMPL: /* fw completed flogi_reg */ |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 1211 | case FCPIO_FLOGI_FIP_REG_CMPL: /* fw completed flogi_fip_reg */ |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1212 | fnic_fcpio_flogi_reg_cmpl_handler(fnic, desc); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1213 | break; |
| 1214 | |
| 1215 | case FCPIO_RESET_CMPL: /* fw completed reset */ |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1216 | fnic_fcpio_fw_reset_cmpl_handler(fnic, desc); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1217 | break; |
| 1218 | |
| 1219 | default: |
| 1220 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1221 | "firmware completion type %d\n", |
| 1222 | desc->hdr.type); |
| 1223 | break; |
| 1224 | } |
| 1225 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1226 | return 0; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | /* |
| 1230 | * fnic_wq_copy_cmpl_handler |
| 1231 | * Routine to process wq copy |
| 1232 | */ |
| 1233 | int fnic_wq_copy_cmpl_handler(struct fnic *fnic, int copy_work_to_do) |
| 1234 | { |
| 1235 | unsigned int wq_work_done = 0; |
| 1236 | unsigned int i, cq_index; |
| 1237 | unsigned int cur_work_done; |
| 1238 | |
| 1239 | for (i = 0; i < fnic->wq_copy_count; i++) { |
| 1240 | cq_index = i + fnic->raw_wq_count + fnic->rq_count; |
| 1241 | cur_work_done = vnic_cq_copy_service(&fnic->cq[cq_index], |
| 1242 | fnic_fcpio_cmpl_handler, |
| 1243 | copy_work_to_do); |
| 1244 | wq_work_done += cur_work_done; |
| 1245 | } |
| 1246 | return wq_work_done; |
| 1247 | } |
| 1248 | |
| 1249 | static void fnic_cleanup_io(struct fnic *fnic, int exclude_id) |
| 1250 | { |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1251 | int i; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1252 | struct fnic_io_req *io_req; |
| 1253 | unsigned long flags = 0; |
| 1254 | struct scsi_cmnd *sc; |
| 1255 | spinlock_t *io_lock; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1256 | unsigned long start_time = 0; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1257 | struct fnic_stats *fnic_stats = &fnic->fnic_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1258 | |
Hiral Patel | fc85799 | 2013-09-09 13:31:51 -0700 | [diff] [blame] | 1259 | for (i = 0; i < fnic->fnic_max_tag_id; i++) { |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1260 | if (i == exclude_id) |
| 1261 | continue; |
| 1262 | |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1263 | io_lock = fnic_io_lock_tag(fnic, i); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1264 | spin_lock_irqsave(io_lock, flags); |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1265 | sc = scsi_host_find_tag(fnic->lport->host, i); |
| 1266 | if (!sc) { |
| 1267 | spin_unlock_irqrestore(io_lock, flags); |
| 1268 | continue; |
| 1269 | } |
| 1270 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1271 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1272 | if ((CMD_FLAGS(sc) & FNIC_DEVICE_RESET) && |
| 1273 | !(CMD_FLAGS(sc) & FNIC_DEV_RST_DONE)) { |
| 1274 | /* |
| 1275 | * We will be here only when FW completes reset |
| 1276 | * without sending completions for outstanding ios. |
| 1277 | */ |
| 1278 | CMD_FLAGS(sc) |= FNIC_DEV_RST_DONE; |
| 1279 | if (io_req && io_req->dr_done) |
| 1280 | complete(io_req->dr_done); |
| 1281 | else if (io_req && io_req->abts_done) |
| 1282 | complete(io_req->abts_done); |
| 1283 | spin_unlock_irqrestore(io_lock, flags); |
| 1284 | continue; |
| 1285 | } else if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) { |
| 1286 | spin_unlock_irqrestore(io_lock, flags); |
| 1287 | continue; |
| 1288 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1289 | if (!io_req) { |
| 1290 | spin_unlock_irqrestore(io_lock, flags); |
| 1291 | goto cleanup_scsi_cmd; |
| 1292 | } |
| 1293 | |
| 1294 | CMD_SP(sc) = NULL; |
| 1295 | |
| 1296 | spin_unlock_irqrestore(io_lock, flags); |
| 1297 | |
| 1298 | /* |
| 1299 | * If there is a scsi_cmnd associated with this io_req, then |
| 1300 | * free the corresponding state |
| 1301 | */ |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1302 | start_time = io_req->start_time; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1303 | fnic_release_ioreq_buf(fnic, io_req, sc); |
| 1304 | mempool_free(io_req, fnic->io_req_pool); |
| 1305 | |
| 1306 | cleanup_scsi_cmd: |
| 1307 | sc->result = DID_TRANSPORT_DISRUPTED << 16; |
Hiral Shah | 6681866 | 2014-04-18 12:28:18 -0700 | [diff] [blame] | 1308 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1309 | "%s: sc duration = %lu DID_TRANSPORT_DISRUPTED\n", |
| 1310 | __func__, (jiffies - start_time)); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1311 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1312 | if (atomic64_read(&fnic->io_cmpl_skip)) |
| 1313 | atomic64_dec(&fnic->io_cmpl_skip); |
| 1314 | else |
| 1315 | atomic64_inc(&fnic_stats->io_stats.io_completions); |
| 1316 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1317 | /* Complete the command to SCSI */ |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 1318 | if (sc->scsi_done) { |
| 1319 | FNIC_TRACE(fnic_cleanup_io, |
| 1320 | sc->device->host->host_no, i, sc, |
| 1321 | jiffies_to_msecs(jiffies - start_time), |
| 1322 | 0, ((u64)sc->cmnd[0] << 32 | |
| 1323 | (u64)sc->cmnd[2] << 24 | |
| 1324 | (u64)sc->cmnd[3] << 16 | |
| 1325 | (u64)sc->cmnd[4] << 8 | sc->cmnd[5]), |
| 1326 | (((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); |
| 1327 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1328 | sc->scsi_done(sc); |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 1329 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq, |
| 1334 | struct fcpio_host_req *desc) |
| 1335 | { |
| 1336 | u32 id; |
| 1337 | struct fnic *fnic = vnic_dev_priv(wq->vdev); |
| 1338 | struct fnic_io_req *io_req; |
| 1339 | struct scsi_cmnd *sc; |
| 1340 | unsigned long flags; |
| 1341 | spinlock_t *io_lock; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1342 | unsigned long start_time = 0; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1343 | |
| 1344 | /* get the tag reference */ |
| 1345 | fcpio_tag_id_dec(&desc->hdr.tag, &id); |
| 1346 | id &= FNIC_TAG_MASK; |
| 1347 | |
Hiral Patel | fc85799 | 2013-09-09 13:31:51 -0700 | [diff] [blame] | 1348 | if (id >= fnic->fnic_max_tag_id) |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1349 | return; |
| 1350 | |
| 1351 | sc = scsi_host_find_tag(fnic->lport->host, id); |
| 1352 | if (!sc) |
| 1353 | return; |
| 1354 | |
| 1355 | io_lock = fnic_io_lock_hash(fnic, sc); |
| 1356 | spin_lock_irqsave(io_lock, flags); |
| 1357 | |
| 1358 | /* Get the IO context which this desc refers to */ |
| 1359 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 1360 | |
| 1361 | /* fnic interrupts are turned off by now */ |
| 1362 | |
| 1363 | if (!io_req) { |
| 1364 | spin_unlock_irqrestore(io_lock, flags); |
| 1365 | goto wq_copy_cleanup_scsi_cmd; |
| 1366 | } |
| 1367 | |
| 1368 | CMD_SP(sc) = NULL; |
| 1369 | |
| 1370 | spin_unlock_irqrestore(io_lock, flags); |
| 1371 | |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1372 | start_time = io_req->start_time; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1373 | fnic_release_ioreq_buf(fnic, io_req, sc); |
| 1374 | mempool_free(io_req, fnic->io_req_pool); |
| 1375 | |
| 1376 | wq_copy_cleanup_scsi_cmd: |
| 1377 | sc->result = DID_NO_CONNECT << 16; |
| 1378 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "wq_copy_cleanup_handler:" |
| 1379 | " DID_NO_CONNECT\n"); |
| 1380 | |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 1381 | if (sc->scsi_done) { |
| 1382 | FNIC_TRACE(fnic_wq_copy_cleanup_handler, |
| 1383 | sc->device->host->host_no, id, sc, |
| 1384 | jiffies_to_msecs(jiffies - start_time), |
| 1385 | 0, ((u64)sc->cmnd[0] << 32 | |
| 1386 | (u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[3] << 16 | |
| 1387 | (u64)sc->cmnd[4] << 8 | sc->cmnd[5]), |
| 1388 | (((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); |
| 1389 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1390 | sc->scsi_done(sc); |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 1391 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | static inline int fnic_queue_abort_io_req(struct fnic *fnic, int tag, |
| 1395 | u32 task_req, u8 *fc_lun, |
| 1396 | struct fnic_io_req *io_req) |
| 1397 | { |
| 1398 | struct vnic_wq_copy *wq = &fnic->wq_copy[0]; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1399 | struct Scsi_Host *host = fnic->lport->host; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1400 | struct misc_stats *misc_stats = &fnic->fnic_stats.misc_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1401 | unsigned long flags; |
| 1402 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1403 | spin_lock_irqsave(host->host_lock, flags); |
| 1404 | if (unlikely(fnic_chk_state_flags_locked(fnic, |
| 1405 | FNIC_FLAGS_IO_BLOCKED))) { |
| 1406 | spin_unlock_irqrestore(host->host_lock, flags); |
| 1407 | return 1; |
| 1408 | } else |
| 1409 | atomic_inc(&fnic->in_flight); |
| 1410 | spin_unlock_irqrestore(host->host_lock, flags); |
| 1411 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1412 | spin_lock_irqsave(&fnic->wq_copy_lock[0], flags); |
| 1413 | |
| 1414 | if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0]) |
| 1415 | free_wq_copy_descs(fnic, wq); |
| 1416 | |
| 1417 | if (!vnic_wq_copy_desc_avail(wq)) { |
| 1418 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1419 | atomic_dec(&fnic->in_flight); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1420 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1421 | "fnic_queue_abort_io_req: failure: no descriptors\n"); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1422 | atomic64_inc(&misc_stats->abts_cpwq_alloc_failures); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1423 | return 1; |
| 1424 | } |
| 1425 | fnic_queue_wq_copy_desc_itmf(wq, tag | FNIC_TAG_ABORT, |
| 1426 | 0, task_req, tag, fc_lun, io_req->port_id, |
| 1427 | fnic->config.ra_tov, fnic->config.ed_tov); |
| 1428 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1429 | atomic64_inc(&fnic->fnic_stats.fw_stats.active_fw_reqs); |
| 1430 | if (atomic64_read(&fnic->fnic_stats.fw_stats.active_fw_reqs) > |
| 1431 | atomic64_read(&fnic->fnic_stats.fw_stats.max_fw_reqs)) |
| 1432 | atomic64_set(&fnic->fnic_stats.fw_stats.max_fw_reqs, |
| 1433 | atomic64_read(&fnic->fnic_stats.fw_stats.active_fw_reqs)); |
| 1434 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1435 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], flags); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1436 | atomic_dec(&fnic->in_flight); |
| 1437 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1438 | return 0; |
| 1439 | } |
| 1440 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1441 | static void fnic_rport_exch_reset(struct fnic *fnic, u32 port_id) |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1442 | { |
| 1443 | int tag; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1444 | int abt_tag; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1445 | int term_cnt = 0; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1446 | struct fnic_io_req *io_req; |
| 1447 | spinlock_t *io_lock; |
| 1448 | unsigned long flags; |
| 1449 | struct scsi_cmnd *sc; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1450 | struct reset_stats *reset_stats = &fnic->fnic_stats.reset_stats; |
| 1451 | struct terminate_stats *term_stats = &fnic->fnic_stats.term_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1452 | struct scsi_lun fc_lun; |
| 1453 | enum fnic_ioreq_state old_ioreq_state; |
| 1454 | |
| 1455 | FNIC_SCSI_DBG(KERN_DEBUG, |
| 1456 | fnic->lport->host, |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1457 | "fnic_rport_exch_reset called portid 0x%06x\n", |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1458 | port_id); |
| 1459 | |
| 1460 | if (fnic->in_remove) |
| 1461 | return; |
| 1462 | |
Hiral Patel | fc85799 | 2013-09-09 13:31:51 -0700 | [diff] [blame] | 1463 | for (tag = 0; tag < fnic->fnic_max_tag_id; tag++) { |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1464 | abt_tag = tag; |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1465 | io_lock = fnic_io_lock_tag(fnic, tag); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1466 | spin_lock_irqsave(io_lock, flags); |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1467 | sc = scsi_host_find_tag(fnic->lport->host, tag); |
| 1468 | if (!sc) { |
| 1469 | spin_unlock_irqrestore(io_lock, flags); |
| 1470 | continue; |
| 1471 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1472 | |
| 1473 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 1474 | |
| 1475 | if (!io_req || io_req->port_id != port_id) { |
| 1476 | spin_unlock_irqrestore(io_lock, flags); |
| 1477 | continue; |
| 1478 | } |
| 1479 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1480 | if ((CMD_FLAGS(sc) & FNIC_DEVICE_RESET) && |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1481 | (!(CMD_FLAGS(sc) & FNIC_DEV_RST_ISSUED))) { |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1482 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1483 | "fnic_rport_exch_reset dev rst not pending sc 0x%p\n", |
| 1484 | sc); |
| 1485 | spin_unlock_irqrestore(io_lock, flags); |
| 1486 | continue; |
| 1487 | } |
| 1488 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1489 | /* |
| 1490 | * Found IO that is still pending with firmware and |
| 1491 | * belongs to rport that went away |
| 1492 | */ |
| 1493 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { |
| 1494 | spin_unlock_irqrestore(io_lock, flags); |
| 1495 | continue; |
| 1496 | } |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1497 | if (io_req->abts_done) { |
| 1498 | shost_printk(KERN_ERR, fnic->lport->host, |
| 1499 | "fnic_rport_exch_reset: io_req->abts_done is set " |
| 1500 | "state is %s\n", |
| 1501 | fnic_ioreq_state_to_str(CMD_STATE(sc))); |
| 1502 | } |
| 1503 | |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1504 | if (!(CMD_FLAGS(sc) & FNIC_IO_ISSUED)) { |
| 1505 | shost_printk(KERN_ERR, fnic->lport->host, |
| 1506 | "rport_exch_reset " |
| 1507 | "IO not yet issued %p tag 0x%x flags " |
| 1508 | "%x state %d\n", |
| 1509 | sc, tag, CMD_FLAGS(sc), CMD_STATE(sc)); |
| 1510 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1511 | old_ioreq_state = CMD_STATE(sc); |
| 1512 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; |
| 1513 | CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1514 | if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1515 | atomic64_inc(&reset_stats->device_reset_terminates); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1516 | abt_tag = (tag | FNIC_TAG_DEV_RST); |
| 1517 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1518 | "fnic_rport_exch_reset dev rst sc 0x%p\n", |
| 1519 | sc); |
| 1520 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1521 | |
| 1522 | BUG_ON(io_req->abts_done); |
| 1523 | |
| 1524 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1525 | "fnic_rport_reset_exch: Issuing abts\n"); |
| 1526 | |
| 1527 | spin_unlock_irqrestore(io_lock, flags); |
| 1528 | |
| 1529 | /* Now queue the abort command to firmware */ |
| 1530 | int_to_scsilun(sc->device->lun, &fc_lun); |
| 1531 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1532 | if (fnic_queue_abort_io_req(fnic, abt_tag, |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1533 | FCPIO_ITMF_ABT_TASK_TERM, |
| 1534 | fc_lun.scsi_lun, io_req)) { |
| 1535 | /* |
| 1536 | * Revert the cmd state back to old state, if |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1537 | * it hasn't changed in between. This cmd will get |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1538 | * aborted later by scsi_eh, or cleaned up during |
| 1539 | * lun reset |
| 1540 | */ |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1541 | spin_lock_irqsave(io_lock, flags); |
| 1542 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) |
| 1543 | CMD_STATE(sc) = old_ioreq_state; |
| 1544 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1545 | } else { |
| 1546 | spin_lock_irqsave(io_lock, flags); |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 1547 | if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) |
| 1548 | CMD_FLAGS(sc) |= FNIC_DEV_RST_TERM_ISSUED; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1549 | else |
| 1550 | CMD_FLAGS(sc) |= FNIC_IO_INTERNAL_TERM_ISSUED; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1551 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1552 | atomic64_inc(&term_stats->terminates); |
| 1553 | term_cnt++; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1554 | } |
| 1555 | } |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1556 | if (term_cnt > atomic64_read(&term_stats->max_terminates)) |
| 1557 | atomic64_set(&term_stats->max_terminates, term_cnt); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1558 | |
| 1559 | } |
| 1560 | |
| 1561 | void fnic_terminate_rport_io(struct fc_rport *rport) |
| 1562 | { |
| 1563 | int tag; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1564 | int abt_tag; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1565 | int term_cnt = 0; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1566 | struct fnic_io_req *io_req; |
| 1567 | spinlock_t *io_lock; |
| 1568 | unsigned long flags; |
| 1569 | struct scsi_cmnd *sc; |
| 1570 | struct scsi_lun fc_lun; |
Sesidhar Beddel | d0385d9 | 2013-09-09 13:31:50 -0700 | [diff] [blame] | 1571 | struct fc_rport_libfc_priv *rdata; |
| 1572 | struct fc_lport *lport; |
| 1573 | struct fnic *fnic; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1574 | struct fc_rport *cmd_rport; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1575 | struct reset_stats *reset_stats; |
| 1576 | struct terminate_stats *term_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1577 | enum fnic_ioreq_state old_ioreq_state; |
| 1578 | |
Sesidhar Beddel | d0385d9 | 2013-09-09 13:31:50 -0700 | [diff] [blame] | 1579 | if (!rport) { |
| 1580 | printk(KERN_ERR "fnic_terminate_rport_io: rport is NULL\n"); |
| 1581 | return; |
| 1582 | } |
| 1583 | rdata = rport->dd_data; |
| 1584 | |
| 1585 | if (!rdata) { |
| 1586 | printk(KERN_ERR "fnic_terminate_rport_io: rdata is NULL\n"); |
| 1587 | return; |
| 1588 | } |
| 1589 | lport = rdata->local_port; |
| 1590 | |
| 1591 | if (!lport) { |
| 1592 | printk(KERN_ERR "fnic_terminate_rport_io: lport is NULL\n"); |
| 1593 | return; |
| 1594 | } |
| 1595 | fnic = lport_priv(lport); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1596 | FNIC_SCSI_DBG(KERN_DEBUG, |
| 1597 | fnic->lport->host, "fnic_terminate_rport_io called" |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1598 | " wwpn 0x%llx, wwnn0x%llx, rport 0x%p, portid 0x%06x\n", |
| 1599 | rport->port_name, rport->node_name, rport, |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1600 | rport->port_id); |
| 1601 | |
| 1602 | if (fnic->in_remove) |
| 1603 | return; |
| 1604 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1605 | reset_stats = &fnic->fnic_stats.reset_stats; |
| 1606 | term_stats = &fnic->fnic_stats.term_stats; |
| 1607 | |
Hiral Patel | fc85799 | 2013-09-09 13:31:51 -0700 | [diff] [blame] | 1608 | for (tag = 0; tag < fnic->fnic_max_tag_id; tag++) { |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1609 | abt_tag = tag; |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1610 | io_lock = fnic_io_lock_tag(fnic, tag); |
| 1611 | spin_lock_irqsave(io_lock, flags); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1612 | sc = scsi_host_find_tag(fnic->lport->host, tag); |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1613 | if (!sc) { |
| 1614 | spin_unlock_irqrestore(io_lock, flags); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1615 | continue; |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1616 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1617 | |
| 1618 | cmd_rport = starget_to_rport(scsi_target(sc->device)); |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1619 | if (rport != cmd_rport) { |
| 1620 | spin_unlock_irqrestore(io_lock, flags); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1621 | continue; |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1622 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1623 | |
| 1624 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 1625 | |
| 1626 | if (!io_req || rport != cmd_rport) { |
| 1627 | spin_unlock_irqrestore(io_lock, flags); |
| 1628 | continue; |
| 1629 | } |
| 1630 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1631 | if ((CMD_FLAGS(sc) & FNIC_DEVICE_RESET) && |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1632 | (!(CMD_FLAGS(sc) & FNIC_DEV_RST_ISSUED))) { |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1633 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1634 | "fnic_terminate_rport_io dev rst not pending sc 0x%p\n", |
| 1635 | sc); |
| 1636 | spin_unlock_irqrestore(io_lock, flags); |
| 1637 | continue; |
| 1638 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1639 | /* |
| 1640 | * Found IO that is still pending with firmware and |
| 1641 | * belongs to rport that went away |
| 1642 | */ |
| 1643 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { |
| 1644 | spin_unlock_irqrestore(io_lock, flags); |
| 1645 | continue; |
| 1646 | } |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1647 | if (io_req->abts_done) { |
| 1648 | shost_printk(KERN_ERR, fnic->lport->host, |
| 1649 | "fnic_terminate_rport_io: io_req->abts_done is set " |
| 1650 | "state is %s\n", |
| 1651 | fnic_ioreq_state_to_str(CMD_STATE(sc))); |
| 1652 | } |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1653 | if (!(CMD_FLAGS(sc) & FNIC_IO_ISSUED)) { |
| 1654 | FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, |
| 1655 | "fnic_terminate_rport_io " |
| 1656 | "IO not yet issued %p tag 0x%x flags " |
| 1657 | "%x state %d\n", |
| 1658 | sc, tag, CMD_FLAGS(sc), CMD_STATE(sc)); |
| 1659 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1660 | old_ioreq_state = CMD_STATE(sc); |
| 1661 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; |
| 1662 | CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1663 | if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1664 | atomic64_inc(&reset_stats->device_reset_terminates); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1665 | abt_tag = (tag | FNIC_TAG_DEV_RST); |
| 1666 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1667 | "fnic_terminate_rport_io dev rst sc 0x%p\n", sc); |
| 1668 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1669 | |
| 1670 | BUG_ON(io_req->abts_done); |
| 1671 | |
| 1672 | FNIC_SCSI_DBG(KERN_DEBUG, |
| 1673 | fnic->lport->host, |
| 1674 | "fnic_terminate_rport_io: Issuing abts\n"); |
| 1675 | |
| 1676 | spin_unlock_irqrestore(io_lock, flags); |
| 1677 | |
| 1678 | /* Now queue the abort command to firmware */ |
| 1679 | int_to_scsilun(sc->device->lun, &fc_lun); |
| 1680 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1681 | if (fnic_queue_abort_io_req(fnic, abt_tag, |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1682 | FCPIO_ITMF_ABT_TASK_TERM, |
| 1683 | fc_lun.scsi_lun, io_req)) { |
| 1684 | /* |
| 1685 | * Revert the cmd state back to old state, if |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1686 | * it hasn't changed in between. This cmd will get |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1687 | * aborted later by scsi_eh, or cleaned up during |
| 1688 | * lun reset |
| 1689 | */ |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1690 | spin_lock_irqsave(io_lock, flags); |
| 1691 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) |
| 1692 | CMD_STATE(sc) = old_ioreq_state; |
| 1693 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1694 | } else { |
| 1695 | spin_lock_irqsave(io_lock, flags); |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 1696 | if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) |
| 1697 | CMD_FLAGS(sc) |= FNIC_DEV_RST_TERM_ISSUED; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1698 | else |
| 1699 | CMD_FLAGS(sc) |= FNIC_IO_INTERNAL_TERM_ISSUED; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1700 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1701 | atomic64_inc(&term_stats->terminates); |
| 1702 | term_cnt++; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1703 | } |
| 1704 | } |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1705 | if (term_cnt > atomic64_read(&term_stats->max_terminates)) |
| 1706 | atomic64_set(&term_stats->max_terminates, term_cnt); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1707 | |
| 1708 | } |
| 1709 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1710 | /* |
| 1711 | * This function is exported to SCSI for sending abort cmnds. |
| 1712 | * A SCSI IO is represented by a io_req in the driver. |
| 1713 | * The ioreq is linked to the SCSI Cmd, thus a link with the ULP's IO. |
| 1714 | */ |
| 1715 | int fnic_abort_cmd(struct scsi_cmnd *sc) |
| 1716 | { |
| 1717 | struct fc_lport *lp; |
| 1718 | struct fnic *fnic; |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 1719 | struct fnic_io_req *io_req = NULL; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1720 | struct fc_rport *rport; |
| 1721 | spinlock_t *io_lock; |
| 1722 | unsigned long flags; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1723 | unsigned long start_time = 0; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1724 | int ret = SUCCESS; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1725 | u32 task_req = 0; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1726 | struct scsi_lun fc_lun; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1727 | struct fnic_stats *fnic_stats; |
| 1728 | struct abort_stats *abts_stats; |
| 1729 | struct terminate_stats *term_stats; |
Hiral Shah | 6681866 | 2014-04-18 12:28:18 -0700 | [diff] [blame] | 1730 | enum fnic_ioreq_state old_ioreq_state; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1731 | int tag; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1732 | DECLARE_COMPLETION_ONSTACK(tm_done); |
| 1733 | |
| 1734 | /* Wait for rport to unblock */ |
Christof Schmitt | 65d430f | 2009-10-30 17:59:29 +0100 | [diff] [blame] | 1735 | fc_block_scsi_eh(sc); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1736 | |
| 1737 | /* Get local-port, check ready and link up */ |
| 1738 | lp = shost_priv(sc->device->host); |
| 1739 | |
| 1740 | fnic = lport_priv(lp); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1741 | fnic_stats = &fnic->fnic_stats; |
| 1742 | abts_stats = &fnic->fnic_stats.abts_stats; |
| 1743 | term_stats = &fnic->fnic_stats.term_stats; |
| 1744 | |
Roel Kluin | 0db6f43 | 2010-06-11 16:44:46 -0700 | [diff] [blame] | 1745 | rport = starget_to_rport(scsi_target(sc->device)); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1746 | tag = sc->request->tag; |
| 1747 | FNIC_SCSI_DBG(KERN_DEBUG, |
| 1748 | fnic->lport->host, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 1749 | "Abort Cmd called FCID 0x%x, LUN 0x%llx TAG %x flags %x\n", |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1750 | rport->port_id, sc->device->lun, tag, CMD_FLAGS(sc)); |
| 1751 | |
| 1752 | CMD_FLAGS(sc) = FNIC_NO_FLAGS; |
| 1753 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1754 | if (lp->state != LPORT_ST_READY || !(lp->link_up)) { |
| 1755 | ret = FAILED; |
| 1756 | goto fnic_abort_cmd_end; |
| 1757 | } |
| 1758 | |
| 1759 | /* |
| 1760 | * Avoid a race between SCSI issuing the abort and the device |
| 1761 | * completing the command. |
| 1762 | * |
| 1763 | * If the command is already completed by the fw cmpl code, |
| 1764 | * we just return SUCCESS from here. This means that the abort |
| 1765 | * succeeded. In the SCSI ML, since the timeout for command has |
| 1766 | * happened, the completion wont actually complete the command |
| 1767 | * and it will be considered as an aborted command |
| 1768 | * |
| 1769 | * The CMD_SP will not be cleared except while holding io_req_lock. |
| 1770 | */ |
| 1771 | io_lock = fnic_io_lock_hash(fnic, sc); |
| 1772 | spin_lock_irqsave(io_lock, flags); |
| 1773 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 1774 | if (!io_req) { |
| 1775 | spin_unlock_irqrestore(io_lock, flags); |
| 1776 | goto fnic_abort_cmd_end; |
| 1777 | } |
| 1778 | |
| 1779 | io_req->abts_done = &tm_done; |
| 1780 | |
| 1781 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { |
| 1782 | spin_unlock_irqrestore(io_lock, flags); |
| 1783 | goto wait_pending; |
| 1784 | } |
| 1785 | /* |
| 1786 | * Command is still pending, need to abort it |
| 1787 | * If the firmware completes the command after this point, |
| 1788 | * the completion wont be done till mid-layer, since abort |
| 1789 | * has already started. |
| 1790 | */ |
Hiral Shah | 6681866 | 2014-04-18 12:28:18 -0700 | [diff] [blame] | 1791 | old_ioreq_state = CMD_STATE(sc); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1792 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; |
| 1793 | CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE; |
| 1794 | |
| 1795 | spin_unlock_irqrestore(io_lock, flags); |
| 1796 | |
| 1797 | /* |
| 1798 | * Check readiness of the remote port. If the path to remote |
| 1799 | * port is up, then send abts to the remote port to terminate |
| 1800 | * the IO. Else, just locally terminate the IO in the firmware |
| 1801 | */ |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1802 | if (fc_remote_port_chkready(rport) == 0) |
| 1803 | task_req = FCPIO_ITMF_ABT_TASK; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1804 | else { |
| 1805 | atomic64_inc(&fnic_stats->misc_stats.rport_not_ready); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1806 | task_req = FCPIO_ITMF_ABT_TASK_TERM; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1807 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1808 | |
| 1809 | /* Now queue the abort command to firmware */ |
| 1810 | int_to_scsilun(sc->device->lun, &fc_lun); |
| 1811 | |
| 1812 | if (fnic_queue_abort_io_req(fnic, sc->request->tag, task_req, |
| 1813 | fc_lun.scsi_lun, io_req)) { |
| 1814 | spin_lock_irqsave(io_lock, flags); |
Hiral Shah | 6681866 | 2014-04-18 12:28:18 -0700 | [diff] [blame] | 1815 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) |
| 1816 | CMD_STATE(sc) = old_ioreq_state; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1817 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 1818 | if (io_req) |
| 1819 | io_req->abts_done = NULL; |
| 1820 | spin_unlock_irqrestore(io_lock, flags); |
| 1821 | ret = FAILED; |
| 1822 | goto fnic_abort_cmd_end; |
| 1823 | } |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1824 | if (task_req == FCPIO_ITMF_ABT_TASK) { |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1825 | CMD_FLAGS(sc) |= FNIC_IO_ABTS_ISSUED; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1826 | atomic64_inc(&fnic_stats->abts_stats.aborts); |
| 1827 | } else { |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1828 | CMD_FLAGS(sc) |= FNIC_IO_TERM_ISSUED; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1829 | atomic64_inc(&fnic_stats->term_stats.terminates); |
| 1830 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1831 | |
| 1832 | /* |
| 1833 | * We queued an abort IO, wait for its completion. |
| 1834 | * Once the firmware completes the abort command, it will |
| 1835 | * wake up this thread. |
| 1836 | */ |
| 1837 | wait_pending: |
| 1838 | wait_for_completion_timeout(&tm_done, |
| 1839 | msecs_to_jiffies |
| 1840 | (2 * fnic->config.ra_tov + |
| 1841 | fnic->config.ed_tov)); |
| 1842 | |
| 1843 | /* Check the abort status */ |
| 1844 | spin_lock_irqsave(io_lock, flags); |
| 1845 | |
| 1846 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 1847 | if (!io_req) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1848 | atomic64_inc(&fnic_stats->io_stats.ioreq_null); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1849 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1850 | CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_REQ_NULL; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1851 | ret = FAILED; |
| 1852 | goto fnic_abort_cmd_end; |
| 1853 | } |
| 1854 | io_req->abts_done = NULL; |
| 1855 | |
| 1856 | /* fw did not complete abort, timed out */ |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1857 | if (CMD_ABTS_STATUS(sc) == FCPIO_INVALID_CODE) { |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1858 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1859 | if (task_req == FCPIO_ITMF_ABT_TASK) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1860 | atomic64_inc(&abts_stats->abort_drv_timeouts); |
| 1861 | } else { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1862 | atomic64_inc(&term_stats->terminate_drv_timeouts); |
| 1863 | } |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1864 | CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_TIMED_OUT; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1865 | ret = FAILED; |
| 1866 | goto fnic_abort_cmd_end; |
| 1867 | } |
| 1868 | |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1869 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_COMPLETE; |
| 1870 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1871 | /* |
| 1872 | * firmware completed the abort, check the status, |
| 1873 | * free the io_req irrespective of failure or success |
| 1874 | */ |
| 1875 | if (CMD_ABTS_STATUS(sc) != FCPIO_SUCCESS) |
| 1876 | ret = FAILED; |
| 1877 | |
| 1878 | CMD_SP(sc) = NULL; |
| 1879 | |
| 1880 | spin_unlock_irqrestore(io_lock, flags); |
| 1881 | |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1882 | start_time = io_req->start_time; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1883 | fnic_release_ioreq_buf(fnic, io_req, sc); |
| 1884 | mempool_free(io_req, fnic->io_req_pool); |
| 1885 | |
| 1886 | fnic_abort_cmd_end: |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 1887 | FNIC_TRACE(fnic_abort_cmd, sc->device->host->host_no, |
| 1888 | sc->request->tag, sc, |
| 1889 | jiffies_to_msecs(jiffies - start_time), |
| 1890 | 0, ((u64)sc->cmnd[0] << 32 | |
| 1891 | (u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[3] << 16 | |
| 1892 | (u64)sc->cmnd[4] << 8 | sc->cmnd[5]), |
| 1893 | (((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); |
| 1894 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1895 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1896 | "Returning from abort cmd type %x %s\n", task_req, |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1897 | (ret == SUCCESS) ? |
| 1898 | "SUCCESS" : "FAILED"); |
| 1899 | return ret; |
| 1900 | } |
| 1901 | |
| 1902 | static inline int fnic_queue_dr_io_req(struct fnic *fnic, |
| 1903 | struct scsi_cmnd *sc, |
| 1904 | struct fnic_io_req *io_req) |
| 1905 | { |
| 1906 | struct vnic_wq_copy *wq = &fnic->wq_copy[0]; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1907 | struct Scsi_Host *host = fnic->lport->host; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1908 | struct misc_stats *misc_stats = &fnic->fnic_stats.misc_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1909 | struct scsi_lun fc_lun; |
| 1910 | int ret = 0; |
| 1911 | unsigned long intr_flags; |
| 1912 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1913 | spin_lock_irqsave(host->host_lock, intr_flags); |
| 1914 | if (unlikely(fnic_chk_state_flags_locked(fnic, |
| 1915 | FNIC_FLAGS_IO_BLOCKED))) { |
| 1916 | spin_unlock_irqrestore(host->host_lock, intr_flags); |
| 1917 | return FAILED; |
| 1918 | } else |
| 1919 | atomic_inc(&fnic->in_flight); |
| 1920 | spin_unlock_irqrestore(host->host_lock, intr_flags); |
| 1921 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1922 | spin_lock_irqsave(&fnic->wq_copy_lock[0], intr_flags); |
| 1923 | |
| 1924 | if (vnic_wq_copy_desc_avail(wq) <= fnic->wq_copy_desc_low[0]) |
| 1925 | free_wq_copy_descs(fnic, wq); |
| 1926 | |
| 1927 | if (!vnic_wq_copy_desc_avail(wq)) { |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 1928 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 1929 | "queue_dr_io_req failure - no descriptors\n"); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1930 | atomic64_inc(&misc_stats->devrst_cpwq_alloc_failures); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1931 | ret = -EAGAIN; |
| 1932 | goto lr_io_req_end; |
| 1933 | } |
| 1934 | |
| 1935 | /* fill in the lun info */ |
| 1936 | int_to_scsilun(sc->device->lun, &fc_lun); |
| 1937 | |
| 1938 | fnic_queue_wq_copy_desc_itmf(wq, sc->request->tag | FNIC_TAG_DEV_RST, |
| 1939 | 0, FCPIO_ITMF_LUN_RESET, SCSI_NO_TAG, |
| 1940 | fc_lun.scsi_lun, io_req->port_id, |
| 1941 | fnic->config.ra_tov, fnic->config.ed_tov); |
| 1942 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 1943 | atomic64_inc(&fnic->fnic_stats.fw_stats.active_fw_reqs); |
| 1944 | if (atomic64_read(&fnic->fnic_stats.fw_stats.active_fw_reqs) > |
| 1945 | atomic64_read(&fnic->fnic_stats.fw_stats.max_fw_reqs)) |
| 1946 | atomic64_set(&fnic->fnic_stats.fw_stats.max_fw_reqs, |
| 1947 | atomic64_read(&fnic->fnic_stats.fw_stats.active_fw_reqs)); |
| 1948 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1949 | lr_io_req_end: |
| 1950 | spin_unlock_irqrestore(&fnic->wq_copy_lock[0], intr_flags); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 1951 | atomic_dec(&fnic->in_flight); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1952 | |
| 1953 | return ret; |
| 1954 | } |
| 1955 | |
| 1956 | /* |
| 1957 | * Clean up any pending aborts on the lun |
| 1958 | * For each outstanding IO on this lun, whose abort is not completed by fw, |
| 1959 | * issue a local abort. Wait for abort to complete. Return 0 if all commands |
| 1960 | * successfully aborted, 1 otherwise |
| 1961 | */ |
| 1962 | static int fnic_clean_pending_aborts(struct fnic *fnic, |
| 1963 | struct scsi_cmnd *lr_sc) |
| 1964 | { |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 1965 | int tag, abt_tag; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1966 | struct fnic_io_req *io_req; |
| 1967 | spinlock_t *io_lock; |
| 1968 | unsigned long flags; |
| 1969 | int ret = 0; |
| 1970 | struct scsi_cmnd *sc; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1971 | struct scsi_lun fc_lun; |
| 1972 | struct scsi_device *lun_dev = lr_sc->device; |
| 1973 | DECLARE_COMPLETION_ONSTACK(tm_done); |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 1974 | enum fnic_ioreq_state old_ioreq_state; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1975 | |
Hiral Patel | fc85799 | 2013-09-09 13:31:51 -0700 | [diff] [blame] | 1976 | for (tag = 0; tag < fnic->fnic_max_tag_id; tag++) { |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1977 | io_lock = fnic_io_lock_tag(fnic, tag); |
| 1978 | spin_lock_irqsave(io_lock, flags); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1979 | sc = scsi_host_find_tag(fnic->lport->host, tag); |
| 1980 | /* |
| 1981 | * ignore this lun reset cmd or cmds that do not belong to |
| 1982 | * this lun |
| 1983 | */ |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1984 | if (!sc || sc == lr_sc || sc->device != lun_dev) { |
| 1985 | spin_unlock_irqrestore(io_lock, flags); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1986 | continue; |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 1987 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 1988 | |
| 1989 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 1990 | |
| 1991 | if (!io_req || sc->device != lun_dev) { |
| 1992 | spin_unlock_irqrestore(io_lock, flags); |
| 1993 | continue; |
| 1994 | } |
| 1995 | |
| 1996 | /* |
| 1997 | * Found IO that is still pending with firmware and |
| 1998 | * belongs to the LUN that we are resetting |
| 1999 | */ |
| 2000 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 2001 | "Found IO in %s on lun\n", |
| 2002 | fnic_ioreq_state_to_str(CMD_STATE(sc))); |
| 2003 | |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2004 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) { |
| 2005 | spin_unlock_irqrestore(io_lock, flags); |
| 2006 | continue; |
| 2007 | } |
| 2008 | if ((CMD_FLAGS(sc) & FNIC_DEVICE_RESET) && |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 2009 | (!(CMD_FLAGS(sc) & FNIC_DEV_RST_ISSUED))) { |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2010 | FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, |
| 2011 | "%s dev rst not pending sc 0x%p\n", __func__, |
| 2012 | sc); |
| 2013 | spin_unlock_irqrestore(io_lock, flags); |
| 2014 | continue; |
| 2015 | } |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 2016 | |
| 2017 | if (io_req->abts_done) |
| 2018 | shost_printk(KERN_ERR, fnic->lport->host, |
| 2019 | "%s: io_req->abts_done is set state is %s\n", |
| 2020 | __func__, fnic_ioreq_state_to_str(CMD_STATE(sc))); |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2021 | old_ioreq_state = CMD_STATE(sc); |
| 2022 | /* |
| 2023 | * Any pending IO issued prior to reset is expected to be |
| 2024 | * in abts pending state, if not we need to set |
| 2025 | * FNIC_IOREQ_ABTS_PENDING to indicate the IO is abort pending. |
| 2026 | * When IO is completed, the IO will be handed over and |
| 2027 | * handled in this function. |
| 2028 | */ |
| 2029 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; |
| 2030 | |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2031 | BUG_ON(io_req->abts_done); |
| 2032 | |
| 2033 | abt_tag = tag; |
| 2034 | if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) { |
| 2035 | abt_tag |= FNIC_TAG_DEV_RST; |
| 2036 | FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, |
| 2037 | "%s: dev rst sc 0x%p\n", __func__, sc); |
| 2038 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2039 | |
| 2040 | CMD_ABTS_STATUS(sc) = FCPIO_INVALID_CODE; |
| 2041 | io_req->abts_done = &tm_done; |
| 2042 | spin_unlock_irqrestore(io_lock, flags); |
| 2043 | |
| 2044 | /* Now queue the abort command to firmware */ |
| 2045 | int_to_scsilun(sc->device->lun, &fc_lun); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2046 | |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2047 | if (fnic_queue_abort_io_req(fnic, abt_tag, |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2048 | FCPIO_ITMF_ABT_TASK_TERM, |
| 2049 | fc_lun.scsi_lun, io_req)) { |
| 2050 | spin_lock_irqsave(io_lock, flags); |
| 2051 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 2052 | if (io_req) |
| 2053 | io_req->abts_done = NULL; |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2054 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) |
| 2055 | CMD_STATE(sc) = old_ioreq_state; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2056 | spin_unlock_irqrestore(io_lock, flags); |
| 2057 | ret = 1; |
| 2058 | goto clean_pending_aborts_end; |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2059 | } else { |
| 2060 | spin_lock_irqsave(io_lock, flags); |
| 2061 | if (CMD_FLAGS(sc) & FNIC_DEVICE_RESET) |
| 2062 | CMD_FLAGS(sc) |= FNIC_DEV_RST_TERM_ISSUED; |
| 2063 | spin_unlock_irqrestore(io_lock, flags); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2064 | } |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 2065 | CMD_FLAGS(sc) |= FNIC_IO_INTERNAL_TERM_ISSUED; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2066 | |
| 2067 | wait_for_completion_timeout(&tm_done, |
| 2068 | msecs_to_jiffies |
| 2069 | (fnic->config.ed_tov)); |
| 2070 | |
| 2071 | /* Recheck cmd state to check if it is now aborted */ |
| 2072 | spin_lock_irqsave(io_lock, flags); |
| 2073 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 2074 | if (!io_req) { |
| 2075 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 2076 | CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_REQ_NULL; |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2077 | continue; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | io_req->abts_done = NULL; |
| 2081 | |
| 2082 | /* if abort is still pending with fw, fail */ |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 2083 | if (CMD_ABTS_STATUS(sc) == FCPIO_INVALID_CODE) { |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2084 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 2085 | CMD_FLAGS(sc) |= FNIC_IO_ABT_TERM_DONE; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2086 | ret = 1; |
| 2087 | goto clean_pending_aborts_end; |
| 2088 | } |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 2089 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_COMPLETE; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2090 | CMD_SP(sc) = NULL; |
| 2091 | spin_unlock_irqrestore(io_lock, flags); |
| 2092 | |
| 2093 | fnic_release_ioreq_buf(fnic, io_req, sc); |
| 2094 | mempool_free(io_req, fnic->io_req_pool); |
| 2095 | } |
| 2096 | |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2097 | schedule_timeout(msecs_to_jiffies(2 * fnic->config.ed_tov)); |
| 2098 | |
| 2099 | /* walk again to check, if IOs are still pending in fw */ |
| 2100 | if (fnic_is_abts_pending(fnic, lr_sc)) |
| 2101 | ret = FAILED; |
| 2102 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2103 | clean_pending_aborts_end: |
| 2104 | return ret; |
| 2105 | } |
| 2106 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2107 | /** |
| 2108 | * fnic_scsi_host_start_tag |
| 2109 | * Allocates tagid from host's tag list |
| 2110 | **/ |
| 2111 | static inline int |
| 2112 | fnic_scsi_host_start_tag(struct fnic *fnic, struct scsi_cmnd *sc) |
| 2113 | { |
| 2114 | struct blk_queue_tag *bqt = fnic->lport->host->bqt; |
| 2115 | int tag, ret = SCSI_NO_TAG; |
| 2116 | |
| 2117 | BUG_ON(!bqt); |
| 2118 | if (!bqt) { |
| 2119 | pr_err("Tags are not supported\n"); |
| 2120 | goto end; |
| 2121 | } |
| 2122 | |
| 2123 | do { |
| 2124 | tag = find_next_zero_bit(bqt->tag_map, bqt->max_depth, 1); |
| 2125 | if (tag >= bqt->max_depth) { |
| 2126 | pr_err("Tag allocation failure\n"); |
| 2127 | goto end; |
| 2128 | } |
| 2129 | } while (test_and_set_bit(tag, bqt->tag_map)); |
| 2130 | |
| 2131 | bqt->tag_index[tag] = sc->request; |
| 2132 | sc->request->tag = tag; |
| 2133 | sc->tag = tag; |
| 2134 | if (!sc->request->special) |
| 2135 | sc->request->special = sc; |
| 2136 | |
| 2137 | ret = tag; |
| 2138 | |
| 2139 | end: |
| 2140 | return ret; |
| 2141 | } |
| 2142 | |
| 2143 | /** |
| 2144 | * fnic_scsi_host_end_tag |
| 2145 | * frees tag allocated by fnic_scsi_host_start_tag. |
| 2146 | **/ |
| 2147 | static inline void |
| 2148 | fnic_scsi_host_end_tag(struct fnic *fnic, struct scsi_cmnd *sc) |
| 2149 | { |
| 2150 | struct blk_queue_tag *bqt = fnic->lport->host->bqt; |
| 2151 | int tag = sc->request->tag; |
| 2152 | |
| 2153 | if (tag == SCSI_NO_TAG) |
| 2154 | return; |
| 2155 | |
| 2156 | BUG_ON(!bqt || !bqt->tag_index[tag]); |
| 2157 | if (!bqt) |
| 2158 | return; |
| 2159 | |
| 2160 | bqt->tag_index[tag] = NULL; |
| 2161 | clear_bit(tag, bqt->tag_map); |
| 2162 | |
| 2163 | return; |
| 2164 | } |
| 2165 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2166 | /* |
| 2167 | * SCSI Eh thread issues a Lun Reset when one or more commands on a LUN |
| 2168 | * fail to get aborted. It calls driver's eh_device_reset with a SCSI command |
| 2169 | * on the LUN. |
| 2170 | */ |
| 2171 | int fnic_device_reset(struct scsi_cmnd *sc) |
| 2172 | { |
| 2173 | struct fc_lport *lp; |
| 2174 | struct fnic *fnic; |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 2175 | struct fnic_io_req *io_req = NULL; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2176 | struct fc_rport *rport; |
| 2177 | int status; |
| 2178 | int ret = FAILED; |
| 2179 | spinlock_t *io_lock; |
| 2180 | unsigned long flags; |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 2181 | unsigned long start_time = 0; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2182 | struct scsi_lun fc_lun; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 2183 | struct fnic_stats *fnic_stats; |
| 2184 | struct reset_stats *reset_stats; |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 2185 | int tag = 0; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2186 | DECLARE_COMPLETION_ONSTACK(tm_done); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2187 | int tag_gen_flag = 0; /*to track tags allocated by fnic driver*/ |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2188 | |
| 2189 | /* Wait for rport to unblock */ |
Christof Schmitt | 65d430f | 2009-10-30 17:59:29 +0100 | [diff] [blame] | 2190 | fc_block_scsi_eh(sc); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2191 | |
| 2192 | /* Get local-port, check ready and link up */ |
| 2193 | lp = shost_priv(sc->device->host); |
| 2194 | |
| 2195 | fnic = lport_priv(lp); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 2196 | fnic_stats = &fnic->fnic_stats; |
| 2197 | reset_stats = &fnic->fnic_stats.reset_stats; |
| 2198 | |
| 2199 | atomic64_inc(&reset_stats->device_resets); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2200 | |
Roel Kluin | 0db6f43 | 2010-06-11 16:44:46 -0700 | [diff] [blame] | 2201 | rport = starget_to_rport(scsi_target(sc->device)); |
| 2202 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 2203 | "Device reset called FCID 0x%x, LUN 0x%llx sc 0x%p\n", |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2204 | rport->port_id, sc->device->lun, sc); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2205 | |
| 2206 | if (lp->state != LPORT_ST_READY || !(lp->link_up)) |
| 2207 | goto fnic_device_reset_end; |
| 2208 | |
| 2209 | /* Check if remote port up */ |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 2210 | if (fc_remote_port_chkready(rport)) { |
| 2211 | atomic64_inc(&fnic_stats->misc_stats.rport_not_ready); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2212 | goto fnic_device_reset_end; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 2213 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2214 | |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 2215 | CMD_FLAGS(sc) = FNIC_DEVICE_RESET; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2216 | /* Allocate tag if not present */ |
| 2217 | |
| 2218 | tag = sc->request->tag; |
| 2219 | if (unlikely(tag < 0)) { |
Christoph Hellwig | 4d63716 | 2014-06-12 14:53:23 +0200 | [diff] [blame] | 2220 | /* |
| 2221 | * XXX(hch): current the midlayer fakes up a struct |
| 2222 | * request for the explicit reset ioctls, and those |
| 2223 | * don't have a tag allocated to them. The below |
| 2224 | * code pokes into midlayer structures to paper over |
| 2225 | * this design issue, but that won't work for blk-mq. |
| 2226 | * |
| 2227 | * Either someone who can actually test the hardware |
| 2228 | * will have to come up with a similar hack for the |
| 2229 | * blk-mq case, or we'll have to bite the bullet and |
| 2230 | * fix the way the EH ioctls work for real, but until |
| 2231 | * that happens we fail these explicit requests here. |
| 2232 | */ |
| 2233 | if (shost_use_blk_mq(sc->device->host)) |
| 2234 | goto fnic_device_reset_end; |
| 2235 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2236 | tag = fnic_scsi_host_start_tag(fnic, sc); |
| 2237 | if (unlikely(tag == SCSI_NO_TAG)) |
| 2238 | goto fnic_device_reset_end; |
| 2239 | tag_gen_flag = 1; |
| 2240 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2241 | io_lock = fnic_io_lock_hash(fnic, sc); |
| 2242 | spin_lock_irqsave(io_lock, flags); |
| 2243 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 2244 | |
| 2245 | /* |
| 2246 | * If there is a io_req attached to this command, then use it, |
| 2247 | * else allocate a new one. |
| 2248 | */ |
| 2249 | if (!io_req) { |
| 2250 | io_req = mempool_alloc(fnic->io_req_pool, GFP_ATOMIC); |
| 2251 | if (!io_req) { |
| 2252 | spin_unlock_irqrestore(io_lock, flags); |
| 2253 | goto fnic_device_reset_end; |
| 2254 | } |
| 2255 | memset(io_req, 0, sizeof(*io_req)); |
| 2256 | io_req->port_id = rport->port_id; |
| 2257 | CMD_SP(sc) = (char *)io_req; |
| 2258 | } |
| 2259 | io_req->dr_done = &tm_done; |
| 2260 | CMD_STATE(sc) = FNIC_IOREQ_CMD_PENDING; |
| 2261 | CMD_LR_STATUS(sc) = FCPIO_INVALID_CODE; |
| 2262 | spin_unlock_irqrestore(io_lock, flags); |
| 2263 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2264 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, "TAG %x\n", tag); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2265 | |
| 2266 | /* |
| 2267 | * issue the device reset, if enqueue failed, clean up the ioreq |
| 2268 | * and break assoc with scsi cmd |
| 2269 | */ |
| 2270 | if (fnic_queue_dr_io_req(fnic, sc, io_req)) { |
| 2271 | spin_lock_irqsave(io_lock, flags); |
| 2272 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 2273 | if (io_req) |
| 2274 | io_req->dr_done = NULL; |
| 2275 | goto fnic_device_reset_clean; |
| 2276 | } |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2277 | spin_lock_irqsave(io_lock, flags); |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 2278 | CMD_FLAGS(sc) |= FNIC_DEV_RST_ISSUED; |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2279 | spin_unlock_irqrestore(io_lock, flags); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2280 | |
| 2281 | /* |
| 2282 | * Wait on the local completion for LUN reset. The io_req may be |
| 2283 | * freed while we wait since we hold no lock. |
| 2284 | */ |
| 2285 | wait_for_completion_timeout(&tm_done, |
| 2286 | msecs_to_jiffies(FNIC_LUN_RESET_TIMEOUT)); |
| 2287 | |
| 2288 | spin_lock_irqsave(io_lock, flags); |
| 2289 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 2290 | if (!io_req) { |
| 2291 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2292 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 2293 | "io_req is null tag 0x%x sc 0x%p\n", tag, sc); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2294 | goto fnic_device_reset_end; |
| 2295 | } |
| 2296 | io_req->dr_done = NULL; |
| 2297 | |
| 2298 | status = CMD_LR_STATUS(sc); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2299 | |
| 2300 | /* |
| 2301 | * If lun reset not completed, bail out with failed. io_req |
| 2302 | * gets cleaned up during higher levels of EH |
| 2303 | */ |
| 2304 | if (status == FCPIO_INVALID_CODE) { |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 2305 | atomic64_inc(&reset_stats->device_reset_timeouts); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2306 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 2307 | "Device reset timed out\n"); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2308 | CMD_FLAGS(sc) |= FNIC_DEV_RST_TIMED_OUT; |
| 2309 | spin_unlock_irqrestore(io_lock, flags); |
| 2310 | int_to_scsilun(sc->device->lun, &fc_lun); |
| 2311 | /* |
Sesidhar Beddel | 1259c5d | 2013-09-09 13:31:49 -0700 | [diff] [blame] | 2312 | * Issue abort and terminate on device reset request. |
| 2313 | * If q'ing of terminate fails, retry it after a delay. |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2314 | */ |
| 2315 | while (1) { |
| 2316 | spin_lock_irqsave(io_lock, flags); |
| 2317 | if (CMD_FLAGS(sc) & FNIC_DEV_RST_TERM_ISSUED) { |
| 2318 | spin_unlock_irqrestore(io_lock, flags); |
| 2319 | break; |
| 2320 | } |
| 2321 | spin_unlock_irqrestore(io_lock, flags); |
| 2322 | if (fnic_queue_abort_io_req(fnic, |
| 2323 | tag | FNIC_TAG_DEV_RST, |
| 2324 | FCPIO_ITMF_ABT_TASK_TERM, |
| 2325 | fc_lun.scsi_lun, io_req)) { |
| 2326 | wait_for_completion_timeout(&tm_done, |
| 2327 | msecs_to_jiffies(FNIC_ABT_TERM_DELAY_TIMEOUT)); |
| 2328 | } else { |
| 2329 | spin_lock_irqsave(io_lock, flags); |
| 2330 | CMD_FLAGS(sc) |= FNIC_DEV_RST_TERM_ISSUED; |
| 2331 | CMD_STATE(sc) = FNIC_IOREQ_ABTS_PENDING; |
| 2332 | io_req->abts_done = &tm_done; |
| 2333 | spin_unlock_irqrestore(io_lock, flags); |
| 2334 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 2335 | "Abort and terminate issued on Device reset " |
| 2336 | "tag 0x%x sc 0x%p\n", tag, sc); |
| 2337 | break; |
| 2338 | } |
| 2339 | } |
| 2340 | while (1) { |
| 2341 | spin_lock_irqsave(io_lock, flags); |
| 2342 | if (!(CMD_FLAGS(sc) & FNIC_DEV_RST_DONE)) { |
| 2343 | spin_unlock_irqrestore(io_lock, flags); |
| 2344 | wait_for_completion_timeout(&tm_done, |
| 2345 | msecs_to_jiffies(FNIC_LUN_RESET_TIMEOUT)); |
| 2346 | break; |
| 2347 | } else { |
| 2348 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 2349 | io_req->abts_done = NULL; |
| 2350 | goto fnic_device_reset_clean; |
| 2351 | } |
| 2352 | } |
| 2353 | } else { |
| 2354 | spin_unlock_irqrestore(io_lock, flags); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | /* Completed, but not successful, clean up the io_req, return fail */ |
| 2358 | if (status != FCPIO_SUCCESS) { |
| 2359 | spin_lock_irqsave(io_lock, flags); |
| 2360 | FNIC_SCSI_DBG(KERN_DEBUG, |
| 2361 | fnic->lport->host, |
| 2362 | "Device reset completed - failed\n"); |
| 2363 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 2364 | goto fnic_device_reset_clean; |
| 2365 | } |
| 2366 | |
| 2367 | /* |
| 2368 | * Clean up any aborts on this lun that have still not |
| 2369 | * completed. If any of these fail, then LUN reset fails. |
| 2370 | * clean_pending_aborts cleans all cmds on this lun except |
| 2371 | * the lun reset cmd. If all cmds get cleaned, the lun reset |
| 2372 | * succeeds |
| 2373 | */ |
| 2374 | if (fnic_clean_pending_aborts(fnic, sc)) { |
| 2375 | spin_lock_irqsave(io_lock, flags); |
| 2376 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 2377 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 2378 | "Device reset failed" |
| 2379 | " since could not abort all IOs\n"); |
| 2380 | goto fnic_device_reset_clean; |
| 2381 | } |
| 2382 | |
| 2383 | /* Clean lun reset command */ |
| 2384 | spin_lock_irqsave(io_lock, flags); |
| 2385 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 2386 | if (io_req) |
| 2387 | /* Completed, and successful */ |
| 2388 | ret = SUCCESS; |
| 2389 | |
| 2390 | fnic_device_reset_clean: |
| 2391 | if (io_req) |
| 2392 | CMD_SP(sc) = NULL; |
| 2393 | |
| 2394 | spin_unlock_irqrestore(io_lock, flags); |
| 2395 | |
| 2396 | if (io_req) { |
Hiral Patel | 14eb5d9 | 2013-02-12 17:01:01 -0800 | [diff] [blame] | 2397 | start_time = io_req->start_time; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2398 | fnic_release_ioreq_buf(fnic, io_req, sc); |
| 2399 | mempool_free(io_req, fnic->io_req_pool); |
| 2400 | } |
| 2401 | |
| 2402 | fnic_device_reset_end: |
Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 2403 | FNIC_TRACE(fnic_device_reset, sc->device->host->host_no, |
| 2404 | sc->request->tag, sc, |
| 2405 | jiffies_to_msecs(jiffies - start_time), |
| 2406 | 0, ((u64)sc->cmnd[0] << 32 | |
| 2407 | (u64)sc->cmnd[2] << 24 | (u64)sc->cmnd[3] << 16 | |
| 2408 | (u64)sc->cmnd[4] << 8 | sc->cmnd[5]), |
| 2409 | (((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); |
| 2410 | |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2411 | /* free tag if it is allocated */ |
| 2412 | if (unlikely(tag_gen_flag)) |
| 2413 | fnic_scsi_host_end_tag(fnic, sc); |
| 2414 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2415 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 2416 | "Returning from device reset %s\n", |
| 2417 | (ret == SUCCESS) ? |
| 2418 | "SUCCESS" : "FAILED"); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 2419 | |
| 2420 | if (ret == FAILED) |
| 2421 | atomic64_inc(&reset_stats->device_reset_failures); |
| 2422 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2423 | return ret; |
| 2424 | } |
| 2425 | |
| 2426 | /* Clean up all IOs, clean up libFC local port */ |
| 2427 | int fnic_reset(struct Scsi_Host *shost) |
| 2428 | { |
| 2429 | struct fc_lport *lp; |
| 2430 | struct fnic *fnic; |
Narsimhulu Musini | 441fbd2 | 2013-09-12 17:45:41 -0700 | [diff] [blame] | 2431 | int ret = 0; |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 2432 | struct reset_stats *reset_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2433 | |
| 2434 | lp = shost_priv(shost); |
| 2435 | fnic = lport_priv(lp); |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 2436 | reset_stats = &fnic->fnic_stats.reset_stats; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2437 | |
| 2438 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 2439 | "fnic_reset called\n"); |
| 2440 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 2441 | atomic64_inc(&reset_stats->fnic_resets); |
| 2442 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2443 | /* |
| 2444 | * Reset local port, this will clean up libFC exchanges, |
| 2445 | * reset remote port sessions, and if link is up, begin flogi |
| 2446 | */ |
Narsimhulu Musini | 441fbd2 | 2013-09-12 17:45:41 -0700 | [diff] [blame] | 2447 | ret = lp->tt.lport_reset(lp); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2448 | |
| 2449 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 2450 | "Returning from fnic reset %s\n", |
Narsimhulu Musini | 441fbd2 | 2013-09-12 17:45:41 -0700 | [diff] [blame] | 2451 | (ret == 0) ? |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2452 | "SUCCESS" : "FAILED"); |
| 2453 | |
Hiral Patel | 67125b0 | 2013-09-12 17:45:42 -0700 | [diff] [blame] | 2454 | if (ret == 0) |
| 2455 | atomic64_inc(&reset_stats->fnic_reset_completions); |
| 2456 | else |
| 2457 | atomic64_inc(&reset_stats->fnic_reset_failures); |
| 2458 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2459 | return ret; |
| 2460 | } |
| 2461 | |
| 2462 | /* |
| 2463 | * SCSI Error handling calls driver's eh_host_reset if all prior |
| 2464 | * error handling levels return FAILED. If host reset completes |
| 2465 | * successfully, and if link is up, then Fabric login begins. |
| 2466 | * |
| 2467 | * Host Reset is the highest level of error recovery. If this fails, then |
| 2468 | * host is offlined by SCSI. |
| 2469 | * |
| 2470 | */ |
| 2471 | int fnic_host_reset(struct scsi_cmnd *sc) |
| 2472 | { |
| 2473 | int ret; |
| 2474 | unsigned long wait_host_tmo; |
| 2475 | struct Scsi_Host *shost = sc->device->host; |
| 2476 | struct fc_lport *lp = shost_priv(shost); |
| 2477 | |
| 2478 | /* |
| 2479 | * If fnic_reset is successful, wait for fabric login to complete |
| 2480 | * scsi-ml tries to send a TUR to every device if host reset is |
| 2481 | * successful, so before returning to scsi, fabric should be up |
| 2482 | */ |
Narsimhulu Musini | 441fbd2 | 2013-09-12 17:45:41 -0700 | [diff] [blame] | 2483 | ret = (fnic_reset(shost) == 0) ? SUCCESS : FAILED; |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2484 | if (ret == SUCCESS) { |
| 2485 | wait_host_tmo = jiffies + FNIC_HOST_RESET_SETTLE_TIME * HZ; |
| 2486 | ret = FAILED; |
| 2487 | while (time_before(jiffies, wait_host_tmo)) { |
| 2488 | if ((lp->state == LPORT_ST_READY) && |
| 2489 | (lp->link_up)) { |
| 2490 | ret = SUCCESS; |
| 2491 | break; |
| 2492 | } |
| 2493 | ssleep(1); |
| 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | return ret; |
| 2498 | } |
| 2499 | |
| 2500 | /* |
| 2501 | * This fxn is called from libFC when host is removed |
| 2502 | */ |
| 2503 | void fnic_scsi_abort_io(struct fc_lport *lp) |
| 2504 | { |
| 2505 | int err = 0; |
| 2506 | unsigned long flags; |
| 2507 | enum fnic_state old_state; |
| 2508 | struct fnic *fnic = lport_priv(lp); |
| 2509 | DECLARE_COMPLETION_ONSTACK(remove_wait); |
| 2510 | |
| 2511 | /* Issue firmware reset for fnic, wait for reset to complete */ |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2512 | retry_fw_reset: |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2513 | spin_lock_irqsave(&fnic->fnic_lock, flags); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2514 | if (unlikely(fnic->state == FNIC_IN_FC_TRANS_ETH_MODE)) { |
| 2515 | /* fw reset is in progress, poll for its completion */ |
| 2516 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
| 2517 | schedule_timeout(msecs_to_jiffies(100)); |
| 2518 | goto retry_fw_reset; |
| 2519 | } |
| 2520 | |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2521 | fnic->remove_wait = &remove_wait; |
| 2522 | old_state = fnic->state; |
| 2523 | fnic->state = FNIC_IN_FC_TRANS_ETH_MODE; |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 2524 | fnic_update_mac_locked(fnic, fnic->ctlr.ctl_src_addr); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2525 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
| 2526 | |
| 2527 | err = fnic_fw_reset_handler(fnic); |
| 2528 | if (err) { |
| 2529 | spin_lock_irqsave(&fnic->fnic_lock, flags); |
| 2530 | if (fnic->state == FNIC_IN_FC_TRANS_ETH_MODE) |
| 2531 | fnic->state = old_state; |
| 2532 | fnic->remove_wait = NULL; |
| 2533 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
| 2534 | return; |
| 2535 | } |
| 2536 | |
| 2537 | /* Wait for firmware reset to complete */ |
| 2538 | wait_for_completion_timeout(&remove_wait, |
| 2539 | msecs_to_jiffies(FNIC_RMDEVICE_TIMEOUT)); |
| 2540 | |
| 2541 | spin_lock_irqsave(&fnic->fnic_lock, flags); |
| 2542 | fnic->remove_wait = NULL; |
| 2543 | FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host, |
| 2544 | "fnic_scsi_abort_io %s\n", |
| 2545 | (fnic->state == FNIC_IN_ETH_MODE) ? |
| 2546 | "SUCCESS" : "FAILED"); |
| 2547 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
| 2548 | |
| 2549 | } |
| 2550 | |
| 2551 | /* |
| 2552 | * This fxn called from libFC to clean up driver IO state on link down |
| 2553 | */ |
| 2554 | void fnic_scsi_cleanup(struct fc_lport *lp) |
| 2555 | { |
| 2556 | unsigned long flags; |
| 2557 | enum fnic_state old_state; |
| 2558 | struct fnic *fnic = lport_priv(lp); |
| 2559 | |
| 2560 | /* issue fw reset */ |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2561 | retry_fw_reset: |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2562 | spin_lock_irqsave(&fnic->fnic_lock, flags); |
Hiral Patel | 0329855 | 2013-02-12 17:00:58 -0800 | [diff] [blame] | 2563 | if (unlikely(fnic->state == FNIC_IN_FC_TRANS_ETH_MODE)) { |
| 2564 | /* fw reset is in progress, poll for its completion */ |
| 2565 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
| 2566 | schedule_timeout(msecs_to_jiffies(100)); |
| 2567 | goto retry_fw_reset; |
| 2568 | } |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2569 | old_state = fnic->state; |
| 2570 | fnic->state = FNIC_IN_FC_TRANS_ETH_MODE; |
Joe Eykholt | 78112e5 | 2009-11-03 11:49:22 -0800 | [diff] [blame] | 2571 | fnic_update_mac_locked(fnic, fnic->ctlr.ctl_src_addr); |
Abhijeet Joglekar | 5df6d73 | 2009-04-17 18:33:26 -0700 | [diff] [blame] | 2572 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
| 2573 | |
| 2574 | if (fnic_fw_reset_handler(fnic)) { |
| 2575 | spin_lock_irqsave(&fnic->fnic_lock, flags); |
| 2576 | if (fnic->state == FNIC_IN_FC_TRANS_ETH_MODE) |
| 2577 | fnic->state = old_state; |
| 2578 | spin_unlock_irqrestore(&fnic->fnic_lock, flags); |
| 2579 | } |
| 2580 | |
| 2581 | } |
| 2582 | |
| 2583 | void fnic_empty_scsi_cleanup(struct fc_lport *lp) |
| 2584 | { |
| 2585 | } |
| 2586 | |
| 2587 | void fnic_exch_mgr_reset(struct fc_lport *lp, u32 sid, u32 did) |
| 2588 | { |
| 2589 | struct fnic *fnic = lport_priv(lp); |
| 2590 | |
| 2591 | /* Non-zero sid, nothing to do */ |
| 2592 | if (sid) |
| 2593 | goto call_fc_exch_mgr_reset; |
| 2594 | |
| 2595 | if (did) { |
| 2596 | fnic_rport_exch_reset(fnic, did); |
| 2597 | goto call_fc_exch_mgr_reset; |
| 2598 | } |
| 2599 | |
| 2600 | /* |
| 2601 | * sid = 0, did = 0 |
| 2602 | * link down or device being removed |
| 2603 | */ |
| 2604 | if (!fnic->in_remove) |
| 2605 | fnic_scsi_cleanup(lp); |
| 2606 | else |
| 2607 | fnic_scsi_abort_io(lp); |
| 2608 | |
| 2609 | /* call libFC exch mgr reset to reset its exchanges */ |
| 2610 | call_fc_exch_mgr_reset: |
| 2611 | fc_exch_mgr_reset(lp, sid, did); |
| 2612 | |
| 2613 | } |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2614 | |
| 2615 | /* |
| 2616 | * fnic_is_abts_pending() is a helper function that |
| 2617 | * walks through tag map to check if there is any IOs pending,if there is one, |
| 2618 | * then it returns 1 (true), otherwise 0 (false) |
| 2619 | * if @lr_sc is non NULL, then it checks IOs specific to particular LUN, |
| 2620 | * otherwise, it checks for all IOs. |
| 2621 | */ |
| 2622 | int fnic_is_abts_pending(struct fnic *fnic, struct scsi_cmnd *lr_sc) |
| 2623 | { |
| 2624 | int tag; |
| 2625 | struct fnic_io_req *io_req; |
| 2626 | spinlock_t *io_lock; |
| 2627 | unsigned long flags; |
| 2628 | int ret = 0; |
| 2629 | struct scsi_cmnd *sc; |
| 2630 | struct scsi_device *lun_dev = NULL; |
| 2631 | |
| 2632 | if (lr_sc) |
| 2633 | lun_dev = lr_sc->device; |
| 2634 | |
| 2635 | /* walk again to check, if IOs are still pending in fw */ |
Hiral Patel | fc85799 | 2013-09-09 13:31:51 -0700 | [diff] [blame] | 2636 | for (tag = 0; tag < fnic->fnic_max_tag_id; tag++) { |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2637 | sc = scsi_host_find_tag(fnic->lport->host, tag); |
| 2638 | /* |
| 2639 | * ignore this lun reset cmd or cmds that do not belong to |
| 2640 | * this lun |
| 2641 | */ |
| 2642 | if (!sc || (lr_sc && (sc->device != lun_dev || sc == lr_sc))) |
| 2643 | continue; |
| 2644 | |
| 2645 | io_lock = fnic_io_lock_hash(fnic, sc); |
| 2646 | spin_lock_irqsave(io_lock, flags); |
| 2647 | |
| 2648 | io_req = (struct fnic_io_req *)CMD_SP(sc); |
| 2649 | |
| 2650 | if (!io_req || sc->device != lun_dev) { |
| 2651 | spin_unlock_irqrestore(io_lock, flags); |
| 2652 | continue; |
| 2653 | } |
| 2654 | |
| 2655 | /* |
| 2656 | * Found IO that is still pending with firmware and |
| 2657 | * belongs to the LUN that we are resetting |
| 2658 | */ |
| 2659 | FNIC_SCSI_DBG(KERN_INFO, fnic->lport->host, |
| 2660 | "Found IO in %s on lun\n", |
| 2661 | fnic_ioreq_state_to_str(CMD_STATE(sc))); |
| 2662 | |
Dan Carpenter | 5d65f91 | 2013-05-30 10:50:46 +0300 | [diff] [blame] | 2663 | if (CMD_STATE(sc) == FNIC_IOREQ_ABTS_PENDING) |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2664 | ret = 1; |
Dan Carpenter | 5d65f91 | 2013-05-30 10:50:46 +0300 | [diff] [blame] | 2665 | spin_unlock_irqrestore(io_lock, flags); |
Hiral Patel | a0bf1ca | 2013-02-12 17:01:00 -0800 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | return ret; |
| 2669 | } |