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