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