James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
| 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | f25e8e7 | 2015-04-07 15:07:28 -0400 | [diff] [blame^] | 4 | * Copyright (C) 2009-2015 Emulex. All rights reserved. * |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| 6 | * www.emulex.com * |
| 7 | * * |
| 8 | * This program is free software; you can redistribute it and/or * |
| 9 | * modify it under the terms of version 2 of the GNU General * |
| 10 | * Public License as published by the Free Software Foundation. * |
| 11 | * This program is distributed in the hope that it will be useful. * |
| 12 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 13 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 15 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 16 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 17 | * more details, a copy of which can be found in the file COPYING * |
| 18 | * included with this package. * |
| 19 | *******************************************************************/ |
| 20 | |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/mempool.h> |
| 23 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
James Smart | 277e76f | 2010-02-18 11:07:15 -0500 | [diff] [blame] | 25 | #include <linux/delay.h> |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 26 | #include <linux/list.h> |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 27 | |
| 28 | #include <scsi/scsi.h> |
| 29 | #include <scsi/scsi_host.h> |
| 30 | #include <scsi/scsi_transport_fc.h> |
| 31 | #include <scsi/scsi_bsg_fc.h> |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 32 | #include <scsi/fc/fc_fs.h> |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 33 | |
| 34 | #include "lpfc_hw4.h" |
| 35 | #include "lpfc_hw.h" |
| 36 | #include "lpfc_sli.h" |
| 37 | #include "lpfc_sli4.h" |
| 38 | #include "lpfc_nl.h" |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 39 | #include "lpfc_bsg.h" |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 40 | #include "lpfc_disc.h" |
| 41 | #include "lpfc_scsi.h" |
| 42 | #include "lpfc.h" |
| 43 | #include "lpfc_logmsg.h" |
| 44 | #include "lpfc_crtn.h" |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 45 | #include "lpfc_debugfs.h" |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 46 | #include "lpfc_vport.h" |
| 47 | #include "lpfc_version.h" |
| 48 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 49 | struct lpfc_bsg_event { |
| 50 | struct list_head node; |
| 51 | struct kref kref; |
| 52 | wait_queue_head_t wq; |
| 53 | |
| 54 | /* Event type and waiter identifiers */ |
| 55 | uint32_t type_mask; |
| 56 | uint32_t req_id; |
| 57 | uint32_t reg_id; |
| 58 | |
| 59 | /* next two flags are here for the auto-delete logic */ |
| 60 | unsigned long wait_time_stamp; |
| 61 | int waiting; |
| 62 | |
| 63 | /* seen and not seen events */ |
| 64 | struct list_head events_to_get; |
| 65 | struct list_head events_to_see; |
| 66 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 67 | /* driver data associated with the job */ |
| 68 | void *dd_data; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | struct lpfc_bsg_iocb { |
| 72 | struct lpfc_iocbq *cmdiocbq; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 73 | struct lpfc_dmabuf *rmp; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 74 | struct lpfc_nodelist *ndlp; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 75 | }; |
| 76 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 77 | struct lpfc_bsg_mbox { |
| 78 | LPFC_MBOXQ_t *pmboxq; |
| 79 | MAILBOX_t *mb; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 80 | struct lpfc_dmabuf *dmabuffers; /* for BIU diags */ |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 81 | uint8_t *ext; /* extended mailbox data */ |
| 82 | uint32_t mbOffset; /* from app */ |
| 83 | uint32_t inExtWLen; /* from app */ |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 84 | uint32_t outExtWLen; /* from app */ |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 85 | }; |
| 86 | |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 87 | #define MENLO_DID 0x0000FC0E |
| 88 | |
| 89 | struct lpfc_bsg_menlo { |
| 90 | struct lpfc_iocbq *cmdiocbq; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 91 | struct lpfc_dmabuf *rmp; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 92 | }; |
| 93 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 94 | #define TYPE_EVT 1 |
| 95 | #define TYPE_IOCB 2 |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 96 | #define TYPE_MBOX 3 |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 97 | #define TYPE_MENLO 4 |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 98 | struct bsg_job_data { |
| 99 | uint32_t type; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 100 | struct fc_bsg_job *set_job; /* job waiting for this iocb to finish */ |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 101 | union { |
| 102 | struct lpfc_bsg_event *evt; |
| 103 | struct lpfc_bsg_iocb iocb; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 104 | struct lpfc_bsg_mbox mbox; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 105 | struct lpfc_bsg_menlo menlo; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 106 | } context_un; |
| 107 | }; |
| 108 | |
| 109 | struct event_data { |
| 110 | struct list_head node; |
| 111 | uint32_t type; |
| 112 | uint32_t immed_dat; |
| 113 | void *data; |
| 114 | uint32_t len; |
| 115 | }; |
| 116 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 117 | #define BUF_SZ_4K 4096 |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 118 | #define SLI_CT_ELX_LOOPBACK 0x10 |
| 119 | |
| 120 | enum ELX_LOOPBACK_CMD { |
| 121 | ELX_LOOPBACK_XRI_SETUP, |
| 122 | ELX_LOOPBACK_DATA, |
| 123 | }; |
| 124 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 125 | #define ELX_LOOPBACK_HEADER_SZ \ |
| 126 | (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un) |
| 127 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 128 | struct lpfc_dmabufext { |
| 129 | struct lpfc_dmabuf dma; |
| 130 | uint32_t size; |
| 131 | uint32_t flag; |
| 132 | }; |
| 133 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 134 | static void |
| 135 | lpfc_free_bsg_buffers(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist) |
| 136 | { |
| 137 | struct lpfc_dmabuf *mlast, *next_mlast; |
| 138 | |
| 139 | if (mlist) { |
| 140 | list_for_each_entry_safe(mlast, next_mlast, &mlist->list, |
| 141 | list) { |
| 142 | lpfc_mbuf_free(phba, mlast->virt, mlast->phys); |
| 143 | list_del(&mlast->list); |
| 144 | kfree(mlast); |
| 145 | } |
| 146 | lpfc_mbuf_free(phba, mlist->virt, mlist->phys); |
| 147 | kfree(mlist); |
| 148 | } |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | static struct lpfc_dmabuf * |
| 153 | lpfc_alloc_bsg_buffers(struct lpfc_hba *phba, unsigned int size, |
| 154 | int outbound_buffers, struct ulp_bde64 *bpl, |
| 155 | int *bpl_entries) |
| 156 | { |
| 157 | struct lpfc_dmabuf *mlist = NULL; |
| 158 | struct lpfc_dmabuf *mp; |
| 159 | unsigned int bytes_left = size; |
| 160 | |
| 161 | /* Verify we can support the size specified */ |
| 162 | if (!size || (size > (*bpl_entries * LPFC_BPL_SIZE))) |
| 163 | return NULL; |
| 164 | |
| 165 | /* Determine the number of dma buffers to allocate */ |
| 166 | *bpl_entries = (size % LPFC_BPL_SIZE ? size/LPFC_BPL_SIZE + 1 : |
| 167 | size/LPFC_BPL_SIZE); |
| 168 | |
| 169 | /* Allocate dma buffer and place in BPL passed */ |
| 170 | while (bytes_left) { |
| 171 | /* Allocate dma buffer */ |
| 172 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 173 | if (!mp) { |
| 174 | if (mlist) |
| 175 | lpfc_free_bsg_buffers(phba, mlist); |
| 176 | return NULL; |
| 177 | } |
| 178 | |
| 179 | INIT_LIST_HEAD(&mp->list); |
| 180 | mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys)); |
| 181 | |
| 182 | if (!mp->virt) { |
| 183 | kfree(mp); |
| 184 | if (mlist) |
| 185 | lpfc_free_bsg_buffers(phba, mlist); |
| 186 | return NULL; |
| 187 | } |
| 188 | |
| 189 | /* Queue it to a linked list */ |
| 190 | if (!mlist) |
| 191 | mlist = mp; |
| 192 | else |
| 193 | list_add_tail(&mp->list, &mlist->list); |
| 194 | |
| 195 | /* Add buffer to buffer pointer list */ |
| 196 | if (outbound_buffers) |
| 197 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 198 | else |
| 199 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 200 | bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys)); |
| 201 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys)); |
| 202 | bpl->tus.f.bdeSize = (uint16_t) |
| 203 | (bytes_left >= LPFC_BPL_SIZE ? LPFC_BPL_SIZE : |
| 204 | bytes_left); |
| 205 | bytes_left -= bpl->tus.f.bdeSize; |
| 206 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 207 | bpl++; |
| 208 | } |
| 209 | return mlist; |
| 210 | } |
| 211 | |
| 212 | static unsigned int |
| 213 | lpfc_bsg_copy_data(struct lpfc_dmabuf *dma_buffers, |
| 214 | struct fc_bsg_buffer *bsg_buffers, |
| 215 | unsigned int bytes_to_transfer, int to_buffers) |
| 216 | { |
| 217 | |
| 218 | struct lpfc_dmabuf *mp; |
| 219 | unsigned int transfer_bytes, bytes_copied = 0; |
| 220 | unsigned int sg_offset, dma_offset; |
| 221 | unsigned char *dma_address, *sg_address; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 222 | LIST_HEAD(temp_list); |
James Smart | d5ce53b | 2013-04-17 20:17:26 -0400 | [diff] [blame] | 223 | struct sg_mapping_iter miter; |
| 224 | unsigned long flags; |
| 225 | unsigned int sg_flags = SG_MITER_ATOMIC; |
| 226 | bool sg_valid; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 227 | |
| 228 | list_splice_init(&dma_buffers->list, &temp_list); |
| 229 | list_add(&dma_buffers->list, &temp_list); |
| 230 | sg_offset = 0; |
James Smart | d5ce53b | 2013-04-17 20:17:26 -0400 | [diff] [blame] | 231 | if (to_buffers) |
| 232 | sg_flags |= SG_MITER_FROM_SG; |
| 233 | else |
| 234 | sg_flags |= SG_MITER_TO_SG; |
| 235 | sg_miter_start(&miter, bsg_buffers->sg_list, bsg_buffers->sg_cnt, |
| 236 | sg_flags); |
| 237 | local_irq_save(flags); |
| 238 | sg_valid = sg_miter_next(&miter); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 239 | list_for_each_entry(mp, &temp_list, list) { |
| 240 | dma_offset = 0; |
James Smart | d5ce53b | 2013-04-17 20:17:26 -0400 | [diff] [blame] | 241 | while (bytes_to_transfer && sg_valid && |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 242 | (dma_offset < LPFC_BPL_SIZE)) { |
| 243 | dma_address = mp->virt + dma_offset; |
| 244 | if (sg_offset) { |
| 245 | /* Continue previous partial transfer of sg */ |
James Smart | d5ce53b | 2013-04-17 20:17:26 -0400 | [diff] [blame] | 246 | sg_address = miter.addr + sg_offset; |
| 247 | transfer_bytes = miter.length - sg_offset; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 248 | } else { |
James Smart | d5ce53b | 2013-04-17 20:17:26 -0400 | [diff] [blame] | 249 | sg_address = miter.addr; |
| 250 | transfer_bytes = miter.length; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 251 | } |
| 252 | if (bytes_to_transfer < transfer_bytes) |
| 253 | transfer_bytes = bytes_to_transfer; |
| 254 | if (transfer_bytes > (LPFC_BPL_SIZE - dma_offset)) |
| 255 | transfer_bytes = LPFC_BPL_SIZE - dma_offset; |
| 256 | if (to_buffers) |
| 257 | memcpy(dma_address, sg_address, transfer_bytes); |
| 258 | else |
| 259 | memcpy(sg_address, dma_address, transfer_bytes); |
| 260 | dma_offset += transfer_bytes; |
| 261 | sg_offset += transfer_bytes; |
| 262 | bytes_to_transfer -= transfer_bytes; |
| 263 | bytes_copied += transfer_bytes; |
James Smart | d5ce53b | 2013-04-17 20:17:26 -0400 | [diff] [blame] | 264 | if (sg_offset >= miter.length) { |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 265 | sg_offset = 0; |
James Smart | d5ce53b | 2013-04-17 20:17:26 -0400 | [diff] [blame] | 266 | sg_valid = sg_miter_next(&miter); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | } |
James Smart | d5ce53b | 2013-04-17 20:17:26 -0400 | [diff] [blame] | 270 | sg_miter_stop(&miter); |
| 271 | local_irq_restore(flags); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 272 | list_del_init(&dma_buffers->list); |
| 273 | list_splice(&temp_list, &dma_buffers->list); |
| 274 | return bytes_copied; |
| 275 | } |
| 276 | |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 277 | /** |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 278 | * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler |
| 279 | * @phba: Pointer to HBA context object. |
| 280 | * @cmdiocbq: Pointer to command iocb. |
| 281 | * @rspiocbq: Pointer to response iocb. |
| 282 | * |
| 283 | * This function is the completion handler for iocbs issued using |
| 284 | * lpfc_bsg_send_mgmt_cmd function. This function is called by the |
| 285 | * ring event handler function without any lock held. This function |
| 286 | * can be called from both worker thread context and interrupt |
| 287 | * context. This function also can be called from another thread which |
| 288 | * cleans up the SLI layer objects. |
| 289 | * This function copies the contents of the response iocb to the |
| 290 | * response iocb memory object provided by the caller of |
| 291 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 292 | * sleeps for the iocb completion. |
| 293 | **/ |
| 294 | static void |
| 295 | lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba, |
| 296 | struct lpfc_iocbq *cmdiocbq, |
| 297 | struct lpfc_iocbq *rspiocbq) |
| 298 | { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 299 | struct bsg_job_data *dd_data; |
| 300 | struct fc_bsg_job *job; |
| 301 | IOCB_t *rsp; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 302 | struct lpfc_dmabuf *bmp, *cmp, *rmp; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 303 | struct lpfc_nodelist *ndlp; |
| 304 | struct lpfc_bsg_iocb *iocb; |
| 305 | unsigned long flags; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 306 | unsigned int rsp_size; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 307 | int rc = 0; |
| 308 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 309 | dd_data = cmdiocbq->context1; |
| 310 | |
| 311 | /* Determine if job has been aborted */ |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 312 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 313 | job = dd_data->set_job; |
| 314 | if (job) { |
| 315 | /* Prevent timeout handling from trying to abort job */ |
| 316 | job->dd_data = NULL; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 317 | } |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 318 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 319 | |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 320 | /* Close the timeout handler abort window */ |
| 321 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 1b8d11a | 2013-09-06 12:20:51 -0400 | [diff] [blame] | 322 | cmdiocbq->iocb_flag &= ~LPFC_IO_CMD_OUTSTANDING; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 323 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 324 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 325 | iocb = &dd_data->context_un.iocb; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 326 | ndlp = iocb->ndlp; |
| 327 | rmp = iocb->rmp; |
| 328 | cmp = cmdiocbq->context2; |
| 329 | bmp = cmdiocbq->context3; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 330 | rsp = &rspiocbq->iocb; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 331 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 332 | /* Copy the completed data or set the error status */ |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 333 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 334 | if (job) { |
| 335 | if (rsp->ulpStatus) { |
| 336 | if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
| 337 | switch (rsp->un.ulpWord[4] & IOERR_PARAM_MASK) { |
| 338 | case IOERR_SEQUENCE_TIMEOUT: |
| 339 | rc = -ETIMEDOUT; |
| 340 | break; |
| 341 | case IOERR_INVALID_RPI: |
| 342 | rc = -EFAULT; |
| 343 | break; |
| 344 | default: |
| 345 | rc = -EACCES; |
| 346 | break; |
| 347 | } |
| 348 | } else { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 349 | rc = -EACCES; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 350 | } |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 351 | } else { |
| 352 | rsp_size = rsp->un.genreq64.bdl.bdeSize; |
| 353 | job->reply->reply_payload_rcv_len = |
| 354 | lpfc_bsg_copy_data(rmp, &job->reply_payload, |
| 355 | rsp_size, 0); |
| 356 | } |
| 357 | } |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 358 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 359 | lpfc_free_bsg_buffers(phba, cmp); |
| 360 | lpfc_free_bsg_buffers(phba, rmp); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 361 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 362 | kfree(bmp); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 363 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 364 | lpfc_nlp_put(ndlp); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 365 | kfree(dd_data); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 366 | |
| 367 | /* Complete the job if the job is still active */ |
| 368 | |
| 369 | if (job) { |
| 370 | job->reply->result = rc; |
| 371 | job->job_done(job); |
| 372 | } |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 373 | return; |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 378 | * @job: fc_bsg_job to handle |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 379 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 380 | static int |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 381 | lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job) |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 382 | { |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 383 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
| 384 | struct lpfc_hba *phba = vport->phba; |
| 385 | struct lpfc_rport_data *rdata = job->rport->dd_data; |
| 386 | struct lpfc_nodelist *ndlp = rdata->pnode; |
| 387 | struct ulp_bde64 *bpl = NULL; |
| 388 | uint32_t timeout; |
| 389 | struct lpfc_iocbq *cmdiocbq = NULL; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 390 | IOCB_t *cmd; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 391 | struct lpfc_dmabuf *bmp = NULL, *cmp = NULL, *rmp = NULL; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 392 | int request_nseg; |
| 393 | int reply_nseg; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 394 | struct bsg_job_data *dd_data; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 395 | unsigned long flags; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 396 | uint32_t creg_val; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 397 | int rc = 0; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 398 | int iocb_stat; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 399 | |
| 400 | /* in case no data is transferred */ |
| 401 | job->reply->reply_payload_rcv_len = 0; |
| 402 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 403 | /* allocate our bsg tracking structure */ |
| 404 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); |
| 405 | if (!dd_data) { |
| 406 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 407 | "2733 Failed allocation of dd_data\n"); |
| 408 | rc = -ENOMEM; |
| 409 | goto no_dd_data; |
| 410 | } |
| 411 | |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 412 | if (!lpfc_nlp_get(ndlp)) { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 413 | rc = -ENODEV; |
| 414 | goto no_ndlp; |
| 415 | } |
| 416 | |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 417 | if (ndlp->nlp_flag & NLP_ELS_SND_MASK) { |
| 418 | rc = -ENODEV; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 419 | goto free_ndlp; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 420 | } |
| 421 | |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 422 | cmdiocbq = lpfc_sli_get_iocbq(phba); |
| 423 | if (!cmdiocbq) { |
| 424 | rc = -ENOMEM; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 425 | goto free_ndlp; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 426 | } |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 427 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 428 | cmd = &cmdiocbq->iocb; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 429 | |
| 430 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 431 | if (!bmp) { |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 432 | rc = -ENOMEM; |
James Smart | be858b6 | 2010-12-15 17:57:20 -0500 | [diff] [blame] | 433 | goto free_cmdiocbq; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 434 | } |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 435 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys); |
| 436 | if (!bmp->virt) { |
| 437 | rc = -ENOMEM; |
| 438 | goto free_bmp; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 439 | } |
| 440 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 441 | INIT_LIST_HEAD(&bmp->list); |
| 442 | |
| 443 | bpl = (struct ulp_bde64 *) bmp->virt; |
| 444 | request_nseg = LPFC_BPL_SIZE/sizeof(struct ulp_bde64); |
| 445 | cmp = lpfc_alloc_bsg_buffers(phba, job->request_payload.payload_len, |
| 446 | 1, bpl, &request_nseg); |
| 447 | if (!cmp) { |
| 448 | rc = -ENOMEM; |
| 449 | goto free_bmp; |
| 450 | } |
| 451 | lpfc_bsg_copy_data(cmp, &job->request_payload, |
| 452 | job->request_payload.payload_len, 1); |
| 453 | |
| 454 | bpl += request_nseg; |
| 455 | reply_nseg = LPFC_BPL_SIZE/sizeof(struct ulp_bde64) - request_nseg; |
| 456 | rmp = lpfc_alloc_bsg_buffers(phba, job->reply_payload.payload_len, 0, |
| 457 | bpl, &reply_nseg); |
| 458 | if (!rmp) { |
| 459 | rc = -ENOMEM; |
| 460 | goto free_cmp; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | cmd->un.genreq64.bdl.ulpIoTag32 = 0; |
| 464 | cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); |
| 465 | cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); |
| 466 | cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 467 | cmd->un.genreq64.bdl.bdeSize = |
| 468 | (request_nseg + reply_nseg) * sizeof(struct ulp_bde64); |
| 469 | cmd->ulpCommand = CMD_GEN_REQUEST64_CR; |
| 470 | cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA); |
| 471 | cmd->un.genreq64.w5.hcsw.Dfctl = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 472 | cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; |
| 473 | cmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 474 | cmd->ulpBdeCount = 1; |
| 475 | cmd->ulpLe = 1; |
| 476 | cmd->ulpClass = CLASS3; |
| 477 | cmd->ulpContext = ndlp->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 478 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 479 | cmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 480 | cmd->ulpOwner = OWN_CHIP; |
| 481 | cmdiocbq->vport = phba->pport; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 482 | cmdiocbq->context3 = bmp; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 483 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 484 | timeout = phba->fc_ratov * 2; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 485 | cmd->ulpTimeout = timeout; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 486 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 487 | cmdiocbq->iocb_cmpl = lpfc_bsg_send_mgmt_cmd_cmp; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 488 | cmdiocbq->context1 = dd_data; |
| 489 | cmdiocbq->context2 = cmp; |
| 490 | cmdiocbq->context3 = bmp; |
James Smart | d5ce53b | 2013-04-17 20:17:26 -0400 | [diff] [blame] | 491 | cmdiocbq->context_un.ndlp = ndlp; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 492 | dd_data->type = TYPE_IOCB; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 493 | dd_data->set_job = job; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 494 | dd_data->context_un.iocb.cmdiocbq = cmdiocbq; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 495 | dd_data->context_un.iocb.ndlp = ndlp; |
| 496 | dd_data->context_un.iocb.rmp = rmp; |
| 497 | job->dd_data = dd_data; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 498 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 499 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 500 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
| 501 | rc = -EIO ; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 502 | goto free_rmp; |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 503 | } |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 504 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 505 | writel(creg_val, phba->HCregaddr); |
| 506 | readl(phba->HCregaddr); /* flush */ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 507 | } |
| 508 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 509 | iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0); |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 510 | |
| 511 | if (iocb_stat == IOCB_SUCCESS) { |
| 512 | spin_lock_irqsave(&phba->hbalock, flags); |
| 513 | /* make sure the I/O had not been completed yet */ |
| 514 | if (cmdiocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 515 | /* open up abort window to timeout handler */ |
James Smart | 1b8d11a | 2013-09-06 12:20:51 -0400 | [diff] [blame] | 516 | cmdiocbq->iocb_flag |= LPFC_IO_CMD_OUTSTANDING; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 517 | } |
| 518 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 519 | return 0; /* done for now */ |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 520 | } else if (iocb_stat == IOCB_BUSY) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 521 | rc = -EAGAIN; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 522 | } else { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 523 | rc = -EIO; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 524 | } |
James Smart | 2a9bf3d | 2010-06-07 15:24:45 -0400 | [diff] [blame] | 525 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 526 | /* iocb failed so cleanup */ |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 527 | job->dd_data = NULL; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 528 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 529 | free_rmp: |
| 530 | lpfc_free_bsg_buffers(phba, rmp); |
| 531 | free_cmp: |
| 532 | lpfc_free_bsg_buffers(phba, cmp); |
| 533 | free_bmp: |
| 534 | if (bmp->virt) |
| 535 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
| 536 | kfree(bmp); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 537 | free_cmdiocbq: |
| 538 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 539 | free_ndlp: |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 540 | lpfc_nlp_put(ndlp); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 541 | no_ndlp: |
| 542 | kfree(dd_data); |
| 543 | no_dd_data: |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 544 | /* make error code available to userspace */ |
| 545 | job->reply->result = rc; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 546 | job->dd_data = NULL; |
| 547 | return rc; |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler |
| 552 | * @phba: Pointer to HBA context object. |
| 553 | * @cmdiocbq: Pointer to command iocb. |
| 554 | * @rspiocbq: Pointer to response iocb. |
| 555 | * |
| 556 | * This function is the completion handler for iocbs issued using |
| 557 | * lpfc_bsg_rport_els_cmp function. This function is called by the |
| 558 | * ring event handler function without any lock held. This function |
| 559 | * can be called from both worker thread context and interrupt |
| 560 | * context. This function also can be called from other thread which |
| 561 | * cleans up the SLI layer objects. |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 562 | * This function copies the contents of the response iocb to the |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 563 | * response iocb memory object provided by the caller of |
| 564 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 565 | * sleeps for the iocb completion. |
| 566 | **/ |
| 567 | static void |
| 568 | lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba, |
| 569 | struct lpfc_iocbq *cmdiocbq, |
| 570 | struct lpfc_iocbq *rspiocbq) |
| 571 | { |
| 572 | struct bsg_job_data *dd_data; |
| 573 | struct fc_bsg_job *job; |
| 574 | IOCB_t *rsp; |
| 575 | struct lpfc_nodelist *ndlp; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 576 | struct lpfc_dmabuf *pcmd = NULL, *prsp = NULL; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 577 | struct fc_bsg_ctels_reply *els_reply; |
| 578 | uint8_t *rjt_data; |
| 579 | unsigned long flags; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 580 | unsigned int rsp_size; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 581 | int rc = 0; |
| 582 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 583 | dd_data = cmdiocbq->context1; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 584 | ndlp = dd_data->context_un.iocb.ndlp; |
| 585 | cmdiocbq->context1 = ndlp; |
| 586 | |
| 587 | /* Determine if job has been aborted */ |
| 588 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 589 | job = dd_data->set_job; |
| 590 | if (job) { |
| 591 | /* Prevent timeout handling from trying to abort job */ |
| 592 | job->dd_data = NULL; |
| 593 | } |
| 594 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 595 | |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 596 | /* Close the timeout handler abort window */ |
| 597 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 1b8d11a | 2013-09-06 12:20:51 -0400 | [diff] [blame] | 598 | cmdiocbq->iocb_flag &= ~LPFC_IO_CMD_OUTSTANDING; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 599 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 600 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 601 | rsp = &rspiocbq->iocb; |
| 602 | pcmd = (struct lpfc_dmabuf *)cmdiocbq->context2; |
| 603 | prsp = (struct lpfc_dmabuf *)pcmd->list.next; |
| 604 | |
| 605 | /* Copy the completed job data or determine the job status if job is |
| 606 | * still active |
| 607 | */ |
| 608 | |
| 609 | if (job) { |
| 610 | if (rsp->ulpStatus == IOSTAT_SUCCESS) { |
| 611 | rsp_size = rsp->un.elsreq64.bdl.bdeSize; |
| 612 | job->reply->reply_payload_rcv_len = |
| 613 | sg_copy_from_buffer(job->reply_payload.sg_list, |
| 614 | job->reply_payload.sg_cnt, |
| 615 | prsp->virt, |
| 616 | rsp_size); |
| 617 | } else if (rsp->ulpStatus == IOSTAT_LS_RJT) { |
| 618 | job->reply->reply_payload_rcv_len = |
| 619 | sizeof(struct fc_bsg_ctels_reply); |
| 620 | /* LS_RJT data returned in word 4 */ |
| 621 | rjt_data = (uint8_t *)&rsp->un.ulpWord[4]; |
| 622 | els_reply = &job->reply->reply_data.ctels_reply; |
| 623 | els_reply->status = FC_CTELS_STATUS_REJECT; |
| 624 | els_reply->rjt_data.action = rjt_data[3]; |
| 625 | els_reply->rjt_data.reason_code = rjt_data[2]; |
| 626 | els_reply->rjt_data.reason_explanation = rjt_data[1]; |
| 627 | els_reply->rjt_data.vendor_unique = rjt_data[0]; |
| 628 | } else { |
| 629 | rc = -EIO; |
| 630 | } |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 631 | } |
| 632 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 633 | lpfc_nlp_put(ndlp); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 634 | lpfc_els_free_iocb(phba, cmdiocbq); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 635 | kfree(dd_data); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 636 | |
| 637 | /* Complete the job if the job is still active */ |
| 638 | |
| 639 | if (job) { |
| 640 | job->reply->result = rc; |
| 641 | job->job_done(job); |
| 642 | } |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 643 | return; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | /** |
| 647 | * lpfc_bsg_rport_els - send an ELS command from a bsg request |
| 648 | * @job: fc_bsg_job to handle |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 649 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 650 | static int |
| 651 | lpfc_bsg_rport_els(struct fc_bsg_job *job) |
| 652 | { |
| 653 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
| 654 | struct lpfc_hba *phba = vport->phba; |
| 655 | struct lpfc_rport_data *rdata = job->rport->dd_data; |
| 656 | struct lpfc_nodelist *ndlp = rdata->pnode; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 657 | uint32_t elscmd; |
| 658 | uint32_t cmdsize; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 659 | struct lpfc_iocbq *cmdiocbq; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 660 | uint16_t rpi = 0; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 661 | struct bsg_job_data *dd_data; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 662 | unsigned long flags; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 663 | uint32_t creg_val; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 664 | int rc = 0; |
| 665 | |
| 666 | /* in case no data is transferred */ |
| 667 | job->reply->reply_payload_rcv_len = 0; |
| 668 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 669 | /* verify the els command is not greater than the |
| 670 | * maximum ELS transfer size. |
| 671 | */ |
| 672 | |
| 673 | if (job->request_payload.payload_len > FCELSSIZE) { |
| 674 | rc = -EINVAL; |
| 675 | goto no_dd_data; |
| 676 | } |
| 677 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 678 | /* allocate our bsg tracking structure */ |
| 679 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); |
| 680 | if (!dd_data) { |
| 681 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 682 | "2735 Failed allocation of dd_data\n"); |
| 683 | rc = -ENOMEM; |
| 684 | goto no_dd_data; |
| 685 | } |
| 686 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 687 | elscmd = job->request->rqst_data.r_els.els_code; |
| 688 | cmdsize = job->request_payload.payload_len; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 689 | |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 690 | if (!lpfc_nlp_get(ndlp)) { |
| 691 | rc = -ENODEV; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 692 | goto free_dd_data; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 693 | } |
| 694 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 695 | /* We will use the allocated dma buffers by prep els iocb for command |
| 696 | * and response to ensure if the job times out and the request is freed, |
| 697 | * we won't be dma into memory that is no longer allocated to for the |
| 698 | * request. |
| 699 | */ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 700 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 701 | cmdiocbq = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 702 | ndlp->nlp_DID, elscmd); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 703 | if (!cmdiocbq) { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 704 | rc = -EIO; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 705 | goto release_ndlp; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 706 | } |
| 707 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 708 | rpi = ndlp->nlp_rpi; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 709 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 710 | /* Transfer the request payload to allocated command dma buffer */ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 711 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 712 | sg_copy_to_buffer(job->request_payload.sg_list, |
| 713 | job->request_payload.sg_cnt, |
| 714 | ((struct lpfc_dmabuf *)cmdiocbq->context2)->virt, |
| 715 | cmdsize); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 716 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 717 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 718 | cmdiocbq->iocb.ulpContext = phba->sli4_hba.rpi_ids[rpi]; |
| 719 | else |
| 720 | cmdiocbq->iocb.ulpContext = rpi; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 721 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 722 | cmdiocbq->context1 = dd_data; |
James Smart | 93d1379e | 2012-05-09 21:19:34 -0400 | [diff] [blame] | 723 | cmdiocbq->context_un.ndlp = ndlp; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 724 | cmdiocbq->iocb_cmpl = lpfc_bsg_rport_els_cmp; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 725 | dd_data->type = TYPE_IOCB; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 726 | dd_data->set_job = job; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 727 | dd_data->context_un.iocb.cmdiocbq = cmdiocbq; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 728 | dd_data->context_un.iocb.ndlp = ndlp; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 729 | dd_data->context_un.iocb.rmp = NULL; |
| 730 | job->dd_data = dd_data; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 731 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 732 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 733 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
| 734 | rc = -EIO; |
| 735 | goto linkdown_err; |
| 736 | } |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 737 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 738 | writel(creg_val, phba->HCregaddr); |
| 739 | readl(phba->HCregaddr); /* flush */ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 740 | } |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 741 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 742 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 743 | |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 744 | if (rc == IOCB_SUCCESS) { |
| 745 | spin_lock_irqsave(&phba->hbalock, flags); |
| 746 | /* make sure the I/O had not been completed/released */ |
| 747 | if (cmdiocbq->iocb_flag & LPFC_IO_LIBDFC) { |
| 748 | /* open up abort window to timeout handler */ |
James Smart | 1b8d11a | 2013-09-06 12:20:51 -0400 | [diff] [blame] | 749 | cmdiocbq->iocb_flag |= LPFC_IO_CMD_OUTSTANDING; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 750 | } |
| 751 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 752 | return 0; /* done for now */ |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 753 | } else if (rc == IOCB_BUSY) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 754 | rc = -EAGAIN; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 755 | } else { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 756 | rc = -EIO; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | /* iocb failed so cleanup */ |
| 760 | job->dd_data = NULL; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 761 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 762 | linkdown_err: |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 763 | cmdiocbq->context1 = ndlp; |
| 764 | lpfc_els_free_iocb(phba, cmdiocbq); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 765 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 766 | release_ndlp: |
| 767 | lpfc_nlp_put(ndlp); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 768 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 769 | free_dd_data: |
| 770 | kfree(dd_data); |
| 771 | |
| 772 | no_dd_data: |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 773 | /* make error code available to userspace */ |
| 774 | job->reply->result = rc; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 775 | job->dd_data = NULL; |
| 776 | return rc; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 777 | } |
| 778 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 779 | /** |
| 780 | * lpfc_bsg_event_free - frees an allocated event structure |
| 781 | * @kref: Pointer to a kref. |
| 782 | * |
| 783 | * Called from kref_put. Back cast the kref into an event structure address. |
| 784 | * Free any events to get, delete associated nodes, free any events to see, |
| 785 | * free any data then free the event itself. |
| 786 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 787 | static void |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 788 | lpfc_bsg_event_free(struct kref *kref) |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 789 | { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 790 | struct lpfc_bsg_event *evt = container_of(kref, struct lpfc_bsg_event, |
| 791 | kref); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 792 | struct event_data *ed; |
| 793 | |
| 794 | list_del(&evt->node); |
| 795 | |
| 796 | while (!list_empty(&evt->events_to_get)) { |
| 797 | ed = list_entry(evt->events_to_get.next, typeof(*ed), node); |
| 798 | list_del(&ed->node); |
| 799 | kfree(ed->data); |
| 800 | kfree(ed); |
| 801 | } |
| 802 | |
| 803 | while (!list_empty(&evt->events_to_see)) { |
| 804 | ed = list_entry(evt->events_to_see.next, typeof(*ed), node); |
| 805 | list_del(&ed->node); |
| 806 | kfree(ed->data); |
| 807 | kfree(ed); |
| 808 | } |
| 809 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 810 | kfree(evt->dd_data); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 811 | kfree(evt); |
| 812 | } |
| 813 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 814 | /** |
| 815 | * lpfc_bsg_event_ref - increments the kref for an event |
| 816 | * @evt: Pointer to an event structure. |
| 817 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 818 | static inline void |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 819 | lpfc_bsg_event_ref(struct lpfc_bsg_event *evt) |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 820 | { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 821 | kref_get(&evt->kref); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 822 | } |
| 823 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 824 | /** |
| 825 | * lpfc_bsg_event_unref - Uses kref_put to free an event structure |
| 826 | * @evt: Pointer to an event structure. |
| 827 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 828 | static inline void |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 829 | lpfc_bsg_event_unref(struct lpfc_bsg_event *evt) |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 830 | { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 831 | kref_put(&evt->kref, lpfc_bsg_event_free); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 832 | } |
| 833 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 834 | /** |
| 835 | * lpfc_bsg_event_new - allocate and initialize a event structure |
| 836 | * @ev_mask: Mask of events. |
| 837 | * @ev_reg_id: Event reg id. |
| 838 | * @ev_req_id: Event request id. |
| 839 | **/ |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 840 | static struct lpfc_bsg_event * |
| 841 | lpfc_bsg_event_new(uint32_t ev_mask, int ev_reg_id, uint32_t ev_req_id) |
| 842 | { |
| 843 | struct lpfc_bsg_event *evt = kzalloc(sizeof(*evt), GFP_KERNEL); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 844 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 845 | if (!evt) |
| 846 | return NULL; |
| 847 | |
| 848 | INIT_LIST_HEAD(&evt->events_to_get); |
| 849 | INIT_LIST_HEAD(&evt->events_to_see); |
| 850 | evt->type_mask = ev_mask; |
| 851 | evt->req_id = ev_req_id; |
| 852 | evt->reg_id = ev_reg_id; |
| 853 | evt->wait_time_stamp = jiffies; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 854 | evt->dd_data = NULL; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 855 | init_waitqueue_head(&evt->wq); |
| 856 | kref_init(&evt->kref); |
| 857 | return evt; |
| 858 | } |
| 859 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 860 | /** |
| 861 | * diag_cmd_data_free - Frees an lpfc dma buffer extension |
| 862 | * @phba: Pointer to HBA context object. |
| 863 | * @mlist: Pointer to an lpfc dma buffer extension. |
| 864 | **/ |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 865 | static int |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 866 | diag_cmd_data_free(struct lpfc_hba *phba, struct lpfc_dmabufext *mlist) |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 867 | { |
| 868 | struct lpfc_dmabufext *mlast; |
| 869 | struct pci_dev *pcidev; |
| 870 | struct list_head head, *curr, *next; |
| 871 | |
| 872 | if ((!mlist) || (!lpfc_is_link_up(phba) && |
| 873 | (phba->link_flag & LS_LOOPBACK_MODE))) { |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | pcidev = phba->pcidev; |
| 878 | list_add_tail(&head, &mlist->dma.list); |
| 879 | |
| 880 | list_for_each_safe(curr, next, &head) { |
| 881 | mlast = list_entry(curr, struct lpfc_dmabufext , dma.list); |
| 882 | if (mlast->dma.virt) |
| 883 | dma_free_coherent(&pcidev->dev, |
| 884 | mlast->size, |
| 885 | mlast->dma.virt, |
| 886 | mlast->dma.phys); |
| 887 | kfree(mlast); |
| 888 | } |
| 889 | return 0; |
| 890 | } |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 891 | |
| 892 | /** |
| 893 | * lpfc_bsg_ct_unsol_event - process an unsolicited CT command |
| 894 | * @phba: |
| 895 | * @pring: |
| 896 | * @piocbq: |
| 897 | * |
| 898 | * This function is called when an unsolicited CT command is received. It |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 899 | * forwards the event to any processes registered to receive CT events. |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 900 | **/ |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 901 | int |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 902 | lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 903 | struct lpfc_iocbq *piocbq) |
| 904 | { |
| 905 | uint32_t evt_req_id = 0; |
| 906 | uint32_t cmd; |
| 907 | uint32_t len; |
| 908 | struct lpfc_dmabuf *dmabuf = NULL; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 909 | struct lpfc_bsg_event *evt; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 910 | struct event_data *evt_dat = NULL; |
| 911 | struct lpfc_iocbq *iocbq; |
| 912 | size_t offset = 0; |
| 913 | struct list_head head; |
| 914 | struct ulp_bde64 *bde; |
| 915 | dma_addr_t dma_addr; |
| 916 | int i; |
| 917 | struct lpfc_dmabuf *bdeBuf1 = piocbq->context2; |
| 918 | struct lpfc_dmabuf *bdeBuf2 = piocbq->context3; |
| 919 | struct lpfc_hbq_entry *hbqe; |
| 920 | struct lpfc_sli_ct_request *ct_req; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 921 | struct fc_bsg_job *job = NULL; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 922 | struct bsg_job_data *dd_data = NULL; |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 923 | unsigned long flags; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 924 | int size = 0; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 925 | |
| 926 | INIT_LIST_HEAD(&head); |
| 927 | list_add_tail(&head, &piocbq->list); |
| 928 | |
| 929 | if (piocbq->iocb.ulpBdeCount == 0 || |
| 930 | piocbq->iocb.un.cont64[0].tus.f.bdeSize == 0) |
| 931 | goto error_ct_unsol_exit; |
| 932 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 933 | if (phba->link_state == LPFC_HBA_ERROR || |
| 934 | (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) |
| 935 | goto error_ct_unsol_exit; |
| 936 | |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 937 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 938 | dmabuf = bdeBuf1; |
| 939 | else { |
| 940 | dma_addr = getPaddr(piocbq->iocb.un.cont64[0].addrHigh, |
| 941 | piocbq->iocb.un.cont64[0].addrLow); |
| 942 | dmabuf = lpfc_sli_ringpostbuf_get(phba, pring, dma_addr); |
| 943 | } |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 944 | if (dmabuf == NULL) |
| 945 | goto error_ct_unsol_exit; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 946 | ct_req = (struct lpfc_sli_ct_request *)dmabuf->virt; |
| 947 | evt_req_id = ct_req->FsType; |
| 948 | cmd = ct_req->CommandResponse.bits.CmdRsp; |
| 949 | len = ct_req->CommandResponse.bits.Size; |
| 950 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
| 951 | lpfc_sli_ringpostbuf_put(phba, pring, dmabuf); |
| 952 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 953 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 954 | list_for_each_entry(evt, &phba->ct_ev_waiters, node) { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 955 | if (!(evt->type_mask & FC_REG_CT_EVENT) || |
| 956 | evt->req_id != evt_req_id) |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 957 | continue; |
| 958 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 959 | lpfc_bsg_event_ref(evt); |
| 960 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 961 | evt_dat = kzalloc(sizeof(*evt_dat), GFP_KERNEL); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 962 | if (evt_dat == NULL) { |
| 963 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 964 | lpfc_bsg_event_unref(evt); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 965 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 966 | "2614 Memory allocation failed for " |
| 967 | "CT event\n"); |
| 968 | break; |
| 969 | } |
| 970 | |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 971 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 972 | /* take accumulated byte count from the last iocbq */ |
| 973 | iocbq = list_entry(head.prev, typeof(*iocbq), list); |
| 974 | evt_dat->len = iocbq->iocb.unsli3.rcvsli3.acc_len; |
| 975 | } else { |
| 976 | list_for_each_entry(iocbq, &head, list) { |
| 977 | for (i = 0; i < iocbq->iocb.ulpBdeCount; i++) |
| 978 | evt_dat->len += |
| 979 | iocbq->iocb.un.cont64[i].tus.f.bdeSize; |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | evt_dat->data = kzalloc(evt_dat->len, GFP_KERNEL); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 984 | if (evt_dat->data == NULL) { |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 985 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 986 | "2615 Memory allocation failed for " |
| 987 | "CT event data, size %d\n", |
| 988 | evt_dat->len); |
| 989 | kfree(evt_dat); |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 990 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 991 | lpfc_bsg_event_unref(evt); |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 992 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 993 | goto error_ct_unsol_exit; |
| 994 | } |
| 995 | |
| 996 | list_for_each_entry(iocbq, &head, list) { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 997 | size = 0; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 998 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 999 | bdeBuf1 = iocbq->context2; |
| 1000 | bdeBuf2 = iocbq->context3; |
| 1001 | } |
| 1002 | for (i = 0; i < iocbq->iocb.ulpBdeCount; i++) { |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1003 | if (phba->sli3_options & |
| 1004 | LPFC_SLI3_HBQ_ENABLED) { |
| 1005 | if (i == 0) { |
| 1006 | hbqe = (struct lpfc_hbq_entry *) |
| 1007 | &iocbq->iocb.un.ulpWord[0]; |
| 1008 | size = hbqe->bde.tus.f.bdeSize; |
| 1009 | dmabuf = bdeBuf1; |
| 1010 | } else if (i == 1) { |
| 1011 | hbqe = (struct lpfc_hbq_entry *) |
| 1012 | &iocbq->iocb.unsli3. |
| 1013 | sli3Words[4]; |
| 1014 | size = hbqe->bde.tus.f.bdeSize; |
| 1015 | dmabuf = bdeBuf2; |
| 1016 | } |
| 1017 | if ((offset + size) > evt_dat->len) |
| 1018 | size = evt_dat->len - offset; |
| 1019 | } else { |
| 1020 | size = iocbq->iocb.un.cont64[i]. |
| 1021 | tus.f.bdeSize; |
| 1022 | bde = &iocbq->iocb.un.cont64[i]; |
| 1023 | dma_addr = getPaddr(bde->addrHigh, |
| 1024 | bde->addrLow); |
| 1025 | dmabuf = lpfc_sli_ringpostbuf_get(phba, |
| 1026 | pring, dma_addr); |
| 1027 | } |
| 1028 | if (!dmabuf) { |
| 1029 | lpfc_printf_log(phba, KERN_ERR, |
| 1030 | LOG_LIBDFC, "2616 No dmabuf " |
| 1031 | "found for iocbq 0x%p\n", |
| 1032 | iocbq); |
| 1033 | kfree(evt_dat->data); |
| 1034 | kfree(evt_dat); |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1035 | spin_lock_irqsave(&phba->ct_ev_lock, |
| 1036 | flags); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1037 | lpfc_bsg_event_unref(evt); |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1038 | spin_unlock_irqrestore( |
| 1039 | &phba->ct_ev_lock, flags); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1040 | goto error_ct_unsol_exit; |
| 1041 | } |
| 1042 | memcpy((char *)(evt_dat->data) + offset, |
| 1043 | dmabuf->virt, size); |
| 1044 | offset += size; |
| 1045 | if (evt_req_id != SLI_CT_ELX_LOOPBACK && |
| 1046 | !(phba->sli3_options & |
| 1047 | LPFC_SLI3_HBQ_ENABLED)) { |
| 1048 | lpfc_sli_ringpostbuf_put(phba, pring, |
| 1049 | dmabuf); |
| 1050 | } else { |
| 1051 | switch (cmd) { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1052 | case ELX_LOOPBACK_DATA: |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1053 | if (phba->sli_rev < |
| 1054 | LPFC_SLI_REV4) |
| 1055 | diag_cmd_data_free(phba, |
| 1056 | (struct lpfc_dmabufext |
| 1057 | *)dmabuf); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1058 | break; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1059 | case ELX_LOOPBACK_XRI_SETUP: |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1060 | if ((phba->sli_rev == |
| 1061 | LPFC_SLI_REV2) || |
| 1062 | (phba->sli3_options & |
| 1063 | LPFC_SLI3_HBQ_ENABLED |
| 1064 | )) { |
| 1065 | lpfc_in_buf_free(phba, |
| 1066 | dmabuf); |
| 1067 | } else { |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1068 | lpfc_post_buffer(phba, |
| 1069 | pring, |
| 1070 | 1); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1071 | } |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1072 | break; |
| 1073 | default: |
| 1074 | if (!(phba->sli3_options & |
| 1075 | LPFC_SLI3_HBQ_ENABLED)) |
| 1076 | lpfc_post_buffer(phba, |
| 1077 | pring, |
| 1078 | 1); |
| 1079 | break; |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | } |
| 1084 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1085 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1086 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1087 | evt_dat->immed_dat = phba->ctx_idx; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 1088 | phba->ctx_idx = (phba->ctx_idx + 1) % LPFC_CT_CTX_MAX; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1089 | /* Provide warning for over-run of the ct_ctx array */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 1090 | if (phba->ct_ctx[evt_dat->immed_dat].valid == |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1091 | UNSOL_VALID) |
| 1092 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 1093 | "2717 CT context array entry " |
| 1094 | "[%d] over-run: oxid:x%x, " |
| 1095 | "sid:x%x\n", phba->ctx_idx, |
| 1096 | phba->ct_ctx[ |
| 1097 | evt_dat->immed_dat].oxid, |
| 1098 | phba->ct_ctx[ |
| 1099 | evt_dat->immed_dat].SID); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 1100 | phba->ct_ctx[evt_dat->immed_dat].rxid = |
| 1101 | piocbq->iocb.ulpContext; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1102 | phba->ct_ctx[evt_dat->immed_dat].oxid = |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 1103 | piocbq->iocb.unsli3.rcvsli3.ox_id; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1104 | phba->ct_ctx[evt_dat->immed_dat].SID = |
| 1105 | piocbq->iocb.un.rcvels.remoteID; |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 1106 | phba->ct_ctx[evt_dat->immed_dat].valid = UNSOL_VALID; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1107 | } else |
| 1108 | evt_dat->immed_dat = piocbq->iocb.ulpContext; |
| 1109 | |
| 1110 | evt_dat->type = FC_REG_CT_EVENT; |
| 1111 | list_add(&evt_dat->node, &evt->events_to_see); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1112 | if (evt_req_id == SLI_CT_ELX_LOOPBACK) { |
| 1113 | wake_up_interruptible(&evt->wq); |
| 1114 | lpfc_bsg_event_unref(evt); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1115 | break; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | list_move(evt->events_to_see.prev, &evt->events_to_get); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1119 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1120 | dd_data = (struct bsg_job_data *)evt->dd_data; |
| 1121 | job = dd_data->set_job; |
| 1122 | dd_data->set_job = NULL; |
| 1123 | lpfc_bsg_event_unref(evt); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1124 | if (job) { |
| 1125 | job->reply->reply_payload_rcv_len = size; |
| 1126 | /* make error code available to userspace */ |
| 1127 | job->reply->result = 0; |
| 1128 | job->dd_data = NULL; |
| 1129 | /* complete the job back to userspace */ |
| 1130 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 1131 | job->job_done(job); |
| 1132 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 1133 | } |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1134 | } |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1135 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1136 | |
| 1137 | error_ct_unsol_exit: |
| 1138 | if (!list_empty(&head)) |
| 1139 | list_del(&head); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1140 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
| 1141 | (evt_req_id == SLI_CT_ELX_LOOPBACK)) |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1142 | return 0; |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1143 | return 1; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 1147 | * lpfc_bsg_ct_unsol_abort - handler ct abort to management plane |
| 1148 | * @phba: Pointer to HBA context object. |
| 1149 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
| 1150 | * |
| 1151 | * This function handles abort to the CT command toward management plane |
| 1152 | * for SLI4 port. |
| 1153 | * |
| 1154 | * If the pending context of a CT command to management plane present, clears |
| 1155 | * such context and returns 1 for handled; otherwise, it returns 0 indicating |
| 1156 | * no context exists. |
| 1157 | **/ |
| 1158 | int |
| 1159 | lpfc_bsg_ct_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf) |
| 1160 | { |
| 1161 | struct fc_frame_header fc_hdr; |
| 1162 | struct fc_frame_header *fc_hdr_ptr = &fc_hdr; |
| 1163 | int ctx_idx, handled = 0; |
| 1164 | uint16_t oxid, rxid; |
| 1165 | uint32_t sid; |
| 1166 | |
| 1167 | memcpy(fc_hdr_ptr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); |
| 1168 | sid = sli4_sid_from_fc_hdr(fc_hdr_ptr); |
| 1169 | oxid = be16_to_cpu(fc_hdr_ptr->fh_ox_id); |
| 1170 | rxid = be16_to_cpu(fc_hdr_ptr->fh_rx_id); |
| 1171 | |
| 1172 | for (ctx_idx = 0; ctx_idx < LPFC_CT_CTX_MAX; ctx_idx++) { |
| 1173 | if (phba->ct_ctx[ctx_idx].valid != UNSOL_VALID) |
| 1174 | continue; |
| 1175 | if (phba->ct_ctx[ctx_idx].rxid != rxid) |
| 1176 | continue; |
| 1177 | if (phba->ct_ctx[ctx_idx].oxid != oxid) |
| 1178 | continue; |
| 1179 | if (phba->ct_ctx[ctx_idx].SID != sid) |
| 1180 | continue; |
| 1181 | phba->ct_ctx[ctx_idx].valid = UNSOL_INVALID; |
| 1182 | handled = 1; |
| 1183 | } |
| 1184 | return handled; |
| 1185 | } |
| 1186 | |
| 1187 | /** |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1188 | * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1189 | * @job: SET_EVENT fc_bsg_job |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1190 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1191 | static int |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1192 | lpfc_bsg_hba_set_event(struct fc_bsg_job *job) |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1193 | { |
| 1194 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
| 1195 | struct lpfc_hba *phba = vport->phba; |
| 1196 | struct set_ct_event *event_req; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1197 | struct lpfc_bsg_event *evt; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1198 | int rc = 0; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1199 | struct bsg_job_data *dd_data = NULL; |
| 1200 | uint32_t ev_mask; |
| 1201 | unsigned long flags; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1202 | |
| 1203 | if (job->request_len < |
| 1204 | sizeof(struct fc_bsg_request) + sizeof(struct set_ct_event)) { |
| 1205 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 1206 | "2612 Received SET_CT_EVENT below minimum " |
| 1207 | "size\n"); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1208 | rc = -EINVAL; |
| 1209 | goto job_error; |
| 1210 | } |
| 1211 | |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1212 | event_req = (struct set_ct_event *) |
| 1213 | job->request->rqst_data.h_vendor.vendor_cmd; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1214 | ev_mask = ((uint32_t)(unsigned long)event_req->type_mask & |
| 1215 | FC_REG_EVENT_MASK); |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1216 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1217 | list_for_each_entry(evt, &phba->ct_ev_waiters, node) { |
| 1218 | if (evt->reg_id == event_req->ev_reg_id) { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1219 | lpfc_bsg_event_ref(evt); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1220 | evt->wait_time_stamp = jiffies; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1221 | dd_data = (struct bsg_job_data *)evt->dd_data; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1222 | break; |
| 1223 | } |
| 1224 | } |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1225 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1226 | |
| 1227 | if (&evt->node == &phba->ct_ev_waiters) { |
| 1228 | /* no event waiting struct yet - first call */ |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1229 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); |
| 1230 | if (dd_data == NULL) { |
| 1231 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 1232 | "2734 Failed allocation of dd_data\n"); |
| 1233 | rc = -ENOMEM; |
| 1234 | goto job_error; |
| 1235 | } |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1236 | evt = lpfc_bsg_event_new(ev_mask, event_req->ev_reg_id, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1237 | event_req->ev_req_id); |
| 1238 | if (!evt) { |
| 1239 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 1240 | "2617 Failed allocation of event " |
| 1241 | "waiter\n"); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1242 | rc = -ENOMEM; |
| 1243 | goto job_error; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1244 | } |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1245 | dd_data->type = TYPE_EVT; |
| 1246 | dd_data->set_job = NULL; |
| 1247 | dd_data->context_un.evt = evt; |
| 1248 | evt->dd_data = (void *)dd_data; |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1249 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1250 | list_add(&evt->node, &phba->ct_ev_waiters); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1251 | lpfc_bsg_event_ref(evt); |
| 1252 | evt->wait_time_stamp = jiffies; |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1253 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1254 | } |
| 1255 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1256 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1257 | evt->waiting = 1; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1258 | dd_data->set_job = job; /* for unsolicited command */ |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1259 | job->dd_data = dd_data; /* for fc transport timeout callback*/ |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1260 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1261 | return 0; /* call job done later */ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1262 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1263 | job_error: |
| 1264 | if (dd_data != NULL) |
| 1265 | kfree(dd_data); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1266 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1267 | job->dd_data = NULL; |
| 1268 | return rc; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | /** |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1272 | * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1273 | * @job: GET_EVENT fc_bsg_job |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1274 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1275 | static int |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1276 | lpfc_bsg_hba_get_event(struct fc_bsg_job *job) |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1277 | { |
| 1278 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
| 1279 | struct lpfc_hba *phba = vport->phba; |
| 1280 | struct get_ct_event *event_req; |
| 1281 | struct get_ct_event_reply *event_reply; |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 1282 | struct lpfc_bsg_event *evt, *evt_next; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1283 | struct event_data *evt_dat = NULL; |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1284 | unsigned long flags; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1285 | uint32_t rc = 0; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1286 | |
| 1287 | if (job->request_len < |
| 1288 | sizeof(struct fc_bsg_request) + sizeof(struct get_ct_event)) { |
| 1289 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 1290 | "2613 Received GET_CT_EVENT request below " |
| 1291 | "minimum size\n"); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1292 | rc = -EINVAL; |
| 1293 | goto job_error; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | event_req = (struct get_ct_event *) |
| 1297 | job->request->rqst_data.h_vendor.vendor_cmd; |
| 1298 | |
| 1299 | event_reply = (struct get_ct_event_reply *) |
| 1300 | job->reply->reply_data.vendor_reply.vendor_rsp; |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1301 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
James Smart | 9a803a7 | 2013-09-06 12:17:56 -0400 | [diff] [blame] | 1302 | list_for_each_entry_safe(evt, evt_next, &phba->ct_ev_waiters, node) { |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1303 | if (evt->reg_id == event_req->ev_reg_id) { |
| 1304 | if (list_empty(&evt->events_to_get)) |
| 1305 | break; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1306 | lpfc_bsg_event_ref(evt); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1307 | evt->wait_time_stamp = jiffies; |
| 1308 | evt_dat = list_entry(evt->events_to_get.prev, |
| 1309 | struct event_data, node); |
| 1310 | list_del(&evt_dat->node); |
| 1311 | break; |
| 1312 | } |
| 1313 | } |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1314 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1315 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1316 | /* The app may continue to ask for event data until it gets |
| 1317 | * an error indicating that there isn't anymore |
| 1318 | */ |
| 1319 | if (evt_dat == NULL) { |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1320 | job->reply->reply_payload_rcv_len = 0; |
| 1321 | rc = -ENOENT; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1322 | goto job_error; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1323 | } |
| 1324 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1325 | if (evt_dat->len > job->request_payload.payload_len) { |
| 1326 | evt_dat->len = job->request_payload.payload_len; |
| 1327 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 1328 | "2618 Truncated event data at %d " |
| 1329 | "bytes\n", |
| 1330 | job->request_payload.payload_len); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1331 | } |
| 1332 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1333 | event_reply->type = evt_dat->type; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1334 | event_reply->immed_data = evt_dat->immed_dat; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1335 | if (evt_dat->len > 0) |
| 1336 | job->reply->reply_payload_rcv_len = |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1337 | sg_copy_from_buffer(job->request_payload.sg_list, |
| 1338 | job->request_payload.sg_cnt, |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1339 | evt_dat->data, evt_dat->len); |
| 1340 | else |
| 1341 | job->reply->reply_payload_rcv_len = 0; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1342 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1343 | if (evt_dat) { |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1344 | kfree(evt_dat->data); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1345 | kfree(evt_dat); |
| 1346 | } |
| 1347 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1348 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1349 | lpfc_bsg_event_unref(evt); |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 1350 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1351 | job->dd_data = NULL; |
| 1352 | job->reply->result = 0; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1353 | job->job_done(job); |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1354 | return 0; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1355 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 1356 | job_error: |
| 1357 | job->dd_data = NULL; |
| 1358 | job->reply->result = rc; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 1359 | return rc; |
| 1360 | } |
| 1361 | |
| 1362 | /** |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1363 | * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler |
| 1364 | * @phba: Pointer to HBA context object. |
| 1365 | * @cmdiocbq: Pointer to command iocb. |
| 1366 | * @rspiocbq: Pointer to response iocb. |
| 1367 | * |
| 1368 | * This function is the completion handler for iocbs issued using |
| 1369 | * lpfc_issue_ct_rsp_cmp function. This function is called by the |
| 1370 | * ring event handler function without any lock held. This function |
| 1371 | * can be called from both worker thread context and interrupt |
| 1372 | * context. This function also can be called from other thread which |
| 1373 | * cleans up the SLI layer objects. |
| 1374 | * This function copy the contents of the response iocb to the |
| 1375 | * response iocb memory object provided by the caller of |
| 1376 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 1377 | * sleeps for the iocb completion. |
| 1378 | **/ |
| 1379 | static void |
| 1380 | lpfc_issue_ct_rsp_cmp(struct lpfc_hba *phba, |
| 1381 | struct lpfc_iocbq *cmdiocbq, |
| 1382 | struct lpfc_iocbq *rspiocbq) |
| 1383 | { |
| 1384 | struct bsg_job_data *dd_data; |
| 1385 | struct fc_bsg_job *job; |
| 1386 | IOCB_t *rsp; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1387 | struct lpfc_dmabuf *bmp, *cmp; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1388 | struct lpfc_nodelist *ndlp; |
| 1389 | unsigned long flags; |
| 1390 | int rc = 0; |
| 1391 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1392 | dd_data = cmdiocbq->context1; |
| 1393 | |
| 1394 | /* Determine if job has been aborted */ |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1395 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1396 | job = dd_data->set_job; |
| 1397 | if (job) { |
| 1398 | /* Prevent timeout handling from trying to abort job */ |
| 1399 | job->dd_data = NULL; |
| 1400 | } |
| 1401 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 1402 | |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 1403 | /* Close the timeout handler abort window */ |
| 1404 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 1b8d11a | 2013-09-06 12:20:51 -0400 | [diff] [blame] | 1405 | cmdiocbq->iocb_flag &= ~LPFC_IO_CMD_OUTSTANDING; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 1406 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 1407 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1408 | ndlp = dd_data->context_un.iocb.ndlp; |
| 1409 | cmp = cmdiocbq->context2; |
| 1410 | bmp = cmdiocbq->context3; |
| 1411 | rsp = &rspiocbq->iocb; |
| 1412 | |
| 1413 | /* Copy the completed job data or set the error status */ |
| 1414 | |
| 1415 | if (job) { |
| 1416 | if (rsp->ulpStatus) { |
| 1417 | if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
| 1418 | switch (rsp->un.ulpWord[4] & IOERR_PARAM_MASK) { |
| 1419 | case IOERR_SEQUENCE_TIMEOUT: |
| 1420 | rc = -ETIMEDOUT; |
| 1421 | break; |
| 1422 | case IOERR_INVALID_RPI: |
| 1423 | rc = -EFAULT; |
| 1424 | break; |
| 1425 | default: |
| 1426 | rc = -EACCES; |
| 1427 | break; |
| 1428 | } |
| 1429 | } else { |
| 1430 | rc = -EACCES; |
| 1431 | } |
| 1432 | } else { |
| 1433 | job->reply->reply_payload_rcv_len = 0; |
| 1434 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1435 | } |
| 1436 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1437 | lpfc_free_bsg_buffers(phba, cmp); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1438 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1439 | kfree(bmp); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1440 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 1441 | lpfc_nlp_put(ndlp); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1442 | kfree(dd_data); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1443 | |
| 1444 | /* Complete the job if the job is still active */ |
| 1445 | |
| 1446 | if (job) { |
| 1447 | job->reply->result = rc; |
| 1448 | job->job_done(job); |
| 1449 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1450 | return; |
| 1451 | } |
| 1452 | |
| 1453 | /** |
| 1454 | * lpfc_issue_ct_rsp - issue a ct response |
| 1455 | * @phba: Pointer to HBA context object. |
| 1456 | * @job: Pointer to the job object. |
| 1457 | * @tag: tag index value into the ports context exchange array. |
| 1458 | * @bmp: Pointer to a dma buffer descriptor. |
| 1459 | * @num_entry: Number of enties in the bde. |
| 1460 | **/ |
| 1461 | static int |
| 1462 | lpfc_issue_ct_rsp(struct lpfc_hba *phba, struct fc_bsg_job *job, uint32_t tag, |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1463 | struct lpfc_dmabuf *cmp, struct lpfc_dmabuf *bmp, |
| 1464 | int num_entry) |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1465 | { |
| 1466 | IOCB_t *icmd; |
| 1467 | struct lpfc_iocbq *ctiocb = NULL; |
| 1468 | int rc = 0; |
| 1469 | struct lpfc_nodelist *ndlp = NULL; |
| 1470 | struct bsg_job_data *dd_data; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 1471 | unsigned long flags; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1472 | uint32_t creg_val; |
| 1473 | |
| 1474 | /* allocate our bsg tracking structure */ |
| 1475 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); |
| 1476 | if (!dd_data) { |
| 1477 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 1478 | "2736 Failed allocation of dd_data\n"); |
| 1479 | rc = -ENOMEM; |
| 1480 | goto no_dd_data; |
| 1481 | } |
| 1482 | |
| 1483 | /* Allocate buffer for command iocb */ |
| 1484 | ctiocb = lpfc_sli_get_iocbq(phba); |
| 1485 | if (!ctiocb) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 1486 | rc = -ENOMEM; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1487 | goto no_ctiocb; |
| 1488 | } |
| 1489 | |
| 1490 | icmd = &ctiocb->iocb; |
| 1491 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
| 1492 | icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(bmp->phys); |
| 1493 | icmd->un.xseq64.bdl.addrLow = putPaddrLow(bmp->phys); |
| 1494 | icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 1495 | icmd->un.xseq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64)); |
| 1496 | icmd->un.xseq64.w5.hcsw.Fctl = (LS | LA); |
| 1497 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 1498 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_SOL_CTL; |
| 1499 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT; |
| 1500 | |
| 1501 | /* Fill in rest of iocb */ |
| 1502 | icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX; |
| 1503 | icmd->ulpBdeCount = 1; |
| 1504 | icmd->ulpLe = 1; |
| 1505 | icmd->ulpClass = CLASS3; |
| 1506 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 1507 | /* Do not issue unsol response if oxid not marked as valid */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 1508 | if (phba->ct_ctx[tag].valid != UNSOL_VALID) { |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1509 | rc = IOCB_ERROR; |
| 1510 | goto issue_ct_rsp_exit; |
| 1511 | } |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 1512 | icmd->ulpContext = phba->ct_ctx[tag].rxid; |
| 1513 | icmd->unsli3.rcvsli3.ox_id = phba->ct_ctx[tag].oxid; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1514 | ndlp = lpfc_findnode_did(phba->pport, phba->ct_ctx[tag].SID); |
| 1515 | if (!ndlp) { |
| 1516 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, |
| 1517 | "2721 ndlp null for oxid %x SID %x\n", |
| 1518 | icmd->ulpContext, |
| 1519 | phba->ct_ctx[tag].SID); |
| 1520 | rc = IOCB_ERROR; |
| 1521 | goto issue_ct_rsp_exit; |
| 1522 | } |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1523 | |
| 1524 | /* Check if the ndlp is active */ |
| 1525 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1526 | rc = IOCB_ERROR; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1527 | goto issue_ct_rsp_exit; |
| 1528 | } |
| 1529 | |
| 1530 | /* get a refernece count so the ndlp doesn't go away while |
| 1531 | * we respond |
| 1532 | */ |
| 1533 | if (!lpfc_nlp_get(ndlp)) { |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1534 | rc = IOCB_ERROR; |
James Smart | 589a52d | 2010-07-14 15:30:54 -0400 | [diff] [blame] | 1535 | goto issue_ct_rsp_exit; |
| 1536 | } |
| 1537 | |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 1538 | icmd->un.ulpWord[3] = |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1539 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
| 1540 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1541 | /* The exchange is done, mark the entry as invalid */ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 1542 | phba->ct_ctx[tag].valid = UNSOL_INVALID; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1543 | } else |
| 1544 | icmd->ulpContext = (ushort) tag; |
| 1545 | |
| 1546 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| 1547 | |
| 1548 | /* Xmit CT response on exchange <xid> */ |
| 1549 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 1550 | "2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n", |
| 1551 | icmd->ulpContext, icmd->ulpIoTag, tag, phba->link_state); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1552 | |
| 1553 | ctiocb->iocb_cmpl = NULL; |
| 1554 | ctiocb->iocb_flag |= LPFC_IO_LIBDFC; |
| 1555 | ctiocb->vport = phba->pport; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1556 | ctiocb->context1 = dd_data; |
| 1557 | ctiocb->context2 = cmp; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1558 | ctiocb->context3 = bmp; |
James Smart | d5ce53b | 2013-04-17 20:17:26 -0400 | [diff] [blame] | 1559 | ctiocb->context_un.ndlp = ndlp; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1560 | ctiocb->iocb_cmpl = lpfc_issue_ct_rsp_cmp; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1561 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1562 | dd_data->type = TYPE_IOCB; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1563 | dd_data->set_job = job; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1564 | dd_data->context_un.iocb.cmdiocbq = ctiocb; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1565 | dd_data->context_un.iocb.ndlp = ndlp; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1566 | dd_data->context_un.iocb.rmp = NULL; |
| 1567 | job->dd_data = dd_data; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1568 | |
| 1569 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1570 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
| 1571 | rc = -IOCB_ERROR; |
| 1572 | goto issue_ct_rsp_exit; |
| 1573 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1574 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 1575 | writel(creg_val, phba->HCregaddr); |
| 1576 | readl(phba->HCregaddr); /* flush */ |
| 1577 | } |
| 1578 | |
| 1579 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); |
| 1580 | |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 1581 | if (rc == IOCB_SUCCESS) { |
| 1582 | spin_lock_irqsave(&phba->hbalock, flags); |
| 1583 | /* make sure the I/O had not been completed/released */ |
| 1584 | if (ctiocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 1585 | /* open up abort window to timeout handler */ |
James Smart | 1b8d11a | 2013-09-06 12:20:51 -0400 | [diff] [blame] | 1586 | ctiocb->iocb_flag |= LPFC_IO_CMD_OUTSTANDING; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 1587 | } |
| 1588 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1589 | return 0; /* done for now */ |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | /* iocb failed so cleanup */ |
| 1593 | job->dd_data = NULL; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1594 | |
| 1595 | issue_ct_rsp_exit: |
| 1596 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 1597 | no_ctiocb: |
| 1598 | kfree(dd_data); |
| 1599 | no_dd_data: |
| 1600 | return rc; |
| 1601 | } |
| 1602 | |
| 1603 | /** |
| 1604 | * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command |
| 1605 | * @job: SEND_MGMT_RESP fc_bsg_job |
| 1606 | **/ |
| 1607 | static int |
| 1608 | lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job *job) |
| 1609 | { |
| 1610 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
| 1611 | struct lpfc_hba *phba = vport->phba; |
| 1612 | struct send_mgmt_resp *mgmt_resp = (struct send_mgmt_resp *) |
| 1613 | job->request->rqst_data.h_vendor.vendor_cmd; |
| 1614 | struct ulp_bde64 *bpl; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1615 | struct lpfc_dmabuf *bmp = NULL, *cmp = NULL; |
| 1616 | int bpl_entries; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1617 | uint32_t tag = mgmt_resp->tag; |
| 1618 | unsigned long reqbfrcnt = |
| 1619 | (unsigned long)job->request_payload.payload_len; |
| 1620 | int rc = 0; |
| 1621 | |
| 1622 | /* in case no data is transferred */ |
| 1623 | job->reply->reply_payload_rcv_len = 0; |
| 1624 | |
| 1625 | if (!reqbfrcnt || (reqbfrcnt > (80 * BUF_SZ_4K))) { |
| 1626 | rc = -ERANGE; |
| 1627 | goto send_mgmt_rsp_exit; |
| 1628 | } |
| 1629 | |
| 1630 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 1631 | if (!bmp) { |
| 1632 | rc = -ENOMEM; |
| 1633 | goto send_mgmt_rsp_exit; |
| 1634 | } |
| 1635 | |
| 1636 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys); |
| 1637 | if (!bmp->virt) { |
| 1638 | rc = -ENOMEM; |
| 1639 | goto send_mgmt_rsp_free_bmp; |
| 1640 | } |
| 1641 | |
| 1642 | INIT_LIST_HEAD(&bmp->list); |
| 1643 | bpl = (struct ulp_bde64 *) bmp->virt; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1644 | bpl_entries = (LPFC_BPL_SIZE/sizeof(struct ulp_bde64)); |
| 1645 | cmp = lpfc_alloc_bsg_buffers(phba, job->request_payload.payload_len, |
| 1646 | 1, bpl, &bpl_entries); |
| 1647 | if (!cmp) { |
| 1648 | rc = -ENOMEM; |
| 1649 | goto send_mgmt_rsp_free_bmp; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1650 | } |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1651 | lpfc_bsg_copy_data(cmp, &job->request_payload, |
| 1652 | job->request_payload.payload_len, 1); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1653 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1654 | rc = lpfc_issue_ct_rsp(phba, job, tag, cmp, bmp, bpl_entries); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1655 | |
| 1656 | if (rc == IOCB_SUCCESS) |
| 1657 | return 0; /* done for now */ |
| 1658 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1659 | rc = -EACCES; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1660 | |
| 1661 | lpfc_free_bsg_buffers(phba, cmp); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1662 | |
| 1663 | send_mgmt_rsp_free_bmp: |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 1664 | if (bmp->virt) |
| 1665 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1666 | kfree(bmp); |
| 1667 | send_mgmt_rsp_exit: |
| 1668 | /* make error code available to userspace */ |
| 1669 | job->reply->result = rc; |
| 1670 | job->dd_data = NULL; |
| 1671 | return rc; |
| 1672 | } |
| 1673 | |
| 1674 | /** |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1675 | * lpfc_bsg_diag_mode_enter - process preparing into device diag loopback mode |
| 1676 | * @phba: Pointer to HBA context object. |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1677 | * |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1678 | * This function is responsible for preparing driver for diag loopback |
| 1679 | * on device. |
| 1680 | */ |
| 1681 | static int |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 1682 | lpfc_bsg_diag_mode_enter(struct lpfc_hba *phba) |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1683 | { |
| 1684 | struct lpfc_vport **vports; |
| 1685 | struct Scsi_Host *shost; |
| 1686 | struct lpfc_sli *psli; |
| 1687 | struct lpfc_sli_ring *pring; |
| 1688 | int i = 0; |
| 1689 | |
| 1690 | psli = &phba->sli; |
| 1691 | if (!psli) |
| 1692 | return -ENODEV; |
| 1693 | |
| 1694 | pring = &psli->ring[LPFC_FCP_RING]; |
| 1695 | if (!pring) |
| 1696 | return -ENODEV; |
| 1697 | |
| 1698 | if ((phba->link_state == LPFC_HBA_ERROR) || |
| 1699 | (psli->sli_flag & LPFC_BLOCK_MGMT_IO) || |
| 1700 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) |
| 1701 | return -EACCES; |
| 1702 | |
| 1703 | vports = lpfc_create_vport_work_array(phba); |
| 1704 | if (vports) { |
| 1705 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 1706 | shost = lpfc_shost_from_vport(vports[i]); |
| 1707 | scsi_block_requests(shost); |
| 1708 | } |
| 1709 | lpfc_destroy_vport_work_array(phba, vports); |
| 1710 | } else { |
| 1711 | shost = lpfc_shost_from_vport(phba->pport); |
| 1712 | scsi_block_requests(shost); |
| 1713 | } |
| 1714 | |
James Smart | 0e9bb8d | 2013-03-01 16:35:12 -0500 | [diff] [blame] | 1715 | while (!list_empty(&pring->txcmplq)) { |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1716 | if (i++ > 500) /* wait up to 5 seconds */ |
| 1717 | break; |
| 1718 | msleep(10); |
| 1719 | } |
| 1720 | return 0; |
| 1721 | } |
| 1722 | |
| 1723 | /** |
| 1724 | * lpfc_bsg_diag_mode_exit - exit process from device diag loopback mode |
| 1725 | * @phba: Pointer to HBA context object. |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1726 | * |
| 1727 | * This function is responsible for driver exit processing of setting up |
| 1728 | * diag loopback mode on device. |
| 1729 | */ |
| 1730 | static void |
| 1731 | lpfc_bsg_diag_mode_exit(struct lpfc_hba *phba) |
| 1732 | { |
| 1733 | struct Scsi_Host *shost; |
| 1734 | struct lpfc_vport **vports; |
| 1735 | int i; |
| 1736 | |
| 1737 | vports = lpfc_create_vport_work_array(phba); |
| 1738 | if (vports) { |
| 1739 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 1740 | shost = lpfc_shost_from_vport(vports[i]); |
| 1741 | scsi_unblock_requests(shost); |
| 1742 | } |
| 1743 | lpfc_destroy_vport_work_array(phba, vports); |
| 1744 | } else { |
| 1745 | shost = lpfc_shost_from_vport(phba->pport); |
| 1746 | scsi_unblock_requests(shost); |
| 1747 | } |
| 1748 | return; |
| 1749 | } |
| 1750 | |
| 1751 | /** |
| 1752 | * lpfc_sli3_bsg_diag_loopback_mode - process an sli3 bsg vendor command |
| 1753 | * @phba: Pointer to HBA context object. |
| 1754 | * @job: LPFC_BSG_VENDOR_DIAG_MODE |
| 1755 | * |
| 1756 | * This function is responsible for placing an sli3 port into diagnostic |
| 1757 | * loopback mode in order to perform a diagnostic loopback test. |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1758 | * All new scsi requests are blocked, a small delay is used to allow the |
| 1759 | * scsi requests to complete then the link is brought down. If the link is |
| 1760 | * is placed in loopback mode then scsi requests are again allowed |
| 1761 | * so the scsi mid-layer doesn't give up on the port. |
| 1762 | * All of this is done in-line. |
| 1763 | */ |
| 1764 | static int |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1765 | lpfc_sli3_bsg_diag_loopback_mode(struct lpfc_hba *phba, struct fc_bsg_job *job) |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1766 | { |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1767 | struct diag_mode_set *loopback_mode; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1768 | uint32_t link_flags; |
| 1769 | uint32_t timeout; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1770 | LPFC_MBOXQ_t *pmboxq = NULL; |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 1771 | int mbxstatus = MBX_SUCCESS; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1772 | int i = 0; |
| 1773 | int rc = 0; |
| 1774 | |
| 1775 | /* no data to return just the return code */ |
| 1776 | job->reply->reply_payload_rcv_len = 0; |
| 1777 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1778 | if (job->request_len < sizeof(struct fc_bsg_request) + |
| 1779 | sizeof(struct diag_mode_set)) { |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1780 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1781 | "2738 Received DIAG MODE request size:%d " |
| 1782 | "below the minimum size:%d\n", |
| 1783 | job->request_len, |
| 1784 | (int)(sizeof(struct fc_bsg_request) + |
| 1785 | sizeof(struct diag_mode_set))); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1786 | rc = -EINVAL; |
| 1787 | goto job_error; |
| 1788 | } |
| 1789 | |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 1790 | rc = lpfc_bsg_diag_mode_enter(phba); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1791 | if (rc) |
| 1792 | goto job_error; |
| 1793 | |
| 1794 | /* bring the link to diagnostic mode */ |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1795 | loopback_mode = (struct diag_mode_set *) |
| 1796 | job->request->rqst_data.h_vendor.vendor_cmd; |
| 1797 | link_flags = loopback_mode->type; |
James Smart | 515e0aa | 2010-09-29 11:19:00 -0400 | [diff] [blame] | 1798 | timeout = loopback_mode->timeout * 100; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1799 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1800 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1801 | if (!pmboxq) { |
| 1802 | rc = -ENOMEM; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1803 | goto loopback_mode_exit; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1804 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1805 | memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 1806 | pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK; |
| 1807 | pmboxq->u.mb.mbxOwner = OWN_HOST; |
| 1808 | |
| 1809 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO); |
| 1810 | |
| 1811 | if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0)) { |
| 1812 | /* wait for link down before proceeding */ |
| 1813 | i = 0; |
| 1814 | while (phba->link_state != LPFC_LINK_DOWN) { |
| 1815 | if (i++ > timeout) { |
| 1816 | rc = -ETIMEDOUT; |
| 1817 | goto loopback_mode_exit; |
| 1818 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1819 | msleep(10); |
| 1820 | } |
| 1821 | |
| 1822 | memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 1823 | if (link_flags == INTERNAL_LOOP_BACK) |
| 1824 | pmboxq->u.mb.un.varInitLnk.link_flags = FLAGS_LOCAL_LB; |
| 1825 | else |
| 1826 | pmboxq->u.mb.un.varInitLnk.link_flags = |
| 1827 | FLAGS_TOPOLOGY_MODE_LOOP; |
| 1828 | |
| 1829 | pmboxq->u.mb.mbxCommand = MBX_INIT_LINK; |
| 1830 | pmboxq->u.mb.mbxOwner = OWN_HOST; |
| 1831 | |
| 1832 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, |
| 1833 | LPFC_MBOX_TMO); |
| 1834 | |
| 1835 | if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus)) |
| 1836 | rc = -ENODEV; |
| 1837 | else { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1838 | spin_lock_irq(&phba->hbalock); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1839 | phba->link_flag |= LS_LOOPBACK_MODE; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1840 | spin_unlock_irq(&phba->hbalock); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1841 | /* wait for the link attention interrupt */ |
| 1842 | msleep(100); |
| 1843 | |
| 1844 | i = 0; |
| 1845 | while (phba->link_state != LPFC_HBA_READY) { |
| 1846 | if (i++ > timeout) { |
| 1847 | rc = -ETIMEDOUT; |
| 1848 | break; |
| 1849 | } |
| 1850 | |
| 1851 | msleep(10); |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | } else |
| 1856 | rc = -ENODEV; |
| 1857 | |
| 1858 | loopback_mode_exit: |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1859 | lpfc_bsg_diag_mode_exit(phba); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1860 | |
| 1861 | /* |
| 1862 | * Let SLI layer release mboxq if mbox command completed after timeout. |
| 1863 | */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1864 | if (pmboxq && mbxstatus != MBX_TIMEOUT) |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 1865 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1866 | |
| 1867 | job_error: |
| 1868 | /* make error code available to userspace */ |
| 1869 | job->reply->result = rc; |
| 1870 | /* complete the job back to userspace if no error */ |
| 1871 | if (rc == 0) |
| 1872 | job->job_done(job); |
| 1873 | return rc; |
| 1874 | } |
| 1875 | |
| 1876 | /** |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1877 | * lpfc_sli4_bsg_set_link_diag_state - set sli4 link diag state |
| 1878 | * @phba: Pointer to HBA context object. |
| 1879 | * @diag: Flag for set link to diag or nomral operation state. |
| 1880 | * |
| 1881 | * This function is responsible for issuing a sli4 mailbox command for setting |
| 1882 | * link to either diag state or normal operation state. |
| 1883 | */ |
| 1884 | static int |
| 1885 | lpfc_sli4_bsg_set_link_diag_state(struct lpfc_hba *phba, uint32_t diag) |
| 1886 | { |
| 1887 | LPFC_MBOXQ_t *pmboxq; |
| 1888 | struct lpfc_mbx_set_link_diag_state *link_diag_state; |
| 1889 | uint32_t req_len, alloc_len; |
| 1890 | int mbxstatus = MBX_SUCCESS, rc; |
| 1891 | |
| 1892 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1893 | if (!pmboxq) |
| 1894 | return -ENOMEM; |
| 1895 | |
| 1896 | req_len = (sizeof(struct lpfc_mbx_set_link_diag_state) - |
| 1897 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 1898 | alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 1899 | LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE, |
| 1900 | req_len, LPFC_SLI4_MBX_EMBED); |
| 1901 | if (alloc_len != req_len) { |
| 1902 | rc = -ENOMEM; |
| 1903 | goto link_diag_state_set_out; |
| 1904 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1905 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 1906 | "3128 Set link to diagnostic state:x%x (x%x/x%x)\n", |
| 1907 | diag, phba->sli4_hba.lnk_info.lnk_tp, |
| 1908 | phba->sli4_hba.lnk_info.lnk_no); |
| 1909 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1910 | link_diag_state = &pmboxq->u.mqe.un.link_diag_state; |
James Smart | 9731592 | 2012-08-03 12:32:52 -0400 | [diff] [blame] | 1911 | bf_set(lpfc_mbx_set_diag_state_diag_bit_valid, &link_diag_state->u.req, |
| 1912 | LPFC_DIAG_STATE_DIAG_BIT_VALID_CHANGE); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1913 | bf_set(lpfc_mbx_set_diag_state_link_num, &link_diag_state->u.req, |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1914 | phba->sli4_hba.lnk_info.lnk_no); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1915 | bf_set(lpfc_mbx_set_diag_state_link_type, &link_diag_state->u.req, |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1916 | phba->sli4_hba.lnk_info.lnk_tp); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 1917 | if (diag) |
| 1918 | bf_set(lpfc_mbx_set_diag_state_diag, |
| 1919 | &link_diag_state->u.req, 1); |
| 1920 | else |
| 1921 | bf_set(lpfc_mbx_set_diag_state_diag, |
| 1922 | &link_diag_state->u.req, 0); |
| 1923 | |
| 1924 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO); |
| 1925 | |
| 1926 | if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0)) |
| 1927 | rc = 0; |
| 1928 | else |
| 1929 | rc = -ENODEV; |
| 1930 | |
| 1931 | link_diag_state_set_out: |
| 1932 | if (pmboxq && (mbxstatus != MBX_TIMEOUT)) |
| 1933 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1934 | |
| 1935 | return rc; |
| 1936 | } |
| 1937 | |
| 1938 | /** |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1939 | * lpfc_sli4_bsg_set_internal_loopback - set sli4 internal loopback diagnostic |
| 1940 | * @phba: Pointer to HBA context object. |
| 1941 | * |
| 1942 | * This function is responsible for issuing a sli4 mailbox command for setting |
| 1943 | * up internal loopback diagnostic. |
| 1944 | */ |
| 1945 | static int |
| 1946 | lpfc_sli4_bsg_set_internal_loopback(struct lpfc_hba *phba) |
| 1947 | { |
| 1948 | LPFC_MBOXQ_t *pmboxq; |
| 1949 | uint32_t req_len, alloc_len; |
| 1950 | struct lpfc_mbx_set_link_diag_loopback *link_diag_loopback; |
| 1951 | int mbxstatus = MBX_SUCCESS, rc = 0; |
| 1952 | |
| 1953 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1954 | if (!pmboxq) |
| 1955 | return -ENOMEM; |
| 1956 | req_len = (sizeof(struct lpfc_mbx_set_link_diag_loopback) - |
| 1957 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 1958 | alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 1959 | LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK, |
| 1960 | req_len, LPFC_SLI4_MBX_EMBED); |
| 1961 | if (alloc_len != req_len) { |
| 1962 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1963 | return -ENOMEM; |
| 1964 | } |
| 1965 | link_diag_loopback = &pmboxq->u.mqe.un.link_diag_loopback; |
| 1966 | bf_set(lpfc_mbx_set_diag_state_link_num, |
| 1967 | &link_diag_loopback->u.req, phba->sli4_hba.lnk_info.lnk_no); |
| 1968 | bf_set(lpfc_mbx_set_diag_state_link_type, |
| 1969 | &link_diag_loopback->u.req, phba->sli4_hba.lnk_info.lnk_tp); |
| 1970 | bf_set(lpfc_mbx_set_diag_lpbk_type, &link_diag_loopback->u.req, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 1971 | LPFC_DIAG_LOOPBACK_TYPE_INTERNAL); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 1972 | |
| 1973 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO); |
| 1974 | if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus)) { |
| 1975 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 1976 | "3127 Failed setup loopback mode mailbox " |
| 1977 | "command, rc:x%x, status:x%x\n", mbxstatus, |
| 1978 | pmboxq->u.mb.mbxStatus); |
| 1979 | rc = -ENODEV; |
| 1980 | } |
| 1981 | if (pmboxq && (mbxstatus != MBX_TIMEOUT)) |
| 1982 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1983 | return rc; |
| 1984 | } |
| 1985 | |
| 1986 | /** |
| 1987 | * lpfc_sli4_diag_fcport_reg_setup - setup port registrations for diagnostic |
| 1988 | * @phba: Pointer to HBA context object. |
| 1989 | * |
| 1990 | * This function set up SLI4 FC port registrations for diagnostic run, which |
| 1991 | * includes all the rpis, vfi, and also vpi. |
| 1992 | */ |
| 1993 | static int |
| 1994 | lpfc_sli4_diag_fcport_reg_setup(struct lpfc_hba *phba) |
| 1995 | { |
| 1996 | int rc; |
| 1997 | |
| 1998 | if (phba->pport->fc_flag & FC_VFI_REGISTERED) { |
| 1999 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 2000 | "3136 Port still had vfi registered: " |
| 2001 | "mydid:x%x, fcfi:%d, vfi:%d, vpi:%d\n", |
| 2002 | phba->pport->fc_myDID, phba->fcf.fcfi, |
| 2003 | phba->sli4_hba.vfi_ids[phba->pport->vfi], |
| 2004 | phba->vpi_ids[phba->pport->vpi]); |
| 2005 | return -EINVAL; |
| 2006 | } |
| 2007 | rc = lpfc_issue_reg_vfi(phba->pport); |
| 2008 | return rc; |
| 2009 | } |
| 2010 | |
| 2011 | /** |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2012 | * lpfc_sli4_bsg_diag_loopback_mode - process an sli4 bsg vendor command |
| 2013 | * @phba: Pointer to HBA context object. |
| 2014 | * @job: LPFC_BSG_VENDOR_DIAG_MODE |
| 2015 | * |
| 2016 | * This function is responsible for placing an sli4 port into diagnostic |
| 2017 | * loopback mode in order to perform a diagnostic loopback test. |
| 2018 | */ |
| 2019 | static int |
| 2020 | lpfc_sli4_bsg_diag_loopback_mode(struct lpfc_hba *phba, struct fc_bsg_job *job) |
| 2021 | { |
| 2022 | struct diag_mode_set *loopback_mode; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2023 | uint32_t link_flags, timeout; |
| 2024 | int i, rc = 0; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2025 | |
| 2026 | /* no data to return just the return code */ |
| 2027 | job->reply->reply_payload_rcv_len = 0; |
| 2028 | |
| 2029 | if (job->request_len < sizeof(struct fc_bsg_request) + |
| 2030 | sizeof(struct diag_mode_set)) { |
| 2031 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 2032 | "3011 Received DIAG MODE request size:%d " |
| 2033 | "below the minimum size:%d\n", |
| 2034 | job->request_len, |
| 2035 | (int)(sizeof(struct fc_bsg_request) + |
| 2036 | sizeof(struct diag_mode_set))); |
| 2037 | rc = -EINVAL; |
| 2038 | goto job_error; |
| 2039 | } |
| 2040 | |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 2041 | rc = lpfc_bsg_diag_mode_enter(phba); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2042 | if (rc) |
| 2043 | goto job_error; |
| 2044 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2045 | /* indicate we are in loobpack diagnostic mode */ |
| 2046 | spin_lock_irq(&phba->hbalock); |
| 2047 | phba->link_flag |= LS_LOOPBACK_MODE; |
| 2048 | spin_unlock_irq(&phba->hbalock); |
| 2049 | |
| 2050 | /* reset port to start frome scratch */ |
| 2051 | rc = lpfc_selective_reset(phba); |
| 2052 | if (rc) |
| 2053 | goto job_error; |
| 2054 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2055 | /* bring the link to diagnostic mode */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2056 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 2057 | "3129 Bring link to diagnostic state.\n"); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2058 | loopback_mode = (struct diag_mode_set *) |
| 2059 | job->request->rqst_data.h_vendor.vendor_cmd; |
| 2060 | link_flags = loopback_mode->type; |
| 2061 | timeout = loopback_mode->timeout * 100; |
| 2062 | |
| 2063 | rc = lpfc_sli4_bsg_set_link_diag_state(phba, 1); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2064 | if (rc) { |
| 2065 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 2066 | "3130 Failed to bring link to diagnostic " |
| 2067 | "state, rc:x%x\n", rc); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2068 | goto loopback_mode_exit; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2069 | } |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2070 | |
| 2071 | /* wait for link down before proceeding */ |
| 2072 | i = 0; |
| 2073 | while (phba->link_state != LPFC_LINK_DOWN) { |
| 2074 | if (i++ > timeout) { |
| 2075 | rc = -ETIMEDOUT; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2076 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 2077 | "3131 Timeout waiting for link to " |
| 2078 | "diagnostic mode, timeout:%d ms\n", |
| 2079 | timeout * 10); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2080 | goto loopback_mode_exit; |
| 2081 | } |
| 2082 | msleep(10); |
| 2083 | } |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2084 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2085 | /* set up loopback mode */ |
| 2086 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 2087 | "3132 Set up loopback mode:x%x\n", link_flags); |
| 2088 | |
| 2089 | if (link_flags == INTERNAL_LOOP_BACK) |
| 2090 | rc = lpfc_sli4_bsg_set_internal_loopback(phba); |
| 2091 | else if (link_flags == EXTERNAL_LOOP_BACK) |
| 2092 | rc = lpfc_hba_init_link_fc_topology(phba, |
| 2093 | FLAGS_TOPOLOGY_MODE_PT_PT, |
| 2094 | MBX_NOWAIT); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2095 | else { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2096 | rc = -EINVAL; |
| 2097 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 2098 | "3141 Loopback mode:x%x not supported\n", |
| 2099 | link_flags); |
| 2100 | goto loopback_mode_exit; |
| 2101 | } |
| 2102 | |
| 2103 | if (!rc) { |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2104 | /* wait for the link attention interrupt */ |
| 2105 | msleep(100); |
| 2106 | i = 0; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2107 | while (phba->link_state < LPFC_LINK_UP) { |
| 2108 | if (i++ > timeout) { |
| 2109 | rc = -ETIMEDOUT; |
| 2110 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 2111 | "3137 Timeout waiting for link up " |
| 2112 | "in loopback mode, timeout:%d ms\n", |
| 2113 | timeout * 10); |
| 2114 | break; |
| 2115 | } |
| 2116 | msleep(10); |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | /* port resource registration setup for loopback diagnostic */ |
| 2121 | if (!rc) { |
| 2122 | /* set up a none zero myDID for loopback test */ |
| 2123 | phba->pport->fc_myDID = 1; |
| 2124 | rc = lpfc_sli4_diag_fcport_reg_setup(phba); |
| 2125 | } else |
| 2126 | goto loopback_mode_exit; |
| 2127 | |
| 2128 | if (!rc) { |
| 2129 | /* wait for the port ready */ |
| 2130 | msleep(100); |
| 2131 | i = 0; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2132 | while (phba->link_state != LPFC_HBA_READY) { |
| 2133 | if (i++ > timeout) { |
| 2134 | rc = -ETIMEDOUT; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2135 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 2136 | "3133 Timeout waiting for port " |
| 2137 | "loopback mode ready, timeout:%d ms\n", |
| 2138 | timeout * 10); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2139 | break; |
| 2140 | } |
| 2141 | msleep(10); |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | loopback_mode_exit: |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2146 | /* clear loopback diagnostic mode */ |
| 2147 | if (rc) { |
| 2148 | spin_lock_irq(&phba->hbalock); |
| 2149 | phba->link_flag &= ~LS_LOOPBACK_MODE; |
| 2150 | spin_unlock_irq(&phba->hbalock); |
| 2151 | } |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2152 | lpfc_bsg_diag_mode_exit(phba); |
| 2153 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2154 | job_error: |
| 2155 | /* make error code available to userspace */ |
| 2156 | job->reply->result = rc; |
| 2157 | /* complete the job back to userspace if no error */ |
| 2158 | if (rc == 0) |
| 2159 | job->job_done(job); |
| 2160 | return rc; |
| 2161 | } |
| 2162 | |
| 2163 | /** |
| 2164 | * lpfc_bsg_diag_loopback_mode - bsg vendor command for diag loopback mode |
| 2165 | * @job: LPFC_BSG_VENDOR_DIAG_MODE |
| 2166 | * |
| 2167 | * This function is responsible for responding to check and dispatch bsg diag |
| 2168 | * command from the user to proper driver action routines. |
| 2169 | */ |
| 2170 | static int |
| 2171 | lpfc_bsg_diag_loopback_mode(struct fc_bsg_job *job) |
| 2172 | { |
| 2173 | struct Scsi_Host *shost; |
| 2174 | struct lpfc_vport *vport; |
| 2175 | struct lpfc_hba *phba; |
| 2176 | int rc; |
| 2177 | |
| 2178 | shost = job->shost; |
| 2179 | if (!shost) |
| 2180 | return -ENODEV; |
| 2181 | vport = (struct lpfc_vport *)job->shost->hostdata; |
| 2182 | if (!vport) |
| 2183 | return -ENODEV; |
| 2184 | phba = vport->phba; |
| 2185 | if (!phba) |
| 2186 | return -ENODEV; |
| 2187 | |
| 2188 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 2189 | rc = lpfc_sli3_bsg_diag_loopback_mode(phba, job); |
| 2190 | else if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 2191 | LPFC_SLI_INTF_IF_TYPE_2) |
| 2192 | rc = lpfc_sli4_bsg_diag_loopback_mode(phba, job); |
| 2193 | else |
| 2194 | rc = -ENODEV; |
| 2195 | |
| 2196 | return rc; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | /** |
| 2200 | * lpfc_sli4_bsg_diag_mode_end - sli4 bsg vendor command for ending diag mode |
| 2201 | * @job: LPFC_BSG_VENDOR_DIAG_MODE_END |
| 2202 | * |
| 2203 | * This function is responsible for responding to check and dispatch bsg diag |
| 2204 | * command from the user to proper driver action routines. |
| 2205 | */ |
| 2206 | static int |
| 2207 | lpfc_sli4_bsg_diag_mode_end(struct fc_bsg_job *job) |
| 2208 | { |
| 2209 | struct Scsi_Host *shost; |
| 2210 | struct lpfc_vport *vport; |
| 2211 | struct lpfc_hba *phba; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2212 | struct diag_mode_set *loopback_mode_end_cmd; |
| 2213 | uint32_t timeout; |
| 2214 | int rc, i; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2215 | |
| 2216 | shost = job->shost; |
| 2217 | if (!shost) |
| 2218 | return -ENODEV; |
| 2219 | vport = (struct lpfc_vport *)job->shost->hostdata; |
| 2220 | if (!vport) |
| 2221 | return -ENODEV; |
| 2222 | phba = vport->phba; |
| 2223 | if (!phba) |
| 2224 | return -ENODEV; |
| 2225 | |
| 2226 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 2227 | return -ENODEV; |
| 2228 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2229 | LPFC_SLI_INTF_IF_TYPE_2) |
| 2230 | return -ENODEV; |
| 2231 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2232 | /* clear loopback diagnostic mode */ |
| 2233 | spin_lock_irq(&phba->hbalock); |
| 2234 | phba->link_flag &= ~LS_LOOPBACK_MODE; |
| 2235 | spin_unlock_irq(&phba->hbalock); |
| 2236 | loopback_mode_end_cmd = (struct diag_mode_set *) |
| 2237 | job->request->rqst_data.h_vendor.vendor_cmd; |
| 2238 | timeout = loopback_mode_end_cmd->timeout * 100; |
| 2239 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2240 | rc = lpfc_sli4_bsg_set_link_diag_state(phba, 0); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2241 | if (rc) { |
| 2242 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 2243 | "3139 Failed to bring link to diagnostic " |
| 2244 | "state, rc:x%x\n", rc); |
| 2245 | goto loopback_mode_end_exit; |
| 2246 | } |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2247 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2248 | /* wait for link down before proceeding */ |
| 2249 | i = 0; |
| 2250 | while (phba->link_state != LPFC_LINK_DOWN) { |
| 2251 | if (i++ > timeout) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2252 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 2253 | "3140 Timeout waiting for link to " |
| 2254 | "diagnostic mode_end, timeout:%d ms\n", |
| 2255 | timeout * 10); |
| 2256 | /* there is nothing much we can do here */ |
| 2257 | break; |
| 2258 | } |
| 2259 | msleep(10); |
| 2260 | } |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2261 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2262 | /* reset port resource registrations */ |
| 2263 | rc = lpfc_selective_reset(phba); |
| 2264 | phba->pport->fc_myDID = 0; |
| 2265 | |
| 2266 | loopback_mode_end_exit: |
| 2267 | /* make return code available to userspace */ |
| 2268 | job->reply->result = rc; |
| 2269 | /* complete the job back to userspace if no error */ |
| 2270 | if (rc == 0) |
| 2271 | job->job_done(job); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2272 | return rc; |
| 2273 | } |
| 2274 | |
| 2275 | /** |
| 2276 | * lpfc_sli4_bsg_link_diag_test - sli4 bsg vendor command for diag link test |
| 2277 | * @job: LPFC_BSG_VENDOR_DIAG_LINK_TEST |
| 2278 | * |
| 2279 | * This function is to perform SLI4 diag link test request from the user |
| 2280 | * applicaiton. |
| 2281 | */ |
| 2282 | static int |
| 2283 | lpfc_sli4_bsg_link_diag_test(struct fc_bsg_job *job) |
| 2284 | { |
| 2285 | struct Scsi_Host *shost; |
| 2286 | struct lpfc_vport *vport; |
| 2287 | struct lpfc_hba *phba; |
| 2288 | LPFC_MBOXQ_t *pmboxq; |
| 2289 | struct sli4_link_diag *link_diag_test_cmd; |
| 2290 | uint32_t req_len, alloc_len; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2291 | struct lpfc_mbx_run_link_diag_test *run_link_diag_test; |
| 2292 | union lpfc_sli4_cfg_shdr *shdr; |
| 2293 | uint32_t shdr_status, shdr_add_status; |
| 2294 | struct diag_status *diag_status_reply; |
| 2295 | int mbxstatus, rc = 0; |
| 2296 | |
| 2297 | shost = job->shost; |
| 2298 | if (!shost) { |
| 2299 | rc = -ENODEV; |
| 2300 | goto job_error; |
| 2301 | } |
| 2302 | vport = (struct lpfc_vport *)job->shost->hostdata; |
| 2303 | if (!vport) { |
| 2304 | rc = -ENODEV; |
| 2305 | goto job_error; |
| 2306 | } |
| 2307 | phba = vport->phba; |
| 2308 | if (!phba) { |
| 2309 | rc = -ENODEV; |
| 2310 | goto job_error; |
| 2311 | } |
| 2312 | |
| 2313 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 2314 | rc = -ENODEV; |
| 2315 | goto job_error; |
| 2316 | } |
| 2317 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 2318 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 2319 | rc = -ENODEV; |
| 2320 | goto job_error; |
| 2321 | } |
| 2322 | |
| 2323 | if (job->request_len < sizeof(struct fc_bsg_request) + |
| 2324 | sizeof(struct sli4_link_diag)) { |
| 2325 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 2326 | "3013 Received LINK DIAG TEST request " |
| 2327 | " size:%d below the minimum size:%d\n", |
| 2328 | job->request_len, |
| 2329 | (int)(sizeof(struct fc_bsg_request) + |
| 2330 | sizeof(struct sli4_link_diag))); |
| 2331 | rc = -EINVAL; |
| 2332 | goto job_error; |
| 2333 | } |
| 2334 | |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 2335 | rc = lpfc_bsg_diag_mode_enter(phba); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2336 | if (rc) |
| 2337 | goto job_error; |
| 2338 | |
| 2339 | link_diag_test_cmd = (struct sli4_link_diag *) |
| 2340 | job->request->rqst_data.h_vendor.vendor_cmd; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2341 | |
| 2342 | rc = lpfc_sli4_bsg_set_link_diag_state(phba, 1); |
| 2343 | |
| 2344 | if (rc) |
| 2345 | goto job_error; |
| 2346 | |
| 2347 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2348 | if (!pmboxq) { |
| 2349 | rc = -ENOMEM; |
| 2350 | goto link_diag_test_exit; |
| 2351 | } |
| 2352 | |
| 2353 | req_len = (sizeof(struct lpfc_mbx_set_link_diag_state) - |
| 2354 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 2355 | alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 2356 | LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE, |
| 2357 | req_len, LPFC_SLI4_MBX_EMBED); |
| 2358 | if (alloc_len != req_len) { |
| 2359 | rc = -ENOMEM; |
| 2360 | goto link_diag_test_exit; |
| 2361 | } |
| 2362 | run_link_diag_test = &pmboxq->u.mqe.un.link_diag_test; |
| 2363 | bf_set(lpfc_mbx_run_diag_test_link_num, &run_link_diag_test->u.req, |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2364 | phba->sli4_hba.lnk_info.lnk_no); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2365 | bf_set(lpfc_mbx_run_diag_test_link_type, &run_link_diag_test->u.req, |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2366 | phba->sli4_hba.lnk_info.lnk_tp); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2367 | bf_set(lpfc_mbx_run_diag_test_test_id, &run_link_diag_test->u.req, |
| 2368 | link_diag_test_cmd->test_id); |
| 2369 | bf_set(lpfc_mbx_run_diag_test_loops, &run_link_diag_test->u.req, |
| 2370 | link_diag_test_cmd->loops); |
| 2371 | bf_set(lpfc_mbx_run_diag_test_test_ver, &run_link_diag_test->u.req, |
| 2372 | link_diag_test_cmd->test_version); |
| 2373 | bf_set(lpfc_mbx_run_diag_test_err_act, &run_link_diag_test->u.req, |
| 2374 | link_diag_test_cmd->error_action); |
| 2375 | |
| 2376 | mbxstatus = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
| 2377 | |
| 2378 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 2379 | &pmboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 2380 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 2381 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 2382 | if (shdr_status || shdr_add_status || mbxstatus) { |
| 2383 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 2384 | "3010 Run link diag test mailbox failed with " |
| 2385 | "mbx_status x%x status x%x, add_status x%x\n", |
| 2386 | mbxstatus, shdr_status, shdr_add_status); |
| 2387 | } |
| 2388 | |
| 2389 | diag_status_reply = (struct diag_status *) |
| 2390 | job->reply->reply_data.vendor_reply.vendor_rsp; |
| 2391 | |
| 2392 | if (job->reply_len < |
| 2393 | sizeof(struct fc_bsg_request) + sizeof(struct diag_status)) { |
| 2394 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 2395 | "3012 Received Run link diag test reply " |
| 2396 | "below minimum size (%d): reply_len:%d\n", |
| 2397 | (int)(sizeof(struct fc_bsg_request) + |
| 2398 | sizeof(struct diag_status)), |
| 2399 | job->reply_len); |
| 2400 | rc = -EINVAL; |
| 2401 | goto job_error; |
| 2402 | } |
| 2403 | |
| 2404 | diag_status_reply->mbox_status = mbxstatus; |
| 2405 | diag_status_reply->shdr_status = shdr_status; |
| 2406 | diag_status_reply->shdr_add_status = shdr_add_status; |
| 2407 | |
| 2408 | link_diag_test_exit: |
| 2409 | rc = lpfc_sli4_bsg_set_link_diag_state(phba, 0); |
| 2410 | |
| 2411 | if (pmboxq) |
| 2412 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 2413 | |
| 2414 | lpfc_bsg_diag_mode_exit(phba); |
| 2415 | |
| 2416 | job_error: |
| 2417 | /* make error code available to userspace */ |
| 2418 | job->reply->result = rc; |
| 2419 | /* complete the job back to userspace if no error */ |
| 2420 | if (rc == 0) |
| 2421 | job->job_done(job); |
| 2422 | return rc; |
| 2423 | } |
| 2424 | |
| 2425 | /** |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2426 | * lpfcdiag_loop_self_reg - obtains a remote port login id |
| 2427 | * @phba: Pointer to HBA context object |
| 2428 | * @rpi: Pointer to a remote port login id |
| 2429 | * |
| 2430 | * This function obtains a remote port login id so the diag loopback test |
| 2431 | * can send and receive its own unsolicited CT command. |
| 2432 | **/ |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 2433 | static int lpfcdiag_loop_self_reg(struct lpfc_hba *phba, uint16_t *rpi) |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2434 | { |
| 2435 | LPFC_MBOXQ_t *mbox; |
| 2436 | struct lpfc_dmabuf *dmabuff; |
| 2437 | int status; |
| 2438 | |
| 2439 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2440 | if (!mbox) |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2441 | return -ENOMEM; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2442 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2443 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 2444 | status = lpfc_reg_rpi(phba, 0, phba->pport->fc_myDID, |
| 2445 | (uint8_t *)&phba->pport->fc_sparam, |
| 2446 | mbox, *rpi); |
| 2447 | else { |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 2448 | *rpi = lpfc_sli4_alloc_rpi(phba); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2449 | status = lpfc_reg_rpi(phba, phba->pport->vpi, |
| 2450 | phba->pport->fc_myDID, |
| 2451 | (uint8_t *)&phba->pport->fc_sparam, |
| 2452 | mbox, *rpi); |
| 2453 | } |
| 2454 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2455 | if (status) { |
| 2456 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 2457 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2458 | lpfc_sli4_free_rpi(phba, *rpi); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2459 | return -ENOMEM; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | dmabuff = (struct lpfc_dmabuf *) mbox->context1; |
| 2463 | mbox->context1 = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2464 | mbox->context2 = NULL; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2465 | status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
| 2466 | |
| 2467 | if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) { |
| 2468 | lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys); |
| 2469 | kfree(dmabuff); |
| 2470 | if (status != MBX_TIMEOUT) |
| 2471 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 2472 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2473 | lpfc_sli4_free_rpi(phba, *rpi); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2474 | return -ENODEV; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2475 | } |
| 2476 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2477 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 2478 | *rpi = mbox->u.mb.un.varWords[0]; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2479 | |
| 2480 | lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys); |
| 2481 | kfree(dmabuff); |
| 2482 | mempool_free(mbox, phba->mbox_mem_pool); |
| 2483 | return 0; |
| 2484 | } |
| 2485 | |
| 2486 | /** |
| 2487 | * lpfcdiag_loop_self_unreg - unregs from the rpi |
| 2488 | * @phba: Pointer to HBA context object |
| 2489 | * @rpi: Remote port login id |
| 2490 | * |
| 2491 | * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg |
| 2492 | **/ |
| 2493 | static int lpfcdiag_loop_self_unreg(struct lpfc_hba *phba, uint16_t rpi) |
| 2494 | { |
| 2495 | LPFC_MBOXQ_t *mbox; |
| 2496 | int status; |
| 2497 | |
| 2498 | /* Allocate mboxq structure */ |
| 2499 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2500 | if (mbox == NULL) |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2501 | return -ENOMEM; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2502 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2503 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 2504 | lpfc_unreg_login(phba, 0, rpi, mbox); |
| 2505 | else |
| 2506 | lpfc_unreg_login(phba, phba->pport->vpi, |
| 2507 | phba->sli4_hba.rpi_ids[rpi], mbox); |
| 2508 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2509 | status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); |
| 2510 | |
| 2511 | if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) { |
| 2512 | if (status != MBX_TIMEOUT) |
| 2513 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2514 | return -EIO; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2515 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2516 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 2517 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 2518 | lpfc_sli4_free_rpi(phba, rpi); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2519 | return 0; |
| 2520 | } |
| 2521 | |
| 2522 | /** |
| 2523 | * lpfcdiag_loop_get_xri - obtains the transmit and receive ids |
| 2524 | * @phba: Pointer to HBA context object |
| 2525 | * @rpi: Remote port login id |
| 2526 | * @txxri: Pointer to transmit exchange id |
| 2527 | * @rxxri: Pointer to response exchabge id |
| 2528 | * |
| 2529 | * This function obtains the transmit and receive ids required to send |
| 2530 | * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp |
| 2531 | * flags are used to the unsolicted response handler is able to process |
| 2532 | * the ct command sent on the same port. |
| 2533 | **/ |
| 2534 | static int lpfcdiag_loop_get_xri(struct lpfc_hba *phba, uint16_t rpi, |
| 2535 | uint16_t *txxri, uint16_t * rxxri) |
| 2536 | { |
| 2537 | struct lpfc_bsg_event *evt; |
| 2538 | struct lpfc_iocbq *cmdiocbq, *rspiocbq; |
| 2539 | IOCB_t *cmd, *rsp; |
| 2540 | struct lpfc_dmabuf *dmabuf; |
| 2541 | struct ulp_bde64 *bpl = NULL; |
| 2542 | struct lpfc_sli_ct_request *ctreq = NULL; |
| 2543 | int ret_val = 0; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2544 | int time_left; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 2545 | int iocb_stat = IOCB_SUCCESS; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2546 | unsigned long flags; |
| 2547 | |
| 2548 | *txxri = 0; |
| 2549 | *rxxri = 0; |
| 2550 | evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid, |
| 2551 | SLI_CT_ELX_LOOPBACK); |
| 2552 | if (!evt) |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2553 | return -ENOMEM; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2554 | |
| 2555 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 2556 | list_add(&evt->node, &phba->ct_ev_waiters); |
| 2557 | lpfc_bsg_event_ref(evt); |
| 2558 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 2559 | |
| 2560 | cmdiocbq = lpfc_sli_get_iocbq(phba); |
| 2561 | rspiocbq = lpfc_sli_get_iocbq(phba); |
| 2562 | |
| 2563 | dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 2564 | if (dmabuf) { |
| 2565 | dmabuf->virt = lpfc_mbuf_alloc(phba, 0, &dmabuf->phys); |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2566 | if (dmabuf->virt) { |
| 2567 | INIT_LIST_HEAD(&dmabuf->list); |
| 2568 | bpl = (struct ulp_bde64 *) dmabuf->virt; |
| 2569 | memset(bpl, 0, sizeof(*bpl)); |
| 2570 | ctreq = (struct lpfc_sli_ct_request *)(bpl + 1); |
| 2571 | bpl->addrHigh = |
| 2572 | le32_to_cpu(putPaddrHigh(dmabuf->phys + |
| 2573 | sizeof(*bpl))); |
| 2574 | bpl->addrLow = |
| 2575 | le32_to_cpu(putPaddrLow(dmabuf->phys + |
| 2576 | sizeof(*bpl))); |
| 2577 | bpl->tus.f.bdeFlags = 0; |
| 2578 | bpl->tus.f.bdeSize = ELX_LOOPBACK_HEADER_SZ; |
| 2579 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 2580 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | if (cmdiocbq == NULL || rspiocbq == NULL || |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2584 | dmabuf == NULL || bpl == NULL || ctreq == NULL || |
| 2585 | dmabuf->virt == NULL) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2586 | ret_val = -ENOMEM; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2587 | goto err_get_xri_exit; |
| 2588 | } |
| 2589 | |
| 2590 | cmd = &cmdiocbq->iocb; |
| 2591 | rsp = &rspiocbq->iocb; |
| 2592 | |
| 2593 | memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ); |
| 2594 | |
| 2595 | ctreq->RevisionId.bits.Revision = SLI_CT_REVISION; |
| 2596 | ctreq->RevisionId.bits.InId = 0; |
| 2597 | ctreq->FsType = SLI_CT_ELX_LOOPBACK; |
| 2598 | ctreq->FsSubType = 0; |
| 2599 | ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_XRI_SETUP; |
| 2600 | ctreq->CommandResponse.bits.Size = 0; |
| 2601 | |
| 2602 | |
| 2603 | cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(dmabuf->phys); |
| 2604 | cmd->un.xseq64.bdl.addrLow = putPaddrLow(dmabuf->phys); |
| 2605 | cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 2606 | cmd->un.xseq64.bdl.bdeSize = sizeof(*bpl); |
| 2607 | |
| 2608 | cmd->un.xseq64.w5.hcsw.Fctl = LA; |
| 2609 | cmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 2610 | cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; |
| 2611 | cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT; |
| 2612 | |
| 2613 | cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CR; |
| 2614 | cmd->ulpBdeCount = 1; |
| 2615 | cmd->ulpLe = 1; |
| 2616 | cmd->ulpClass = CLASS3; |
| 2617 | cmd->ulpContext = rpi; |
| 2618 | |
| 2619 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; |
| 2620 | cmdiocbq->vport = phba->pport; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 2621 | cmdiocbq->iocb_cmpl = NULL; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2622 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2623 | iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq, |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2624 | rspiocbq, |
| 2625 | (phba->fc_ratov * 2) |
| 2626 | + LPFC_DRVR_TIMEOUT); |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 2627 | if ((iocb_stat != IOCB_SUCCESS) || (rsp->ulpStatus != IOSTAT_SUCCESS)) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2628 | ret_val = -EIO; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2629 | goto err_get_xri_exit; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2630 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2631 | *txxri = rsp->ulpContext; |
| 2632 | |
| 2633 | evt->waiting = 1; |
| 2634 | evt->wait_time_stamp = jiffies; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2635 | time_left = wait_event_interruptible_timeout( |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2636 | evt->wq, !list_empty(&evt->events_to_see), |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 2637 | msecs_to_jiffies(1000 * |
| 2638 | ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT))); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2639 | if (list_empty(&evt->events_to_see)) |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2640 | ret_val = (time_left) ? -EINTR : -ETIMEDOUT; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2641 | else { |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2642 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 2643 | list_move(evt->events_to_see.prev, &evt->events_to_get); |
| 2644 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 2645 | *rxxri = (list_entry(evt->events_to_get.prev, |
| 2646 | typeof(struct event_data), |
| 2647 | node))->immed_dat; |
| 2648 | } |
| 2649 | evt->waiting = 0; |
| 2650 | |
| 2651 | err_get_xri_exit: |
| 2652 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 2653 | lpfc_bsg_event_unref(evt); /* release ref */ |
| 2654 | lpfc_bsg_event_unref(evt); /* delete */ |
| 2655 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 2656 | |
| 2657 | if (dmabuf) { |
| 2658 | if (dmabuf->virt) |
| 2659 | lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys); |
| 2660 | kfree(dmabuf); |
| 2661 | } |
| 2662 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2663 | if (cmdiocbq && (iocb_stat != IOCB_TIMEDOUT)) |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2664 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 2665 | if (rspiocbq) |
| 2666 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 2667 | return ret_val; |
| 2668 | } |
| 2669 | |
| 2670 | /** |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2671 | * lpfc_bsg_dma_page_alloc - allocate a bsg mbox page sized dma buffers |
| 2672 | * @phba: Pointer to HBA context object |
| 2673 | * |
| 2674 | * This function allocates BSG_MBOX_SIZE (4KB) page size dma buffer and. |
Joe Perches | 9e03aa2 | 2013-09-03 13:45:58 -0700 | [diff] [blame] | 2675 | * returns the pointer to the buffer. |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2676 | **/ |
| 2677 | static struct lpfc_dmabuf * |
| 2678 | lpfc_bsg_dma_page_alloc(struct lpfc_hba *phba) |
| 2679 | { |
| 2680 | struct lpfc_dmabuf *dmabuf; |
| 2681 | struct pci_dev *pcidev = phba->pcidev; |
| 2682 | |
| 2683 | /* allocate dma buffer struct */ |
| 2684 | dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 2685 | if (!dmabuf) |
| 2686 | return NULL; |
| 2687 | |
| 2688 | INIT_LIST_HEAD(&dmabuf->list); |
| 2689 | |
| 2690 | /* now, allocate dma buffer */ |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 2691 | dmabuf->virt = dma_zalloc_coherent(&pcidev->dev, BSG_MBOX_SIZE, |
| 2692 | &(dmabuf->phys), GFP_KERNEL); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2693 | |
| 2694 | if (!dmabuf->virt) { |
| 2695 | kfree(dmabuf); |
| 2696 | return NULL; |
| 2697 | } |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2698 | |
| 2699 | return dmabuf; |
| 2700 | } |
| 2701 | |
| 2702 | /** |
| 2703 | * lpfc_bsg_dma_page_free - free a bsg mbox page sized dma buffer |
| 2704 | * @phba: Pointer to HBA context object. |
| 2705 | * @dmabuf: Pointer to the bsg mbox page sized dma buffer descriptor. |
| 2706 | * |
| 2707 | * This routine just simply frees a dma buffer and its associated buffer |
| 2708 | * descriptor referred by @dmabuf. |
| 2709 | **/ |
| 2710 | static void |
| 2711 | lpfc_bsg_dma_page_free(struct lpfc_hba *phba, struct lpfc_dmabuf *dmabuf) |
| 2712 | { |
| 2713 | struct pci_dev *pcidev = phba->pcidev; |
| 2714 | |
| 2715 | if (!dmabuf) |
| 2716 | return; |
| 2717 | |
| 2718 | if (dmabuf->virt) |
| 2719 | dma_free_coherent(&pcidev->dev, BSG_MBOX_SIZE, |
| 2720 | dmabuf->virt, dmabuf->phys); |
| 2721 | kfree(dmabuf); |
| 2722 | return; |
| 2723 | } |
| 2724 | |
| 2725 | /** |
| 2726 | * lpfc_bsg_dma_page_list_free - free a list of bsg mbox page sized dma buffers |
| 2727 | * @phba: Pointer to HBA context object. |
| 2728 | * @dmabuf_list: Pointer to a list of bsg mbox page sized dma buffer descs. |
| 2729 | * |
| 2730 | * This routine just simply frees all dma buffers and their associated buffer |
| 2731 | * descriptors referred by @dmabuf_list. |
| 2732 | **/ |
| 2733 | static void |
| 2734 | lpfc_bsg_dma_page_list_free(struct lpfc_hba *phba, |
| 2735 | struct list_head *dmabuf_list) |
| 2736 | { |
| 2737 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
| 2738 | |
| 2739 | if (list_empty(dmabuf_list)) |
| 2740 | return; |
| 2741 | |
| 2742 | list_for_each_entry_safe(dmabuf, next_dmabuf, dmabuf_list, list) { |
| 2743 | list_del_init(&dmabuf->list); |
| 2744 | lpfc_bsg_dma_page_free(phba, dmabuf); |
| 2745 | } |
| 2746 | return; |
| 2747 | } |
| 2748 | |
| 2749 | /** |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2750 | * diag_cmd_data_alloc - fills in a bde struct with dma buffers |
| 2751 | * @phba: Pointer to HBA context object |
| 2752 | * @bpl: Pointer to 64 bit bde structure |
| 2753 | * @size: Number of bytes to process |
| 2754 | * @nocopydata: Flag to copy user data into the allocated buffer |
| 2755 | * |
| 2756 | * This function allocates page size buffers and populates an lpfc_dmabufext. |
| 2757 | * If allowed the user data pointed to with indataptr is copied into the kernel |
| 2758 | * memory. The chained list of page size buffers is returned. |
| 2759 | **/ |
| 2760 | static struct lpfc_dmabufext * |
| 2761 | diag_cmd_data_alloc(struct lpfc_hba *phba, |
| 2762 | struct ulp_bde64 *bpl, uint32_t size, |
| 2763 | int nocopydata) |
| 2764 | { |
| 2765 | struct lpfc_dmabufext *mlist = NULL; |
| 2766 | struct lpfc_dmabufext *dmp; |
| 2767 | int cnt, offset = 0, i = 0; |
| 2768 | struct pci_dev *pcidev; |
| 2769 | |
| 2770 | pcidev = phba->pcidev; |
| 2771 | |
| 2772 | while (size) { |
| 2773 | /* We get chunks of 4K */ |
| 2774 | if (size > BUF_SZ_4K) |
| 2775 | cnt = BUF_SZ_4K; |
| 2776 | else |
| 2777 | cnt = size; |
| 2778 | |
| 2779 | /* allocate struct lpfc_dmabufext buffer header */ |
| 2780 | dmp = kmalloc(sizeof(struct lpfc_dmabufext), GFP_KERNEL); |
| 2781 | if (!dmp) |
| 2782 | goto out; |
| 2783 | |
| 2784 | INIT_LIST_HEAD(&dmp->dma.list); |
| 2785 | |
| 2786 | /* Queue it to a linked list */ |
| 2787 | if (mlist) |
| 2788 | list_add_tail(&dmp->dma.list, &mlist->dma.list); |
| 2789 | else |
| 2790 | mlist = dmp; |
| 2791 | |
| 2792 | /* allocate buffer */ |
| 2793 | dmp->dma.virt = dma_alloc_coherent(&pcidev->dev, |
| 2794 | cnt, |
| 2795 | &(dmp->dma.phys), |
| 2796 | GFP_KERNEL); |
| 2797 | |
| 2798 | if (!dmp->dma.virt) |
| 2799 | goto out; |
| 2800 | |
| 2801 | dmp->size = cnt; |
| 2802 | |
| 2803 | if (nocopydata) { |
| 2804 | bpl->tus.f.bdeFlags = 0; |
| 2805 | pci_dma_sync_single_for_device(phba->pcidev, |
| 2806 | dmp->dma.phys, LPFC_BPL_SIZE, PCI_DMA_TODEVICE); |
| 2807 | |
| 2808 | } else { |
| 2809 | memset((uint8_t *)dmp->dma.virt, 0, cnt); |
| 2810 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| 2811 | } |
| 2812 | |
| 2813 | /* build buffer ptr list for IOCB */ |
| 2814 | bpl->addrLow = le32_to_cpu(putPaddrLow(dmp->dma.phys)); |
| 2815 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(dmp->dma.phys)); |
| 2816 | bpl->tus.f.bdeSize = (ushort) cnt; |
| 2817 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 2818 | bpl++; |
| 2819 | |
| 2820 | i++; |
| 2821 | offset += cnt; |
| 2822 | size -= cnt; |
| 2823 | } |
| 2824 | |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 2825 | if (mlist) { |
| 2826 | mlist->flag = i; |
| 2827 | return mlist; |
| 2828 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2829 | out: |
| 2830 | diag_cmd_data_free(phba, mlist); |
| 2831 | return NULL; |
| 2832 | } |
| 2833 | |
| 2834 | /** |
| 2835 | * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd |
| 2836 | * @phba: Pointer to HBA context object |
| 2837 | * @rxxri: Receive exchange id |
| 2838 | * @len: Number of data bytes |
| 2839 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2840 | * This function allocates and posts a data buffer of sufficient size to receive |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2841 | * an unsolicted CT command. |
| 2842 | **/ |
| 2843 | static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba *phba, uint16_t rxxri, |
| 2844 | size_t len) |
| 2845 | { |
| 2846 | struct lpfc_sli *psli = &phba->sli; |
| 2847 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| 2848 | struct lpfc_iocbq *cmdiocbq; |
| 2849 | IOCB_t *cmd = NULL; |
| 2850 | struct list_head head, *curr, *next; |
| 2851 | struct lpfc_dmabuf *rxbmp; |
| 2852 | struct lpfc_dmabuf *dmp; |
| 2853 | struct lpfc_dmabuf *mp[2] = {NULL, NULL}; |
| 2854 | struct ulp_bde64 *rxbpl = NULL; |
| 2855 | uint32_t num_bde; |
| 2856 | struct lpfc_dmabufext *rxbuffer = NULL; |
| 2857 | int ret_val = 0; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2858 | int iocb_stat; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2859 | int i = 0; |
| 2860 | |
| 2861 | cmdiocbq = lpfc_sli_get_iocbq(phba); |
| 2862 | rxbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 2863 | if (rxbmp != NULL) { |
| 2864 | rxbmp->virt = lpfc_mbuf_alloc(phba, 0, &rxbmp->phys); |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 2865 | if (rxbmp->virt) { |
| 2866 | INIT_LIST_HEAD(&rxbmp->list); |
| 2867 | rxbpl = (struct ulp_bde64 *) rxbmp->virt; |
| 2868 | rxbuffer = diag_cmd_data_alloc(phba, rxbpl, len, 0); |
| 2869 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | if (!cmdiocbq || !rxbmp || !rxbpl || !rxbuffer) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2873 | ret_val = -ENOMEM; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2874 | goto err_post_rxbufs_exit; |
| 2875 | } |
| 2876 | |
| 2877 | /* Queue buffers for the receive exchange */ |
| 2878 | num_bde = (uint32_t)rxbuffer->flag; |
| 2879 | dmp = &rxbuffer->dma; |
| 2880 | |
| 2881 | cmd = &cmdiocbq->iocb; |
| 2882 | i = 0; |
| 2883 | |
| 2884 | INIT_LIST_HEAD(&head); |
| 2885 | list_add_tail(&head, &dmp->list); |
| 2886 | list_for_each_safe(curr, next, &head) { |
| 2887 | mp[i] = list_entry(curr, struct lpfc_dmabuf, list); |
| 2888 | list_del(curr); |
| 2889 | |
| 2890 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
| 2891 | mp[i]->buffer_tag = lpfc_sli_get_buffer_tag(phba); |
| 2892 | cmd->un.quexri64cx.buff.bde.addrHigh = |
| 2893 | putPaddrHigh(mp[i]->phys); |
| 2894 | cmd->un.quexri64cx.buff.bde.addrLow = |
| 2895 | putPaddrLow(mp[i]->phys); |
| 2896 | cmd->un.quexri64cx.buff.bde.tus.f.bdeSize = |
| 2897 | ((struct lpfc_dmabufext *)mp[i])->size; |
| 2898 | cmd->un.quexri64cx.buff.buffer_tag = mp[i]->buffer_tag; |
| 2899 | cmd->ulpCommand = CMD_QUE_XRI64_CX; |
| 2900 | cmd->ulpPU = 0; |
| 2901 | cmd->ulpLe = 1; |
| 2902 | cmd->ulpBdeCount = 1; |
| 2903 | cmd->unsli3.que_xri64cx_ext_words.ebde_count = 0; |
| 2904 | |
| 2905 | } else { |
| 2906 | cmd->un.cont64[i].addrHigh = putPaddrHigh(mp[i]->phys); |
| 2907 | cmd->un.cont64[i].addrLow = putPaddrLow(mp[i]->phys); |
| 2908 | cmd->un.cont64[i].tus.f.bdeSize = |
| 2909 | ((struct lpfc_dmabufext *)mp[i])->size; |
| 2910 | cmd->ulpBdeCount = ++i; |
| 2911 | |
| 2912 | if ((--num_bde > 0) && (i < 2)) |
| 2913 | continue; |
| 2914 | |
| 2915 | cmd->ulpCommand = CMD_QUE_XRI_BUF64_CX; |
| 2916 | cmd->ulpLe = 1; |
| 2917 | } |
| 2918 | |
| 2919 | cmd->ulpClass = CLASS3; |
| 2920 | cmd->ulpContext = rxxri; |
| 2921 | |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2922 | iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, |
| 2923 | 0); |
| 2924 | if (iocb_stat == IOCB_ERROR) { |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2925 | diag_cmd_data_free(phba, |
| 2926 | (struct lpfc_dmabufext *)mp[0]); |
| 2927 | if (mp[1]) |
| 2928 | diag_cmd_data_free(phba, |
| 2929 | (struct lpfc_dmabufext *)mp[1]); |
| 2930 | dmp = list_entry(next, struct lpfc_dmabuf, list); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2931 | ret_val = -EIO; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2932 | goto err_post_rxbufs_exit; |
| 2933 | } |
| 2934 | |
| 2935 | lpfc_sli_ringpostbuf_put(phba, pring, mp[0]); |
| 2936 | if (mp[1]) { |
| 2937 | lpfc_sli_ringpostbuf_put(phba, pring, mp[1]); |
| 2938 | mp[1] = NULL; |
| 2939 | } |
| 2940 | |
| 2941 | /* The iocb was freed by lpfc_sli_issue_iocb */ |
| 2942 | cmdiocbq = lpfc_sli_get_iocbq(phba); |
| 2943 | if (!cmdiocbq) { |
| 2944 | dmp = list_entry(next, struct lpfc_dmabuf, list); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 2945 | ret_val = -EIO; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2946 | goto err_post_rxbufs_exit; |
| 2947 | } |
| 2948 | |
| 2949 | cmd = &cmdiocbq->iocb; |
| 2950 | i = 0; |
| 2951 | } |
| 2952 | list_del(&head); |
| 2953 | |
| 2954 | err_post_rxbufs_exit: |
| 2955 | |
| 2956 | if (rxbmp) { |
| 2957 | if (rxbmp->virt) |
| 2958 | lpfc_mbuf_free(phba, rxbmp->virt, rxbmp->phys); |
| 2959 | kfree(rxbmp); |
| 2960 | } |
| 2961 | |
| 2962 | if (cmdiocbq) |
| 2963 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 2964 | return ret_val; |
| 2965 | } |
| 2966 | |
| 2967 | /** |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2968 | * lpfc_bsg_diag_loopback_run - run loopback on a port by issue ct cmd to itself |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2969 | * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job |
| 2970 | * |
| 2971 | * This function receives a user data buffer to be transmitted and received on |
| 2972 | * the same port, the link must be up and in loopback mode prior |
| 2973 | * to being called. |
| 2974 | * 1. A kernel buffer is allocated to copy the user data into. |
| 2975 | * 2. The port registers with "itself". |
| 2976 | * 3. The transmit and receive exchange ids are obtained. |
| 2977 | * 4. The receive exchange id is posted. |
| 2978 | * 5. A new els loopback event is created. |
| 2979 | * 6. The command and response iocbs are allocated. |
| 2980 | * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback. |
| 2981 | * |
| 2982 | * This function is meant to be called n times while the port is in loopback |
| 2983 | * so it is the apps responsibility to issue a reset to take the port out |
| 2984 | * of loopback mode. |
| 2985 | **/ |
| 2986 | static int |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 2987 | lpfc_bsg_diag_loopback_run(struct fc_bsg_job *job) |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 2988 | { |
| 2989 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
| 2990 | struct lpfc_hba *phba = vport->phba; |
| 2991 | struct diag_mode_test *diag_mode; |
| 2992 | struct lpfc_bsg_event *evt; |
| 2993 | struct event_data *evdat; |
| 2994 | struct lpfc_sli *psli = &phba->sli; |
| 2995 | uint32_t size; |
| 2996 | uint32_t full_size; |
| 2997 | size_t segment_len = 0, segment_offset = 0, current_offset = 0; |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 2998 | uint16_t rpi = 0; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2999 | struct lpfc_iocbq *cmdiocbq, *rspiocbq = NULL; |
| 3000 | IOCB_t *cmd, *rsp = NULL; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3001 | struct lpfc_sli_ct_request *ctreq; |
| 3002 | struct lpfc_dmabuf *txbmp; |
| 3003 | struct ulp_bde64 *txbpl = NULL; |
| 3004 | struct lpfc_dmabufext *txbuffer = NULL; |
| 3005 | struct list_head head; |
| 3006 | struct lpfc_dmabuf *curr; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3007 | uint16_t txxri = 0, rxxri; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3008 | uint32_t num_bde; |
| 3009 | uint8_t *ptr = NULL, *rx_databuf = NULL; |
| 3010 | int rc = 0; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3011 | int time_left; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 3012 | int iocb_stat = IOCB_SUCCESS; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3013 | unsigned long flags; |
| 3014 | void *dataout = NULL; |
| 3015 | uint32_t total_mem; |
| 3016 | |
| 3017 | /* in case no data is returned return just the return code */ |
| 3018 | job->reply->reply_payload_rcv_len = 0; |
| 3019 | |
| 3020 | if (job->request_len < |
| 3021 | sizeof(struct fc_bsg_request) + sizeof(struct diag_mode_test)) { |
| 3022 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 3023 | "2739 Received DIAG TEST request below minimum " |
| 3024 | "size\n"); |
| 3025 | rc = -EINVAL; |
| 3026 | goto loopback_test_exit; |
| 3027 | } |
| 3028 | |
| 3029 | if (job->request_payload.payload_len != |
| 3030 | job->reply_payload.payload_len) { |
| 3031 | rc = -EINVAL; |
| 3032 | goto loopback_test_exit; |
| 3033 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3034 | diag_mode = (struct diag_mode_test *) |
| 3035 | job->request->rqst_data.h_vendor.vendor_cmd; |
| 3036 | |
| 3037 | if ((phba->link_state == LPFC_HBA_ERROR) || |
| 3038 | (psli->sli_flag & LPFC_BLOCK_MGMT_IO) || |
| 3039 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) { |
| 3040 | rc = -EACCES; |
| 3041 | goto loopback_test_exit; |
| 3042 | } |
| 3043 | |
| 3044 | if (!lpfc_is_link_up(phba) || !(phba->link_flag & LS_LOOPBACK_MODE)) { |
| 3045 | rc = -EACCES; |
| 3046 | goto loopback_test_exit; |
| 3047 | } |
| 3048 | |
| 3049 | size = job->request_payload.payload_len; |
| 3050 | full_size = size + ELX_LOOPBACK_HEADER_SZ; /* plus the header */ |
| 3051 | |
| 3052 | if ((size == 0) || (size > 80 * BUF_SZ_4K)) { |
| 3053 | rc = -ERANGE; |
| 3054 | goto loopback_test_exit; |
| 3055 | } |
| 3056 | |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 3057 | if (full_size >= BUF_SZ_4K) { |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3058 | /* |
| 3059 | * Allocate memory for ioctl data. If buffer is bigger than 64k, |
| 3060 | * then we allocate 64k and re-use that buffer over and over to |
| 3061 | * xfer the whole block. This is because Linux kernel has a |
| 3062 | * problem allocating more than 120k of kernel space memory. Saw |
| 3063 | * problem with GET_FCPTARGETMAPPING... |
| 3064 | */ |
| 3065 | if (size <= (64 * 1024)) |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 3066 | total_mem = full_size; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3067 | else |
| 3068 | total_mem = 64 * 1024; |
| 3069 | } else |
| 3070 | /* Allocate memory for ioctl data */ |
| 3071 | total_mem = BUF_SZ_4K; |
| 3072 | |
| 3073 | dataout = kmalloc(total_mem, GFP_KERNEL); |
| 3074 | if (dataout == NULL) { |
| 3075 | rc = -ENOMEM; |
| 3076 | goto loopback_test_exit; |
| 3077 | } |
| 3078 | |
| 3079 | ptr = dataout; |
| 3080 | ptr += ELX_LOOPBACK_HEADER_SZ; |
| 3081 | sg_copy_to_buffer(job->request_payload.sg_list, |
| 3082 | job->request_payload.sg_cnt, |
| 3083 | ptr, size); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3084 | rc = lpfcdiag_loop_self_reg(phba, &rpi); |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3085 | if (rc) |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3086 | goto loopback_test_exit; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3087 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3088 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3089 | rc = lpfcdiag_loop_get_xri(phba, rpi, &txxri, &rxxri); |
| 3090 | if (rc) { |
| 3091 | lpfcdiag_loop_self_unreg(phba, rpi); |
| 3092 | goto loopback_test_exit; |
| 3093 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3094 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3095 | rc = lpfcdiag_loop_post_rxbufs(phba, rxxri, full_size); |
| 3096 | if (rc) { |
| 3097 | lpfcdiag_loop_self_unreg(phba, rpi); |
| 3098 | goto loopback_test_exit; |
| 3099 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3100 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3101 | evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid, |
| 3102 | SLI_CT_ELX_LOOPBACK); |
| 3103 | if (!evt) { |
| 3104 | lpfcdiag_loop_self_unreg(phba, rpi); |
| 3105 | rc = -ENOMEM; |
| 3106 | goto loopback_test_exit; |
| 3107 | } |
| 3108 | |
| 3109 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 3110 | list_add(&evt->node, &phba->ct_ev_waiters); |
| 3111 | lpfc_bsg_event_ref(evt); |
| 3112 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 3113 | |
| 3114 | cmdiocbq = lpfc_sli_get_iocbq(phba); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3115 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3116 | rspiocbq = lpfc_sli_get_iocbq(phba); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3117 | txbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 3118 | |
| 3119 | if (txbmp) { |
| 3120 | txbmp->virt = lpfc_mbuf_alloc(phba, 0, &txbmp->phys); |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 3121 | if (txbmp->virt) { |
| 3122 | INIT_LIST_HEAD(&txbmp->list); |
| 3123 | txbpl = (struct ulp_bde64 *) txbmp->virt; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3124 | txbuffer = diag_cmd_data_alloc(phba, |
| 3125 | txbpl, full_size, 0); |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 3126 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3127 | } |
| 3128 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3129 | if (!cmdiocbq || !txbmp || !txbpl || !txbuffer || !txbmp->virt) { |
| 3130 | rc = -ENOMEM; |
| 3131 | goto err_loopback_test_exit; |
| 3132 | } |
| 3133 | if ((phba->sli_rev < LPFC_SLI_REV4) && !rspiocbq) { |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3134 | rc = -ENOMEM; |
| 3135 | goto err_loopback_test_exit; |
| 3136 | } |
| 3137 | |
| 3138 | cmd = &cmdiocbq->iocb; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3139 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 3140 | rsp = &rspiocbq->iocb; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3141 | |
| 3142 | INIT_LIST_HEAD(&head); |
| 3143 | list_add_tail(&head, &txbuffer->dma.list); |
| 3144 | list_for_each_entry(curr, &head, list) { |
| 3145 | segment_len = ((struct lpfc_dmabufext *)curr)->size; |
| 3146 | if (current_offset == 0) { |
| 3147 | ctreq = curr->virt; |
| 3148 | memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ); |
| 3149 | ctreq->RevisionId.bits.Revision = SLI_CT_REVISION; |
| 3150 | ctreq->RevisionId.bits.InId = 0; |
| 3151 | ctreq->FsType = SLI_CT_ELX_LOOPBACK; |
| 3152 | ctreq->FsSubType = 0; |
| 3153 | ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_DATA; |
| 3154 | ctreq->CommandResponse.bits.Size = size; |
| 3155 | segment_offset = ELX_LOOPBACK_HEADER_SZ; |
| 3156 | } else |
| 3157 | segment_offset = 0; |
| 3158 | |
| 3159 | BUG_ON(segment_offset >= segment_len); |
| 3160 | memcpy(curr->virt + segment_offset, |
| 3161 | ptr + current_offset, |
| 3162 | segment_len - segment_offset); |
| 3163 | |
| 3164 | current_offset += segment_len - segment_offset; |
| 3165 | BUG_ON(current_offset > size); |
| 3166 | } |
| 3167 | list_del(&head); |
| 3168 | |
| 3169 | /* Build the XMIT_SEQUENCE iocb */ |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3170 | num_bde = (uint32_t)txbuffer->flag; |
| 3171 | |
| 3172 | cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(txbmp->phys); |
| 3173 | cmd->un.xseq64.bdl.addrLow = putPaddrLow(txbmp->phys); |
| 3174 | cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 3175 | cmd->un.xseq64.bdl.bdeSize = (num_bde * sizeof(struct ulp_bde64)); |
| 3176 | |
| 3177 | cmd->un.xseq64.w5.hcsw.Fctl = (LS | LA); |
| 3178 | cmd->un.xseq64.w5.hcsw.Dfctl = 0; |
| 3179 | cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; |
| 3180 | cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT; |
| 3181 | |
| 3182 | cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX; |
| 3183 | cmd->ulpBdeCount = 1; |
| 3184 | cmd->ulpLe = 1; |
| 3185 | cmd->ulpClass = CLASS3; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3186 | |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3187 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3188 | cmd->ulpContext = txxri; |
| 3189 | } else { |
| 3190 | cmd->un.xseq64.bdl.ulpIoTag32 = 0; |
| 3191 | cmd->un.ulpWord[3] = phba->sli4_hba.rpi_ids[rpi]; |
| 3192 | cmdiocbq->context3 = txbmp; |
| 3193 | cmdiocbq->sli4_xritag = NO_XRI; |
| 3194 | cmd->unsli3.rcvsli3.ox_id = 0xffff; |
| 3195 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3196 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; |
James Smart | 6c7cf48 | 2015-04-07 15:07:25 -0400 | [diff] [blame] | 3197 | cmdiocbq->iocb_flag |= LPFC_IO_LOOPBACK; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3198 | cmdiocbq->vport = phba->pport; |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 3199 | cmdiocbq->iocb_cmpl = NULL; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3200 | iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq, |
| 3201 | rspiocbq, (phba->fc_ratov * 2) + |
| 3202 | LPFC_DRVR_TIMEOUT); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3203 | |
James Smart | 53151bb | 2013-10-10 12:24:07 -0400 | [diff] [blame] | 3204 | if ((iocb_stat != IOCB_SUCCESS) || |
| 3205 | ((phba->sli_rev < LPFC_SLI_REV4) && |
| 3206 | (rsp->ulpStatus != IOSTAT_SUCCESS))) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3207 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 3208 | "3126 Failed loopback test issue iocb: " |
| 3209 | "iocb_stat:x%x\n", iocb_stat); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3210 | rc = -EIO; |
| 3211 | goto err_loopback_test_exit; |
| 3212 | } |
| 3213 | |
| 3214 | evt->waiting = 1; |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3215 | time_left = wait_event_interruptible_timeout( |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3216 | evt->wq, !list_empty(&evt->events_to_see), |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 3217 | msecs_to_jiffies(1000 * |
| 3218 | ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT))); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3219 | evt->waiting = 0; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3220 | if (list_empty(&evt->events_to_see)) { |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 3221 | rc = (time_left) ? -EINTR : -ETIMEDOUT; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3222 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 3223 | "3125 Not receiving unsolicited event, " |
| 3224 | "rc:x%x\n", rc); |
| 3225 | } else { |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3226 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 3227 | list_move(evt->events_to_see.prev, &evt->events_to_get); |
| 3228 | evdat = list_entry(evt->events_to_get.prev, |
| 3229 | typeof(*evdat), node); |
| 3230 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 3231 | rx_databuf = evdat->data; |
| 3232 | if (evdat->len != full_size) { |
| 3233 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 3234 | "1603 Loopback test did not receive expected " |
| 3235 | "data length. actual length 0x%x expected " |
| 3236 | "length 0x%x\n", |
| 3237 | evdat->len, full_size); |
| 3238 | rc = -EIO; |
| 3239 | } else if (rx_databuf == NULL) |
| 3240 | rc = -EIO; |
| 3241 | else { |
| 3242 | rc = IOCB_SUCCESS; |
| 3243 | /* skip over elx loopback header */ |
| 3244 | rx_databuf += ELX_LOOPBACK_HEADER_SZ; |
| 3245 | job->reply->reply_payload_rcv_len = |
| 3246 | sg_copy_from_buffer(job->reply_payload.sg_list, |
| 3247 | job->reply_payload.sg_cnt, |
| 3248 | rx_databuf, size); |
| 3249 | job->reply->reply_payload_rcv_len = size; |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | err_loopback_test_exit: |
| 3254 | lpfcdiag_loop_self_unreg(phba, rpi); |
| 3255 | |
| 3256 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 3257 | lpfc_bsg_event_unref(evt); /* release ref */ |
| 3258 | lpfc_bsg_event_unref(evt); /* delete */ |
| 3259 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 3260 | |
James Smart | 5a0916b | 2013-07-15 18:31:42 -0400 | [diff] [blame] | 3261 | if ((cmdiocbq != NULL) && (iocb_stat != IOCB_TIMEDOUT)) |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3262 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
| 3263 | |
| 3264 | if (rspiocbq != NULL) |
| 3265 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 3266 | |
| 3267 | if (txbmp != NULL) { |
| 3268 | if (txbpl != NULL) { |
| 3269 | if (txbuffer != NULL) |
| 3270 | diag_cmd_data_free(phba, txbuffer); |
| 3271 | lpfc_mbuf_free(phba, txbmp->virt, txbmp->phys); |
| 3272 | } |
| 3273 | kfree(txbmp); |
| 3274 | } |
| 3275 | |
| 3276 | loopback_test_exit: |
| 3277 | kfree(dataout); |
| 3278 | /* make error code available to userspace */ |
| 3279 | job->reply->result = rc; |
| 3280 | job->dd_data = NULL; |
| 3281 | /* complete the job back to userspace if no error */ |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3282 | if (rc == IOCB_SUCCESS) |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3283 | job->job_done(job); |
| 3284 | return rc; |
| 3285 | } |
| 3286 | |
| 3287 | /** |
| 3288 | * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command |
| 3289 | * @job: GET_DFC_REV fc_bsg_job |
| 3290 | **/ |
| 3291 | static int |
| 3292 | lpfc_bsg_get_dfc_rev(struct fc_bsg_job *job) |
| 3293 | { |
| 3294 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
| 3295 | struct lpfc_hba *phba = vport->phba; |
| 3296 | struct get_mgmt_rev *event_req; |
| 3297 | struct get_mgmt_rev_reply *event_reply; |
| 3298 | int rc = 0; |
| 3299 | |
| 3300 | if (job->request_len < |
| 3301 | sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev)) { |
| 3302 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 3303 | "2740 Received GET_DFC_REV request below " |
| 3304 | "minimum size\n"); |
| 3305 | rc = -EINVAL; |
| 3306 | goto job_error; |
| 3307 | } |
| 3308 | |
| 3309 | event_req = (struct get_mgmt_rev *) |
| 3310 | job->request->rqst_data.h_vendor.vendor_cmd; |
| 3311 | |
| 3312 | event_reply = (struct get_mgmt_rev_reply *) |
| 3313 | job->reply->reply_data.vendor_reply.vendor_rsp; |
| 3314 | |
| 3315 | if (job->reply_len < |
| 3316 | sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev_reply)) { |
| 3317 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 3318 | "2741 Received GET_DFC_REV reply below " |
| 3319 | "minimum size\n"); |
| 3320 | rc = -EINVAL; |
| 3321 | goto job_error; |
| 3322 | } |
| 3323 | |
| 3324 | event_reply->info.a_Major = MANAGEMENT_MAJOR_REV; |
| 3325 | event_reply->info.a_Minor = MANAGEMENT_MINOR_REV; |
| 3326 | job_error: |
| 3327 | job->reply->result = rc; |
| 3328 | if (rc == 0) |
| 3329 | job->job_done(job); |
| 3330 | return rc; |
| 3331 | } |
| 3332 | |
| 3333 | /** |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3334 | * lpfc_bsg_issue_mbox_cmpl - lpfc_bsg_issue_mbox mbox completion handler |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3335 | * @phba: Pointer to HBA context object. |
| 3336 | * @pmboxq: Pointer to mailbox command. |
| 3337 | * |
| 3338 | * This is completion handler function for mailbox commands issued from |
| 3339 | * lpfc_bsg_issue_mbox function. This function is called by the |
| 3340 | * mailbox event handler function with no lock held. This function |
| 3341 | * will wake up thread waiting on the wait queue pointed by context1 |
| 3342 | * of the mailbox. |
| 3343 | **/ |
Rashika Kheria | 9ab9b13 | 2014-09-03 12:55:46 -0400 | [diff] [blame] | 3344 | static void |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3345 | lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3346 | { |
| 3347 | struct bsg_job_data *dd_data; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3348 | struct fc_bsg_job *job; |
| 3349 | uint32_t size; |
| 3350 | unsigned long flags; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3351 | uint8_t *pmb, *pmb_buf; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3352 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3353 | dd_data = pmboxq->context1; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3354 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3355 | /* |
| 3356 | * The outgoing buffer is readily referred from the dma buffer, |
| 3357 | * just need to get header part from mailboxq structure. |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 3358 | */ |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3359 | pmb = (uint8_t *)&pmboxq->u.mb; |
| 3360 | pmb_buf = (uint8_t *)dd_data->context_un.mbox.mb; |
| 3361 | memcpy(pmb_buf, pmb, sizeof(MAILBOX_t)); |
James Smart | 515e0aa | 2010-09-29 11:19:00 -0400 | [diff] [blame] | 3362 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3363 | /* Determine if job has been aborted */ |
| 3364 | |
| 3365 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 3366 | job = dd_data->set_job; |
| 3367 | if (job) { |
| 3368 | /* Prevent timeout handling from trying to abort job */ |
| 3369 | job->dd_data = NULL; |
| 3370 | } |
| 3371 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 3372 | |
| 3373 | /* Copy the mailbox data to the job if it is still active */ |
| 3374 | |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 3375 | if (job) { |
| 3376 | size = job->reply_payload.payload_len; |
| 3377 | job->reply->reply_payload_rcv_len = |
| 3378 | sg_copy_from_buffer(job->reply_payload.sg_list, |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3379 | job->reply_payload.sg_cnt, |
| 3380 | pmb_buf, size); |
James Smart | 5a6f133 | 2011-03-11 16:05:35 -0500 | [diff] [blame] | 3381 | } |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 3382 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3383 | dd_data->set_job = NULL; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3384 | mempool_free(dd_data->context_un.mbox.pmboxq, phba->mbox_mem_pool); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3385 | lpfc_bsg_dma_page_free(phba, dd_data->context_un.mbox.dmabuffers); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3386 | kfree(dd_data); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3387 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3388 | /* Complete the job if the job is still active */ |
| 3389 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3390 | if (job) { |
| 3391 | job->reply->result = 0; |
| 3392 | job->job_done(job); |
| 3393 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3394 | return; |
| 3395 | } |
| 3396 | |
| 3397 | /** |
| 3398 | * lpfc_bsg_check_cmd_access - test for a supported mailbox command |
| 3399 | * @phba: Pointer to HBA context object. |
| 3400 | * @mb: Pointer to a mailbox object. |
| 3401 | * @vport: Pointer to a vport object. |
| 3402 | * |
| 3403 | * Some commands require the port to be offline, some may not be called from |
| 3404 | * the application. |
| 3405 | **/ |
| 3406 | static int lpfc_bsg_check_cmd_access(struct lpfc_hba *phba, |
| 3407 | MAILBOX_t *mb, struct lpfc_vport *vport) |
| 3408 | { |
| 3409 | /* return negative error values for bsg job */ |
| 3410 | switch (mb->mbxCommand) { |
| 3411 | /* Offline only */ |
| 3412 | case MBX_INIT_LINK: |
| 3413 | case MBX_DOWN_LINK: |
| 3414 | case MBX_CONFIG_LINK: |
| 3415 | case MBX_CONFIG_RING: |
| 3416 | case MBX_RESET_RING: |
| 3417 | case MBX_UNREG_LOGIN: |
| 3418 | case MBX_CLEAR_LA: |
| 3419 | case MBX_DUMP_CONTEXT: |
| 3420 | case MBX_RUN_DIAGS: |
| 3421 | case MBX_RESTART: |
| 3422 | case MBX_SET_MASK: |
| 3423 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) { |
| 3424 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 3425 | "2743 Command 0x%x is illegal in on-line " |
| 3426 | "state\n", |
| 3427 | mb->mbxCommand); |
| 3428 | return -EPERM; |
| 3429 | } |
| 3430 | case MBX_WRITE_NV: |
| 3431 | case MBX_WRITE_VPARMS: |
| 3432 | case MBX_LOAD_SM: |
| 3433 | case MBX_READ_NV: |
| 3434 | case MBX_READ_CONFIG: |
| 3435 | case MBX_READ_RCONFIG: |
| 3436 | case MBX_READ_STATUS: |
| 3437 | case MBX_READ_XRI: |
| 3438 | case MBX_READ_REV: |
| 3439 | case MBX_READ_LNK_STAT: |
| 3440 | case MBX_DUMP_MEMORY: |
| 3441 | case MBX_DOWN_LOAD: |
| 3442 | case MBX_UPDATE_CFG: |
| 3443 | case MBX_KILL_BOARD: |
James Smart | 06f3555 | 2013-05-31 17:04:50 -0400 | [diff] [blame] | 3444 | case MBX_READ_TOPOLOGY: |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3445 | case MBX_LOAD_AREA: |
| 3446 | case MBX_LOAD_EXP_ROM: |
| 3447 | case MBX_BEACON: |
| 3448 | case MBX_DEL_LD_ENTRY: |
| 3449 | case MBX_SET_DEBUG: |
| 3450 | case MBX_WRITE_WWN: |
| 3451 | case MBX_SLI4_CONFIG: |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 3452 | case MBX_READ_EVENT_LOG: |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3453 | case MBX_READ_EVENT_LOG_STATUS: |
| 3454 | case MBX_WRITE_EVENT_LOG: |
| 3455 | case MBX_PORT_CAPABILITIES: |
| 3456 | case MBX_PORT_IOV_CONTROL: |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 3457 | case MBX_RUN_BIU_DIAG64: |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3458 | break; |
| 3459 | case MBX_SET_VARIABLE: |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 3460 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3461 | "1226 mbox: set_variable 0x%x, 0x%x\n", |
| 3462 | mb->un.varWords[0], |
| 3463 | mb->un.varWords[1]); |
| 3464 | if ((mb->un.varWords[0] == SETVAR_MLOMNT) |
| 3465 | && (mb->un.varWords[1] == 1)) { |
| 3466 | phba->wait_4_mlo_maint_flg = 1; |
| 3467 | } else if (mb->un.varWords[0] == SETVAR_MLORST) { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3468 | spin_lock_irq(&phba->hbalock); |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 3469 | phba->link_flag &= ~LS_LOOPBACK_MODE; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 3470 | spin_unlock_irq(&phba->hbalock); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 3471 | phba->fc_topology = LPFC_TOPOLOGY_PT_PT; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 3472 | } |
| 3473 | break; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3474 | case MBX_READ_SPARM64: |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 3475 | case MBX_REG_LOGIN: |
| 3476 | case MBX_REG_LOGIN64: |
| 3477 | case MBX_CONFIG_PORT: |
| 3478 | case MBX_RUN_BIU_DIAG: |
| 3479 | default: |
| 3480 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 3481 | "2742 Unknown Command 0x%x\n", |
| 3482 | mb->mbxCommand); |
| 3483 | return -EPERM; |
| 3484 | } |
| 3485 | |
| 3486 | return 0; /* ok */ |
| 3487 | } |
| 3488 | |
| 3489 | /** |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3490 | * lpfc_bsg_mbox_ext_cleanup - clean up context of multi-buffer mbox session |
| 3491 | * @phba: Pointer to HBA context object. |
| 3492 | * |
| 3493 | * This is routine clean up and reset BSG handling of multi-buffer mbox |
| 3494 | * command session. |
| 3495 | **/ |
| 3496 | static void |
| 3497 | lpfc_bsg_mbox_ext_session_reset(struct lpfc_hba *phba) |
| 3498 | { |
| 3499 | if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_IDLE) |
| 3500 | return; |
| 3501 | |
| 3502 | /* free all memory, including dma buffers */ |
| 3503 | lpfc_bsg_dma_page_list_free(phba, |
| 3504 | &phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 3505 | lpfc_bsg_dma_page_free(phba, phba->mbox_ext_buf_ctx.mbx_dmabuf); |
| 3506 | /* multi-buffer write mailbox command pass-through complete */ |
| 3507 | memset((char *)&phba->mbox_ext_buf_ctx, 0, |
| 3508 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 3509 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 3510 | |
| 3511 | return; |
| 3512 | } |
| 3513 | |
| 3514 | /** |
| 3515 | * lpfc_bsg_issue_mbox_ext_handle_job - job handler for multi-buffer mbox cmpl |
| 3516 | * @phba: Pointer to HBA context object. |
| 3517 | * @pmboxq: Pointer to mailbox command. |
| 3518 | * |
| 3519 | * This is routine handles BSG job for mailbox commands completions with |
| 3520 | * multiple external buffers. |
| 3521 | **/ |
| 3522 | static struct fc_bsg_job * |
| 3523 | lpfc_bsg_issue_mbox_ext_handle_job(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 3524 | { |
| 3525 | struct bsg_job_data *dd_data; |
| 3526 | struct fc_bsg_job *job; |
| 3527 | uint8_t *pmb, *pmb_buf; |
| 3528 | unsigned long flags; |
| 3529 | uint32_t size; |
| 3530 | int rc = 0; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 3531 | struct lpfc_dmabuf *dmabuf; |
| 3532 | struct lpfc_sli_config_mbox *sli_cfg_mbx; |
| 3533 | uint8_t *pmbx; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3534 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3535 | dd_data = pmboxq->context1; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3536 | |
| 3537 | /* Determine if job has been aborted */ |
| 3538 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 3539 | job = dd_data->set_job; |
| 3540 | if (job) { |
| 3541 | /* Prevent timeout handling from trying to abort job */ |
| 3542 | job->dd_data = NULL; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3543 | } |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3544 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3545 | |
| 3546 | /* |
| 3547 | * The outgoing buffer is readily referred from the dma buffer, |
| 3548 | * just need to get header part from mailboxq structure. |
| 3549 | */ |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3550 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3551 | pmb = (uint8_t *)&pmboxq->u.mb; |
| 3552 | pmb_buf = (uint8_t *)dd_data->context_un.mbox.mb; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 3553 | /* Copy the byte swapped response mailbox back to the user */ |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3554 | memcpy(pmb_buf, pmb, sizeof(MAILBOX_t)); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 3555 | /* if there is any non-embedded extended data copy that too */ |
| 3556 | dmabuf = phba->mbox_ext_buf_ctx.mbx_dmabuf; |
| 3557 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt; |
| 3558 | if (!bsg_bf_get(lpfc_mbox_hdr_emb, |
| 3559 | &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) { |
| 3560 | pmbx = (uint8_t *)dmabuf->virt; |
| 3561 | /* byte swap the extended data following the mailbox command */ |
| 3562 | lpfc_sli_pcimem_bcopy(&pmbx[sizeof(MAILBOX_t)], |
| 3563 | &pmbx[sizeof(MAILBOX_t)], |
| 3564 | sli_cfg_mbx->un.sli_config_emb0_subsys.mse[0].buf_len); |
| 3565 | } |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3566 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3567 | /* Complete the job if the job is still active */ |
| 3568 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3569 | if (job) { |
| 3570 | size = job->reply_payload.payload_len; |
| 3571 | job->reply->reply_payload_rcv_len = |
| 3572 | sg_copy_from_buffer(job->reply_payload.sg_list, |
| 3573 | job->reply_payload.sg_cnt, |
| 3574 | pmb_buf, size); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3575 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3576 | /* result for successful */ |
| 3577 | job->reply->result = 0; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3578 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3579 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 3580 | "2937 SLI_CONFIG ext-buffer maibox command " |
| 3581 | "(x%x/x%x) complete bsg job done, bsize:%d\n", |
| 3582 | phba->mbox_ext_buf_ctx.nembType, |
| 3583 | phba->mbox_ext_buf_ctx.mboxType, size); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3584 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, |
| 3585 | phba->mbox_ext_buf_ctx.nembType, |
| 3586 | phba->mbox_ext_buf_ctx.mboxType, |
| 3587 | dma_ebuf, sta_pos_addr, |
| 3588 | phba->mbox_ext_buf_ctx.mbx_dmabuf, 0); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3589 | } else { |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3590 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 3591 | "2938 SLI_CONFIG ext-buffer maibox " |
| 3592 | "command (x%x/x%x) failure, rc:x%x\n", |
| 3593 | phba->mbox_ext_buf_ctx.nembType, |
| 3594 | phba->mbox_ext_buf_ctx.mboxType, rc); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3598 | /* state change */ |
| 3599 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_DONE; |
| 3600 | kfree(dd_data); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3601 | return job; |
| 3602 | } |
| 3603 | |
| 3604 | /** |
| 3605 | * lpfc_bsg_issue_read_mbox_ext_cmpl - compl handler for multi-buffer read mbox |
| 3606 | * @phba: Pointer to HBA context object. |
| 3607 | * @pmboxq: Pointer to mailbox command. |
| 3608 | * |
| 3609 | * This is completion handler function for mailbox read commands with multiple |
| 3610 | * external buffers. |
| 3611 | **/ |
| 3612 | static void |
| 3613 | lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 3614 | { |
| 3615 | struct fc_bsg_job *job; |
| 3616 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3617 | job = lpfc_bsg_issue_mbox_ext_handle_job(phba, pmboxq); |
| 3618 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3619 | /* handle the BSG job with mailbox command */ |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3620 | if (!job) |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3621 | pmboxq->u.mb.mbxStatus = MBXERR_ERROR; |
| 3622 | |
| 3623 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 3624 | "2939 SLI_CONFIG ext-buffer rd maibox command " |
| 3625 | "complete, ctxState:x%x, mbxStatus:x%x\n", |
| 3626 | phba->mbox_ext_buf_ctx.state, pmboxq->u.mb.mbxStatus); |
| 3627 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3628 | if (pmboxq->u.mb.mbxStatus || phba->mbox_ext_buf_ctx.numBuf == 1) |
| 3629 | lpfc_bsg_mbox_ext_session_reset(phba); |
| 3630 | |
| 3631 | /* free base driver mailbox structure memory */ |
| 3632 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 3633 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3634 | /* if the job is still active, call job done */ |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3635 | if (job) |
| 3636 | job->job_done(job); |
| 3637 | |
| 3638 | return; |
| 3639 | } |
| 3640 | |
| 3641 | /** |
| 3642 | * lpfc_bsg_issue_write_mbox_ext_cmpl - cmpl handler for multi-buffer write mbox |
| 3643 | * @phba: Pointer to HBA context object. |
| 3644 | * @pmboxq: Pointer to mailbox command. |
| 3645 | * |
| 3646 | * This is completion handler function for mailbox write commands with multiple |
| 3647 | * external buffers. |
| 3648 | **/ |
| 3649 | static void |
| 3650 | lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 3651 | { |
| 3652 | struct fc_bsg_job *job; |
| 3653 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3654 | job = lpfc_bsg_issue_mbox_ext_handle_job(phba, pmboxq); |
| 3655 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3656 | /* handle the BSG job with the mailbox command */ |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3657 | if (!job) |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3658 | pmboxq->u.mb.mbxStatus = MBXERR_ERROR; |
| 3659 | |
| 3660 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 3661 | "2940 SLI_CONFIG ext-buffer wr maibox command " |
| 3662 | "complete, ctxState:x%x, mbxStatus:x%x\n", |
| 3663 | phba->mbox_ext_buf_ctx.state, pmboxq->u.mb.mbxStatus); |
| 3664 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3665 | /* free all memory, including dma buffers */ |
| 3666 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 3667 | lpfc_bsg_mbox_ext_session_reset(phba); |
| 3668 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3669 | /* if the job is still active, call job done */ |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3670 | if (job) |
| 3671 | job->job_done(job); |
| 3672 | |
| 3673 | return; |
| 3674 | } |
| 3675 | |
| 3676 | static void |
| 3677 | lpfc_bsg_sli_cfg_dma_desc_setup(struct lpfc_hba *phba, enum nemb_type nemb_tp, |
| 3678 | uint32_t index, struct lpfc_dmabuf *mbx_dmabuf, |
| 3679 | struct lpfc_dmabuf *ext_dmabuf) |
| 3680 | { |
| 3681 | struct lpfc_sli_config_mbox *sli_cfg_mbx; |
| 3682 | |
| 3683 | /* pointer to the start of mailbox command */ |
| 3684 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *)mbx_dmabuf->virt; |
| 3685 | |
| 3686 | if (nemb_tp == nemb_mse) { |
| 3687 | if (index == 0) { |
| 3688 | sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 3689 | mse[index].pa_hi = |
| 3690 | putPaddrHigh(mbx_dmabuf->phys + |
| 3691 | sizeof(MAILBOX_t)); |
| 3692 | sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 3693 | mse[index].pa_lo = |
| 3694 | putPaddrLow(mbx_dmabuf->phys + |
| 3695 | sizeof(MAILBOX_t)); |
| 3696 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 3697 | "2943 SLI_CONFIG(mse)[%d], " |
| 3698 | "bufLen:%d, addrHi:x%x, addrLo:x%x\n", |
| 3699 | index, |
| 3700 | sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 3701 | mse[index].buf_len, |
| 3702 | sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 3703 | mse[index].pa_hi, |
| 3704 | sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 3705 | mse[index].pa_lo); |
| 3706 | } else { |
| 3707 | sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 3708 | mse[index].pa_hi = |
| 3709 | putPaddrHigh(ext_dmabuf->phys); |
| 3710 | sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 3711 | mse[index].pa_lo = |
| 3712 | putPaddrLow(ext_dmabuf->phys); |
| 3713 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 3714 | "2944 SLI_CONFIG(mse)[%d], " |
| 3715 | "bufLen:%d, addrHi:x%x, addrLo:x%x\n", |
| 3716 | index, |
| 3717 | sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 3718 | mse[index].buf_len, |
| 3719 | sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 3720 | mse[index].pa_hi, |
| 3721 | sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 3722 | mse[index].pa_lo); |
| 3723 | } |
| 3724 | } else { |
| 3725 | if (index == 0) { |
| 3726 | sli_cfg_mbx->un.sli_config_emb1_subsys. |
| 3727 | hbd[index].pa_hi = |
| 3728 | putPaddrHigh(mbx_dmabuf->phys + |
| 3729 | sizeof(MAILBOX_t)); |
| 3730 | sli_cfg_mbx->un.sli_config_emb1_subsys. |
| 3731 | hbd[index].pa_lo = |
| 3732 | putPaddrLow(mbx_dmabuf->phys + |
| 3733 | sizeof(MAILBOX_t)); |
| 3734 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 3735 | "3007 SLI_CONFIG(hbd)[%d], " |
| 3736 | "bufLen:%d, addrHi:x%x, addrLo:x%x\n", |
| 3737 | index, |
| 3738 | bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len, |
| 3739 | &sli_cfg_mbx->un. |
| 3740 | sli_config_emb1_subsys.hbd[index]), |
| 3741 | sli_cfg_mbx->un.sli_config_emb1_subsys. |
| 3742 | hbd[index].pa_hi, |
| 3743 | sli_cfg_mbx->un.sli_config_emb1_subsys. |
| 3744 | hbd[index].pa_lo); |
| 3745 | |
| 3746 | } else { |
| 3747 | sli_cfg_mbx->un.sli_config_emb1_subsys. |
| 3748 | hbd[index].pa_hi = |
| 3749 | putPaddrHigh(ext_dmabuf->phys); |
| 3750 | sli_cfg_mbx->un.sli_config_emb1_subsys. |
| 3751 | hbd[index].pa_lo = |
| 3752 | putPaddrLow(ext_dmabuf->phys); |
| 3753 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 3754 | "3008 SLI_CONFIG(hbd)[%d], " |
| 3755 | "bufLen:%d, addrHi:x%x, addrLo:x%x\n", |
| 3756 | index, |
| 3757 | bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len, |
| 3758 | &sli_cfg_mbx->un. |
| 3759 | sli_config_emb1_subsys.hbd[index]), |
| 3760 | sli_cfg_mbx->un.sli_config_emb1_subsys. |
| 3761 | hbd[index].pa_hi, |
| 3762 | sli_cfg_mbx->un.sli_config_emb1_subsys. |
| 3763 | hbd[index].pa_lo); |
| 3764 | } |
| 3765 | } |
| 3766 | return; |
| 3767 | } |
| 3768 | |
| 3769 | /** |
| 3770 | * lpfc_bsg_sli_cfg_mse_read_cmd_ext - sli_config non-embedded mailbox cmd read |
| 3771 | * @phba: Pointer to HBA context object. |
| 3772 | * @mb: Pointer to a BSG mailbox object. |
| 3773 | * @nemb_tp: Enumerate of non-embedded mailbox command type. |
| 3774 | * @dmabuff: Pointer to a DMA buffer descriptor. |
| 3775 | * |
| 3776 | * This routine performs SLI_CONFIG (0x9B) read mailbox command operation with |
| 3777 | * non-embedded external bufffers. |
| 3778 | **/ |
| 3779 | static int |
| 3780 | lpfc_bsg_sli_cfg_read_cmd_ext(struct lpfc_hba *phba, struct fc_bsg_job *job, |
| 3781 | enum nemb_type nemb_tp, |
| 3782 | struct lpfc_dmabuf *dmabuf) |
| 3783 | { |
| 3784 | struct lpfc_sli_config_mbox *sli_cfg_mbx; |
| 3785 | struct dfc_mbox_req *mbox_req; |
| 3786 | struct lpfc_dmabuf *curr_dmabuf, *next_dmabuf; |
| 3787 | uint32_t ext_buf_cnt, ext_buf_index; |
| 3788 | struct lpfc_dmabuf *ext_dmabuf = NULL; |
| 3789 | struct bsg_job_data *dd_data = NULL; |
| 3790 | LPFC_MBOXQ_t *pmboxq = NULL; |
| 3791 | MAILBOX_t *pmb; |
| 3792 | uint8_t *pmbx; |
| 3793 | int rc, i; |
| 3794 | |
| 3795 | mbox_req = |
| 3796 | (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd; |
| 3797 | |
| 3798 | /* pointer to the start of mailbox command */ |
| 3799 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt; |
| 3800 | |
| 3801 | if (nemb_tp == nemb_mse) { |
| 3802 | ext_buf_cnt = bsg_bf_get(lpfc_mbox_hdr_mse_cnt, |
| 3803 | &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr); |
| 3804 | if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_MSE) { |
| 3805 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 3806 | "2945 Handled SLI_CONFIG(mse) rd, " |
| 3807 | "ext_buf_cnt(%d) out of range(%d)\n", |
| 3808 | ext_buf_cnt, |
| 3809 | LPFC_MBX_SLI_CONFIG_MAX_MSE); |
| 3810 | rc = -ERANGE; |
| 3811 | goto job_error; |
| 3812 | } |
| 3813 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 3814 | "2941 Handled SLI_CONFIG(mse) rd, " |
| 3815 | "ext_buf_cnt:%d\n", ext_buf_cnt); |
| 3816 | } else { |
| 3817 | /* sanity check on interface type for support */ |
| 3818 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 3819 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 3820 | rc = -ENODEV; |
| 3821 | goto job_error; |
| 3822 | } |
| 3823 | /* nemb_tp == nemb_hbd */ |
| 3824 | ext_buf_cnt = sli_cfg_mbx->un.sli_config_emb1_subsys.hbd_count; |
| 3825 | if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_HBD) { |
| 3826 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 3827 | "2946 Handled SLI_CONFIG(hbd) rd, " |
| 3828 | "ext_buf_cnt(%d) out of range(%d)\n", |
| 3829 | ext_buf_cnt, |
| 3830 | LPFC_MBX_SLI_CONFIG_MAX_HBD); |
| 3831 | rc = -ERANGE; |
| 3832 | goto job_error; |
| 3833 | } |
| 3834 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 3835 | "2942 Handled SLI_CONFIG(hbd) rd, " |
| 3836 | "ext_buf_cnt:%d\n", ext_buf_cnt); |
| 3837 | } |
| 3838 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3839 | /* before dma descriptor setup */ |
| 3840 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_rd, dma_mbox, |
| 3841 | sta_pre_addr, dmabuf, ext_buf_cnt); |
| 3842 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3843 | /* reject non-embedded mailbox command with none external buffer */ |
| 3844 | if (ext_buf_cnt == 0) { |
| 3845 | rc = -EPERM; |
| 3846 | goto job_error; |
| 3847 | } else if (ext_buf_cnt > 1) { |
| 3848 | /* additional external read buffers */ |
| 3849 | for (i = 1; i < ext_buf_cnt; i++) { |
| 3850 | ext_dmabuf = lpfc_bsg_dma_page_alloc(phba); |
| 3851 | if (!ext_dmabuf) { |
| 3852 | rc = -ENOMEM; |
| 3853 | goto job_error; |
| 3854 | } |
| 3855 | list_add_tail(&ext_dmabuf->list, |
| 3856 | &phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 3857 | } |
| 3858 | } |
| 3859 | |
| 3860 | /* bsg tracking structure */ |
| 3861 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); |
| 3862 | if (!dd_data) { |
| 3863 | rc = -ENOMEM; |
| 3864 | goto job_error; |
| 3865 | } |
| 3866 | |
| 3867 | /* mailbox command structure for base driver */ |
| 3868 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3869 | if (!pmboxq) { |
| 3870 | rc = -ENOMEM; |
| 3871 | goto job_error; |
| 3872 | } |
| 3873 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 3874 | |
| 3875 | /* for the first external buffer */ |
| 3876 | lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, 0, dmabuf, dmabuf); |
| 3877 | |
| 3878 | /* for the rest of external buffer descriptors if any */ |
| 3879 | if (ext_buf_cnt > 1) { |
| 3880 | ext_buf_index = 1; |
| 3881 | list_for_each_entry_safe(curr_dmabuf, next_dmabuf, |
| 3882 | &phba->mbox_ext_buf_ctx.ext_dmabuf_list, list) { |
| 3883 | lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, |
| 3884 | ext_buf_index, dmabuf, |
| 3885 | curr_dmabuf); |
| 3886 | ext_buf_index++; |
| 3887 | } |
| 3888 | } |
| 3889 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3890 | /* after dma descriptor setup */ |
| 3891 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_rd, dma_mbox, |
| 3892 | sta_pos_addr, dmabuf, ext_buf_cnt); |
| 3893 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3894 | /* construct base driver mbox command */ |
| 3895 | pmb = &pmboxq->u.mb; |
| 3896 | pmbx = (uint8_t *)dmabuf->virt; |
| 3897 | memcpy(pmb, pmbx, sizeof(*pmb)); |
| 3898 | pmb->mbxOwner = OWN_HOST; |
| 3899 | pmboxq->vport = phba->pport; |
| 3900 | |
| 3901 | /* multi-buffer handling context */ |
| 3902 | phba->mbox_ext_buf_ctx.nembType = nemb_tp; |
| 3903 | phba->mbox_ext_buf_ctx.mboxType = mbox_rd; |
| 3904 | phba->mbox_ext_buf_ctx.numBuf = ext_buf_cnt; |
| 3905 | phba->mbox_ext_buf_ctx.mbxTag = mbox_req->extMboxTag; |
| 3906 | phba->mbox_ext_buf_ctx.seqNum = mbox_req->extSeqNum; |
| 3907 | phba->mbox_ext_buf_ctx.mbx_dmabuf = dmabuf; |
| 3908 | |
| 3909 | /* callback for multi-buffer read mailbox command */ |
| 3910 | pmboxq->mbox_cmpl = lpfc_bsg_issue_read_mbox_ext_cmpl; |
| 3911 | |
| 3912 | /* context fields to callback function */ |
| 3913 | pmboxq->context1 = dd_data; |
| 3914 | dd_data->type = TYPE_MBOX; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 3915 | dd_data->set_job = job; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3916 | dd_data->context_un.mbox.pmboxq = pmboxq; |
| 3917 | dd_data->context_un.mbox.mb = (MAILBOX_t *)pmbx; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3918 | job->dd_data = dd_data; |
| 3919 | |
| 3920 | /* state change */ |
| 3921 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT; |
| 3922 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 3923 | /* |
| 3924 | * Non-embedded mailbox subcommand data gets byte swapped here because |
| 3925 | * the lower level driver code only does the first 64 mailbox words. |
| 3926 | */ |
| 3927 | if ((!bsg_bf_get(lpfc_mbox_hdr_emb, |
| 3928 | &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) && |
| 3929 | (nemb_tp == nemb_mse)) |
| 3930 | lpfc_sli_pcimem_bcopy(&pmbx[sizeof(MAILBOX_t)], |
| 3931 | &pmbx[sizeof(MAILBOX_t)], |
| 3932 | sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 3933 | mse[0].buf_len); |
| 3934 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3935 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 3936 | if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) { |
| 3937 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 3938 | "2947 Issued SLI_CONFIG ext-buffer " |
| 3939 | "maibox command, rc:x%x\n", rc); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 3940 | return SLI_CONFIG_HANDLED; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3941 | } |
| 3942 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 3943 | "2948 Failed to issue SLI_CONFIG ext-buffer " |
| 3944 | "maibox command, rc:x%x\n", rc); |
| 3945 | rc = -EPIPE; |
| 3946 | |
| 3947 | job_error: |
| 3948 | if (pmboxq) |
| 3949 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 3950 | lpfc_bsg_dma_page_list_free(phba, |
| 3951 | &phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 3952 | kfree(dd_data); |
| 3953 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_IDLE; |
| 3954 | return rc; |
| 3955 | } |
| 3956 | |
| 3957 | /** |
| 3958 | * lpfc_bsg_sli_cfg_write_cmd_ext - sli_config non-embedded mailbox cmd write |
| 3959 | * @phba: Pointer to HBA context object. |
| 3960 | * @mb: Pointer to a BSG mailbox object. |
| 3961 | * @dmabuff: Pointer to a DMA buffer descriptor. |
| 3962 | * |
| 3963 | * This routine performs SLI_CONFIG (0x9B) write mailbox command operation with |
| 3964 | * non-embedded external bufffers. |
| 3965 | **/ |
| 3966 | static int |
| 3967 | lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba *phba, struct fc_bsg_job *job, |
| 3968 | enum nemb_type nemb_tp, |
| 3969 | struct lpfc_dmabuf *dmabuf) |
| 3970 | { |
| 3971 | struct dfc_mbox_req *mbox_req; |
| 3972 | struct lpfc_sli_config_mbox *sli_cfg_mbx; |
| 3973 | uint32_t ext_buf_cnt; |
| 3974 | struct bsg_job_data *dd_data = NULL; |
| 3975 | LPFC_MBOXQ_t *pmboxq = NULL; |
| 3976 | MAILBOX_t *pmb; |
| 3977 | uint8_t *mbx; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 3978 | int rc = SLI_CONFIG_NOT_HANDLED, i; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3979 | |
| 3980 | mbox_req = |
| 3981 | (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd; |
| 3982 | |
| 3983 | /* pointer to the start of mailbox command */ |
| 3984 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt; |
| 3985 | |
| 3986 | if (nemb_tp == nemb_mse) { |
| 3987 | ext_buf_cnt = bsg_bf_get(lpfc_mbox_hdr_mse_cnt, |
| 3988 | &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr); |
| 3989 | if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_MSE) { |
| 3990 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 3991 | "2953 Failed SLI_CONFIG(mse) wr, " |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 3992 | "ext_buf_cnt(%d) out of range(%d)\n", |
| 3993 | ext_buf_cnt, |
| 3994 | LPFC_MBX_SLI_CONFIG_MAX_MSE); |
| 3995 | return -ERANGE; |
| 3996 | } |
| 3997 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 3998 | "2949 Handled SLI_CONFIG(mse) wr, " |
| 3999 | "ext_buf_cnt:%d\n", ext_buf_cnt); |
| 4000 | } else { |
| 4001 | /* sanity check on interface type for support */ |
| 4002 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 4003 | LPFC_SLI_INTF_IF_TYPE_2) |
| 4004 | return -ENODEV; |
| 4005 | /* nemb_tp == nemb_hbd */ |
| 4006 | ext_buf_cnt = sli_cfg_mbx->un.sli_config_emb1_subsys.hbd_count; |
| 4007 | if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_HBD) { |
| 4008 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4009 | "2954 Failed SLI_CONFIG(hbd) wr, " |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4010 | "ext_buf_cnt(%d) out of range(%d)\n", |
| 4011 | ext_buf_cnt, |
| 4012 | LPFC_MBX_SLI_CONFIG_MAX_HBD); |
| 4013 | return -ERANGE; |
| 4014 | } |
| 4015 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4016 | "2950 Handled SLI_CONFIG(hbd) wr, " |
| 4017 | "ext_buf_cnt:%d\n", ext_buf_cnt); |
| 4018 | } |
| 4019 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4020 | /* before dma buffer descriptor setup */ |
| 4021 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_wr, dma_mbox, |
| 4022 | sta_pre_addr, dmabuf, ext_buf_cnt); |
| 4023 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4024 | if (ext_buf_cnt == 0) |
| 4025 | return -EPERM; |
| 4026 | |
| 4027 | /* for the first external buffer */ |
| 4028 | lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, 0, dmabuf, dmabuf); |
| 4029 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4030 | /* after dma descriptor setup */ |
| 4031 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, nemb_tp, mbox_wr, dma_mbox, |
| 4032 | sta_pos_addr, dmabuf, ext_buf_cnt); |
| 4033 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4034 | /* log for looking forward */ |
| 4035 | for (i = 1; i < ext_buf_cnt; i++) { |
| 4036 | if (nemb_tp == nemb_mse) |
| 4037 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4038 | "2951 SLI_CONFIG(mse), buf[%d]-length:%d\n", |
| 4039 | i, sli_cfg_mbx->un.sli_config_emb0_subsys. |
| 4040 | mse[i].buf_len); |
| 4041 | else |
| 4042 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4043 | "2952 SLI_CONFIG(hbd), buf[%d]-length:%d\n", |
| 4044 | i, bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len, |
| 4045 | &sli_cfg_mbx->un.sli_config_emb1_subsys. |
| 4046 | hbd[i])); |
| 4047 | } |
| 4048 | |
| 4049 | /* multi-buffer handling context */ |
| 4050 | phba->mbox_ext_buf_ctx.nembType = nemb_tp; |
| 4051 | phba->mbox_ext_buf_ctx.mboxType = mbox_wr; |
| 4052 | phba->mbox_ext_buf_ctx.numBuf = ext_buf_cnt; |
| 4053 | phba->mbox_ext_buf_ctx.mbxTag = mbox_req->extMboxTag; |
| 4054 | phba->mbox_ext_buf_ctx.seqNum = mbox_req->extSeqNum; |
| 4055 | phba->mbox_ext_buf_ctx.mbx_dmabuf = dmabuf; |
| 4056 | |
| 4057 | if (ext_buf_cnt == 1) { |
| 4058 | /* bsg tracking structure */ |
| 4059 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); |
| 4060 | if (!dd_data) { |
| 4061 | rc = -ENOMEM; |
| 4062 | goto job_error; |
| 4063 | } |
| 4064 | |
| 4065 | /* mailbox command structure for base driver */ |
| 4066 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4067 | if (!pmboxq) { |
| 4068 | rc = -ENOMEM; |
| 4069 | goto job_error; |
| 4070 | } |
| 4071 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 4072 | pmb = &pmboxq->u.mb; |
| 4073 | mbx = (uint8_t *)dmabuf->virt; |
| 4074 | memcpy(pmb, mbx, sizeof(*pmb)); |
| 4075 | pmb->mbxOwner = OWN_HOST; |
| 4076 | pmboxq->vport = phba->pport; |
| 4077 | |
| 4078 | /* callback for multi-buffer read mailbox command */ |
| 4079 | pmboxq->mbox_cmpl = lpfc_bsg_issue_write_mbox_ext_cmpl; |
| 4080 | |
| 4081 | /* context fields to callback function */ |
| 4082 | pmboxq->context1 = dd_data; |
| 4083 | dd_data->type = TYPE_MBOX; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 4084 | dd_data->set_job = job; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4085 | dd_data->context_un.mbox.pmboxq = pmboxq; |
| 4086 | dd_data->context_un.mbox.mb = (MAILBOX_t *)mbx; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4087 | job->dd_data = dd_data; |
| 4088 | |
| 4089 | /* state change */ |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4090 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 4091 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4092 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 4093 | if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) { |
| 4094 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4095 | "2955 Issued SLI_CONFIG ext-buffer " |
| 4096 | "maibox command, rc:x%x\n", rc); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4097 | return SLI_CONFIG_HANDLED; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4098 | } |
| 4099 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 4100 | "2956 Failed to issue SLI_CONFIG ext-buffer " |
| 4101 | "maibox command, rc:x%x\n", rc); |
| 4102 | rc = -EPIPE; |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4103 | goto job_error; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4104 | } |
| 4105 | |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4106 | /* wait for additoinal external buffers */ |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 4107 | |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4108 | job->reply->result = 0; |
| 4109 | job->job_done(job); |
| 4110 | return SLI_CONFIG_HANDLED; |
| 4111 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4112 | job_error: |
| 4113 | if (pmboxq) |
| 4114 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 4115 | kfree(dd_data); |
| 4116 | |
| 4117 | return rc; |
| 4118 | } |
| 4119 | |
| 4120 | /** |
| 4121 | * lpfc_bsg_handle_sli_cfg_mbox - handle sli-cfg mailbox cmd with ext buffer |
| 4122 | * @phba: Pointer to HBA context object. |
| 4123 | * @mb: Pointer to a BSG mailbox object. |
| 4124 | * @dmabuff: Pointer to a DMA buffer descriptor. |
| 4125 | * |
| 4126 | * This routine handles SLI_CONFIG (0x9B) mailbox command with non-embedded |
| 4127 | * external bufffers, including both 0x9B with non-embedded MSEs and 0x9B |
| 4128 | * with embedded sussystem 0x1 and opcodes with external HBDs. |
| 4129 | **/ |
| 4130 | static int |
| 4131 | lpfc_bsg_handle_sli_cfg_mbox(struct lpfc_hba *phba, struct fc_bsg_job *job, |
| 4132 | struct lpfc_dmabuf *dmabuf) |
| 4133 | { |
| 4134 | struct lpfc_sli_config_mbox *sli_cfg_mbx; |
| 4135 | uint32_t subsys; |
| 4136 | uint32_t opcode; |
| 4137 | int rc = SLI_CONFIG_NOT_HANDLED; |
| 4138 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4139 | /* state change on new multi-buffer pass-through mailbox command */ |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4140 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_HOST; |
| 4141 | |
| 4142 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt; |
| 4143 | |
| 4144 | if (!bsg_bf_get(lpfc_mbox_hdr_emb, |
| 4145 | &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) { |
| 4146 | subsys = bsg_bf_get(lpfc_emb0_subcmnd_subsys, |
| 4147 | &sli_cfg_mbx->un.sli_config_emb0_subsys); |
| 4148 | opcode = bsg_bf_get(lpfc_emb0_subcmnd_opcode, |
| 4149 | &sli_cfg_mbx->un.sli_config_emb0_subsys); |
| 4150 | if (subsys == SLI_CONFIG_SUBSYS_FCOE) { |
| 4151 | switch (opcode) { |
| 4152 | case FCOE_OPCODE_READ_FCF: |
James Smart | 2a2719d | 2014-02-20 09:56:28 -0500 | [diff] [blame] | 4153 | case FCOE_OPCODE_GET_DPORT_RESULTS: |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4154 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4155 | "2957 Handled SLI_CONFIG " |
| 4156 | "subsys_fcoe, opcode:x%x\n", |
| 4157 | opcode); |
| 4158 | rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job, |
| 4159 | nemb_mse, dmabuf); |
| 4160 | break; |
| 4161 | case FCOE_OPCODE_ADD_FCF: |
James Smart | 2a2719d | 2014-02-20 09:56:28 -0500 | [diff] [blame] | 4162 | case FCOE_OPCODE_SET_DPORT_MODE: |
| 4163 | case LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE: |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4164 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4165 | "2958 Handled SLI_CONFIG " |
| 4166 | "subsys_fcoe, opcode:x%x\n", |
| 4167 | opcode); |
| 4168 | rc = lpfc_bsg_sli_cfg_write_cmd_ext(phba, job, |
| 4169 | nemb_mse, dmabuf); |
| 4170 | break; |
| 4171 | default: |
| 4172 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4173 | "2959 Reject SLI_CONFIG " |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4174 | "subsys_fcoe, opcode:x%x\n", |
| 4175 | opcode); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4176 | rc = -EPERM; |
| 4177 | break; |
| 4178 | } |
| 4179 | } else if (subsys == SLI_CONFIG_SUBSYS_COMN) { |
| 4180 | switch (opcode) { |
| 4181 | case COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES: |
James Smart | b99570d | 2012-05-09 21:16:24 -0400 | [diff] [blame] | 4182 | case COMN_OPCODE_GET_CNTL_ATTRIBUTES: |
James Smart | c637797 | 2015-04-07 15:07:10 -0400 | [diff] [blame] | 4183 | case COMN_OPCODE_GET_PROFILE_CONFIG: |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4184 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4185 | "3106 Handled SLI_CONFIG " |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 4186 | "subsys_comn, opcode:x%x\n", |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4187 | opcode); |
| 4188 | rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job, |
| 4189 | nemb_mse, dmabuf); |
| 4190 | break; |
| 4191 | default: |
| 4192 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4193 | "3107 Reject SLI_CONFIG " |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 4194 | "subsys_comn, opcode:x%x\n", |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4195 | opcode); |
| 4196 | rc = -EPERM; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4197 | break; |
| 4198 | } |
| 4199 | } else { |
| 4200 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4201 | "2977 Reject SLI_CONFIG " |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4202 | "subsys:x%d, opcode:x%x\n", |
| 4203 | subsys, opcode); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4204 | rc = -EPERM; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4205 | } |
| 4206 | } else { |
| 4207 | subsys = bsg_bf_get(lpfc_emb1_subcmnd_subsys, |
| 4208 | &sli_cfg_mbx->un.sli_config_emb1_subsys); |
| 4209 | opcode = bsg_bf_get(lpfc_emb1_subcmnd_opcode, |
| 4210 | &sli_cfg_mbx->un.sli_config_emb1_subsys); |
| 4211 | if (subsys == SLI_CONFIG_SUBSYS_COMN) { |
| 4212 | switch (opcode) { |
| 4213 | case COMN_OPCODE_READ_OBJECT: |
| 4214 | case COMN_OPCODE_READ_OBJECT_LIST: |
| 4215 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4216 | "2960 Handled SLI_CONFIG " |
| 4217 | "subsys_comn, opcode:x%x\n", |
| 4218 | opcode); |
| 4219 | rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job, |
| 4220 | nemb_hbd, dmabuf); |
| 4221 | break; |
| 4222 | case COMN_OPCODE_WRITE_OBJECT: |
| 4223 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4224 | "2961 Handled SLI_CONFIG " |
| 4225 | "subsys_comn, opcode:x%x\n", |
| 4226 | opcode); |
| 4227 | rc = lpfc_bsg_sli_cfg_write_cmd_ext(phba, job, |
| 4228 | nemb_hbd, dmabuf); |
| 4229 | break; |
| 4230 | default: |
| 4231 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4232 | "2962 Not handled SLI_CONFIG " |
| 4233 | "subsys_comn, opcode:x%x\n", |
| 4234 | opcode); |
| 4235 | rc = SLI_CONFIG_NOT_HANDLED; |
| 4236 | break; |
| 4237 | } |
| 4238 | } else { |
| 4239 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4240 | "2978 Not handled SLI_CONFIG " |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4241 | "subsys:x%d, opcode:x%x\n", |
| 4242 | subsys, opcode); |
| 4243 | rc = SLI_CONFIG_NOT_HANDLED; |
| 4244 | } |
| 4245 | } |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4246 | |
| 4247 | /* state reset on not handled new multi-buffer mailbox command */ |
| 4248 | if (rc != SLI_CONFIG_HANDLED) |
| 4249 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_IDLE; |
| 4250 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4251 | return rc; |
| 4252 | } |
| 4253 | |
| 4254 | /** |
| 4255 | * lpfc_bsg_mbox_ext_abort_req - request to abort mbox command with ext buffers |
| 4256 | * @phba: Pointer to HBA context object. |
| 4257 | * |
| 4258 | * This routine is for requesting to abort a pass-through mailbox command with |
| 4259 | * multiple external buffers due to error condition. |
| 4260 | **/ |
| 4261 | static void |
| 4262 | lpfc_bsg_mbox_ext_abort(struct lpfc_hba *phba) |
| 4263 | { |
| 4264 | if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_PORT) |
| 4265 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_ABTS; |
| 4266 | else |
| 4267 | lpfc_bsg_mbox_ext_session_reset(phba); |
| 4268 | return; |
| 4269 | } |
| 4270 | |
| 4271 | /** |
| 4272 | * lpfc_bsg_read_ebuf_get - get the next mailbox read external buffer |
| 4273 | * @phba: Pointer to HBA context object. |
| 4274 | * @dmabuf: Pointer to a DMA buffer descriptor. |
| 4275 | * |
| 4276 | * This routine extracts the next mailbox read external buffer back to |
| 4277 | * user space through BSG. |
| 4278 | **/ |
| 4279 | static int |
| 4280 | lpfc_bsg_read_ebuf_get(struct lpfc_hba *phba, struct fc_bsg_job *job) |
| 4281 | { |
| 4282 | struct lpfc_sli_config_mbox *sli_cfg_mbx; |
| 4283 | struct lpfc_dmabuf *dmabuf; |
| 4284 | uint8_t *pbuf; |
| 4285 | uint32_t size; |
| 4286 | uint32_t index; |
| 4287 | |
| 4288 | index = phba->mbox_ext_buf_ctx.seqNum; |
| 4289 | phba->mbox_ext_buf_ctx.seqNum++; |
| 4290 | |
| 4291 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *) |
| 4292 | phba->mbox_ext_buf_ctx.mbx_dmabuf->virt; |
| 4293 | |
| 4294 | if (phba->mbox_ext_buf_ctx.nembType == nemb_mse) { |
| 4295 | size = bsg_bf_get(lpfc_mbox_sli_config_mse_len, |
| 4296 | &sli_cfg_mbx->un.sli_config_emb0_subsys.mse[index]); |
| 4297 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4298 | "2963 SLI_CONFIG (mse) ext-buffer rd get " |
| 4299 | "buffer[%d], size:%d\n", index, size); |
| 4300 | } else { |
| 4301 | size = bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len, |
| 4302 | &sli_cfg_mbx->un.sli_config_emb1_subsys.hbd[index]); |
| 4303 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4304 | "2964 SLI_CONFIG (hbd) ext-buffer rd get " |
| 4305 | "buffer[%d], size:%d\n", index, size); |
| 4306 | } |
| 4307 | if (list_empty(&phba->mbox_ext_buf_ctx.ext_dmabuf_list)) |
| 4308 | return -EPIPE; |
| 4309 | dmabuf = list_first_entry(&phba->mbox_ext_buf_ctx.ext_dmabuf_list, |
| 4310 | struct lpfc_dmabuf, list); |
| 4311 | list_del_init(&dmabuf->list); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4312 | |
| 4313 | /* after dma buffer descriptor setup */ |
| 4314 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, phba->mbox_ext_buf_ctx.nembType, |
| 4315 | mbox_rd, dma_ebuf, sta_pos_addr, |
| 4316 | dmabuf, index); |
| 4317 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4318 | pbuf = (uint8_t *)dmabuf->virt; |
| 4319 | job->reply->reply_payload_rcv_len = |
| 4320 | sg_copy_from_buffer(job->reply_payload.sg_list, |
| 4321 | job->reply_payload.sg_cnt, |
| 4322 | pbuf, size); |
| 4323 | |
| 4324 | lpfc_bsg_dma_page_free(phba, dmabuf); |
| 4325 | |
| 4326 | if (phba->mbox_ext_buf_ctx.seqNum == phba->mbox_ext_buf_ctx.numBuf) { |
| 4327 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4328 | "2965 SLI_CONFIG (hbd) ext-buffer rd mbox " |
| 4329 | "command session done\n"); |
| 4330 | lpfc_bsg_mbox_ext_session_reset(phba); |
| 4331 | } |
| 4332 | |
| 4333 | job->reply->result = 0; |
| 4334 | job->job_done(job); |
| 4335 | |
| 4336 | return SLI_CONFIG_HANDLED; |
| 4337 | } |
| 4338 | |
| 4339 | /** |
| 4340 | * lpfc_bsg_write_ebuf_set - set the next mailbox write external buffer |
| 4341 | * @phba: Pointer to HBA context object. |
| 4342 | * @dmabuf: Pointer to a DMA buffer descriptor. |
| 4343 | * |
| 4344 | * This routine sets up the next mailbox read external buffer obtained |
| 4345 | * from user space through BSG. |
| 4346 | **/ |
| 4347 | static int |
| 4348 | lpfc_bsg_write_ebuf_set(struct lpfc_hba *phba, struct fc_bsg_job *job, |
| 4349 | struct lpfc_dmabuf *dmabuf) |
| 4350 | { |
| 4351 | struct lpfc_sli_config_mbox *sli_cfg_mbx; |
| 4352 | struct bsg_job_data *dd_data = NULL; |
| 4353 | LPFC_MBOXQ_t *pmboxq = NULL; |
| 4354 | MAILBOX_t *pmb; |
| 4355 | enum nemb_type nemb_tp; |
| 4356 | uint8_t *pbuf; |
| 4357 | uint32_t size; |
| 4358 | uint32_t index; |
| 4359 | int rc; |
| 4360 | |
| 4361 | index = phba->mbox_ext_buf_ctx.seqNum; |
| 4362 | phba->mbox_ext_buf_ctx.seqNum++; |
| 4363 | nemb_tp = phba->mbox_ext_buf_ctx.nembType; |
| 4364 | |
| 4365 | sli_cfg_mbx = (struct lpfc_sli_config_mbox *) |
| 4366 | phba->mbox_ext_buf_ctx.mbx_dmabuf->virt; |
| 4367 | |
| 4368 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); |
| 4369 | if (!dd_data) { |
| 4370 | rc = -ENOMEM; |
| 4371 | goto job_error; |
| 4372 | } |
| 4373 | |
| 4374 | pbuf = (uint8_t *)dmabuf->virt; |
| 4375 | size = job->request_payload.payload_len; |
| 4376 | sg_copy_to_buffer(job->request_payload.sg_list, |
| 4377 | job->request_payload.sg_cnt, |
| 4378 | pbuf, size); |
| 4379 | |
| 4380 | if (phba->mbox_ext_buf_ctx.nembType == nemb_mse) { |
| 4381 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4382 | "2966 SLI_CONFIG (mse) ext-buffer wr set " |
| 4383 | "buffer[%d], size:%d\n", |
| 4384 | phba->mbox_ext_buf_ctx.seqNum, size); |
| 4385 | |
| 4386 | } else { |
| 4387 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4388 | "2967 SLI_CONFIG (hbd) ext-buffer wr set " |
| 4389 | "buffer[%d], size:%d\n", |
| 4390 | phba->mbox_ext_buf_ctx.seqNum, size); |
| 4391 | |
| 4392 | } |
| 4393 | |
| 4394 | /* set up external buffer descriptor and add to external buffer list */ |
| 4395 | lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, index, |
| 4396 | phba->mbox_ext_buf_ctx.mbx_dmabuf, |
| 4397 | dmabuf); |
| 4398 | list_add_tail(&dmabuf->list, &phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 4399 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4400 | /* after write dma buffer */ |
| 4401 | lpfc_idiag_mbxacc_dump_bsg_mbox(phba, phba->mbox_ext_buf_ctx.nembType, |
| 4402 | mbox_wr, dma_ebuf, sta_pos_addr, |
| 4403 | dmabuf, index); |
| 4404 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4405 | if (phba->mbox_ext_buf_ctx.seqNum == phba->mbox_ext_buf_ctx.numBuf) { |
| 4406 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4407 | "2968 SLI_CONFIG ext-buffer wr all %d " |
| 4408 | "ebuffers received\n", |
| 4409 | phba->mbox_ext_buf_ctx.numBuf); |
| 4410 | /* mailbox command structure for base driver */ |
| 4411 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4412 | if (!pmboxq) { |
| 4413 | rc = -ENOMEM; |
| 4414 | goto job_error; |
| 4415 | } |
| 4416 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 4417 | pbuf = (uint8_t *)phba->mbox_ext_buf_ctx.mbx_dmabuf->virt; |
| 4418 | pmb = &pmboxq->u.mb; |
| 4419 | memcpy(pmb, pbuf, sizeof(*pmb)); |
| 4420 | pmb->mbxOwner = OWN_HOST; |
| 4421 | pmboxq->vport = phba->pport; |
| 4422 | |
| 4423 | /* callback for multi-buffer write mailbox command */ |
| 4424 | pmboxq->mbox_cmpl = lpfc_bsg_issue_write_mbox_ext_cmpl; |
| 4425 | |
| 4426 | /* context fields to callback function */ |
| 4427 | pmboxq->context1 = dd_data; |
| 4428 | dd_data->type = TYPE_MBOX; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 4429 | dd_data->set_job = job; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4430 | dd_data->context_un.mbox.pmboxq = pmboxq; |
| 4431 | dd_data->context_un.mbox.mb = (MAILBOX_t *)pbuf; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4432 | job->dd_data = dd_data; |
| 4433 | |
| 4434 | /* state change */ |
| 4435 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT; |
| 4436 | |
| 4437 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 4438 | if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) { |
| 4439 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4440 | "2969 Issued SLI_CONFIG ext-buffer " |
| 4441 | "maibox command, rc:x%x\n", rc); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4442 | return SLI_CONFIG_HANDLED; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4443 | } |
| 4444 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 4445 | "2970 Failed to issue SLI_CONFIG ext-buffer " |
| 4446 | "maibox command, rc:x%x\n", rc); |
| 4447 | rc = -EPIPE; |
| 4448 | goto job_error; |
| 4449 | } |
| 4450 | |
| 4451 | /* wait for additoinal external buffers */ |
| 4452 | job->reply->result = 0; |
| 4453 | job->job_done(job); |
| 4454 | return SLI_CONFIG_HANDLED; |
| 4455 | |
| 4456 | job_error: |
| 4457 | lpfc_bsg_dma_page_free(phba, dmabuf); |
| 4458 | kfree(dd_data); |
| 4459 | |
| 4460 | return rc; |
| 4461 | } |
| 4462 | |
| 4463 | /** |
| 4464 | * lpfc_bsg_handle_sli_cfg_ebuf - handle ext buffer with sli-cfg mailbox cmd |
| 4465 | * @phba: Pointer to HBA context object. |
| 4466 | * @mb: Pointer to a BSG mailbox object. |
| 4467 | * @dmabuff: Pointer to a DMA buffer descriptor. |
| 4468 | * |
| 4469 | * This routine handles the external buffer with SLI_CONFIG (0x9B) mailbox |
| 4470 | * command with multiple non-embedded external buffers. |
| 4471 | **/ |
| 4472 | static int |
| 4473 | lpfc_bsg_handle_sli_cfg_ebuf(struct lpfc_hba *phba, struct fc_bsg_job *job, |
| 4474 | struct lpfc_dmabuf *dmabuf) |
| 4475 | { |
| 4476 | int rc; |
| 4477 | |
| 4478 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4479 | "2971 SLI_CONFIG buffer (type:x%x)\n", |
| 4480 | phba->mbox_ext_buf_ctx.mboxType); |
| 4481 | |
| 4482 | if (phba->mbox_ext_buf_ctx.mboxType == mbox_rd) { |
| 4483 | if (phba->mbox_ext_buf_ctx.state != LPFC_BSG_MBOX_DONE) { |
| 4484 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 4485 | "2972 SLI_CONFIG rd buffer state " |
| 4486 | "mismatch:x%x\n", |
| 4487 | phba->mbox_ext_buf_ctx.state); |
| 4488 | lpfc_bsg_mbox_ext_abort(phba); |
| 4489 | return -EPIPE; |
| 4490 | } |
| 4491 | rc = lpfc_bsg_read_ebuf_get(phba, job); |
| 4492 | if (rc == SLI_CONFIG_HANDLED) |
| 4493 | lpfc_bsg_dma_page_free(phba, dmabuf); |
| 4494 | } else { /* phba->mbox_ext_buf_ctx.mboxType == mbox_wr */ |
| 4495 | if (phba->mbox_ext_buf_ctx.state != LPFC_BSG_MBOX_HOST) { |
| 4496 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 4497 | "2973 SLI_CONFIG wr buffer state " |
| 4498 | "mismatch:x%x\n", |
| 4499 | phba->mbox_ext_buf_ctx.state); |
| 4500 | lpfc_bsg_mbox_ext_abort(phba); |
| 4501 | return -EPIPE; |
| 4502 | } |
| 4503 | rc = lpfc_bsg_write_ebuf_set(phba, job, dmabuf); |
| 4504 | } |
| 4505 | return rc; |
| 4506 | } |
| 4507 | |
| 4508 | /** |
| 4509 | * lpfc_bsg_handle_sli_cfg_ext - handle sli-cfg mailbox with external buffer |
| 4510 | * @phba: Pointer to HBA context object. |
| 4511 | * @mb: Pointer to a BSG mailbox object. |
| 4512 | * @dmabuff: Pointer to a DMA buffer descriptor. |
| 4513 | * |
| 4514 | * This routine checkes and handles non-embedded multi-buffer SLI_CONFIG |
| 4515 | * (0x9B) mailbox commands and external buffers. |
| 4516 | **/ |
| 4517 | static int |
| 4518 | lpfc_bsg_handle_sli_cfg_ext(struct lpfc_hba *phba, struct fc_bsg_job *job, |
| 4519 | struct lpfc_dmabuf *dmabuf) |
| 4520 | { |
| 4521 | struct dfc_mbox_req *mbox_req; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4522 | int rc = SLI_CONFIG_NOT_HANDLED; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4523 | |
| 4524 | mbox_req = |
| 4525 | (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd; |
| 4526 | |
| 4527 | /* mbox command with/without single external buffer */ |
| 4528 | if (mbox_req->extMboxTag == 0 && mbox_req->extSeqNum == 0) |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4529 | return rc; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4530 | |
| 4531 | /* mbox command and first external buffer */ |
| 4532 | if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_IDLE) { |
| 4533 | if (mbox_req->extSeqNum == 1) { |
| 4534 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4535 | "2974 SLI_CONFIG mailbox: tag:%d, " |
| 4536 | "seq:%d\n", mbox_req->extMboxTag, |
| 4537 | mbox_req->extSeqNum); |
| 4538 | rc = lpfc_bsg_handle_sli_cfg_mbox(phba, job, dmabuf); |
| 4539 | return rc; |
| 4540 | } else |
| 4541 | goto sli_cfg_ext_error; |
| 4542 | } |
| 4543 | |
| 4544 | /* |
| 4545 | * handle additional external buffers |
| 4546 | */ |
| 4547 | |
| 4548 | /* check broken pipe conditions */ |
| 4549 | if (mbox_req->extMboxTag != phba->mbox_ext_buf_ctx.mbxTag) |
| 4550 | goto sli_cfg_ext_error; |
| 4551 | if (mbox_req->extSeqNum > phba->mbox_ext_buf_ctx.numBuf) |
| 4552 | goto sli_cfg_ext_error; |
| 4553 | if (mbox_req->extSeqNum != phba->mbox_ext_buf_ctx.seqNum + 1) |
| 4554 | goto sli_cfg_ext_error; |
| 4555 | |
| 4556 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
| 4557 | "2975 SLI_CONFIG mailbox external buffer: " |
| 4558 | "extSta:x%x, tag:%d, seq:%d\n", |
| 4559 | phba->mbox_ext_buf_ctx.state, mbox_req->extMboxTag, |
| 4560 | mbox_req->extSeqNum); |
| 4561 | rc = lpfc_bsg_handle_sli_cfg_ebuf(phba, job, dmabuf); |
| 4562 | return rc; |
| 4563 | |
| 4564 | sli_cfg_ext_error: |
| 4565 | /* all other cases, broken pipe */ |
| 4566 | lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC, |
| 4567 | "2976 SLI_CONFIG mailbox broken pipe: " |
| 4568 | "ctxSta:x%x, ctxNumBuf:%d " |
| 4569 | "ctxTag:%d, ctxSeq:%d, tag:%d, seq:%d\n", |
| 4570 | phba->mbox_ext_buf_ctx.state, |
| 4571 | phba->mbox_ext_buf_ctx.numBuf, |
| 4572 | phba->mbox_ext_buf_ctx.mbxTag, |
| 4573 | phba->mbox_ext_buf_ctx.seqNum, |
| 4574 | mbox_req->extMboxTag, mbox_req->extSeqNum); |
| 4575 | |
| 4576 | lpfc_bsg_mbox_ext_session_reset(phba); |
| 4577 | |
| 4578 | return -EPIPE; |
| 4579 | } |
| 4580 | |
| 4581 | /** |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4582 | * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app |
| 4583 | * @phba: Pointer to HBA context object. |
| 4584 | * @mb: Pointer to a mailbox object. |
| 4585 | * @vport: Pointer to a vport object. |
| 4586 | * |
| 4587 | * Allocate a tracking object, mailbox command memory, get a mailbox |
| 4588 | * from the mailbox pool, copy the caller mailbox command. |
| 4589 | * |
| 4590 | * If offline and the sli is active we need to poll for the command (port is |
| 4591 | * being reset) and com-plete the job, otherwise issue the mailbox command and |
| 4592 | * let our completion handler finish the command. |
| 4593 | **/ |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 4594 | static int |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4595 | lpfc_bsg_issue_mbox(struct lpfc_hba *phba, struct fc_bsg_job *job, |
| 4596 | struct lpfc_vport *vport) |
| 4597 | { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4598 | LPFC_MBOXQ_t *pmboxq = NULL; /* internal mailbox queue */ |
| 4599 | MAILBOX_t *pmb; /* shortcut to the pmboxq mailbox */ |
| 4600 | /* a 4k buffer to hold the mb and extended data from/to the bsg */ |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4601 | uint8_t *pmbx = NULL; |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4602 | struct bsg_job_data *dd_data = NULL; /* bsg data tracking structure */ |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4603 | struct lpfc_dmabuf *dmabuf = NULL; |
| 4604 | struct dfc_mbox_req *mbox_req; |
James Smart | b6e3b9c | 2011-04-16 11:03:43 -0400 | [diff] [blame] | 4605 | struct READ_EVENT_LOG_VAR *rdEventLog; |
| 4606 | uint32_t transmit_length, receive_length, mode; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4607 | struct lpfc_mbx_sli4_config *sli4_config; |
James Smart | b6e3b9c | 2011-04-16 11:03:43 -0400 | [diff] [blame] | 4608 | struct lpfc_mbx_nembed_cmd *nembed_sge; |
| 4609 | struct mbox_header *header; |
| 4610 | struct ulp_bde64 *bde; |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4611 | uint8_t *ext = NULL; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4612 | int rc = 0; |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4613 | uint8_t *from; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4614 | uint32_t size; |
| 4615 | |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4616 | /* in case no data is transferred */ |
| 4617 | job->reply->reply_payload_rcv_len = 0; |
| 4618 | |
James Smart | b6e3b9c | 2011-04-16 11:03:43 -0400 | [diff] [blame] | 4619 | /* sanity check to protect driver */ |
| 4620 | if (job->reply_payload.payload_len > BSG_MBOX_SIZE || |
| 4621 | job->request_payload.payload_len > BSG_MBOX_SIZE) { |
| 4622 | rc = -ERANGE; |
| 4623 | goto job_done; |
| 4624 | } |
| 4625 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4626 | /* |
| 4627 | * Don't allow mailbox commands to be sent when blocked or when in |
| 4628 | * the middle of discovery |
| 4629 | */ |
| 4630 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) { |
| 4631 | rc = -EAGAIN; |
| 4632 | goto job_done; |
| 4633 | } |
| 4634 | |
| 4635 | mbox_req = |
| 4636 | (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd; |
| 4637 | |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4638 | /* check if requested extended data lengths are valid */ |
James Smart | b6e3b9c | 2011-04-16 11:03:43 -0400 | [diff] [blame] | 4639 | if ((mbox_req->inExtWLen > BSG_MBOX_SIZE/sizeof(uint32_t)) || |
| 4640 | (mbox_req->outExtWLen > BSG_MBOX_SIZE/sizeof(uint32_t))) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4641 | rc = -ERANGE; |
| 4642 | goto job_done; |
| 4643 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4644 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4645 | dmabuf = lpfc_bsg_dma_page_alloc(phba); |
| 4646 | if (!dmabuf || !dmabuf->virt) { |
| 4647 | rc = -ENOMEM; |
| 4648 | goto job_done; |
| 4649 | } |
| 4650 | |
| 4651 | /* Get the mailbox command or external buffer from BSG */ |
| 4652 | pmbx = (uint8_t *)dmabuf->virt; |
| 4653 | size = job->request_payload.payload_len; |
| 4654 | sg_copy_to_buffer(job->request_payload.sg_list, |
| 4655 | job->request_payload.sg_cnt, pmbx, size); |
| 4656 | |
| 4657 | /* Handle possible SLI_CONFIG with non-embedded payloads */ |
| 4658 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4659 | rc = lpfc_bsg_handle_sli_cfg_ext(phba, job, dmabuf); |
| 4660 | if (rc == SLI_CONFIG_HANDLED) |
| 4661 | goto job_cont; |
| 4662 | if (rc) |
| 4663 | goto job_done; |
| 4664 | /* SLI_CONFIG_NOT_HANDLED for other mailbox commands */ |
| 4665 | } |
| 4666 | |
| 4667 | rc = lpfc_bsg_check_cmd_access(phba, (MAILBOX_t *)pmbx, vport); |
| 4668 | if (rc != 0) |
| 4669 | goto job_done; /* must be negative */ |
| 4670 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4671 | /* allocate our bsg tracking structure */ |
| 4672 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); |
| 4673 | if (!dd_data) { |
| 4674 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 4675 | "2727 Failed allocation of dd_data\n"); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4676 | rc = -ENOMEM; |
| 4677 | goto job_done; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4678 | } |
| 4679 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4680 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4681 | if (!pmboxq) { |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4682 | rc = -ENOMEM; |
| 4683 | goto job_done; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4684 | } |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4685 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4686 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4687 | pmb = &pmboxq->u.mb; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4688 | memcpy(pmb, pmbx, sizeof(*pmb)); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4689 | pmb->mbxOwner = OWN_HOST; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4690 | pmboxq->vport = vport; |
| 4691 | |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4692 | /* If HBA encountered an error attention, allow only DUMP |
| 4693 | * or RESTART mailbox commands until the HBA is restarted. |
| 4694 | */ |
| 4695 | if (phba->pport->stopped && |
| 4696 | pmb->mbxCommand != MBX_DUMP_MEMORY && |
| 4697 | pmb->mbxCommand != MBX_RESTART && |
| 4698 | pmb->mbxCommand != MBX_WRITE_VPARMS && |
| 4699 | pmb->mbxCommand != MBX_WRITE_WWN) |
| 4700 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 4701 | "2797 mbox: Issued mailbox cmd " |
| 4702 | "0x%x while in stopped state.\n", |
| 4703 | pmb->mbxCommand); |
| 4704 | |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4705 | /* extended mailbox commands will need an extended buffer */ |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4706 | if (mbox_req->inExtWLen || mbox_req->outExtWLen) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 4707 | from = pmbx; |
| 4708 | ext = from + sizeof(MAILBOX_t); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4709 | pmboxq->context2 = ext; |
| 4710 | pmboxq->in_ext_byte_len = |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4711 | mbox_req->inExtWLen * sizeof(uint32_t); |
| 4712 | pmboxq->out_ext_byte_len = |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4713 | mbox_req->outExtWLen * sizeof(uint32_t); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4714 | pmboxq->mbox_offset_word = mbox_req->mbOffset; |
| 4715 | } |
| 4716 | |
| 4717 | /* biu diag will need a kernel buffer to transfer the data |
| 4718 | * allocate our own buffer and setup the mailbox command to |
| 4719 | * use ours |
| 4720 | */ |
| 4721 | if (pmb->mbxCommand == MBX_RUN_BIU_DIAG64) { |
James Smart | b6e3b9c | 2011-04-16 11:03:43 -0400 | [diff] [blame] | 4722 | transmit_length = pmb->un.varWords[1]; |
| 4723 | receive_length = pmb->un.varWords[4]; |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4724 | /* transmit length cannot be greater than receive length or |
| 4725 | * mailbox extension size |
| 4726 | */ |
| 4727 | if ((transmit_length > receive_length) || |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4728 | (transmit_length > BSG_MBOX_SIZE - sizeof(MAILBOX_t))) { |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4729 | rc = -ERANGE; |
| 4730 | goto job_done; |
| 4731 | } |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4732 | pmb->un.varBIUdiag.un.s2.xmit_bde64.addrHigh = |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4733 | putPaddrHigh(dmabuf->phys + sizeof(MAILBOX_t)); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4734 | pmb->un.varBIUdiag.un.s2.xmit_bde64.addrLow = |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4735 | putPaddrLow(dmabuf->phys + sizeof(MAILBOX_t)); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4736 | |
| 4737 | pmb->un.varBIUdiag.un.s2.rcv_bde64.addrHigh = |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4738 | putPaddrHigh(dmabuf->phys + sizeof(MAILBOX_t) |
| 4739 | + pmb->un.varBIUdiag.un.s2.xmit_bde64.tus.f.bdeSize); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4740 | pmb->un.varBIUdiag.un.s2.rcv_bde64.addrLow = |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4741 | putPaddrLow(dmabuf->phys + sizeof(MAILBOX_t) |
| 4742 | + pmb->un.varBIUdiag.un.s2.xmit_bde64.tus.f.bdeSize); |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4743 | } else if (pmb->mbxCommand == MBX_READ_EVENT_LOG) { |
James Smart | b6e3b9c | 2011-04-16 11:03:43 -0400 | [diff] [blame] | 4744 | rdEventLog = &pmb->un.varRdEventLog; |
| 4745 | receive_length = rdEventLog->rcv_bde64.tus.f.bdeSize; |
| 4746 | mode = bf_get(lpfc_event_log, rdEventLog); |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4747 | |
| 4748 | /* receive length cannot be greater than mailbox |
| 4749 | * extension size |
| 4750 | */ |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4751 | if (receive_length > BSG_MBOX_SIZE - sizeof(MAILBOX_t)) { |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4752 | rc = -ERANGE; |
| 4753 | goto job_done; |
| 4754 | } |
| 4755 | |
| 4756 | /* mode zero uses a bde like biu diags command */ |
| 4757 | if (mode == 0) { |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4758 | pmb->un.varWords[3] = putPaddrLow(dmabuf->phys |
| 4759 | + sizeof(MAILBOX_t)); |
| 4760 | pmb->un.varWords[4] = putPaddrHigh(dmabuf->phys |
| 4761 | + sizeof(MAILBOX_t)); |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4762 | } |
| 4763 | } else if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 4764 | /* Let type 4 (well known data) through because the data is |
| 4765 | * returned in varwords[4-8] |
| 4766 | * otherwise check the recieve length and fetch the buffer addr |
| 4767 | */ |
| 4768 | if ((pmb->mbxCommand == MBX_DUMP_MEMORY) && |
| 4769 | (pmb->un.varDmp.type != DMP_WELL_KNOWN)) { |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4770 | /* rebuild the command for sli4 using our own buffers |
| 4771 | * like we do for biu diags |
| 4772 | */ |
James Smart | b6e3b9c | 2011-04-16 11:03:43 -0400 | [diff] [blame] | 4773 | receive_length = pmb->un.varWords[2]; |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4774 | /* receive length cannot be greater than mailbox |
| 4775 | * extension size |
| 4776 | */ |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4777 | if (receive_length == 0) { |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4778 | rc = -ERANGE; |
| 4779 | goto job_done; |
| 4780 | } |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4781 | pmb->un.varWords[3] = putPaddrLow(dmabuf->phys |
| 4782 | + sizeof(MAILBOX_t)); |
| 4783 | pmb->un.varWords[4] = putPaddrHigh(dmabuf->phys |
| 4784 | + sizeof(MAILBOX_t)); |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4785 | } else if ((pmb->mbxCommand == MBX_UPDATE_CFG) && |
| 4786 | pmb->un.varUpdateCfg.co) { |
James Smart | b6e3b9c | 2011-04-16 11:03:43 -0400 | [diff] [blame] | 4787 | bde = (struct ulp_bde64 *)&pmb->un.varWords[4]; |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4788 | |
| 4789 | /* bde size cannot be greater than mailbox ext size */ |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4790 | if (bde->tus.f.bdeSize > |
| 4791 | BSG_MBOX_SIZE - sizeof(MAILBOX_t)) { |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4792 | rc = -ERANGE; |
| 4793 | goto job_done; |
| 4794 | } |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4795 | bde->addrHigh = putPaddrHigh(dmabuf->phys |
| 4796 | + sizeof(MAILBOX_t)); |
| 4797 | bde->addrLow = putPaddrLow(dmabuf->phys |
| 4798 | + sizeof(MAILBOX_t)); |
James Smart | 515e0aa | 2010-09-29 11:19:00 -0400 | [diff] [blame] | 4799 | } else if (pmb->mbxCommand == MBX_SLI4_CONFIG) { |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4800 | /* Handling non-embedded SLI_CONFIG mailbox command */ |
| 4801 | sli4_config = &pmboxq->u.mqe.un.sli4_config; |
| 4802 | if (!bf_get(lpfc_mbox_hdr_emb, |
| 4803 | &sli4_config->header.cfg_mhdr)) { |
| 4804 | /* rebuild the command for sli4 using our |
| 4805 | * own buffers like we do for biu diags |
| 4806 | */ |
| 4807 | header = (struct mbox_header *) |
| 4808 | &pmb->un.varWords[0]; |
| 4809 | nembed_sge = (struct lpfc_mbx_nembed_cmd *) |
| 4810 | &pmb->un.varWords[0]; |
| 4811 | receive_length = nembed_sge->sge[0].length; |
James Smart | 515e0aa | 2010-09-29 11:19:00 -0400 | [diff] [blame] | 4812 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4813 | /* receive length cannot be greater than |
| 4814 | * mailbox extension size |
| 4815 | */ |
| 4816 | if ((receive_length == 0) || |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4817 | (receive_length > |
| 4818 | BSG_MBOX_SIZE - sizeof(MAILBOX_t))) { |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4819 | rc = -ERANGE; |
| 4820 | goto job_done; |
| 4821 | } |
| 4822 | |
| 4823 | nembed_sge->sge[0].pa_hi = |
| 4824 | putPaddrHigh(dmabuf->phys |
| 4825 | + sizeof(MAILBOX_t)); |
| 4826 | nembed_sge->sge[0].pa_lo = |
| 4827 | putPaddrLow(dmabuf->phys |
| 4828 | + sizeof(MAILBOX_t)); |
James Smart | 515e0aa | 2010-09-29 11:19:00 -0400 | [diff] [blame] | 4829 | } |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4830 | } |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4831 | } |
| 4832 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4833 | dd_data->context_un.mbox.dmabuffers = dmabuf; |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4834 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4835 | /* setup wake call as IOCB callback */ |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4836 | pmboxq->mbox_cmpl = lpfc_bsg_issue_mbox_cmpl; |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4837 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4838 | /* setup context field to pass wait_queue pointer to wake function */ |
| 4839 | pmboxq->context1 = dd_data; |
| 4840 | dd_data->type = TYPE_MBOX; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 4841 | dd_data->set_job = job; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4842 | dd_data->context_un.mbox.pmboxq = pmboxq; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4843 | dd_data->context_un.mbox.mb = (MAILBOX_t *)pmbx; |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4844 | dd_data->context_un.mbox.ext = ext; |
| 4845 | dd_data->context_un.mbox.mbOffset = mbox_req->mbOffset; |
| 4846 | dd_data->context_un.mbox.inExtWLen = mbox_req->inExtWLen; |
James Smart | c749593 | 2010-04-06 15:05:28 -0400 | [diff] [blame] | 4847 | dd_data->context_un.mbox.outExtWLen = mbox_req->outExtWLen; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4848 | job->dd_data = dd_data; |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4849 | |
| 4850 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
| 4851 | (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) { |
| 4852 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
| 4853 | if (rc != MBX_SUCCESS) { |
| 4854 | rc = (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; |
| 4855 | goto job_done; |
| 4856 | } |
| 4857 | |
| 4858 | /* job finished, copy the data */ |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4859 | memcpy(pmbx, pmb, sizeof(*pmb)); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4860 | job->reply->reply_payload_rcv_len = |
| 4861 | sg_copy_from_buffer(job->reply_payload.sg_list, |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4862 | job->reply_payload.sg_cnt, |
| 4863 | pmbx, size); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4864 | /* not waiting mbox already done */ |
| 4865 | rc = 0; |
| 4866 | goto job_done; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4867 | } |
| 4868 | |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4869 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 4870 | if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) |
| 4871 | return 1; /* job started */ |
| 4872 | |
| 4873 | job_done: |
| 4874 | /* common exit for error or job completed inline */ |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4875 | if (pmboxq) |
| 4876 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4877 | lpfc_bsg_dma_page_free(phba, dmabuf); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4878 | kfree(dd_data); |
| 4879 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4880 | job_cont: |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 4881 | return rc; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | /** |
| 4885 | * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command |
| 4886 | * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX. |
| 4887 | **/ |
| 4888 | static int |
| 4889 | lpfc_bsg_mbox_cmd(struct fc_bsg_job *job) |
| 4890 | { |
| 4891 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
| 4892 | struct lpfc_hba *phba = vport->phba; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4893 | struct dfc_mbox_req *mbox_req; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4894 | int rc = 0; |
| 4895 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4896 | /* mix-and-match backward compatibility */ |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4897 | job->reply->reply_payload_rcv_len = 0; |
| 4898 | if (job->request_len < |
| 4899 | sizeof(struct fc_bsg_request) + sizeof(struct dfc_mbox_req)) { |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4900 | lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC, |
Masanari Iida | 1051e9b | 2013-03-31 01:23:50 +0900 | [diff] [blame] | 4901 | "2737 Mix-and-match backward compatibility " |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 4902 | "between MBOX_REQ old size:%d and " |
| 4903 | "new request size:%d\n", |
| 4904 | (int)(job->request_len - |
| 4905 | sizeof(struct fc_bsg_request)), |
| 4906 | (int)sizeof(struct dfc_mbox_req)); |
| 4907 | mbox_req = (struct dfc_mbox_req *) |
| 4908 | job->request->rqst_data.h_vendor.vendor_cmd; |
| 4909 | mbox_req->extMboxTag = 0; |
| 4910 | mbox_req->extSeqNum = 0; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | rc = lpfc_bsg_issue_mbox(phba, job, vport); |
| 4914 | |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 4915 | if (rc == 0) { |
| 4916 | /* job done */ |
| 4917 | job->reply->result = 0; |
| 4918 | job->dd_data = NULL; |
| 4919 | job->job_done(job); |
| 4920 | } else if (rc == 1) |
| 4921 | /* job submitted, will complete later*/ |
| 4922 | rc = 0; /* return zero, no error */ |
| 4923 | else { |
| 4924 | /* some error occurred */ |
| 4925 | job->reply->result = rc; |
| 4926 | job->dd_data = NULL; |
| 4927 | } |
| 4928 | |
| 4929 | return rc; |
| 4930 | } |
| 4931 | |
| 4932 | /** |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 4933 | * lpfc_bsg_menlo_cmd_cmp - lpfc_menlo_cmd completion handler |
| 4934 | * @phba: Pointer to HBA context object. |
| 4935 | * @cmdiocbq: Pointer to command iocb. |
| 4936 | * @rspiocbq: Pointer to response iocb. |
| 4937 | * |
| 4938 | * This function is the completion handler for iocbs issued using |
| 4939 | * lpfc_menlo_cmd function. This function is called by the |
| 4940 | * ring event handler function without any lock held. This function |
| 4941 | * can be called from both worker thread context and interrupt |
| 4942 | * context. This function also can be called from another thread which |
| 4943 | * cleans up the SLI layer objects. |
| 4944 | * This function copies the contents of the response iocb to the |
| 4945 | * response iocb memory object provided by the caller of |
| 4946 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which |
| 4947 | * sleeps for the iocb completion. |
| 4948 | **/ |
| 4949 | static void |
| 4950 | lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba *phba, |
| 4951 | struct lpfc_iocbq *cmdiocbq, |
| 4952 | struct lpfc_iocbq *rspiocbq) |
| 4953 | { |
| 4954 | struct bsg_job_data *dd_data; |
| 4955 | struct fc_bsg_job *job; |
| 4956 | IOCB_t *rsp; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 4957 | struct lpfc_dmabuf *bmp, *cmp, *rmp; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 4958 | struct lpfc_bsg_menlo *menlo; |
| 4959 | unsigned long flags; |
| 4960 | struct menlo_response *menlo_resp; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 4961 | unsigned int rsp_size; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 4962 | int rc = 0; |
| 4963 | |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 4964 | dd_data = cmdiocbq->context1; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 4965 | cmp = cmdiocbq->context2; |
| 4966 | bmp = cmdiocbq->context3; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 4967 | menlo = &dd_data->context_un.menlo; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 4968 | rmp = menlo->rmp; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 4969 | rsp = &rspiocbq->iocb; |
| 4970 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 4971 | /* Determine if job has been aborted */ |
| 4972 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 4973 | job = dd_data->set_job; |
| 4974 | if (job) { |
| 4975 | /* Prevent timeout handling from trying to abort job */ |
| 4976 | job->dd_data = NULL; |
| 4977 | } |
| 4978 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 4979 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 4980 | /* Copy the job data or set the failing status for the job */ |
| 4981 | |
| 4982 | if (job) { |
| 4983 | /* always return the xri, this would be used in the case |
| 4984 | * of a menlo download to allow the data to be sent as a |
| 4985 | * continuation of the exchange. |
| 4986 | */ |
| 4987 | |
| 4988 | menlo_resp = (struct menlo_response *) |
| 4989 | job->reply->reply_data.vendor_reply.vendor_rsp; |
| 4990 | menlo_resp->xri = rsp->ulpContext; |
| 4991 | if (rsp->ulpStatus) { |
| 4992 | if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
| 4993 | switch (rsp->un.ulpWord[4] & IOERR_PARAM_MASK) { |
| 4994 | case IOERR_SEQUENCE_TIMEOUT: |
| 4995 | rc = -ETIMEDOUT; |
| 4996 | break; |
| 4997 | case IOERR_INVALID_RPI: |
| 4998 | rc = -EFAULT; |
| 4999 | break; |
| 5000 | default: |
| 5001 | rc = -EACCES; |
| 5002 | break; |
| 5003 | } |
| 5004 | } else { |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5005 | rc = -EACCES; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5006 | } |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5007 | } else { |
| 5008 | rsp_size = rsp->un.genreq64.bdl.bdeSize; |
| 5009 | job->reply->reply_payload_rcv_len = |
| 5010 | lpfc_bsg_copy_data(rmp, &job->reply_payload, |
| 5011 | rsp_size, 0); |
| 5012 | } |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5013 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5014 | } |
| 5015 | |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5016 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5017 | lpfc_free_bsg_buffers(phba, cmp); |
| 5018 | lpfc_free_bsg_buffers(phba, rmp); |
| 5019 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5020 | kfree(bmp); |
| 5021 | kfree(dd_data); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5022 | |
| 5023 | /* Complete the job if active */ |
| 5024 | |
| 5025 | if (job) { |
| 5026 | job->reply->result = rc; |
| 5027 | job->job_done(job); |
| 5028 | } |
| 5029 | |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5030 | return; |
| 5031 | } |
| 5032 | |
| 5033 | /** |
| 5034 | * lpfc_menlo_cmd - send an ioctl for menlo hardware |
| 5035 | * @job: fc_bsg_job to handle |
| 5036 | * |
| 5037 | * This function issues a gen request 64 CR ioctl for all menlo cmd requests, |
| 5038 | * all the command completions will return the xri for the command. |
| 5039 | * For menlo data requests a gen request 64 CX is used to continue the exchange |
| 5040 | * supplied in the menlo request header xri field. |
| 5041 | **/ |
| 5042 | static int |
| 5043 | lpfc_menlo_cmd(struct fc_bsg_job *job) |
| 5044 | { |
| 5045 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
| 5046 | struct lpfc_hba *phba = vport->phba; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5047 | struct lpfc_iocbq *cmdiocbq; |
| 5048 | IOCB_t *cmd; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5049 | int rc = 0; |
| 5050 | struct menlo_command *menlo_cmd; |
| 5051 | struct menlo_response *menlo_resp; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5052 | struct lpfc_dmabuf *bmp = NULL, *cmp = NULL, *rmp = NULL; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5053 | int request_nseg; |
| 5054 | int reply_nseg; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5055 | struct bsg_job_data *dd_data; |
| 5056 | struct ulp_bde64 *bpl = NULL; |
| 5057 | |
| 5058 | /* in case no data is returned return just the return code */ |
| 5059 | job->reply->reply_payload_rcv_len = 0; |
| 5060 | |
| 5061 | if (job->request_len < |
| 5062 | sizeof(struct fc_bsg_request) + |
| 5063 | sizeof(struct menlo_command)) { |
| 5064 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 5065 | "2784 Received MENLO_CMD request below " |
| 5066 | "minimum size\n"); |
| 5067 | rc = -ERANGE; |
| 5068 | goto no_dd_data; |
| 5069 | } |
| 5070 | |
| 5071 | if (job->reply_len < |
| 5072 | sizeof(struct fc_bsg_request) + sizeof(struct menlo_response)) { |
| 5073 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 5074 | "2785 Received MENLO_CMD reply below " |
| 5075 | "minimum size\n"); |
| 5076 | rc = -ERANGE; |
| 5077 | goto no_dd_data; |
| 5078 | } |
| 5079 | |
| 5080 | if (!(phba->menlo_flag & HBA_MENLO_SUPPORT)) { |
| 5081 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 5082 | "2786 Adapter does not support menlo " |
| 5083 | "commands\n"); |
| 5084 | rc = -EPERM; |
| 5085 | goto no_dd_data; |
| 5086 | } |
| 5087 | |
| 5088 | menlo_cmd = (struct menlo_command *) |
| 5089 | job->request->rqst_data.h_vendor.vendor_cmd; |
| 5090 | |
| 5091 | menlo_resp = (struct menlo_response *) |
| 5092 | job->reply->reply_data.vendor_reply.vendor_rsp; |
| 5093 | |
| 5094 | /* allocate our bsg tracking structure */ |
| 5095 | dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL); |
| 5096 | if (!dd_data) { |
| 5097 | lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, |
| 5098 | "2787 Failed allocation of dd_data\n"); |
| 5099 | rc = -ENOMEM; |
| 5100 | goto no_dd_data; |
| 5101 | } |
| 5102 | |
| 5103 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5104 | if (!bmp) { |
| 5105 | rc = -ENOMEM; |
| 5106 | goto free_dd; |
| 5107 | } |
| 5108 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5109 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys); |
| 5110 | if (!bmp->virt) { |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5111 | rc = -ENOMEM; |
| 5112 | goto free_bmp; |
| 5113 | } |
| 5114 | |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5115 | INIT_LIST_HEAD(&bmp->list); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5116 | |
| 5117 | bpl = (struct ulp_bde64 *)bmp->virt; |
| 5118 | request_nseg = LPFC_BPL_SIZE/sizeof(struct ulp_bde64); |
| 5119 | cmp = lpfc_alloc_bsg_buffers(phba, job->request_payload.payload_len, |
| 5120 | 1, bpl, &request_nseg); |
| 5121 | if (!cmp) { |
| 5122 | rc = -ENOMEM; |
| 5123 | goto free_bmp; |
| 5124 | } |
| 5125 | lpfc_bsg_copy_data(cmp, &job->request_payload, |
| 5126 | job->request_payload.payload_len, 1); |
| 5127 | |
| 5128 | bpl += request_nseg; |
| 5129 | reply_nseg = LPFC_BPL_SIZE/sizeof(struct ulp_bde64) - request_nseg; |
| 5130 | rmp = lpfc_alloc_bsg_buffers(phba, job->reply_payload.payload_len, 0, |
| 5131 | bpl, &reply_nseg); |
| 5132 | if (!rmp) { |
| 5133 | rc = -ENOMEM; |
| 5134 | goto free_cmp; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5135 | } |
| 5136 | |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5137 | cmdiocbq = lpfc_sli_get_iocbq(phba); |
| 5138 | if (!cmdiocbq) { |
| 5139 | rc = -ENOMEM; |
| 5140 | goto free_rmp; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | cmd = &cmdiocbq->iocb; |
| 5144 | cmd->un.genreq64.bdl.ulpIoTag32 = 0; |
| 5145 | cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); |
| 5146 | cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); |
| 5147 | cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
| 5148 | cmd->un.genreq64.bdl.bdeSize = |
| 5149 | (request_nseg + reply_nseg) * sizeof(struct ulp_bde64); |
| 5150 | cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA); |
| 5151 | cmd->un.genreq64.w5.hcsw.Dfctl = 0; |
| 5152 | cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CMD; |
| 5153 | cmd->un.genreq64.w5.hcsw.Type = MENLO_TRANSPORT_TYPE; /* 0xfe */ |
| 5154 | cmd->ulpBdeCount = 1; |
| 5155 | cmd->ulpClass = CLASS3; |
| 5156 | cmd->ulpOwner = OWN_CHIP; |
| 5157 | cmd->ulpLe = 1; /* Limited Edition */ |
| 5158 | cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; |
| 5159 | cmdiocbq->vport = phba->pport; |
| 5160 | /* We want the firmware to timeout before we do */ |
| 5161 | cmd->ulpTimeout = MENLO_TIMEOUT - 5; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5162 | cmdiocbq->iocb_cmpl = lpfc_bsg_menlo_cmd_cmp; |
| 5163 | cmdiocbq->context1 = dd_data; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5164 | cmdiocbq->context2 = cmp; |
| 5165 | cmdiocbq->context3 = bmp; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5166 | if (menlo_cmd->cmd == LPFC_BSG_VENDOR_MENLO_CMD) { |
| 5167 | cmd->ulpCommand = CMD_GEN_REQUEST64_CR; |
| 5168 | cmd->ulpPU = MENLO_PU; /* 3 */ |
| 5169 | cmd->un.ulpWord[4] = MENLO_DID; /* 0x0000FC0E */ |
| 5170 | cmd->ulpContext = MENLO_CONTEXT; /* 0 */ |
| 5171 | } else { |
| 5172 | cmd->ulpCommand = CMD_GEN_REQUEST64_CX; |
| 5173 | cmd->ulpPU = 1; |
| 5174 | cmd->un.ulpWord[4] = 0; |
| 5175 | cmd->ulpContext = menlo_cmd->xri; |
| 5176 | } |
| 5177 | |
| 5178 | dd_data->type = TYPE_MENLO; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5179 | dd_data->set_job = job; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5180 | dd_data->context_un.menlo.cmdiocbq = cmdiocbq; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5181 | dd_data->context_un.menlo.rmp = rmp; |
| 5182 | job->dd_data = dd_data; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5183 | |
| 5184 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, |
| 5185 | MENLO_TIMEOUT - 5); |
| 5186 | if (rc == IOCB_SUCCESS) |
| 5187 | return 0; /* done for now */ |
| 5188 | |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5189 | lpfc_sli_release_iocbq(phba, cmdiocbq); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5190 | |
| 5191 | free_rmp: |
| 5192 | lpfc_free_bsg_buffers(phba, rmp); |
| 5193 | free_cmp: |
| 5194 | lpfc_free_bsg_buffers(phba, cmp); |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5195 | free_bmp: |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5196 | if (bmp->virt) |
| 5197 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5198 | kfree(bmp); |
| 5199 | free_dd: |
| 5200 | kfree(dd_data); |
| 5201 | no_dd_data: |
| 5202 | /* make error code available to userspace */ |
| 5203 | job->reply->result = rc; |
| 5204 | job->dd_data = NULL; |
| 5205 | return rc; |
| 5206 | } |
James Smart | b6e3b9c | 2011-04-16 11:03:43 -0400 | [diff] [blame] | 5207 | |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5208 | /** |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5209 | * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job |
| 5210 | * @job: fc_bsg_job to handle |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 5211 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5212 | static int |
| 5213 | lpfc_bsg_hst_vendor(struct fc_bsg_job *job) |
| 5214 | { |
| 5215 | int command = job->request->rqst_data.h_vendor.vendor_cmd[0]; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5216 | int rc; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5217 | |
| 5218 | switch (command) { |
| 5219 | case LPFC_BSG_VENDOR_SET_CT_EVENT: |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5220 | rc = lpfc_bsg_hba_set_event(job); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5221 | break; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5222 | case LPFC_BSG_VENDOR_GET_CT_EVENT: |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5223 | rc = lpfc_bsg_hba_get_event(job); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5224 | break; |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 5225 | case LPFC_BSG_VENDOR_SEND_MGMT_RESP: |
| 5226 | rc = lpfc_bsg_send_mgmt_rsp(job); |
| 5227 | break; |
| 5228 | case LPFC_BSG_VENDOR_DIAG_MODE: |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 5229 | rc = lpfc_bsg_diag_loopback_mode(job); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 5230 | break; |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 5231 | case LPFC_BSG_VENDOR_DIAG_MODE_END: |
| 5232 | rc = lpfc_sli4_bsg_diag_mode_end(job); |
| 5233 | break; |
| 5234 | case LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK: |
| 5235 | rc = lpfc_bsg_diag_loopback_run(job); |
| 5236 | break; |
| 5237 | case LPFC_BSG_VENDOR_LINK_DIAG_TEST: |
| 5238 | rc = lpfc_sli4_bsg_link_diag_test(job); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 5239 | break; |
| 5240 | case LPFC_BSG_VENDOR_GET_MGMT_REV: |
| 5241 | rc = lpfc_bsg_get_dfc_rev(job); |
| 5242 | break; |
| 5243 | case LPFC_BSG_VENDOR_MBOX: |
| 5244 | rc = lpfc_bsg_mbox_cmd(job); |
| 5245 | break; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5246 | case LPFC_BSG_VENDOR_MENLO_CMD: |
| 5247 | case LPFC_BSG_VENDOR_MENLO_DATA: |
| 5248 | rc = lpfc_menlo_cmd(job); |
| 5249 | break; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5250 | default: |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5251 | rc = -EINVAL; |
| 5252 | job->reply->reply_payload_rcv_len = 0; |
| 5253 | /* make error code available to userspace */ |
| 5254 | job->reply->result = rc; |
| 5255 | break; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5256 | } |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5257 | |
| 5258 | return rc; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | /** |
| 5262 | * lpfc_bsg_request - handle a bsg request from the FC transport |
| 5263 | * @job: fc_bsg_job to handle |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 5264 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5265 | int |
| 5266 | lpfc_bsg_request(struct fc_bsg_job *job) |
| 5267 | { |
| 5268 | uint32_t msgcode; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5269 | int rc; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5270 | |
| 5271 | msgcode = job->request->msgcode; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5272 | switch (msgcode) { |
| 5273 | case FC_BSG_HST_VENDOR: |
| 5274 | rc = lpfc_bsg_hst_vendor(job); |
| 5275 | break; |
| 5276 | case FC_BSG_RPT_ELS: |
| 5277 | rc = lpfc_bsg_rport_els(job); |
| 5278 | break; |
| 5279 | case FC_BSG_RPT_CT: |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5280 | rc = lpfc_bsg_send_mgmt_cmd(job); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5281 | break; |
| 5282 | default: |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5283 | rc = -EINVAL; |
| 5284 | job->reply->reply_payload_rcv_len = 0; |
| 5285 | /* make error code available to userspace */ |
| 5286 | job->reply->result = rc; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5287 | break; |
| 5288 | } |
| 5289 | |
| 5290 | return rc; |
| 5291 | } |
| 5292 | |
| 5293 | /** |
| 5294 | * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport |
| 5295 | * @job: fc_bsg_job that has timed out |
| 5296 | * |
| 5297 | * This function just aborts the job's IOCB. The aborted IOCB will return to |
| 5298 | * the waiting function which will handle passing the error back to userspace |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 5299 | **/ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5300 | int |
| 5301 | lpfc_bsg_timeout(struct fc_bsg_job *job) |
| 5302 | { |
| 5303 | struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; |
| 5304 | struct lpfc_hba *phba = vport->phba; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5305 | struct lpfc_iocbq *cmdiocb; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5306 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5307 | struct bsg_job_data *dd_data; |
| 5308 | unsigned long flags; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5309 | int rc = 0; |
| 5310 | LIST_HEAD(completions); |
| 5311 | struct lpfc_iocbq *check_iocb, *next_iocb; |
| 5312 | |
| 5313 | /* if job's driver data is NULL, the command completed or is in the |
| 5314 | * the process of completing. In this case, return status to request |
| 5315 | * so the timeout is retried. This avoids double completion issues |
| 5316 | * and the request will be pulled off the timer queue when the |
| 5317 | * command's completion handler executes. Otherwise, prevent the |
| 5318 | * command's completion handler from executing the job done callback |
| 5319 | * and continue processing to abort the outstanding the command. |
| 5320 | */ |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5321 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5322 | spin_lock_irqsave(&phba->ct_ev_lock, flags); |
| 5323 | dd_data = (struct bsg_job_data *)job->dd_data; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5324 | if (dd_data) { |
| 5325 | dd_data->set_job = NULL; |
| 5326 | job->dd_data = NULL; |
| 5327 | } else { |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5328 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5329 | return -EAGAIN; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | switch (dd_data->type) { |
| 5333 | case TYPE_IOCB: |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5334 | /* Check to see if IOCB was issued to the port or not. If not, |
| 5335 | * remove it from the txq queue and call cancel iocbs. |
| 5336 | * Otherwise, call abort iotag |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5337 | */ |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5338 | cmdiocb = dd_data->context_un.iocb.cmdiocbq; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 5339 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 5340 | |
| 5341 | spin_lock_irqsave(&phba->hbalock, flags); |
| 5342 | /* make sure the I/O abort window is still open */ |
James Smart | 1b8d11a | 2013-09-06 12:20:51 -0400 | [diff] [blame] | 5343 | if (!(cmdiocb->iocb_flag & LPFC_IO_CMD_OUTSTANDING)) { |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 5344 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| 5345 | return -EAGAIN; |
| 5346 | } |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5347 | list_for_each_entry_safe(check_iocb, next_iocb, &pring->txq, |
| 5348 | list) { |
| 5349 | if (check_iocb == cmdiocb) { |
| 5350 | list_move_tail(&check_iocb->list, &completions); |
| 5351 | break; |
| 5352 | } |
| 5353 | } |
| 5354 | if (list_empty(&completions)) |
| 5355 | lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb); |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 5356 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5357 | if (!list_empty(&completions)) { |
| 5358 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 5359 | IOSTAT_LOCAL_REJECT, |
| 5360 | IOERR_SLI_ABORTED); |
| 5361 | } |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5362 | break; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5363 | |
| 5364 | case TYPE_EVT: |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 5365 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5366 | break; |
| 5367 | |
| 5368 | case TYPE_MBOX: |
| 5369 | /* Update the ext buf ctx state if needed */ |
| 5370 | |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 5371 | if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_PORT) |
| 5372 | phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_ABTS; |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5373 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
James Smart | 3b5dd52 | 2010-01-26 23:10:15 -0500 | [diff] [blame] | 5374 | break; |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5375 | case TYPE_MENLO: |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5376 | /* Check to see if IOCB was issued to the port or not. If not, |
| 5377 | * remove it from the txq queue and call cancel iocbs. |
| 5378 | * Otherwise, call abort iotag. |
| 5379 | */ |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5380 | cmdiocb = dd_data->context_un.menlo.cmdiocbq; |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 5381 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 5382 | |
| 5383 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5384 | list_for_each_entry_safe(check_iocb, next_iocb, &pring->txq, |
| 5385 | list) { |
| 5386 | if (check_iocb == cmdiocb) { |
| 5387 | list_move_tail(&check_iocb->list, &completions); |
| 5388 | break; |
| 5389 | } |
| 5390 | } |
| 5391 | if (list_empty(&completions)) |
| 5392 | lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb); |
James Smart | b5a9b2d | 2013-09-06 12:19:45 -0400 | [diff] [blame] | 5393 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5394 | if (!list_empty(&completions)) { |
| 5395 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 5396 | IOSTAT_LOCAL_REJECT, |
| 5397 | IOERR_SLI_ABORTED); |
| 5398 | } |
James Smart | e2aed29 | 2010-02-26 14:15:00 -0500 | [diff] [blame] | 5399 | break; |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5400 | default: |
| 5401 | spin_unlock_irqrestore(&phba->ct_ev_lock, flags); |
| 5402 | break; |
| 5403 | } |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5404 | |
James Smart | 4cc0e56 | 2010-01-26 23:09:48 -0500 | [diff] [blame] | 5405 | /* scsi transport fc fc_bsg_job_timeout expects a zero return code, |
| 5406 | * otherwise an error message will be displayed on the console |
| 5407 | * so always return success (zero) |
| 5408 | */ |
James Smart | a33c4f7 | 2013-03-01 16:36:00 -0500 | [diff] [blame] | 5409 | return rc; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 5410 | } |