| 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 * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * 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] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| 23 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
| 28 | |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 29 | #include <scsi/scsi_device.h> |
| 30 | #include <scsi/scsi_transport_fc.h> |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 31 | #include <scsi/scsi.h> |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 32 | #include <scsi/fc/fc_fs.h> |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 33 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 34 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 35 | #include "lpfc_hw.h" |
| 36 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 37 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 38 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 39 | #include "lpfc_disc.h" |
| 40 | #include "lpfc_scsi.h" |
| 41 | #include "lpfc.h" |
| 42 | #include "lpfc_logmsg.h" |
| 43 | #include "lpfc_crtn.h" |
| 44 | #include "lpfc_compat.h" |
| 45 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 46 | /** |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 47 | * lpfc_dump_static_vport - Dump HBA's static vport information. |
| 48 | * @phba: pointer to lpfc hba data structure. |
| 49 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 50 | * @offset: offset for dumping vport info. |
| 51 | * |
| 52 | * The dump mailbox command provides a method for the device driver to obtain |
| 53 | * various types of information from the HBA device. |
| 54 | * |
| 55 | * This routine prepares the mailbox command for dumping list of static |
| 56 | * vports to be created. |
| 57 | **/ |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 58 | int |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 59 | lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, |
| 60 | uint16_t offset) |
| 61 | { |
| 62 | MAILBOX_t *mb; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 63 | struct lpfc_dmabuf *mp; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 64 | |
| 65 | mb = &pmb->u.mb; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 66 | |
| 67 | /* Setup to dump vport info region */ |
| 68 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 69 | mb->mbxCommand = MBX_DUMP_MEMORY; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 70 | mb->un.varDmp.type = DMP_NV_PARAMS; |
| 71 | mb->un.varDmp.entry_index = offset; |
| 72 | mb->un.varDmp.region_id = DMP_REGION_VPORT; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 73 | mb->mbxOwner = OWN_HOST; |
| 74 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 75 | /* For SLI3 HBAs data is embedded in mailbox */ |
| 76 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 77 | mb->un.varDmp.cv = 1; |
| 78 | mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | /* For SLI4 HBAs driver need to allocate memory */ |
| 83 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 84 | if (mp) |
| 85 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 86 | |
| 87 | if (!mp || !mp->virt) { |
| 88 | kfree(mp); |
| 89 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 90 | "2605 lpfc_dump_static_vport: memory" |
| 91 | " allocation failed\n"); |
| 92 | return 1; |
| 93 | } |
| 94 | memset(mp->virt, 0, LPFC_BPL_SIZE); |
| 95 | INIT_LIST_HEAD(&mp->list); |
| 96 | /* save address for completion */ |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 97 | pmb->context1 = (uint8_t *)mp; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 98 | mb->un.varWords[3] = putPaddrLow(mp->phys); |
| 99 | mb->un.varWords[4] = putPaddrHigh(mp->phys); |
| 100 | mb->un.varDmp.sli4_length = sizeof(struct static_vport_info); |
| 101 | |
| 102 | return 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 106 | * lpfc_down_link - Bring down HBAs link. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 107 | * @phba: pointer to lpfc hba data structure. |
| 108 | * @pmb: pointer to the driver internal queue element for mailbox command. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 109 | * |
| 110 | * This routine prepares a mailbox command to bring down HBA link. |
| 111 | **/ |
| 112 | void |
| 113 | lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 114 | { |
| 115 | MAILBOX_t *mb; |
| 116 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 117 | mb = &pmb->u.mb; |
| 118 | mb->mbxCommand = MBX_DOWN_LINK; |
| 119 | mb->mbxOwner = OWN_HOST; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * lpfc_dump_mem - Prepare a mailbox command for reading a region. |
| 124 | * @phba: pointer to lpfc hba data structure. |
| 125 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 126 | * @offset: offset into the region. |
| 127 | * @region_id: config region id. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 128 | * |
| 129 | * The dump mailbox command provides a method for the device driver to obtain |
| 130 | * various types of information from the HBA device. |
| 131 | * |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 132 | * This routine prepares the mailbox command for dumping HBA's config region. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 133 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 134 | void |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 135 | lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset, |
| 136 | uint16_t region_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 137 | { |
| 138 | MAILBOX_t *mb; |
| 139 | void *ctx; |
| 140 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 141 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 142 | ctx = pmb->context2; |
| 143 | |
| 144 | /* Setup to dump VPD region */ |
| 145 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 146 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 147 | mb->un.varDmp.cv = 1; |
| 148 | mb->un.varDmp.type = DMP_NV_PARAMS; |
| 149 | mb->un.varDmp.entry_index = offset; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 150 | mb->un.varDmp.region_id = region_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 151 | mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t)); |
| 152 | mb->un.varDmp.co = 0; |
| 153 | mb->un.varDmp.resp_offset = 0; |
| 154 | pmb->context2 = ctx; |
| 155 | mb->mbxOwner = OWN_HOST; |
| 156 | return; |
| 157 | } |
| 158 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 159 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 160 | * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 161 | * @phba: pointer to lpfc hba data structure. |
| 162 | * @pmb: pointer to the driver internal queue element for mailbox command. |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 163 | * |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 164 | * This function create a dump memory mailbox command to dump wake up |
| 165 | * parameters. |
| 166 | */ |
| 167 | void |
| 168 | lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 169 | { |
| 170 | MAILBOX_t *mb; |
| 171 | void *ctx; |
| 172 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 173 | mb = &pmb->u.mb; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 174 | /* Save context so that we can restore after memset */ |
| 175 | ctx = pmb->context2; |
| 176 | |
| 177 | /* Setup to dump VPD region */ |
| 178 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 179 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 180 | mb->mbxOwner = OWN_HOST; |
| 181 | mb->un.varDmp.cv = 1; |
| 182 | mb->un.varDmp.type = DMP_NV_PARAMS; |
James Smart | 1d1c296 | 2013-07-15 18:33:04 -0400 | [diff] [blame] | 183 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 184 | mb->un.varDmp.entry_index = 0; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 185 | mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID; |
| 186 | mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE; |
| 187 | mb->un.varDmp.co = 0; |
| 188 | mb->un.varDmp.resp_offset = 0; |
| 189 | pmb->context2 = ctx; |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 194 | * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 195 | * @phba: pointer to lpfc hba data structure. |
| 196 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 197 | * |
| 198 | * The read NVRAM mailbox command returns the HBA's non-volatile parameters |
| 199 | * that are used as defaults when the Fibre Channel link is brought on-line. |
| 200 | * |
| 201 | * This routine prepares the mailbox command for reading information stored |
| 202 | * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN. |
| 203 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 204 | void |
| 205 | lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 206 | { |
| 207 | MAILBOX_t *mb; |
| 208 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 209 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 211 | mb->mbxCommand = MBX_READ_NV; |
| 212 | mb->mbxOwner = OWN_HOST; |
| 213 | return; |
| 214 | } |
| 215 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 216 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 217 | * lpfc_config_async - Prepare a mailbox command for enabling HBA async event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 218 | * @phba: pointer to lpfc hba data structure. |
| 219 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 220 | * @ring: ring number for the asynchronous event to be configured. |
| 221 | * |
| 222 | * The asynchronous event enable mailbox command is used to enable the |
| 223 | * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and |
| 224 | * specifies the default ring to which events are posted. |
| 225 | * |
| 226 | * This routine prepares the mailbox command for enabling HBA asynchronous |
| 227 | * event support on a IOCB ring. |
| 228 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 229 | void |
| 230 | lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, |
| 231 | uint32_t ring) |
| 232 | { |
| 233 | MAILBOX_t *mb; |
| 234 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 235 | mb = &pmb->u.mb; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 236 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 237 | mb->mbxCommand = MBX_ASYNCEVT_ENABLE; |
| 238 | mb->un.varCfgAsyncEvent.ring = ring; |
| 239 | mb->mbxOwner = OWN_HOST; |
| 240 | return; |
| 241 | } |
| 242 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 243 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 244 | * lpfc_heart_beat - Prepare a mailbox command for heart beat |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 245 | * @phba: pointer to lpfc hba data structure. |
| 246 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 247 | * |
| 248 | * The heart beat mailbox command is used to detect an unresponsive HBA, which |
| 249 | * is defined as any device where no error attention is sent and both mailbox |
| 250 | * and rings are not processed. |
| 251 | * |
| 252 | * This routine prepares the mailbox command for issuing a heart beat in the |
| 253 | * form of mailbox command to the HBA. The timely completion of the heart |
| 254 | * beat mailbox command indicates the health of the HBA. |
| 255 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 256 | void |
| 257 | lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 258 | { |
| 259 | MAILBOX_t *mb; |
| 260 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 261 | mb = &pmb->u.mb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 262 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 263 | mb->mbxCommand = MBX_HEARTBEAT; |
| 264 | mb->mbxOwner = OWN_HOST; |
| 265 | return; |
| 266 | } |
| 267 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 268 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 269 | * lpfc_read_topology - Prepare a mailbox command for reading HBA topology |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 270 | * @phba: pointer to lpfc hba data structure. |
| 271 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 272 | * @mp: DMA buffer memory for reading the link attention information into. |
| 273 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 274 | * The read topology mailbox command is issued to read the link topology |
| 275 | * information indicated by the HBA port when the Link Event bit of the Host |
| 276 | * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link |
| 277 | * Attention ACQE is received from the port (For SLI-4). A Link Event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 278 | * Attention occurs based on an exception detected at the Fibre Channel link |
| 279 | * interface. |
| 280 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 281 | * This routine prepares the mailbox command for reading HBA link topology |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 282 | * information. A DMA memory has been set aside and address passed to the |
| 283 | * HBA through @mp for the HBA to DMA link attention information into the |
| 284 | * memory as part of the execution of the mailbox command. |
| 285 | * |
| 286 | * Return codes |
| 287 | * 0 - Success (currently always return 0) |
| 288 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 289 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 290 | lpfc_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, |
| 291 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 292 | { |
| 293 | MAILBOX_t *mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 294 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 295 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 296 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 297 | |
| 298 | INIT_LIST_HEAD(&mp->list); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 299 | mb->mbxCommand = MBX_READ_TOPOLOGY; |
| 300 | mb->un.varReadTop.lilpBde64.tus.f.bdeSize = LPFC_ALPA_MAP_SIZE; |
| 301 | mb->un.varReadTop.lilpBde64.addrHigh = putPaddrHigh(mp->phys); |
| 302 | mb->un.varReadTop.lilpBde64.addrLow = putPaddrLow(mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 303 | |
| 304 | /* Save address for later completion and set the owner to host so that |
| 305 | * the FW knows this mailbox is available for processing. |
| 306 | */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 307 | pmb->context1 = (uint8_t *)mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 308 | mb->mbxOwner = OWN_HOST; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 309 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 310 | } |
| 311 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 312 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 313 | * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 314 | * @phba: pointer to lpfc hba data structure. |
| 315 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 316 | * |
| 317 | * The clear link attention mailbox command is issued to clear the link event |
| 318 | * attention condition indicated by the Link Event bit of the Host Attention |
| 319 | * (HSTATT) register. The link event attention condition is cleared only if |
| 320 | * the event tag specified matches that of the current link event counter. |
| 321 | * The current event tag is read using the read link attention event mailbox |
| 322 | * command. |
| 323 | * |
| 324 | * This routine prepares the mailbox command for clearing HBA link attention |
| 325 | * information. |
| 326 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 327 | void |
| 328 | lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 329 | { |
| 330 | MAILBOX_t *mb; |
| 331 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 332 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 333 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 334 | |
| 335 | mb->un.varClearLA.eventTag = phba->fc_eventTag; |
| 336 | mb->mbxCommand = MBX_CLEAR_LA; |
| 337 | mb->mbxOwner = OWN_HOST; |
| 338 | return; |
| 339 | } |
| 340 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 341 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 342 | * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 343 | * @phba: pointer to lpfc hba data structure. |
| 344 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 345 | * |
| 346 | * The configure link mailbox command is used before the initialize link |
| 347 | * mailbox command to override default value and to configure link-oriented |
| 348 | * parameters such as DID address and various timers. Typically, this |
| 349 | * command would be used after an F_Port login to set the returned DID address |
| 350 | * and the fabric timeout values. This command is not valid before a configure |
| 351 | * port command has configured the HBA port. |
| 352 | * |
| 353 | * This routine prepares the mailbox command for configuring link on a HBA. |
| 354 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 355 | void |
| 356 | lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 357 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 358 | struct lpfc_vport *vport = phba->pport; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 359 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 360 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 361 | |
| 362 | /* NEW_FEATURE |
| 363 | * SLI-2, Coalescing Response Feature. |
| 364 | */ |
James Smart | 1d1c296 | 2013-07-15 18:33:04 -0400 | [diff] [blame] | 365 | if (phba->cfg_cr_delay && (phba->sli_rev < LPFC_SLI_REV4)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 366 | mb->un.varCfgLnk.cr = 1; |
| 367 | mb->un.varCfgLnk.ci = 1; |
| 368 | mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay; |
| 369 | mb->un.varCfgLnk.cr_count = phba->cfg_cr_count; |
| 370 | } |
| 371 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 372 | mb->un.varCfgLnk.myId = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 373 | mb->un.varCfgLnk.edtov = phba->fc_edtov; |
| 374 | mb->un.varCfgLnk.arbtov = phba->fc_arbtov; |
| 375 | mb->un.varCfgLnk.ratov = phba->fc_ratov; |
| 376 | mb->un.varCfgLnk.rttov = phba->fc_rttov; |
| 377 | mb->un.varCfgLnk.altov = phba->fc_altov; |
| 378 | mb->un.varCfgLnk.crtov = phba->fc_crtov; |
| 379 | mb->un.varCfgLnk.citov = phba->fc_citov; |
| 380 | |
James Smart | 1d1c296 | 2013-07-15 18:33:04 -0400 | [diff] [blame] | 381 | if (phba->cfg_ack0 && (phba->sli_rev < LPFC_SLI_REV4)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 382 | mb->un.varCfgLnk.ack0_enable = 1; |
| 383 | |
| 384 | mb->mbxCommand = MBX_CONFIG_LINK; |
| 385 | mb->mbxOwner = OWN_HOST; |
| 386 | return; |
| 387 | } |
| 388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 389 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 390 | * lpfc_config_msi - Prepare a mailbox command for configuring msi-x |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 391 | * @phba: pointer to lpfc hba data structure. |
| 392 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 393 | * |
| 394 | * The configure MSI-X mailbox command is used to configure the HBA's SLI-3 |
| 395 | * MSI-X multi-message interrupt vector association to interrupt attention |
| 396 | * conditions. |
| 397 | * |
| 398 | * Return codes |
| 399 | * 0 - Success |
| 400 | * -EINVAL - Failure |
| 401 | **/ |
| 402 | int |
| 403 | lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 404 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 405 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 406 | uint32_t attentionConditions[2]; |
| 407 | |
| 408 | /* Sanity check */ |
| 409 | if (phba->cfg_use_msi != 2) { |
| 410 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 411 | "0475 Not configured for supporting MSI-X " |
| 412 | "cfg_use_msi: 0x%x\n", phba->cfg_use_msi); |
| 413 | return -EINVAL; |
| 414 | } |
| 415 | |
| 416 | if (phba->sli_rev < 3) { |
| 417 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 418 | "0476 HBA not supporting SLI-3 or later " |
| 419 | "SLI Revision: 0x%x\n", phba->sli_rev); |
| 420 | return -EINVAL; |
| 421 | } |
| 422 | |
| 423 | /* Clear mailbox command fields */ |
| 424 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 425 | |
| 426 | /* |
| 427 | * SLI-3, Message Signaled Interrupt Fearure. |
| 428 | */ |
| 429 | |
| 430 | /* Multi-message attention configuration */ |
| 431 | attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT | |
| 432 | HA_LATT | HA_MBATT); |
| 433 | attentionConditions[1] = 0; |
| 434 | |
| 435 | mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0]; |
| 436 | mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1]; |
| 437 | |
| 438 | /* |
| 439 | * Set up message number to HA bit association |
| 440 | */ |
| 441 | #ifdef __BIG_ENDIAN_BITFIELD |
| 442 | /* RA0 (FCP Ring) */ |
| 443 | mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1; |
| 444 | /* RA1 (Other Protocol Extra Ring) */ |
| 445 | mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1; |
| 446 | #else /* __LITTLE_ENDIAN_BITFIELD */ |
| 447 | /* RA0 (FCP Ring) */ |
| 448 | mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1; |
| 449 | /* RA1 (Other Protocol Extra Ring) */ |
| 450 | mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1; |
| 451 | #endif |
| 452 | /* Multi-message interrupt autoclear configuration*/ |
| 453 | mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0]; |
| 454 | mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1]; |
| 455 | |
| 456 | /* For now, HBA autoclear does not work reliably, disable it */ |
| 457 | mb->un.varCfgMSI.autoClearHA[0] = 0; |
| 458 | mb->un.varCfgMSI.autoClearHA[1] = 0; |
| 459 | |
| 460 | /* Set command and owner bit */ |
| 461 | mb->mbxCommand = MBX_CONFIG_MSI; |
| 462 | mb->mbxOwner = OWN_HOST; |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 468 | * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 469 | * @phba: pointer to lpfc hba data structure. |
| 470 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 471 | * @topology: the link topology for the link to be initialized to. |
| 472 | * @linkspeed: the link speed for the link to be initialized to. |
| 473 | * |
| 474 | * The initialize link mailbox command is used to initialize the Fibre |
| 475 | * Channel link. This command must follow a configure port command that |
| 476 | * establishes the mode of operation. |
| 477 | * |
| 478 | * This routine prepares the mailbox command for initializing link on a HBA |
| 479 | * with the specified link topology and speed. |
| 480 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 481 | void |
| 482 | lpfc_init_link(struct lpfc_hba * phba, |
| 483 | LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed) |
| 484 | { |
| 485 | lpfc_vpd_t *vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 486 | MAILBOX_t *mb; |
| 487 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 488 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 489 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 490 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 491 | switch (topology) { |
| 492 | case FLAGS_TOPOLOGY_MODE_LOOP_PT: |
| 493 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; |
| 494 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; |
| 495 | break; |
| 496 | case FLAGS_TOPOLOGY_MODE_PT_PT: |
| 497 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 498 | break; |
| 499 | case FLAGS_TOPOLOGY_MODE_LOOP: |
| 500 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; |
| 501 | break; |
| 502 | case FLAGS_TOPOLOGY_MODE_PT_LOOP: |
| 503 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 504 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; |
| 505 | break; |
Jamie Wellnitz | 367c271 | 2006-02-28 19:25:32 -0500 | [diff] [blame] | 506 | case FLAGS_LOCAL_LB: |
| 507 | mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB; |
| 508 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 509 | } |
| 510 | |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 511 | if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && |
| 512 | mb->un.varInitLnk.link_flags & FLAGS_TOPOLOGY_MODE_LOOP) { |
| 513 | /* Failover is not tried for Lancer G6 */ |
| 514 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 515 | phba->cfg_topology = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 516 | } |
| 517 | |
James Smart | 4b0b91d | 2006-04-15 11:53:00 -0400 | [diff] [blame] | 518 | /* Enable asynchronous ABTS responses from firmware */ |
| 519 | mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT; |
| 520 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 521 | /* NEW_FEATURE |
| 522 | * Setting up the link speed |
| 523 | */ |
| 524 | vpd = &phba->vpd; |
| 525 | if (vpd->rev.feaLevelHigh >= 0x02){ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 526 | switch(linkspeed){ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 527 | case LPFC_USER_LINK_SPEED_1G: |
| 528 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 529 | mb->un.varInitLnk.link_speed = LINK_SPEED_1G; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 530 | break; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 531 | case LPFC_USER_LINK_SPEED_2G: |
| 532 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 533 | mb->un.varInitLnk.link_speed = LINK_SPEED_2G; |
| 534 | break; |
| 535 | case LPFC_USER_LINK_SPEED_4G: |
| 536 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 537 | mb->un.varInitLnk.link_speed = LINK_SPEED_4G; |
| 538 | break; |
| 539 | case LPFC_USER_LINK_SPEED_8G: |
| 540 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 541 | mb->un.varInitLnk.link_speed = LINK_SPEED_8G; |
| 542 | break; |
| 543 | case LPFC_USER_LINK_SPEED_10G: |
| 544 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 545 | mb->un.varInitLnk.link_speed = LINK_SPEED_10G; |
| 546 | break; |
| 547 | case LPFC_USER_LINK_SPEED_16G: |
| 548 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 549 | mb->un.varInitLnk.link_speed = LINK_SPEED_16G; |
| 550 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 551 | case LPFC_USER_LINK_SPEED_32G: |
| 552 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 553 | mb->un.varInitLnk.link_speed = LINK_SPEED_32G; |
| 554 | break; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 555 | case LPFC_USER_LINK_SPEED_AUTO: |
| 556 | default: |
| 557 | mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 558 | break; |
| 559 | } |
| 560 | |
| 561 | } |
| 562 | else |
| 563 | mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; |
| 564 | |
| 565 | mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK; |
| 566 | mb->mbxOwner = OWN_HOST; |
| 567 | mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA; |
| 568 | return; |
| 569 | } |
| 570 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 571 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 572 | * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 573 | * @phba: pointer to lpfc hba data structure. |
| 574 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 575 | * @vpi: virtual N_Port identifier. |
| 576 | * |
| 577 | * The read service parameter mailbox command is used to read the HBA port |
| 578 | * service parameters. The service parameters are read into the buffer |
| 579 | * specified directly by a BDE in the mailbox command. These service |
| 580 | * parameters may then be used to build the payload of an N_Port/F_POrt |
| 581 | * login request and reply (LOGI/ACC). |
| 582 | * |
| 583 | * This routine prepares the mailbox command for reading HBA port service |
| 584 | * parameters. The DMA memory is allocated in this function and the addresses |
| 585 | * are populated into the mailbox command for the HBA to DMA the service |
| 586 | * parameters into. |
| 587 | * |
| 588 | * Return codes |
| 589 | * 0 - Success |
| 590 | * 1 - DMA memory allocation failed |
| 591 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 592 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 593 | lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 594 | { |
| 595 | struct lpfc_dmabuf *mp; |
| 596 | MAILBOX_t *mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 597 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 598 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 600 | |
| 601 | mb->mbxOwner = OWN_HOST; |
| 602 | |
| 603 | /* Get a buffer to hold the HBAs Service Parameters */ |
| 604 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 605 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 606 | if (mp) |
| 607 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 608 | if (!mp || !mp->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 609 | kfree(mp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 610 | mb->mbxCommand = MBX_READ_SPARM64; |
| 611 | /* READ_SPARAM: no buffers */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 612 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 613 | "0301 READ_SPARAM: no buffers\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 614 | return (1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 615 | } |
| 616 | INIT_LIST_HEAD(&mp->list); |
| 617 | mb->mbxCommand = MBX_READ_SPARM64; |
| 618 | mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); |
| 619 | mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys); |
| 620 | mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 621 | if (phba->sli_rev >= LPFC_SLI_REV3) |
| 622 | mb->un.varRdSparm.vpi = phba->vpi_ids[vpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 623 | |
| 624 | /* save address for completion */ |
| 625 | pmb->context1 = mp; |
| 626 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 627 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 628 | } |
| 629 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 630 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 631 | * lpfc_unreg_did - Prepare a mailbox command for unregistering DID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 632 | * @phba: pointer to lpfc hba data structure. |
| 633 | * @vpi: virtual N_Port identifier. |
| 634 | * @did: remote port identifier. |
| 635 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 636 | * |
| 637 | * The unregister DID mailbox command is used to unregister an N_Port/F_Port |
| 638 | * login for an unknown RPI by specifying the DID of a remote port. This |
| 639 | * command frees an RPI context in the HBA port. This has the effect of |
| 640 | * performing an implicit N_Port/F_Port logout. |
| 641 | * |
| 642 | * This routine prepares the mailbox command for unregistering a remote |
| 643 | * N_Port/F_Port (DID) login. |
| 644 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 645 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 646 | lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did, |
| 647 | LPFC_MBOXQ_t * pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 648 | { |
| 649 | MAILBOX_t *mb; |
| 650 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 651 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 652 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 653 | |
| 654 | mb->un.varUnregDID.did = did; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 655 | mb->un.varUnregDID.vpi = vpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 656 | if ((vpi != 0xffff) && |
| 657 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 658 | mb->un.varUnregDID.vpi = phba->vpi_ids[vpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 659 | |
| 660 | mb->mbxCommand = MBX_UNREG_D_ID; |
| 661 | mb->mbxOwner = OWN_HOST; |
| 662 | return; |
| 663 | } |
| 664 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 665 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 666 | * lpfc_read_config - Prepare a mailbox command for reading HBA configuration |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 667 | * @phba: pointer to lpfc hba data structure. |
| 668 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 669 | * |
| 670 | * The read configuration mailbox command is used to read the HBA port |
| 671 | * configuration parameters. This mailbox command provides a method for |
| 672 | * seeing any parameters that may have changed via various configuration |
| 673 | * mailbox commands. |
| 674 | * |
| 675 | * This routine prepares the mailbox command for reading out HBA configuration |
| 676 | * parameters. |
| 677 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 678 | void |
| 679 | lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 680 | { |
| 681 | MAILBOX_t *mb; |
| 682 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 683 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 684 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 685 | |
| 686 | mb->mbxCommand = MBX_READ_CONFIG; |
| 687 | mb->mbxOwner = OWN_HOST; |
| 688 | return; |
| 689 | } |
| 690 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 691 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 692 | * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 693 | * @phba: pointer to lpfc hba data structure. |
| 694 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 695 | * |
| 696 | * The read link status mailbox command is used to read the link status from |
| 697 | * the HBA. Link status includes all link-related error counters. These |
| 698 | * counters are maintained by the HBA and originated in the link hardware |
| 699 | * unit. Note that all of these counters wrap. |
| 700 | * |
| 701 | * This routine prepares the mailbox command for reading out HBA link status. |
| 702 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 703 | void |
| 704 | lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 705 | { |
| 706 | MAILBOX_t *mb; |
| 707 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 708 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 709 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 710 | |
| 711 | mb->mbxCommand = MBX_READ_LNK_STAT; |
| 712 | mb->mbxOwner = OWN_HOST; |
| 713 | return; |
| 714 | } |
| 715 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 716 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 717 | * lpfc_reg_rpi - Prepare a mailbox command for registering remote login |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 718 | * @phba: pointer to lpfc hba data structure. |
| 719 | * @vpi: virtual N_Port identifier. |
| 720 | * @did: remote port identifier. |
| 721 | * @param: pointer to memory holding the server parameters. |
| 722 | * @pmb: pointer to the driver internal queue element for mailbox command. |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 723 | * @rpi: the rpi to use in the registration (usually only used for SLI4. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 724 | * |
| 725 | * The registration login mailbox command is used to register an N_Port or |
| 726 | * F_Port login. This registration allows the HBA to cache the remote N_Port |
| 727 | * service parameters internally and thereby make the appropriate FC-2 |
| 728 | * decisions. The remote port service parameters are handed off by the driver |
| 729 | * to the HBA using a descriptor entry that directly identifies a buffer in |
| 730 | * host memory. In exchange, the HBA returns an RPI identifier. |
| 731 | * |
| 732 | * This routine prepares the mailbox command for registering remote port login. |
| 733 | * The function allocates DMA buffer for passing the service parameters to the |
| 734 | * HBA with the mailbox command. |
| 735 | * |
| 736 | * Return codes |
| 737 | * 0 - Success |
| 738 | * 1 - DMA memory allocation failed |
| 739 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 740 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 741 | lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did, |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 742 | uint8_t *param, LPFC_MBOXQ_t *pmb, uint16_t rpi) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 743 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 744 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 745 | uint8_t *sparam; |
| 746 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 747 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 749 | |
| 750 | mb->un.varRegLogin.rpi = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 751 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 752 | mb->un.varRegLogin.rpi = phba->sli4_hba.rpi_ids[rpi]; |
| 753 | if (phba->sli_rev >= LPFC_SLI_REV3) |
| 754 | mb->un.varRegLogin.vpi = phba->vpi_ids[vpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 755 | mb->un.varRegLogin.did = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 756 | mb->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 757 | /* Get a buffer to hold NPorts Service Parameters */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 758 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 759 | if (mp) |
| 760 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 761 | if (!mp || !mp->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 762 | kfree(mp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 763 | mb->mbxCommand = MBX_REG_LOGIN64; |
| 764 | /* REG_LOGIN: no buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 765 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 766 | "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, " |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 767 | "rpi x%x\n", vpi, did, rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 768 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 769 | } |
| 770 | INIT_LIST_HEAD(&mp->list); |
| 771 | sparam = mp->virt; |
| 772 | |
| 773 | /* Copy param's into a new buffer */ |
| 774 | memcpy(sparam, param, sizeof (struct serv_parm)); |
| 775 | |
| 776 | /* save address for completion */ |
| 777 | pmb->context1 = (uint8_t *) mp; |
| 778 | |
| 779 | mb->mbxCommand = MBX_REG_LOGIN64; |
| 780 | mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); |
| 781 | mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys); |
| 782 | mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys); |
| 783 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 784 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 785 | } |
| 786 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 787 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 788 | * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 789 | * @phba: pointer to lpfc hba data structure. |
| 790 | * @vpi: virtual N_Port identifier. |
| 791 | * @rpi: remote port identifier |
| 792 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 793 | * |
| 794 | * The unregistration login mailbox command is used to unregister an N_Port |
| 795 | * or F_Port login. This command frees an RPI context in the HBA. It has the |
| 796 | * effect of performing an implicit N_Port/F_Port logout. |
| 797 | * |
| 798 | * This routine prepares the mailbox command for unregistering remote port |
| 799 | * login. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 800 | * |
| 801 | * For SLI4 ports, the rpi passed to this function must be the physical |
| 802 | * rpi value, not the logical index. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 803 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 804 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 805 | lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi, |
| 806 | LPFC_MBOXQ_t * pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 807 | { |
| 808 | MAILBOX_t *mb; |
| 809 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 810 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 811 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 812 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 813 | mb->un.varUnregLogin.rpi = rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 814 | mb->un.varUnregLogin.rsvd1 = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 815 | if (phba->sli_rev >= LPFC_SLI_REV3) |
| 816 | mb->un.varUnregLogin.vpi = phba->vpi_ids[vpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 817 | |
| 818 | mb->mbxCommand = MBX_UNREG_LOGIN; |
| 819 | mb->mbxOwner = OWN_HOST; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 820 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 821 | return; |
| 822 | } |
| 823 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 824 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 825 | * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA. |
| 826 | * @vport: pointer to a vport object. |
| 827 | * |
| 828 | * This routine sends mailbox command to unregister all active RPIs for |
| 829 | * a vport. |
| 830 | **/ |
| 831 | void |
| 832 | lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport) |
| 833 | { |
| 834 | struct lpfc_hba *phba = vport->phba; |
| 835 | LPFC_MBOXQ_t *mbox; |
| 836 | int rc; |
| 837 | |
| 838 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 839 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 840 | /* |
| 841 | * For SLI4 functions, the rpi field is overloaded for |
| 842 | * the vport context unreg all. This routine passes |
| 843 | * 0 for the rpi field in lpfc_unreg_login for compatibility |
| 844 | * with SLI3 and then overrides the rpi field with the |
| 845 | * expected value for SLI4. |
| 846 | */ |
| 847 | lpfc_unreg_login(phba, vport->vpi, phba->vpi_ids[vport->vpi], |
| 848 | mbox); |
| 849 | mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 850 | mbox->vport = vport; |
| 851 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 852 | mbox->context1 = NULL; |
| 853 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 854 | if (rc == MBX_NOT_FINISHED) |
| 855 | mempool_free(mbox, phba->mbox_mem_pool); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 860 | * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 861 | * @phba: pointer to lpfc hba data structure. |
| 862 | * @vpi: virtual N_Port identifier. |
| 863 | * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port). |
| 864 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 865 | * |
| 866 | * The registration vport identifier mailbox command is used to activate a |
| 867 | * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the |
| 868 | * N_Port_ID against the information in the selected virtual N_Port context |
| 869 | * block and marks it active to allow normal processing of IOCB commands and |
| 870 | * received unsolicited exchanges. |
| 871 | * |
| 872 | * This routine prepares the mailbox command for registering a virtual N_Port. |
| 873 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 874 | void |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 875 | lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 876 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 877 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 878 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 879 | |
| 880 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 881 | /* |
| 882 | * Set the re-reg VPI bit for f/w to update the MAC address. |
| 883 | */ |
| 884 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 885 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) |
| 886 | mb->un.varRegVpi.upd = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 887 | |
| 888 | mb->un.varRegVpi.vpi = phba->vpi_ids[vport->vpi]; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 889 | mb->un.varRegVpi.sid = vport->fc_myDID; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 890 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 891 | mb->un.varRegVpi.vfi = phba->sli4_hba.vfi_ids[vport->vfi]; |
| 892 | else |
| 893 | mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 894 | memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname, |
| 895 | sizeof(struct lpfc_name)); |
| 896 | mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]); |
| 897 | mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 898 | |
| 899 | mb->mbxCommand = MBX_REG_VPI; |
| 900 | mb->mbxOwner = OWN_HOST; |
| 901 | return; |
| 902 | |
| 903 | } |
| 904 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 905 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 906 | * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 907 | * @phba: pointer to lpfc hba data structure. |
| 908 | * @vpi: virtual N_Port identifier. |
| 909 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 910 | * |
| 911 | * The unregistration vport identifier mailbox command is used to inactivate |
| 912 | * a virtual N_Port. The driver must have logged out and unregistered all |
| 913 | * remote N_Ports to abort any activity on the virtual N_Port. The HBA will |
| 914 | * unregisters any default RPIs associated with the specified vpi, aborting |
| 915 | * any active exchanges. The HBA will post the mailbox response after making |
| 916 | * the virtual N_Port inactive. |
| 917 | * |
| 918 | * This routine prepares the mailbox command for unregistering a virtual |
| 919 | * N_Port. |
| 920 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 921 | void |
| 922 | lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb) |
| 923 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 924 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 925 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 926 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 927 | if (phba->sli_rev == LPFC_SLI_REV3) |
| 928 | mb->un.varUnregVpi.vpi = phba->vpi_ids[vpi]; |
| 929 | else if (phba->sli_rev >= LPFC_SLI_REV4) |
| 930 | mb->un.varUnregVpi.sli4_vpi = phba->vpi_ids[vpi]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 931 | |
| 932 | mb->mbxCommand = MBX_UNREG_VPI; |
| 933 | mb->mbxOwner = OWN_HOST; |
| 934 | return; |
| 935 | |
| 936 | } |
| 937 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 938 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 939 | * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 940 | * @phba: pointer to lpfc hba data structure. |
| 941 | * |
| 942 | * This routine sets up and initializes the IOCB rings in the Port Control |
| 943 | * Block (PCB). |
| 944 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 945 | static void |
| 946 | lpfc_config_pcb_setup(struct lpfc_hba * phba) |
| 947 | { |
| 948 | struct lpfc_sli *psli = &phba->sli; |
| 949 | struct lpfc_sli_ring *pring; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 950 | PCB_t *pcbp = phba->pcb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 951 | dma_addr_t pdma_addr; |
| 952 | uint32_t offset; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 953 | uint32_t iocbCnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 954 | int i; |
| 955 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 956 | pcbp->maxRing = (psli->num_rings - 1); |
| 957 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 958 | for (i = 0; i < psli->num_rings; i++) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 959 | pring = &psli->sli3_ring[i]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 960 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 961 | pring->sli.sli3.sizeCiocb = |
| 962 | phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE : |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 963 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 964 | pring->sli.sli3.sizeRiocb = |
| 965 | phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE : |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 966 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 967 | /* A ring MUST have both cmd and rsp entries defined to be |
| 968 | valid */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 969 | if ((pring->sli.sli3.numCiocb == 0) || |
| 970 | (pring->sli.sli3.numRiocb == 0)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 971 | pcbp->rdsc[i].cmdEntries = 0; |
| 972 | pcbp->rdsc[i].rspEntries = 0; |
| 973 | pcbp->rdsc[i].cmdAddrHigh = 0; |
| 974 | pcbp->rdsc[i].rspAddrHigh = 0; |
| 975 | pcbp->rdsc[i].cmdAddrLow = 0; |
| 976 | pcbp->rdsc[i].rspAddrLow = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 977 | pring->sli.sli3.cmdringaddr = NULL; |
| 978 | pring->sli.sli3.rspringaddr = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 979 | continue; |
| 980 | } |
| 981 | /* Command ring setup for ring */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 982 | pring->sli.sli3.cmdringaddr = (void *)&phba->IOCBs[iocbCnt]; |
| 983 | pcbp->rdsc[i].cmdEntries = pring->sli.sli3.numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 984 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 985 | offset = (uint8_t *) &phba->IOCBs[iocbCnt] - |
| 986 | (uint8_t *) phba->slim2p.virt; |
| 987 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 988 | pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr); |
| 989 | pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 990 | iocbCnt += pring->sli.sli3.numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 991 | |
| 992 | /* Response ring setup for ring */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 993 | pring->sli.sli3.rspringaddr = (void *) &phba->IOCBs[iocbCnt]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 994 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 995 | pcbp->rdsc[i].rspEntries = pring->sli.sli3.numRiocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 996 | offset = (uint8_t *)&phba->IOCBs[iocbCnt] - |
| 997 | (uint8_t *)phba->slim2p.virt; |
| 998 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 999 | pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr); |
| 1000 | pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 1001 | iocbCnt += pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1002 | } |
| 1003 | } |
| 1004 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1005 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1006 | * lpfc_read_rev - Prepare a mailbox command for reading HBA revision |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1007 | * @phba: pointer to lpfc hba data structure. |
| 1008 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1009 | * |
| 1010 | * The read revision mailbox command is used to read the revision levels of |
| 1011 | * the HBA components. These components include hardware units, resident |
| 1012 | * firmware, and available firmware. HBAs that supports SLI-3 mode of |
| 1013 | * operation provide different response information depending on the version |
| 1014 | * requested by the driver. |
| 1015 | * |
| 1016 | * This routine prepares the mailbox command for reading HBA revision |
| 1017 | * information. |
| 1018 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1019 | void |
| 1020 | lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 1021 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1022 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1023 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 1024 | mb->un.varRdRev.cv = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1025 | mb->un.varRdRev.v3req = 1; /* Request SLI3 info */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1026 | mb->mbxCommand = MBX_READ_REV; |
| 1027 | mb->mbxOwner = OWN_HOST; |
| 1028 | return; |
| 1029 | } |
| 1030 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 1031 | void |
| 1032 | lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 1033 | { |
| 1034 | MAILBOX_t *mb = &pmb->u.mb; |
| 1035 | struct lpfc_mqe *mqe; |
| 1036 | |
| 1037 | switch (mb->mbxCommand) { |
| 1038 | case MBX_READ_REV: |
| 1039 | mqe = &pmb->u.mqe; |
| 1040 | lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name, |
| 1041 | mqe->un.read_rev.fw_name, 16); |
| 1042 | lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name, |
| 1043 | mqe->un.read_rev.ulp_fw_name, 16); |
| 1044 | break; |
| 1045 | default: |
| 1046 | break; |
| 1047 | } |
| 1048 | return; |
| 1049 | } |
| 1050 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1051 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1052 | * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2 |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1053 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 1054 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 1055 | * |
| 1056 | * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA |
| 1057 | * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs |
| 1058 | * the Sequence Length Test using the fields in the Selection Profile 2 |
| 1059 | * extension in words 20:31. |
| 1060 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1061 | static void |
| 1062 | lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb, |
| 1063 | struct lpfc_hbq_init *hbq_desc) |
| 1064 | { |
| 1065 | hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 1066 | hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen; |
| 1067 | hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff; |
| 1068 | } |
| 1069 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1070 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1071 | * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3 |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1072 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 1073 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 1074 | * |
| 1075 | * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA |
| 1076 | * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs |
| 1077 | * the Sequence Length Test and Byte Field Test using the fields in the |
| 1078 | * Selection Profile 3 extension in words 20:31. |
| 1079 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1080 | static void |
| 1081 | lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb, |
| 1082 | struct lpfc_hbq_init *hbq_desc) |
| 1083 | { |
| 1084 | hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 1085 | hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen; |
| 1086 | hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff; |
| 1087 | hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff; |
| 1088 | memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch, |
| 1089 | sizeof(hbqmb->profiles.profile3.cmdmatch)); |
| 1090 | } |
| 1091 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1092 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1093 | * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5 |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1094 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 1095 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 1096 | * |
| 1097 | * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The |
| 1098 | * HBA tests the initial frame of an incoming sequence using the frame's |
| 1099 | * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test |
| 1100 | * and Byte Field Test using the fields in the Selection Profile 5 extension |
| 1101 | * words 20:31. |
| 1102 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1103 | static void |
| 1104 | lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb, |
| 1105 | struct lpfc_hbq_init *hbq_desc) |
| 1106 | { |
| 1107 | hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 1108 | hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen; |
| 1109 | hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff; |
| 1110 | hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff; |
| 1111 | memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch, |
| 1112 | sizeof(hbqmb->profiles.profile5.cmdmatch)); |
| 1113 | } |
| 1114 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1115 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1116 | * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1117 | * @phba: pointer to lpfc hba data structure. |
| 1118 | * @id: HBQ identifier. |
| 1119 | * @hbq_desc: pointer to the HBA descriptor data structure. |
| 1120 | * @hbq_entry_index: index of the HBQ entry data structures. |
| 1121 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1122 | * |
| 1123 | * The configure HBQ (Host Buffer Queue) mailbox command is used to configure |
| 1124 | * an HBQ. The configuration binds events that require buffers to a particular |
| 1125 | * ring and HBQ based on a selection profile. |
| 1126 | * |
| 1127 | * This routine prepares the mailbox command for configuring an HBQ. |
| 1128 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1129 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1130 | lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id, |
| 1131 | struct lpfc_hbq_init *hbq_desc, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1132 | uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb) |
| 1133 | { |
| 1134 | int i; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1135 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1136 | struct config_hbq_var *hbqmb = &mb->un.varCfgHbq; |
| 1137 | |
| 1138 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1139 | hbqmb->hbqId = id; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1140 | hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */ |
| 1141 | hbqmb->recvNotify = hbq_desc->rn; /* Receive |
| 1142 | * Notification */ |
| 1143 | hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks |
| 1144 | * # in words 0-19 */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1145 | hbqmb->profile = hbq_desc->profile; /* Selection profile: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1146 | * 0 = all, |
| 1147 | * 7 = logentry */ |
| 1148 | hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring |
| 1149 | * e.g. Ring0=b0001, |
| 1150 | * ring2=b0100 */ |
| 1151 | hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4 |
| 1152 | * or 5 */ |
| 1153 | hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this |
| 1154 | * HBQ will be used |
| 1155 | * for LogEntry |
| 1156 | * buffers */ |
| 1157 | hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) + |
| 1158 | hbq_entry_index * sizeof(struct lpfc_hbq_entry); |
| 1159 | hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys); |
| 1160 | |
| 1161 | mb->mbxCommand = MBX_CONFIG_HBQ; |
| 1162 | mb->mbxOwner = OWN_HOST; |
| 1163 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1164 | /* Copy info for profiles 2,3,5. Other |
| 1165 | * profiles this area is reserved |
| 1166 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1167 | if (hbq_desc->profile == 2) |
| 1168 | lpfc_build_hbq_profile2(hbqmb, hbq_desc); |
| 1169 | else if (hbq_desc->profile == 3) |
| 1170 | lpfc_build_hbq_profile3(hbqmb, hbq_desc); |
| 1171 | else if (hbq_desc->profile == 5) |
| 1172 | lpfc_build_hbq_profile5(hbqmb, hbq_desc); |
| 1173 | |
| 1174 | /* Return if no rctl / type masks for this HBQ */ |
| 1175 | if (!hbq_desc->mask_count) |
| 1176 | return; |
| 1177 | |
| 1178 | /* Otherwise we setup specific rctl / type masks for this HBQ */ |
| 1179 | for (i = 0; i < hbq_desc->mask_count; i++) { |
| 1180 | hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch; |
| 1181 | hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask; |
| 1182 | hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch; |
| 1183 | hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask; |
| 1184 | } |
| 1185 | |
| 1186 | return; |
| 1187 | } |
| 1188 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1189 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1190 | * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1191 | * @phba: pointer to lpfc hba data structure. |
| 1192 | * @ring: |
| 1193 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1194 | * |
| 1195 | * The configure ring mailbox command is used to configure an IOCB ring. This |
| 1196 | * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the |
| 1197 | * ring. This is used to map incoming sequences to a particular ring whose |
| 1198 | * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not |
| 1199 | * attempt to configure a ring whose number is greater than the number |
| 1200 | * specified in the Port Control Block (PCB). It is an error to issue the |
| 1201 | * configure ring command more than once with the same ring number. The HBA |
| 1202 | * returns an error if the driver attempts this. |
| 1203 | * |
| 1204 | * This routine prepares the mailbox command for configuring IOCB ring. |
| 1205 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1206 | void |
| 1207 | lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb) |
| 1208 | { |
| 1209 | int i; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1210 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1211 | struct lpfc_sli *psli; |
| 1212 | struct lpfc_sli_ring *pring; |
| 1213 | |
| 1214 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 1215 | |
| 1216 | mb->un.varCfgRing.ring = ring; |
| 1217 | mb->un.varCfgRing.maxOrigXchg = 0; |
| 1218 | mb->un.varCfgRing.maxRespXchg = 0; |
| 1219 | mb->un.varCfgRing.recvNotify = 1; |
| 1220 | |
| 1221 | psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1222 | pring = &psli->sli3_ring[ring]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1223 | mb->un.varCfgRing.numMask = pring->num_mask; |
| 1224 | mb->mbxCommand = MBX_CONFIG_RING; |
| 1225 | mb->mbxOwner = OWN_HOST; |
| 1226 | |
| 1227 | /* Is this ring configured for a specific profile */ |
| 1228 | if (pring->prt[0].profile) { |
| 1229 | mb->un.varCfgRing.profile = pring->prt[0].profile; |
| 1230 | return; |
| 1231 | } |
| 1232 | |
| 1233 | /* Otherwise we setup specific rctl / type masks for this ring */ |
| 1234 | for (i = 0; i < pring->num_mask; i++) { |
| 1235 | mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1236 | if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1237 | mb->un.varCfgRing.rrRegs[i].rmask = 0xff; |
| 1238 | else |
| 1239 | mb->un.varCfgRing.rrRegs[i].rmask = 0xfe; |
| 1240 | mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type; |
| 1241 | mb->un.varCfgRing.rrRegs[i].tmask = 0xff; |
| 1242 | } |
| 1243 | |
| 1244 | return; |
| 1245 | } |
| 1246 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1247 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1248 | * lpfc_config_port - Prepare a mailbox command for configuring port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1249 | * @phba: pointer to lpfc hba data structure. |
| 1250 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1251 | * |
| 1252 | * The configure port mailbox command is used to identify the Port Control |
| 1253 | * Block (PCB) in the driver memory. After this command is issued, the |
| 1254 | * driver must not access the mailbox in the HBA without first resetting |
| 1255 | * the HBA. The HBA may copy the PCB information to internal storage for |
| 1256 | * subsequent use; the driver can not change the PCB information unless it |
| 1257 | * resets the HBA. |
| 1258 | * |
| 1259 | * This routine prepares the mailbox command for configuring port. |
| 1260 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1261 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1262 | lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1263 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1264 | MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1265 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1266 | dma_addr_t pdma_addr; |
| 1267 | uint32_t bar_low, bar_high; |
| 1268 | size_t offset; |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 1269 | struct lpfc_hgp hgp; |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1270 | int i; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1271 | uint32_t pgp_offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1272 | |
| 1273 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 1274 | mb->mbxCommand = MBX_CONFIG_PORT; |
| 1275 | mb->mbxOwner = OWN_HOST; |
| 1276 | |
| 1277 | mb->un.varCfgPort.pcbLen = sizeof(PCB_t); |
| 1278 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1279 | offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt; |
| 1280 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1281 | mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr); |
| 1282 | mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr); |
| 1283 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 1284 | /* Always Host Group Pointer is in SLIM */ |
| 1285 | mb->un.varCfgPort.hps = 1; |
| 1286 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1287 | /* If HBA supports SLI=3 ask for it */ |
| 1288 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1289 | if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1290 | if (phba->cfg_enable_bg) |
| 1291 | mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */ |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 1292 | if (phba->cfg_enable_dss) |
| 1293 | mb->un.varCfgPort.cdss = 1; /* Configure Security */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1294 | mb->un.varCfgPort.cerbm = 1; /* Request HBQs */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1295 | mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1296 | mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count(); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1297 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1298 | phba->vpd.sli3Feat.cmv) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1299 | mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1300 | mb->un.varCfgPort.cmv = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1301 | } else |
| 1302 | mb->un.varCfgPort.max_vpi = phba->max_vpi = 0; |
| 1303 | } else |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1304 | phba->sli_rev = LPFC_SLI_REV2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1305 | mb->un.varCfgPort.sli_mode = phba->sli_rev; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1306 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 1307 | /* If this is an SLI3 port, configure async status notification. */ |
| 1308 | if (phba->sli_rev == LPFC_SLI_REV3) |
| 1309 | mb->un.varCfgPort.casabt = 1; |
| 1310 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1311 | /* Now setup pcb */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1312 | phba->pcb->type = TYPE_NATIVE_SLI2; |
| 1313 | phba->pcb->feature = FEATURE_INITIAL_SLI2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1314 | |
| 1315 | /* Setup Mailbox pointers */ |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1316 | phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1317 | offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt; |
| 1318 | pdma_addr = phba->slim2p.phys + offset; |
| 1319 | phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr); |
| 1320 | phba->pcb->mbAddrLow = putPaddrLow(pdma_addr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1321 | |
| 1322 | /* |
| 1323 | * Setup Host Group ring pointer. |
| 1324 | * |
| 1325 | * For efficiency reasons, the ring get/put pointers can be |
| 1326 | * placed in adapter memory (SLIM) rather than in host memory. |
| 1327 | * This allows firmware to avoid PCI reads/writes when updating |
| 1328 | * and checking pointers. |
| 1329 | * |
| 1330 | * The firmware recognizes the use of SLIM memory by comparing |
| 1331 | * the address of the get/put pointers structure with that of |
| 1332 | * the SLIM BAR (BAR0). |
| 1333 | * |
| 1334 | * Caution: be sure to use the PCI config space value of BAR0/BAR1 |
| 1335 | * (the hardware's view of the base address), not the OS's |
| 1336 | * value of pci_resource_start() as the OS value may be a cookie |
| 1337 | * for ioremap/iomap. |
| 1338 | */ |
| 1339 | |
| 1340 | |
| 1341 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low); |
| 1342 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high); |
| 1343 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1344 | /* |
| 1345 | * Set up HGP - Port Memory |
| 1346 | * |
| 1347 | * The port expects the host get/put pointers to reside in memory |
| 1348 | * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes) |
| 1349 | * area of SLIM. In SLI-2 mode, there's an additional 16 reserved |
| 1350 | * words (0x40 bytes). This area is not reserved if HBQs are |
| 1351 | * configured in SLI-3. |
| 1352 | * |
| 1353 | * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80 |
| 1354 | * RR0Get 0xc4 0x84 |
| 1355 | * CR1Put 0xc8 0x88 |
| 1356 | * RR1Get 0xcc 0x8c |
| 1357 | * CR2Put 0xd0 0x90 |
| 1358 | * RR2Get 0xd4 0x94 |
| 1359 | * CR3Put 0xd8 0x98 |
| 1360 | * RR3Get 0xdc 0x9c |
| 1361 | * |
| 1362 | * Reserved 0xa0-0xbf |
| 1363 | * If HBQs configured: |
| 1364 | * HBQ 0 Put ptr 0xc0 |
| 1365 | * HBQ 1 Put ptr 0xc4 |
| 1366 | * HBQ 2 Put ptr 0xc8 |
| 1367 | * ...... |
| 1368 | * HBQ(M-1)Put Pointer 0xc0+(M-1)*4 |
| 1369 | * |
| 1370 | */ |
| 1371 | |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1372 | if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) { |
| 1373 | phba->host_gp = &phba->mbox->us.s2.host[0]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1374 | phba->hbq_put = NULL; |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1375 | offset = (uint8_t *)&phba->mbox->us.s2.host - |
| 1376 | (uint8_t *)phba->slim2p.virt; |
| 1377 | pdma_addr = phba->slim2p.phys + offset; |
| 1378 | phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr); |
| 1379 | phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr); |
| 1380 | } else { |
| 1381 | /* Always Host Group Pointer is in SLIM */ |
| 1382 | mb->un.varCfgPort.hps = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1383 | |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1384 | if (phba->sli_rev == 3) { |
| 1385 | phba->host_gp = &mb_slim->us.s3.host[0]; |
| 1386 | phba->hbq_put = &mb_slim->us.s3.hbq_put[0]; |
| 1387 | } else { |
| 1388 | phba->host_gp = &mb_slim->us.s2.host[0]; |
| 1389 | phba->hbq_put = NULL; |
| 1390 | } |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1391 | |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1392 | /* mask off BAR0's flag bits 0 - 3 */ |
| 1393 | phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) + |
| 1394 | (void __iomem *)phba->host_gp - |
| 1395 | (void __iomem *)phba->MBslimaddr; |
| 1396 | if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64) |
| 1397 | phba->pcb->hgpAddrHigh = bar_high; |
| 1398 | else |
| 1399 | phba->pcb->hgpAddrHigh = 0; |
| 1400 | /* write HGP data to SLIM at the required longword offset */ |
| 1401 | memset(&hgp, 0, sizeof(struct lpfc_hgp)); |
| 1402 | |
| 1403 | for (i = 0; i < phba->sli.num_rings; i++) { |
| 1404 | lpfc_memcpy_to_slim(phba->host_gp + i, &hgp, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1405 | sizeof(*phba->host_gp)); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1406 | } |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1407 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 1409 | /* Setup Port Group offset */ |
| 1410 | if (phba->sli_rev == 3) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1411 | pgp_offset = offsetof(struct lpfc_sli2_slim, |
| 1412 | mbx.us.s3_pgp.port); |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 1413 | else |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1414 | pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port); |
| 1415 | pdma_addr = phba->slim2p.phys + pgp_offset; |
| 1416 | phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr); |
| 1417 | phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1418 | |
| 1419 | /* Use callback routine to setp rings in the pcb */ |
| 1420 | lpfc_config_pcb_setup(phba); |
| 1421 | |
| 1422 | /* special handling for LC HBAs */ |
| 1423 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
| 1424 | uint32_t hbainit[5]; |
| 1425 | |
| 1426 | lpfc_hba_init(phba, hbainit); |
| 1427 | |
| 1428 | memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20); |
| 1429 | } |
| 1430 | |
| 1431 | /* Swap PCB if needed */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1432 | lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1433 | } |
| 1434 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1435 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1436 | * lpfc_kill_board - Prepare a mailbox command for killing board |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1437 | * @phba: pointer to lpfc hba data structure. |
| 1438 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1439 | * |
| 1440 | * The kill board mailbox command is used to tell firmware to perform a |
| 1441 | * graceful shutdown of a channel on a specified board to prepare for reset. |
| 1442 | * When the kill board mailbox command is received, the ER3 bit is set to 1 |
| 1443 | * in the Host Status register and the ER Attention bit is set to 1 in the |
| 1444 | * Host Attention register of the HBA function that received the kill board |
| 1445 | * command. |
| 1446 | * |
| 1447 | * This routine prepares the mailbox command for killing the board in |
| 1448 | * preparation for a graceful shutdown. |
| 1449 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1450 | void |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1451 | lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 1452 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1453 | MAILBOX_t *mb = &pmb->u.mb; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1454 | |
| 1455 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 1456 | mb->mbxCommand = MBX_KILL_BOARD; |
| 1457 | mb->mbxOwner = OWN_HOST; |
| 1458 | return; |
| 1459 | } |
| 1460 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1461 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1462 | * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1463 | * @phba: pointer to lpfc hba data structure. |
| 1464 | * @mbq: pointer to the driver internal queue element for mailbox command. |
| 1465 | * |
| 1466 | * Driver maintains a internal mailbox command queue implemented as a linked |
| 1467 | * list. When a mailbox command is issued, it shall be put into the mailbox |
| 1468 | * command queue such that they shall be processed orderly as HBA can process |
| 1469 | * one mailbox command at a time. |
| 1470 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1471 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1472 | lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) |
| 1473 | { |
| 1474 | struct lpfc_sli *psli; |
| 1475 | |
| 1476 | psli = &phba->sli; |
| 1477 | |
| 1478 | list_add_tail(&mbq->list, &psli->mboxq); |
| 1479 | |
| 1480 | psli->mboxq_cnt++; |
| 1481 | |
| 1482 | return; |
| 1483 | } |
| 1484 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1485 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1486 | * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1487 | * @phba: pointer to lpfc hba data structure. |
| 1488 | * |
| 1489 | * Driver maintains a internal mailbox command queue implemented as a linked |
| 1490 | * list. When a mailbox command is issued, it shall be put into the mailbox |
| 1491 | * command queue such that they shall be processed orderly as HBA can process |
| 1492 | * one mailbox command at a time. After HBA finished processing a mailbox |
| 1493 | * command, the driver will remove a pending mailbox command from the head of |
| 1494 | * the mailbox command queue and send to the HBA for processing. |
| 1495 | * |
| 1496 | * Return codes |
| 1497 | * pointer to the driver internal queue element for mailbox command. |
| 1498 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1499 | LPFC_MBOXQ_t * |
| 1500 | lpfc_mbox_get(struct lpfc_hba * phba) |
| 1501 | { |
| 1502 | LPFC_MBOXQ_t *mbq = NULL; |
| 1503 | struct lpfc_sli *psli = &phba->sli; |
| 1504 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1505 | list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1506 | if (mbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1507 | psli->mboxq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1508 | |
| 1509 | return mbq; |
| 1510 | } |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1511 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1512 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1513 | * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list |
| 1514 | * @phba: pointer to lpfc hba data structure. |
| 1515 | * @mbq: pointer to the driver internal queue element for mailbox command. |
| 1516 | * |
| 1517 | * This routine put the completed mailbox command into the mailbox command |
| 1518 | * complete list. This is the unlocked version of the routine. The mailbox |
| 1519 | * complete list is used by the driver worker thread to process mailbox |
| 1520 | * complete callback functions outside the driver interrupt handler. |
| 1521 | **/ |
| 1522 | void |
| 1523 | __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) |
| 1524 | { |
| 1525 | list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl); |
| 1526 | } |
| 1527 | |
| 1528 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1529 | * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1530 | * @phba: pointer to lpfc hba data structure. |
| 1531 | * @mbq: pointer to the driver internal queue element for mailbox command. |
| 1532 | * |
| 1533 | * This routine put the completed mailbox command into the mailbox command |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1534 | * complete list. This is the locked version of the routine. The mailbox |
| 1535 | * complete list is used by the driver worker thread to process mailbox |
| 1536 | * complete callback functions outside the driver interrupt handler. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1537 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1538 | void |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1539 | lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1540 | { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1541 | unsigned long iflag; |
| 1542 | |
Joe Perches | b1c1181 | 2008-02-03 17:28:22 +0200 | [diff] [blame] | 1543 | /* This function expects to be called from interrupt context */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1544 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1545 | __lpfc_mbox_cmpl_put(phba, mbq); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1546 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1547 | return; |
| 1548 | } |
| 1549 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1550 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1551 | * lpfc_mbox_cmd_check - Check the validality of a mailbox command |
| 1552 | * @phba: pointer to lpfc hba data structure. |
| 1553 | * @mboxq: pointer to the driver internal queue element for mailbox command. |
| 1554 | * |
| 1555 | * This routine is to check whether a mailbox command is valid to be issued. |
| 1556 | * This check will be performed by both the mailbox issue API when a client |
| 1557 | * is to issue a mailbox command to the mailbox transport. |
| 1558 | * |
| 1559 | * Return 0 - pass the check, -ENODEV - fail the check |
| 1560 | **/ |
| 1561 | int |
| 1562 | lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1563 | { |
| 1564 | /* Mailbox command that have a completion handler must also have a |
| 1565 | * vport specified. |
| 1566 | */ |
| 1567 | if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
| 1568 | mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
| 1569 | if (!mboxq->vport) { |
| 1570 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 1571 | "1814 Mbox x%x failed, no vport\n", |
| 1572 | mboxq->u.mb.mbxCommand); |
| 1573 | dump_stack(); |
| 1574 | return -ENODEV; |
| 1575 | } |
| 1576 | } |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
| 1580 | /** |
| 1581 | * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command |
| 1582 | * @phba: pointer to lpfc hba data structure. |
| 1583 | * |
| 1584 | * This routine is to check whether the HBA device is ready for posting a |
| 1585 | * mailbox command. It is used by the mailbox transport API at the time the |
| 1586 | * to post a mailbox command to the device. |
| 1587 | * |
| 1588 | * Return 0 - pass the check, -ENODEV - fail the check |
| 1589 | **/ |
| 1590 | int |
| 1591 | lpfc_mbox_dev_check(struct lpfc_hba *phba) |
| 1592 | { |
| 1593 | /* If the PCI channel is in offline state, do not issue mbox */ |
| 1594 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 1595 | return -ENODEV; |
| 1596 | |
| 1597 | /* If the HBA is in error state, do not issue mbox */ |
| 1598 | if (phba->link_state == LPFC_HBA_ERROR) |
| 1599 | return -ENODEV; |
| 1600 | |
| 1601 | return 0; |
| 1602 | } |
| 1603 | |
| 1604 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1605 | * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1606 | * @phba: pointer to lpfc hba data structure. |
| 1607 | * @cmd: mailbox command code. |
| 1608 | * |
| 1609 | * This routine retrieves the proper timeout value according to the mailbox |
| 1610 | * command code. |
| 1611 | * |
| 1612 | * Return codes |
| 1613 | * Timeout value to be used for the given mailbox command |
| 1614 | **/ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1615 | int |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1616 | lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1617 | { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1618 | MAILBOX_t *mbox = &mboxq->u.mb; |
| 1619 | uint8_t subsys, opcode; |
| 1620 | |
| 1621 | switch (mbox->mbxCommand) { |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1622 | case MBX_WRITE_NV: /* 0x03 */ |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 1623 | case MBX_DUMP_MEMORY: /* 0x17 */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1624 | case MBX_UPDATE_CFG: /* 0x1B */ |
| 1625 | case MBX_DOWN_LOAD: /* 0x1C */ |
| 1626 | case MBX_DEL_LD_ENTRY: /* 0x1D */ |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 1627 | case MBX_WRITE_VPARMS: /* 0x32 */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1628 | case MBX_LOAD_AREA: /* 0x81 */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1629 | case MBX_WRITE_WWN: /* 0x98 */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1630 | case MBX_LOAD_EXP_ROM: /* 0x9C */ |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 1631 | case MBX_ACCESS_VDATA: /* 0xA5 */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1632 | return LPFC_MBOX_TMO_FLASH_CMD; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1633 | case MBX_SLI4_CONFIG: /* 0x9b */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1634 | subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq); |
| 1635 | opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq); |
| 1636 | if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) { |
| 1637 | switch (opcode) { |
| 1638 | case LPFC_MBOX_OPCODE_READ_OBJECT: |
| 1639 | case LPFC_MBOX_OPCODE_WRITE_OBJECT: |
| 1640 | case LPFC_MBOX_OPCODE_READ_OBJECT_LIST: |
| 1641 | case LPFC_MBOX_OPCODE_DELETE_OBJECT: |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1642 | case LPFC_MBOX_OPCODE_GET_PROFILE_LIST: |
| 1643 | case LPFC_MBOX_OPCODE_SET_ACT_PROFILE: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 1644 | case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG: |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1645 | case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG: |
| 1646 | case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 1647 | case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES: |
| 1648 | case LPFC_MBOX_OPCODE_SEND_ACTIVATION: |
| 1649 | case LPFC_MBOX_OPCODE_RESET_LICENSES: |
| 1650 | case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG: |
| 1651 | case LPFC_MBOX_OPCODE_GET_VPD_DATA: |
| 1652 | case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG: |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1653 | return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO; |
| 1654 | } |
| 1655 | } |
| 1656 | if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) { |
| 1657 | switch (opcode) { |
| 1658 | case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS: |
| 1659 | return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO; |
| 1660 | } |
| 1661 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1662 | return LPFC_MBOX_SLI4_CONFIG_TMO; |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1663 | } |
| 1664 | return LPFC_MBOX_TMO; |
| 1665 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1666 | |
| 1667 | /** |
| 1668 | * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command |
| 1669 | * @mbox: pointer to lpfc mbox command. |
| 1670 | * @sgentry: sge entry index. |
| 1671 | * @phyaddr: physical address for the sge |
| 1672 | * @length: Length of the sge. |
| 1673 | * |
| 1674 | * This routine sets up an entry in the non-embedded mailbox command at the sge |
| 1675 | * index location. |
| 1676 | **/ |
| 1677 | void |
| 1678 | lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry, |
| 1679 | dma_addr_t phyaddr, uint32_t length) |
| 1680 | { |
| 1681 | struct lpfc_mbx_nembed_cmd *nembed_sge; |
| 1682 | |
| 1683 | nembed_sge = (struct lpfc_mbx_nembed_cmd *) |
| 1684 | &mbox->u.mqe.un.nembed_cmd; |
| 1685 | nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr); |
| 1686 | nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr); |
| 1687 | nembed_sge->sge[sgentry].length = length; |
| 1688 | } |
| 1689 | |
| 1690 | /** |
| 1691 | * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command |
| 1692 | * @mbox: pointer to lpfc mbox command. |
| 1693 | * @sgentry: sge entry index. |
| 1694 | * |
| 1695 | * This routine gets an entry from the non-embedded mailbox command at the sge |
| 1696 | * index location. |
| 1697 | **/ |
| 1698 | void |
| 1699 | lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry, |
| 1700 | struct lpfc_mbx_sge *sge) |
| 1701 | { |
| 1702 | struct lpfc_mbx_nembed_cmd *nembed_sge; |
| 1703 | |
| 1704 | nembed_sge = (struct lpfc_mbx_nembed_cmd *) |
| 1705 | &mbox->u.mqe.un.nembed_cmd; |
| 1706 | sge->pa_lo = nembed_sge->sge[sgentry].pa_lo; |
| 1707 | sge->pa_hi = nembed_sge->sge[sgentry].pa_hi; |
| 1708 | sge->length = nembed_sge->sge[sgentry].length; |
| 1709 | } |
| 1710 | |
| 1711 | /** |
| 1712 | * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command |
| 1713 | * @phba: pointer to lpfc hba data structure. |
| 1714 | * @mbox: pointer to lpfc mbox command. |
| 1715 | * |
| 1716 | * This routine frees SLI4 specific mailbox command for sending IOCTL command. |
| 1717 | **/ |
| 1718 | void |
| 1719 | lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox) |
| 1720 | { |
| 1721 | struct lpfc_mbx_sli4_config *sli4_cfg; |
| 1722 | struct lpfc_mbx_sge sge; |
| 1723 | dma_addr_t phyaddr; |
| 1724 | uint32_t sgecount, sgentry; |
| 1725 | |
| 1726 | sli4_cfg = &mbox->u.mqe.un.sli4_config; |
| 1727 | |
| 1728 | /* For embedded mbox command, just free the mbox command */ |
| 1729 | if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { |
| 1730 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1731 | return; |
| 1732 | } |
| 1733 | |
| 1734 | /* For non-embedded mbox command, we need to free the pages first */ |
| 1735 | sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr); |
| 1736 | /* There is nothing we can do if there is no sge address array */ |
| 1737 | if (unlikely(!mbox->sge_array)) { |
| 1738 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1739 | return; |
| 1740 | } |
| 1741 | /* Each non-embedded DMA memory was allocated in the length of a page */ |
| 1742 | for (sgentry = 0; sgentry < sgecount; sgentry++) { |
| 1743 | lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge); |
| 1744 | phyaddr = getPaddr(sge.pa_hi, sge.pa_lo); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 1745 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1746 | mbox->sge_array->addr[sgentry], phyaddr); |
| 1747 | } |
| 1748 | /* Free the sge address array memory */ |
| 1749 | kfree(mbox->sge_array); |
| 1750 | /* Finally, free the mailbox command itself */ |
| 1751 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1752 | } |
| 1753 | |
| 1754 | /** |
| 1755 | * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command |
| 1756 | * @phba: pointer to lpfc hba data structure. |
| 1757 | * @mbox: pointer to lpfc mbox command. |
| 1758 | * @subsystem: The sli4 config sub mailbox subsystem. |
| 1759 | * @opcode: The sli4 config sub mailbox command opcode. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1760 | * @length: Length of the sli4 config mailbox command (including sub-header). |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1761 | * |
| 1762 | * This routine sets up the header fields of SLI4 specific mailbox command |
| 1763 | * for sending IOCTL command. |
| 1764 | * |
| 1765 | * Return: the actual length of the mbox command allocated (mostly useful |
| 1766 | * for none embedded mailbox command). |
| 1767 | **/ |
| 1768 | int |
| 1769 | lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox, |
| 1770 | uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb) |
| 1771 | { |
| 1772 | struct lpfc_mbx_sli4_config *sli4_config; |
| 1773 | union lpfc_sli4_cfg_shdr *cfg_shdr = NULL; |
| 1774 | uint32_t alloc_len; |
| 1775 | uint32_t resid_len; |
| 1776 | uint32_t pagen, pcount; |
| 1777 | void *viraddr; |
| 1778 | dma_addr_t phyaddr; |
| 1779 | |
| 1780 | /* Set up SLI4 mailbox command header fields */ |
| 1781 | memset(mbox, 0, sizeof(*mbox)); |
| 1782 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG); |
| 1783 | |
| 1784 | /* Set up SLI4 ioctl command header fields */ |
| 1785 | sli4_config = &mbox->u.mqe.un.sli4_config; |
| 1786 | |
| 1787 | /* Setup for the embedded mbox command */ |
| 1788 | if (emb) { |
| 1789 | /* Set up main header fields */ |
| 1790 | bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1791 | sli4_config->header.cfg_mhdr.payload_length = length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1792 | /* Set up sub-header fields following main header */ |
| 1793 | bf_set(lpfc_mbox_hdr_opcode, |
| 1794 | &sli4_config->header.cfg_shdr.request, opcode); |
| 1795 | bf_set(lpfc_mbox_hdr_subsystem, |
| 1796 | &sli4_config->header.cfg_shdr.request, subsystem); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1797 | sli4_config->header.cfg_shdr.request.request_length = |
| 1798 | length - LPFC_MBX_CMD_HDR_LENGTH; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1799 | return length; |
| 1800 | } |
| 1801 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1802 | /* Setup for the non-embedded mbox command */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 1803 | pcount = (SLI4_PAGE_ALIGN(length))/SLI4_PAGE_SIZE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1804 | pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ? |
| 1805 | LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount; |
| 1806 | /* Allocate record for keeping SGE virtual addresses */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1807 | mbox->sge_array = kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt), |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1808 | GFP_KERNEL); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1809 | if (!mbox->sge_array) { |
| 1810 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1811 | "2527 Failed to allocate non-embedded SGE " |
| 1812 | "array.\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1813 | return 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1814 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1815 | for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) { |
| 1816 | /* The DMA memory is always allocated in the length of a |
| 1817 | * page even though the last SGE might not fill up to a |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 1818 | * page, this is used as a priori size of SLI4_PAGE_SIZE for |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1819 | * the later DMA memory free. |
| 1820 | */ |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 1821 | viraddr = dma_zalloc_coherent(&phba->pcidev->dev, |
| 1822 | SLI4_PAGE_SIZE, &phyaddr, |
| 1823 | GFP_KERNEL); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1824 | /* In case of malloc fails, proceed with whatever we have */ |
| 1825 | if (!viraddr) |
| 1826 | break; |
| 1827 | mbox->sge_array->addr[pagen] = viraddr; |
| 1828 | /* Keep the first page for later sub-header construction */ |
| 1829 | if (pagen == 0) |
| 1830 | cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr; |
| 1831 | resid_len = length - alloc_len; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 1832 | if (resid_len > SLI4_PAGE_SIZE) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1833 | lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 1834 | SLI4_PAGE_SIZE); |
| 1835 | alloc_len += SLI4_PAGE_SIZE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1836 | } else { |
| 1837 | lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, |
| 1838 | resid_len); |
| 1839 | alloc_len = length; |
| 1840 | } |
| 1841 | } |
| 1842 | |
| 1843 | /* Set up main header fields in mailbox command */ |
| 1844 | sli4_config->header.cfg_mhdr.payload_length = alloc_len; |
| 1845 | bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen); |
| 1846 | |
| 1847 | /* Set up sub-header fields into the first page */ |
| 1848 | if (pagen > 0) { |
| 1849 | bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode); |
| 1850 | bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem); |
| 1851 | cfg_shdr->request.request_length = |
| 1852 | alloc_len - sizeof(union lpfc_sli4_cfg_shdr); |
| 1853 | } |
| 1854 | /* The sub-header is in DMA memory, which needs endian converstion */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 1855 | if (cfg_shdr) |
| 1856 | lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1857 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1858 | return alloc_len; |
| 1859 | } |
| 1860 | |
| 1861 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1862 | * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent. |
| 1863 | * @phba: pointer to lpfc hba data structure. |
| 1864 | * @mbox: pointer to an allocated lpfc mbox resource. |
| 1865 | * @exts_count: the number of extents, if required, to allocate. |
| 1866 | * @rsrc_type: the resource extent type. |
| 1867 | * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED. |
| 1868 | * |
| 1869 | * This routine completes the subcommand header for SLI4 resource extent |
| 1870 | * mailbox commands. It is called after lpfc_sli4_config. The caller must |
| 1871 | * pass an allocated mailbox and the attributes required to initialize the |
| 1872 | * mailbox correctly. |
| 1873 | * |
| 1874 | * Return: the actual length of the mbox command allocated. |
| 1875 | **/ |
| 1876 | int |
| 1877 | lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox, |
| 1878 | uint16_t exts_count, uint16_t rsrc_type, bool emb) |
| 1879 | { |
| 1880 | uint8_t opcode = 0; |
| 1881 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc_extnt = NULL; |
| 1882 | void *virtaddr = NULL; |
| 1883 | |
| 1884 | /* Set up SLI4 ioctl command header fields */ |
| 1885 | if (emb == LPFC_SLI4_MBX_NEMBED) { |
| 1886 | /* Get the first SGE entry from the non-embedded DMA memory */ |
| 1887 | virtaddr = mbox->sge_array->addr[0]; |
| 1888 | if (virtaddr == NULL) |
| 1889 | return 1; |
| 1890 | n_rsrc_extnt = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 1891 | } |
| 1892 | |
| 1893 | /* |
| 1894 | * The resource type is common to all extent Opcodes and resides in the |
| 1895 | * same position. |
| 1896 | */ |
| 1897 | if (emb == LPFC_SLI4_MBX_EMBED) |
| 1898 | bf_set(lpfc_mbx_alloc_rsrc_extents_type, |
| 1899 | &mbox->u.mqe.un.alloc_rsrc_extents.u.req, |
| 1900 | rsrc_type); |
| 1901 | else { |
| 1902 | /* This is DMA data. Byteswap is required. */ |
| 1903 | bf_set(lpfc_mbx_alloc_rsrc_extents_type, |
| 1904 | n_rsrc_extnt, rsrc_type); |
| 1905 | lpfc_sli_pcimem_bcopy(&n_rsrc_extnt->word4, |
| 1906 | &n_rsrc_extnt->word4, |
| 1907 | sizeof(uint32_t)); |
| 1908 | } |
| 1909 | |
| 1910 | /* Complete the initialization for the particular Opcode. */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1911 | opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1912 | switch (opcode) { |
| 1913 | case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT: |
| 1914 | if (emb == LPFC_SLI4_MBX_EMBED) |
| 1915 | bf_set(lpfc_mbx_alloc_rsrc_extents_cnt, |
| 1916 | &mbox->u.mqe.un.alloc_rsrc_extents.u.req, |
| 1917 | exts_count); |
| 1918 | else |
| 1919 | bf_set(lpfc_mbx_alloc_rsrc_extents_cnt, |
| 1920 | n_rsrc_extnt, exts_count); |
| 1921 | break; |
| 1922 | case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT: |
| 1923 | case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO: |
| 1924 | case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT: |
| 1925 | /* Initialization is complete.*/ |
| 1926 | break; |
| 1927 | default: |
| 1928 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1929 | "2929 Resource Extent Opcode x%x is " |
| 1930 | "unsupported\n", opcode); |
| 1931 | return 1; |
| 1932 | } |
| 1933 | |
| 1934 | return 0; |
| 1935 | } |
| 1936 | |
| 1937 | /** |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1938 | * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1939 | * @phba: pointer to lpfc hba data structure. |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1940 | * @mbox: pointer to lpfc mbox command queue entry. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1941 | * |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1942 | * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox |
| 1943 | * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the |
| 1944 | * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall |
| 1945 | * be returned. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1946 | **/ |
| 1947 | uint8_t |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1948 | lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1949 | { |
| 1950 | struct lpfc_mbx_sli4_config *sli4_cfg; |
| 1951 | union lpfc_sli4_cfg_shdr *cfg_shdr; |
| 1952 | |
| 1953 | if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1954 | return LPFC_MBOX_SUBSYSTEM_NA; |
| 1955 | sli4_cfg = &mbox->u.mqe.un.sli4_config; |
| 1956 | |
| 1957 | /* For embedded mbox command, get opcode from embedded sub-header*/ |
| 1958 | if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { |
| 1959 | cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; |
| 1960 | return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request); |
| 1961 | } |
| 1962 | |
| 1963 | /* For non-embedded mbox command, get opcode from first dma page */ |
| 1964 | if (unlikely(!mbox->sge_array)) |
| 1965 | return LPFC_MBOX_SUBSYSTEM_NA; |
| 1966 | cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; |
| 1967 | return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request); |
| 1968 | } |
| 1969 | |
| 1970 | /** |
| 1971 | * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd |
| 1972 | * @phba: pointer to lpfc hba data structure. |
| 1973 | * @mbox: pointer to lpfc mbox command queue entry. |
| 1974 | * |
| 1975 | * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox |
| 1976 | * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if |
| 1977 | * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be |
| 1978 | * returned. |
| 1979 | **/ |
| 1980 | uint8_t |
| 1981 | lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 1982 | { |
| 1983 | struct lpfc_mbx_sli4_config *sli4_cfg; |
| 1984 | union lpfc_sli4_cfg_shdr *cfg_shdr; |
| 1985 | |
| 1986 | if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) |
| 1987 | return LPFC_MBOX_OPCODE_NA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1988 | sli4_cfg = &mbox->u.mqe.un.sli4_config; |
| 1989 | |
| 1990 | /* For embedded mbox command, get opcode from embedded sub-header*/ |
| 1991 | if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { |
| 1992 | cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; |
| 1993 | return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); |
| 1994 | } |
| 1995 | |
| 1996 | /* For non-embedded mbox command, get opcode from first dma page */ |
| 1997 | if (unlikely(!mbox->sge_array)) |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1998 | return LPFC_MBOX_OPCODE_NA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1999 | cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; |
| 2000 | return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); |
| 2001 | } |
| 2002 | |
| 2003 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2004 | * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2005 | * @phba: pointer to lpfc hba data structure. |
| 2006 | * @fcf_index: index to fcf table. |
| 2007 | * |
| 2008 | * This routine routine allocates and constructs non-embedded mailbox command |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2009 | * for reading a FCF table entry referred by @fcf_index. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2010 | * |
| 2011 | * Return: pointer to the mailbox command constructed if successful, otherwise |
| 2012 | * NULL. |
| 2013 | **/ |
| 2014 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2015 | lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba, |
| 2016 | struct lpfcMboxq *mboxq, |
| 2017 | uint16_t fcf_index) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2018 | { |
| 2019 | void *virt_addr; |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2020 | uint8_t *bytep; |
| 2021 | struct lpfc_mbx_sge sge; |
| 2022 | uint32_t alloc_len, req_len; |
| 2023 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
| 2024 | |
| 2025 | if (!mboxq) |
| 2026 | return -ENOMEM; |
| 2027 | |
| 2028 | req_len = sizeof(struct fcf_record) + |
| 2029 | sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t); |
| 2030 | |
| 2031 | /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */ |
| 2032 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 2033 | LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len, |
| 2034 | LPFC_SLI4_MBX_NEMBED); |
| 2035 | |
| 2036 | if (alloc_len < req_len) { |
| 2037 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 2038 | "0291 Allocated DMA memory size (x%x) is " |
| 2039 | "less than the requested DMA memory " |
| 2040 | "size (x%x)\n", alloc_len, req_len); |
| 2041 | return -ENOMEM; |
| 2042 | } |
| 2043 | |
| 2044 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 2045 | * routine only uses a single SGE. |
| 2046 | */ |
| 2047 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2048 | virt_addr = mboxq->sge_array->addr[0]; |
| 2049 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 2050 | |
| 2051 | /* Set up command fields */ |
| 2052 | bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index); |
| 2053 | /* Perform necessary endian conversion */ |
| 2054 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 2055 | lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t)); |
| 2056 | |
| 2057 | return 0; |
| 2058 | } |
| 2059 | |
| 2060 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2061 | * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox |
| 2062 | * @mboxq: pointer to lpfc mbox command. |
| 2063 | * |
| 2064 | * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES |
| 2065 | * mailbox command. |
| 2066 | **/ |
| 2067 | void |
| 2068 | lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq) |
| 2069 | { |
| 2070 | /* Set up SLI4 mailbox command header fields */ |
| 2071 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 2072 | bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS); |
| 2073 | |
| 2074 | /* Set up host requested features. */ |
| 2075 | bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2076 | bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2077 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2078 | /* Enable DIF (block guard) only if configured to do so. */ |
| 2079 | if (phba->cfg_enable_bg) |
| 2080 | bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1); |
| 2081 | |
| 2082 | /* Enable NPIV only if configured to do so. */ |
| 2083 | if (phba->max_vpi && phba->cfg_enable_npiv) |
| 2084 | bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1); |
| 2085 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame^] | 2086 | if (phba->nvmet_support) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2087 | bf_set(lpfc_mbx_rq_ftr_rq_mrqp, &mboxq->u.mqe.un.req_ftrs, 1); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame^] | 2088 | /* iaab/iaar NOT set for now */ |
| 2089 | bf_set(lpfc_mbx_rq_ftr_rq_iaab, &mboxq->u.mqe.un.req_ftrs, 0); |
| 2090 | bf_set(lpfc_mbx_rq_ftr_rq_iaar, &mboxq->u.mqe.un.req_ftrs, 0); |
| 2091 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2092 | return; |
| 2093 | } |
| 2094 | |
| 2095 | /** |
| 2096 | * lpfc_init_vfi - Initialize the INIT_VFI mailbox command |
| 2097 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2098 | * @vport: Vport associated with the VF. |
| 2099 | * |
| 2100 | * This routine initializes @mbox to all zeros and then fills in the mailbox |
| 2101 | * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI |
| 2102 | * in the context of an FCF. The driver issues this command to setup a VFI |
| 2103 | * before issuing a FLOGI to login to the VSAN. The driver should also issue a |
| 2104 | * REG_VFI after a successful VSAN login. |
| 2105 | **/ |
| 2106 | void |
| 2107 | lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) |
| 2108 | { |
| 2109 | struct lpfc_mbx_init_vfi *init_vfi; |
| 2110 | |
| 2111 | memset(mbox, 0, sizeof(*mbox)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2112 | mbox->vport = vport; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2113 | init_vfi = &mbox->u.mqe.un.init_vfi; |
| 2114 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI); |
| 2115 | bf_set(lpfc_init_vfi_vr, init_vfi, 1); |
| 2116 | bf_set(lpfc_init_vfi_vt, init_vfi, 1); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2117 | bf_set(lpfc_init_vfi_vp, init_vfi, 1); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2118 | bf_set(lpfc_init_vfi_vfi, init_vfi, |
| 2119 | vport->phba->sli4_hba.vfi_ids[vport->vfi]); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2120 | bf_set(lpfc_init_vfi_vpi, init_vfi, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2121 | vport->phba->vpi_ids[vport->vpi]); |
| 2122 | bf_set(lpfc_init_vfi_fcfi, init_vfi, |
| 2123 | vport->phba->fcf.fcfi); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | /** |
| 2127 | * lpfc_reg_vfi - Initialize the REG_VFI mailbox command |
| 2128 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2129 | * @vport: vport associated with the VF. |
| 2130 | * @phys: BDE DMA bus address used to send the service parameters to the HBA. |
| 2131 | * |
| 2132 | * This routine initializes @mbox to all zeros and then fills in the mailbox |
| 2133 | * fields from @vport, and uses @buf as a DMAable buffer to send the vport's |
| 2134 | * fc service parameters to the HBA for this VFI. REG_VFI configures virtual |
| 2135 | * fabrics identified by VFI in the context of an FCF. |
| 2136 | **/ |
| 2137 | void |
| 2138 | lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys) |
| 2139 | { |
| 2140 | struct lpfc_mbx_reg_vfi *reg_vfi; |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2141 | struct lpfc_hba *phba = vport->phba; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2142 | |
| 2143 | memset(mbox, 0, sizeof(*mbox)); |
| 2144 | reg_vfi = &mbox->u.mqe.un.reg_vfi; |
| 2145 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI); |
| 2146 | bf_set(lpfc_reg_vfi_vp, reg_vfi, 1); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2147 | bf_set(lpfc_reg_vfi_vfi, reg_vfi, |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2148 | phba->sli4_hba.vfi_ids[vport->vfi]); |
| 2149 | bf_set(lpfc_reg_vfi_fcfi, reg_vfi, phba->fcf.fcfi); |
| 2150 | bf_set(lpfc_reg_vfi_vpi, reg_vfi, phba->vpi_ids[vport->vpi]); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2151 | memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2152 | reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]); |
| 2153 | reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]); |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2154 | reg_vfi->e_d_tov = phba->fc_edtov; |
| 2155 | reg_vfi->r_a_tov = phba->fc_ratov; |
James Smart | ae09c76 | 2016-03-31 14:12:28 -0700 | [diff] [blame] | 2156 | if (phys) { |
| 2157 | reg_vfi->bde.addrHigh = putPaddrHigh(phys); |
| 2158 | reg_vfi->bde.addrLow = putPaddrLow(phys); |
| 2159 | reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam); |
| 2160 | reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 2161 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2162 | bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID); |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2163 | |
| 2164 | /* Only FC supports upd bit */ |
| 2165 | if ((phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) && |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2166 | (vport->fc_flag & FC_VFI_REGISTERED) && |
| 2167 | (!phba->fc_topology_changed)) { |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2168 | bf_set(lpfc_reg_vfi_vp, reg_vfi, 0); |
| 2169 | bf_set(lpfc_reg_vfi_upd, reg_vfi, 1); |
| 2170 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2171 | lpfc_printf_vlog(vport, KERN_INFO, LOG_MBOX, |
| 2172 | "3134 Register VFI, mydid:x%x, fcfi:%d, " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2173 | " vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x" |
| 2174 | " port_state:x%x topology chg:%d\n", |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2175 | vport->fc_myDID, |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2176 | phba->fcf.fcfi, |
| 2177 | phba->sli4_hba.vfi_ids[vport->vfi], |
| 2178 | phba->vpi_ids[vport->vpi], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2179 | reg_vfi->wwn[0], reg_vfi->wwn[1], vport->fc_flag, |
| 2180 | vport->port_state, phba->fc_topology_changed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2181 | } |
| 2182 | |
| 2183 | /** |
| 2184 | * lpfc_init_vpi - Initialize the INIT_VPI mailbox command |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2185 | * @phba: pointer to the hba structure to init the VPI for. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2186 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2187 | * @vpi: VPI to be initialized. |
| 2188 | * |
| 2189 | * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the |
| 2190 | * command to activate a virtual N_Port. The HBA assigns a MAC address to use |
| 2191 | * with the virtual N Port. The SLI Host issues this command before issuing a |
| 2192 | * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a |
| 2193 | * successful virtual NPort login. |
| 2194 | **/ |
| 2195 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2196 | lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2197 | { |
| 2198 | memset(mbox, 0, sizeof(*mbox)); |
| 2199 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2200 | bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2201 | phba->vpi_ids[vpi]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2202 | bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2203 | phba->sli4_hba.vfi_ids[phba->pport->vfi]); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | /** |
| 2207 | * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command |
| 2208 | * @mbox: pointer to lpfc mbox command to initialize. |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2209 | * @vport: vport associated with the VF. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2210 | * |
| 2211 | * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric |
| 2212 | * (logical NPort) into the inactive state. The SLI Host must have logged out |
| 2213 | * and unregistered all remote N_Ports to abort any activity on the virtual |
| 2214 | * fabric. The SLI Port posts the mailbox response after marking the virtual |
| 2215 | * fabric inactive. |
| 2216 | **/ |
| 2217 | void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2218 | lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2219 | { |
| 2220 | memset(mbox, 0, sizeof(*mbox)); |
| 2221 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2222 | bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2223 | vport->phba->sli4_hba.vfi_ids[vport->vfi]); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 2227 | * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23 |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2228 | * @phba: pointer to the hba structure containing. |
| 2229 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2230 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 2231 | * This function create a SLI4 dump mailbox command to dump configure |
| 2232 | * region 23. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2233 | **/ |
| 2234 | int |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 2235 | lpfc_sli4_dump_cfg_rg23(struct lpfc_hba *phba, struct lpfcMboxq *mbox) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2236 | { |
| 2237 | struct lpfc_dmabuf *mp = NULL; |
| 2238 | MAILBOX_t *mb; |
| 2239 | |
| 2240 | memset(mbox, 0, sizeof(*mbox)); |
| 2241 | mb = &mbox->u.mb; |
| 2242 | |
| 2243 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 2244 | if (mp) |
| 2245 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 2246 | |
| 2247 | if (!mp || !mp->virt) { |
| 2248 | kfree(mp); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 2249 | /* dump config region 23 failed to allocate memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2250 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 2251 | "2569 lpfc dump config region 23: memory" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 2252 | " allocation failed\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2253 | return 1; |
| 2254 | } |
| 2255 | |
| 2256 | memset(mp->virt, 0, LPFC_BPL_SIZE); |
| 2257 | INIT_LIST_HEAD(&mp->list); |
| 2258 | |
| 2259 | /* save address for completion */ |
| 2260 | mbox->context1 = (uint8_t *) mp; |
| 2261 | |
| 2262 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 2263 | mb->un.varDmp.type = DMP_NV_PARAMS; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 2264 | mb->un.varDmp.region_id = DMP_REGION_23; |
| 2265 | mb->un.varDmp.sli4_length = DMP_RGN23_SIZE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2266 | mb->un.varWords[3] = putPaddrLow(mp->phys); |
| 2267 | mb->un.varWords[4] = putPaddrHigh(mp->phys); |
| 2268 | return 0; |
| 2269 | } |
| 2270 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2271 | static void |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 2272 | lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 2273 | { |
| 2274 | MAILBOX_t *mb; |
| 2275 | int rc = FAILURE; |
| 2276 | struct lpfc_rdp_context *rdp_context = |
| 2277 | (struct lpfc_rdp_context *)(mboxq->context2); |
| 2278 | |
| 2279 | mb = &mboxq->u.mb; |
| 2280 | if (mb->mbxStatus) |
| 2281 | goto mbx_failed; |
| 2282 | |
| 2283 | memcpy(&rdp_context->link_stat, &mb->un.varRdLnk, sizeof(READ_LNK_VAR)); |
| 2284 | |
| 2285 | rc = SUCCESS; |
| 2286 | |
| 2287 | mbx_failed: |
| 2288 | lpfc_sli4_mbox_cmd_free(phba, mboxq); |
| 2289 | rdp_context->cmpl(phba, rdp_context, rc); |
| 2290 | } |
| 2291 | |
Baoyou Xie | bd4b3e5 | 2016-09-25 13:44:55 +0800 | [diff] [blame] | 2292 | static void |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 2293 | lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 2294 | { |
| 2295 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) mbox->context1; |
| 2296 | struct lpfc_rdp_context *rdp_context = |
| 2297 | (struct lpfc_rdp_context *)(mbox->context2); |
| 2298 | |
| 2299 | if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) |
Johannes Thumshirn | 612872c | 2015-08-17 13:03:02 +0200 | [diff] [blame] | 2300 | goto error_mbuf_free; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 2301 | |
| 2302 | lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2, |
| 2303 | DMP_SFF_PAGE_A2_SIZE); |
| 2304 | |
| 2305 | /* We don't need dma buffer for link stat. */ |
| 2306 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2307 | kfree(mp); |
| 2308 | |
| 2309 | memset(mbox, 0, sizeof(*mbox)); |
| 2310 | lpfc_read_lnk_stat(phba, mbox); |
| 2311 | mbox->vport = rdp_context->ndlp->vport; |
| 2312 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_link_stat; |
| 2313 | mbox->context2 = (struct lpfc_rdp_context *) rdp_context; |
| 2314 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == MBX_NOT_FINISHED) |
Johannes Thumshirn | 612872c | 2015-08-17 13:03:02 +0200 | [diff] [blame] | 2315 | goto error_cmd_free; |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 2316 | |
| 2317 | return; |
| 2318 | |
Johannes Thumshirn | 612872c | 2015-08-17 13:03:02 +0200 | [diff] [blame] | 2319 | error_mbuf_free: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 2320 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2321 | kfree(mp); |
Johannes Thumshirn | 612872c | 2015-08-17 13:03:02 +0200 | [diff] [blame] | 2322 | error_cmd_free: |
James Smart | 8647887 | 2015-05-21 13:55:21 -0400 | [diff] [blame] | 2323 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 2324 | rdp_context->cmpl(phba, rdp_context, FAILURE); |
| 2325 | } |
| 2326 | |
| 2327 | void |
| 2328 | lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 2329 | { |
| 2330 | int rc; |
| 2331 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (mbox->context1); |
| 2332 | struct lpfc_rdp_context *rdp_context = |
| 2333 | (struct lpfc_rdp_context *)(mbox->context2); |
| 2334 | |
| 2335 | if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) |
| 2336 | goto error; |
| 2337 | |
| 2338 | lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0, |
| 2339 | DMP_SFF_PAGE_A0_SIZE); |
| 2340 | |
| 2341 | memset(mbox, 0, sizeof(*mbox)); |
| 2342 | |
| 2343 | memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE); |
| 2344 | INIT_LIST_HEAD(&mp->list); |
| 2345 | |
| 2346 | /* save address for completion */ |
| 2347 | mbox->context1 = mp; |
| 2348 | mbox->vport = rdp_context->ndlp->vport; |
| 2349 | |
| 2350 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY); |
| 2351 | bf_set(lpfc_mbx_memory_dump_type3_type, |
| 2352 | &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD); |
| 2353 | bf_set(lpfc_mbx_memory_dump_type3_link, |
| 2354 | &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port); |
| 2355 | bf_set(lpfc_mbx_memory_dump_type3_page_no, |
| 2356 | &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2); |
| 2357 | bf_set(lpfc_mbx_memory_dump_type3_length, |
| 2358 | &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE); |
| 2359 | mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys); |
| 2360 | mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys); |
| 2361 | |
| 2362 | mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a2; |
| 2363 | mbox->context2 = (struct lpfc_rdp_context *) rdp_context; |
| 2364 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 2365 | if (rc == MBX_NOT_FINISHED) |
| 2366 | goto error; |
| 2367 | |
| 2368 | return; |
| 2369 | |
| 2370 | error: |
| 2371 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2372 | kfree(mp); |
| 2373 | lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 2374 | rdp_context->cmpl(phba, rdp_context, FAILURE); |
| 2375 | } |
| 2376 | |
| 2377 | |
| 2378 | /* |
| 2379 | * lpfc_sli4_dump_sfp_pagea0 - Dump sli4 read SFP Diagnostic. |
| 2380 | * @phba: pointer to the hba structure containing. |
| 2381 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2382 | * |
| 2383 | * This function create a SLI4 dump mailbox command to dump configure |
| 2384 | * type 3 page 0xA0. |
| 2385 | */ |
| 2386 | int |
| 2387 | lpfc_sli4_dump_page_a0(struct lpfc_hba *phba, struct lpfcMboxq *mbox) |
| 2388 | { |
| 2389 | struct lpfc_dmabuf *mp = NULL; |
| 2390 | |
| 2391 | memset(mbox, 0, sizeof(*mbox)); |
| 2392 | |
| 2393 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 2394 | if (mp) |
| 2395 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 2396 | if (!mp || !mp->virt) { |
| 2397 | kfree(mp); |
| 2398 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 2399 | "3569 dump type 3 page 0xA0 allocation failed\n"); |
| 2400 | return 1; |
| 2401 | } |
| 2402 | |
| 2403 | memset(mp->virt, 0, LPFC_BPL_SIZE); |
| 2404 | INIT_LIST_HEAD(&mp->list); |
| 2405 | |
| 2406 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY); |
| 2407 | /* save address for completion */ |
| 2408 | mbox->context1 = mp; |
| 2409 | |
| 2410 | bf_set(lpfc_mbx_memory_dump_type3_type, |
| 2411 | &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD); |
| 2412 | bf_set(lpfc_mbx_memory_dump_type3_link, |
| 2413 | &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port); |
| 2414 | bf_set(lpfc_mbx_memory_dump_type3_page_no, |
| 2415 | &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A0); |
| 2416 | bf_set(lpfc_mbx_memory_dump_type3_length, |
| 2417 | &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE); |
| 2418 | mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys); |
| 2419 | mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys); |
| 2420 | |
| 2421 | return 0; |
| 2422 | } |
| 2423 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2424 | /** |
| 2425 | * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command |
| 2426 | * @phba: pointer to the hba structure containing the FCF index and RQ ID. |
| 2427 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2428 | * |
| 2429 | * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The |
| 2430 | * SLI Host uses the command to activate an FCF after it has acquired FCF |
| 2431 | * information via a READ_FCF mailbox command. This mailbox command also is used |
| 2432 | * to indicate where received unsolicited frames from this FCF will be sent. By |
| 2433 | * default this routine will set up the FCF to forward all unsolicited frames |
| 2434 | * the the RQ ID passed in the @phba. This can be overridden by the caller for |
| 2435 | * more complicated setups. |
| 2436 | **/ |
| 2437 | void |
| 2438 | lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox) |
| 2439 | { |
| 2440 | struct lpfc_mbx_reg_fcfi *reg_fcfi; |
| 2441 | |
| 2442 | memset(mbox, 0, sizeof(*mbox)); |
| 2443 | reg_fcfi = &mbox->u.mqe.un.reg_fcfi; |
| 2444 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2445 | if (phba->nvmet_support == 0) { |
| 2446 | bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, |
| 2447 | phba->sli4_hba.hdr_rq->queue_id); |
| 2448 | /* Match everything - rq_id0 */ |
| 2449 | bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, 0); |
| 2450 | bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0); |
| 2451 | bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi, 0); |
| 2452 | bf_set(lpfc_reg_fcfi_rctl_mask0, reg_fcfi, 0); |
| 2453 | |
| 2454 | bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID); |
| 2455 | |
| 2456 | /* addr mode is bit wise inverted value of fcf addr_mode */ |
| 2457 | bf_set(lpfc_reg_fcfi_mam, reg_fcfi, |
| 2458 | (~phba->fcf.addr_mode) & 0x3); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2459 | } else { |
| 2460 | /* This is ONLY for NVMET MRQ == 1 */ |
| 2461 | if (phba->cfg_nvmet_mrq != 1) |
| 2462 | return; |
| 2463 | |
| 2464 | bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, |
| 2465 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id); |
| 2466 | /* Match type FCP - rq_id0 */ |
| 2467 | bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, FC_TYPE_FCP); |
| 2468 | bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0xff); |
| 2469 | bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi, |
| 2470 | FC_RCTL_DD_UNSOL_CMD); |
| 2471 | |
| 2472 | bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, |
| 2473 | phba->sli4_hba.hdr_rq->queue_id); |
| 2474 | /* Match everything else - rq_id1 */ |
| 2475 | bf_set(lpfc_reg_fcfi_type_match1, reg_fcfi, 0); |
| 2476 | bf_set(lpfc_reg_fcfi_type_mask1, reg_fcfi, 0); |
| 2477 | bf_set(lpfc_reg_fcfi_rctl_match1, reg_fcfi, 0); |
| 2478 | bf_set(lpfc_reg_fcfi_rctl_mask1, reg_fcfi, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2479 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2480 | bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID); |
| 2481 | bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2482 | bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, |
| 2483 | phba->fcf.current_rec.fcf_indx); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2484 | if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2485 | bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2486 | bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, |
| 2487 | phba->fcf.current_rec.vlan_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2488 | } |
| 2489 | } |
| 2490 | |
| 2491 | /** |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 2492 | * lpfc_reg_fcfi_mrq - Initialize the REG_FCFI_MRQ mailbox command |
| 2493 | * @phba: pointer to the hba structure containing the FCF index and RQ ID. |
| 2494 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2495 | * @mode: 0 to register FCFI, 1 to register MRQs |
| 2496 | * |
| 2497 | * The REG_FCFI_MRQ mailbox command supports Fibre Channel Forwarders (FCFs). |
| 2498 | * The SLI Host uses the command to activate an FCF after it has acquired FCF |
| 2499 | * information via a READ_FCF mailbox command. This mailbox command also is used |
| 2500 | * to indicate where received unsolicited frames from this FCF will be sent. By |
| 2501 | * default this routine will set up the FCF to forward all unsolicited frames |
| 2502 | * the the RQ ID passed in the @phba. This can be overridden by the caller for |
| 2503 | * more complicated setups. |
| 2504 | **/ |
| 2505 | void |
| 2506 | lpfc_reg_fcfi_mrq(struct lpfc_hba *phba, struct lpfcMboxq *mbox, int mode) |
| 2507 | { |
| 2508 | struct lpfc_mbx_reg_fcfi_mrq *reg_fcfi; |
| 2509 | |
| 2510 | /* This is ONLY for MRQ */ |
| 2511 | if (phba->cfg_nvmet_mrq <= 1) |
| 2512 | return; |
| 2513 | |
| 2514 | memset(mbox, 0, sizeof(*mbox)); |
| 2515 | reg_fcfi = &mbox->u.mqe.un.reg_fcfi_mrq; |
| 2516 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI_MRQ); |
| 2517 | if (mode == 0) { |
| 2518 | bf_set(lpfc_reg_fcfi_mrq_info_index, reg_fcfi, |
| 2519 | phba->fcf.current_rec.fcf_indx); |
| 2520 | if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) { |
| 2521 | bf_set(lpfc_reg_fcfi_mrq_vv, reg_fcfi, 1); |
| 2522 | bf_set(lpfc_reg_fcfi_mrq_vlan_tag, reg_fcfi, |
| 2523 | phba->fcf.current_rec.vlan_id); |
| 2524 | } |
| 2525 | return; |
| 2526 | } |
| 2527 | |
| 2528 | bf_set(lpfc_reg_fcfi_mrq_rq_id0, reg_fcfi, |
| 2529 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id); |
| 2530 | /* Match NVME frames of type FCP (protocol NVME) - rq_id0 */ |
| 2531 | bf_set(lpfc_reg_fcfi_mrq_type_match0, reg_fcfi, FC_TYPE_FCP); |
| 2532 | bf_set(lpfc_reg_fcfi_mrq_type_mask0, reg_fcfi, 0xff); |
| 2533 | bf_set(lpfc_reg_fcfi_mrq_rctl_match0, reg_fcfi, FC_RCTL_DD_UNSOL_CMD); |
| 2534 | bf_set(lpfc_reg_fcfi_mrq_rctl_mask0, reg_fcfi, 0xff); |
| 2535 | bf_set(lpfc_reg_fcfi_mrq_ptc0, reg_fcfi, 1); |
| 2536 | bf_set(lpfc_reg_fcfi_mrq_pt0, reg_fcfi, 1); |
| 2537 | |
| 2538 | bf_set(lpfc_reg_fcfi_mrq_policy, reg_fcfi, 3); /* NVME connection id */ |
| 2539 | bf_set(lpfc_reg_fcfi_mrq_mode, reg_fcfi, 1); |
| 2540 | bf_set(lpfc_reg_fcfi_mrq_filter, reg_fcfi, 1); /* rq_id0 */ |
| 2541 | bf_set(lpfc_reg_fcfi_mrq_npairs, reg_fcfi, phba->cfg_nvmet_mrq); |
| 2542 | |
| 2543 | bf_set(lpfc_reg_fcfi_mrq_rq_id1, reg_fcfi, |
| 2544 | phba->sli4_hba.hdr_rq->queue_id); |
| 2545 | /* Match everything - rq_id1 */ |
| 2546 | bf_set(lpfc_reg_fcfi_mrq_type_match1, reg_fcfi, 0); |
| 2547 | bf_set(lpfc_reg_fcfi_mrq_type_mask1, reg_fcfi, 0); |
| 2548 | bf_set(lpfc_reg_fcfi_mrq_rctl_match1, reg_fcfi, 0); |
| 2549 | bf_set(lpfc_reg_fcfi_mrq_rctl_mask1, reg_fcfi, 0); |
| 2550 | |
| 2551 | bf_set(lpfc_reg_fcfi_mrq_rq_id2, reg_fcfi, REG_FCF_INVALID_QID); |
| 2552 | bf_set(lpfc_reg_fcfi_mrq_rq_id3, reg_fcfi, REG_FCF_INVALID_QID); |
| 2553 | } |
| 2554 | |
| 2555 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2556 | * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command |
| 2557 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2558 | * @fcfi: FCFI to be unregistered. |
| 2559 | * |
| 2560 | * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). |
| 2561 | * The SLI Host uses the command to inactivate an FCFI. |
| 2562 | **/ |
| 2563 | void |
| 2564 | lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi) |
| 2565 | { |
| 2566 | memset(mbox, 0, sizeof(*mbox)); |
| 2567 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI); |
| 2568 | bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi); |
| 2569 | } |
| 2570 | |
| 2571 | /** |
| 2572 | * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command |
| 2573 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2574 | * @ndlp: The nodelist structure that describes the RPI to resume. |
| 2575 | * |
| 2576 | * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a |
| 2577 | * link event. |
| 2578 | **/ |
| 2579 | void |
| 2580 | lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp) |
| 2581 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2582 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2583 | struct lpfc_mbx_resume_rpi *resume_rpi; |
| 2584 | |
| 2585 | memset(mbox, 0, sizeof(*mbox)); |
| 2586 | resume_rpi = &mbox->u.mqe.un.resume_rpi; |
| 2587 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2588 | bf_set(lpfc_resume_rpi_index, resume_rpi, |
| 2589 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 2590 | bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI); |
| 2591 | resume_rpi->event_tag = ndlp->phba->fc_eventTag; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2592 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 2593 | |
| 2594 | /** |
| 2595 | * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages |
| 2596 | * mailbox command. |
| 2597 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2598 | * |
| 2599 | * The PORT_CAPABILITIES supported pages mailbox command is issued to |
| 2600 | * retrieve the particular feature pages supported by the port. |
| 2601 | **/ |
| 2602 | void |
| 2603 | lpfc_supported_pages(struct lpfcMboxq *mbox) |
| 2604 | { |
| 2605 | struct lpfc_mbx_supp_pages *supp_pages; |
| 2606 | |
| 2607 | memset(mbox, 0, sizeof(*mbox)); |
| 2608 | supp_pages = &mbox->u.mqe.un.supp_pages; |
| 2609 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES); |
| 2610 | bf_set(cpn, supp_pages, LPFC_SUPP_PAGES); |
| 2611 | } |
| 2612 | |
| 2613 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2614 | * lpfc_pc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params mbox cmd. |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 2615 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2616 | * |
| 2617 | * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to |
| 2618 | * retrieve the particular SLI4 features supported by the port. |
| 2619 | **/ |
| 2620 | void |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2621 | lpfc_pc_sli4_params(struct lpfcMboxq *mbox) |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 2622 | { |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2623 | struct lpfc_mbx_pc_sli4_params *sli4_params; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 2624 | |
| 2625 | memset(mbox, 0, sizeof(*mbox)); |
| 2626 | sli4_params = &mbox->u.mqe.un.sli4_params; |
| 2627 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES); |
| 2628 | bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS); |
| 2629 | } |