| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * |
| 5 | * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9 | * * |
| 10 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 11 | * modify it under the terms of version 2 of the GNU General * |
| 12 | * Public License as published by the Free Software Foundation. * |
| 13 | * This program is distributed in the hope that it will be useful. * |
| 14 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 15 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 17 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 18 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 19 | * more details, a copy of which can be found in the file COPYING * |
| 20 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 21 | *******************************************************************/ |
| 22 | |
| 23 | /* |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 24 | * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #include <linux/blkdev.h> |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/interrupt.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | #include <linux/utsname.h> |
| 32 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 33 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 34 | #include <scsi/scsi_device.h> |
| 35 | #include <scsi/scsi_host.h> |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 36 | #include <scsi/scsi_transport_fc.h> |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 37 | #include <scsi/fc/fc_fs.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 38 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 39 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 40 | #include "lpfc_hw.h" |
| 41 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 42 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 43 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 44 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | #include "lpfc.h" |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 46 | #include "lpfc_scsi.h" |
| 47 | #include "lpfc_nvme.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 48 | #include "lpfc_logmsg.h" |
| 49 | #include "lpfc_crtn.h" |
| 50 | #include "lpfc_version.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 51 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 52 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 53 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 54 | /* FDMI Port Speed definitions - FC-GS-7 */ |
| 55 | #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */ |
| 56 | #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */ |
| 57 | #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */ |
| 58 | #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */ |
| 59 | #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */ |
| 60 | #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */ |
| 61 | #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */ |
| 62 | #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */ |
| 63 | #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */ |
| 64 | #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */ |
| 65 | #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */ |
| 66 | #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */ |
| 67 | #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */ |
| 68 | #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */ |
| 69 | #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */ |
| 70 | #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */ |
| 71 | #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */ |
| 72 | #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */ |
| 73 | #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 74 | |
| 75 | #define FOURBYTES 4 |
| 76 | |
| 77 | |
| 78 | static char *lpfc_release_version = LPFC_DRIVER_VERSION; |
| 79 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 80 | static void |
| 81 | lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 82 | struct lpfc_dmabuf *mp, uint32_t size) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 83 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 84 | if (!mp) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 85 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 86 | "0146 Ignoring unsolicited CT No HBQ " |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 87 | "status = x%x\n", |
| 88 | piocbq->iocb.ulpStatus); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 89 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 90 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
| 91 | "0145 Ignoring unsolicted CT HBQ Size:%d " |
| 92 | "status = x%x\n", |
| 93 | size, piocbq->iocb.ulpStatus); |
| 94 | } |
| 95 | |
| 96 | static void |
| 97 | lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
| 98 | struct lpfc_dmabuf *mp, uint32_t size) |
| 99 | { |
| 100 | lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 103 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 104 | lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 105 | struct lpfc_iocbq *piocbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 106 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 107 | struct lpfc_dmabuf *mp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 108 | IOCB_t *icmd = &piocbq->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 109 | int i; |
| 110 | struct lpfc_iocbq *iocbq; |
| 111 | dma_addr_t paddr; |
| 112 | uint32_t size; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 113 | struct list_head head; |
| 114 | struct lpfc_dmabuf *bdeBuf; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 115 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 116 | if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0) |
| 117 | return; |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 118 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 119 | if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) { |
| 120 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 121 | } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 122 | ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 123 | IOERR_RCV_BUFFER_WAITING)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 124 | /* Not enough posted buffers; Try posting more buffers */ |
| 125 | phba->fc_stat.NoRcvBuf++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 126 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 127 | lpfc_post_buffer(phba, pring, 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 128 | return; |
| 129 | } |
| 130 | |
| 131 | /* If there are no BDEs associated with this IOCB, |
| 132 | * there is nothing to do. |
| 133 | */ |
| 134 | if (icmd->ulpBdeCount == 0) |
| 135 | return; |
| 136 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 137 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 138 | INIT_LIST_HEAD(&head); |
| 139 | list_add_tail(&head, &piocbq->list); |
| 140 | list_for_each_entry(iocbq, &head, list) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 141 | icmd = &iocbq->iocb; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 142 | if (icmd->ulpBdeCount == 0) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 143 | continue; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 144 | bdeBuf = iocbq->context2; |
| 145 | iocbq->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 146 | size = icmd->un.cont64[0].tus.f.bdeSize; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 147 | lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size); |
| 148 | lpfc_in_buf_free(phba, bdeBuf); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 149 | if (icmd->ulpBdeCount == 2) { |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 150 | bdeBuf = iocbq->context3; |
| 151 | iocbq->context3 = NULL; |
| 152 | size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize; |
| 153 | lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, |
| 154 | size); |
| 155 | lpfc_in_buf_free(phba, bdeBuf); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 156 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | } |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 158 | list_del(&head); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 159 | } else { |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 160 | INIT_LIST_HEAD(&head); |
| 161 | list_add_tail(&head, &piocbq->list); |
| 162 | list_for_each_entry(iocbq, &head, list) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 163 | icmd = &iocbq->iocb; |
James Smart | 9c2face | 2008-01-11 01:53:18 -0500 | [diff] [blame] | 164 | if (icmd->ulpBdeCount == 0) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 165 | lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 166 | for (i = 0; i < icmd->ulpBdeCount; i++) { |
| 167 | paddr = getPaddr(icmd->un.cont64[i].addrHigh, |
| 168 | icmd->un.cont64[i].addrLow); |
| 169 | mp = lpfc_sli_ringpostbuf_get(phba, pring, |
| 170 | paddr); |
| 171 | size = icmd->un.cont64[i].tus.f.bdeSize; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 172 | lpfc_ct_unsol_buffer(phba, iocbq, mp, size); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 173 | lpfc_in_buf_free(phba, mp); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 174 | } |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 175 | lpfc_post_buffer(phba, pring, i); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 176 | } |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 177 | list_del(&head); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 178 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 179 | } |
| 180 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 181 | /** |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 182 | * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 183 | * @phba: Pointer to HBA context object. |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 184 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 185 | * |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 186 | * This function serves as the upper level protocol abort handler for CT |
| 187 | * protocol. |
| 188 | * |
| 189 | * Return 1 if abort has been handled, 0 otherwise. |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 190 | **/ |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 191 | int |
| 192 | lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf) |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 193 | { |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 194 | int handled; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 195 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 196 | /* CT upper level goes through BSG */ |
| 197 | handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 198 | |
James Smart | 6dd9e31 | 2013-01-03 15:43:37 -0500 | [diff] [blame] | 199 | return handled; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 200 | } |
| 201 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 202 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 203 | lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 204 | { |
| 205 | struct lpfc_dmabuf *mlast, *next_mlast; |
| 206 | |
| 207 | list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) { |
| 208 | lpfc_mbuf_free(phba, mlast->virt, mlast->phys); |
| 209 | list_del(&mlast->list); |
| 210 | kfree(mlast); |
| 211 | } |
| 212 | lpfc_mbuf_free(phba, mlist->virt, mlist->phys); |
| 213 | kfree(mlist); |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | static struct lpfc_dmabuf * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 218 | lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 219 | uint32_t size, int *entries) |
| 220 | { |
| 221 | struct lpfc_dmabuf *mlist = NULL; |
| 222 | struct lpfc_dmabuf *mp; |
| 223 | int cnt, i = 0; |
| 224 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 225 | /* We get chunks of FCELSSIZE */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 226 | cnt = size > FCELSSIZE ? FCELSSIZE: size; |
| 227 | |
| 228 | while (size) { |
| 229 | /* Allocate buffer for rsp payload */ |
| 230 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 231 | if (!mp) { |
| 232 | if (mlist) |
| 233 | lpfc_free_ct_rsp(phba, mlist); |
| 234 | return NULL; |
| 235 | } |
| 236 | |
| 237 | INIT_LIST_HEAD(&mp->list); |
| 238 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 239 | if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) || |
| 240 | cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys)); |
| 242 | else |
| 243 | mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys)); |
| 244 | |
| 245 | if (!mp->virt) { |
| 246 | kfree(mp); |
Eric Sesterhenn | 0b3a82d | 2006-10-10 14:41:43 -0700 | [diff] [blame] | 247 | if (mlist) |
| 248 | lpfc_free_ct_rsp(phba, mlist); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 249 | return NULL; |
| 250 | } |
| 251 | |
| 252 | /* Queue it to a linked list */ |
| 253 | if (!mlist) |
| 254 | mlist = mp; |
| 255 | else |
| 256 | list_add_tail(&mp->list, &mlist->list); |
| 257 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 258 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 259 | /* build buffer ptr list for IOCB */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 260 | bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) ); |
| 261 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) ); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 262 | bpl->tus.f.bdeSize = (uint16_t) cnt; |
| 263 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 264 | bpl++; |
| 265 | |
| 266 | i++; |
| 267 | size -= cnt; |
| 268 | } |
| 269 | |
| 270 | *entries = i; |
| 271 | return mlist; |
| 272 | } |
| 273 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 274 | int |
| 275 | lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb) |
| 276 | { |
| 277 | struct lpfc_dmabuf *buf_ptr; |
| 278 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 279 | if (ctiocb->context_un.ndlp) { |
| 280 | lpfc_nlp_put(ctiocb->context_un.ndlp); |
| 281 | ctiocb->context_un.ndlp = NULL; |
| 282 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 283 | if (ctiocb->context1) { |
| 284 | buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1; |
| 285 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 286 | kfree(buf_ptr); |
| 287 | ctiocb->context1 = NULL; |
| 288 | } |
| 289 | if (ctiocb->context2) { |
| 290 | lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2); |
| 291 | ctiocb->context2 = NULL; |
| 292 | } |
| 293 | |
| 294 | if (ctiocb->context3) { |
| 295 | buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3; |
| 296 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 297 | kfree(buf_ptr); |
Felipe Pena | 1109c94 | 2013-10-15 21:29:50 -0300 | [diff] [blame] | 298 | ctiocb->context3 = NULL; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 299 | } |
| 300 | lpfc_sli_release_iocbq(phba, ctiocb); |
| 301 | return 0; |
| 302 | } |
| 303 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 304 | /** |
| 305 | * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer |
| 306 | * @vport: pointer to a host virtual N_Port data structure. |
| 307 | * @bmp: Pointer to BPL for SLI command |
| 308 | * @inp: Pointer to data buffer for response data. |
| 309 | * @outp: Pointer to data buffer that hold the CT command. |
| 310 | * @cmpl: completion routine to call when command completes |
| 311 | * @ndlp: Destination NPort nodelist entry |
| 312 | * |
| 313 | * This function as the final part for issuing a CT command. |
| 314 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 315 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 316 | lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 317 | struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp, |
| 318 | void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, |
| 319 | struct lpfc_iocbq *), |
| 320 | struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 321 | uint32_t tmo, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 322 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 323 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 324 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 325 | struct lpfc_iocbq *geniocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 326 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 327 | |
| 328 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 329 | geniocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 330 | |
| 331 | if (geniocb == NULL) |
| 332 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 333 | |
| 334 | icmd = &geniocb->iocb; |
| 335 | icmd->un.genreq64.bdl.ulpIoTag32 = 0; |
| 336 | icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); |
| 337 | icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 338 | icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 339 | icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 340 | |
| 341 | if (usr_flg) |
| 342 | geniocb->context3 = NULL; |
| 343 | else |
| 344 | geniocb->context3 = (uint8_t *) bmp; |
| 345 | |
| 346 | /* Save for completion so we can release these resources */ |
| 347 | geniocb->context1 = (uint8_t *) inp; |
| 348 | geniocb->context2 = (uint8_t *) outp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 349 | geniocb->context_un.ndlp = lpfc_nlp_get(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 350 | |
| 351 | /* Fill in payload, bp points to frame payload */ |
| 352 | icmd->ulpCommand = CMD_GEN_REQUEST64_CR; |
| 353 | |
| 354 | /* Fill in rest of iocb */ |
| 355 | icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA); |
| 356 | icmd->un.genreq64.w5.hcsw.Dfctl = 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 357 | icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; |
| 358 | icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 359 | |
Jamie Wellnitz | c9f8735 | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 360 | if (!tmo) { |
| 361 | /* FC spec states we need 3 * ratov for CT requests */ |
| 362 | tmo = (3 * phba->fc_ratov); |
| 363 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 364 | icmd->ulpTimeout = tmo; |
| 365 | icmd->ulpBdeCount = 1; |
| 366 | icmd->ulpLe = 1; |
| 367 | icmd->ulpClass = CLASS3; |
| 368 | icmd->ulpContext = ndlp->nlp_rpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 369 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 370 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 371 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 372 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 373 | /* For GEN_REQUEST64_CR, use the RPI */ |
| 374 | icmd->ulpCt_h = 0; |
| 375 | icmd->ulpCt_l = 0; |
| 376 | } |
| 377 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 378 | /* Issue GEN REQ IOCB for NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 379 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 380 | "0119 Issue GEN REQ IOCB to NPORT x%x " |
| 381 | "Data: x%x x%x\n", |
| 382 | ndlp->nlp_DID, icmd->ulpIoTag, |
| 383 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 384 | geniocb->iocb_cmpl = cmpl; |
| 385 | geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 386 | geniocb->vport = vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 387 | geniocb->retry = retry; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 388 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 389 | |
| 390 | if (rc == IOCB_ERROR) { |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 391 | lpfc_sli_release_iocbq(phba, geniocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 392 | return 1; |
| 393 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 394 | |
| 395 | return 0; |
| 396 | } |
| 397 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 398 | /** |
| 399 | * lpfc_ct_cmd - Build and issue a CT command |
| 400 | * @vport: pointer to a host virtual N_Port data structure. |
| 401 | * @inmp: Pointer to data buffer for response data. |
| 402 | * @bmp: Pointer to BPL for SLI command |
| 403 | * @ndlp: Destination NPort nodelist entry |
| 404 | * @cmpl: completion routine to call when command completes |
| 405 | * |
| 406 | * This function is called for issuing a CT command. |
| 407 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 408 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 409 | lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp, |
| 411 | void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, |
| 412 | struct lpfc_iocbq *), |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 413 | uint32_t rsp_size, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 415 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 416 | struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt; |
| 417 | struct lpfc_dmabuf *outmp; |
| 418 | int cnt = 0, status; |
| 419 | int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)-> |
| 420 | CommandResponse.bits.CmdRsp; |
| 421 | |
| 422 | bpl++; /* Skip past ct request */ |
| 423 | |
| 424 | /* Put buffer(s) for ct rsp in bpl */ |
| 425 | outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt); |
| 426 | if (!outmp) |
| 427 | return -ENOMEM; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 428 | /* |
| 429 | * Form the CT IOCB. The total number of BDEs in this IOCB |
| 430 | * is the single command plus response count from |
| 431 | * lpfc_alloc_ct_rsp. |
| 432 | */ |
| 433 | cnt += 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 434 | status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0, |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 435 | cnt, 0, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 436 | if (status) { |
| 437 | lpfc_free_ct_rsp(phba, outmp); |
| 438 | return -ENOMEM; |
| 439 | } |
| 440 | return 0; |
| 441 | } |
| 442 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 443 | struct lpfc_vport * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 444 | lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 445 | struct lpfc_vport *vport_curr; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 446 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 447 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 448 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 449 | list_for_each_entry(vport_curr, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 450 | if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) { |
| 451 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 452 | return vport_curr; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 453 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 454 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 455 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 456 | return NULL; |
| 457 | } |
| 458 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 459 | static void |
| 460 | lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type) |
| 461 | { |
| 462 | struct lpfc_nodelist *ndlp; |
| 463 | |
| 464 | if ((vport->port_type != LPFC_NPIV_PORT) || |
| 465 | !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) { |
| 466 | |
| 467 | ndlp = lpfc_setup_disc_node(vport, Did); |
| 468 | |
| 469 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | bd2cdd5 | 2017-02-12 13:52:33 -0800 | [diff] [blame] | 470 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 471 | "Parse GID_FTrsp: did:x%x flg:x%x x%x", |
| 472 | Did, ndlp->nlp_flag, vport->fc_flag); |
| 473 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 474 | /* By default, the driver expects to support FCP FC4 */ |
| 475 | if (fc4_type == FC_TYPE_FCP) |
| 476 | ndlp->nlp_fc4_type |= NLP_FC4_FCP; |
| 477 | |
| 478 | if (fc4_type == FC_TYPE_NVME) |
| 479 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; |
| 480 | |
| 481 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 482 | "0238 Process x%06x NameServer Rsp " |
| 483 | "Data: x%x x%x x%x x%x\n", Did, |
| 484 | ndlp->nlp_flag, ndlp->nlp_fc4_type, |
| 485 | vport->fc_flag, |
| 486 | vport->fc_rscn_id_cnt); |
James Smart | bd2cdd5 | 2017-02-12 13:52:33 -0800 | [diff] [blame] | 487 | } else { |
| 488 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 489 | "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d", |
| 490 | Did, vport->fc_flag, vport->fc_rscn_id_cnt); |
| 491 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 492 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 493 | "0239 Skip x%06x NameServer Rsp " |
| 494 | "Data: x%x x%x\n", Did, |
| 495 | vport->fc_flag, |
| 496 | vport->fc_rscn_id_cnt); |
James Smart | bd2cdd5 | 2017-02-12 13:52:33 -0800 | [diff] [blame] | 497 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 498 | } else { |
| 499 | if (!(vport->fc_flag & FC_RSCN_MODE) || |
| 500 | lpfc_rscn_payload_check(vport, Did)) { |
James Smart | bd2cdd5 | 2017-02-12 13:52:33 -0800 | [diff] [blame] | 501 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 502 | "Query GID_FTrsp: did:x%x flg:x%x cnt:%d", |
| 503 | Did, vport->fc_flag, vport->fc_rscn_id_cnt); |
| 504 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 505 | /* |
James Smart | b57ab746 | 2017-06-01 21:07:08 -0700 | [diff] [blame] | 506 | * This NPortID was previously a FCP/NVMe target, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 507 | * Don't even bother to send GFF_ID. |
| 508 | */ |
| 509 | ndlp = lpfc_findnode_did(vport, Did); |
James Smart | b57ab746 | 2017-06-01 21:07:08 -0700 | [diff] [blame] | 510 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 511 | (ndlp->nlp_type & |
| 512 | (NLP_FCP_TARGET | NLP_NVME_TARGET))) { |
| 513 | if (fc4_type == FC_TYPE_FCP) |
| 514 | ndlp->nlp_fc4_type |= NLP_FC4_FCP; |
| 515 | if (fc4_type == FC_TYPE_NVME) |
| 516 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; |
| 517 | lpfc_setup_disc_node(vport, Did); |
| 518 | } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID, |
| 519 | 0, Did) == 0) |
| 520 | vport->num_disc_nodes++; |
| 521 | else |
| 522 | lpfc_setup_disc_node(vport, Did); |
James Smart | bd2cdd5 | 2017-02-12 13:52:33 -0800 | [diff] [blame] | 523 | } else { |
| 524 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 525 | "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d", |
| 526 | Did, vport->fc_flag, vport->fc_rscn_id_cnt); |
| 527 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 528 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 529 | "0245 Skip x%06x NameServer Rsp " |
| 530 | "Data: x%x x%x\n", Did, |
| 531 | vport->fc_flag, |
| 532 | vport->fc_rscn_id_cnt); |
James Smart | bd2cdd5 | 2017-02-12 13:52:33 -0800 | [diff] [blame] | 533 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 537 | static void |
| 538 | lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type) |
| 539 | { |
| 540 | struct lpfc_hba *phba = vport->phba; |
| 541 | struct lpfc_nodelist *ndlp = NULL; |
| 542 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 543 | |
| 544 | /* |
| 545 | * To conserve rpi's, filter out addresses for other |
| 546 | * vports on the same physical HBAs. |
| 547 | */ |
| 548 | if (Did != vport->fc_myDID && |
| 549 | (!lpfc_find_vport_by_did(phba, Did) || |
| 550 | vport->cfg_peer_port_login)) { |
| 551 | if (!phba->nvmet_support) { |
| 552 | /* FCPI/NVMEI path. Process Did */ |
| 553 | lpfc_prep_node_fc4type(vport, Did, fc4_type); |
| 554 | return; |
| 555 | } |
| 556 | /* NVMET path. NVMET only cares about NVMEI nodes. */ |
| 557 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 558 | if (ndlp->nlp_type != NLP_NVME_INITIATOR || |
| 559 | ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) |
| 560 | continue; |
| 561 | spin_lock_irq(shost->host_lock); |
| 562 | if (ndlp->nlp_DID == Did) |
| 563 | ndlp->nlp_flag &= ~NLP_NVMET_RECOV; |
| 564 | else |
| 565 | ndlp->nlp_flag |= NLP_NVMET_RECOV; |
| 566 | spin_unlock_irq(shost->host_lock); |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 571 | static int |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 572 | lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type, |
| 573 | uint32_t Size) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 574 | { |
| 575 | struct lpfc_sli_ct_request *Response = |
| 576 | (struct lpfc_sli_ct_request *) mp->virt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 577 | struct lpfc_dmabuf *mlast, *next_mp; |
| 578 | uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 579 | uint32_t Did, CTentry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 580 | int Cnt; |
| 581 | struct list_head head; |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 582 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 583 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 584 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 585 | lpfc_set_disctmo(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 586 | vport->num_disc_nodes = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 587 | vport->fc_ns_retry = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 588 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 589 | |
| 590 | list_add_tail(&head, &mp->list); |
| 591 | list_for_each_entry_safe(mp, next_mp, &head, list) { |
| 592 | mlast = mp; |
| 593 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 594 | Cnt = Size > FCELSSIZE ? FCELSSIZE : Size; |
| 595 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 596 | Size -= Cnt; |
| 597 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 598 | if (!ctptr) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 | ctptr = (uint32_t *) mlast->virt; |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 600 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 601 | Cnt -= 16; /* subtract length of CT header */ |
| 602 | |
| 603 | /* Loop through entire NameServer list of DIDs */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 604 | while (Cnt >= sizeof(uint32_t)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 605 | /* Get next DID from NameServer List */ |
| 606 | CTentry = *ctptr++; |
| 607 | Did = ((be32_to_cpu(CTentry)) & Mask_DID); |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 608 | lpfc_ns_rsp_audit_did(vport, Did, fc4_type); |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 609 | if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY))) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 610 | goto nsout1; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 611 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 612 | Cnt -= sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 613 | } |
| 614 | ctptr = NULL; |
| 615 | |
| 616 | } |
| 617 | |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 618 | /* All GID_FT entries processed. If the driver is running in |
| 619 | * in target mode, put impacted nodes into recovery and drop |
| 620 | * the RPI to flush outstanding IO. |
| 621 | */ |
| 622 | if (vport->phba->nvmet_support) { |
| 623 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 624 | if (!(ndlp->nlp_flag & NLP_NVMET_RECOV)) |
| 625 | continue; |
| 626 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 627 | NLP_EVT_DEVICE_RECOVERY); |
| 628 | spin_lock_irq(shost->host_lock); |
| 629 | ndlp->nlp_flag &= ~NLP_NVMET_RECOV; |
Dan Carpenter | 0d618cf | 2017-05-04 00:22:16 +0300 | [diff] [blame] | 630 | spin_unlock_irq(shost->host_lock); |
James Smart | 1c5b12f | 2017-04-21 16:05:03 -0700 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 634 | nsout1: |
| 635 | list_del(&head); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 639 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 640 | lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 641 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 642 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 643 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 644 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 645 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 646 | struct lpfc_dmabuf *outp; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 647 | struct lpfc_dmabuf *inp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 648 | struct lpfc_sli_ct_request *CTrsp; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 649 | struct lpfc_sli_ct_request *CTreq; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 650 | struct lpfc_nodelist *ndlp; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 651 | int rc, type; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 652 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 653 | /* First save ndlp, before we overwrite it */ |
| 654 | ndlp = cmdiocb->context_un.ndlp; |
| 655 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 656 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 657 | cmdiocb->context_un.rsp_iocb = rspiocb; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 658 | inp = (struct lpfc_dmabuf *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 659 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 660 | irsp = &rspiocb->iocb; |
| 661 | |
| 662 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 663 | "GID_FT cmpl: status:x%x/x%x rtry:%d", |
| 664 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 665 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 666 | /* Don't bother processing response if vport is being torn down. */ |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 667 | if (vport->load_flag & FC_UNLOADING) { |
| 668 | if (vport->fc_flag & FC_RSCN_MODE) |
| 669 | lpfc_els_flush_rscn(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 670 | goto out; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 671 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 672 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 673 | if (lpfc_els_chk_latt(vport)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 674 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 675 | "0216 Link event during NS query\n"); |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 676 | if (vport->fc_flag & FC_RSCN_MODE) |
| 677 | lpfc_els_flush_rscn(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 678 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 679 | goto out; |
| 680 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 681 | if (lpfc_error_lost_link(irsp)) { |
| 682 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 683 | "0226 NS query failed due to link event\n"); |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 684 | if (vport->fc_flag & FC_RSCN_MODE) |
| 685 | lpfc_els_flush_rscn(vport); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 686 | goto out; |
| 687 | } |
James Smart | 4938250 | 2017-11-20 16:00:38 -0800 | [diff] [blame^] | 688 | |
| 689 | spin_lock_irq(shost->host_lock); |
| 690 | if (vport->fc_flag & FC_RSCN_DEFERRED) { |
| 691 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
| 692 | spin_unlock_irq(shost->host_lock); |
| 693 | |
| 694 | /* |
| 695 | * Skip processing the NS response |
| 696 | * Re-issue the NS cmd |
| 697 | */ |
| 698 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 699 | "0151 Process Deferred RSCN Data: x%x x%x\n", |
| 700 | vport->fc_flag, vport->fc_rscn_id_cnt); |
| 701 | lpfc_els_handle_rscn(vport); |
| 702 | |
| 703 | goto out; |
| 704 | } |
| 705 | spin_unlock_irq(shost->host_lock); |
| 706 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 707 | if (irsp->ulpStatus) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 708 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 709 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 710 | if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT || |
James Smart | edb22f0 | 2012-10-31 14:45:21 -0400 | [diff] [blame] | 711 | (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 712 | IOERR_NO_RESOURCES) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 713 | vport->fc_ns_retry++; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 714 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 715 | type = lpfc_get_gidft_type(vport, cmdiocb); |
| 716 | if (type == 0) |
| 717 | goto out; |
| 718 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 719 | /* CT command is being retried */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 720 | vport->gidft_inp--; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 721 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 722 | vport->fc_ns_retry, type); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 723 | if (rc == 0) |
| 724 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 725 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 726 | if (vport->fc_flag & FC_RSCN_MODE) |
| 727 | lpfc_els_flush_rscn(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 728 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 729 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 730 | "0257 GID_FT Query error: 0x%x 0x%x\n", |
| 731 | irsp->ulpStatus, vport->fc_ns_retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 732 | } else { |
| 733 | /* Good status, continue checking */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 734 | CTreq = (struct lpfc_sli_ct_request *) inp->virt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 735 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; |
| 736 | if (CTrsp->CommandResponse.bits.CmdRsp == |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 737 | cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 738 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 739 | "0208 NameServer Rsp Data: x%x x%x\n", |
| 740 | vport->fc_flag, |
| 741 | CTreq->un.gid.Fc4Type); |
| 742 | |
| 743 | lpfc_ns_rsp(vport, |
| 744 | outp, |
| 745 | CTreq->un.gid.Fc4Type, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 746 | (uint32_t) (irsp->un.genreq64.bdl.bdeSize)); |
| 747 | } else if (CTrsp->CommandResponse.bits.CmdRsp == |
| 748 | be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) { |
| 749 | /* NameServer Rsp Error */ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 750 | if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ) |
| 751 | && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 752 | lpfc_printf_vlog(vport, KERN_INFO, |
| 753 | LOG_DISCOVERY, |
| 754 | "0269 No NameServer Entries " |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 755 | "Data: x%x x%x x%x x%x\n", |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 756 | CTrsp->CommandResponse.bits.CmdRsp, |
| 757 | (uint32_t) CTrsp->ReasonCode, |
| 758 | (uint32_t) CTrsp->Explanation, |
| 759 | vport->fc_flag); |
| 760 | |
| 761 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 762 | "GID_FT no entry cmd:x%x rsn:x%x exp:x%x", |
| 763 | (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, |
| 764 | (uint32_t) CTrsp->ReasonCode, |
| 765 | (uint32_t) CTrsp->Explanation); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 766 | } else { |
| 767 | lpfc_printf_vlog(vport, KERN_INFO, |
| 768 | LOG_DISCOVERY, |
| 769 | "0240 NameServer Rsp Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 770 | "Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 771 | CTrsp->CommandResponse.bits.CmdRsp, |
| 772 | (uint32_t) CTrsp->ReasonCode, |
| 773 | (uint32_t) CTrsp->Explanation, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 774 | vport->fc_flag); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 775 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 776 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 777 | "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x", |
| 778 | (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, |
| 779 | (uint32_t) CTrsp->ReasonCode, |
| 780 | (uint32_t) CTrsp->Explanation); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 781 | } |
| 782 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 783 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 784 | } else { |
| 785 | /* NameServer Rsp Error */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 786 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 787 | "0241 NameServer Rsp Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 788 | "Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 789 | CTrsp->CommandResponse.bits.CmdRsp, |
| 790 | (uint32_t) CTrsp->ReasonCode, |
| 791 | (uint32_t) CTrsp->Explanation, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 792 | vport->fc_flag); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 793 | |
| 794 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 795 | "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x", |
| 796 | (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, |
| 797 | (uint32_t) CTrsp->ReasonCode, |
| 798 | (uint32_t) CTrsp->Explanation); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 799 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 800 | vport->gidft_inp--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 801 | } |
| 802 | /* Link up / RSCN discovery */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 803 | if ((vport->num_disc_nodes == 0) && |
| 804 | (vport->gidft_inp == 0)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 805 | /* |
| 806 | * The driver has cycled through all Nports in the RSCN payload. |
| 807 | * Complete the handling by cleaning up and marking the |
| 808 | * current driver state. |
| 809 | */ |
| 810 | if (vport->port_state >= LPFC_DISC_AUTH) { |
| 811 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 812 | lpfc_els_flush_rscn(vport); |
| 813 | spin_lock_irq(shost->host_lock); |
| 814 | vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */ |
| 815 | spin_unlock_irq(shost->host_lock); |
| 816 | } |
| 817 | else |
| 818 | lpfc_els_flush_rscn(vport); |
| 819 | } |
| 820 | |
| 821 | lpfc_disc_start(vport); |
| 822 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 823 | out: |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 824 | cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 825 | lpfc_ct_free_iocb(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 826 | return; |
| 827 | } |
| 828 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 829 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 830 | lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 831 | struct lpfc_iocbq *rspiocb) |
| 832 | { |
| 833 | struct lpfc_vport *vport = cmdiocb->vport; |
| 834 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 835 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 836 | struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1; |
| 837 | struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 838 | struct lpfc_sli_ct_request *CTrsp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 839 | int did, rc, retry; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 840 | uint8_t fbits; |
| 841 | struct lpfc_nodelist *ndlp; |
| 842 | |
| 843 | did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId; |
| 844 | did = be32_to_cpu(did); |
| 845 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 846 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 847 | "GFF_ID cmpl: status:x%x/x%x did:x%x", |
| 848 | irsp->ulpStatus, irsp->un.ulpWord[4], did); |
| 849 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 850 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 851 | /* Good status, continue checking */ |
| 852 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; |
| 853 | fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET]; |
| 854 | |
| 855 | if (CTrsp->CommandResponse.bits.CmdRsp == |
| 856 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) { |
| 857 | if ((fbits & FC4_FEATURE_INIT) && |
| 858 | !(fbits & FC4_FEATURE_TARGET)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 859 | lpfc_printf_vlog(vport, KERN_INFO, |
| 860 | LOG_DISCOVERY, |
| 861 | "0270 Skip x%x GFF " |
| 862 | "NameServer Rsp Data: (init) " |
| 863 | "x%x x%x\n", did, fbits, |
| 864 | vport->fc_rscn_id_cnt); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 865 | goto out; |
| 866 | } |
| 867 | } |
| 868 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 869 | else { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 870 | /* Check for retry */ |
| 871 | if (cmdiocb->retry < LPFC_MAX_NS_RETRY) { |
| 872 | retry = 1; |
| 873 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 874 | switch ((irsp->un.ulpWord[4] & |
| 875 | IOERR_PARAM_MASK)) { |
| 876 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 877 | case IOERR_NO_RESOURCES: |
| 878 | /* We don't increment the retry |
| 879 | * count for this case. |
| 880 | */ |
| 881 | break; |
| 882 | case IOERR_LINK_DOWN: |
| 883 | case IOERR_SLI_ABORTED: |
| 884 | case IOERR_SLI_DOWN: |
| 885 | retry = 0; |
| 886 | break; |
| 887 | default: |
| 888 | cmdiocb->retry++; |
| 889 | } |
| 890 | } |
| 891 | else |
| 892 | cmdiocb->retry++; |
| 893 | |
| 894 | if (retry) { |
| 895 | /* CT command is being retried */ |
| 896 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID, |
| 897 | cmdiocb->retry, did); |
| 898 | if (rc == 0) { |
| 899 | /* success */ |
| 900 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 901 | return; |
| 902 | } |
| 903 | } |
| 904 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 905 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 906 | "0267 NameServer GFF Rsp " |
| 907 | "x%x Error (%d %d) Data: x%x x%x\n", |
| 908 | did, irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 909 | vport->fc_flag, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 910 | } |
| 911 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 912 | /* This is a target port, unregistered port, or the GFF_ID failed */ |
| 913 | ndlp = lpfc_setup_disc_node(vport, did); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 914 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 915 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 916 | "0242 Process x%x GFF " |
| 917 | "NameServer Rsp Data: x%x x%x x%x\n", |
| 918 | did, ndlp->nlp_flag, vport->fc_flag, |
| 919 | vport->fc_rscn_id_cnt); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 920 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 921 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 922 | "0243 Skip x%x GFF " |
| 923 | "NameServer Rsp Data: x%x x%x\n", did, |
| 924 | vport->fc_flag, vport->fc_rscn_id_cnt); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 925 | } |
| 926 | out: |
| 927 | /* Link up / RSCN discovery */ |
| 928 | if (vport->num_disc_nodes) |
| 929 | vport->num_disc_nodes--; |
| 930 | if (vport->num_disc_nodes == 0) { |
| 931 | /* |
| 932 | * The driver has cycled through all Nports in the RSCN payload. |
| 933 | * Complete the handling by cleaning up and marking the |
| 934 | * current driver state. |
| 935 | */ |
| 936 | if (vport->port_state >= LPFC_DISC_AUTH) { |
| 937 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 938 | lpfc_els_flush_rscn(vport); |
| 939 | spin_lock_irq(shost->host_lock); |
| 940 | vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */ |
| 941 | spin_unlock_irq(shost->host_lock); |
| 942 | } |
| 943 | else |
| 944 | lpfc_els_flush_rscn(vport); |
| 945 | } |
| 946 | lpfc_disc_start(vport); |
| 947 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 948 | lpfc_ct_free_iocb(phba, cmdiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 949 | return; |
| 950 | } |
| 951 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 952 | static void |
| 953 | lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 954 | struct lpfc_iocbq *rspiocb) |
| 955 | { |
| 956 | struct lpfc_vport *vport = cmdiocb->vport; |
| 957 | IOCB_t *irsp = &rspiocb->iocb; |
| 958 | struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1; |
| 959 | struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 960 | struct lpfc_sli_ct_request *CTrsp; |
| 961 | int did; |
| 962 | struct lpfc_nodelist *ndlp; |
| 963 | uint32_t fc4_data_0, fc4_data_1; |
| 964 | |
| 965 | did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId; |
| 966 | did = be32_to_cpu(did); |
| 967 | |
James Smart | bd2cdd5 | 2017-02-12 13:52:33 -0800 | [diff] [blame] | 968 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 969 | "GFT_ID cmpl: status:x%x/x%x did:x%x", |
| 970 | irsp->ulpStatus, irsp->un.ulpWord[4], did); |
| 971 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 972 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 973 | /* Good status, continue checking */ |
| 974 | CTrsp = (struct lpfc_sli_ct_request *)outp->virt; |
| 975 | fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]); |
| 976 | fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]); |
Dick Kennedy | ffb70cd | 2017-08-23 16:55:34 -0700 | [diff] [blame] | 977 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 978 | "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n", |
| 979 | did, fc4_data_0, fc4_data_1); |
| 980 | |
| 981 | ndlp = lpfc_findnode_did(vport, did); |
| 982 | if (ndlp) { |
| 983 | /* The bitmask value for FCP and NVME FCP types is |
| 984 | * the same because they are 32 bits distant from |
| 985 | * each other in word0 and word0. |
| 986 | */ |
| 987 | if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) |
| 988 | ndlp->nlp_fc4_type |= NLP_FC4_FCP; |
| 989 | if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) |
| 990 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; |
Dick Kennedy | ffb70cd | 2017-08-23 16:55:34 -0700 | [diff] [blame] | 991 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 992 | "3064 Setting ndlp %p, DID x%06x with " |
| 993 | "FC4 x%08x, Data: x%08x x%08x\n", |
| 994 | ndlp, did, ndlp->nlp_fc4_type, |
| 995 | FC_TYPE_FCP, FC_TYPE_NVME); |
James Smart | b5ccc7d | 2017-03-04 09:30:39 -0800 | [diff] [blame] | 996 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; |
Gustavo A. R. Silva | e6ef6a7 | 2017-05-23 10:09:28 -0500 | [diff] [blame] | 997 | |
| 998 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 999 | lpfc_issue_els_prli(vport, ndlp, 0); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1000 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1001 | } else |
| 1002 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1003 | "3065 GFT_ID failed x%08x\n", irsp->ulpStatus); |
| 1004 | |
| 1005 | lpfc_ct_free_iocb(phba, cmdiocb); |
| 1006 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1007 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1008 | static void |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1009 | lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1010 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1011 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1012 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1013 | struct lpfc_dmabuf *inp; |
| 1014 | struct lpfc_dmabuf *outp; |
| 1015 | IOCB_t *irsp; |
| 1016 | struct lpfc_sli_ct_request *CTrsp; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1017 | struct lpfc_nodelist *ndlp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1018 | int cmdcode, rc; |
| 1019 | uint8_t retry; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1020 | uint32_t latt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1021 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1022 | /* First save ndlp, before we overwrite it */ |
| 1023 | ndlp = cmdiocb->context_un.ndlp; |
| 1024 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1025 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1026 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1027 | |
| 1028 | inp = (struct lpfc_dmabuf *) cmdiocb->context1; |
| 1029 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1030 | irsp = &rspiocb->iocb; |
| 1031 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1032 | cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)-> |
| 1033 | CommandResponse.bits.CmdRsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1034 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; |
| 1035 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1036 | latt = lpfc_els_chk_latt(vport); |
| 1037 | |
| 1038 | /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1039 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1040 | "0209 CT Request completes, latt %d, " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1041 | "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n", |
| 1042 | latt, irsp->ulpStatus, |
| 1043 | CTrsp->CommandResponse.bits.CmdRsp, |
| 1044 | cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1045 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1046 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 1047 | "CT cmd cmpl: status:x%x/x%x cmd:x%x", |
| 1048 | irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode); |
| 1049 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1050 | if (irsp->ulpStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1051 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | 6e15520 | 2013-07-15 18:35:21 -0400 | [diff] [blame] | 1052 | "0268 NS cmd x%x Error (x%x x%x)\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1053 | cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1054 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1055 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
James Smart | e3d2b80 | 2012-08-14 14:25:43 -0400 | [diff] [blame] | 1056 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1057 | IOERR_SLI_DOWN) || |
| 1058 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
| 1059 | IOERR_SLI_ABORTED))) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1060 | goto out; |
| 1061 | |
| 1062 | retry = cmdiocb->retry; |
| 1063 | if (retry >= LPFC_MAX_NS_RETRY) |
| 1064 | goto out; |
| 1065 | |
| 1066 | retry++; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1067 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1068 | "0250 Retrying NS cmd %x\n", cmdcode); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1069 | rc = lpfc_ns_cmd(vport, cmdcode, retry, 0); |
| 1070 | if (rc == 0) |
| 1071 | goto out; |
| 1072 | } |
| 1073 | |
| 1074 | out: |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1075 | cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1076 | lpfc_ct_free_iocb(phba, cmdiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1077 | return; |
| 1078 | } |
| 1079 | |
| 1080 | static void |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1081 | lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1082 | struct lpfc_iocbq *rspiocb) |
| 1083 | { |
| 1084 | IOCB_t *irsp = &rspiocb->iocb; |
| 1085 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1086 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1087 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 1088 | struct lpfc_dmabuf *outp; |
| 1089 | struct lpfc_sli_ct_request *CTrsp; |
| 1090 | |
| 1091 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 1092 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; |
| 1093 | if (CTrsp->CommandResponse.bits.CmdRsp == |
| 1094 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) |
| 1095 | vport->ct_flags |= FC_CT_RFT_ID; |
| 1096 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1097 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
| 1098 | return; |
| 1099 | } |
| 1100 | |
| 1101 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1102 | lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1103 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1104 | { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1105 | IOCB_t *irsp = &rspiocb->iocb; |
| 1106 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1107 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1108 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 1109 | struct lpfc_dmabuf *outp; |
| 1110 | struct lpfc_sli_ct_request *CTrsp; |
| 1111 | |
| 1112 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 1113 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; |
| 1114 | if (CTrsp->CommandResponse.bits.CmdRsp == |
| 1115 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) |
| 1116 | vport->ct_flags |= FC_CT_RNN_ID; |
| 1117 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1118 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1119 | return; |
| 1120 | } |
| 1121 | |
| 1122 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1123 | lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1124 | struct lpfc_iocbq *rspiocb) |
| 1125 | { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1126 | IOCB_t *irsp = &rspiocb->iocb; |
| 1127 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1128 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1129 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 1130 | struct lpfc_dmabuf *outp; |
| 1131 | struct lpfc_sli_ct_request *CTrsp; |
| 1132 | |
| 1133 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 1134 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; |
| 1135 | if (CTrsp->CommandResponse.bits.CmdRsp == |
| 1136 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) |
| 1137 | vport->ct_flags |= FC_CT_RSPN_ID; |
| 1138 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1139 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1140 | return; |
| 1141 | } |
| 1142 | |
| 1143 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1144 | lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1145 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1146 | { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1147 | IOCB_t *irsp = &rspiocb->iocb; |
| 1148 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1149 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1150 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 1151 | struct lpfc_dmabuf *outp; |
| 1152 | struct lpfc_sli_ct_request *CTrsp; |
| 1153 | |
| 1154 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 1155 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; |
| 1156 | if (CTrsp->CommandResponse.bits.CmdRsp == |
| 1157 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) |
| 1158 | vport->ct_flags |= FC_CT_RSNN_NN; |
| 1159 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1160 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
| 1161 | return; |
| 1162 | } |
| 1163 | |
| 1164 | static void |
| 1165 | lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1166 | struct lpfc_iocbq *rspiocb) |
| 1167 | { |
| 1168 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1169 | |
| 1170 | /* even if it fails we will act as though it succeeded. */ |
| 1171 | vport->ct_flags = 0; |
| 1172 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1173 | return; |
| 1174 | } |
| 1175 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1176 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1177 | lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1178 | struct lpfc_iocbq *rspiocb) |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1179 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1180 | IOCB_t *irsp = &rspiocb->iocb; |
| 1181 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1182 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1183 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
| 1184 | struct lpfc_dmabuf *outp; |
| 1185 | struct lpfc_sli_ct_request *CTrsp; |
| 1186 | |
| 1187 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 1188 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; |
| 1189 | if (CTrsp->CommandResponse.bits.CmdRsp == |
| 1190 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) |
| 1191 | vport->ct_flags |= FC_CT_RFF_ID; |
| 1192 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1193 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1194 | return; |
| 1195 | } |
| 1196 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1197 | /* |
| 1198 | * Although the symbolic port name is thought to be an integer |
| 1199 | * as of January 18, 2016, leave it as a string until more of |
| 1200 | * the record state becomes defined. |
| 1201 | */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1202 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1203 | lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol, |
| 1204 | size_t size) |
| 1205 | { |
| 1206 | int n; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1207 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1208 | /* |
| 1209 | * Use the lpfc board number as the Symbolic Port |
| 1210 | * Name object. NPIV is not in play so this integer |
| 1211 | * value is sufficient and unique per FC-ID. |
| 1212 | */ |
| 1213 | n = snprintf(symbol, size, "%d", vport->phba->brd_no); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1214 | return n; |
| 1215 | } |
| 1216 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1217 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1218 | int |
| 1219 | lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol, |
| 1220 | size_t size) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1221 | { |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1222 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1223 | int n; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1224 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1225 | lpfc_decode_firmware_rev(vport->phba, fwrev, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1226 | |
James Smart | f0bf5f9 | 2015-04-07 15:07:18 -0400 | [diff] [blame] | 1227 | n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName); |
James Smart | f0bf5f9 | 2015-04-07 15:07:18 -0400 | [diff] [blame] | 1228 | if (size < n) |
| 1229 | return n; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1230 | |
James Smart | f0bf5f9 | 2015-04-07 15:07:18 -0400 | [diff] [blame] | 1231 | n += snprintf(symbol + n, size - n, " FV%s", fwrev); |
James Smart | f0bf5f9 | 2015-04-07 15:07:18 -0400 | [diff] [blame] | 1232 | if (size < n) |
| 1233 | return n; |
James Smart | f0bf5f9 | 2015-04-07 15:07:18 -0400 | [diff] [blame] | 1234 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1235 | n += snprintf(symbol + n, size - n, " DV%s.", |
| 1236 | lpfc_release_version); |
James Smart | f0bf5f9 | 2015-04-07 15:07:18 -0400 | [diff] [blame] | 1237 | if (size < n) |
| 1238 | return n; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1239 | |
| 1240 | n += snprintf(symbol + n, size - n, " HN:%s.", |
| 1241 | init_utsname()->nodename); |
| 1242 | if (size < n) |
| 1243 | return n; |
James Smart | f0bf5f9 | 2015-04-07 15:07:18 -0400 | [diff] [blame] | 1244 | |
| 1245 | /* Note :- OS name is "Linux" */ |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1246 | n += snprintf(symbol + n, size - n, " OS:%s\n", |
| 1247 | init_utsname()->sysname); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1248 | return n; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1249 | } |
| 1250 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1251 | static uint32_t |
| 1252 | lpfc_find_map_node(struct lpfc_vport *vport) |
| 1253 | { |
| 1254 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 1255 | struct Scsi_Host *shost; |
| 1256 | uint32_t cnt = 0; |
| 1257 | |
| 1258 | shost = lpfc_shost_from_vport(vport); |
| 1259 | spin_lock_irq(shost->host_lock); |
| 1260 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
| 1261 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1262 | continue; |
| 1263 | if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) || |
| 1264 | (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)) |
| 1265 | cnt++; |
| 1266 | } |
| 1267 | spin_unlock_irq(shost->host_lock); |
| 1268 | return cnt; |
| 1269 | } |
| 1270 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1271 | /* |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1272 | * This routine will return the FC4 Type associated with the CT |
| 1273 | * GID_FT command. |
| 1274 | */ |
| 1275 | int |
| 1276 | lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb) |
| 1277 | { |
| 1278 | struct lpfc_sli_ct_request *CtReq; |
| 1279 | struct lpfc_dmabuf *mp; |
| 1280 | uint32_t type; |
| 1281 | |
| 1282 | mp = cmdiocb->context1; |
| 1283 | if (mp == NULL) |
| 1284 | return 0; |
| 1285 | CtReq = (struct lpfc_sli_ct_request *)mp->virt; |
| 1286 | type = (uint32_t)CtReq->un.gid.Fc4Type; |
| 1287 | if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME)) |
| 1288 | return 0; |
| 1289 | return type; |
| 1290 | } |
| 1291 | |
| 1292 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1293 | * lpfc_ns_cmd |
| 1294 | * Description: |
| 1295 | * Issue Cmd to NameServer |
| 1296 | * SLI_CTNS_GID_FT |
| 1297 | * LI_CTNS_RFT_ID |
| 1298 | */ |
| 1299 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1300 | lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode, |
| 1301 | uint8_t retry, uint32_t context) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1302 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1303 | struct lpfc_nodelist * ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1304 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1305 | struct lpfc_dmabuf *mp, *bmp; |
| 1306 | struct lpfc_sli_ct_request *CtReq; |
| 1307 | struct ulp_bde64 *bpl; |
| 1308 | void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, |
| 1309 | struct lpfc_iocbq *) = NULL; |
| 1310 | uint32_t rsp_size = 1024; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1311 | size_t size; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1312 | int rc = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1313 | |
| 1314 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1315 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) |
| 1316 | || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1317 | rc=1; |
| 1318 | goto ns_cmd_exit; |
| 1319 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1320 | |
| 1321 | /* fill in BDEs for command */ |
| 1322 | /* Allocate buffer for command payload */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1323 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1324 | if (!mp) { |
| 1325 | rc=2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1326 | goto ns_cmd_exit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1327 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1328 | |
| 1329 | INIT_LIST_HEAD(&mp->list); |
| 1330 | mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1331 | if (!mp->virt) { |
| 1332 | rc=3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1333 | goto ns_cmd_free_mp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1334 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | |
| 1336 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1337 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1338 | if (!bmp) { |
| 1339 | rc=4; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1340 | goto ns_cmd_free_mpvirt; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1341 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1342 | |
| 1343 | INIT_LIST_HEAD(&bmp->list); |
| 1344 | bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1345 | if (!bmp->virt) { |
| 1346 | rc=5; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1347 | goto ns_cmd_free_bmp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1348 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1349 | |
| 1350 | /* NameServer Req */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1351 | lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY, |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1352 | "0236 NameServer Req Data: x%x x%x x%x x%x\n", |
| 1353 | cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt, |
| 1354 | context); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1355 | |
| 1356 | bpl = (struct ulp_bde64 *) bmp->virt; |
| 1357 | memset(bpl, 0, sizeof(struct ulp_bde64)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1358 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) ); |
| 1359 | bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) ); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1360 | bpl->tus.f.bdeFlags = 0; |
| 1361 | if (cmdcode == SLI_CTNS_GID_FT) |
| 1362 | bpl->tus.f.bdeSize = GID_REQUEST_SZ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1363 | else if (cmdcode == SLI_CTNS_GFF_ID) |
| 1364 | bpl->tus.f.bdeSize = GFF_REQUEST_SZ; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1365 | else if (cmdcode == SLI_CTNS_GFT_ID) |
| 1366 | bpl->tus.f.bdeSize = GFT_REQUEST_SZ; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1367 | else if (cmdcode == SLI_CTNS_RFT_ID) |
| 1368 | bpl->tus.f.bdeSize = RFT_REQUEST_SZ; |
| 1369 | else if (cmdcode == SLI_CTNS_RNN_ID) |
| 1370 | bpl->tus.f.bdeSize = RNN_REQUEST_SZ; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1371 | else if (cmdcode == SLI_CTNS_RSPN_ID) |
| 1372 | bpl->tus.f.bdeSize = RSPN_REQUEST_SZ; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1373 | else if (cmdcode == SLI_CTNS_RSNN_NN) |
| 1374 | bpl->tus.f.bdeSize = RSNN_REQUEST_SZ; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1375 | else if (cmdcode == SLI_CTNS_DA_ID) |
| 1376 | bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ; |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 1377 | else if (cmdcode == SLI_CTNS_RFF_ID) |
| 1378 | bpl->tus.f.bdeSize = RFF_REQUEST_SZ; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1379 | else |
| 1380 | bpl->tus.f.bdeSize = 0; |
| 1381 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 1382 | |
| 1383 | CtReq = (struct lpfc_sli_ct_request *) mp->virt; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1384 | memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1385 | CtReq->RevisionId.bits.Revision = SLI_CT_REVISION; |
| 1386 | CtReq->RevisionId.bits.InId = 0; |
| 1387 | CtReq->FsType = SLI_CT_DIRECTORY_SERVICE; |
| 1388 | CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER; |
| 1389 | CtReq->CommandResponse.bits.Size = 0; |
| 1390 | switch (cmdcode) { |
| 1391 | case SLI_CTNS_GID_FT: |
| 1392 | CtReq->CommandResponse.bits.CmdRsp = |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1393 | cpu_to_be16(SLI_CTNS_GID_FT); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1394 | CtReq->un.gid.Fc4Type = context; |
| 1395 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1396 | if (vport->port_state < LPFC_NS_QRY) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1397 | vport->port_state = LPFC_NS_QRY; |
| 1398 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1399 | cmpl = lpfc_cmpl_ct_cmd_gid_ft; |
| 1400 | rsp_size = FC_MAX_NS_RSP; |
| 1401 | break; |
| 1402 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1403 | case SLI_CTNS_GFF_ID: |
| 1404 | CtReq->CommandResponse.bits.CmdRsp = |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1405 | cpu_to_be16(SLI_CTNS_GFF_ID); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1406 | CtReq->un.gff.PortId = cpu_to_be32(context); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1407 | cmpl = lpfc_cmpl_ct_cmd_gff_id; |
| 1408 | break; |
| 1409 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1410 | case SLI_CTNS_GFT_ID: |
| 1411 | CtReq->CommandResponse.bits.CmdRsp = |
| 1412 | cpu_to_be16(SLI_CTNS_GFT_ID); |
| 1413 | CtReq->un.gft.PortId = cpu_to_be32(context); |
| 1414 | cmpl = lpfc_cmpl_ct_cmd_gft_id; |
| 1415 | break; |
| 1416 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1417 | case SLI_CTNS_RFT_ID: |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1418 | vport->ct_flags &= ~FC_CT_RFT_ID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1419 | CtReq->CommandResponse.bits.CmdRsp = |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1420 | cpu_to_be16(SLI_CTNS_RFT_ID); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1421 | CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID); |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1422 | |
| 1423 | /* Register FC4 FCP type if enabled. */ |
| 1424 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 1425 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) |
| 1426 | CtReq->un.rft.fcpReg = 1; |
| 1427 | |
| 1428 | /* Register NVME type if enabled. Defined LE and swapped. |
| 1429 | * rsvd[0] is used as word1 because of the hard-coded |
| 1430 | * word0 usage in the ct_request data structure. |
| 1431 | */ |
| 1432 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 1433 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) |
| 1434 | CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100); |
| 1435 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1436 | cmpl = lpfc_cmpl_ct_cmd_rft_id; |
| 1437 | break; |
| 1438 | |
| 1439 | case SLI_CTNS_RNN_ID: |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1440 | vport->ct_flags &= ~FC_CT_RNN_ID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1441 | CtReq->CommandResponse.bits.CmdRsp = |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1442 | cpu_to_be16(SLI_CTNS_RNN_ID); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1443 | CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1444 | memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename, |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1445 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1446 | cmpl = lpfc_cmpl_ct_cmd_rnn_id; |
| 1447 | break; |
| 1448 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1449 | case SLI_CTNS_RSPN_ID: |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1450 | vport->ct_flags &= ~FC_CT_RSPN_ID; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1451 | CtReq->CommandResponse.bits.CmdRsp = |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1452 | cpu_to_be16(SLI_CTNS_RSPN_ID); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1453 | CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1454 | size = sizeof(CtReq->un.rspn.symbname); |
| 1455 | CtReq->un.rspn.len = |
| 1456 | lpfc_vport_symbolic_port_name(vport, |
| 1457 | CtReq->un.rspn.symbname, size); |
| 1458 | cmpl = lpfc_cmpl_ct_cmd_rspn_id; |
| 1459 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1460 | case SLI_CTNS_RSNN_NN: |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1461 | vport->ct_flags &= ~FC_CT_RSNN_NN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1462 | CtReq->CommandResponse.bits.CmdRsp = |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1463 | cpu_to_be16(SLI_CTNS_RSNN_NN); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1464 | memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename, |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1465 | sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1466 | size = sizeof(CtReq->un.rsnn.symbname); |
| 1467 | CtReq->un.rsnn.len = |
| 1468 | lpfc_vport_symbolic_node_name(vport, |
| 1469 | CtReq->un.rsnn.symbname, size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1470 | cmpl = lpfc_cmpl_ct_cmd_rsnn_nn; |
| 1471 | break; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1472 | case SLI_CTNS_DA_ID: |
| 1473 | /* Implement DA_ID Nameserver request */ |
| 1474 | CtReq->CommandResponse.bits.CmdRsp = |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1475 | cpu_to_be16(SLI_CTNS_DA_ID); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1476 | CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1477 | cmpl = lpfc_cmpl_ct_cmd_da_id; |
| 1478 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1479 | case SLI_CTNS_RFF_ID: |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1480 | vport->ct_flags &= ~FC_CT_RFF_ID; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1481 | CtReq->CommandResponse.bits.CmdRsp = |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1482 | cpu_to_be16(SLI_CTNS_RFF_ID); |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 1483 | CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1484 | CtReq->un.rff.fbits = FC4_FEATURE_INIT; |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1485 | |
| 1486 | /* The driver always supports FC_TYPE_FCP. However, the |
| 1487 | * caller can specify NVME (type x28) as well. But only |
| 1488 | * these that FC4 type is supported. |
| 1489 | */ |
| 1490 | if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 1491 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) && |
| 1492 | (context == FC_TYPE_NVME)) { |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 1493 | if ((vport == phba->pport) && phba->nvmet_support) { |
| 1494 | CtReq->un.rff.fbits = (FC4_FEATURE_TARGET | |
| 1495 | FC4_FEATURE_NVME_DISC); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 1496 | lpfc_nvmet_update_targetport(phba); |
James Smart | 8c25864 | 2017-02-12 13:52:36 -0800 | [diff] [blame] | 1497 | } else { |
| 1498 | lpfc_nvme_update_localport(vport); |
| 1499 | } |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1500 | CtReq->un.rff.type_code = context; |
| 1501 | |
| 1502 | } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || |
| 1503 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) && |
| 1504 | (context == FC_TYPE_FCP)) |
| 1505 | CtReq->un.rff.type_code = context; |
| 1506 | |
| 1507 | else |
| 1508 | goto ns_cmd_free_bmpvirt; |
| 1509 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1510 | cmpl = lpfc_cmpl_ct_cmd_rff_id; |
| 1511 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1513 | /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count |
| 1514 | * to hold ndlp reference for the corresponding callback function. |
| 1515 | */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1516 | if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1517 | /* On success, The cmpl function will free the buffers */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1518 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 1519 | "Issue CT cmd: cmd:x%x did:x%x", |
| 1520 | cmdcode, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1521 | return 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1522 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1523 | rc=6; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1524 | |
| 1525 | /* Decrement ndlp reference count to release ndlp reference held |
| 1526 | * for the failed command's callback function. |
| 1527 | */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1528 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1529 | |
James Smart | a0f2d3e | 2017-02-12 13:52:31 -0800 | [diff] [blame] | 1530 | ns_cmd_free_bmpvirt: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1531 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
| 1532 | ns_cmd_free_bmp: |
| 1533 | kfree(bmp); |
| 1534 | ns_cmd_free_mpvirt: |
| 1535 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 1536 | ns_cmd_free_mp: |
| 1537 | kfree(mp); |
| 1538 | ns_cmd_exit: |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1539 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 1540 | "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n", |
| 1541 | cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | return 1; |
| 1543 | } |
| 1544 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1545 | /** |
| 1546 | * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion |
| 1547 | * @phba: Pointer to HBA context object. |
| 1548 | * @cmdiocb: Pointer to the command IOCBQ. |
| 1549 | * @rspiocb: Pointer to the response IOCBQ. |
| 1550 | * |
| 1551 | * This function to handle the completion of a driver initiated FDMI |
| 1552 | * CT command issued during discovery. |
| 1553 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1554 | static void |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1555 | lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1556 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1557 | { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1558 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1559 | struct lpfc_dmabuf *inp = cmdiocb->context1; |
| 1560 | struct lpfc_dmabuf *outp = cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1561 | struct lpfc_sli_ct_request *CTcmd = inp->virt; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1562 | struct lpfc_sli_ct_request *CTrsp = outp->virt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1563 | uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp; |
| 1564 | uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1565 | IOCB_t *irsp = &rspiocb->iocb; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1566 | struct lpfc_nodelist *ndlp; |
| 1567 | uint32_t latt, cmd, err; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1568 | |
| 1569 | latt = lpfc_els_chk_latt(vport); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1570 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
| 1571 | "FDMI cmpl: status:x%x/x%x latt:%d", |
| 1572 | irsp->ulpStatus, irsp->un.ulpWord[4], latt); |
| 1573 | |
| 1574 | if (latt || irsp->ulpStatus) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1575 | |
| 1576 | /* Look for a retryable error */ |
| 1577 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
| 1578 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { |
| 1579 | case IOERR_SLI_ABORTED: |
| 1580 | case IOERR_ABORT_IN_PROGRESS: |
| 1581 | case IOERR_SEQUENCE_TIMEOUT: |
| 1582 | case IOERR_ILLEGAL_FRAME: |
| 1583 | case IOERR_NO_RESOURCES: |
| 1584 | case IOERR_ILLEGAL_COMMAND: |
| 1585 | cmdiocb->retry++; |
| 1586 | if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY) |
| 1587 | break; |
| 1588 | |
| 1589 | /* Retry the same FDMI command */ |
| 1590 | err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, |
| 1591 | cmdiocb, 0); |
| 1592 | if (err == IOCB_ERROR) |
| 1593 | break; |
| 1594 | return; |
| 1595 | default: |
| 1596 | break; |
| 1597 | } |
| 1598 | } |
| 1599 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1600 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1601 | "0229 FDMI cmd %04x failed, latt = %d " |
| 1602 | "ulpStatus: x%x, rid x%x\n", |
| 1603 | be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus, |
| 1604 | irsp->un.ulpWord[4]); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1605 | } |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1606 | lpfc_ct_free_iocb(phba, cmdiocb); |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1607 | |
| 1608 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
| 1609 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 1610 | return; |
| 1611 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1612 | /* Check for a CT LS_RJT response */ |
| 1613 | cmd = be16_to_cpu(fdmi_cmd); |
| 1614 | if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) { |
| 1615 | /* FDMI rsp failed */ |
| 1616 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1617 | "0220 FDMI cmd failed FS_RJT Data: x%x", cmd); |
| 1618 | |
| 1619 | /* Should we fallback to FDMI-2 / FDMI-1 ? */ |
| 1620 | switch (cmd) { |
| 1621 | case SLI_MGMT_RHBA: |
| 1622 | if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) { |
| 1623 | /* Fallback to FDMI-1 */ |
| 1624 | vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR; |
| 1625 | vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; |
| 1626 | /* Start over */ |
| 1627 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); |
| 1628 | } |
| 1629 | return; |
| 1630 | |
| 1631 | case SLI_MGMT_RPRT: |
| 1632 | if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) { |
| 1633 | /* Fallback to FDMI-1 */ |
| 1634 | vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; |
| 1635 | /* Start over */ |
| 1636 | lpfc_fdmi_cmd(vport, ndlp, cmd, 0); |
| 1637 | } |
| 1638 | if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) { |
| 1639 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 1640 | /* Retry the same command */ |
| 1641 | lpfc_fdmi_cmd(vport, ndlp, cmd, 0); |
| 1642 | } |
| 1643 | return; |
| 1644 | |
| 1645 | case SLI_MGMT_RPA: |
| 1646 | if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) { |
| 1647 | /* Fallback to FDMI-1 */ |
| 1648 | vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR; |
| 1649 | vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; |
| 1650 | /* Start over */ |
| 1651 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); |
| 1652 | } |
| 1653 | if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) { |
| 1654 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 1655 | /* Retry the same command */ |
| 1656 | lpfc_fdmi_cmd(vport, ndlp, cmd, 0); |
| 1657 | } |
| 1658 | return; |
| 1659 | } |
| 1660 | } |
| 1661 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1662 | /* |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1663 | * On success, need to cycle thru FDMI registration for discovery |
| 1664 | * DHBA -> DPRT -> RHBA -> RPA (physical port) |
| 1665 | * DPRT -> RPRT (vports) |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1666 | */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1667 | switch (cmd) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1668 | case SLI_MGMT_RHBA: |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1669 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1670 | break; |
| 1671 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1672 | case SLI_MGMT_DHBA: |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1673 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1674 | break; |
| 1675 | |
| 1676 | case SLI_MGMT_DPRT: |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1677 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 1678 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0); |
| 1679 | else |
| 1680 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1681 | break; |
| 1682 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1683 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1684 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1685 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 1686 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1687 | /** |
| 1688 | * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to |
| 1689 | * @vport: pointer to a host virtual N_Port data structure. |
| 1690 | * |
| 1691 | * Called from hbeat timeout routine to check if the number of discovered |
| 1692 | * ports has changed. If so, re-register thar port Attribute. |
| 1693 | */ |
| 1694 | void |
| 1695 | lpfc_fdmi_num_disc_check(struct lpfc_vport *vport) |
| 1696 | { |
| 1697 | struct lpfc_hba *phba = vport->phba; |
| 1698 | struct lpfc_nodelist *ndlp; |
| 1699 | uint16_t cnt; |
| 1700 | |
| 1701 | if (!lpfc_is_link_up(phba)) |
| 1702 | return; |
| 1703 | |
James Smart | a03a421 | 2016-07-06 12:36:12 -0700 | [diff] [blame] | 1704 | /* Must be connected to a Fabric */ |
| 1705 | if (!(vport->fc_flag & FC_FABRIC)) |
| 1706 | return; |
| 1707 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1708 | if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc)) |
| 1709 | return; |
| 1710 | |
| 1711 | cnt = lpfc_find_map_node(vport); |
| 1712 | if (cnt == vport->fdmi_num_disc) |
| 1713 | return; |
| 1714 | |
| 1715 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
| 1716 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 1717 | return; |
| 1718 | |
| 1719 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 1720 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, |
| 1721 | LPFC_FDMI_PORT_ATTR_num_disc); |
| 1722 | } else { |
| 1723 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, |
| 1724 | LPFC_FDMI_PORT_ATTR_num_disc); |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | /* Routines for all individual HBA attributes */ |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1729 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1730 | lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) |
| 1731 | { |
| 1732 | struct lpfc_fdmi_attr_entry *ae; |
| 1733 | uint32_t size; |
| 1734 | |
| 1735 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1736 | memset(ae, 0, sizeof(struct lpfc_name)); |
| 1737 | |
| 1738 | memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName, |
| 1739 | sizeof(struct lpfc_name)); |
| 1740 | size = FOURBYTES + sizeof(struct lpfc_name); |
| 1741 | ad->AttrLen = cpu_to_be16(size); |
| 1742 | ad->AttrType = cpu_to_be16(RHBA_NODENAME); |
| 1743 | return size; |
| 1744 | } |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1745 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1746 | lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport, |
| 1747 | struct lpfc_fdmi_attr_def *ad) |
| 1748 | { |
| 1749 | struct lpfc_fdmi_attr_entry *ae; |
| 1750 | uint32_t len, size; |
| 1751 | |
| 1752 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1753 | memset(ae, 0, 256); |
| 1754 | |
| 1755 | strncpy(ae->un.AttrString, |
| 1756 | "Emulex Corporation", |
| 1757 | sizeof(ae->un.AttrString)); |
| 1758 | len = strnlen(ae->un.AttrString, |
| 1759 | sizeof(ae->un.AttrString)); |
| 1760 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 1761 | size = FOURBYTES + len; |
| 1762 | ad->AttrLen = cpu_to_be16(size); |
| 1763 | ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER); |
| 1764 | return size; |
| 1765 | } |
| 1766 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1767 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1768 | lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) |
| 1769 | { |
| 1770 | struct lpfc_hba *phba = vport->phba; |
| 1771 | struct lpfc_fdmi_attr_entry *ae; |
| 1772 | uint32_t len, size; |
| 1773 | |
| 1774 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1775 | memset(ae, 0, 256); |
| 1776 | |
| 1777 | strncpy(ae->un.AttrString, phba->SerialNumber, |
| 1778 | sizeof(ae->un.AttrString)); |
| 1779 | len = strnlen(ae->un.AttrString, |
| 1780 | sizeof(ae->un.AttrString)); |
| 1781 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 1782 | size = FOURBYTES + len; |
| 1783 | ad->AttrLen = cpu_to_be16(size); |
| 1784 | ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER); |
| 1785 | return size; |
| 1786 | } |
| 1787 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1788 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1789 | lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport, |
| 1790 | struct lpfc_fdmi_attr_def *ad) |
| 1791 | { |
| 1792 | struct lpfc_hba *phba = vport->phba; |
| 1793 | struct lpfc_fdmi_attr_entry *ae; |
| 1794 | uint32_t len, size; |
| 1795 | |
| 1796 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1797 | memset(ae, 0, 256); |
| 1798 | |
| 1799 | strncpy(ae->un.AttrString, phba->ModelName, |
| 1800 | sizeof(ae->un.AttrString)); |
| 1801 | len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); |
| 1802 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 1803 | size = FOURBYTES + len; |
| 1804 | ad->AttrLen = cpu_to_be16(size); |
| 1805 | ad->AttrType = cpu_to_be16(RHBA_MODEL); |
| 1806 | return size; |
| 1807 | } |
| 1808 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1809 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1810 | lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport, |
| 1811 | struct lpfc_fdmi_attr_def *ad) |
| 1812 | { |
| 1813 | struct lpfc_hba *phba = vport->phba; |
| 1814 | struct lpfc_fdmi_attr_entry *ae; |
| 1815 | uint32_t len, size; |
| 1816 | |
| 1817 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1818 | memset(ae, 0, 256); |
| 1819 | |
| 1820 | strncpy(ae->un.AttrString, phba->ModelDesc, |
| 1821 | sizeof(ae->un.AttrString)); |
| 1822 | len = strnlen(ae->un.AttrString, |
| 1823 | sizeof(ae->un.AttrString)); |
| 1824 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 1825 | size = FOURBYTES + len; |
| 1826 | ad->AttrLen = cpu_to_be16(size); |
| 1827 | ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION); |
| 1828 | return size; |
| 1829 | } |
| 1830 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1831 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1832 | lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport, |
| 1833 | struct lpfc_fdmi_attr_def *ad) |
| 1834 | { |
| 1835 | struct lpfc_hba *phba = vport->phba; |
| 1836 | lpfc_vpd_t *vp = &phba->vpd; |
| 1837 | struct lpfc_fdmi_attr_entry *ae; |
| 1838 | uint32_t i, j, incr, size; |
| 1839 | |
| 1840 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1841 | memset(ae, 0, 256); |
| 1842 | |
| 1843 | /* Convert JEDEC ID to ascii for hardware version */ |
| 1844 | incr = vp->rev.biuRev; |
| 1845 | for (i = 0; i < 8; i++) { |
| 1846 | j = (incr & 0xf); |
| 1847 | if (j <= 9) |
| 1848 | ae->un.AttrString[7 - i] = |
| 1849 | (char)((uint8_t) 0x30 + |
| 1850 | (uint8_t) j); |
| 1851 | else |
| 1852 | ae->un.AttrString[7 - i] = |
| 1853 | (char)((uint8_t) 0x61 + |
| 1854 | (uint8_t) (j - 10)); |
| 1855 | incr = (incr >> 4); |
| 1856 | } |
| 1857 | size = FOURBYTES + 8; |
| 1858 | ad->AttrLen = cpu_to_be16(size); |
| 1859 | ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION); |
| 1860 | return size; |
| 1861 | } |
| 1862 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1863 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1864 | lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport, |
| 1865 | struct lpfc_fdmi_attr_def *ad) |
| 1866 | { |
| 1867 | struct lpfc_fdmi_attr_entry *ae; |
| 1868 | uint32_t len, size; |
| 1869 | |
| 1870 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1871 | memset(ae, 0, 256); |
| 1872 | |
| 1873 | strncpy(ae->un.AttrString, lpfc_release_version, |
| 1874 | sizeof(ae->un.AttrString)); |
| 1875 | len = strnlen(ae->un.AttrString, |
| 1876 | sizeof(ae->un.AttrString)); |
| 1877 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 1878 | size = FOURBYTES + len; |
| 1879 | ad->AttrLen = cpu_to_be16(size); |
| 1880 | ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION); |
| 1881 | return size; |
| 1882 | } |
| 1883 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1884 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1885 | lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport, |
| 1886 | struct lpfc_fdmi_attr_def *ad) |
| 1887 | { |
| 1888 | struct lpfc_hba *phba = vport->phba; |
| 1889 | struct lpfc_fdmi_attr_entry *ae; |
| 1890 | uint32_t len, size; |
| 1891 | |
| 1892 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1893 | memset(ae, 0, 256); |
| 1894 | |
| 1895 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 1896 | lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1); |
| 1897 | else |
| 1898 | strncpy(ae->un.AttrString, phba->OptionROMVersion, |
| 1899 | sizeof(ae->un.AttrString)); |
| 1900 | len = strnlen(ae->un.AttrString, |
| 1901 | sizeof(ae->un.AttrString)); |
| 1902 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 1903 | size = FOURBYTES + len; |
| 1904 | ad->AttrLen = cpu_to_be16(size); |
| 1905 | ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION); |
| 1906 | return size; |
| 1907 | } |
| 1908 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1909 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1910 | lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport, |
| 1911 | struct lpfc_fdmi_attr_def *ad) |
| 1912 | { |
| 1913 | struct lpfc_hba *phba = vport->phba; |
| 1914 | struct lpfc_fdmi_attr_entry *ae; |
| 1915 | uint32_t len, size; |
| 1916 | |
| 1917 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1918 | memset(ae, 0, 256); |
| 1919 | |
| 1920 | lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1); |
| 1921 | len = strnlen(ae->un.AttrString, |
| 1922 | sizeof(ae->un.AttrString)); |
| 1923 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 1924 | size = FOURBYTES + len; |
| 1925 | ad->AttrLen = cpu_to_be16(size); |
| 1926 | ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION); |
| 1927 | return size; |
| 1928 | } |
| 1929 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1930 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1931 | lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport, |
| 1932 | struct lpfc_fdmi_attr_def *ad) |
| 1933 | { |
| 1934 | struct lpfc_fdmi_attr_entry *ae; |
| 1935 | uint32_t len, size; |
| 1936 | |
| 1937 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1938 | memset(ae, 0, 256); |
| 1939 | |
| 1940 | snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s", |
| 1941 | init_utsname()->sysname, |
| 1942 | init_utsname()->release, |
| 1943 | init_utsname()->version); |
| 1944 | |
| 1945 | len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); |
| 1946 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 1947 | size = FOURBYTES + len; |
| 1948 | ad->AttrLen = cpu_to_be16(size); |
| 1949 | ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION); |
| 1950 | return size; |
| 1951 | } |
| 1952 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1953 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1954 | lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport, |
| 1955 | struct lpfc_fdmi_attr_def *ad) |
| 1956 | { |
| 1957 | struct lpfc_fdmi_attr_entry *ae; |
| 1958 | uint32_t size; |
| 1959 | |
| 1960 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1961 | |
| 1962 | ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE); |
| 1963 | size = FOURBYTES + sizeof(uint32_t); |
| 1964 | ad->AttrLen = cpu_to_be16(size); |
| 1965 | ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN); |
| 1966 | return size; |
| 1967 | } |
| 1968 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1969 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1970 | lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport, |
| 1971 | struct lpfc_fdmi_attr_def *ad) |
| 1972 | { |
| 1973 | struct lpfc_fdmi_attr_entry *ae; |
| 1974 | uint32_t len, size; |
| 1975 | |
| 1976 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1977 | memset(ae, 0, 256); |
| 1978 | |
| 1979 | len = lpfc_vport_symbolic_node_name(vport, |
| 1980 | ae->un.AttrString, 256); |
| 1981 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 1982 | size = FOURBYTES + len; |
| 1983 | ad->AttrLen = cpu_to_be16(size); |
| 1984 | ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME); |
| 1985 | return size; |
| 1986 | } |
| 1987 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 1988 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1989 | lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport, |
| 1990 | struct lpfc_fdmi_attr_def *ad) |
| 1991 | { |
| 1992 | struct lpfc_fdmi_attr_entry *ae; |
| 1993 | uint32_t size; |
| 1994 | |
| 1995 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 1996 | |
| 1997 | /* Nothing is defined for this currently */ |
| 1998 | ae->un.AttrInt = cpu_to_be32(0); |
| 1999 | size = FOURBYTES + sizeof(uint32_t); |
| 2000 | ad->AttrLen = cpu_to_be16(size); |
| 2001 | ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO); |
| 2002 | return size; |
| 2003 | } |
| 2004 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2005 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2006 | lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport, |
| 2007 | struct lpfc_fdmi_attr_def *ad) |
| 2008 | { |
| 2009 | struct lpfc_fdmi_attr_entry *ae; |
| 2010 | uint32_t size; |
| 2011 | |
| 2012 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2013 | |
| 2014 | /* Each driver instance corresponds to a single port */ |
| 2015 | ae->un.AttrInt = cpu_to_be32(1); |
| 2016 | size = FOURBYTES + sizeof(uint32_t); |
| 2017 | ad->AttrLen = cpu_to_be16(size); |
| 2018 | ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS); |
| 2019 | return size; |
| 2020 | } |
| 2021 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2022 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2023 | lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport, |
| 2024 | struct lpfc_fdmi_attr_def *ad) |
| 2025 | { |
| 2026 | struct lpfc_fdmi_attr_entry *ae; |
| 2027 | uint32_t size; |
| 2028 | |
| 2029 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2030 | memset(ae, 0, sizeof(struct lpfc_name)); |
| 2031 | |
| 2032 | memcpy(&ae->un.AttrWWN, &vport->fabric_nodename, |
| 2033 | sizeof(struct lpfc_name)); |
| 2034 | size = FOURBYTES + sizeof(struct lpfc_name); |
| 2035 | ad->AttrLen = cpu_to_be16(size); |
| 2036 | ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN); |
| 2037 | return size; |
| 2038 | } |
| 2039 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2040 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2041 | lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport, |
| 2042 | struct lpfc_fdmi_attr_def *ad) |
| 2043 | { |
| 2044 | struct lpfc_hba *phba = vport->phba; |
| 2045 | struct lpfc_fdmi_attr_entry *ae; |
| 2046 | uint32_t len, size; |
| 2047 | |
| 2048 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2049 | memset(ae, 0, 256); |
| 2050 | |
| 2051 | lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1); |
| 2052 | len = strnlen(ae->un.AttrString, |
| 2053 | sizeof(ae->un.AttrString)); |
| 2054 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 2055 | size = FOURBYTES + len; |
| 2056 | ad->AttrLen = cpu_to_be16(size); |
| 2057 | ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION); |
| 2058 | return size; |
| 2059 | } |
| 2060 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2061 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2062 | lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport, |
| 2063 | struct lpfc_fdmi_attr_def *ad) |
| 2064 | { |
| 2065 | struct lpfc_fdmi_attr_entry *ae; |
| 2066 | uint32_t size; |
| 2067 | |
| 2068 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2069 | |
| 2070 | /* Driver doesn't have access to this information */ |
| 2071 | ae->un.AttrInt = cpu_to_be32(0); |
| 2072 | size = FOURBYTES + sizeof(uint32_t); |
| 2073 | ad->AttrLen = cpu_to_be16(size); |
| 2074 | ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE); |
| 2075 | return size; |
| 2076 | } |
| 2077 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2078 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2079 | lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport, |
| 2080 | struct lpfc_fdmi_attr_def *ad) |
| 2081 | { |
| 2082 | struct lpfc_fdmi_attr_entry *ae; |
| 2083 | uint32_t len, size; |
| 2084 | |
| 2085 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2086 | memset(ae, 0, 256); |
| 2087 | |
| 2088 | strncpy(ae->un.AttrString, "EMULEX", |
| 2089 | sizeof(ae->un.AttrString)); |
| 2090 | len = strnlen(ae->un.AttrString, |
| 2091 | sizeof(ae->un.AttrString)); |
| 2092 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 2093 | size = FOURBYTES + len; |
| 2094 | ad->AttrLen = cpu_to_be16(size); |
| 2095 | ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID); |
| 2096 | return size; |
| 2097 | } |
| 2098 | |
| 2099 | /* Routines for all individual PORT attributes */ |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2100 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2101 | lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport, |
| 2102 | struct lpfc_fdmi_attr_def *ad) |
| 2103 | { |
| 2104 | struct lpfc_fdmi_attr_entry *ae; |
| 2105 | uint32_t size; |
| 2106 | |
| 2107 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2108 | memset(ae, 0, 32); |
| 2109 | |
| 2110 | ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */ |
| 2111 | ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */ |
James Smart | 82820f0 | 2017-05-15 15:20:47 -0700 | [diff] [blame] | 2112 | ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */ |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2113 | ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */ |
| 2114 | size = FOURBYTES + 32; |
| 2115 | ad->AttrLen = cpu_to_be16(size); |
| 2116 | ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES); |
| 2117 | return size; |
| 2118 | } |
| 2119 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2120 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2121 | lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport, |
| 2122 | struct lpfc_fdmi_attr_def *ad) |
| 2123 | { |
| 2124 | struct lpfc_hba *phba = vport->phba; |
| 2125 | struct lpfc_fdmi_attr_entry *ae; |
| 2126 | uint32_t size; |
| 2127 | |
| 2128 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2129 | |
| 2130 | ae->un.AttrInt = 0; |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 2131 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 2132 | if (phba->lmt & LMT_32Gb) |
| 2133 | ae->un.AttrInt |= HBA_PORTSPEED_32GFC; |
| 2134 | if (phba->lmt & LMT_16Gb) |
| 2135 | ae->un.AttrInt |= HBA_PORTSPEED_16GFC; |
| 2136 | if (phba->lmt & LMT_10Gb) |
| 2137 | ae->un.AttrInt |= HBA_PORTSPEED_10GFC; |
| 2138 | if (phba->lmt & LMT_8Gb) |
| 2139 | ae->un.AttrInt |= HBA_PORTSPEED_8GFC; |
| 2140 | if (phba->lmt & LMT_4Gb) |
| 2141 | ae->un.AttrInt |= HBA_PORTSPEED_4GFC; |
| 2142 | if (phba->lmt & LMT_2Gb) |
| 2143 | ae->un.AttrInt |= HBA_PORTSPEED_2GFC; |
| 2144 | if (phba->lmt & LMT_1Gb) |
| 2145 | ae->un.AttrInt |= HBA_PORTSPEED_1GFC; |
| 2146 | } else { |
| 2147 | /* FCoE links support only one speed */ |
| 2148 | switch (phba->fc_linkspeed) { |
| 2149 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
| 2150 | ae->un.AttrInt = HBA_PORTSPEED_10GE; |
| 2151 | break; |
| 2152 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 2153 | ae->un.AttrInt = HBA_PORTSPEED_25GE; |
| 2154 | break; |
| 2155 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 2156 | ae->un.AttrInt = HBA_PORTSPEED_40GE; |
| 2157 | break; |
| 2158 | case LPFC_ASYNC_LINK_SPEED_100GBPS: |
| 2159 | ae->un.AttrInt = HBA_PORTSPEED_100GE; |
| 2160 | break; |
| 2161 | } |
| 2162 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2163 | ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); |
| 2164 | size = FOURBYTES + sizeof(uint32_t); |
| 2165 | ad->AttrLen = cpu_to_be16(size); |
| 2166 | ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED); |
| 2167 | return size; |
| 2168 | } |
| 2169 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2170 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2171 | lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport, |
| 2172 | struct lpfc_fdmi_attr_def *ad) |
| 2173 | { |
| 2174 | struct lpfc_hba *phba = vport->phba; |
| 2175 | struct lpfc_fdmi_attr_entry *ae; |
| 2176 | uint32_t size; |
| 2177 | |
| 2178 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2179 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 2180 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 2181 | switch (phba->fc_linkspeed) { |
| 2182 | case LPFC_LINK_SPEED_1GHZ: |
| 2183 | ae->un.AttrInt = HBA_PORTSPEED_1GFC; |
| 2184 | break; |
| 2185 | case LPFC_LINK_SPEED_2GHZ: |
| 2186 | ae->un.AttrInt = HBA_PORTSPEED_2GFC; |
| 2187 | break; |
| 2188 | case LPFC_LINK_SPEED_4GHZ: |
| 2189 | ae->un.AttrInt = HBA_PORTSPEED_4GFC; |
| 2190 | break; |
| 2191 | case LPFC_LINK_SPEED_8GHZ: |
| 2192 | ae->un.AttrInt = HBA_PORTSPEED_8GFC; |
| 2193 | break; |
| 2194 | case LPFC_LINK_SPEED_10GHZ: |
| 2195 | ae->un.AttrInt = HBA_PORTSPEED_10GFC; |
| 2196 | break; |
| 2197 | case LPFC_LINK_SPEED_16GHZ: |
| 2198 | ae->un.AttrInt = HBA_PORTSPEED_16GFC; |
| 2199 | break; |
| 2200 | case LPFC_LINK_SPEED_32GHZ: |
| 2201 | ae->un.AttrInt = HBA_PORTSPEED_32GFC; |
| 2202 | break; |
| 2203 | default: |
| 2204 | ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN; |
| 2205 | break; |
| 2206 | } |
| 2207 | } else { |
| 2208 | switch (phba->fc_linkspeed) { |
| 2209 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
| 2210 | ae->un.AttrInt = HBA_PORTSPEED_10GE; |
| 2211 | break; |
| 2212 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 2213 | ae->un.AttrInt = HBA_PORTSPEED_25GE; |
| 2214 | break; |
| 2215 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 2216 | ae->un.AttrInt = HBA_PORTSPEED_40GE; |
| 2217 | break; |
| 2218 | case LPFC_ASYNC_LINK_SPEED_100GBPS: |
| 2219 | ae->un.AttrInt = HBA_PORTSPEED_100GE; |
| 2220 | break; |
| 2221 | default: |
| 2222 | ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN; |
| 2223 | break; |
| 2224 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2225 | } |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 2226 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2227 | ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); |
| 2228 | size = FOURBYTES + sizeof(uint32_t); |
| 2229 | ad->AttrLen = cpu_to_be16(size); |
| 2230 | ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED); |
| 2231 | return size; |
| 2232 | } |
| 2233 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2234 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2235 | lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport, |
| 2236 | struct lpfc_fdmi_attr_def *ad) |
| 2237 | { |
| 2238 | struct serv_parm *hsp; |
| 2239 | struct lpfc_fdmi_attr_entry *ae; |
| 2240 | uint32_t size; |
| 2241 | |
| 2242 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2243 | |
| 2244 | hsp = (struct serv_parm *)&vport->fc_sparam; |
| 2245 | ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) | |
| 2246 | (uint32_t) hsp->cmn.bbRcvSizeLsb; |
| 2247 | ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); |
| 2248 | size = FOURBYTES + sizeof(uint32_t); |
| 2249 | ad->AttrLen = cpu_to_be16(size); |
| 2250 | ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE); |
| 2251 | return size; |
| 2252 | } |
| 2253 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2254 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2255 | lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport, |
| 2256 | struct lpfc_fdmi_attr_def *ad) |
| 2257 | { |
| 2258 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2259 | struct lpfc_fdmi_attr_entry *ae; |
| 2260 | uint32_t len, size; |
| 2261 | |
| 2262 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2263 | memset(ae, 0, 256); |
| 2264 | |
| 2265 | snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), |
| 2266 | "/sys/class/scsi_host/host%d", shost->host_no); |
| 2267 | len = strnlen((char *)ae->un.AttrString, |
| 2268 | sizeof(ae->un.AttrString)); |
| 2269 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 2270 | size = FOURBYTES + len; |
| 2271 | ad->AttrLen = cpu_to_be16(size); |
| 2272 | ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME); |
| 2273 | return size; |
| 2274 | } |
| 2275 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2276 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2277 | lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport, |
| 2278 | struct lpfc_fdmi_attr_def *ad) |
| 2279 | { |
| 2280 | struct lpfc_fdmi_attr_entry *ae; |
| 2281 | uint32_t len, size; |
| 2282 | |
| 2283 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2284 | memset(ae, 0, 256); |
| 2285 | |
| 2286 | snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s", |
| 2287 | init_utsname()->nodename); |
| 2288 | |
| 2289 | len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); |
| 2290 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 2291 | size = FOURBYTES + len; |
| 2292 | ad->AttrLen = cpu_to_be16(size); |
| 2293 | ad->AttrType = cpu_to_be16(RPRT_HOST_NAME); |
| 2294 | return size; |
| 2295 | } |
| 2296 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2297 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2298 | lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport, |
| 2299 | struct lpfc_fdmi_attr_def *ad) |
| 2300 | { |
| 2301 | struct lpfc_fdmi_attr_entry *ae; |
| 2302 | uint32_t size; |
| 2303 | |
| 2304 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2305 | memset(ae, 0, sizeof(struct lpfc_name)); |
| 2306 | |
| 2307 | memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName, |
| 2308 | sizeof(struct lpfc_name)); |
| 2309 | size = FOURBYTES + sizeof(struct lpfc_name); |
| 2310 | ad->AttrLen = cpu_to_be16(size); |
| 2311 | ad->AttrType = cpu_to_be16(RPRT_NODENAME); |
| 2312 | return size; |
| 2313 | } |
| 2314 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2315 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2316 | lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport, |
| 2317 | struct lpfc_fdmi_attr_def *ad) |
| 2318 | { |
| 2319 | struct lpfc_fdmi_attr_entry *ae; |
| 2320 | uint32_t size; |
| 2321 | |
| 2322 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2323 | memset(ae, 0, sizeof(struct lpfc_name)); |
| 2324 | |
| 2325 | memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName, |
| 2326 | sizeof(struct lpfc_name)); |
| 2327 | size = FOURBYTES + sizeof(struct lpfc_name); |
| 2328 | ad->AttrLen = cpu_to_be16(size); |
| 2329 | ad->AttrType = cpu_to_be16(RPRT_PORTNAME); |
| 2330 | return size; |
| 2331 | } |
| 2332 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2333 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2334 | lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport, |
| 2335 | struct lpfc_fdmi_attr_def *ad) |
| 2336 | { |
| 2337 | struct lpfc_fdmi_attr_entry *ae; |
| 2338 | uint32_t len, size; |
| 2339 | |
| 2340 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2341 | memset(ae, 0, 256); |
| 2342 | |
| 2343 | len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256); |
| 2344 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 2345 | size = FOURBYTES + len; |
| 2346 | ad->AttrLen = cpu_to_be16(size); |
| 2347 | ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME); |
| 2348 | return size; |
| 2349 | } |
| 2350 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2351 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2352 | lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport, |
| 2353 | struct lpfc_fdmi_attr_def *ad) |
| 2354 | { |
| 2355 | struct lpfc_hba *phba = vport->phba; |
| 2356 | struct lpfc_fdmi_attr_entry *ae; |
| 2357 | uint32_t size; |
| 2358 | |
| 2359 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2360 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) |
| 2361 | ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT); |
| 2362 | else |
| 2363 | ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT); |
| 2364 | size = FOURBYTES + sizeof(uint32_t); |
| 2365 | ad->AttrLen = cpu_to_be16(size); |
| 2366 | ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE); |
| 2367 | return size; |
| 2368 | } |
| 2369 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2370 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2371 | lpfc_fdmi_port_attr_class(struct lpfc_vport *vport, |
| 2372 | struct lpfc_fdmi_attr_def *ad) |
| 2373 | { |
| 2374 | struct lpfc_fdmi_attr_entry *ae; |
| 2375 | uint32_t size; |
| 2376 | |
| 2377 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2378 | ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3); |
| 2379 | size = FOURBYTES + sizeof(uint32_t); |
| 2380 | ad->AttrLen = cpu_to_be16(size); |
| 2381 | ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS); |
| 2382 | return size; |
| 2383 | } |
| 2384 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2385 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2386 | lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport, |
| 2387 | struct lpfc_fdmi_attr_def *ad) |
| 2388 | { |
| 2389 | struct lpfc_fdmi_attr_entry *ae; |
| 2390 | uint32_t size; |
| 2391 | |
| 2392 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2393 | memset(ae, 0, sizeof(struct lpfc_name)); |
| 2394 | |
| 2395 | memcpy(&ae->un.AttrWWN, &vport->fabric_portname, |
| 2396 | sizeof(struct lpfc_name)); |
| 2397 | size = FOURBYTES + sizeof(struct lpfc_name); |
| 2398 | ad->AttrLen = cpu_to_be16(size); |
| 2399 | ad->AttrType = cpu_to_be16(RPRT_FABRICNAME); |
| 2400 | return size; |
| 2401 | } |
| 2402 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2403 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2404 | lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport, |
| 2405 | struct lpfc_fdmi_attr_def *ad) |
| 2406 | { |
| 2407 | struct lpfc_fdmi_attr_entry *ae; |
| 2408 | uint32_t size; |
| 2409 | |
| 2410 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2411 | memset(ae, 0, 32); |
| 2412 | |
| 2413 | ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */ |
| 2414 | ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */ |
| 2415 | ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */ |
| 2416 | size = FOURBYTES + 32; |
| 2417 | ad->AttrLen = cpu_to_be16(size); |
| 2418 | ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES); |
| 2419 | return size; |
| 2420 | } |
| 2421 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2422 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2423 | lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport, |
| 2424 | struct lpfc_fdmi_attr_def *ad) |
| 2425 | { |
| 2426 | struct lpfc_fdmi_attr_entry *ae; |
| 2427 | uint32_t size; |
| 2428 | |
| 2429 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2430 | /* Link Up - operational */ |
| 2431 | ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE); |
| 2432 | size = FOURBYTES + sizeof(uint32_t); |
| 2433 | ad->AttrLen = cpu_to_be16(size); |
| 2434 | ad->AttrType = cpu_to_be16(RPRT_PORT_STATE); |
| 2435 | return size; |
| 2436 | } |
| 2437 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2438 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2439 | lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport, |
| 2440 | struct lpfc_fdmi_attr_def *ad) |
| 2441 | { |
| 2442 | struct lpfc_fdmi_attr_entry *ae; |
| 2443 | uint32_t size; |
| 2444 | |
| 2445 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2446 | vport->fdmi_num_disc = lpfc_find_map_node(vport); |
| 2447 | ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc); |
| 2448 | size = FOURBYTES + sizeof(uint32_t); |
| 2449 | ad->AttrLen = cpu_to_be16(size); |
| 2450 | ad->AttrType = cpu_to_be16(RPRT_DISC_PORT); |
| 2451 | return size; |
| 2452 | } |
| 2453 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2454 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2455 | lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport, |
| 2456 | struct lpfc_fdmi_attr_def *ad) |
| 2457 | { |
| 2458 | struct lpfc_fdmi_attr_entry *ae; |
| 2459 | uint32_t size; |
| 2460 | |
| 2461 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2462 | ae->un.AttrInt = cpu_to_be32(vport->fc_myDID); |
| 2463 | size = FOURBYTES + sizeof(uint32_t); |
| 2464 | ad->AttrLen = cpu_to_be16(size); |
| 2465 | ad->AttrType = cpu_to_be16(RPRT_PORT_ID); |
| 2466 | return size; |
| 2467 | } |
| 2468 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2469 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2470 | lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport, |
| 2471 | struct lpfc_fdmi_attr_def *ad) |
| 2472 | { |
| 2473 | struct lpfc_fdmi_attr_entry *ae; |
| 2474 | uint32_t len, size; |
| 2475 | |
| 2476 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2477 | memset(ae, 0, 256); |
| 2478 | |
| 2479 | strncpy(ae->un.AttrString, "Smart SAN Initiator", |
| 2480 | sizeof(ae->un.AttrString)); |
| 2481 | len = strnlen(ae->un.AttrString, |
| 2482 | sizeof(ae->un.AttrString)); |
| 2483 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 2484 | size = FOURBYTES + len; |
| 2485 | ad->AttrLen = cpu_to_be16(size); |
| 2486 | ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE); |
| 2487 | return size; |
| 2488 | } |
| 2489 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2490 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2491 | lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport, |
| 2492 | struct lpfc_fdmi_attr_def *ad) |
| 2493 | { |
| 2494 | struct lpfc_fdmi_attr_entry *ae; |
| 2495 | uint32_t size; |
| 2496 | |
| 2497 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2498 | memset(ae, 0, 256); |
| 2499 | |
| 2500 | memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName, |
| 2501 | sizeof(struct lpfc_name)); |
| 2502 | memcpy((((uint8_t *)&ae->un.AttrString) + |
| 2503 | sizeof(struct lpfc_name)), |
| 2504 | &vport->fc_sparam.portName, sizeof(struct lpfc_name)); |
| 2505 | size = FOURBYTES + (2 * sizeof(struct lpfc_name)); |
| 2506 | ad->AttrLen = cpu_to_be16(size); |
| 2507 | ad->AttrType = cpu_to_be16(RPRT_SMART_GUID); |
| 2508 | return size; |
| 2509 | } |
| 2510 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2511 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2512 | lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport, |
| 2513 | struct lpfc_fdmi_attr_def *ad) |
| 2514 | { |
| 2515 | struct lpfc_fdmi_attr_entry *ae; |
| 2516 | uint32_t len, size; |
| 2517 | |
| 2518 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2519 | memset(ae, 0, 256); |
| 2520 | |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 2521 | strncpy(ae->un.AttrString, "Smart SAN Version 2.0", |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2522 | sizeof(ae->un.AttrString)); |
| 2523 | len = strnlen(ae->un.AttrString, |
| 2524 | sizeof(ae->un.AttrString)); |
| 2525 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 2526 | size = FOURBYTES + len; |
| 2527 | ad->AttrLen = cpu_to_be16(size); |
| 2528 | ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION); |
| 2529 | return size; |
| 2530 | } |
| 2531 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2532 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2533 | lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport, |
| 2534 | struct lpfc_fdmi_attr_def *ad) |
| 2535 | { |
| 2536 | struct lpfc_hba *phba = vport->phba; |
| 2537 | struct lpfc_fdmi_attr_entry *ae; |
| 2538 | uint32_t len, size; |
| 2539 | |
| 2540 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2541 | memset(ae, 0, 256); |
| 2542 | |
| 2543 | strncpy(ae->un.AttrString, phba->ModelName, |
| 2544 | sizeof(ae->un.AttrString)); |
| 2545 | len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); |
| 2546 | len += (len & 3) ? (4 - (len & 3)) : 4; |
| 2547 | size = FOURBYTES + len; |
| 2548 | ad->AttrLen = cpu_to_be16(size); |
| 2549 | ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL); |
| 2550 | return size; |
| 2551 | } |
| 2552 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2553 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2554 | lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport, |
| 2555 | struct lpfc_fdmi_attr_def *ad) |
| 2556 | { |
| 2557 | struct lpfc_fdmi_attr_entry *ae; |
| 2558 | uint32_t size; |
| 2559 | |
| 2560 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2561 | |
| 2562 | /* SRIOV (type 3) is not supported */ |
| 2563 | if (vport->vpi) |
| 2564 | ae->un.AttrInt = cpu_to_be32(2); /* NPIV */ |
| 2565 | else |
| 2566 | ae->un.AttrInt = cpu_to_be32(1); /* Physical */ |
| 2567 | size = FOURBYTES + sizeof(uint32_t); |
| 2568 | ad->AttrLen = cpu_to_be16(size); |
| 2569 | ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO); |
| 2570 | return size; |
| 2571 | } |
| 2572 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2573 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2574 | lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport, |
| 2575 | struct lpfc_fdmi_attr_def *ad) |
| 2576 | { |
| 2577 | struct lpfc_fdmi_attr_entry *ae; |
| 2578 | uint32_t size; |
| 2579 | |
| 2580 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
| 2581 | ae->un.AttrInt = cpu_to_be32(0); |
| 2582 | size = FOURBYTES + sizeof(uint32_t); |
| 2583 | ad->AttrLen = cpu_to_be16(size); |
| 2584 | ad->AttrType = cpu_to_be16(RPRT_SMART_QOS); |
| 2585 | return size; |
| 2586 | } |
| 2587 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2588 | static int |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2589 | lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport, |
| 2590 | struct lpfc_fdmi_attr_def *ad) |
| 2591 | { |
| 2592 | struct lpfc_fdmi_attr_entry *ae; |
| 2593 | uint32_t size; |
| 2594 | |
| 2595 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
James Smart | 5620498 | 2016-03-31 14:12:32 -0700 | [diff] [blame] | 2596 | ae->un.AttrInt = cpu_to_be32(1); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2597 | size = FOURBYTES + sizeof(uint32_t); |
| 2598 | ad->AttrLen = cpu_to_be16(size); |
| 2599 | ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY); |
| 2600 | return size; |
| 2601 | } |
| 2602 | |
| 2603 | /* RHBA attribute jump table */ |
| 2604 | int (*lpfc_fdmi_hba_action[]) |
| 2605 | (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = { |
| 2606 | /* Action routine Mask bit Attribute type */ |
| 2607 | lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */ |
| 2608 | lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */ |
| 2609 | lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */ |
| 2610 | lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */ |
| 2611 | lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */ |
| 2612 | lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */ |
| 2613 | lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */ |
| 2614 | lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */ |
| 2615 | lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */ |
| 2616 | lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */ |
| 2617 | lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */ |
| 2618 | lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */ |
| 2619 | lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */ |
| 2620 | lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */ |
| 2621 | lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */ |
| 2622 | lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */ |
| 2623 | lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */ |
| 2624 | lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */ |
| 2625 | }; |
| 2626 | |
| 2627 | /* RPA / RPRT attribute jump table */ |
| 2628 | int (*lpfc_fdmi_port_action[]) |
| 2629 | (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = { |
| 2630 | /* Action routine Mask bit Attribute type */ |
| 2631 | lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */ |
| 2632 | lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */ |
| 2633 | lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */ |
| 2634 | lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */ |
| 2635 | lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */ |
| 2636 | lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */ |
| 2637 | lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */ |
| 2638 | lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */ |
| 2639 | lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */ |
| 2640 | lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */ |
| 2641 | lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */ |
| 2642 | lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */ |
| 2643 | lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */ |
| 2644 | lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */ |
| 2645 | lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */ |
| 2646 | lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */ |
| 2647 | lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */ |
| 2648 | lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */ |
| 2649 | lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */ |
| 2650 | lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */ |
| 2651 | lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */ |
| 2652 | lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */ |
| 2653 | lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */ |
| 2654 | }; |
| 2655 | |
| 2656 | /** |
| 2657 | * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort |
| 2658 | * @vport: pointer to a host virtual N_Port data structure. |
| 2659 | * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID) |
| 2660 | * cmdcode: FDMI command to send |
| 2661 | * mask: Mask of HBA or PORT Attributes to send |
| 2662 | * |
| 2663 | * Builds and sends a FDMI command using the CT subsystem. |
| 2664 | */ |
| 2665 | int |
| 2666 | lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 2667 | int cmdcode, uint32_t new_mask) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2668 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2669 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | struct lpfc_dmabuf *mp, *bmp; |
| 2671 | struct lpfc_sli_ct_request *CtReq; |
| 2672 | struct ulp_bde64 *bpl; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2673 | uint32_t bit_pos; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2674 | uint32_t size; |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2675 | uint32_t rsp_size; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2676 | uint32_t mask; |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2677 | struct lpfc_fdmi_reg_hba *rh; |
| 2678 | struct lpfc_fdmi_port_entry *pe; |
| 2679 | struct lpfc_fdmi_reg_portattr *pab = NULL; |
| 2680 | struct lpfc_fdmi_attr_block *ab = NULL; |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2681 | int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad); |
| 2682 | void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *, |
| 2683 | struct lpfc_iocbq *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2684 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2685 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 2686 | return 0; |
| 2687 | |
| 2688 | cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2689 | |
| 2690 | /* fill in BDEs for command */ |
| 2691 | /* Allocate buffer for command payload */ |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2692 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2693 | if (!mp) |
| 2694 | goto fdmi_cmd_exit; |
| 2695 | |
| 2696 | mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys)); |
| 2697 | if (!mp->virt) |
| 2698 | goto fdmi_cmd_free_mp; |
| 2699 | |
| 2700 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2701 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2702 | if (!bmp) |
| 2703 | goto fdmi_cmd_free_mpvirt; |
| 2704 | |
| 2705 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys)); |
| 2706 | if (!bmp->virt) |
| 2707 | goto fdmi_cmd_free_bmp; |
| 2708 | |
| 2709 | INIT_LIST_HEAD(&mp->list); |
| 2710 | INIT_LIST_HEAD(&bmp->list); |
| 2711 | |
| 2712 | /* FDMI request */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2713 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2714 | "0218 FDMI Request Data: x%x x%x x%x\n", |
| 2715 | vport->fc_flag, vport->port_state, cmdcode); |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2716 | CtReq = (struct lpfc_sli_ct_request *)mp->virt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2717 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2718 | /* First populate the CT_IU preamble */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2719 | memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request)); |
| 2720 | CtReq->RevisionId.bits.Revision = SLI_CT_REVISION; |
| 2721 | CtReq->RevisionId.bits.InId = 0; |
| 2722 | |
| 2723 | CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE; |
| 2724 | CtReq->FsSubType = SLI_CT_FDMI_Subtypes; |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2725 | |
| 2726 | CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode); |
| 2727 | rsp_size = LPFC_BPL_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2728 | size = 0; |
| 2729 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2730 | /* Next fill in the specific FDMI cmd information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2731 | switch (cmdcode) { |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2732 | case SLI_MGMT_RHAT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2733 | case SLI_MGMT_RHBA: |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2734 | rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID; |
| 2735 | /* HBA Identifier */ |
| 2736 | memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName, |
| 2737 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2738 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2739 | if (cmdcode == SLI_MGMT_RHBA) { |
| 2740 | /* Registered Port List */ |
| 2741 | /* One entry (port) per adapter */ |
| 2742 | rh->rpl.EntryCnt = cpu_to_be32(1); |
| 2743 | memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName, |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2744 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2746 | /* point to the HBA attribute block */ |
| 2747 | size = 2 * sizeof(struct lpfc_name) + |
| 2748 | FOURBYTES; |
| 2749 | } else { |
| 2750 | size = sizeof(struct lpfc_name); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2751 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2752 | ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size); |
| 2753 | ab->EntryCnt = 0; |
| 2754 | size += FOURBYTES; |
| 2755 | bit_pos = 0; |
| 2756 | if (new_mask) |
| 2757 | mask = new_mask; |
| 2758 | else |
| 2759 | mask = vport->fdmi_hba_mask; |
| 2760 | |
| 2761 | /* Mask will dictate what attributes to build in the request */ |
| 2762 | while (mask) { |
| 2763 | if (mask & 0x1) { |
| 2764 | func = lpfc_fdmi_hba_action[bit_pos]; |
| 2765 | size += func(vport, |
| 2766 | (struct lpfc_fdmi_attr_def *) |
| 2767 | ((uint8_t *)rh + size)); |
| 2768 | ab->EntryCnt++; |
| 2769 | if ((size + 256) > |
| 2770 | (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE)) |
| 2771 | goto hba_out; |
| 2772 | } |
| 2773 | mask = mask >> 1; |
| 2774 | bit_pos++; |
| 2775 | } |
| 2776 | hba_out: |
| 2777 | ab->EntryCnt = cpu_to_be32(ab->EntryCnt); |
| 2778 | /* Total size */ |
| 2779 | size = GID_REQUEST_SZ - 4 + size; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2780 | break; |
| 2781 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2782 | case SLI_MGMT_RPRT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2783 | case SLI_MGMT_RPA: |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2784 | pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID; |
| 2785 | if (cmdcode == SLI_MGMT_RPRT) { |
| 2786 | rh = (struct lpfc_fdmi_reg_hba *)pab; |
| 2787 | /* HBA Identifier */ |
| 2788 | memcpy(&rh->hi.PortName, |
| 2789 | &phba->pport->fc_sparam.portName, |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2790 | sizeof(struct lpfc_name)); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2791 | pab = (struct lpfc_fdmi_reg_portattr *) |
| 2792 | ((uint8_t *)pab + sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2793 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 2794 | |
| 2795 | memcpy((uint8_t *)&pab->PortName, |
| 2796 | (uint8_t *)&vport->fc_sparam.portName, |
| 2797 | sizeof(struct lpfc_name)); |
| 2798 | size += sizeof(struct lpfc_name) + FOURBYTES; |
| 2799 | pab->ab.EntryCnt = 0; |
| 2800 | bit_pos = 0; |
| 2801 | if (new_mask) |
| 2802 | mask = new_mask; |
| 2803 | else |
| 2804 | mask = vport->fdmi_port_mask; |
| 2805 | |
| 2806 | /* Mask will dictate what attributes to build in the request */ |
| 2807 | while (mask) { |
| 2808 | if (mask & 0x1) { |
| 2809 | func = lpfc_fdmi_port_action[bit_pos]; |
| 2810 | size += func(vport, |
| 2811 | (struct lpfc_fdmi_attr_def *) |
| 2812 | ((uint8_t *)pab + size)); |
| 2813 | pab->ab.EntryCnt++; |
| 2814 | if ((size + 256) > |
| 2815 | (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE)) |
| 2816 | goto port_out; |
| 2817 | } |
| 2818 | mask = mask >> 1; |
| 2819 | bit_pos++; |
| 2820 | } |
| 2821 | port_out: |
| 2822 | pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt); |
| 2823 | /* Total size */ |
| 2824 | if (cmdcode == SLI_MGMT_RPRT) |
| 2825 | size += sizeof(struct lpfc_name); |
| 2826 | size = GID_REQUEST_SZ - 4 + size; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2827 | break; |
| 2828 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2829 | case SLI_MGMT_GHAT: |
| 2830 | case SLI_MGMT_GRPL: |
| 2831 | rsp_size = FC_MAX_NS_RSP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2832 | case SLI_MGMT_DHBA: |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2833 | case SLI_MGMT_DHAT: |
| 2834 | pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID; |
| 2835 | memcpy((uint8_t *)&pe->PortName, |
| 2836 | (uint8_t *)&vport->fc_sparam.portName, |
| 2837 | sizeof(struct lpfc_name)); |
| 2838 | size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2839 | break; |
| 2840 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2841 | case SLI_MGMT_GPAT: |
| 2842 | case SLI_MGMT_GPAS: |
| 2843 | rsp_size = FC_MAX_NS_RSP; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2844 | case SLI_MGMT_DPRT: |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2845 | case SLI_MGMT_DPA: |
| 2846 | pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID; |
| 2847 | memcpy((uint8_t *)&pe->PortName, |
| 2848 | (uint8_t *)&vport->fc_sparam.portName, |
| 2849 | sizeof(struct lpfc_name)); |
| 2850 | size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2851 | break; |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2852 | case SLI_MGMT_GRHL: |
| 2853 | size = GID_REQUEST_SZ - 4; |
| 2854 | break; |
| 2855 | default: |
| 2856 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
| 2857 | "0298 FDMI cmdcode x%x not supported\n", |
| 2858 | cmdcode); |
| 2859 | goto fdmi_cmd_free_bmpvirt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2860 | } |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2861 | CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2862 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2863 | bpl = (struct ulp_bde64 *)bmp->virt; |
| 2864 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys)); |
| 2865 | bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2866 | bpl->tus.f.bdeFlags = 0; |
| 2867 | bpl->tus.f.bdeSize = size; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2868 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2869 | /* |
| 2870 | * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2871 | * to hold ndlp reference for the corresponding callback function. |
| 2872 | */ |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2873 | if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2874 | return 0; |
| 2875 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2876 | /* |
| 2877 | * Decrement ndlp reference count to release ndlp reference held |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2878 | * for the failed command's callback function. |
| 2879 | */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2880 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2881 | |
James Smart | 76b2c34 | 2015-04-07 15:07:19 -0400 | [diff] [blame] | 2882 | fdmi_cmd_free_bmpvirt: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2883 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
| 2884 | fdmi_cmd_free_bmp: |
| 2885 | kfree(bmp); |
| 2886 | fdmi_cmd_free_mpvirt: |
| 2887 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2888 | fdmi_cmd_free_mp: |
| 2889 | kfree(mp); |
| 2890 | fdmi_cmd_exit: |
| 2891 | /* Issue FDMI request failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2892 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 2893 | "0244 Issue FDMI request failed Data: x%x\n", |
| 2894 | cmdcode); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2895 | return 1; |
| 2896 | } |
| 2897 | |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2898 | /** |
| 2899 | * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer. |
| 2900 | * @ptr - Context object of the timer. |
| 2901 | * |
| 2902 | * This function set the WORKER_DELAYED_DISC_TMO flag and wake up |
| 2903 | * the worker thread. |
| 2904 | **/ |
| 2905 | void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 2906 | lpfc_delayed_disc_tmo(struct timer_list *t) |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2907 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 2908 | struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2909 | struct lpfc_hba *phba = vport->phba; |
| 2910 | uint32_t tmo_posted; |
| 2911 | unsigned long iflag; |
| 2912 | |
| 2913 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
| 2914 | tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO; |
| 2915 | if (!tmo_posted) |
| 2916 | vport->work_port_events |= WORKER_DELAYED_DISC_TMO; |
| 2917 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
| 2918 | |
| 2919 | if (!tmo_posted) |
| 2920 | lpfc_worker_wake_up(phba); |
| 2921 | return; |
| 2922 | } |
| 2923 | |
| 2924 | /** |
| 2925 | * lpfc_delayed_disc_timeout_handler - Function called by worker thread to |
| 2926 | * handle delayed discovery. |
| 2927 | * @vport: pointer to a host virtual N_Port data structure. |
| 2928 | * |
| 2929 | * This function start nport discovery of the vport. |
| 2930 | **/ |
| 2931 | void |
| 2932 | lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport) |
| 2933 | { |
| 2934 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2935 | |
| 2936 | spin_lock_irq(shost->host_lock); |
| 2937 | if (!(vport->fc_flag & FC_DISC_DELAYED)) { |
| 2938 | spin_unlock_irq(shost->host_lock); |
| 2939 | return; |
| 2940 | } |
| 2941 | vport->fc_flag &= ~FC_DISC_DELAYED; |
| 2942 | spin_unlock_irq(shost->host_lock); |
| 2943 | |
| 2944 | lpfc_do_scr_ns_plogi(vport->phba, vport); |
| 2945 | } |
| 2946 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2947 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2948 | lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2949 | { |
| 2950 | struct lpfc_sli *psli = &phba->sli; |
| 2951 | lpfc_vpd_t *vp = &phba->vpd; |
| 2952 | uint32_t b1, b2, b3, b4, i, rev; |
| 2953 | char c; |
| 2954 | uint32_t *ptr, str[4]; |
| 2955 | uint8_t *fwname; |
| 2956 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 2957 | if (phba->sli_rev == LPFC_SLI_REV4) |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2958 | snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName); |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 2959 | else if (vp->rev.rBit) { |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 2960 | if (psli->sli_flag & LPFC_SLI_ACTIVE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2961 | rev = vp->rev.sli2FwRev; |
| 2962 | else |
| 2963 | rev = vp->rev.sli1FwRev; |
| 2964 | |
| 2965 | b1 = (rev & 0x0000f000) >> 12; |
| 2966 | b2 = (rev & 0x00000f00) >> 8; |
| 2967 | b3 = (rev & 0x000000c0) >> 6; |
| 2968 | b4 = (rev & 0x00000030) >> 4; |
| 2969 | |
| 2970 | switch (b4) { |
| 2971 | case 0: |
| 2972 | c = 'N'; |
| 2973 | break; |
| 2974 | case 1: |
| 2975 | c = 'A'; |
| 2976 | break; |
| 2977 | case 2: |
| 2978 | c = 'B'; |
| 2979 | break; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 2980 | case 3: |
| 2981 | c = 'X'; |
| 2982 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | default: |
| 2984 | c = 0; |
| 2985 | break; |
| 2986 | } |
| 2987 | b4 = (rev & 0x0000000f); |
| 2988 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 2989 | if (psli->sli_flag & LPFC_SLI_ACTIVE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2990 | fwname = vp->rev.sli2FwName; |
| 2991 | else |
| 2992 | fwname = vp->rev.sli1FwName; |
| 2993 | |
| 2994 | for (i = 0; i < 16; i++) |
| 2995 | if (fwname[i] == 0x20) |
| 2996 | fwname[i] = 0; |
| 2997 | |
| 2998 | ptr = (uint32_t*)fwname; |
| 2999 | |
| 3000 | for (i = 0; i < 3; i++) |
| 3001 | str[i] = be32_to_cpu(*ptr++); |
| 3002 | |
| 3003 | if (c == 0) { |
| 3004 | if (flag) |
| 3005 | sprintf(fwrevision, "%d.%d%d (%s)", |
| 3006 | b1, b2, b3, (char *)str); |
| 3007 | else |
| 3008 | sprintf(fwrevision, "%d.%d%d", b1, |
| 3009 | b2, b3); |
| 3010 | } else { |
| 3011 | if (flag) |
| 3012 | sprintf(fwrevision, "%d.%d%d%c%d (%s)", |
| 3013 | b1, b2, b3, c, |
| 3014 | b4, (char *)str); |
| 3015 | else |
| 3016 | sprintf(fwrevision, "%d.%d%d%c%d", |
| 3017 | b1, b2, b3, c, b4); |
| 3018 | } |
| 3019 | } else { |
| 3020 | rev = vp->rev.smFwRev; |
| 3021 | |
| 3022 | b1 = (rev & 0xff000000) >> 24; |
| 3023 | b2 = (rev & 0x00f00000) >> 20; |
| 3024 | b3 = (rev & 0x000f0000) >> 16; |
| 3025 | c = (rev & 0x0000ff00) >> 8; |
| 3026 | b4 = (rev & 0x000000ff); |
| 3027 | |
Roel Kluin | d44a6d2 | 2010-01-17 16:15:57 +0100 | [diff] [blame] | 3028 | sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3029 | } |
| 3030 | return; |
| 3031 | } |