1dea3101eS /******************************************************************* 2dea3101eS * This file is part of the Emulex Linux Device Driver for * 3c44ce173SJames.Smart@Emulex.Com * Fibre Channel Host Bus Adapters. * 4128bddacSJames Smart * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term * 54ae2ebdeSJames Smart * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * 650611577SJames Smart * Copyright (C) 2004-2016 Emulex. All rights reserved. * 7c44ce173SJames.Smart@Emulex.Com * EMULEX and SLI are trademarks of Emulex. * 8d080abe0SJames Smart * www.broadcom.com * 9c44ce173SJames.Smart@Emulex.Com * Portions Copyright (C) 2004-2005 Christoph Hellwig * 10dea3101eS * * 11dea3101eS * This program is free software; you can redistribute it and/or * 12c44ce173SJames.Smart@Emulex.Com * modify it under the terms of version 2 of the GNU General * 13c44ce173SJames.Smart@Emulex.Com * Public License as published by the Free Software Foundation. * 14c44ce173SJames.Smart@Emulex.Com * This program is distributed in the hope that it will be useful. * 15c44ce173SJames.Smart@Emulex.Com * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 16c44ce173SJames.Smart@Emulex.Com * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 17c44ce173SJames.Smart@Emulex.Com * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 18c44ce173SJames.Smart@Emulex.Com * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 19c44ce173SJames.Smart@Emulex.Com * TO BE LEGALLY INVALID. See the GNU General Public License for * 20c44ce173SJames.Smart@Emulex.Com * more details, a copy of which can be found in the file COPYING * 21c44ce173SJames.Smart@Emulex.Com * included with this package. * 22dea3101eS *******************************************************************/ 23dea3101eS 24dea3101eS #include <linux/blkdev.h> 25dea3101eS #include <linux/pci.h> 265a0e3ad6STejun Heo #include <linux/slab.h> 27dea3101eS #include <linux/interrupt.h> 28dea3101eS 29f888ba3cSJames.Smart@Emulex.Com #include <scsi/scsi_device.h> 30f888ba3cSJames.Smart@Emulex.Com #include <scsi/scsi_transport_fc.h> 3191886523SJames.Smart@Emulex.Com #include <scsi/scsi.h> 326a9c52cfSJames Smart #include <scsi/fc/fc_fs.h> 3391886523SJames.Smart@Emulex.Com 34da0436e9SJames Smart #include "lpfc_hw4.h" 35dea3101eS #include "lpfc_hw.h" 36dea3101eS #include "lpfc_sli.h" 37da0436e9SJames Smart #include "lpfc_sli4.h" 38ea2151b4SJames Smart #include "lpfc_nl.h" 39dea3101eS #include "lpfc_disc.h" 40dea3101eS #include "lpfc_scsi.h" 41dea3101eS #include "lpfc.h" 42dea3101eS #include "lpfc_logmsg.h" 43dea3101eS #include "lpfc_crtn.h" 44dea3101eS #include "lpfc_compat.h" 45dea3101eS 46e59058c4SJames Smart /** 4721e9a0a5SJames Smart * lpfc_dump_static_vport - Dump HBA's static vport information. 4821e9a0a5SJames Smart * @phba: pointer to lpfc hba data structure. 4921e9a0a5SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 5021e9a0a5SJames Smart * @offset: offset for dumping vport info. 5121e9a0a5SJames Smart * 5221e9a0a5SJames Smart * The dump mailbox command provides a method for the device driver to obtain 5321e9a0a5SJames Smart * various types of information from the HBA device. 5421e9a0a5SJames Smart * 5521e9a0a5SJames Smart * This routine prepares the mailbox command for dumping list of static 5621e9a0a5SJames Smart * vports to be created. 5721e9a0a5SJames Smart **/ 581c6834a7SJames Smart int 5921e9a0a5SJames Smart lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, 6021e9a0a5SJames Smart uint16_t offset) 6121e9a0a5SJames Smart { 6221e9a0a5SJames Smart MAILBOX_t *mb; 631c6834a7SJames Smart struct lpfc_dmabuf *mp; 6421e9a0a5SJames Smart 6521e9a0a5SJames Smart mb = &pmb->u.mb; 6621e9a0a5SJames Smart 6721e9a0a5SJames Smart /* Setup to dump vport info region */ 6821e9a0a5SJames Smart memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 6921e9a0a5SJames Smart mb->mbxCommand = MBX_DUMP_MEMORY; 7021e9a0a5SJames Smart mb->un.varDmp.type = DMP_NV_PARAMS; 7121e9a0a5SJames Smart mb->un.varDmp.entry_index = offset; 7221e9a0a5SJames Smart mb->un.varDmp.region_id = DMP_REGION_VPORT; 7321e9a0a5SJames Smart mb->mbxOwner = OWN_HOST; 7421e9a0a5SJames Smart 751c6834a7SJames Smart /* For SLI3 HBAs data is embedded in mailbox */ 761c6834a7SJames Smart if (phba->sli_rev != LPFC_SLI_REV4) { 771c6834a7SJames Smart mb->un.varDmp.cv = 1; 781c6834a7SJames Smart mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t); 791c6834a7SJames Smart return 0; 801c6834a7SJames Smart } 811c6834a7SJames Smart 821c6834a7SJames Smart /* For SLI4 HBAs driver need to allocate memory */ 831c6834a7SJames Smart mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 841c6834a7SJames Smart if (mp) 851c6834a7SJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 861c6834a7SJames Smart 871c6834a7SJames Smart if (!mp || !mp->virt) { 881c6834a7SJames Smart kfree(mp); 891c6834a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, 901c6834a7SJames Smart "2605 lpfc_dump_static_vport: memory" 911c6834a7SJames Smart " allocation failed\n"); 921c6834a7SJames Smart return 1; 931c6834a7SJames Smart } 941c6834a7SJames Smart memset(mp->virt, 0, LPFC_BPL_SIZE); 951c6834a7SJames Smart INIT_LIST_HEAD(&mp->list); 961c6834a7SJames Smart /* save address for completion */ 973e1f0718SJames Smart pmb->ctx_buf = (uint8_t *)mp; 981c6834a7SJames Smart mb->un.varWords[3] = putPaddrLow(mp->phys); 991c6834a7SJames Smart mb->un.varWords[4] = putPaddrHigh(mp->phys); 1001c6834a7SJames Smart mb->un.varDmp.sli4_length = sizeof(struct static_vport_info); 1011c6834a7SJames Smart 1021c6834a7SJames Smart return 0; 10321e9a0a5SJames Smart } 10421e9a0a5SJames Smart 10521e9a0a5SJames Smart /** 106a0c87cbdSJames Smart * lpfc_down_link - Bring down HBAs link. 107e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 108e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 109a0c87cbdSJames Smart * 110a0c87cbdSJames Smart * This routine prepares a mailbox command to bring down HBA link. 111a0c87cbdSJames Smart **/ 112a0c87cbdSJames Smart void 113a0c87cbdSJames Smart lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 114a0c87cbdSJames Smart { 115a0c87cbdSJames Smart MAILBOX_t *mb; 116a0c87cbdSJames Smart memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 117a0c87cbdSJames Smart mb = &pmb->u.mb; 118a0c87cbdSJames Smart mb->mbxCommand = MBX_DOWN_LINK; 119a0c87cbdSJames Smart mb->mbxOwner = OWN_HOST; 120a0c87cbdSJames Smart } 121a0c87cbdSJames Smart 122a0c87cbdSJames Smart /** 123a0c87cbdSJames Smart * lpfc_dump_mem - Prepare a mailbox command for reading a region. 124a0c87cbdSJames Smart * @phba: pointer to lpfc hba data structure. 125a0c87cbdSJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 126a0c87cbdSJames Smart * @offset: offset into the region. 127a0c87cbdSJames Smart * @region_id: config region id. 128e59058c4SJames Smart * 129e59058c4SJames Smart * The dump mailbox command provides a method for the device driver to obtain 130e59058c4SJames Smart * various types of information from the HBA device. 131e59058c4SJames Smart * 132a0c87cbdSJames Smart * This routine prepares the mailbox command for dumping HBA's config region. 133e59058c4SJames Smart **/ 134dea3101eS void 135a0c87cbdSJames Smart lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset, 136a0c87cbdSJames Smart uint16_t region_id) 137dea3101eS { 138dea3101eS MAILBOX_t *mb; 139dea3101eS void *ctx; 140dea3101eS 14104c68496SJames Smart mb = &pmb->u.mb; 1423e1f0718SJames Smart ctx = pmb->ctx_buf; 143dea3101eS 144dea3101eS /* Setup to dump VPD region */ 145dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 146dea3101eS mb->mbxCommand = MBX_DUMP_MEMORY; 147dea3101eS mb->un.varDmp.cv = 1; 148dea3101eS mb->un.varDmp.type = DMP_NV_PARAMS; 149dea3101eS mb->un.varDmp.entry_index = offset; 150a0c87cbdSJames Smart mb->un.varDmp.region_id = region_id; 151dea3101eS mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t)); 152dea3101eS mb->un.varDmp.co = 0; 153dea3101eS mb->un.varDmp.resp_offset = 0; 1543e1f0718SJames Smart pmb->ctx_buf = ctx; 155dea3101eS mb->mbxOwner = OWN_HOST; 156dea3101eS return; 157dea3101eS } 158dea3101eS 159e59058c4SJames Smart /** 1603621a710SJames Smart * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params 16197207482SJames Smart * @phba: pointer to lpfc hba data structure. 16297207482SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1633621a710SJames Smart * 16497207482SJames Smart * This function create a dump memory mailbox command to dump wake up 16597207482SJames Smart * parameters. 16697207482SJames Smart */ 16797207482SJames Smart void 16897207482SJames Smart lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 16997207482SJames Smart { 17097207482SJames Smart MAILBOX_t *mb; 17197207482SJames Smart void *ctx; 17297207482SJames Smart 17304c68496SJames Smart mb = &pmb->u.mb; 17497207482SJames Smart /* Save context so that we can restore after memset */ 1753e1f0718SJames Smart ctx = pmb->ctx_buf; 17697207482SJames Smart 17797207482SJames Smart /* Setup to dump VPD region */ 17897207482SJames Smart memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 17997207482SJames Smart mb->mbxCommand = MBX_DUMP_MEMORY; 18097207482SJames Smart mb->mbxOwner = OWN_HOST; 18197207482SJames Smart mb->un.varDmp.cv = 1; 18297207482SJames Smart mb->un.varDmp.type = DMP_NV_PARAMS; 1831d1c296fSJames Smart if (phba->sli_rev < LPFC_SLI_REV4) 18497207482SJames Smart mb->un.varDmp.entry_index = 0; 18597207482SJames Smart mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID; 18697207482SJames Smart mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE; 18797207482SJames Smart mb->un.varDmp.co = 0; 18897207482SJames Smart mb->un.varDmp.resp_offset = 0; 1893e1f0718SJames Smart pmb->ctx_buf = ctx; 19097207482SJames Smart return; 19197207482SJames Smart } 19297207482SJames Smart 19397207482SJames Smart /** 1943621a710SJames Smart * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param 195e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 196e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 197e59058c4SJames Smart * 198e59058c4SJames Smart * The read NVRAM mailbox command returns the HBA's non-volatile parameters 199e59058c4SJames Smart * that are used as defaults when the Fibre Channel link is brought on-line. 200e59058c4SJames Smart * 201e59058c4SJames Smart * This routine prepares the mailbox command for reading information stored 202e59058c4SJames Smart * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN. 203e59058c4SJames Smart **/ 204dea3101eS void 205dea3101eS lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 206dea3101eS { 207dea3101eS MAILBOX_t *mb; 208dea3101eS 20904c68496SJames Smart mb = &pmb->u.mb; 210dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 211dea3101eS mb->mbxCommand = MBX_READ_NV; 212dea3101eS mb->mbxOwner = OWN_HOST; 213dea3101eS return; 214dea3101eS } 215dea3101eS 216e59058c4SJames Smart /** 2173621a710SJames Smart * lpfc_config_async - Prepare a mailbox command for enabling HBA async event 218e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 219e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 220e59058c4SJames Smart * @ring: ring number for the asynchronous event to be configured. 221e59058c4SJames Smart * 222e59058c4SJames Smart * The asynchronous event enable mailbox command is used to enable the 223e59058c4SJames Smart * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and 224e59058c4SJames Smart * specifies the default ring to which events are posted. 225e59058c4SJames Smart * 226e59058c4SJames Smart * This routine prepares the mailbox command for enabling HBA asynchronous 227e59058c4SJames Smart * event support on a IOCB ring. 228e59058c4SJames Smart **/ 22957127f15SJames Smart void 23057127f15SJames Smart lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, 23157127f15SJames Smart uint32_t ring) 23257127f15SJames Smart { 23357127f15SJames Smart MAILBOX_t *mb; 23457127f15SJames Smart 23504c68496SJames Smart mb = &pmb->u.mb; 23657127f15SJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 23757127f15SJames Smart mb->mbxCommand = MBX_ASYNCEVT_ENABLE; 23857127f15SJames Smart mb->un.varCfgAsyncEvent.ring = ring; 23957127f15SJames Smart mb->mbxOwner = OWN_HOST; 24057127f15SJames Smart return; 24157127f15SJames Smart } 24257127f15SJames Smart 243e59058c4SJames Smart /** 2443621a710SJames Smart * lpfc_heart_beat - Prepare a mailbox command for heart beat 245e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 246e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 247e59058c4SJames Smart * 248e59058c4SJames Smart * The heart beat mailbox command is used to detect an unresponsive HBA, which 249e59058c4SJames Smart * is defined as any device where no error attention is sent and both mailbox 250e59058c4SJames Smart * and rings are not processed. 251e59058c4SJames Smart * 252e59058c4SJames Smart * This routine prepares the mailbox command for issuing a heart beat in the 253e59058c4SJames Smart * form of mailbox command to the HBA. The timely completion of the heart 254e59058c4SJames Smart * beat mailbox command indicates the health of the HBA. 255e59058c4SJames Smart **/ 256858c9f6cSJames Smart void 257858c9f6cSJames Smart lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 258858c9f6cSJames Smart { 259858c9f6cSJames Smart MAILBOX_t *mb; 260858c9f6cSJames Smart 26104c68496SJames Smart mb = &pmb->u.mb; 262858c9f6cSJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 263858c9f6cSJames Smart mb->mbxCommand = MBX_HEARTBEAT; 264858c9f6cSJames Smart mb->mbxOwner = OWN_HOST; 265858c9f6cSJames Smart return; 266858c9f6cSJames Smart } 267858c9f6cSJames Smart 268e59058c4SJames Smart /** 26976a95d75SJames Smart * lpfc_read_topology - Prepare a mailbox command for reading HBA topology 270e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 271e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 272e59058c4SJames Smart * @mp: DMA buffer memory for reading the link attention information into. 273e59058c4SJames Smart * 27476a95d75SJames Smart * The read topology mailbox command is issued to read the link topology 27576a95d75SJames Smart * information indicated by the HBA port when the Link Event bit of the Host 27676a95d75SJames Smart * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link 27776a95d75SJames Smart * Attention ACQE is received from the port (For SLI-4). A Link Event 278e59058c4SJames Smart * Attention occurs based on an exception detected at the Fibre Channel link 279e59058c4SJames Smart * interface. 280e59058c4SJames Smart * 28176a95d75SJames Smart * This routine prepares the mailbox command for reading HBA link topology 282e59058c4SJames Smart * information. A DMA memory has been set aside and address passed to the 283e59058c4SJames Smart * HBA through @mp for the HBA to DMA link attention information into the 284e59058c4SJames Smart * memory as part of the execution of the mailbox command. 285e59058c4SJames Smart * 286e59058c4SJames Smart * Return codes 287e59058c4SJames Smart * 0 - Success (currently always return 0) 288e59058c4SJames Smart **/ 289dea3101eS int 29076a95d75SJames Smart lpfc_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, 29176a95d75SJames Smart struct lpfc_dmabuf *mp) 292dea3101eS { 293dea3101eS MAILBOX_t *mb; 294dea3101eS 29504c68496SJames Smart mb = &pmb->u.mb; 296dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 297dea3101eS 298dea3101eS INIT_LIST_HEAD(&mp->list); 29976a95d75SJames Smart mb->mbxCommand = MBX_READ_TOPOLOGY; 30076a95d75SJames Smart mb->un.varReadTop.lilpBde64.tus.f.bdeSize = LPFC_ALPA_MAP_SIZE; 30176a95d75SJames Smart mb->un.varReadTop.lilpBde64.addrHigh = putPaddrHigh(mp->phys); 30276a95d75SJames Smart mb->un.varReadTop.lilpBde64.addrLow = putPaddrLow(mp->phys); 303dea3101eS 304dea3101eS /* Save address for later completion and set the owner to host so that 305dea3101eS * the FW knows this mailbox is available for processing. 306dea3101eS */ 3073e1f0718SJames Smart pmb->ctx_buf = (uint8_t *)mp; 308dea3101eS mb->mbxOwner = OWN_HOST; 30992d7f7b0SJames Smart return (0); 310dea3101eS } 311dea3101eS 312e59058c4SJames Smart /** 3133621a710SJames Smart * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention 314e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 315e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 316e59058c4SJames Smart * 317e59058c4SJames Smart * The clear link attention mailbox command is issued to clear the link event 318e59058c4SJames Smart * attention condition indicated by the Link Event bit of the Host Attention 319e59058c4SJames Smart * (HSTATT) register. The link event attention condition is cleared only if 320e59058c4SJames Smart * the event tag specified matches that of the current link event counter. 321e59058c4SJames Smart * The current event tag is read using the read link attention event mailbox 322e59058c4SJames Smart * command. 323e59058c4SJames Smart * 324e59058c4SJames Smart * This routine prepares the mailbox command for clearing HBA link attention 325e59058c4SJames Smart * information. 326e59058c4SJames Smart **/ 327dea3101eS void 328dea3101eS lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 329dea3101eS { 330dea3101eS MAILBOX_t *mb; 331dea3101eS 33204c68496SJames Smart mb = &pmb->u.mb; 333dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 334dea3101eS 335dea3101eS mb->un.varClearLA.eventTag = phba->fc_eventTag; 336dea3101eS mb->mbxCommand = MBX_CLEAR_LA; 337dea3101eS mb->mbxOwner = OWN_HOST; 338dea3101eS return; 339dea3101eS } 340dea3101eS 341e59058c4SJames Smart /** 3423621a710SJames Smart * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA 343e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 344e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 345e59058c4SJames Smart * 346e59058c4SJames Smart * The configure link mailbox command is used before the initialize link 347e59058c4SJames Smart * mailbox command to override default value and to configure link-oriented 348e59058c4SJames Smart * parameters such as DID address and various timers. Typically, this 349e59058c4SJames Smart * command would be used after an F_Port login to set the returned DID address 350e59058c4SJames Smart * and the fabric timeout values. This command is not valid before a configure 351e59058c4SJames Smart * port command has configured the HBA port. 352e59058c4SJames Smart * 353e59058c4SJames Smart * This routine prepares the mailbox command for configuring link on a HBA. 354e59058c4SJames Smart **/ 355dea3101eS void 356dea3101eS lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 357dea3101eS { 3582e0fef85SJames Smart struct lpfc_vport *vport = phba->pport; 35904c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 360dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 361dea3101eS 362dea3101eS /* NEW_FEATURE 363dea3101eS * SLI-2, Coalescing Response Feature. 364dea3101eS */ 3651d1c296fSJames Smart if (phba->cfg_cr_delay && (phba->sli_rev < LPFC_SLI_REV4)) { 366dea3101eS mb->un.varCfgLnk.cr = 1; 367dea3101eS mb->un.varCfgLnk.ci = 1; 368dea3101eS mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay; 369dea3101eS mb->un.varCfgLnk.cr_count = phba->cfg_cr_count; 370dea3101eS } 371dea3101eS 3722e0fef85SJames Smart mb->un.varCfgLnk.myId = vport->fc_myDID; 373dea3101eS mb->un.varCfgLnk.edtov = phba->fc_edtov; 374dea3101eS mb->un.varCfgLnk.arbtov = phba->fc_arbtov; 375dea3101eS mb->un.varCfgLnk.ratov = phba->fc_ratov; 376dea3101eS mb->un.varCfgLnk.rttov = phba->fc_rttov; 377dea3101eS mb->un.varCfgLnk.altov = phba->fc_altov; 378dea3101eS mb->un.varCfgLnk.crtov = phba->fc_crtov; 37944fd7fe3SJames Smart mb->un.varCfgLnk.cscn = 0; 38044fd7fe3SJames Smart if (phba->bbcredit_support && phba->cfg_enable_bbcr) { 38144fd7fe3SJames Smart mb->un.varCfgLnk.cscn = 1; 38244fd7fe3SJames Smart mb->un.varCfgLnk.bbscn = bf_get(lpfc_bbscn_def, 38344fd7fe3SJames Smart &phba->sli4_hba.bbscn_params); 38444fd7fe3SJames Smart } 385dea3101eS 3861d1c296fSJames Smart if (phba->cfg_ack0 && (phba->sli_rev < LPFC_SLI_REV4)) 387dea3101eS mb->un.varCfgLnk.ack0_enable = 1; 388dea3101eS 389dea3101eS mb->mbxCommand = MBX_CONFIG_LINK; 390dea3101eS mb->mbxOwner = OWN_HOST; 391dea3101eS return; 392dea3101eS } 393dea3101eS 394e59058c4SJames Smart /** 3953621a710SJames Smart * lpfc_config_msi - Prepare a mailbox command for configuring msi-x 3969399627fSJames Smart * @phba: pointer to lpfc hba data structure. 3979399627fSJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 3989399627fSJames Smart * 3999399627fSJames Smart * The configure MSI-X mailbox command is used to configure the HBA's SLI-3 4009399627fSJames Smart * MSI-X multi-message interrupt vector association to interrupt attention 4019399627fSJames Smart * conditions. 4029399627fSJames Smart * 4039399627fSJames Smart * Return codes 4049399627fSJames Smart * 0 - Success 4059399627fSJames Smart * -EINVAL - Failure 4069399627fSJames Smart **/ 4079399627fSJames Smart int 4089399627fSJames Smart lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 4099399627fSJames Smart { 41004c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 4119399627fSJames Smart uint32_t attentionConditions[2]; 4129399627fSJames Smart 4139399627fSJames Smart /* Sanity check */ 4149399627fSJames Smart if (phba->cfg_use_msi != 2) { 4159399627fSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4169399627fSJames Smart "0475 Not configured for supporting MSI-X " 4179399627fSJames Smart "cfg_use_msi: 0x%x\n", phba->cfg_use_msi); 4189399627fSJames Smart return -EINVAL; 4199399627fSJames Smart } 4209399627fSJames Smart 4219399627fSJames Smart if (phba->sli_rev < 3) { 4229399627fSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4239399627fSJames Smart "0476 HBA not supporting SLI-3 or later " 4249399627fSJames Smart "SLI Revision: 0x%x\n", phba->sli_rev); 4259399627fSJames Smart return -EINVAL; 4269399627fSJames Smart } 4279399627fSJames Smart 4289399627fSJames Smart /* Clear mailbox command fields */ 4299399627fSJames Smart memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 4309399627fSJames Smart 4319399627fSJames Smart /* 4329399627fSJames Smart * SLI-3, Message Signaled Interrupt Fearure. 4339399627fSJames Smart */ 4349399627fSJames Smart 4359399627fSJames Smart /* Multi-message attention configuration */ 4369399627fSJames Smart attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT | 4379399627fSJames Smart HA_LATT | HA_MBATT); 4389399627fSJames Smart attentionConditions[1] = 0; 4399399627fSJames Smart 4409399627fSJames Smart mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0]; 4419399627fSJames Smart mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1]; 4429399627fSJames Smart 4439399627fSJames Smart /* 4449399627fSJames Smart * Set up message number to HA bit association 4459399627fSJames Smart */ 4469399627fSJames Smart #ifdef __BIG_ENDIAN_BITFIELD 4479399627fSJames Smart /* RA0 (FCP Ring) */ 4489399627fSJames Smart mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1; 4499399627fSJames Smart /* RA1 (Other Protocol Extra Ring) */ 4509399627fSJames Smart mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1; 4519399627fSJames Smart #else /* __LITTLE_ENDIAN_BITFIELD */ 4529399627fSJames Smart /* RA0 (FCP Ring) */ 4539399627fSJames Smart mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1; 4549399627fSJames Smart /* RA1 (Other Protocol Extra Ring) */ 4559399627fSJames Smart mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1; 4569399627fSJames Smart #endif 4579399627fSJames Smart /* Multi-message interrupt autoclear configuration*/ 4589399627fSJames Smart mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0]; 4599399627fSJames Smart mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1]; 4609399627fSJames Smart 4619399627fSJames Smart /* For now, HBA autoclear does not work reliably, disable it */ 4629399627fSJames Smart mb->un.varCfgMSI.autoClearHA[0] = 0; 4639399627fSJames Smart mb->un.varCfgMSI.autoClearHA[1] = 0; 4649399627fSJames Smart 4659399627fSJames Smart /* Set command and owner bit */ 4669399627fSJames Smart mb->mbxCommand = MBX_CONFIG_MSI; 4679399627fSJames Smart mb->mbxOwner = OWN_HOST; 4689399627fSJames Smart 4699399627fSJames Smart return 0; 4709399627fSJames Smart } 4719399627fSJames Smart 4729399627fSJames Smart /** 4733621a710SJames Smart * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA 474e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 475e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 476e59058c4SJames Smart * @topology: the link topology for the link to be initialized to. 477e59058c4SJames Smart * @linkspeed: the link speed for the link to be initialized to. 478e59058c4SJames Smart * 479e59058c4SJames Smart * The initialize link mailbox command is used to initialize the Fibre 480e59058c4SJames Smart * Channel link. This command must follow a configure port command that 481e59058c4SJames Smart * establishes the mode of operation. 482e59058c4SJames Smart * 483e59058c4SJames Smart * This routine prepares the mailbox command for initializing link on a HBA 484e59058c4SJames Smart * with the specified link topology and speed. 485e59058c4SJames Smart **/ 486dea3101eS void 487dea3101eS lpfc_init_link(struct lpfc_hba * phba, 488dea3101eS LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed) 489dea3101eS { 490dea3101eS lpfc_vpd_t *vpd; 491dea3101eS MAILBOX_t *mb; 492dea3101eS 49304c68496SJames Smart mb = &pmb->u.mb; 494dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 495dea3101eS 496dea3101eS switch (topology) { 497dea3101eS case FLAGS_TOPOLOGY_MODE_LOOP_PT: 498dea3101eS mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; 499dea3101eS mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; 500dea3101eS break; 501dea3101eS case FLAGS_TOPOLOGY_MODE_PT_PT: 502dea3101eS mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; 503dea3101eS break; 504dea3101eS case FLAGS_TOPOLOGY_MODE_LOOP: 505dea3101eS mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; 506dea3101eS break; 507dea3101eS case FLAGS_TOPOLOGY_MODE_PT_LOOP: 508dea3101eS mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; 509dea3101eS mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; 510dea3101eS break; 511367c2713SJamie Wellnitz case FLAGS_LOCAL_LB: 512367c2713SJamie Wellnitz mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB; 513367c2713SJamie Wellnitz break; 514dea3101eS } 515dea3101eS 51676558b25SJames Smart if ((phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC || 51776558b25SJames Smart phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC) && 518d38dd52cSJames Smart mb->un.varInitLnk.link_flags & FLAGS_TOPOLOGY_MODE_LOOP) { 519d38dd52cSJames Smart mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; 520d38dd52cSJames Smart phba->cfg_topology = FLAGS_TOPOLOGY_MODE_PT_PT; 521d38dd52cSJames Smart } 522d38dd52cSJames Smart 5234b0b91d4SJames Smart /* Enable asynchronous ABTS responses from firmware */ 5244b0b91d4SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT; 5254b0b91d4SJames Smart 526dea3101eS /* NEW_FEATURE 527dea3101eS * Setting up the link speed 528dea3101eS */ 529dea3101eS vpd = &phba->vpd; 530dea3101eS if (vpd->rev.feaLevelHigh >= 0x02){ 531dea3101eS switch(linkspeed){ 53276a95d75SJames Smart case LPFC_USER_LINK_SPEED_1G: 53376a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 53476a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_1G; 535dea3101eS break; 53676a95d75SJames Smart case LPFC_USER_LINK_SPEED_2G: 53776a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 53876a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_2G; 53976a95d75SJames Smart break; 54076a95d75SJames Smart case LPFC_USER_LINK_SPEED_4G: 54176a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 54276a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_4G; 54376a95d75SJames Smart break; 54476a95d75SJames Smart case LPFC_USER_LINK_SPEED_8G: 54576a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 54676a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_8G; 54776a95d75SJames Smart break; 54876a95d75SJames Smart case LPFC_USER_LINK_SPEED_10G: 54976a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 55076a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_10G; 55176a95d75SJames Smart break; 55276a95d75SJames Smart case LPFC_USER_LINK_SPEED_16G: 55376a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 55476a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_16G; 55576a95d75SJames Smart break; 556d38dd52cSJames Smart case LPFC_USER_LINK_SPEED_32G: 557d38dd52cSJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 558d38dd52cSJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_32G; 559d38dd52cSJames Smart break; 560fbd8a6baSJames Smart case LPFC_USER_LINK_SPEED_64G: 561fbd8a6baSJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 562fbd8a6baSJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_64G; 563fbd8a6baSJames Smart break; 56476a95d75SJames Smart case LPFC_USER_LINK_SPEED_AUTO: 565dea3101eS default: 56676a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; 567dea3101eS break; 568dea3101eS } 569dea3101eS 570dea3101eS } 571dea3101eS else 572dea3101eS mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; 573dea3101eS 574dea3101eS mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK; 575dea3101eS mb->mbxOwner = OWN_HOST; 576dea3101eS mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA; 577dea3101eS return; 578dea3101eS } 579dea3101eS 580e59058c4SJames Smart /** 5813621a710SJames Smart * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters 582e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 583e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 584e59058c4SJames Smart * @vpi: virtual N_Port identifier. 585e59058c4SJames Smart * 586e59058c4SJames Smart * The read service parameter mailbox command is used to read the HBA port 587e59058c4SJames Smart * service parameters. The service parameters are read into the buffer 588e59058c4SJames Smart * specified directly by a BDE in the mailbox command. These service 589e59058c4SJames Smart * parameters may then be used to build the payload of an N_Port/F_POrt 590e59058c4SJames Smart * login request and reply (LOGI/ACC). 591e59058c4SJames Smart * 592e59058c4SJames Smart * This routine prepares the mailbox command for reading HBA port service 593e59058c4SJames Smart * parameters. The DMA memory is allocated in this function and the addresses 594e59058c4SJames Smart * are populated into the mailbox command for the HBA to DMA the service 595e59058c4SJames Smart * parameters into. 596e59058c4SJames Smart * 597e59058c4SJames Smart * Return codes 598e59058c4SJames Smart * 0 - Success 599e59058c4SJames Smart * 1 - DMA memory allocation failed 600e59058c4SJames Smart **/ 601dea3101eS int 60292d7f7b0SJames Smart lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi) 603dea3101eS { 604dea3101eS struct lpfc_dmabuf *mp; 605dea3101eS MAILBOX_t *mb; 606dea3101eS 60704c68496SJames Smart mb = &pmb->u.mb; 608dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 609dea3101eS 610dea3101eS mb->mbxOwner = OWN_HOST; 611dea3101eS 612dea3101eS /* Get a buffer to hold the HBAs Service Parameters */ 613dea3101eS 61498c9ea5cSJames Smart mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); 61598c9ea5cSJames Smart if (mp) 61698c9ea5cSJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 61798c9ea5cSJames Smart if (!mp || !mp->virt) { 618dea3101eS kfree(mp); 619dea3101eS mb->mbxCommand = MBX_READ_SPARM64; 620dea3101eS /* READ_SPARAM: no buffers */ 621e8b62011SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 622e8b62011SJames Smart "0301 READ_SPARAM: no buffers\n"); 62392d7f7b0SJames Smart return (1); 624dea3101eS } 625dea3101eS INIT_LIST_HEAD(&mp->list); 626dea3101eS mb->mbxCommand = MBX_READ_SPARM64; 627dea3101eS mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); 628dea3101eS mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys); 629dea3101eS mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys); 6306d368e53SJames Smart if (phba->sli_rev >= LPFC_SLI_REV3) 6316d368e53SJames Smart mb->un.varRdSparm.vpi = phba->vpi_ids[vpi]; 632dea3101eS 633dea3101eS /* save address for completion */ 6343e1f0718SJames Smart pmb->ctx_buf = mp; 635dea3101eS 63692d7f7b0SJames Smart return (0); 637dea3101eS } 638dea3101eS 639e59058c4SJames Smart /** 6403621a710SJames Smart * lpfc_unreg_did - Prepare a mailbox command for unregistering DID 641e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 642e59058c4SJames Smart * @vpi: virtual N_Port identifier. 643e59058c4SJames Smart * @did: remote port identifier. 644e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 645e59058c4SJames Smart * 646e59058c4SJames Smart * The unregister DID mailbox command is used to unregister an N_Port/F_Port 647e59058c4SJames Smart * login for an unknown RPI by specifying the DID of a remote port. This 648e59058c4SJames Smart * command frees an RPI context in the HBA port. This has the effect of 649e59058c4SJames Smart * performing an implicit N_Port/F_Port logout. 650e59058c4SJames Smart * 651e59058c4SJames Smart * This routine prepares the mailbox command for unregistering a remote 652e59058c4SJames Smart * N_Port/F_Port (DID) login. 653e59058c4SJames Smart **/ 654dea3101eS void 65592d7f7b0SJames Smart lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did, 65692d7f7b0SJames Smart LPFC_MBOXQ_t * pmb) 657dea3101eS { 658dea3101eS MAILBOX_t *mb; 659dea3101eS 66004c68496SJames Smart mb = &pmb->u.mb; 661dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 662dea3101eS 663dea3101eS mb->un.varUnregDID.did = did; 66492d7f7b0SJames Smart mb->un.varUnregDID.vpi = vpi; 6656d368e53SJames Smart if ((vpi != 0xffff) && 6666d368e53SJames Smart (phba->sli_rev == LPFC_SLI_REV4)) 6676d368e53SJames Smart mb->un.varUnregDID.vpi = phba->vpi_ids[vpi]; 668dea3101eS 669dea3101eS mb->mbxCommand = MBX_UNREG_D_ID; 670dea3101eS mb->mbxOwner = OWN_HOST; 671dea3101eS return; 672dea3101eS } 673dea3101eS 674e59058c4SJames Smart /** 6753621a710SJames Smart * lpfc_read_config - Prepare a mailbox command for reading HBA configuration 676e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 677e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 678e59058c4SJames Smart * 679e59058c4SJames Smart * The read configuration mailbox command is used to read the HBA port 680e59058c4SJames Smart * configuration parameters. This mailbox command provides a method for 681e59058c4SJames Smart * seeing any parameters that may have changed via various configuration 682e59058c4SJames Smart * mailbox commands. 683e59058c4SJames Smart * 684e59058c4SJames Smart * This routine prepares the mailbox command for reading out HBA configuration 685e59058c4SJames Smart * parameters. 686e59058c4SJames Smart **/ 687dea3101eS void 688dea3101eS lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 689dea3101eS { 690dea3101eS MAILBOX_t *mb; 691dea3101eS 69204c68496SJames Smart mb = &pmb->u.mb; 693dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 694dea3101eS 695dea3101eS mb->mbxCommand = MBX_READ_CONFIG; 696dea3101eS mb->mbxOwner = OWN_HOST; 697dea3101eS return; 698dea3101eS } 699dea3101eS 700e59058c4SJames Smart /** 7013621a710SJames Smart * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats 702e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 703e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 704e59058c4SJames Smart * 705e59058c4SJames Smart * The read link status mailbox command is used to read the link status from 706e59058c4SJames Smart * the HBA. Link status includes all link-related error counters. These 707e59058c4SJames Smart * counters are maintained by the HBA and originated in the link hardware 708e59058c4SJames Smart * unit. Note that all of these counters wrap. 709e59058c4SJames Smart * 710e59058c4SJames Smart * This routine prepares the mailbox command for reading out HBA link status. 711e59058c4SJames Smart **/ 7127bb3b137SJamie Wellnitz void 7137bb3b137SJamie Wellnitz lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 7147bb3b137SJamie Wellnitz { 7157bb3b137SJamie Wellnitz MAILBOX_t *mb; 7167bb3b137SJamie Wellnitz 71704c68496SJames Smart mb = &pmb->u.mb; 7187bb3b137SJamie Wellnitz memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 7197bb3b137SJamie Wellnitz 7207bb3b137SJamie Wellnitz mb->mbxCommand = MBX_READ_LNK_STAT; 7217bb3b137SJamie Wellnitz mb->mbxOwner = OWN_HOST; 7227bb3b137SJamie Wellnitz return; 7237bb3b137SJamie Wellnitz } 7247bb3b137SJamie Wellnitz 725e59058c4SJames Smart /** 72604c68496SJames Smart * lpfc_reg_rpi - Prepare a mailbox command for registering remote login 727e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 728e59058c4SJames Smart * @vpi: virtual N_Port identifier. 729e59058c4SJames Smart * @did: remote port identifier. 730e59058c4SJames Smart * @param: pointer to memory holding the server parameters. 731e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 7324042629eSJames Smart * @rpi: the rpi to use in the registration (usually only used for SLI4. 733e59058c4SJames Smart * 734e59058c4SJames Smart * The registration login mailbox command is used to register an N_Port or 735e59058c4SJames Smart * F_Port login. This registration allows the HBA to cache the remote N_Port 736e59058c4SJames Smart * service parameters internally and thereby make the appropriate FC-2 737e59058c4SJames Smart * decisions. The remote port service parameters are handed off by the driver 738e59058c4SJames Smart * to the HBA using a descriptor entry that directly identifies a buffer in 739e59058c4SJames Smart * host memory. In exchange, the HBA returns an RPI identifier. 740e59058c4SJames Smart * 741e59058c4SJames Smart * This routine prepares the mailbox command for registering remote port login. 742e59058c4SJames Smart * The function allocates DMA buffer for passing the service parameters to the 743e59058c4SJames Smart * HBA with the mailbox command. 744e59058c4SJames Smart * 745e59058c4SJames Smart * Return codes 746e59058c4SJames Smart * 0 - Success 747e59058c4SJames Smart * 1 - DMA memory allocation failed 748e59058c4SJames Smart **/ 749dea3101eS int 75004c68496SJames Smart lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did, 7514042629eSJames Smart uint8_t *param, LPFC_MBOXQ_t *pmb, uint16_t rpi) 752dea3101eS { 75304c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 754dea3101eS uint8_t *sparam; 755dea3101eS struct lpfc_dmabuf *mp; 756dea3101eS 757dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 758dea3101eS 759dea3101eS mb->un.varRegLogin.rpi = 0; 7606d368e53SJames Smart if (phba->sli_rev == LPFC_SLI_REV4) 7616d368e53SJames Smart mb->un.varRegLogin.rpi = phba->sli4_hba.rpi_ids[rpi]; 7626d368e53SJames Smart if (phba->sli_rev >= LPFC_SLI_REV3) 7636d368e53SJames Smart mb->un.varRegLogin.vpi = phba->vpi_ids[vpi]; 764dea3101eS mb->un.varRegLogin.did = did; 765dea3101eS mb->mbxOwner = OWN_HOST; 766dea3101eS /* Get a buffer to hold NPorts Service Parameters */ 76798c9ea5cSJames Smart mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); 76898c9ea5cSJames Smart if (mp) 76998c9ea5cSJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 77098c9ea5cSJames Smart if (!mp || !mp->virt) { 771dea3101eS kfree(mp); 772dea3101eS mb->mbxCommand = MBX_REG_LOGIN64; 773dea3101eS /* REG_LOGIN: no buffers */ 77492d7f7b0SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 775e8b62011SJames Smart "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, " 7764042629eSJames Smart "rpi x%x\n", vpi, did, rpi); 7776d368e53SJames Smart return 1; 778dea3101eS } 779dea3101eS INIT_LIST_HEAD(&mp->list); 780dea3101eS sparam = mp->virt; 781dea3101eS 782dea3101eS /* Copy param's into a new buffer */ 783dea3101eS memcpy(sparam, param, sizeof (struct serv_parm)); 784dea3101eS 785dea3101eS /* save address for completion */ 7863e1f0718SJames Smart pmb->ctx_buf = (uint8_t *)mp; 787dea3101eS 788dea3101eS mb->mbxCommand = MBX_REG_LOGIN64; 789dea3101eS mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); 790dea3101eS mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys); 791dea3101eS mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys); 792dea3101eS 7936d368e53SJames Smart return 0; 794dea3101eS } 795dea3101eS 796e59058c4SJames Smart /** 7973621a710SJames Smart * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login 798e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 799e59058c4SJames Smart * @vpi: virtual N_Port identifier. 800e59058c4SJames Smart * @rpi: remote port identifier 801e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 802e59058c4SJames Smart * 803e59058c4SJames Smart * The unregistration login mailbox command is used to unregister an N_Port 804e59058c4SJames Smart * or F_Port login. This command frees an RPI context in the HBA. It has the 805e59058c4SJames Smart * effect of performing an implicit N_Port/F_Port logout. 806e59058c4SJames Smart * 807e59058c4SJames Smart * This routine prepares the mailbox command for unregistering remote port 808e59058c4SJames Smart * login. 8096d368e53SJames Smart * 8106d368e53SJames Smart * For SLI4 ports, the rpi passed to this function must be the physical 8116d368e53SJames Smart * rpi value, not the logical index. 812e59058c4SJames Smart **/ 813dea3101eS void 81492d7f7b0SJames Smart lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi, 81592d7f7b0SJames Smart LPFC_MBOXQ_t * pmb) 816dea3101eS { 817dea3101eS MAILBOX_t *mb; 818dea3101eS 81904c68496SJames Smart mb = &pmb->u.mb; 820dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 821dea3101eS 8226d368e53SJames Smart mb->un.varUnregLogin.rpi = rpi; 823dea3101eS mb->un.varUnregLogin.rsvd1 = 0; 8246d368e53SJames Smart if (phba->sli_rev >= LPFC_SLI_REV3) 8256d368e53SJames Smart mb->un.varUnregLogin.vpi = phba->vpi_ids[vpi]; 826dea3101eS 827dea3101eS mb->mbxCommand = MBX_UNREG_LOGIN; 828dea3101eS mb->mbxOwner = OWN_HOST; 82904c68496SJames Smart 830dea3101eS return; 831dea3101eS } 832dea3101eS 833e59058c4SJames Smart /** 8345af5eee7SJames Smart * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA. 8355af5eee7SJames Smart * @vport: pointer to a vport object. 8365af5eee7SJames Smart * 8375af5eee7SJames Smart * This routine sends mailbox command to unregister all active RPIs for 8385af5eee7SJames Smart * a vport. 8395af5eee7SJames Smart **/ 8405af5eee7SJames Smart void 8415af5eee7SJames Smart lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport) 8425af5eee7SJames Smart { 8435af5eee7SJames Smart struct lpfc_hba *phba = vport->phba; 8445af5eee7SJames Smart LPFC_MBOXQ_t *mbox; 8455af5eee7SJames Smart int rc; 8465af5eee7SJames Smart 8475af5eee7SJames Smart mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 8485af5eee7SJames Smart if (mbox) { 8496d368e53SJames Smart /* 8506d368e53SJames Smart * For SLI4 functions, the rpi field is overloaded for 8516d368e53SJames Smart * the vport context unreg all. This routine passes 8526d368e53SJames Smart * 0 for the rpi field in lpfc_unreg_login for compatibility 8536d368e53SJames Smart * with SLI3 and then overrides the rpi field with the 8546d368e53SJames Smart * expected value for SLI4. 8556d368e53SJames Smart */ 8566d368e53SJames Smart lpfc_unreg_login(phba, vport->vpi, phba->vpi_ids[vport->vpi], 8576d368e53SJames Smart mbox); 8585af5eee7SJames Smart mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000; 8595af5eee7SJames Smart mbox->vport = vport; 8605af5eee7SJames Smart mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 8613e1f0718SJames Smart mbox->ctx_ndlp = NULL; 8625af5eee7SJames Smart rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 8635af5eee7SJames Smart if (rc == MBX_NOT_FINISHED) 8645af5eee7SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 8655af5eee7SJames Smart } 8665af5eee7SJames Smart } 8675af5eee7SJames Smart 8685af5eee7SJames Smart /** 8693621a710SJames Smart * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier 870e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 871e59058c4SJames Smart * @vpi: virtual N_Port identifier. 872e59058c4SJames Smart * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port). 873e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 874e59058c4SJames Smart * 875e59058c4SJames Smart * The registration vport identifier mailbox command is used to activate a 876e59058c4SJames Smart * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the 877e59058c4SJames Smart * N_Port_ID against the information in the selected virtual N_Port context 878e59058c4SJames Smart * block and marks it active to allow normal processing of IOCB commands and 879e59058c4SJames Smart * received unsolicited exchanges. 880e59058c4SJames Smart * 881e59058c4SJames Smart * This routine prepares the mailbox command for registering a virtual N_Port. 882e59058c4SJames Smart **/ 88392d7f7b0SJames Smart void 88404c68496SJames Smart lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb) 88592d7f7b0SJames Smart { 88604c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 88738b92ef8SJames Smart struct lpfc_hba *phba = vport->phba; 88892d7f7b0SJames Smart 88992d7f7b0SJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 89038b92ef8SJames Smart /* 89138b92ef8SJames Smart * Set the re-reg VPI bit for f/w to update the MAC address. 89238b92ef8SJames Smart */ 89338b92ef8SJames Smart if ((phba->sli_rev == LPFC_SLI_REV4) && 89438b92ef8SJames Smart !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) 89538b92ef8SJames Smart mb->un.varRegVpi.upd = 1; 8966d368e53SJames Smart 8976d368e53SJames Smart mb->un.varRegVpi.vpi = phba->vpi_ids[vport->vpi]; 89804c68496SJames Smart mb->un.varRegVpi.sid = vport->fc_myDID; 8996d368e53SJames Smart if (phba->sli_rev == LPFC_SLI_REV4) 9006d368e53SJames Smart mb->un.varRegVpi.vfi = phba->sli4_hba.vfi_ids[vport->vfi]; 9016d368e53SJames Smart else 90204c68496SJames Smart mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base; 903c868595dSJames Smart memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname, 904c868595dSJames Smart sizeof(struct lpfc_name)); 905c868595dSJames Smart mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]); 906c868595dSJames Smart mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]); 90792d7f7b0SJames Smart 90892d7f7b0SJames Smart mb->mbxCommand = MBX_REG_VPI; 90992d7f7b0SJames Smart mb->mbxOwner = OWN_HOST; 91092d7f7b0SJames Smart return; 91192d7f7b0SJames Smart 91292d7f7b0SJames Smart } 91392d7f7b0SJames Smart 914e59058c4SJames Smart /** 9153621a710SJames Smart * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id 916e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 917e59058c4SJames Smart * @vpi: virtual N_Port identifier. 918e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 919e59058c4SJames Smart * 920e59058c4SJames Smart * The unregistration vport identifier mailbox command is used to inactivate 921e59058c4SJames Smart * a virtual N_Port. The driver must have logged out and unregistered all 922e59058c4SJames Smart * remote N_Ports to abort any activity on the virtual N_Port. The HBA will 923e59058c4SJames Smart * unregisters any default RPIs associated with the specified vpi, aborting 924e59058c4SJames Smart * any active exchanges. The HBA will post the mailbox response after making 925e59058c4SJames Smart * the virtual N_Port inactive. 926e59058c4SJames Smart * 927e59058c4SJames Smart * This routine prepares the mailbox command for unregistering a virtual 928e59058c4SJames Smart * N_Port. 929e59058c4SJames Smart **/ 93092d7f7b0SJames Smart void 93192d7f7b0SJames Smart lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb) 93292d7f7b0SJames Smart { 93304c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 93492d7f7b0SJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 93592d7f7b0SJames Smart 9366d368e53SJames Smart if (phba->sli_rev == LPFC_SLI_REV3) 9376d368e53SJames Smart mb->un.varUnregVpi.vpi = phba->vpi_ids[vpi]; 9386d368e53SJames Smart else if (phba->sli_rev >= LPFC_SLI_REV4) 9396d368e53SJames Smart mb->un.varUnregVpi.sli4_vpi = phba->vpi_ids[vpi]; 94092d7f7b0SJames Smart 94192d7f7b0SJames Smart mb->mbxCommand = MBX_UNREG_VPI; 94292d7f7b0SJames Smart mb->mbxOwner = OWN_HOST; 94392d7f7b0SJames Smart return; 94492d7f7b0SJames Smart 94592d7f7b0SJames Smart } 94692d7f7b0SJames Smart 947e59058c4SJames Smart /** 9483621a710SJames Smart * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB) 949e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 950e59058c4SJames Smart * 951e59058c4SJames Smart * This routine sets up and initializes the IOCB rings in the Port Control 952e59058c4SJames Smart * Block (PCB). 953e59058c4SJames Smart **/ 954dea3101eS static void 955dea3101eS lpfc_config_pcb_setup(struct lpfc_hba * phba) 956dea3101eS { 957dea3101eS struct lpfc_sli *psli = &phba->sli; 958dea3101eS struct lpfc_sli_ring *pring; 95934b02dcdSJames Smart PCB_t *pcbp = phba->pcb; 960dea3101eS dma_addr_t pdma_addr; 961dea3101eS uint32_t offset; 9622e0fef85SJames Smart uint32_t iocbCnt = 0; 963dea3101eS int i; 964dea3101eS 965dea3101eS pcbp->maxRing = (psli->num_rings - 1); 966dea3101eS 967dea3101eS for (i = 0; i < psli->num_rings; i++) { 968895427bdSJames Smart pring = &psli->sli3_ring[i]; 9692e0fef85SJames Smart 9707e56aa25SJames Smart pring->sli.sli3.sizeCiocb = 9717e56aa25SJames Smart phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE : 972ed957684SJames Smart SLI2_IOCB_CMD_SIZE; 9737e56aa25SJames Smart pring->sli.sli3.sizeRiocb = 9747e56aa25SJames Smart phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE : 975ed957684SJames Smart SLI2_IOCB_RSP_SIZE; 976dea3101eS /* A ring MUST have both cmd and rsp entries defined to be 977dea3101eS valid */ 9787e56aa25SJames Smart if ((pring->sli.sli3.numCiocb == 0) || 9797e56aa25SJames Smart (pring->sli.sli3.numRiocb == 0)) { 980dea3101eS pcbp->rdsc[i].cmdEntries = 0; 981dea3101eS pcbp->rdsc[i].rspEntries = 0; 982dea3101eS pcbp->rdsc[i].cmdAddrHigh = 0; 983dea3101eS pcbp->rdsc[i].rspAddrHigh = 0; 984dea3101eS pcbp->rdsc[i].cmdAddrLow = 0; 985dea3101eS pcbp->rdsc[i].rspAddrLow = 0; 9867e56aa25SJames Smart pring->sli.sli3.cmdringaddr = NULL; 9877e56aa25SJames Smart pring->sli.sli3.rspringaddr = NULL; 988dea3101eS continue; 989dea3101eS } 990dea3101eS /* Command ring setup for ring */ 9917e56aa25SJames Smart pring->sli.sli3.cmdringaddr = (void *)&phba->IOCBs[iocbCnt]; 9927e56aa25SJames Smart pcbp->rdsc[i].cmdEntries = pring->sli.sli3.numCiocb; 993dea3101eS 99434b02dcdSJames Smart offset = (uint8_t *) &phba->IOCBs[iocbCnt] - 99534b02dcdSJames Smart (uint8_t *) phba->slim2p.virt; 99634b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 997dea3101eS pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr); 998dea3101eS pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr); 9997e56aa25SJames Smart iocbCnt += pring->sli.sli3.numCiocb; 1000dea3101eS 1001dea3101eS /* Response ring setup for ring */ 10027e56aa25SJames Smart pring->sli.sli3.rspringaddr = (void *) &phba->IOCBs[iocbCnt]; 1003dea3101eS 10047e56aa25SJames Smart pcbp->rdsc[i].rspEntries = pring->sli.sli3.numRiocb; 100534b02dcdSJames Smart offset = (uint8_t *)&phba->IOCBs[iocbCnt] - 100634b02dcdSJames Smart (uint8_t *)phba->slim2p.virt; 100734b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 1008dea3101eS pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr); 1009dea3101eS pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr); 10107e56aa25SJames Smart iocbCnt += pring->sli.sli3.numRiocb; 1011dea3101eS } 1012dea3101eS } 1013dea3101eS 1014e59058c4SJames Smart /** 10153621a710SJames Smart * lpfc_read_rev - Prepare a mailbox command for reading HBA revision 1016e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1017e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1018e59058c4SJames Smart * 1019e59058c4SJames Smart * The read revision mailbox command is used to read the revision levels of 1020e59058c4SJames Smart * the HBA components. These components include hardware units, resident 1021e59058c4SJames Smart * firmware, and available firmware. HBAs that supports SLI-3 mode of 1022e59058c4SJames Smart * operation provide different response information depending on the version 1023e59058c4SJames Smart * requested by the driver. 1024e59058c4SJames Smart * 1025e59058c4SJames Smart * This routine prepares the mailbox command for reading HBA revision 1026e59058c4SJames Smart * information. 1027e59058c4SJames Smart **/ 1028dea3101eS void 1029dea3101eS lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 1030dea3101eS { 103104c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1032dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 1033dea3101eS mb->un.varRdRev.cv = 1; 1034ed957684SJames Smart mb->un.varRdRev.v3req = 1; /* Request SLI3 info */ 1035dea3101eS mb->mbxCommand = MBX_READ_REV; 1036dea3101eS mb->mbxOwner = OWN_HOST; 1037dea3101eS return; 1038dea3101eS } 1039dea3101eS 1040d7c47992SJames Smart void 1041d7c47992SJames Smart lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 1042d7c47992SJames Smart { 1043d7c47992SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1044d7c47992SJames Smart struct lpfc_mqe *mqe; 1045d7c47992SJames Smart 1046d7c47992SJames Smart switch (mb->mbxCommand) { 1047d7c47992SJames Smart case MBX_READ_REV: 1048d7c47992SJames Smart mqe = &pmb->u.mqe; 1049d7c47992SJames Smart lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name, 1050d7c47992SJames Smart mqe->un.read_rev.fw_name, 16); 1051d7c47992SJames Smart lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name, 1052d7c47992SJames Smart mqe->un.read_rev.ulp_fw_name, 16); 1053d7c47992SJames Smart break; 1054d7c47992SJames Smart default: 1055d7c47992SJames Smart break; 1056d7c47992SJames Smart } 1057d7c47992SJames Smart return; 1058d7c47992SJames Smart } 1059d7c47992SJames Smart 1060e59058c4SJames Smart /** 10613621a710SJames Smart * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2 1062e59058c4SJames Smart * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. 1063e59058c4SJames Smart * @hbq_desc: pointer to the HBQ selection profile descriptor. 1064e59058c4SJames Smart * 1065e59058c4SJames Smart * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA 1066e59058c4SJames Smart * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs 1067e59058c4SJames Smart * the Sequence Length Test using the fields in the Selection Profile 2 1068e59058c4SJames Smart * extension in words 20:31. 1069e59058c4SJames Smart **/ 1070ed957684SJames Smart static void 1071ed957684SJames Smart lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb, 1072ed957684SJames Smart struct lpfc_hbq_init *hbq_desc) 1073ed957684SJames Smart { 1074ed957684SJames Smart hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt; 1075ed957684SJames Smart hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen; 1076ed957684SJames Smart hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff; 1077ed957684SJames Smart } 1078ed957684SJames Smart 1079e59058c4SJames Smart /** 10803621a710SJames Smart * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3 1081e59058c4SJames Smart * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. 1082e59058c4SJames Smart * @hbq_desc: pointer to the HBQ selection profile descriptor. 1083e59058c4SJames Smart * 1084e59058c4SJames Smart * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA 1085e59058c4SJames Smart * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs 1086e59058c4SJames Smart * the Sequence Length Test and Byte Field Test using the fields in the 1087e59058c4SJames Smart * Selection Profile 3 extension in words 20:31. 1088e59058c4SJames Smart **/ 1089ed957684SJames Smart static void 1090ed957684SJames Smart lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb, 1091ed957684SJames Smart struct lpfc_hbq_init *hbq_desc) 1092ed957684SJames Smart { 1093ed957684SJames Smart hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt; 1094ed957684SJames Smart hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen; 1095ed957684SJames Smart hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff; 1096ed957684SJames Smart hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff; 1097ed957684SJames Smart memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch, 1098ed957684SJames Smart sizeof(hbqmb->profiles.profile3.cmdmatch)); 1099ed957684SJames Smart } 1100ed957684SJames Smart 1101e59058c4SJames Smart /** 11023621a710SJames Smart * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5 1103e59058c4SJames Smart * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. 1104e59058c4SJames Smart * @hbq_desc: pointer to the HBQ selection profile descriptor. 1105e59058c4SJames Smart * 1106e59058c4SJames Smart * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The 1107e59058c4SJames Smart * HBA tests the initial frame of an incoming sequence using the frame's 1108e59058c4SJames Smart * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test 1109e59058c4SJames Smart * and Byte Field Test using the fields in the Selection Profile 5 extension 1110e59058c4SJames Smart * words 20:31. 1111e59058c4SJames Smart **/ 1112ed957684SJames Smart static void 1113ed957684SJames Smart lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb, 1114ed957684SJames Smart struct lpfc_hbq_init *hbq_desc) 1115ed957684SJames Smart { 1116ed957684SJames Smart hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt; 1117ed957684SJames Smart hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen; 1118ed957684SJames Smart hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff; 1119ed957684SJames Smart hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff; 1120ed957684SJames Smart memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch, 1121ed957684SJames Smart sizeof(hbqmb->profiles.profile5.cmdmatch)); 1122ed957684SJames Smart } 1123ed957684SJames Smart 1124e59058c4SJames Smart /** 11253621a710SJames Smart * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ 1126e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1127e59058c4SJames Smart * @id: HBQ identifier. 1128e59058c4SJames Smart * @hbq_desc: pointer to the HBA descriptor data structure. 1129e59058c4SJames Smart * @hbq_entry_index: index of the HBQ entry data structures. 1130e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1131e59058c4SJames Smart * 1132e59058c4SJames Smart * The configure HBQ (Host Buffer Queue) mailbox command is used to configure 1133e59058c4SJames Smart * an HBQ. The configuration binds events that require buffers to a particular 1134e59058c4SJames Smart * ring and HBQ based on a selection profile. 1135e59058c4SJames Smart * 1136e59058c4SJames Smart * This routine prepares the mailbox command for configuring an HBQ. 1137e59058c4SJames Smart **/ 1138ed957684SJames Smart void 113951ef4c26SJames Smart lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id, 114051ef4c26SJames Smart struct lpfc_hbq_init *hbq_desc, 1141ed957684SJames Smart uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb) 1142ed957684SJames Smart { 1143ed957684SJames Smart int i; 114404c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1145ed957684SJames Smart struct config_hbq_var *hbqmb = &mb->un.varCfgHbq; 1146ed957684SJames Smart 1147ed957684SJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 114851ef4c26SJames Smart hbqmb->hbqId = id; 1149ed957684SJames Smart hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */ 1150ed957684SJames Smart hbqmb->recvNotify = hbq_desc->rn; /* Receive 1151ed957684SJames Smart * Notification */ 1152ed957684SJames Smart hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks 1153ed957684SJames Smart * # in words 0-19 */ 1154ed957684SJames Smart hbqmb->profile = hbq_desc->profile; /* Selection profile: 1155ed957684SJames Smart * 0 = all, 1156ed957684SJames Smart * 7 = logentry */ 1157ed957684SJames Smart hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring 1158ed957684SJames Smart * e.g. Ring0=b0001, 1159ed957684SJames Smart * ring2=b0100 */ 1160ed957684SJames Smart hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4 1161ed957684SJames Smart * or 5 */ 1162ed957684SJames Smart hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this 1163ed957684SJames Smart * HBQ will be used 1164ed957684SJames Smart * for LogEntry 1165ed957684SJames Smart * buffers */ 1166ed957684SJames Smart hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) + 1167ed957684SJames Smart hbq_entry_index * sizeof(struct lpfc_hbq_entry); 1168ed957684SJames Smart hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys); 1169ed957684SJames Smart 1170ed957684SJames Smart mb->mbxCommand = MBX_CONFIG_HBQ; 1171ed957684SJames Smart mb->mbxOwner = OWN_HOST; 1172ed957684SJames Smart 1173ed957684SJames Smart /* Copy info for profiles 2,3,5. Other 1174ed957684SJames Smart * profiles this area is reserved 1175ed957684SJames Smart */ 1176ed957684SJames Smart if (hbq_desc->profile == 2) 1177ed957684SJames Smart lpfc_build_hbq_profile2(hbqmb, hbq_desc); 1178ed957684SJames Smart else if (hbq_desc->profile == 3) 1179ed957684SJames Smart lpfc_build_hbq_profile3(hbqmb, hbq_desc); 1180ed957684SJames Smart else if (hbq_desc->profile == 5) 1181ed957684SJames Smart lpfc_build_hbq_profile5(hbqmb, hbq_desc); 1182ed957684SJames Smart 1183ed957684SJames Smart /* Return if no rctl / type masks for this HBQ */ 1184ed957684SJames Smart if (!hbq_desc->mask_count) 1185ed957684SJames Smart return; 1186ed957684SJames Smart 1187ed957684SJames Smart /* Otherwise we setup specific rctl / type masks for this HBQ */ 1188ed957684SJames Smart for (i = 0; i < hbq_desc->mask_count; i++) { 1189ed957684SJames Smart hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch; 1190ed957684SJames Smart hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask; 1191ed957684SJames Smart hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch; 1192ed957684SJames Smart hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask; 1193ed957684SJames Smart } 1194ed957684SJames Smart 1195ed957684SJames Smart return; 1196ed957684SJames Smart } 1197ed957684SJames Smart 1198e59058c4SJames Smart /** 11993621a710SJames Smart * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring 1200e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1201e59058c4SJames Smart * @ring: 1202e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1203e59058c4SJames Smart * 1204e59058c4SJames Smart * The configure ring mailbox command is used to configure an IOCB ring. This 1205e59058c4SJames Smart * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the 1206e59058c4SJames Smart * ring. This is used to map incoming sequences to a particular ring whose 1207e59058c4SJames Smart * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not 1208e59058c4SJames Smart * attempt to configure a ring whose number is greater than the number 1209e59058c4SJames Smart * specified in the Port Control Block (PCB). It is an error to issue the 1210e59058c4SJames Smart * configure ring command more than once with the same ring number. The HBA 1211e59058c4SJames Smart * returns an error if the driver attempts this. 1212e59058c4SJames Smart * 1213e59058c4SJames Smart * This routine prepares the mailbox command for configuring IOCB ring. 1214e59058c4SJames Smart **/ 1215dea3101eS void 1216dea3101eS lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb) 1217dea3101eS { 1218dea3101eS int i; 121904c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1220dea3101eS struct lpfc_sli *psli; 1221dea3101eS struct lpfc_sli_ring *pring; 1222dea3101eS 1223dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 1224dea3101eS 1225dea3101eS mb->un.varCfgRing.ring = ring; 1226dea3101eS mb->un.varCfgRing.maxOrigXchg = 0; 1227dea3101eS mb->un.varCfgRing.maxRespXchg = 0; 1228dea3101eS mb->un.varCfgRing.recvNotify = 1; 1229dea3101eS 1230dea3101eS psli = &phba->sli; 1231895427bdSJames Smart pring = &psli->sli3_ring[ring]; 1232dea3101eS mb->un.varCfgRing.numMask = pring->num_mask; 1233dea3101eS mb->mbxCommand = MBX_CONFIG_RING; 1234dea3101eS mb->mbxOwner = OWN_HOST; 1235dea3101eS 1236dea3101eS /* Is this ring configured for a specific profile */ 1237dea3101eS if (pring->prt[0].profile) { 1238dea3101eS mb->un.varCfgRing.profile = pring->prt[0].profile; 1239dea3101eS return; 1240dea3101eS } 1241dea3101eS 1242dea3101eS /* Otherwise we setup specific rctl / type masks for this ring */ 1243dea3101eS for (i = 0; i < pring->num_mask; i++) { 1244dea3101eS mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl; 12456a9c52cfSJames Smart if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ) 1246dea3101eS mb->un.varCfgRing.rrRegs[i].rmask = 0xff; 1247dea3101eS else 1248dea3101eS mb->un.varCfgRing.rrRegs[i].rmask = 0xfe; 1249dea3101eS mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type; 1250dea3101eS mb->un.varCfgRing.rrRegs[i].tmask = 0xff; 1251dea3101eS } 1252dea3101eS 1253dea3101eS return; 1254dea3101eS } 1255dea3101eS 1256e59058c4SJames Smart /** 12573621a710SJames Smart * lpfc_config_port - Prepare a mailbox command for configuring port 1258e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1259e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1260e59058c4SJames Smart * 1261e59058c4SJames Smart * The configure port mailbox command is used to identify the Port Control 1262e59058c4SJames Smart * Block (PCB) in the driver memory. After this command is issued, the 1263e59058c4SJames Smart * driver must not access the mailbox in the HBA without first resetting 1264e59058c4SJames Smart * the HBA. The HBA may copy the PCB information to internal storage for 1265e59058c4SJames Smart * subsequent use; the driver can not change the PCB information unless it 1266e59058c4SJames Smart * resets the HBA. 1267e59058c4SJames Smart * 1268e59058c4SJames Smart * This routine prepares the mailbox command for configuring port. 1269e59058c4SJames Smart **/ 1270dea3101eS void 1271dea3101eS lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 1272dea3101eS { 1273ed957684SJames Smart MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr; 127404c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1275dea3101eS dma_addr_t pdma_addr; 1276dea3101eS uint32_t bar_low, bar_high; 1277dea3101eS size_t offset; 12784cc2da1dSJames.Smart@Emulex.Com struct lpfc_hgp hgp; 1279f91b392cSJames.Smart@Emulex.Com int i; 1280ed957684SJames Smart uint32_t pgp_offset; 1281dea3101eS 1282dea3101eS memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 1283dea3101eS mb->mbxCommand = MBX_CONFIG_PORT; 1284dea3101eS mb->mbxOwner = OWN_HOST; 1285dea3101eS 1286dea3101eS mb->un.varCfgPort.pcbLen = sizeof(PCB_t); 1287dea3101eS 128834b02dcdSJames Smart offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt; 128934b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 1290dea3101eS mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr); 1291dea3101eS mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr); 1292dea3101eS 129397207482SJames Smart /* Always Host Group Pointer is in SLIM */ 129497207482SJames Smart mb->un.varCfgPort.hps = 1; 129597207482SJames Smart 1296ed957684SJames Smart /* If HBA supports SLI=3 ask for it */ 1297ed957684SJames Smart 129804c68496SJames Smart if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) { 1299e2a0a9d6SJames Smart if (phba->cfg_enable_bg) 1300e2a0a9d6SJames Smart mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */ 1301ab56dc2eSJames Smart if (phba->cfg_enable_dss) 130204c68496SJames Smart mb->un.varCfgPort.cdss = 1; /* Configure Security */ 1303ed957684SJames Smart mb->un.varCfgPort.cerbm = 1; /* Request HBQs */ 130434b02dcdSJames Smart mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */ 130551ef4c26SJames Smart mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count(); 130678b2d852SJames Smart if (phba->max_vpi && phba->cfg_enable_npiv && 130792d7f7b0SJames Smart phba->vpd.sli3Feat.cmv) { 130804c68496SJames Smart mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI; 130992d7f7b0SJames Smart mb->un.varCfgPort.cmv = 1; 131092d7f7b0SJames Smart } else 131192d7f7b0SJames Smart mb->un.varCfgPort.max_vpi = phba->max_vpi = 0; 131292d7f7b0SJames Smart } else 131304c68496SJames Smart phba->sli_rev = LPFC_SLI_REV2; 131492d7f7b0SJames Smart mb->un.varCfgPort.sli_mode = phba->sli_rev; 1315ed957684SJames Smart 1316cb69f7deSJames Smart /* If this is an SLI3 port, configure async status notification. */ 1317cb69f7deSJames Smart if (phba->sli_rev == LPFC_SLI_REV3) 1318cb69f7deSJames Smart mb->un.varCfgPort.casabt = 1; 1319cb69f7deSJames Smart 1320dea3101eS /* Now setup pcb */ 132134b02dcdSJames Smart phba->pcb->type = TYPE_NATIVE_SLI2; 132234b02dcdSJames Smart phba->pcb->feature = FEATURE_INITIAL_SLI2; 1323dea3101eS 1324dea3101eS /* Setup Mailbox pointers */ 13257a470277SJames Smart phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE; 132634b02dcdSJames Smart offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt; 132734b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 132834b02dcdSJames Smart phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr); 132934b02dcdSJames Smart phba->pcb->mbAddrLow = putPaddrLow(pdma_addr); 1330dea3101eS 1331dea3101eS /* 1332dea3101eS * Setup Host Group ring pointer. 1333dea3101eS * 1334dea3101eS * For efficiency reasons, the ring get/put pointers can be 1335dea3101eS * placed in adapter memory (SLIM) rather than in host memory. 1336dea3101eS * This allows firmware to avoid PCI reads/writes when updating 1337dea3101eS * and checking pointers. 1338dea3101eS * 1339dea3101eS * The firmware recognizes the use of SLIM memory by comparing 1340dea3101eS * the address of the get/put pointers structure with that of 1341dea3101eS * the SLIM BAR (BAR0). 1342dea3101eS * 1343dea3101eS * Caution: be sure to use the PCI config space value of BAR0/BAR1 1344dea3101eS * (the hardware's view of the base address), not the OS's 1345dea3101eS * value of pci_resource_start() as the OS value may be a cookie 1346dea3101eS * for ioremap/iomap. 1347dea3101eS */ 1348dea3101eS 1349dea3101eS 1350dea3101eS pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low); 1351dea3101eS pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high); 1352dea3101eS 1353ed957684SJames Smart /* 1354ed957684SJames Smart * Set up HGP - Port Memory 1355ed957684SJames Smart * 1356ed957684SJames Smart * The port expects the host get/put pointers to reside in memory 1357ed957684SJames Smart * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes) 1358ed957684SJames Smart * area of SLIM. In SLI-2 mode, there's an additional 16 reserved 1359ed957684SJames Smart * words (0x40 bytes). This area is not reserved if HBQs are 1360ed957684SJames Smart * configured in SLI-3. 1361ed957684SJames Smart * 1362ed957684SJames Smart * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80 1363ed957684SJames Smart * RR0Get 0xc4 0x84 1364ed957684SJames Smart * CR1Put 0xc8 0x88 1365ed957684SJames Smart * RR1Get 0xcc 0x8c 1366ed957684SJames Smart * CR2Put 0xd0 0x90 1367ed957684SJames Smart * RR2Get 0xd4 0x94 1368ed957684SJames Smart * CR3Put 0xd8 0x98 1369ed957684SJames Smart * RR3Get 0xdc 0x9c 1370ed957684SJames Smart * 1371ed957684SJames Smart * Reserved 0xa0-0xbf 1372ed957684SJames Smart * If HBQs configured: 1373ed957684SJames Smart * HBQ 0 Put ptr 0xc0 1374ed957684SJames Smart * HBQ 1 Put ptr 0xc4 1375ed957684SJames Smart * HBQ 2 Put ptr 0xc8 1376ed957684SJames Smart * ...... 1377ed957684SJames Smart * HBQ(M-1)Put Pointer 0xc0+(M-1)*4 1378ed957684SJames Smart * 1379ed957684SJames Smart */ 1380ed957684SJames Smart 13817a470277SJames Smart if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) { 13827a470277SJames Smart phba->host_gp = &phba->mbox->us.s2.host[0]; 13837a470277SJames Smart phba->hbq_put = NULL; 13847a470277SJames Smart offset = (uint8_t *)&phba->mbox->us.s2.host - 13857a470277SJames Smart (uint8_t *)phba->slim2p.virt; 13867a470277SJames Smart pdma_addr = phba->slim2p.phys + offset; 13877a470277SJames Smart phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr); 13887a470277SJames Smart phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr); 13897a470277SJames Smart } else { 13907a470277SJames Smart /* Always Host Group Pointer is in SLIM */ 13917a470277SJames Smart mb->un.varCfgPort.hps = 1; 13927a470277SJames Smart 1393ed957684SJames Smart if (phba->sli_rev == 3) { 1394ed957684SJames Smart phba->host_gp = &mb_slim->us.s3.host[0]; 1395ed957684SJames Smart phba->hbq_put = &mb_slim->us.s3.hbq_put[0]; 1396ed957684SJames Smart } else { 1397ed957684SJames Smart phba->host_gp = &mb_slim->us.s2.host[0]; 1398ed957684SJames Smart phba->hbq_put = NULL; 1399ed957684SJames Smart } 1400dea3101eS 1401dea3101eS /* mask off BAR0's flag bits 0 - 3 */ 140234b02dcdSJames Smart phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) + 1403ed957684SJames Smart (void __iomem *)phba->host_gp - 1404ed957684SJames Smart (void __iomem *)phba->MBslimaddr; 1405dea3101eS if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64) 140634b02dcdSJames Smart phba->pcb->hgpAddrHigh = bar_high; 1407dea3101eS else 140834b02dcdSJames Smart phba->pcb->hgpAddrHigh = 0; 1409dea3101eS /* write HGP data to SLIM at the required longword offset */ 14104cc2da1dSJames.Smart@Emulex.Com memset(&hgp, 0, sizeof(struct lpfc_hgp)); 1411f91b392cSJames.Smart@Emulex.Com 1412f91b392cSJames.Smart@Emulex.Com for (i = 0; i < phba->sli.num_rings; i++) { 1413ed957684SJames Smart lpfc_memcpy_to_slim(phba->host_gp + i, &hgp, 1414ed957684SJames Smart sizeof(*phba->host_gp)); 1415f91b392cSJames.Smart@Emulex.Com } 14167a470277SJames Smart } 1417dea3101eS 14188f34f4ceSJames Smart /* Setup Port Group offset */ 14198f34f4ceSJames Smart if (phba->sli_rev == 3) 142034b02dcdSJames Smart pgp_offset = offsetof(struct lpfc_sli2_slim, 142134b02dcdSJames Smart mbx.us.s3_pgp.port); 14228f34f4ceSJames Smart else 142334b02dcdSJames Smart pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port); 142434b02dcdSJames Smart pdma_addr = phba->slim2p.phys + pgp_offset; 142534b02dcdSJames Smart phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr); 142634b02dcdSJames Smart phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr); 1427dea3101eS 1428dea3101eS /* Use callback routine to setp rings in the pcb */ 1429dea3101eS lpfc_config_pcb_setup(phba); 1430dea3101eS 1431dea3101eS /* special handling for LC HBAs */ 1432dea3101eS if (lpfc_is_LC_HBA(phba->pcidev->device)) { 1433dea3101eS uint32_t hbainit[5]; 1434dea3101eS 1435dea3101eS lpfc_hba_init(phba, hbainit); 1436dea3101eS 1437dea3101eS memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20); 1438dea3101eS } 1439dea3101eS 1440dea3101eS /* Swap PCB if needed */ 144134b02dcdSJames Smart lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t)); 1442dea3101eS } 1443dea3101eS 1444e59058c4SJames Smart /** 14453621a710SJames Smart * lpfc_kill_board - Prepare a mailbox command for killing board 1446e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1447e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1448e59058c4SJames Smart * 1449e59058c4SJames Smart * The kill board mailbox command is used to tell firmware to perform a 1450e59058c4SJames Smart * graceful shutdown of a channel on a specified board to prepare for reset. 1451e59058c4SJames Smart * When the kill board mailbox command is received, the ER3 bit is set to 1 1452e59058c4SJames Smart * in the Host Status register and the ER Attention bit is set to 1 in the 1453e59058c4SJames Smart * Host Attention register of the HBA function that received the kill board 1454e59058c4SJames Smart * command. 1455e59058c4SJames Smart * 1456e59058c4SJames Smart * This routine prepares the mailbox command for killing the board in 1457e59058c4SJames Smart * preparation for a graceful shutdown. 1458e59058c4SJames Smart **/ 1459dea3101eS void 146041415862SJamie Wellnitz lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 146141415862SJamie Wellnitz { 146204c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 146341415862SJamie Wellnitz 146441415862SJamie Wellnitz memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 146541415862SJamie Wellnitz mb->mbxCommand = MBX_KILL_BOARD; 146641415862SJamie Wellnitz mb->mbxOwner = OWN_HOST; 146741415862SJamie Wellnitz return; 146841415862SJamie Wellnitz } 146941415862SJamie Wellnitz 1470e59058c4SJames Smart /** 14713621a710SJames Smart * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue 1472e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1473e59058c4SJames Smart * @mbq: pointer to the driver internal queue element for mailbox command. 1474e59058c4SJames Smart * 1475e59058c4SJames Smart * Driver maintains a internal mailbox command queue implemented as a linked 1476e59058c4SJames Smart * list. When a mailbox command is issued, it shall be put into the mailbox 1477e59058c4SJames Smart * command queue such that they shall be processed orderly as HBA can process 1478e59058c4SJames Smart * one mailbox command at a time. 1479e59058c4SJames Smart **/ 148041415862SJamie Wellnitz void 1481dea3101eS lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) 1482dea3101eS { 1483dea3101eS struct lpfc_sli *psli; 1484dea3101eS 1485dea3101eS psli = &phba->sli; 1486dea3101eS 1487dea3101eS list_add_tail(&mbq->list, &psli->mboxq); 1488dea3101eS 1489dea3101eS psli->mboxq_cnt++; 1490dea3101eS 1491dea3101eS return; 1492dea3101eS } 1493dea3101eS 1494e59058c4SJames Smart /** 14953621a710SJames Smart * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue 1496e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1497e59058c4SJames Smart * 1498e59058c4SJames Smart * Driver maintains a internal mailbox command queue implemented as a linked 1499e59058c4SJames Smart * list. When a mailbox command is issued, it shall be put into the mailbox 1500e59058c4SJames Smart * command queue such that they shall be processed orderly as HBA can process 1501e59058c4SJames Smart * one mailbox command at a time. After HBA finished processing a mailbox 1502e59058c4SJames Smart * command, the driver will remove a pending mailbox command from the head of 1503e59058c4SJames Smart * the mailbox command queue and send to the HBA for processing. 1504e59058c4SJames Smart * 1505e59058c4SJames Smart * Return codes 1506e59058c4SJames Smart * pointer to the driver internal queue element for mailbox command. 1507e59058c4SJames Smart **/ 1508dea3101eS LPFC_MBOXQ_t * 1509dea3101eS lpfc_mbox_get(struct lpfc_hba * phba) 1510dea3101eS { 1511dea3101eS LPFC_MBOXQ_t *mbq = NULL; 1512dea3101eS struct lpfc_sli *psli = &phba->sli; 1513dea3101eS 15142e0fef85SJames Smart list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list); 151592d7f7b0SJames Smart if (mbq) 1516dea3101eS psli->mboxq_cnt--; 1517dea3101eS 1518dea3101eS return mbq; 1519dea3101eS } 1520a309a6b6SJames Smart 1521e59058c4SJames Smart /** 152204c68496SJames Smart * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list 152304c68496SJames Smart * @phba: pointer to lpfc hba data structure. 152404c68496SJames Smart * @mbq: pointer to the driver internal queue element for mailbox command. 152504c68496SJames Smart * 152604c68496SJames Smart * This routine put the completed mailbox command into the mailbox command 152704c68496SJames Smart * complete list. This is the unlocked version of the routine. The mailbox 152804c68496SJames Smart * complete list is used by the driver worker thread to process mailbox 152904c68496SJames Smart * complete callback functions outside the driver interrupt handler. 153004c68496SJames Smart **/ 153104c68496SJames Smart void 153204c68496SJames Smart __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) 153304c68496SJames Smart { 153404c68496SJames Smart list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl); 153504c68496SJames Smart } 153604c68496SJames Smart 153704c68496SJames Smart /** 15383621a710SJames Smart * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list 1539e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1540e59058c4SJames Smart * @mbq: pointer to the driver internal queue element for mailbox command. 1541e59058c4SJames Smart * 1542e59058c4SJames Smart * This routine put the completed mailbox command into the mailbox command 154304c68496SJames Smart * complete list. This is the locked version of the routine. The mailbox 154404c68496SJames Smart * complete list is used by the driver worker thread to process mailbox 154504c68496SJames Smart * complete callback functions outside the driver interrupt handler. 1546e59058c4SJames Smart **/ 154792d7f7b0SJames Smart void 154892d7f7b0SJames Smart lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) 154992d7f7b0SJames Smart { 15505b75da2fSJames Smart unsigned long iflag; 15515b75da2fSJames Smart 1552b1c11812SJoe Perches /* This function expects to be called from interrupt context */ 15535b75da2fSJames Smart spin_lock_irqsave(&phba->hbalock, iflag); 155404c68496SJames Smart __lpfc_mbox_cmpl_put(phba, mbq); 15555b75da2fSJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 155692d7f7b0SJames Smart return; 155792d7f7b0SJames Smart } 155892d7f7b0SJames Smart 1559e59058c4SJames Smart /** 156004c68496SJames Smart * lpfc_mbox_cmd_check - Check the validality of a mailbox command 156104c68496SJames Smart * @phba: pointer to lpfc hba data structure. 156204c68496SJames Smart * @mboxq: pointer to the driver internal queue element for mailbox command. 156304c68496SJames Smart * 156404c68496SJames Smart * This routine is to check whether a mailbox command is valid to be issued. 156504c68496SJames Smart * This check will be performed by both the mailbox issue API when a client 156604c68496SJames Smart * is to issue a mailbox command to the mailbox transport. 156704c68496SJames Smart * 156804c68496SJames Smart * Return 0 - pass the check, -ENODEV - fail the check 156904c68496SJames Smart **/ 157004c68496SJames Smart int 157104c68496SJames Smart lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) 157204c68496SJames Smart { 157304c68496SJames Smart /* Mailbox command that have a completion handler must also have a 157404c68496SJames Smart * vport specified. 157504c68496SJames Smart */ 157604c68496SJames Smart if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl && 157704c68496SJames Smart mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) { 157804c68496SJames Smart if (!mboxq->vport) { 157904c68496SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT, 158004c68496SJames Smart "1814 Mbox x%x failed, no vport\n", 158104c68496SJames Smart mboxq->u.mb.mbxCommand); 158204c68496SJames Smart dump_stack(); 158304c68496SJames Smart return -ENODEV; 158404c68496SJames Smart } 158504c68496SJames Smart } 158604c68496SJames Smart return 0; 158704c68496SJames Smart } 158804c68496SJames Smart 158904c68496SJames Smart /** 159004c68496SJames Smart * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command 159104c68496SJames Smart * @phba: pointer to lpfc hba data structure. 159204c68496SJames Smart * 159304c68496SJames Smart * This routine is to check whether the HBA device is ready for posting a 159404c68496SJames Smart * mailbox command. It is used by the mailbox transport API at the time the 159504c68496SJames Smart * to post a mailbox command to the device. 159604c68496SJames Smart * 159704c68496SJames Smart * Return 0 - pass the check, -ENODEV - fail the check 159804c68496SJames Smart **/ 159904c68496SJames Smart int 160004c68496SJames Smart lpfc_mbox_dev_check(struct lpfc_hba *phba) 160104c68496SJames Smart { 160204c68496SJames Smart /* If the PCI channel is in offline state, do not issue mbox */ 160304c68496SJames Smart if (unlikely(pci_channel_offline(phba->pcidev))) 160404c68496SJames Smart return -ENODEV; 160504c68496SJames Smart 160604c68496SJames Smart /* If the HBA is in error state, do not issue mbox */ 160704c68496SJames Smart if (phba->link_state == LPFC_HBA_ERROR) 160804c68496SJames Smart return -ENODEV; 160904c68496SJames Smart 161004c68496SJames Smart return 0; 161104c68496SJames Smart } 161204c68496SJames Smart 161304c68496SJames Smart /** 16143621a710SJames Smart * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value 1615e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1616e59058c4SJames Smart * @cmd: mailbox command code. 1617e59058c4SJames Smart * 1618e59058c4SJames Smart * This routine retrieves the proper timeout value according to the mailbox 1619e59058c4SJames Smart * command code. 1620e59058c4SJames Smart * 1621e59058c4SJames Smart * Return codes 1622e59058c4SJames Smart * Timeout value to be used for the given mailbox command 1623e59058c4SJames Smart **/ 1624a309a6b6SJames Smart int 1625a183a15fSJames Smart lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) 1626a309a6b6SJames Smart { 1627a183a15fSJames Smart MAILBOX_t *mbox = &mboxq->u.mb; 1628a183a15fSJames Smart uint8_t subsys, opcode; 1629a183a15fSJames Smart 1630a183a15fSJames Smart switch (mbox->mbxCommand) { 1631a309a6b6SJames Smart case MBX_WRITE_NV: /* 0x03 */ 1632940eb687SJames Smart case MBX_DUMP_MEMORY: /* 0x17 */ 1633a309a6b6SJames Smart case MBX_UPDATE_CFG: /* 0x1B */ 1634a309a6b6SJames Smart case MBX_DOWN_LOAD: /* 0x1C */ 1635a309a6b6SJames Smart case MBX_DEL_LD_ENTRY: /* 0x1D */ 1636940eb687SJames Smart case MBX_WRITE_VPARMS: /* 0x32 */ 1637a309a6b6SJames Smart case MBX_LOAD_AREA: /* 0x81 */ 163809372820SJames Smart case MBX_WRITE_WWN: /* 0x98 */ 1639a309a6b6SJames Smart case MBX_LOAD_EXP_ROM: /* 0x9C */ 1640940eb687SJames Smart case MBX_ACCESS_VDATA: /* 0xA5 */ 1641a309a6b6SJames Smart return LPFC_MBOX_TMO_FLASH_CMD; 164204c68496SJames Smart case MBX_SLI4_CONFIG: /* 0x9b */ 1643a183a15fSJames Smart subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq); 1644a183a15fSJames Smart opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq); 1645a183a15fSJames Smart if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) { 1646a183a15fSJames Smart switch (opcode) { 1647a183a15fSJames Smart case LPFC_MBOX_OPCODE_READ_OBJECT: 1648a183a15fSJames Smart case LPFC_MBOX_OPCODE_WRITE_OBJECT: 1649a183a15fSJames Smart case LPFC_MBOX_OPCODE_READ_OBJECT_LIST: 1650a183a15fSJames Smart case LPFC_MBOX_OPCODE_DELETE_OBJECT: 1651a183a15fSJames Smart case LPFC_MBOX_OPCODE_GET_PROFILE_LIST: 1652a183a15fSJames Smart case LPFC_MBOX_OPCODE_SET_ACT_PROFILE: 1653940eb687SJames Smart case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG: 1654a183a15fSJames Smart case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG: 1655a183a15fSJames Smart case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG: 1656940eb687SJames Smart case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES: 1657940eb687SJames Smart case LPFC_MBOX_OPCODE_SEND_ACTIVATION: 1658940eb687SJames Smart case LPFC_MBOX_OPCODE_RESET_LICENSES: 1659940eb687SJames Smart case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG: 1660940eb687SJames Smart case LPFC_MBOX_OPCODE_GET_VPD_DATA: 1661940eb687SJames Smart case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG: 1662a183a15fSJames Smart return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO; 1663a183a15fSJames Smart } 1664a183a15fSJames Smart } 1665a183a15fSJames Smart if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) { 1666a183a15fSJames Smart switch (opcode) { 1667a183a15fSJames Smart case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS: 1668a183a15fSJames Smart return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO; 1669a183a15fSJames Smart } 1670a183a15fSJames Smart } 167104c68496SJames Smart return LPFC_MBOX_SLI4_CONFIG_TMO; 1672a309a6b6SJames Smart } 1673a309a6b6SJames Smart return LPFC_MBOX_TMO; 1674a309a6b6SJames Smart } 167504c68496SJames Smart 167604c68496SJames Smart /** 167704c68496SJames Smart * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command 167804c68496SJames Smart * @mbox: pointer to lpfc mbox command. 167904c68496SJames Smart * @sgentry: sge entry index. 168004c68496SJames Smart * @phyaddr: physical address for the sge 168104c68496SJames Smart * @length: Length of the sge. 168204c68496SJames Smart * 168304c68496SJames Smart * This routine sets up an entry in the non-embedded mailbox command at the sge 168404c68496SJames Smart * index location. 168504c68496SJames Smart **/ 168604c68496SJames Smart void 168704c68496SJames Smart lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry, 168804c68496SJames Smart dma_addr_t phyaddr, uint32_t length) 168904c68496SJames Smart { 169004c68496SJames Smart struct lpfc_mbx_nembed_cmd *nembed_sge; 169104c68496SJames Smart 169204c68496SJames Smart nembed_sge = (struct lpfc_mbx_nembed_cmd *) 169304c68496SJames Smart &mbox->u.mqe.un.nembed_cmd; 169404c68496SJames Smart nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr); 169504c68496SJames Smart nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr); 169604c68496SJames Smart nembed_sge->sge[sgentry].length = length; 169704c68496SJames Smart } 169804c68496SJames Smart 169904c68496SJames Smart /** 170004c68496SJames Smart * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command 170104c68496SJames Smart * @mbox: pointer to lpfc mbox command. 170204c68496SJames Smart * @sgentry: sge entry index. 170304c68496SJames Smart * 170404c68496SJames Smart * This routine gets an entry from the non-embedded mailbox command at the sge 170504c68496SJames Smart * index location. 170604c68496SJames Smart **/ 170704c68496SJames Smart void 170804c68496SJames Smart lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry, 170904c68496SJames Smart struct lpfc_mbx_sge *sge) 171004c68496SJames Smart { 171104c68496SJames Smart struct lpfc_mbx_nembed_cmd *nembed_sge; 171204c68496SJames Smart 171304c68496SJames Smart nembed_sge = (struct lpfc_mbx_nembed_cmd *) 171404c68496SJames Smart &mbox->u.mqe.un.nembed_cmd; 171504c68496SJames Smart sge->pa_lo = nembed_sge->sge[sgentry].pa_lo; 171604c68496SJames Smart sge->pa_hi = nembed_sge->sge[sgentry].pa_hi; 171704c68496SJames Smart sge->length = nembed_sge->sge[sgentry].length; 171804c68496SJames Smart } 171904c68496SJames Smart 172004c68496SJames Smart /** 172104c68496SJames Smart * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command 172204c68496SJames Smart * @phba: pointer to lpfc hba data structure. 172304c68496SJames Smart * @mbox: pointer to lpfc mbox command. 172404c68496SJames Smart * 172504c68496SJames Smart * This routine frees SLI4 specific mailbox command for sending IOCTL command. 172604c68496SJames Smart **/ 172704c68496SJames Smart void 172804c68496SJames Smart lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox) 172904c68496SJames Smart { 173004c68496SJames Smart struct lpfc_mbx_sli4_config *sli4_cfg; 173104c68496SJames Smart struct lpfc_mbx_sge sge; 173204c68496SJames Smart dma_addr_t phyaddr; 173304c68496SJames Smart uint32_t sgecount, sgentry; 173404c68496SJames Smart 173504c68496SJames Smart sli4_cfg = &mbox->u.mqe.un.sli4_config; 173604c68496SJames Smart 173704c68496SJames Smart /* For embedded mbox command, just free the mbox command */ 173804c68496SJames Smart if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { 173904c68496SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 174004c68496SJames Smart return; 174104c68496SJames Smart } 174204c68496SJames Smart 174304c68496SJames Smart /* For non-embedded mbox command, we need to free the pages first */ 174404c68496SJames Smart sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr); 174504c68496SJames Smart /* There is nothing we can do if there is no sge address array */ 174604c68496SJames Smart if (unlikely(!mbox->sge_array)) { 174704c68496SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 174804c68496SJames Smart return; 174904c68496SJames Smart } 175004c68496SJames Smart /* Each non-embedded DMA memory was allocated in the length of a page */ 175104c68496SJames Smart for (sgentry = 0; sgentry < sgecount; sgentry++) { 175204c68496SJames Smart lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge); 175304c68496SJames Smart phyaddr = getPaddr(sge.pa_hi, sge.pa_lo); 175449198b37SJames Smart dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, 175504c68496SJames Smart mbox->sge_array->addr[sgentry], phyaddr); 175604c68496SJames Smart } 175704c68496SJames Smart /* Free the sge address array memory */ 175804c68496SJames Smart kfree(mbox->sge_array); 175904c68496SJames Smart /* Finally, free the mailbox command itself */ 176004c68496SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 176104c68496SJames Smart } 176204c68496SJames Smart 176304c68496SJames Smart /** 176404c68496SJames Smart * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command 176504c68496SJames Smart * @phba: pointer to lpfc hba data structure. 176604c68496SJames Smart * @mbox: pointer to lpfc mbox command. 176704c68496SJames Smart * @subsystem: The sli4 config sub mailbox subsystem. 176804c68496SJames Smart * @opcode: The sli4 config sub mailbox command opcode. 1769fedd3b7bSJames Smart * @length: Length of the sli4 config mailbox command (including sub-header). 177004c68496SJames Smart * 177104c68496SJames Smart * This routine sets up the header fields of SLI4 specific mailbox command 177204c68496SJames Smart * for sending IOCTL command. 177304c68496SJames Smart * 177404c68496SJames Smart * Return: the actual length of the mbox command allocated (mostly useful 177504c68496SJames Smart * for none embedded mailbox command). 177604c68496SJames Smart **/ 177704c68496SJames Smart int 177804c68496SJames Smart lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox, 177904c68496SJames Smart uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb) 178004c68496SJames Smart { 178104c68496SJames Smart struct lpfc_mbx_sli4_config *sli4_config; 178204c68496SJames Smart union lpfc_sli4_cfg_shdr *cfg_shdr = NULL; 178304c68496SJames Smart uint32_t alloc_len; 178404c68496SJames Smart uint32_t resid_len; 178504c68496SJames Smart uint32_t pagen, pcount; 178604c68496SJames Smart void *viraddr; 178704c68496SJames Smart dma_addr_t phyaddr; 178804c68496SJames Smart 178904c68496SJames Smart /* Set up SLI4 mailbox command header fields */ 179004c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 179104c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG); 179204c68496SJames Smart 179304c68496SJames Smart /* Set up SLI4 ioctl command header fields */ 179404c68496SJames Smart sli4_config = &mbox->u.mqe.un.sli4_config; 179504c68496SJames Smart 179604c68496SJames Smart /* Setup for the embedded mbox command */ 179704c68496SJames Smart if (emb) { 179804c68496SJames Smart /* Set up main header fields */ 179904c68496SJames Smart bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1); 1800fedd3b7bSJames Smart sli4_config->header.cfg_mhdr.payload_length = length; 180104c68496SJames Smart /* Set up sub-header fields following main header */ 180204c68496SJames Smart bf_set(lpfc_mbox_hdr_opcode, 180304c68496SJames Smart &sli4_config->header.cfg_shdr.request, opcode); 180404c68496SJames Smart bf_set(lpfc_mbox_hdr_subsystem, 180504c68496SJames Smart &sli4_config->header.cfg_shdr.request, subsystem); 1806fedd3b7bSJames Smart sli4_config->header.cfg_shdr.request.request_length = 1807fedd3b7bSJames Smart length - LPFC_MBX_CMD_HDR_LENGTH; 180804c68496SJames Smart return length; 180904c68496SJames Smart } 181004c68496SJames Smart 18116d368e53SJames Smart /* Setup for the non-embedded mbox command */ 18129589b062SJames Smart pcount = (SLI4_PAGE_ALIGN(length))/SLI4_PAGE_SIZE; 181304c68496SJames Smart pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ? 181404c68496SJames Smart LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount; 181504c68496SJames Smart /* Allocate record for keeping SGE virtual addresses */ 18166d368e53SJames Smart mbox->sge_array = kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt), 181704c68496SJames Smart GFP_KERNEL); 18186a9c52cfSJames Smart if (!mbox->sge_array) { 18196a9c52cfSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, 18206a9c52cfSJames Smart "2527 Failed to allocate non-embedded SGE " 18216a9c52cfSJames Smart "array.\n"); 182204c68496SJames Smart return 0; 18236a9c52cfSJames Smart } 182404c68496SJames Smart for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) { 182504c68496SJames Smart /* The DMA memory is always allocated in the length of a 182604c68496SJames Smart * page even though the last SGE might not fill up to a 182749198b37SJames Smart * page, this is used as a priori size of SLI4_PAGE_SIZE for 182804c68496SJames Smart * the later DMA memory free. 182904c68496SJames Smart */ 18301aee383dSJoe Perches viraddr = dma_zalloc_coherent(&phba->pcidev->dev, 18311aee383dSJoe Perches SLI4_PAGE_SIZE, &phyaddr, 18321aee383dSJoe Perches GFP_KERNEL); 183304c68496SJames Smart /* In case of malloc fails, proceed with whatever we have */ 183404c68496SJames Smart if (!viraddr) 183504c68496SJames Smart break; 183604c68496SJames Smart mbox->sge_array->addr[pagen] = viraddr; 183704c68496SJames Smart /* Keep the first page for later sub-header construction */ 183804c68496SJames Smart if (pagen == 0) 183904c68496SJames Smart cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr; 184004c68496SJames Smart resid_len = length - alloc_len; 184149198b37SJames Smart if (resid_len > SLI4_PAGE_SIZE) { 184204c68496SJames Smart lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, 184349198b37SJames Smart SLI4_PAGE_SIZE); 184449198b37SJames Smart alloc_len += SLI4_PAGE_SIZE; 184504c68496SJames Smart } else { 184604c68496SJames Smart lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, 184704c68496SJames Smart resid_len); 184804c68496SJames Smart alloc_len = length; 184904c68496SJames Smart } 185004c68496SJames Smart } 185104c68496SJames Smart 185204c68496SJames Smart /* Set up main header fields in mailbox command */ 185304c68496SJames Smart sli4_config->header.cfg_mhdr.payload_length = alloc_len; 185404c68496SJames Smart bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen); 185504c68496SJames Smart 185604c68496SJames Smart /* Set up sub-header fields into the first page */ 185704c68496SJames Smart if (pagen > 0) { 185804c68496SJames Smart bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode); 185904c68496SJames Smart bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem); 186004c68496SJames Smart cfg_shdr->request.request_length = 186104c68496SJames Smart alloc_len - sizeof(union lpfc_sli4_cfg_shdr); 186204c68496SJames Smart } 186304c68496SJames Smart /* The sub-header is in DMA memory, which needs endian converstion */ 186472100cc4SJames Smart if (cfg_shdr) 186504c68496SJames Smart lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr, 186604c68496SJames Smart sizeof(union lpfc_sli4_cfg_shdr)); 186704c68496SJames Smart return alloc_len; 186804c68496SJames Smart } 186904c68496SJames Smart 187004c68496SJames Smart /** 18716d368e53SJames Smart * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent. 18726d368e53SJames Smart * @phba: pointer to lpfc hba data structure. 18736d368e53SJames Smart * @mbox: pointer to an allocated lpfc mbox resource. 18746d368e53SJames Smart * @exts_count: the number of extents, if required, to allocate. 18756d368e53SJames Smart * @rsrc_type: the resource extent type. 18766d368e53SJames Smart * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED. 18776d368e53SJames Smart * 18786d368e53SJames Smart * This routine completes the subcommand header for SLI4 resource extent 18796d368e53SJames Smart * mailbox commands. It is called after lpfc_sli4_config. The caller must 18806d368e53SJames Smart * pass an allocated mailbox and the attributes required to initialize the 18816d368e53SJames Smart * mailbox correctly. 18826d368e53SJames Smart * 18836d368e53SJames Smart * Return: the actual length of the mbox command allocated. 18846d368e53SJames Smart **/ 18856d368e53SJames Smart int 18866d368e53SJames Smart lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox, 18876d368e53SJames Smart uint16_t exts_count, uint16_t rsrc_type, bool emb) 18886d368e53SJames Smart { 18896d368e53SJames Smart uint8_t opcode = 0; 18906d368e53SJames Smart struct lpfc_mbx_nembed_rsrc_extent *n_rsrc_extnt = NULL; 18916d368e53SJames Smart void *virtaddr = NULL; 18926d368e53SJames Smart 18936d368e53SJames Smart /* Set up SLI4 ioctl command header fields */ 18946d368e53SJames Smart if (emb == LPFC_SLI4_MBX_NEMBED) { 18956d368e53SJames Smart /* Get the first SGE entry from the non-embedded DMA memory */ 18966d368e53SJames Smart virtaddr = mbox->sge_array->addr[0]; 18976d368e53SJames Smart if (virtaddr == NULL) 18986d368e53SJames Smart return 1; 18996d368e53SJames Smart n_rsrc_extnt = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; 19006d368e53SJames Smart } 19016d368e53SJames Smart 19026d368e53SJames Smart /* 19036d368e53SJames Smart * The resource type is common to all extent Opcodes and resides in the 19046d368e53SJames Smart * same position. 19056d368e53SJames Smart */ 19066d368e53SJames Smart if (emb == LPFC_SLI4_MBX_EMBED) 19076d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_type, 19086d368e53SJames Smart &mbox->u.mqe.un.alloc_rsrc_extents.u.req, 19096d368e53SJames Smart rsrc_type); 19106d368e53SJames Smart else { 19116d368e53SJames Smart /* This is DMA data. Byteswap is required. */ 19126d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_type, 19136d368e53SJames Smart n_rsrc_extnt, rsrc_type); 19146d368e53SJames Smart lpfc_sli_pcimem_bcopy(&n_rsrc_extnt->word4, 19156d368e53SJames Smart &n_rsrc_extnt->word4, 19166d368e53SJames Smart sizeof(uint32_t)); 19176d368e53SJames Smart } 19186d368e53SJames Smart 19196d368e53SJames Smart /* Complete the initialization for the particular Opcode. */ 1920a183a15fSJames Smart opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox); 19216d368e53SJames Smart switch (opcode) { 19226d368e53SJames Smart case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT: 19236d368e53SJames Smart if (emb == LPFC_SLI4_MBX_EMBED) 19246d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_cnt, 19256d368e53SJames Smart &mbox->u.mqe.un.alloc_rsrc_extents.u.req, 19266d368e53SJames Smart exts_count); 19276d368e53SJames Smart else 19286d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_cnt, 19296d368e53SJames Smart n_rsrc_extnt, exts_count); 19306d368e53SJames Smart break; 19316d368e53SJames Smart case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT: 19326d368e53SJames Smart case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO: 19336d368e53SJames Smart case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT: 19346d368e53SJames Smart /* Initialization is complete.*/ 19356d368e53SJames Smart break; 19366d368e53SJames Smart default: 19376d368e53SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, 19386d368e53SJames Smart "2929 Resource Extent Opcode x%x is " 19396d368e53SJames Smart "unsupported\n", opcode); 19406d368e53SJames Smart return 1; 19416d368e53SJames Smart } 19426d368e53SJames Smart 19436d368e53SJames Smart return 0; 19446d368e53SJames Smart } 19456d368e53SJames Smart 19466d368e53SJames Smart /** 1947a183a15fSJames Smart * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd 194804c68496SJames Smart * @phba: pointer to lpfc hba data structure. 1949a183a15fSJames Smart * @mbox: pointer to lpfc mbox command queue entry. 195004c68496SJames Smart * 1951a183a15fSJames Smart * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox 1952a183a15fSJames Smart * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the 1953a183a15fSJames Smart * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall 1954a183a15fSJames Smart * be returned. 195504c68496SJames Smart **/ 195604c68496SJames Smart uint8_t 1957a183a15fSJames Smart lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) 195804c68496SJames Smart { 195904c68496SJames Smart struct lpfc_mbx_sli4_config *sli4_cfg; 196004c68496SJames Smart union lpfc_sli4_cfg_shdr *cfg_shdr; 196104c68496SJames Smart 196204c68496SJames Smart if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) 1963a183a15fSJames Smart return LPFC_MBOX_SUBSYSTEM_NA; 1964a183a15fSJames Smart sli4_cfg = &mbox->u.mqe.un.sli4_config; 1965a183a15fSJames Smart 1966a183a15fSJames Smart /* For embedded mbox command, get opcode from embedded sub-header*/ 1967a183a15fSJames Smart if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { 1968a183a15fSJames Smart cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; 1969a183a15fSJames Smart return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request); 1970a183a15fSJames Smart } 1971a183a15fSJames Smart 1972a183a15fSJames Smart /* For non-embedded mbox command, get opcode from first dma page */ 1973a183a15fSJames Smart if (unlikely(!mbox->sge_array)) 1974a183a15fSJames Smart return LPFC_MBOX_SUBSYSTEM_NA; 1975a183a15fSJames Smart cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; 1976a183a15fSJames Smart return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request); 1977a183a15fSJames Smart } 1978a183a15fSJames Smart 1979a183a15fSJames Smart /** 1980a183a15fSJames Smart * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd 1981a183a15fSJames Smart * @phba: pointer to lpfc hba data structure. 1982a183a15fSJames Smart * @mbox: pointer to lpfc mbox command queue entry. 1983a183a15fSJames Smart * 1984a183a15fSJames Smart * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox 1985a183a15fSJames Smart * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if 1986a183a15fSJames Smart * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be 1987a183a15fSJames Smart * returned. 1988a183a15fSJames Smart **/ 1989a183a15fSJames Smart uint8_t 1990a183a15fSJames Smart lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) 1991a183a15fSJames Smart { 1992a183a15fSJames Smart struct lpfc_mbx_sli4_config *sli4_cfg; 1993a183a15fSJames Smart union lpfc_sli4_cfg_shdr *cfg_shdr; 1994a183a15fSJames Smart 1995a183a15fSJames Smart if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) 1996a183a15fSJames Smart return LPFC_MBOX_OPCODE_NA; 199704c68496SJames Smart sli4_cfg = &mbox->u.mqe.un.sli4_config; 199804c68496SJames Smart 199904c68496SJames Smart /* For embedded mbox command, get opcode from embedded sub-header*/ 200004c68496SJames Smart if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { 200104c68496SJames Smart cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; 200204c68496SJames Smart return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); 200304c68496SJames Smart } 200404c68496SJames Smart 200504c68496SJames Smart /* For non-embedded mbox command, get opcode from first dma page */ 200604c68496SJames Smart if (unlikely(!mbox->sge_array)) 2007a183a15fSJames Smart return LPFC_MBOX_OPCODE_NA; 200804c68496SJames Smart cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; 200904c68496SJames Smart return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); 201004c68496SJames Smart } 201104c68496SJames Smart 201204c68496SJames Smart /** 20130c9ab6f5SJames Smart * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd 2014ecfd03c6SJames Smart * @phba: pointer to lpfc hba data structure. 2015ecfd03c6SJames Smart * @fcf_index: index to fcf table. 2016ecfd03c6SJames Smart * 2017ecfd03c6SJames Smart * This routine routine allocates and constructs non-embedded mailbox command 201825985edcSLucas De Marchi * for reading a FCF table entry referred by @fcf_index. 2019ecfd03c6SJames Smart * 2020ecfd03c6SJames Smart * Return: pointer to the mailbox command constructed if successful, otherwise 2021ecfd03c6SJames Smart * NULL. 2022ecfd03c6SJames Smart **/ 2023ecfd03c6SJames Smart int 20240c9ab6f5SJames Smart lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba, 2025ecfd03c6SJames Smart struct lpfcMboxq *mboxq, 2026ecfd03c6SJames Smart uint16_t fcf_index) 2027ecfd03c6SJames Smart { 2028ecfd03c6SJames Smart void *virt_addr; 2029ecfd03c6SJames Smart uint8_t *bytep; 2030ecfd03c6SJames Smart struct lpfc_mbx_sge sge; 2031ecfd03c6SJames Smart uint32_t alloc_len, req_len; 2032ecfd03c6SJames Smart struct lpfc_mbx_read_fcf_tbl *read_fcf; 2033ecfd03c6SJames Smart 2034ecfd03c6SJames Smart if (!mboxq) 2035ecfd03c6SJames Smart return -ENOMEM; 2036ecfd03c6SJames Smart 2037ecfd03c6SJames Smart req_len = sizeof(struct fcf_record) + 2038ecfd03c6SJames Smart sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t); 2039ecfd03c6SJames Smart 2040ecfd03c6SJames Smart /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */ 2041ecfd03c6SJames Smart alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, 2042ecfd03c6SJames Smart LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len, 2043ecfd03c6SJames Smart LPFC_SLI4_MBX_NEMBED); 2044ecfd03c6SJames Smart 2045ecfd03c6SJames Smart if (alloc_len < req_len) { 2046ecfd03c6SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, 2047ecfd03c6SJames Smart "0291 Allocated DMA memory size (x%x) is " 2048ecfd03c6SJames Smart "less than the requested DMA memory " 2049ecfd03c6SJames Smart "size (x%x)\n", alloc_len, req_len); 2050ecfd03c6SJames Smart return -ENOMEM; 2051ecfd03c6SJames Smart } 2052ecfd03c6SJames Smart 2053ecfd03c6SJames Smart /* Get the first SGE entry from the non-embedded DMA memory. This 2054ecfd03c6SJames Smart * routine only uses a single SGE. 2055ecfd03c6SJames Smart */ 2056ecfd03c6SJames Smart lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); 2057ecfd03c6SJames Smart virt_addr = mboxq->sge_array->addr[0]; 2058ecfd03c6SJames Smart read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; 2059ecfd03c6SJames Smart 2060ecfd03c6SJames Smart /* Set up command fields */ 2061ecfd03c6SJames Smart bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index); 2062ecfd03c6SJames Smart /* Perform necessary endian conversion */ 2063ecfd03c6SJames Smart bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); 2064ecfd03c6SJames Smart lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t)); 2065ecfd03c6SJames Smart 2066ecfd03c6SJames Smart return 0; 2067ecfd03c6SJames Smart } 2068ecfd03c6SJames Smart 2069ecfd03c6SJames Smart /** 207004c68496SJames Smart * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox 207104c68496SJames Smart * @mboxq: pointer to lpfc mbox command. 207204c68496SJames Smart * 207304c68496SJames Smart * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES 207404c68496SJames Smart * mailbox command. 207504c68496SJames Smart **/ 207604c68496SJames Smart void 207704c68496SJames Smart lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq) 207804c68496SJames Smart { 207904c68496SJames Smart /* Set up SLI4 mailbox command header fields */ 208004c68496SJames Smart memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); 208104c68496SJames Smart bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS); 208204c68496SJames Smart 208304c68496SJames Smart /* Set up host requested features. */ 208404c68496SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1); 2085fedd3b7bSJames Smart bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1); 208604c68496SJames Smart 208704c68496SJames Smart /* Enable DIF (block guard) only if configured to do so. */ 208804c68496SJames Smart if (phba->cfg_enable_bg) 208904c68496SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1); 209004c68496SJames Smart 209104c68496SJames Smart /* Enable NPIV only if configured to do so. */ 209204c68496SJames Smart if (phba->max_vpi && phba->cfg_enable_npiv) 209304c68496SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1); 209404c68496SJames Smart 209586c67379SJames Smart if (phba->nvmet_support) { 20962d7dbc4cSJames Smart bf_set(lpfc_mbx_rq_ftr_rq_mrqp, &mboxq->u.mqe.un.req_ftrs, 1); 209786c67379SJames Smart /* iaab/iaar NOT set for now */ 209886c67379SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_iaab, &mboxq->u.mqe.un.req_ftrs, 0); 209986c67379SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_iaar, &mboxq->u.mqe.un.req_ftrs, 0); 210086c67379SJames Smart } 210104c68496SJames Smart return; 210204c68496SJames Smart } 210304c68496SJames Smart 210404c68496SJames Smart /** 210504c68496SJames Smart * lpfc_init_vfi - Initialize the INIT_VFI mailbox command 210604c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 210704c68496SJames Smart * @vport: Vport associated with the VF. 210804c68496SJames Smart * 210904c68496SJames Smart * This routine initializes @mbox to all zeros and then fills in the mailbox 211004c68496SJames Smart * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI 211104c68496SJames Smart * in the context of an FCF. The driver issues this command to setup a VFI 211204c68496SJames Smart * before issuing a FLOGI to login to the VSAN. The driver should also issue a 211304c68496SJames Smart * REG_VFI after a successful VSAN login. 211404c68496SJames Smart **/ 211504c68496SJames Smart void 211604c68496SJames Smart lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) 211704c68496SJames Smart { 211804c68496SJames Smart struct lpfc_mbx_init_vfi *init_vfi; 211904c68496SJames Smart 212004c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 212176a95d75SJames Smart mbox->vport = vport; 212204c68496SJames Smart init_vfi = &mbox->u.mqe.un.init_vfi; 212304c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI); 212404c68496SJames Smart bf_set(lpfc_init_vfi_vr, init_vfi, 1); 212504c68496SJames Smart bf_set(lpfc_init_vfi_vt, init_vfi, 1); 212676a95d75SJames Smart bf_set(lpfc_init_vfi_vp, init_vfi, 1); 21276d368e53SJames Smart bf_set(lpfc_init_vfi_vfi, init_vfi, 21286d368e53SJames Smart vport->phba->sli4_hba.vfi_ids[vport->vfi]); 21297851fe2cSJames Smart bf_set(lpfc_init_vfi_vpi, init_vfi, 21306d368e53SJames Smart vport->phba->vpi_ids[vport->vpi]); 21316d368e53SJames Smart bf_set(lpfc_init_vfi_fcfi, init_vfi, 21326d368e53SJames Smart vport->phba->fcf.fcfi); 213304c68496SJames Smart } 213404c68496SJames Smart 213504c68496SJames Smart /** 213604c68496SJames Smart * lpfc_reg_vfi - Initialize the REG_VFI mailbox command 213704c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 213804c68496SJames Smart * @vport: vport associated with the VF. 213904c68496SJames Smart * @phys: BDE DMA bus address used to send the service parameters to the HBA. 214004c68496SJames Smart * 214104c68496SJames Smart * This routine initializes @mbox to all zeros and then fills in the mailbox 214204c68496SJames Smart * fields from @vport, and uses @buf as a DMAable buffer to send the vport's 214304c68496SJames Smart * fc service parameters to the HBA for this VFI. REG_VFI configures virtual 214404c68496SJames Smart * fabrics identified by VFI in the context of an FCF. 214504c68496SJames Smart **/ 214604c68496SJames Smart void 214704c68496SJames Smart lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys) 214804c68496SJames Smart { 214904c68496SJames Smart struct lpfc_mbx_reg_vfi *reg_vfi; 2150ae05ebe3SJames Smart struct lpfc_hba *phba = vport->phba; 215144fd7fe3SJames Smart uint8_t bbscn_fabric = 0, bbscn_max = 0, bbscn_def = 0; 215204c68496SJames Smart 215304c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 215404c68496SJames Smart reg_vfi = &mbox->u.mqe.un.reg_vfi; 215504c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI); 215604c68496SJames Smart bf_set(lpfc_reg_vfi_vp, reg_vfi, 1); 21576d368e53SJames Smart bf_set(lpfc_reg_vfi_vfi, reg_vfi, 2158ae05ebe3SJames Smart phba->sli4_hba.vfi_ids[vport->vfi]); 2159ae05ebe3SJames Smart bf_set(lpfc_reg_vfi_fcfi, reg_vfi, phba->fcf.fcfi); 2160ae05ebe3SJames Smart bf_set(lpfc_reg_vfi_vpi, reg_vfi, phba->vpi_ids[vport->vpi]); 2161c868595dSJames Smart memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name)); 2162c868595dSJames Smart reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]); 2163c868595dSJames Smart reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]); 2164ae05ebe3SJames Smart reg_vfi->e_d_tov = phba->fc_edtov; 2165ae05ebe3SJames Smart reg_vfi->r_a_tov = phba->fc_ratov; 2166ae09c765SJames Smart if (phys) { 216704c68496SJames Smart reg_vfi->bde.addrHigh = putPaddrHigh(phys); 216804c68496SJames Smart reg_vfi->bde.addrLow = putPaddrLow(phys); 216904c68496SJames Smart reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam); 217004c68496SJames Smart reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2171ae09c765SJames Smart } 217204c68496SJames Smart bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID); 2173ae05ebe3SJames Smart 2174ae05ebe3SJames Smart /* Only FC supports upd bit */ 2175ae05ebe3SJames Smart if ((phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) && 2176e74c03c8SJames Smart (vport->fc_flag & FC_VFI_REGISTERED) && 21772c3b2a8fSJames Smart (!phba->fc_topology_changed)) 2178ae05ebe3SJames Smart bf_set(lpfc_reg_vfi_upd, reg_vfi, 1); 217944fd7fe3SJames Smart 218044fd7fe3SJames Smart bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 0); 218144fd7fe3SJames Smart bf_set(lpfc_reg_vfi_bbscn, reg_vfi, 0); 218244fd7fe3SJames Smart bbscn_fabric = (phba->fc_fabparam.cmn.bbRcvSizeMsb >> 4) & 0xF; 218344fd7fe3SJames Smart 218444fd7fe3SJames Smart if (phba->bbcredit_support && phba->cfg_enable_bbcr && 218544fd7fe3SJames Smart bbscn_fabric != 0) { 218644fd7fe3SJames Smart bbscn_max = bf_get(lpfc_bbscn_max, 218744fd7fe3SJames Smart &phba->sli4_hba.bbscn_params); 218844fd7fe3SJames Smart if (bbscn_fabric <= bbscn_max) { 218944fd7fe3SJames Smart bbscn_def = bf_get(lpfc_bbscn_def, 219044fd7fe3SJames Smart &phba->sli4_hba.bbscn_params); 219144fd7fe3SJames Smart 219244fd7fe3SJames Smart if (bbscn_fabric > bbscn_def) 219344fd7fe3SJames Smart bf_set(lpfc_reg_vfi_bbscn, reg_vfi, 219444fd7fe3SJames Smart bbscn_fabric); 219544fd7fe3SJames Smart else 219644fd7fe3SJames Smart bf_set(lpfc_reg_vfi_bbscn, reg_vfi, bbscn_def); 219744fd7fe3SJames Smart 219844fd7fe3SJames Smart bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 1); 219944fd7fe3SJames Smart } 220044fd7fe3SJames Smart } 22011b51197dSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_MBOX, 22021b51197dSJames Smart "3134 Register VFI, mydid:x%x, fcfi:%d, " 2203e74c03c8SJames Smart " vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x" 220444fd7fe3SJames Smart " port_state:x%x topology chg:%d bbscn_fabric :%d\n", 22051b51197dSJames Smart vport->fc_myDID, 2206ae05ebe3SJames Smart phba->fcf.fcfi, 2207ae05ebe3SJames Smart phba->sli4_hba.vfi_ids[vport->vfi], 2208ae05ebe3SJames Smart phba->vpi_ids[vport->vpi], 2209e74c03c8SJames Smart reg_vfi->wwn[0], reg_vfi->wwn[1], vport->fc_flag, 221044fd7fe3SJames Smart vport->port_state, phba->fc_topology_changed, 221144fd7fe3SJames Smart bbscn_fabric); 221204c68496SJames Smart } 221304c68496SJames Smart 221404c68496SJames Smart /** 221504c68496SJames Smart * lpfc_init_vpi - Initialize the INIT_VPI mailbox command 22161c6834a7SJames Smart * @phba: pointer to the hba structure to init the VPI for. 221704c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 221804c68496SJames Smart * @vpi: VPI to be initialized. 221904c68496SJames Smart * 222004c68496SJames Smart * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the 222104c68496SJames Smart * command to activate a virtual N_Port. The HBA assigns a MAC address to use 222204c68496SJames Smart * with the virtual N Port. The SLI Host issues this command before issuing a 222304c68496SJames Smart * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a 222404c68496SJames Smart * successful virtual NPort login. 222504c68496SJames Smart **/ 222604c68496SJames Smart void 22271c6834a7SJames Smart lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi) 222804c68496SJames Smart { 222904c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 223004c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI); 22311c6834a7SJames Smart bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi, 22326d368e53SJames Smart phba->vpi_ids[vpi]); 22331c6834a7SJames Smart bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi, 22346d368e53SJames Smart phba->sli4_hba.vfi_ids[phba->pport->vfi]); 223504c68496SJames Smart } 223604c68496SJames Smart 223704c68496SJames Smart /** 223804c68496SJames Smart * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command 223904c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 22406669f9bbSJames Smart * @vport: vport associated with the VF. 224104c68496SJames Smart * 224204c68496SJames Smart * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric 224304c68496SJames Smart * (logical NPort) into the inactive state. The SLI Host must have logged out 224404c68496SJames Smart * and unregistered all remote N_Ports to abort any activity on the virtual 224504c68496SJames Smart * fabric. The SLI Port posts the mailbox response after marking the virtual 224604c68496SJames Smart * fabric inactive. 224704c68496SJames Smart **/ 224804c68496SJames Smart void 22496669f9bbSJames Smart lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) 225004c68496SJames Smart { 225104c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 225204c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI); 22536669f9bbSJames Smart bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi, 22546d368e53SJames Smart vport->phba->sli4_hba.vfi_ids[vport->vfi]); 225504c68496SJames Smart } 225604c68496SJames Smart 225704c68496SJames Smart /** 2258026abb87SJames Smart * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23 225904c68496SJames Smart * @phba: pointer to the hba structure containing. 226004c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 226104c68496SJames Smart * 2262026abb87SJames Smart * This function create a SLI4 dump mailbox command to dump configure 2263026abb87SJames Smart * region 23. 226404c68496SJames Smart **/ 226504c68496SJames Smart int 2266026abb87SJames Smart lpfc_sli4_dump_cfg_rg23(struct lpfc_hba *phba, struct lpfcMboxq *mbox) 226704c68496SJames Smart { 226804c68496SJames Smart struct lpfc_dmabuf *mp = NULL; 226904c68496SJames Smart MAILBOX_t *mb; 227004c68496SJames Smart 227104c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 227204c68496SJames Smart mb = &mbox->u.mb; 227304c68496SJames Smart 227404c68496SJames Smart mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 227504c68496SJames Smart if (mp) 227604c68496SJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 227704c68496SJames Smart 227804c68496SJames Smart if (!mp || !mp->virt) { 227904c68496SJames Smart kfree(mp); 2280026abb87SJames Smart /* dump config region 23 failed to allocate memory */ 228104c68496SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 2282026abb87SJames Smart "2569 lpfc dump config region 23: memory" 228304c68496SJames Smart " allocation failed\n"); 228404c68496SJames Smart return 1; 228504c68496SJames Smart } 228604c68496SJames Smart 228704c68496SJames Smart memset(mp->virt, 0, LPFC_BPL_SIZE); 228804c68496SJames Smart INIT_LIST_HEAD(&mp->list); 228904c68496SJames Smart 229004c68496SJames Smart /* save address for completion */ 22913e1f0718SJames Smart mbox->ctx_buf = (uint8_t *)mp; 229204c68496SJames Smart 229304c68496SJames Smart mb->mbxCommand = MBX_DUMP_MEMORY; 229404c68496SJames Smart mb->un.varDmp.type = DMP_NV_PARAMS; 2295a0c87cbdSJames Smart mb->un.varDmp.region_id = DMP_REGION_23; 2296a0c87cbdSJames Smart mb->un.varDmp.sli4_length = DMP_RGN23_SIZE; 229704c68496SJames Smart mb->un.varWords[3] = putPaddrLow(mp->phys); 229804c68496SJames Smart mb->un.varWords[4] = putPaddrHigh(mp->phys); 229904c68496SJames Smart return 0; 230004c68496SJames Smart } 230104c68496SJames Smart 2302bd4b3e5cSBaoyou Xie static void 230386478875SJames Smart lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) 230486478875SJames Smart { 230586478875SJames Smart MAILBOX_t *mb; 230686478875SJames Smart int rc = FAILURE; 230786478875SJames Smart struct lpfc_rdp_context *rdp_context = 23083e1f0718SJames Smart (struct lpfc_rdp_context *)(mboxq->ctx_ndlp); 230986478875SJames Smart 231086478875SJames Smart mb = &mboxq->u.mb; 231186478875SJames Smart if (mb->mbxStatus) 231286478875SJames Smart goto mbx_failed; 231386478875SJames Smart 231486478875SJames Smart memcpy(&rdp_context->link_stat, &mb->un.varRdLnk, sizeof(READ_LNK_VAR)); 231586478875SJames Smart 231686478875SJames Smart rc = SUCCESS; 231786478875SJames Smart 231886478875SJames Smart mbx_failed: 231986478875SJames Smart lpfc_sli4_mbox_cmd_free(phba, mboxq); 232086478875SJames Smart rdp_context->cmpl(phba, rdp_context, rc); 232186478875SJames Smart } 232286478875SJames Smart 2323bd4b3e5cSBaoyou Xie static void 232486478875SJames Smart lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) 232586478875SJames Smart { 23263e1f0718SJames Smart struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)mbox->ctx_buf; 232786478875SJames Smart struct lpfc_rdp_context *rdp_context = 23283e1f0718SJames Smart (struct lpfc_rdp_context *)(mbox->ctx_ndlp); 232986478875SJames Smart 233086478875SJames Smart if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) 2331612872caSJohannes Thumshirn goto error_mbuf_free; 233286478875SJames Smart 233386478875SJames Smart lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2, 233486478875SJames Smart DMP_SFF_PAGE_A2_SIZE); 233586478875SJames Smart 233686478875SJames Smart /* We don't need dma buffer for link stat. */ 233786478875SJames Smart lpfc_mbuf_free(phba, mp->virt, mp->phys); 233886478875SJames Smart kfree(mp); 233986478875SJames Smart 234086478875SJames Smart memset(mbox, 0, sizeof(*mbox)); 234186478875SJames Smart lpfc_read_lnk_stat(phba, mbox); 234286478875SJames Smart mbox->vport = rdp_context->ndlp->vport; 234386478875SJames Smart mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_link_stat; 23443e1f0718SJames Smart mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context; 234586478875SJames Smart if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == MBX_NOT_FINISHED) 2346612872caSJohannes Thumshirn goto error_cmd_free; 234786478875SJames Smart 234886478875SJames Smart return; 234986478875SJames Smart 2350612872caSJohannes Thumshirn error_mbuf_free: 235186478875SJames Smart lpfc_mbuf_free(phba, mp->virt, mp->phys); 235286478875SJames Smart kfree(mp); 2353612872caSJohannes Thumshirn error_cmd_free: 235486478875SJames Smart lpfc_sli4_mbox_cmd_free(phba, mbox); 235586478875SJames Smart rdp_context->cmpl(phba, rdp_context, FAILURE); 235686478875SJames Smart } 235786478875SJames Smart 235886478875SJames Smart void 235986478875SJames Smart lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) 236086478875SJames Smart { 236186478875SJames Smart int rc; 23623e1f0718SJames Smart struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(mbox->ctx_buf); 236386478875SJames Smart struct lpfc_rdp_context *rdp_context = 23643e1f0718SJames Smart (struct lpfc_rdp_context *)(mbox->ctx_ndlp); 236586478875SJames Smart 236686478875SJames Smart if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) 236786478875SJames Smart goto error; 236886478875SJames Smart 236986478875SJames Smart lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0, 237086478875SJames Smart DMP_SFF_PAGE_A0_SIZE); 237186478875SJames Smart 237286478875SJames Smart memset(mbox, 0, sizeof(*mbox)); 237386478875SJames Smart 237486478875SJames Smart memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE); 237586478875SJames Smart INIT_LIST_HEAD(&mp->list); 237686478875SJames Smart 237786478875SJames Smart /* save address for completion */ 23783e1f0718SJames Smart mbox->ctx_buf = mp; 237986478875SJames Smart mbox->vport = rdp_context->ndlp->vport; 238086478875SJames Smart 238186478875SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY); 238286478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_type, 238386478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD); 238486478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_link, 238586478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port); 238686478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_page_no, 238786478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2); 238886478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_length, 238986478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE); 239086478875SJames Smart mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys); 239186478875SJames Smart mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys); 239286478875SJames Smart 239386478875SJames Smart mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a2; 23943e1f0718SJames Smart mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context; 239586478875SJames Smart rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 239686478875SJames Smart if (rc == MBX_NOT_FINISHED) 239786478875SJames Smart goto error; 239886478875SJames Smart 239986478875SJames Smart return; 240086478875SJames Smart 240186478875SJames Smart error: 240286478875SJames Smart lpfc_mbuf_free(phba, mp->virt, mp->phys); 240386478875SJames Smart kfree(mp); 240486478875SJames Smart lpfc_sli4_mbox_cmd_free(phba, mbox); 240586478875SJames Smart rdp_context->cmpl(phba, rdp_context, FAILURE); 240686478875SJames Smart } 240786478875SJames Smart 240886478875SJames Smart 240986478875SJames Smart /* 241086478875SJames Smart * lpfc_sli4_dump_sfp_pagea0 - Dump sli4 read SFP Diagnostic. 241186478875SJames Smart * @phba: pointer to the hba structure containing. 241286478875SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 241386478875SJames Smart * 241486478875SJames Smart * This function create a SLI4 dump mailbox command to dump configure 241586478875SJames Smart * type 3 page 0xA0. 241686478875SJames Smart */ 241786478875SJames Smart int 241886478875SJames Smart lpfc_sli4_dump_page_a0(struct lpfc_hba *phba, struct lpfcMboxq *mbox) 241986478875SJames Smart { 242086478875SJames Smart struct lpfc_dmabuf *mp = NULL; 242186478875SJames Smart 242286478875SJames Smart memset(mbox, 0, sizeof(*mbox)); 242386478875SJames Smart 242486478875SJames Smart mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 242586478875SJames Smart if (mp) 242686478875SJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 242786478875SJames Smart if (!mp || !mp->virt) { 242886478875SJames Smart kfree(mp); 242986478875SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 243086478875SJames Smart "3569 dump type 3 page 0xA0 allocation failed\n"); 243186478875SJames Smart return 1; 243286478875SJames Smart } 243386478875SJames Smart 243486478875SJames Smart memset(mp->virt, 0, LPFC_BPL_SIZE); 243586478875SJames Smart INIT_LIST_HEAD(&mp->list); 243686478875SJames Smart 243786478875SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY); 243886478875SJames Smart /* save address for completion */ 24393e1f0718SJames Smart mbox->ctx_buf = mp; 244086478875SJames Smart 244186478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_type, 244286478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD); 244386478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_link, 244486478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port); 244586478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_page_no, 244686478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A0); 244786478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_length, 244886478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE); 244986478875SJames Smart mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys); 245086478875SJames Smart mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys); 245186478875SJames Smart 245286478875SJames Smart return 0; 245386478875SJames Smart } 245486478875SJames Smart 245504c68496SJames Smart /** 245604c68496SJames Smart * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command 245704c68496SJames Smart * @phba: pointer to the hba structure containing the FCF index and RQ ID. 245804c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 245904c68496SJames Smart * 246004c68496SJames Smart * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The 246104c68496SJames Smart * SLI Host uses the command to activate an FCF after it has acquired FCF 246204c68496SJames Smart * information via a READ_FCF mailbox command. This mailbox command also is used 246304c68496SJames Smart * to indicate where received unsolicited frames from this FCF will be sent. By 246404c68496SJames Smart * default this routine will set up the FCF to forward all unsolicited frames 246504c68496SJames Smart * the the RQ ID passed in the @phba. This can be overridden by the caller for 246604c68496SJames Smart * more complicated setups. 246704c68496SJames Smart **/ 246804c68496SJames Smart void 246904c68496SJames Smart lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox) 247004c68496SJames Smart { 247104c68496SJames Smart struct lpfc_mbx_reg_fcfi *reg_fcfi; 247204c68496SJames Smart 247304c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 247404c68496SJames Smart reg_fcfi = &mbox->u.mqe.un.reg_fcfi; 247504c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI); 2476895427bdSJames Smart if (phba->nvmet_support == 0) { 2477895427bdSJames Smart bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, 2478895427bdSJames Smart phba->sli4_hba.hdr_rq->queue_id); 2479895427bdSJames Smart /* Match everything - rq_id0 */ 2480895427bdSJames Smart bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, 0); 2481895427bdSJames Smart bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0); 2482895427bdSJames Smart bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi, 0); 2483895427bdSJames Smart bf_set(lpfc_reg_fcfi_rctl_mask0, reg_fcfi, 0); 2484895427bdSJames Smart 248504c68496SJames Smart bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID); 2486895427bdSJames Smart 2487895427bdSJames Smart /* addr mode is bit wise inverted value of fcf addr_mode */ 2488895427bdSJames Smart bf_set(lpfc_reg_fcfi_mam, reg_fcfi, 2489895427bdSJames Smart (~phba->fcf.addr_mode) & 0x3); 24902d7dbc4cSJames Smart } else { 24912d7dbc4cSJames Smart /* This is ONLY for NVMET MRQ == 1 */ 24922d7dbc4cSJames Smart if (phba->cfg_nvmet_mrq != 1) 24932d7dbc4cSJames Smart return; 24942d7dbc4cSJames Smart 24952d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, 24962d7dbc4cSJames Smart phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id); 24972d7dbc4cSJames Smart /* Match type FCP - rq_id0 */ 24982d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, FC_TYPE_FCP); 24992d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0xff); 25002d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi, 25012d7dbc4cSJames Smart FC_RCTL_DD_UNSOL_CMD); 25022d7dbc4cSJames Smart 25032d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, 25042d7dbc4cSJames Smart phba->sli4_hba.hdr_rq->queue_id); 25052d7dbc4cSJames Smart /* Match everything else - rq_id1 */ 25062d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_type_match1, reg_fcfi, 0); 25072d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_type_mask1, reg_fcfi, 0); 25082d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_rctl_match1, reg_fcfi, 0); 25092d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_rctl_mask1, reg_fcfi, 0); 2510895427bdSJames Smart } 251104c68496SJames Smart bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID); 251204c68496SJames Smart bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID); 2513ecfd03c6SJames Smart bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, 2514ecfd03c6SJames Smart phba->fcf.current_rec.fcf_indx); 25153804dc84SJames Smart if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) { 251604c68496SJames Smart bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1); 2517ecfd03c6SJames Smart bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, 2518ecfd03c6SJames Smart phba->fcf.current_rec.vlan_id); 251904c68496SJames Smart } 252004c68496SJames Smart } 252104c68496SJames Smart 252204c68496SJames Smart /** 25232d7dbc4cSJames Smart * lpfc_reg_fcfi_mrq - Initialize the REG_FCFI_MRQ mailbox command 25242d7dbc4cSJames Smart * @phba: pointer to the hba structure containing the FCF index and RQ ID. 25252d7dbc4cSJames Smart * @mbox: pointer to lpfc mbox command to initialize. 25262d7dbc4cSJames Smart * @mode: 0 to register FCFI, 1 to register MRQs 25272d7dbc4cSJames Smart * 25282d7dbc4cSJames Smart * The REG_FCFI_MRQ mailbox command supports Fibre Channel Forwarders (FCFs). 25292d7dbc4cSJames Smart * The SLI Host uses the command to activate an FCF after it has acquired FCF 25302d7dbc4cSJames Smart * information via a READ_FCF mailbox command. This mailbox command also is used 25312d7dbc4cSJames Smart * to indicate where received unsolicited frames from this FCF will be sent. By 25322d7dbc4cSJames Smart * default this routine will set up the FCF to forward all unsolicited frames 25332d7dbc4cSJames Smart * the the RQ ID passed in the @phba. This can be overridden by the caller for 25342d7dbc4cSJames Smart * more complicated setups. 25352d7dbc4cSJames Smart **/ 25362d7dbc4cSJames Smart void 25372d7dbc4cSJames Smart lpfc_reg_fcfi_mrq(struct lpfc_hba *phba, struct lpfcMboxq *mbox, int mode) 25382d7dbc4cSJames Smart { 25392d7dbc4cSJames Smart struct lpfc_mbx_reg_fcfi_mrq *reg_fcfi; 25402d7dbc4cSJames Smart 25412d7dbc4cSJames Smart /* This is ONLY for MRQ */ 25422d7dbc4cSJames Smart if (phba->cfg_nvmet_mrq <= 1) 25432d7dbc4cSJames Smart return; 25442d7dbc4cSJames Smart 25452d7dbc4cSJames Smart memset(mbox, 0, sizeof(*mbox)); 25462d7dbc4cSJames Smart reg_fcfi = &mbox->u.mqe.un.reg_fcfi_mrq; 25472d7dbc4cSJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI_MRQ); 25482d7dbc4cSJames Smart if (mode == 0) { 25492d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_info_index, reg_fcfi, 25502d7dbc4cSJames Smart phba->fcf.current_rec.fcf_indx); 25512d7dbc4cSJames Smart if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) { 25522d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_vv, reg_fcfi, 1); 25532d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_vlan_tag, reg_fcfi, 25542d7dbc4cSJames Smart phba->fcf.current_rec.vlan_id); 25552d7dbc4cSJames Smart } 25562d7dbc4cSJames Smart return; 25572d7dbc4cSJames Smart } 25582d7dbc4cSJames Smart 25592d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rq_id0, reg_fcfi, 25602d7dbc4cSJames Smart phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id); 25612d7dbc4cSJames Smart /* Match NVME frames of type FCP (protocol NVME) - rq_id0 */ 25622d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_type_match0, reg_fcfi, FC_TYPE_FCP); 25632d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_type_mask0, reg_fcfi, 0xff); 25642d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rctl_match0, reg_fcfi, FC_RCTL_DD_UNSOL_CMD); 25652d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rctl_mask0, reg_fcfi, 0xff); 25662d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_ptc0, reg_fcfi, 1); 25672d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_pt0, reg_fcfi, 1); 25682d7dbc4cSJames Smart 25692d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_policy, reg_fcfi, 3); /* NVME connection id */ 25702d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_mode, reg_fcfi, 1); 25712d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_filter, reg_fcfi, 1); /* rq_id0 */ 25722d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_npairs, reg_fcfi, phba->cfg_nvmet_mrq); 25732d7dbc4cSJames Smart 25742d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rq_id1, reg_fcfi, 25752d7dbc4cSJames Smart phba->sli4_hba.hdr_rq->queue_id); 25762d7dbc4cSJames Smart /* Match everything - rq_id1 */ 25772d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_type_match1, reg_fcfi, 0); 25782d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_type_mask1, reg_fcfi, 0); 25792d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rctl_match1, reg_fcfi, 0); 25802d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rctl_mask1, reg_fcfi, 0); 25812d7dbc4cSJames Smart 25822d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rq_id2, reg_fcfi, REG_FCF_INVALID_QID); 25832d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rq_id3, reg_fcfi, REG_FCF_INVALID_QID); 25842d7dbc4cSJames Smart } 25852d7dbc4cSJames Smart 25862d7dbc4cSJames Smart /** 258704c68496SJames Smart * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command 258804c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 258904c68496SJames Smart * @fcfi: FCFI to be unregistered. 259004c68496SJames Smart * 259104c68496SJames Smart * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). 259204c68496SJames Smart * The SLI Host uses the command to inactivate an FCFI. 259304c68496SJames Smart **/ 259404c68496SJames Smart void 259504c68496SJames Smart lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi) 259604c68496SJames Smart { 259704c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 259804c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI); 259904c68496SJames Smart bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi); 260004c68496SJames Smart } 260104c68496SJames Smart 260204c68496SJames Smart /** 260304c68496SJames Smart * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command 260404c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 260504c68496SJames Smart * @ndlp: The nodelist structure that describes the RPI to resume. 260604c68496SJames Smart * 260704c68496SJames Smart * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a 260804c68496SJames Smart * link event. 260904c68496SJames Smart **/ 261004c68496SJames Smart void 261104c68496SJames Smart lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp) 261204c68496SJames Smart { 26136d368e53SJames Smart struct lpfc_hba *phba = ndlp->phba; 261404c68496SJames Smart struct lpfc_mbx_resume_rpi *resume_rpi; 261504c68496SJames Smart 261604c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 261704c68496SJames Smart resume_rpi = &mbox->u.mqe.un.resume_rpi; 261804c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI); 26196d368e53SJames Smart bf_set(lpfc_resume_rpi_index, resume_rpi, 26206d368e53SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 26218fa38513SJames Smart bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI); 26228fa38513SJames Smart resume_rpi->event_tag = ndlp->phba->fc_eventTag; 262304c68496SJames Smart } 262428baac74SJames Smart 262528baac74SJames Smart /** 262628baac74SJames Smart * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages 262728baac74SJames Smart * mailbox command. 262828baac74SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 262928baac74SJames Smart * 263028baac74SJames Smart * The PORT_CAPABILITIES supported pages mailbox command is issued to 263128baac74SJames Smart * retrieve the particular feature pages supported by the port. 263228baac74SJames Smart **/ 263328baac74SJames Smart void 263428baac74SJames Smart lpfc_supported_pages(struct lpfcMboxq *mbox) 263528baac74SJames Smart { 263628baac74SJames Smart struct lpfc_mbx_supp_pages *supp_pages; 263728baac74SJames Smart 263828baac74SJames Smart memset(mbox, 0, sizeof(*mbox)); 263928baac74SJames Smart supp_pages = &mbox->u.mqe.un.supp_pages; 264028baac74SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES); 264128baac74SJames Smart bf_set(cpn, supp_pages, LPFC_SUPP_PAGES); 264228baac74SJames Smart } 264328baac74SJames Smart 264428baac74SJames Smart /** 2645fedd3b7bSJames Smart * lpfc_pc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params mbox cmd. 264628baac74SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 264728baac74SJames Smart * 264828baac74SJames Smart * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to 264928baac74SJames Smart * retrieve the particular SLI4 features supported by the port. 265028baac74SJames Smart **/ 265128baac74SJames Smart void 2652fedd3b7bSJames Smart lpfc_pc_sli4_params(struct lpfcMboxq *mbox) 265328baac74SJames Smart { 2654fedd3b7bSJames Smart struct lpfc_mbx_pc_sli4_params *sli4_params; 265528baac74SJames Smart 265628baac74SJames Smart memset(mbox, 0, sizeof(*mbox)); 265728baac74SJames Smart sli4_params = &mbox->u.mqe.un.sli4_params; 265828baac74SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES); 265928baac74SJames Smart bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS); 266028baac74SJames Smart } 2661