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