1dea3101eS /******************************************************************* 2dea3101eS * This file is part of the Emulex Linux Device Driver for * 3c44ce173SJames.Smart@Emulex.Com * Fibre Channel Host Bus Adapters. * 4d080abe0SJames Smart * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * 5d080abe0SJames Smart * “Broadcom” refers to Broadcom Limited 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 */ 97cdcc2343SJames Smart pmb->context1 = (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; 142dea3101eS ctx = pmb->context2; 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; 154dea3101eS pmb->context2 = 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 */ 17597207482SJames Smart ctx = pmb->context2; 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; 18997207482SJames Smart pmb->context2 = 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 */ 307dea3101eS pmb->context1 = (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 516d38dd52cSJames Smart if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && 517d38dd52cSJames Smart mb->un.varInitLnk.link_flags & FLAGS_TOPOLOGY_MODE_LOOP) { 518d38dd52cSJames Smart /* Failover is not tried for Lancer G6 */ 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; 56076a95d75SJames Smart case LPFC_USER_LINK_SPEED_AUTO: 561dea3101eS default: 56276a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; 563dea3101eS break; 564dea3101eS } 565dea3101eS 566dea3101eS } 567dea3101eS else 568dea3101eS mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; 569dea3101eS 570dea3101eS mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK; 571dea3101eS mb->mbxOwner = OWN_HOST; 572dea3101eS mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA; 573dea3101eS return; 574dea3101eS } 575dea3101eS 576e59058c4SJames Smart /** 5773621a710SJames Smart * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters 578e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 579e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 580e59058c4SJames Smart * @vpi: virtual N_Port identifier. 581e59058c4SJames Smart * 582e59058c4SJames Smart * The read service parameter mailbox command is used to read the HBA port 583e59058c4SJames Smart * service parameters. The service parameters are read into the buffer 584e59058c4SJames Smart * specified directly by a BDE in the mailbox command. These service 585e59058c4SJames Smart * parameters may then be used to build the payload of an N_Port/F_POrt 586e59058c4SJames Smart * login request and reply (LOGI/ACC). 587e59058c4SJames Smart * 588e59058c4SJames Smart * This routine prepares the mailbox command for reading HBA port service 589e59058c4SJames Smart * parameters. The DMA memory is allocated in this function and the addresses 590e59058c4SJames Smart * are populated into the mailbox command for the HBA to DMA the service 591e59058c4SJames Smart * parameters into. 592e59058c4SJames Smart * 593e59058c4SJames Smart * Return codes 594e59058c4SJames Smart * 0 - Success 595e59058c4SJames Smart * 1 - DMA memory allocation failed 596e59058c4SJames Smart **/ 597dea3101eS int 59892d7f7b0SJames Smart lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi) 599dea3101eS { 600dea3101eS struct lpfc_dmabuf *mp; 601dea3101eS MAILBOX_t *mb; 602dea3101eS 60304c68496SJames Smart mb = &pmb->u.mb; 604dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 605dea3101eS 606dea3101eS mb->mbxOwner = OWN_HOST; 607dea3101eS 608dea3101eS /* Get a buffer to hold the HBAs Service Parameters */ 609dea3101eS 61098c9ea5cSJames Smart mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); 61198c9ea5cSJames Smart if (mp) 61298c9ea5cSJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 61398c9ea5cSJames Smart if (!mp || !mp->virt) { 614dea3101eS kfree(mp); 615dea3101eS mb->mbxCommand = MBX_READ_SPARM64; 616dea3101eS /* READ_SPARAM: no buffers */ 617e8b62011SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 618e8b62011SJames Smart "0301 READ_SPARAM: no buffers\n"); 61992d7f7b0SJames Smart return (1); 620dea3101eS } 621dea3101eS INIT_LIST_HEAD(&mp->list); 622dea3101eS mb->mbxCommand = MBX_READ_SPARM64; 623dea3101eS mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); 624dea3101eS mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys); 625dea3101eS mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys); 6266d368e53SJames Smart if (phba->sli_rev >= LPFC_SLI_REV3) 6276d368e53SJames Smart mb->un.varRdSparm.vpi = phba->vpi_ids[vpi]; 628dea3101eS 629dea3101eS /* save address for completion */ 630dea3101eS pmb->context1 = mp; 631dea3101eS 63292d7f7b0SJames Smart return (0); 633dea3101eS } 634dea3101eS 635e59058c4SJames Smart /** 6363621a710SJames Smart * lpfc_unreg_did - Prepare a mailbox command for unregistering DID 637e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 638e59058c4SJames Smart * @vpi: virtual N_Port identifier. 639e59058c4SJames Smart * @did: remote port identifier. 640e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 641e59058c4SJames Smart * 642e59058c4SJames Smart * The unregister DID mailbox command is used to unregister an N_Port/F_Port 643e59058c4SJames Smart * login for an unknown RPI by specifying the DID of a remote port. This 644e59058c4SJames Smart * command frees an RPI context in the HBA port. This has the effect of 645e59058c4SJames Smart * performing an implicit N_Port/F_Port logout. 646e59058c4SJames Smart * 647e59058c4SJames Smart * This routine prepares the mailbox command for unregistering a remote 648e59058c4SJames Smart * N_Port/F_Port (DID) login. 649e59058c4SJames Smart **/ 650dea3101eS void 65192d7f7b0SJames Smart lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did, 65292d7f7b0SJames Smart LPFC_MBOXQ_t * pmb) 653dea3101eS { 654dea3101eS MAILBOX_t *mb; 655dea3101eS 65604c68496SJames Smart mb = &pmb->u.mb; 657dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 658dea3101eS 659dea3101eS mb->un.varUnregDID.did = did; 66092d7f7b0SJames Smart mb->un.varUnregDID.vpi = vpi; 6616d368e53SJames Smart if ((vpi != 0xffff) && 6626d368e53SJames Smart (phba->sli_rev == LPFC_SLI_REV4)) 6636d368e53SJames Smart mb->un.varUnregDID.vpi = phba->vpi_ids[vpi]; 664dea3101eS 665dea3101eS mb->mbxCommand = MBX_UNREG_D_ID; 666dea3101eS mb->mbxOwner = OWN_HOST; 667dea3101eS return; 668dea3101eS } 669dea3101eS 670e59058c4SJames Smart /** 6713621a710SJames Smart * lpfc_read_config - Prepare a mailbox command for reading HBA configuration 672e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 673e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 674e59058c4SJames Smart * 675e59058c4SJames Smart * The read configuration mailbox command is used to read the HBA port 676e59058c4SJames Smart * configuration parameters. This mailbox command provides a method for 677e59058c4SJames Smart * seeing any parameters that may have changed via various configuration 678e59058c4SJames Smart * mailbox commands. 679e59058c4SJames Smart * 680e59058c4SJames Smart * This routine prepares the mailbox command for reading out HBA configuration 681e59058c4SJames Smart * parameters. 682e59058c4SJames Smart **/ 683dea3101eS void 684dea3101eS lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 685dea3101eS { 686dea3101eS MAILBOX_t *mb; 687dea3101eS 68804c68496SJames Smart mb = &pmb->u.mb; 689dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 690dea3101eS 691dea3101eS mb->mbxCommand = MBX_READ_CONFIG; 692dea3101eS mb->mbxOwner = OWN_HOST; 693dea3101eS return; 694dea3101eS } 695dea3101eS 696e59058c4SJames Smart /** 6973621a710SJames Smart * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats 698e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 699e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 700e59058c4SJames Smart * 701e59058c4SJames Smart * The read link status mailbox command is used to read the link status from 702e59058c4SJames Smart * the HBA. Link status includes all link-related error counters. These 703e59058c4SJames Smart * counters are maintained by the HBA and originated in the link hardware 704e59058c4SJames Smart * unit. Note that all of these counters wrap. 705e59058c4SJames Smart * 706e59058c4SJames Smart * This routine prepares the mailbox command for reading out HBA link status. 707e59058c4SJames Smart **/ 7087bb3b137SJamie Wellnitz void 7097bb3b137SJamie Wellnitz lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 7107bb3b137SJamie Wellnitz { 7117bb3b137SJamie Wellnitz MAILBOX_t *mb; 7127bb3b137SJamie Wellnitz 71304c68496SJames Smart mb = &pmb->u.mb; 7147bb3b137SJamie Wellnitz memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 7157bb3b137SJamie Wellnitz 7167bb3b137SJamie Wellnitz mb->mbxCommand = MBX_READ_LNK_STAT; 7177bb3b137SJamie Wellnitz mb->mbxOwner = OWN_HOST; 7187bb3b137SJamie Wellnitz return; 7197bb3b137SJamie Wellnitz } 7207bb3b137SJamie Wellnitz 721e59058c4SJames Smart /** 72204c68496SJames Smart * lpfc_reg_rpi - Prepare a mailbox command for registering remote login 723e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 724e59058c4SJames Smart * @vpi: virtual N_Port identifier. 725e59058c4SJames Smart * @did: remote port identifier. 726e59058c4SJames Smart * @param: pointer to memory holding the server parameters. 727e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 7284042629eSJames Smart * @rpi: the rpi to use in the registration (usually only used for SLI4. 729e59058c4SJames Smart * 730e59058c4SJames Smart * The registration login mailbox command is used to register an N_Port or 731e59058c4SJames Smart * F_Port login. This registration allows the HBA to cache the remote N_Port 732e59058c4SJames Smart * service parameters internally and thereby make the appropriate FC-2 733e59058c4SJames Smart * decisions. The remote port service parameters are handed off by the driver 734e59058c4SJames Smart * to the HBA using a descriptor entry that directly identifies a buffer in 735e59058c4SJames Smart * host memory. In exchange, the HBA returns an RPI identifier. 736e59058c4SJames Smart * 737e59058c4SJames Smart * This routine prepares the mailbox command for registering remote port login. 738e59058c4SJames Smart * The function allocates DMA buffer for passing the service parameters to the 739e59058c4SJames Smart * HBA with the mailbox command. 740e59058c4SJames Smart * 741e59058c4SJames Smart * Return codes 742e59058c4SJames Smart * 0 - Success 743e59058c4SJames Smart * 1 - DMA memory allocation failed 744e59058c4SJames Smart **/ 745dea3101eS int 74604c68496SJames Smart lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did, 7474042629eSJames Smart uint8_t *param, LPFC_MBOXQ_t *pmb, uint16_t rpi) 748dea3101eS { 74904c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 750dea3101eS uint8_t *sparam; 751dea3101eS struct lpfc_dmabuf *mp; 752dea3101eS 753dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 754dea3101eS 755dea3101eS mb->un.varRegLogin.rpi = 0; 7566d368e53SJames Smart if (phba->sli_rev == LPFC_SLI_REV4) 7576d368e53SJames Smart mb->un.varRegLogin.rpi = phba->sli4_hba.rpi_ids[rpi]; 7586d368e53SJames Smart if (phba->sli_rev >= LPFC_SLI_REV3) 7596d368e53SJames Smart mb->un.varRegLogin.vpi = phba->vpi_ids[vpi]; 760dea3101eS mb->un.varRegLogin.did = did; 761dea3101eS mb->mbxOwner = OWN_HOST; 762dea3101eS /* Get a buffer to hold NPorts Service Parameters */ 76398c9ea5cSJames Smart mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); 76498c9ea5cSJames Smart if (mp) 76598c9ea5cSJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 76698c9ea5cSJames Smart if (!mp || !mp->virt) { 767dea3101eS kfree(mp); 768dea3101eS mb->mbxCommand = MBX_REG_LOGIN64; 769dea3101eS /* REG_LOGIN: no buffers */ 77092d7f7b0SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 771e8b62011SJames Smart "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, " 7724042629eSJames Smart "rpi x%x\n", vpi, did, rpi); 7736d368e53SJames Smart return 1; 774dea3101eS } 775dea3101eS INIT_LIST_HEAD(&mp->list); 776dea3101eS sparam = mp->virt; 777dea3101eS 778dea3101eS /* Copy param's into a new buffer */ 779dea3101eS memcpy(sparam, param, sizeof (struct serv_parm)); 780dea3101eS 781dea3101eS /* save address for completion */ 782dea3101eS pmb->context1 = (uint8_t *) mp; 783dea3101eS 784dea3101eS mb->mbxCommand = MBX_REG_LOGIN64; 785dea3101eS mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); 786dea3101eS mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys); 787dea3101eS mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys); 788dea3101eS 7896d368e53SJames Smart return 0; 790dea3101eS } 791dea3101eS 792e59058c4SJames Smart /** 7933621a710SJames Smart * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login 794e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 795e59058c4SJames Smart * @vpi: virtual N_Port identifier. 796e59058c4SJames Smart * @rpi: remote port identifier 797e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 798e59058c4SJames Smart * 799e59058c4SJames Smart * The unregistration login mailbox command is used to unregister an N_Port 800e59058c4SJames Smart * or F_Port login. This command frees an RPI context in the HBA. It has the 801e59058c4SJames Smart * effect of performing an implicit N_Port/F_Port logout. 802e59058c4SJames Smart * 803e59058c4SJames Smart * This routine prepares the mailbox command for unregistering remote port 804e59058c4SJames Smart * login. 8056d368e53SJames Smart * 8066d368e53SJames Smart * For SLI4 ports, the rpi passed to this function must be the physical 8076d368e53SJames Smart * rpi value, not the logical index. 808e59058c4SJames Smart **/ 809dea3101eS void 81092d7f7b0SJames Smart lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi, 81192d7f7b0SJames Smart LPFC_MBOXQ_t * pmb) 812dea3101eS { 813dea3101eS MAILBOX_t *mb; 814dea3101eS 81504c68496SJames Smart mb = &pmb->u.mb; 816dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 817dea3101eS 8186d368e53SJames Smart mb->un.varUnregLogin.rpi = rpi; 819dea3101eS mb->un.varUnregLogin.rsvd1 = 0; 8206d368e53SJames Smart if (phba->sli_rev >= LPFC_SLI_REV3) 8216d368e53SJames Smart mb->un.varUnregLogin.vpi = phba->vpi_ids[vpi]; 822dea3101eS 823dea3101eS mb->mbxCommand = MBX_UNREG_LOGIN; 824dea3101eS mb->mbxOwner = OWN_HOST; 82504c68496SJames Smart 826dea3101eS return; 827dea3101eS } 828dea3101eS 829e59058c4SJames Smart /** 8305af5eee7SJames Smart * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA. 8315af5eee7SJames Smart * @vport: pointer to a vport object. 8325af5eee7SJames Smart * 8335af5eee7SJames Smart * This routine sends mailbox command to unregister all active RPIs for 8345af5eee7SJames Smart * a vport. 8355af5eee7SJames Smart **/ 8365af5eee7SJames Smart void 8375af5eee7SJames Smart lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport) 8385af5eee7SJames Smart { 8395af5eee7SJames Smart struct lpfc_hba *phba = vport->phba; 8405af5eee7SJames Smart LPFC_MBOXQ_t *mbox; 8415af5eee7SJames Smart int rc; 8425af5eee7SJames Smart 8435af5eee7SJames Smart mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 8445af5eee7SJames Smart if (mbox) { 8456d368e53SJames Smart /* 8466d368e53SJames Smart * For SLI4 functions, the rpi field is overloaded for 8476d368e53SJames Smart * the vport context unreg all. This routine passes 8486d368e53SJames Smart * 0 for the rpi field in lpfc_unreg_login for compatibility 8496d368e53SJames Smart * with SLI3 and then overrides the rpi field with the 8506d368e53SJames Smart * expected value for SLI4. 8516d368e53SJames Smart */ 8526d368e53SJames Smart lpfc_unreg_login(phba, vport->vpi, phba->vpi_ids[vport->vpi], 8536d368e53SJames Smart mbox); 8545af5eee7SJames Smart mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000; 8555af5eee7SJames Smart mbox->vport = vport; 8565af5eee7SJames Smart mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 8575af5eee7SJames Smart mbox->context1 = NULL; 8585af5eee7SJames Smart rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 8595af5eee7SJames Smart if (rc == MBX_NOT_FINISHED) 8605af5eee7SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 8615af5eee7SJames Smart } 8625af5eee7SJames Smart } 8635af5eee7SJames Smart 8645af5eee7SJames Smart /** 8653621a710SJames Smart * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier 866e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 867e59058c4SJames Smart * @vpi: virtual N_Port identifier. 868e59058c4SJames Smart * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port). 869e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 870e59058c4SJames Smart * 871e59058c4SJames Smart * The registration vport identifier mailbox command is used to activate a 872e59058c4SJames Smart * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the 873e59058c4SJames Smart * N_Port_ID against the information in the selected virtual N_Port context 874e59058c4SJames Smart * block and marks it active to allow normal processing of IOCB commands and 875e59058c4SJames Smart * received unsolicited exchanges. 876e59058c4SJames Smart * 877e59058c4SJames Smart * This routine prepares the mailbox command for registering a virtual N_Port. 878e59058c4SJames Smart **/ 87992d7f7b0SJames Smart void 88004c68496SJames Smart lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb) 88192d7f7b0SJames Smart { 88204c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 88338b92ef8SJames Smart struct lpfc_hba *phba = vport->phba; 88492d7f7b0SJames Smart 88592d7f7b0SJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 88638b92ef8SJames Smart /* 88738b92ef8SJames Smart * Set the re-reg VPI bit for f/w to update the MAC address. 88838b92ef8SJames Smart */ 88938b92ef8SJames Smart if ((phba->sli_rev == LPFC_SLI_REV4) && 89038b92ef8SJames Smart !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) 89138b92ef8SJames Smart mb->un.varRegVpi.upd = 1; 8926d368e53SJames Smart 8936d368e53SJames Smart mb->un.varRegVpi.vpi = phba->vpi_ids[vport->vpi]; 89404c68496SJames Smart mb->un.varRegVpi.sid = vport->fc_myDID; 8956d368e53SJames Smart if (phba->sli_rev == LPFC_SLI_REV4) 8966d368e53SJames Smart mb->un.varRegVpi.vfi = phba->sli4_hba.vfi_ids[vport->vfi]; 8976d368e53SJames Smart else 89804c68496SJames Smart mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base; 899c868595dSJames Smart memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname, 900c868595dSJames Smart sizeof(struct lpfc_name)); 901c868595dSJames Smart mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]); 902c868595dSJames Smart mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]); 90392d7f7b0SJames Smart 90492d7f7b0SJames Smart mb->mbxCommand = MBX_REG_VPI; 90592d7f7b0SJames Smart mb->mbxOwner = OWN_HOST; 90692d7f7b0SJames Smart return; 90792d7f7b0SJames Smart 90892d7f7b0SJames Smart } 90992d7f7b0SJames Smart 910e59058c4SJames Smart /** 9113621a710SJames Smart * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id 912e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 913e59058c4SJames Smart * @vpi: virtual N_Port identifier. 914e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 915e59058c4SJames Smart * 916e59058c4SJames Smart * The unregistration vport identifier mailbox command is used to inactivate 917e59058c4SJames Smart * a virtual N_Port. The driver must have logged out and unregistered all 918e59058c4SJames Smart * remote N_Ports to abort any activity on the virtual N_Port. The HBA will 919e59058c4SJames Smart * unregisters any default RPIs associated with the specified vpi, aborting 920e59058c4SJames Smart * any active exchanges. The HBA will post the mailbox response after making 921e59058c4SJames Smart * the virtual N_Port inactive. 922e59058c4SJames Smart * 923e59058c4SJames Smart * This routine prepares the mailbox command for unregistering a virtual 924e59058c4SJames Smart * N_Port. 925e59058c4SJames Smart **/ 92692d7f7b0SJames Smart void 92792d7f7b0SJames Smart lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb) 92892d7f7b0SJames Smart { 92904c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 93092d7f7b0SJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 93192d7f7b0SJames Smart 9326d368e53SJames Smart if (phba->sli_rev == LPFC_SLI_REV3) 9336d368e53SJames Smart mb->un.varUnregVpi.vpi = phba->vpi_ids[vpi]; 9346d368e53SJames Smart else if (phba->sli_rev >= LPFC_SLI_REV4) 9356d368e53SJames Smart mb->un.varUnregVpi.sli4_vpi = phba->vpi_ids[vpi]; 93692d7f7b0SJames Smart 93792d7f7b0SJames Smart mb->mbxCommand = MBX_UNREG_VPI; 93892d7f7b0SJames Smart mb->mbxOwner = OWN_HOST; 93992d7f7b0SJames Smart return; 94092d7f7b0SJames Smart 94192d7f7b0SJames Smart } 94292d7f7b0SJames Smart 943e59058c4SJames Smart /** 9443621a710SJames Smart * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB) 945e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 946e59058c4SJames Smart * 947e59058c4SJames Smart * This routine sets up and initializes the IOCB rings in the Port Control 948e59058c4SJames Smart * Block (PCB). 949e59058c4SJames Smart **/ 950dea3101eS static void 951dea3101eS lpfc_config_pcb_setup(struct lpfc_hba * phba) 952dea3101eS { 953dea3101eS struct lpfc_sli *psli = &phba->sli; 954dea3101eS struct lpfc_sli_ring *pring; 95534b02dcdSJames Smart PCB_t *pcbp = phba->pcb; 956dea3101eS dma_addr_t pdma_addr; 957dea3101eS uint32_t offset; 9582e0fef85SJames Smart uint32_t iocbCnt = 0; 959dea3101eS int i; 960dea3101eS 961dea3101eS pcbp->maxRing = (psli->num_rings - 1); 962dea3101eS 963dea3101eS for (i = 0; i < psli->num_rings; i++) { 964895427bdSJames Smart pring = &psli->sli3_ring[i]; 9652e0fef85SJames Smart 9667e56aa25SJames Smart pring->sli.sli3.sizeCiocb = 9677e56aa25SJames Smart phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE : 968ed957684SJames Smart SLI2_IOCB_CMD_SIZE; 9697e56aa25SJames Smart pring->sli.sli3.sizeRiocb = 9707e56aa25SJames Smart phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE : 971ed957684SJames Smart SLI2_IOCB_RSP_SIZE; 972dea3101eS /* A ring MUST have both cmd and rsp entries defined to be 973dea3101eS valid */ 9747e56aa25SJames Smart if ((pring->sli.sli3.numCiocb == 0) || 9757e56aa25SJames Smart (pring->sli.sli3.numRiocb == 0)) { 976dea3101eS pcbp->rdsc[i].cmdEntries = 0; 977dea3101eS pcbp->rdsc[i].rspEntries = 0; 978dea3101eS pcbp->rdsc[i].cmdAddrHigh = 0; 979dea3101eS pcbp->rdsc[i].rspAddrHigh = 0; 980dea3101eS pcbp->rdsc[i].cmdAddrLow = 0; 981dea3101eS pcbp->rdsc[i].rspAddrLow = 0; 9827e56aa25SJames Smart pring->sli.sli3.cmdringaddr = NULL; 9837e56aa25SJames Smart pring->sli.sli3.rspringaddr = NULL; 984dea3101eS continue; 985dea3101eS } 986dea3101eS /* Command ring setup for ring */ 9877e56aa25SJames Smart pring->sli.sli3.cmdringaddr = (void *)&phba->IOCBs[iocbCnt]; 9887e56aa25SJames Smart pcbp->rdsc[i].cmdEntries = pring->sli.sli3.numCiocb; 989dea3101eS 99034b02dcdSJames Smart offset = (uint8_t *) &phba->IOCBs[iocbCnt] - 99134b02dcdSJames Smart (uint8_t *) phba->slim2p.virt; 99234b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 993dea3101eS pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr); 994dea3101eS pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr); 9957e56aa25SJames Smart iocbCnt += pring->sli.sli3.numCiocb; 996dea3101eS 997dea3101eS /* Response ring setup for ring */ 9987e56aa25SJames Smart pring->sli.sli3.rspringaddr = (void *) &phba->IOCBs[iocbCnt]; 999dea3101eS 10007e56aa25SJames Smart pcbp->rdsc[i].rspEntries = pring->sli.sli3.numRiocb; 100134b02dcdSJames Smart offset = (uint8_t *)&phba->IOCBs[iocbCnt] - 100234b02dcdSJames Smart (uint8_t *)phba->slim2p.virt; 100334b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 1004dea3101eS pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr); 1005dea3101eS pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr); 10067e56aa25SJames Smart iocbCnt += pring->sli.sli3.numRiocb; 1007dea3101eS } 1008dea3101eS } 1009dea3101eS 1010e59058c4SJames Smart /** 10113621a710SJames Smart * lpfc_read_rev - Prepare a mailbox command for reading HBA revision 1012e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1013e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1014e59058c4SJames Smart * 1015e59058c4SJames Smart * The read revision mailbox command is used to read the revision levels of 1016e59058c4SJames Smart * the HBA components. These components include hardware units, resident 1017e59058c4SJames Smart * firmware, and available firmware. HBAs that supports SLI-3 mode of 1018e59058c4SJames Smart * operation provide different response information depending on the version 1019e59058c4SJames Smart * requested by the driver. 1020e59058c4SJames Smart * 1021e59058c4SJames Smart * This routine prepares the mailbox command for reading HBA revision 1022e59058c4SJames Smart * information. 1023e59058c4SJames Smart **/ 1024dea3101eS void 1025dea3101eS lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 1026dea3101eS { 102704c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1028dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 1029dea3101eS mb->un.varRdRev.cv = 1; 1030ed957684SJames Smart mb->un.varRdRev.v3req = 1; /* Request SLI3 info */ 1031dea3101eS mb->mbxCommand = MBX_READ_REV; 1032dea3101eS mb->mbxOwner = OWN_HOST; 1033dea3101eS return; 1034dea3101eS } 1035dea3101eS 1036d7c47992SJames Smart void 1037d7c47992SJames Smart lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 1038d7c47992SJames Smart { 1039d7c47992SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1040d7c47992SJames Smart struct lpfc_mqe *mqe; 1041d7c47992SJames Smart 1042d7c47992SJames Smart switch (mb->mbxCommand) { 1043d7c47992SJames Smart case MBX_READ_REV: 1044d7c47992SJames Smart mqe = &pmb->u.mqe; 1045d7c47992SJames Smart lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name, 1046d7c47992SJames Smart mqe->un.read_rev.fw_name, 16); 1047d7c47992SJames Smart lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name, 1048d7c47992SJames Smart mqe->un.read_rev.ulp_fw_name, 16); 1049d7c47992SJames Smart break; 1050d7c47992SJames Smart default: 1051d7c47992SJames Smart break; 1052d7c47992SJames Smart } 1053d7c47992SJames Smart return; 1054d7c47992SJames Smart } 1055d7c47992SJames Smart 1056e59058c4SJames Smart /** 10573621a710SJames Smart * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2 1058e59058c4SJames Smart * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. 1059e59058c4SJames Smart * @hbq_desc: pointer to the HBQ selection profile descriptor. 1060e59058c4SJames Smart * 1061e59058c4SJames Smart * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA 1062e59058c4SJames Smart * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs 1063e59058c4SJames Smart * the Sequence Length Test using the fields in the Selection Profile 2 1064e59058c4SJames Smart * extension in words 20:31. 1065e59058c4SJames Smart **/ 1066ed957684SJames Smart static void 1067ed957684SJames Smart lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb, 1068ed957684SJames Smart struct lpfc_hbq_init *hbq_desc) 1069ed957684SJames Smart { 1070ed957684SJames Smart hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt; 1071ed957684SJames Smart hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen; 1072ed957684SJames Smart hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff; 1073ed957684SJames Smart } 1074ed957684SJames Smart 1075e59058c4SJames Smart /** 10763621a710SJames Smart * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3 1077e59058c4SJames Smart * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. 1078e59058c4SJames Smart * @hbq_desc: pointer to the HBQ selection profile descriptor. 1079e59058c4SJames Smart * 1080e59058c4SJames Smart * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA 1081e59058c4SJames Smart * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs 1082e59058c4SJames Smart * the Sequence Length Test and Byte Field Test using the fields in the 1083e59058c4SJames Smart * Selection Profile 3 extension in words 20:31. 1084e59058c4SJames Smart **/ 1085ed957684SJames Smart static void 1086ed957684SJames Smart lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb, 1087ed957684SJames Smart struct lpfc_hbq_init *hbq_desc) 1088ed957684SJames Smart { 1089ed957684SJames Smart hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt; 1090ed957684SJames Smart hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen; 1091ed957684SJames Smart hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff; 1092ed957684SJames Smart hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff; 1093ed957684SJames Smart memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch, 1094ed957684SJames Smart sizeof(hbqmb->profiles.profile3.cmdmatch)); 1095ed957684SJames Smart } 1096ed957684SJames Smart 1097e59058c4SJames Smart /** 10983621a710SJames Smart * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5 1099e59058c4SJames Smart * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. 1100e59058c4SJames Smart * @hbq_desc: pointer to the HBQ selection profile descriptor. 1101e59058c4SJames Smart * 1102e59058c4SJames Smart * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The 1103e59058c4SJames Smart * HBA tests the initial frame of an incoming sequence using the frame's 1104e59058c4SJames Smart * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test 1105e59058c4SJames Smart * and Byte Field Test using the fields in the Selection Profile 5 extension 1106e59058c4SJames Smart * words 20:31. 1107e59058c4SJames Smart **/ 1108ed957684SJames Smart static void 1109ed957684SJames Smart lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb, 1110ed957684SJames Smart struct lpfc_hbq_init *hbq_desc) 1111ed957684SJames Smart { 1112ed957684SJames Smart hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt; 1113ed957684SJames Smart hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen; 1114ed957684SJames Smart hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff; 1115ed957684SJames Smart hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff; 1116ed957684SJames Smart memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch, 1117ed957684SJames Smart sizeof(hbqmb->profiles.profile5.cmdmatch)); 1118ed957684SJames Smart } 1119ed957684SJames Smart 1120e59058c4SJames Smart /** 11213621a710SJames Smart * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ 1122e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1123e59058c4SJames Smart * @id: HBQ identifier. 1124e59058c4SJames Smart * @hbq_desc: pointer to the HBA descriptor data structure. 1125e59058c4SJames Smart * @hbq_entry_index: index of the HBQ entry data structures. 1126e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1127e59058c4SJames Smart * 1128e59058c4SJames Smart * The configure HBQ (Host Buffer Queue) mailbox command is used to configure 1129e59058c4SJames Smart * an HBQ. The configuration binds events that require buffers to a particular 1130e59058c4SJames Smart * ring and HBQ based on a selection profile. 1131e59058c4SJames Smart * 1132e59058c4SJames Smart * This routine prepares the mailbox command for configuring an HBQ. 1133e59058c4SJames Smart **/ 1134ed957684SJames Smart void 113551ef4c26SJames Smart lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id, 113651ef4c26SJames Smart struct lpfc_hbq_init *hbq_desc, 1137ed957684SJames Smart uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb) 1138ed957684SJames Smart { 1139ed957684SJames Smart int i; 114004c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1141ed957684SJames Smart struct config_hbq_var *hbqmb = &mb->un.varCfgHbq; 1142ed957684SJames Smart 1143ed957684SJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 114451ef4c26SJames Smart hbqmb->hbqId = id; 1145ed957684SJames Smart hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */ 1146ed957684SJames Smart hbqmb->recvNotify = hbq_desc->rn; /* Receive 1147ed957684SJames Smart * Notification */ 1148ed957684SJames Smart hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks 1149ed957684SJames Smart * # in words 0-19 */ 1150ed957684SJames Smart hbqmb->profile = hbq_desc->profile; /* Selection profile: 1151ed957684SJames Smart * 0 = all, 1152ed957684SJames Smart * 7 = logentry */ 1153ed957684SJames Smart hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring 1154ed957684SJames Smart * e.g. Ring0=b0001, 1155ed957684SJames Smart * ring2=b0100 */ 1156ed957684SJames Smart hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4 1157ed957684SJames Smart * or 5 */ 1158ed957684SJames Smart hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this 1159ed957684SJames Smart * HBQ will be used 1160ed957684SJames Smart * for LogEntry 1161ed957684SJames Smart * buffers */ 1162ed957684SJames Smart hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) + 1163ed957684SJames Smart hbq_entry_index * sizeof(struct lpfc_hbq_entry); 1164ed957684SJames Smart hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys); 1165ed957684SJames Smart 1166ed957684SJames Smart mb->mbxCommand = MBX_CONFIG_HBQ; 1167ed957684SJames Smart mb->mbxOwner = OWN_HOST; 1168ed957684SJames Smart 1169ed957684SJames Smart /* Copy info for profiles 2,3,5. Other 1170ed957684SJames Smart * profiles this area is reserved 1171ed957684SJames Smart */ 1172ed957684SJames Smart if (hbq_desc->profile == 2) 1173ed957684SJames Smart lpfc_build_hbq_profile2(hbqmb, hbq_desc); 1174ed957684SJames Smart else if (hbq_desc->profile == 3) 1175ed957684SJames Smart lpfc_build_hbq_profile3(hbqmb, hbq_desc); 1176ed957684SJames Smart else if (hbq_desc->profile == 5) 1177ed957684SJames Smart lpfc_build_hbq_profile5(hbqmb, hbq_desc); 1178ed957684SJames Smart 1179ed957684SJames Smart /* Return if no rctl / type masks for this HBQ */ 1180ed957684SJames Smart if (!hbq_desc->mask_count) 1181ed957684SJames Smart return; 1182ed957684SJames Smart 1183ed957684SJames Smart /* Otherwise we setup specific rctl / type masks for this HBQ */ 1184ed957684SJames Smart for (i = 0; i < hbq_desc->mask_count; i++) { 1185ed957684SJames Smart hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch; 1186ed957684SJames Smart hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask; 1187ed957684SJames Smart hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch; 1188ed957684SJames Smart hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask; 1189ed957684SJames Smart } 1190ed957684SJames Smart 1191ed957684SJames Smart return; 1192ed957684SJames Smart } 1193ed957684SJames Smart 1194e59058c4SJames Smart /** 11953621a710SJames Smart * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring 1196e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1197e59058c4SJames Smart * @ring: 1198e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1199e59058c4SJames Smart * 1200e59058c4SJames Smart * The configure ring mailbox command is used to configure an IOCB ring. This 1201e59058c4SJames Smart * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the 1202e59058c4SJames Smart * ring. This is used to map incoming sequences to a particular ring whose 1203e59058c4SJames Smart * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not 1204e59058c4SJames Smart * attempt to configure a ring whose number is greater than the number 1205e59058c4SJames Smart * specified in the Port Control Block (PCB). It is an error to issue the 1206e59058c4SJames Smart * configure ring command more than once with the same ring number. The HBA 1207e59058c4SJames Smart * returns an error if the driver attempts this. 1208e59058c4SJames Smart * 1209e59058c4SJames Smart * This routine prepares the mailbox command for configuring IOCB ring. 1210e59058c4SJames Smart **/ 1211dea3101eS void 1212dea3101eS lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb) 1213dea3101eS { 1214dea3101eS int i; 121504c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1216dea3101eS struct lpfc_sli *psli; 1217dea3101eS struct lpfc_sli_ring *pring; 1218dea3101eS 1219dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 1220dea3101eS 1221dea3101eS mb->un.varCfgRing.ring = ring; 1222dea3101eS mb->un.varCfgRing.maxOrigXchg = 0; 1223dea3101eS mb->un.varCfgRing.maxRespXchg = 0; 1224dea3101eS mb->un.varCfgRing.recvNotify = 1; 1225dea3101eS 1226dea3101eS psli = &phba->sli; 1227895427bdSJames Smart pring = &psli->sli3_ring[ring]; 1228dea3101eS mb->un.varCfgRing.numMask = pring->num_mask; 1229dea3101eS mb->mbxCommand = MBX_CONFIG_RING; 1230dea3101eS mb->mbxOwner = OWN_HOST; 1231dea3101eS 1232dea3101eS /* Is this ring configured for a specific profile */ 1233dea3101eS if (pring->prt[0].profile) { 1234dea3101eS mb->un.varCfgRing.profile = pring->prt[0].profile; 1235dea3101eS return; 1236dea3101eS } 1237dea3101eS 1238dea3101eS /* Otherwise we setup specific rctl / type masks for this ring */ 1239dea3101eS for (i = 0; i < pring->num_mask; i++) { 1240dea3101eS mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl; 12416a9c52cfSJames Smart if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ) 1242dea3101eS mb->un.varCfgRing.rrRegs[i].rmask = 0xff; 1243dea3101eS else 1244dea3101eS mb->un.varCfgRing.rrRegs[i].rmask = 0xfe; 1245dea3101eS mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type; 1246dea3101eS mb->un.varCfgRing.rrRegs[i].tmask = 0xff; 1247dea3101eS } 1248dea3101eS 1249dea3101eS return; 1250dea3101eS } 1251dea3101eS 1252e59058c4SJames Smart /** 12533621a710SJames Smart * lpfc_config_port - Prepare a mailbox command for configuring port 1254e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1255e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1256e59058c4SJames Smart * 1257e59058c4SJames Smart * The configure port mailbox command is used to identify the Port Control 1258e59058c4SJames Smart * Block (PCB) in the driver memory. After this command is issued, the 1259e59058c4SJames Smart * driver must not access the mailbox in the HBA without first resetting 1260e59058c4SJames Smart * the HBA. The HBA may copy the PCB information to internal storage for 1261e59058c4SJames Smart * subsequent use; the driver can not change the PCB information unless it 1262e59058c4SJames Smart * resets the HBA. 1263e59058c4SJames Smart * 1264e59058c4SJames Smart * This routine prepares the mailbox command for configuring port. 1265e59058c4SJames Smart **/ 1266dea3101eS void 1267dea3101eS lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 1268dea3101eS { 1269ed957684SJames Smart MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr; 127004c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1271dea3101eS dma_addr_t pdma_addr; 1272dea3101eS uint32_t bar_low, bar_high; 1273dea3101eS size_t offset; 12744cc2da1dSJames.Smart@Emulex.Com struct lpfc_hgp hgp; 1275f91b392cSJames.Smart@Emulex.Com int i; 1276ed957684SJames Smart uint32_t pgp_offset; 1277dea3101eS 1278dea3101eS memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 1279dea3101eS mb->mbxCommand = MBX_CONFIG_PORT; 1280dea3101eS mb->mbxOwner = OWN_HOST; 1281dea3101eS 1282dea3101eS mb->un.varCfgPort.pcbLen = sizeof(PCB_t); 1283dea3101eS 128434b02dcdSJames Smart offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt; 128534b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 1286dea3101eS mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr); 1287dea3101eS mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr); 1288dea3101eS 128997207482SJames Smart /* Always Host Group Pointer is in SLIM */ 129097207482SJames Smart mb->un.varCfgPort.hps = 1; 129197207482SJames Smart 1292ed957684SJames Smart /* If HBA supports SLI=3 ask for it */ 1293ed957684SJames Smart 129404c68496SJames Smart if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) { 1295e2a0a9d6SJames Smart if (phba->cfg_enable_bg) 1296e2a0a9d6SJames Smart mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */ 1297ab56dc2eSJames Smart if (phba->cfg_enable_dss) 129804c68496SJames Smart mb->un.varCfgPort.cdss = 1; /* Configure Security */ 1299ed957684SJames Smart mb->un.varCfgPort.cerbm = 1; /* Request HBQs */ 130034b02dcdSJames Smart mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */ 130151ef4c26SJames Smart mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count(); 130278b2d852SJames Smart if (phba->max_vpi && phba->cfg_enable_npiv && 130392d7f7b0SJames Smart phba->vpd.sli3Feat.cmv) { 130404c68496SJames Smart mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI; 130592d7f7b0SJames Smart mb->un.varCfgPort.cmv = 1; 130692d7f7b0SJames Smart } else 130792d7f7b0SJames Smart mb->un.varCfgPort.max_vpi = phba->max_vpi = 0; 130892d7f7b0SJames Smart } else 130904c68496SJames Smart phba->sli_rev = LPFC_SLI_REV2; 131092d7f7b0SJames Smart mb->un.varCfgPort.sli_mode = phba->sli_rev; 1311ed957684SJames Smart 1312cb69f7deSJames Smart /* If this is an SLI3 port, configure async status notification. */ 1313cb69f7deSJames Smart if (phba->sli_rev == LPFC_SLI_REV3) 1314cb69f7deSJames Smart mb->un.varCfgPort.casabt = 1; 1315cb69f7deSJames Smart 1316dea3101eS /* Now setup pcb */ 131734b02dcdSJames Smart phba->pcb->type = TYPE_NATIVE_SLI2; 131834b02dcdSJames Smart phba->pcb->feature = FEATURE_INITIAL_SLI2; 1319dea3101eS 1320dea3101eS /* Setup Mailbox pointers */ 13217a470277SJames Smart phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE; 132234b02dcdSJames Smart offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt; 132334b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 132434b02dcdSJames Smart phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr); 132534b02dcdSJames Smart phba->pcb->mbAddrLow = putPaddrLow(pdma_addr); 1326dea3101eS 1327dea3101eS /* 1328dea3101eS * Setup Host Group ring pointer. 1329dea3101eS * 1330dea3101eS * For efficiency reasons, the ring get/put pointers can be 1331dea3101eS * placed in adapter memory (SLIM) rather than in host memory. 1332dea3101eS * This allows firmware to avoid PCI reads/writes when updating 1333dea3101eS * and checking pointers. 1334dea3101eS * 1335dea3101eS * The firmware recognizes the use of SLIM memory by comparing 1336dea3101eS * the address of the get/put pointers structure with that of 1337dea3101eS * the SLIM BAR (BAR0). 1338dea3101eS * 1339dea3101eS * Caution: be sure to use the PCI config space value of BAR0/BAR1 1340dea3101eS * (the hardware's view of the base address), not the OS's 1341dea3101eS * value of pci_resource_start() as the OS value may be a cookie 1342dea3101eS * for ioremap/iomap. 1343dea3101eS */ 1344dea3101eS 1345dea3101eS 1346dea3101eS pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low); 1347dea3101eS pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high); 1348dea3101eS 1349ed957684SJames Smart /* 1350ed957684SJames Smart * Set up HGP - Port Memory 1351ed957684SJames Smart * 1352ed957684SJames Smart * The port expects the host get/put pointers to reside in memory 1353ed957684SJames Smart * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes) 1354ed957684SJames Smart * area of SLIM. In SLI-2 mode, there's an additional 16 reserved 1355ed957684SJames Smart * words (0x40 bytes). This area is not reserved if HBQs are 1356ed957684SJames Smart * configured in SLI-3. 1357ed957684SJames Smart * 1358ed957684SJames Smart * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80 1359ed957684SJames Smart * RR0Get 0xc4 0x84 1360ed957684SJames Smart * CR1Put 0xc8 0x88 1361ed957684SJames Smart * RR1Get 0xcc 0x8c 1362ed957684SJames Smart * CR2Put 0xd0 0x90 1363ed957684SJames Smart * RR2Get 0xd4 0x94 1364ed957684SJames Smart * CR3Put 0xd8 0x98 1365ed957684SJames Smart * RR3Get 0xdc 0x9c 1366ed957684SJames Smart * 1367ed957684SJames Smart * Reserved 0xa0-0xbf 1368ed957684SJames Smart * If HBQs configured: 1369ed957684SJames Smart * HBQ 0 Put ptr 0xc0 1370ed957684SJames Smart * HBQ 1 Put ptr 0xc4 1371ed957684SJames Smart * HBQ 2 Put ptr 0xc8 1372ed957684SJames Smart * ...... 1373ed957684SJames Smart * HBQ(M-1)Put Pointer 0xc0+(M-1)*4 1374ed957684SJames Smart * 1375ed957684SJames Smart */ 1376ed957684SJames Smart 13777a470277SJames Smart if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) { 13787a470277SJames Smart phba->host_gp = &phba->mbox->us.s2.host[0]; 13797a470277SJames Smart phba->hbq_put = NULL; 13807a470277SJames Smart offset = (uint8_t *)&phba->mbox->us.s2.host - 13817a470277SJames Smart (uint8_t *)phba->slim2p.virt; 13827a470277SJames Smart pdma_addr = phba->slim2p.phys + offset; 13837a470277SJames Smart phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr); 13847a470277SJames Smart phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr); 13857a470277SJames Smart } else { 13867a470277SJames Smart /* Always Host Group Pointer is in SLIM */ 13877a470277SJames Smart mb->un.varCfgPort.hps = 1; 13887a470277SJames Smart 1389ed957684SJames Smart if (phba->sli_rev == 3) { 1390ed957684SJames Smart phba->host_gp = &mb_slim->us.s3.host[0]; 1391ed957684SJames Smart phba->hbq_put = &mb_slim->us.s3.hbq_put[0]; 1392ed957684SJames Smart } else { 1393ed957684SJames Smart phba->host_gp = &mb_slim->us.s2.host[0]; 1394ed957684SJames Smart phba->hbq_put = NULL; 1395ed957684SJames Smart } 1396dea3101eS 1397dea3101eS /* mask off BAR0's flag bits 0 - 3 */ 139834b02dcdSJames Smart phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) + 1399ed957684SJames Smart (void __iomem *)phba->host_gp - 1400ed957684SJames Smart (void __iomem *)phba->MBslimaddr; 1401dea3101eS if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64) 140234b02dcdSJames Smart phba->pcb->hgpAddrHigh = bar_high; 1403dea3101eS else 140434b02dcdSJames Smart phba->pcb->hgpAddrHigh = 0; 1405dea3101eS /* write HGP data to SLIM at the required longword offset */ 14064cc2da1dSJames.Smart@Emulex.Com memset(&hgp, 0, sizeof(struct lpfc_hgp)); 1407f91b392cSJames.Smart@Emulex.Com 1408f91b392cSJames.Smart@Emulex.Com for (i = 0; i < phba->sli.num_rings; i++) { 1409ed957684SJames Smart lpfc_memcpy_to_slim(phba->host_gp + i, &hgp, 1410ed957684SJames Smart sizeof(*phba->host_gp)); 1411f91b392cSJames.Smart@Emulex.Com } 14127a470277SJames Smart } 1413dea3101eS 14148f34f4ceSJames Smart /* Setup Port Group offset */ 14158f34f4ceSJames Smart if (phba->sli_rev == 3) 141634b02dcdSJames Smart pgp_offset = offsetof(struct lpfc_sli2_slim, 141734b02dcdSJames Smart mbx.us.s3_pgp.port); 14188f34f4ceSJames Smart else 141934b02dcdSJames Smart pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port); 142034b02dcdSJames Smart pdma_addr = phba->slim2p.phys + pgp_offset; 142134b02dcdSJames Smart phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr); 142234b02dcdSJames Smart phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr); 1423dea3101eS 1424dea3101eS /* Use callback routine to setp rings in the pcb */ 1425dea3101eS lpfc_config_pcb_setup(phba); 1426dea3101eS 1427dea3101eS /* special handling for LC HBAs */ 1428dea3101eS if (lpfc_is_LC_HBA(phba->pcidev->device)) { 1429dea3101eS uint32_t hbainit[5]; 1430dea3101eS 1431dea3101eS lpfc_hba_init(phba, hbainit); 1432dea3101eS 1433dea3101eS memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20); 1434dea3101eS } 1435dea3101eS 1436dea3101eS /* Swap PCB if needed */ 143734b02dcdSJames Smart lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t)); 1438dea3101eS } 1439dea3101eS 1440e59058c4SJames Smart /** 14413621a710SJames Smart * lpfc_kill_board - Prepare a mailbox command for killing board 1442e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1443e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1444e59058c4SJames Smart * 1445e59058c4SJames Smart * The kill board mailbox command is used to tell firmware to perform a 1446e59058c4SJames Smart * graceful shutdown of a channel on a specified board to prepare for reset. 1447e59058c4SJames Smart * When the kill board mailbox command is received, the ER3 bit is set to 1 1448e59058c4SJames Smart * in the Host Status register and the ER Attention bit is set to 1 in the 1449e59058c4SJames Smart * Host Attention register of the HBA function that received the kill board 1450e59058c4SJames Smart * command. 1451e59058c4SJames Smart * 1452e59058c4SJames Smart * This routine prepares the mailbox command for killing the board in 1453e59058c4SJames Smart * preparation for a graceful shutdown. 1454e59058c4SJames Smart **/ 1455dea3101eS void 145641415862SJamie Wellnitz lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 145741415862SJamie Wellnitz { 145804c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 145941415862SJamie Wellnitz 146041415862SJamie Wellnitz memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 146141415862SJamie Wellnitz mb->mbxCommand = MBX_KILL_BOARD; 146241415862SJamie Wellnitz mb->mbxOwner = OWN_HOST; 146341415862SJamie Wellnitz return; 146441415862SJamie Wellnitz } 146541415862SJamie Wellnitz 1466e59058c4SJames Smart /** 14673621a710SJames Smart * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue 1468e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1469e59058c4SJames Smart * @mbq: pointer to the driver internal queue element for mailbox command. 1470e59058c4SJames Smart * 1471e59058c4SJames Smart * Driver maintains a internal mailbox command queue implemented as a linked 1472e59058c4SJames Smart * list. When a mailbox command is issued, it shall be put into the mailbox 1473e59058c4SJames Smart * command queue such that they shall be processed orderly as HBA can process 1474e59058c4SJames Smart * one mailbox command at a time. 1475e59058c4SJames Smart **/ 147641415862SJamie Wellnitz void 1477dea3101eS lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) 1478dea3101eS { 1479dea3101eS struct lpfc_sli *psli; 1480dea3101eS 1481dea3101eS psli = &phba->sli; 1482dea3101eS 1483dea3101eS list_add_tail(&mbq->list, &psli->mboxq); 1484dea3101eS 1485dea3101eS psli->mboxq_cnt++; 1486dea3101eS 1487dea3101eS return; 1488dea3101eS } 1489dea3101eS 1490e59058c4SJames Smart /** 14913621a710SJames Smart * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue 1492e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1493e59058c4SJames Smart * 1494e59058c4SJames Smart * Driver maintains a internal mailbox command queue implemented as a linked 1495e59058c4SJames Smart * list. When a mailbox command is issued, it shall be put into the mailbox 1496e59058c4SJames Smart * command queue such that they shall be processed orderly as HBA can process 1497e59058c4SJames Smart * one mailbox command at a time. After HBA finished processing a mailbox 1498e59058c4SJames Smart * command, the driver will remove a pending mailbox command from the head of 1499e59058c4SJames Smart * the mailbox command queue and send to the HBA for processing. 1500e59058c4SJames Smart * 1501e59058c4SJames Smart * Return codes 1502e59058c4SJames Smart * pointer to the driver internal queue element for mailbox command. 1503e59058c4SJames Smart **/ 1504dea3101eS LPFC_MBOXQ_t * 1505dea3101eS lpfc_mbox_get(struct lpfc_hba * phba) 1506dea3101eS { 1507dea3101eS LPFC_MBOXQ_t *mbq = NULL; 1508dea3101eS struct lpfc_sli *psli = &phba->sli; 1509dea3101eS 15102e0fef85SJames Smart list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list); 151192d7f7b0SJames Smart if (mbq) 1512dea3101eS psli->mboxq_cnt--; 1513dea3101eS 1514dea3101eS return mbq; 1515dea3101eS } 1516a309a6b6SJames Smart 1517e59058c4SJames Smart /** 151804c68496SJames Smart * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list 151904c68496SJames Smart * @phba: pointer to lpfc hba data structure. 152004c68496SJames Smart * @mbq: pointer to the driver internal queue element for mailbox command. 152104c68496SJames Smart * 152204c68496SJames Smart * This routine put the completed mailbox command into the mailbox command 152304c68496SJames Smart * complete list. This is the unlocked version of the routine. The mailbox 152404c68496SJames Smart * complete list is used by the driver worker thread to process mailbox 152504c68496SJames Smart * complete callback functions outside the driver interrupt handler. 152604c68496SJames Smart **/ 152704c68496SJames Smart void 152804c68496SJames Smart __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) 152904c68496SJames Smart { 153004c68496SJames Smart list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl); 153104c68496SJames Smart } 153204c68496SJames Smart 153304c68496SJames Smart /** 15343621a710SJames Smart * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list 1535e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1536e59058c4SJames Smart * @mbq: pointer to the driver internal queue element for mailbox command. 1537e59058c4SJames Smart * 1538e59058c4SJames Smart * This routine put the completed mailbox command into the mailbox command 153904c68496SJames Smart * complete list. This is the locked version of the routine. The mailbox 154004c68496SJames Smart * complete list is used by the driver worker thread to process mailbox 154104c68496SJames Smart * complete callback functions outside the driver interrupt handler. 1542e59058c4SJames Smart **/ 154392d7f7b0SJames Smart void 154492d7f7b0SJames Smart lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) 154592d7f7b0SJames Smart { 15465b75da2fSJames Smart unsigned long iflag; 15475b75da2fSJames Smart 1548b1c11812SJoe Perches /* This function expects to be called from interrupt context */ 15495b75da2fSJames Smart spin_lock_irqsave(&phba->hbalock, iflag); 155004c68496SJames Smart __lpfc_mbox_cmpl_put(phba, mbq); 15515b75da2fSJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 155292d7f7b0SJames Smart return; 155392d7f7b0SJames Smart } 155492d7f7b0SJames Smart 1555e59058c4SJames Smart /** 155604c68496SJames Smart * lpfc_mbox_cmd_check - Check the validality of a mailbox command 155704c68496SJames Smart * @phba: pointer to lpfc hba data structure. 155804c68496SJames Smart * @mboxq: pointer to the driver internal queue element for mailbox command. 155904c68496SJames Smart * 156004c68496SJames Smart * This routine is to check whether a mailbox command is valid to be issued. 156104c68496SJames Smart * This check will be performed by both the mailbox issue API when a client 156204c68496SJames Smart * is to issue a mailbox command to the mailbox transport. 156304c68496SJames Smart * 156404c68496SJames Smart * Return 0 - pass the check, -ENODEV - fail the check 156504c68496SJames Smart **/ 156604c68496SJames Smart int 156704c68496SJames Smart lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) 156804c68496SJames Smart { 156904c68496SJames Smart /* Mailbox command that have a completion handler must also have a 157004c68496SJames Smart * vport specified. 157104c68496SJames Smart */ 157204c68496SJames Smart if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl && 157304c68496SJames Smart mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) { 157404c68496SJames Smart if (!mboxq->vport) { 157504c68496SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT, 157604c68496SJames Smart "1814 Mbox x%x failed, no vport\n", 157704c68496SJames Smart mboxq->u.mb.mbxCommand); 157804c68496SJames Smart dump_stack(); 157904c68496SJames Smart return -ENODEV; 158004c68496SJames Smart } 158104c68496SJames Smart } 158204c68496SJames Smart return 0; 158304c68496SJames Smart } 158404c68496SJames Smart 158504c68496SJames Smart /** 158604c68496SJames Smart * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command 158704c68496SJames Smart * @phba: pointer to lpfc hba data structure. 158804c68496SJames Smart * 158904c68496SJames Smart * This routine is to check whether the HBA device is ready for posting a 159004c68496SJames Smart * mailbox command. It is used by the mailbox transport API at the time the 159104c68496SJames Smart * to post a mailbox command to the device. 159204c68496SJames Smart * 159304c68496SJames Smart * Return 0 - pass the check, -ENODEV - fail the check 159404c68496SJames Smart **/ 159504c68496SJames Smart int 159604c68496SJames Smart lpfc_mbox_dev_check(struct lpfc_hba *phba) 159704c68496SJames Smart { 159804c68496SJames Smart /* If the PCI channel is in offline state, do not issue mbox */ 159904c68496SJames Smart if (unlikely(pci_channel_offline(phba->pcidev))) 160004c68496SJames Smart return -ENODEV; 160104c68496SJames Smart 160204c68496SJames Smart /* If the HBA is in error state, do not issue mbox */ 160304c68496SJames Smart if (phba->link_state == LPFC_HBA_ERROR) 160404c68496SJames Smart return -ENODEV; 160504c68496SJames Smart 160604c68496SJames Smart return 0; 160704c68496SJames Smart } 160804c68496SJames Smart 160904c68496SJames Smart /** 16103621a710SJames Smart * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value 1611e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1612e59058c4SJames Smart * @cmd: mailbox command code. 1613e59058c4SJames Smart * 1614e59058c4SJames Smart * This routine retrieves the proper timeout value according to the mailbox 1615e59058c4SJames Smart * command code. 1616e59058c4SJames Smart * 1617e59058c4SJames Smart * Return codes 1618e59058c4SJames Smart * Timeout value to be used for the given mailbox command 1619e59058c4SJames Smart **/ 1620a309a6b6SJames Smart int 1621a183a15fSJames Smart lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) 1622a309a6b6SJames Smart { 1623a183a15fSJames Smart MAILBOX_t *mbox = &mboxq->u.mb; 1624a183a15fSJames Smart uint8_t subsys, opcode; 1625a183a15fSJames Smart 1626a183a15fSJames Smart switch (mbox->mbxCommand) { 1627a309a6b6SJames Smart case MBX_WRITE_NV: /* 0x03 */ 1628940eb687SJames Smart case MBX_DUMP_MEMORY: /* 0x17 */ 1629a309a6b6SJames Smart case MBX_UPDATE_CFG: /* 0x1B */ 1630a309a6b6SJames Smart case MBX_DOWN_LOAD: /* 0x1C */ 1631a309a6b6SJames Smart case MBX_DEL_LD_ENTRY: /* 0x1D */ 1632940eb687SJames Smart case MBX_WRITE_VPARMS: /* 0x32 */ 1633a309a6b6SJames Smart case MBX_LOAD_AREA: /* 0x81 */ 163409372820SJames Smart case MBX_WRITE_WWN: /* 0x98 */ 1635a309a6b6SJames Smart case MBX_LOAD_EXP_ROM: /* 0x9C */ 1636940eb687SJames Smart case MBX_ACCESS_VDATA: /* 0xA5 */ 1637a309a6b6SJames Smart return LPFC_MBOX_TMO_FLASH_CMD; 163804c68496SJames Smart case MBX_SLI4_CONFIG: /* 0x9b */ 1639a183a15fSJames Smart subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq); 1640a183a15fSJames Smart opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq); 1641a183a15fSJames Smart if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) { 1642a183a15fSJames Smart switch (opcode) { 1643a183a15fSJames Smart case LPFC_MBOX_OPCODE_READ_OBJECT: 1644a183a15fSJames Smart case LPFC_MBOX_OPCODE_WRITE_OBJECT: 1645a183a15fSJames Smart case LPFC_MBOX_OPCODE_READ_OBJECT_LIST: 1646a183a15fSJames Smart case LPFC_MBOX_OPCODE_DELETE_OBJECT: 1647a183a15fSJames Smart case LPFC_MBOX_OPCODE_GET_PROFILE_LIST: 1648a183a15fSJames Smart case LPFC_MBOX_OPCODE_SET_ACT_PROFILE: 1649940eb687SJames Smart case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG: 1650a183a15fSJames Smart case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG: 1651a183a15fSJames Smart case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG: 1652940eb687SJames Smart case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES: 1653940eb687SJames Smart case LPFC_MBOX_OPCODE_SEND_ACTIVATION: 1654940eb687SJames Smart case LPFC_MBOX_OPCODE_RESET_LICENSES: 1655940eb687SJames Smart case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG: 1656940eb687SJames Smart case LPFC_MBOX_OPCODE_GET_VPD_DATA: 1657940eb687SJames Smart case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG: 1658a183a15fSJames Smart return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO; 1659a183a15fSJames Smart } 1660a183a15fSJames Smart } 1661a183a15fSJames Smart if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) { 1662a183a15fSJames Smart switch (opcode) { 1663a183a15fSJames Smart case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS: 1664a183a15fSJames Smart return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO; 1665a183a15fSJames Smart } 1666a183a15fSJames Smart } 166704c68496SJames Smart return LPFC_MBOX_SLI4_CONFIG_TMO; 1668a309a6b6SJames Smart } 1669a309a6b6SJames Smart return LPFC_MBOX_TMO; 1670a309a6b6SJames Smart } 167104c68496SJames Smart 167204c68496SJames Smart /** 167304c68496SJames Smart * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command 167404c68496SJames Smart * @mbox: pointer to lpfc mbox command. 167504c68496SJames Smart * @sgentry: sge entry index. 167604c68496SJames Smart * @phyaddr: physical address for the sge 167704c68496SJames Smart * @length: Length of the sge. 167804c68496SJames Smart * 167904c68496SJames Smart * This routine sets up an entry in the non-embedded mailbox command at the sge 168004c68496SJames Smart * index location. 168104c68496SJames Smart **/ 168204c68496SJames Smart void 168304c68496SJames Smart lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry, 168404c68496SJames Smart dma_addr_t phyaddr, uint32_t length) 168504c68496SJames Smart { 168604c68496SJames Smart struct lpfc_mbx_nembed_cmd *nembed_sge; 168704c68496SJames Smart 168804c68496SJames Smart nembed_sge = (struct lpfc_mbx_nembed_cmd *) 168904c68496SJames Smart &mbox->u.mqe.un.nembed_cmd; 169004c68496SJames Smart nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr); 169104c68496SJames Smart nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr); 169204c68496SJames Smart nembed_sge->sge[sgentry].length = length; 169304c68496SJames Smart } 169404c68496SJames Smart 169504c68496SJames Smart /** 169604c68496SJames Smart * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command 169704c68496SJames Smart * @mbox: pointer to lpfc mbox command. 169804c68496SJames Smart * @sgentry: sge entry index. 169904c68496SJames Smart * 170004c68496SJames Smart * This routine gets an entry from the non-embedded mailbox command at the sge 170104c68496SJames Smart * index location. 170204c68496SJames Smart **/ 170304c68496SJames Smart void 170404c68496SJames Smart lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry, 170504c68496SJames Smart struct lpfc_mbx_sge *sge) 170604c68496SJames Smart { 170704c68496SJames Smart struct lpfc_mbx_nembed_cmd *nembed_sge; 170804c68496SJames Smart 170904c68496SJames Smart nembed_sge = (struct lpfc_mbx_nembed_cmd *) 171004c68496SJames Smart &mbox->u.mqe.un.nembed_cmd; 171104c68496SJames Smart sge->pa_lo = nembed_sge->sge[sgentry].pa_lo; 171204c68496SJames Smart sge->pa_hi = nembed_sge->sge[sgentry].pa_hi; 171304c68496SJames Smart sge->length = nembed_sge->sge[sgentry].length; 171404c68496SJames Smart } 171504c68496SJames Smart 171604c68496SJames Smart /** 171704c68496SJames Smart * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command 171804c68496SJames Smart * @phba: pointer to lpfc hba data structure. 171904c68496SJames Smart * @mbox: pointer to lpfc mbox command. 172004c68496SJames Smart * 172104c68496SJames Smart * This routine frees SLI4 specific mailbox command for sending IOCTL command. 172204c68496SJames Smart **/ 172304c68496SJames Smart void 172404c68496SJames Smart lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox) 172504c68496SJames Smart { 172604c68496SJames Smart struct lpfc_mbx_sli4_config *sli4_cfg; 172704c68496SJames Smart struct lpfc_mbx_sge sge; 172804c68496SJames Smart dma_addr_t phyaddr; 172904c68496SJames Smart uint32_t sgecount, sgentry; 173004c68496SJames Smart 173104c68496SJames Smart sli4_cfg = &mbox->u.mqe.un.sli4_config; 173204c68496SJames Smart 173304c68496SJames Smart /* For embedded mbox command, just free the mbox command */ 173404c68496SJames Smart if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { 173504c68496SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 173604c68496SJames Smart return; 173704c68496SJames Smart } 173804c68496SJames Smart 173904c68496SJames Smart /* For non-embedded mbox command, we need to free the pages first */ 174004c68496SJames Smart sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr); 174104c68496SJames Smart /* There is nothing we can do if there is no sge address array */ 174204c68496SJames Smart if (unlikely(!mbox->sge_array)) { 174304c68496SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 174404c68496SJames Smart return; 174504c68496SJames Smart } 174604c68496SJames Smart /* Each non-embedded DMA memory was allocated in the length of a page */ 174704c68496SJames Smart for (sgentry = 0; sgentry < sgecount; sgentry++) { 174804c68496SJames Smart lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge); 174904c68496SJames Smart phyaddr = getPaddr(sge.pa_hi, sge.pa_lo); 175049198b37SJames Smart dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, 175104c68496SJames Smart mbox->sge_array->addr[sgentry], phyaddr); 175204c68496SJames Smart } 175304c68496SJames Smart /* Free the sge address array memory */ 175404c68496SJames Smart kfree(mbox->sge_array); 175504c68496SJames Smart /* Finally, free the mailbox command itself */ 175604c68496SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 175704c68496SJames Smart } 175804c68496SJames Smart 175904c68496SJames Smart /** 176004c68496SJames Smart * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command 176104c68496SJames Smart * @phba: pointer to lpfc hba data structure. 176204c68496SJames Smart * @mbox: pointer to lpfc mbox command. 176304c68496SJames Smart * @subsystem: The sli4 config sub mailbox subsystem. 176404c68496SJames Smart * @opcode: The sli4 config sub mailbox command opcode. 1765fedd3b7bSJames Smart * @length: Length of the sli4 config mailbox command (including sub-header). 176604c68496SJames Smart * 176704c68496SJames Smart * This routine sets up the header fields of SLI4 specific mailbox command 176804c68496SJames Smart * for sending IOCTL command. 176904c68496SJames Smart * 177004c68496SJames Smart * Return: the actual length of the mbox command allocated (mostly useful 177104c68496SJames Smart * for none embedded mailbox command). 177204c68496SJames Smart **/ 177304c68496SJames Smart int 177404c68496SJames Smart lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox, 177504c68496SJames Smart uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb) 177604c68496SJames Smart { 177704c68496SJames Smart struct lpfc_mbx_sli4_config *sli4_config; 177804c68496SJames Smart union lpfc_sli4_cfg_shdr *cfg_shdr = NULL; 177904c68496SJames Smart uint32_t alloc_len; 178004c68496SJames Smart uint32_t resid_len; 178104c68496SJames Smart uint32_t pagen, pcount; 178204c68496SJames Smart void *viraddr; 178304c68496SJames Smart dma_addr_t phyaddr; 178404c68496SJames Smart 178504c68496SJames Smart /* Set up SLI4 mailbox command header fields */ 178604c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 178704c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG); 178804c68496SJames Smart 178904c68496SJames Smart /* Set up SLI4 ioctl command header fields */ 179004c68496SJames Smart sli4_config = &mbox->u.mqe.un.sli4_config; 179104c68496SJames Smart 179204c68496SJames Smart /* Setup for the embedded mbox command */ 179304c68496SJames Smart if (emb) { 179404c68496SJames Smart /* Set up main header fields */ 179504c68496SJames Smart bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1); 1796fedd3b7bSJames Smart sli4_config->header.cfg_mhdr.payload_length = length; 179704c68496SJames Smart /* Set up sub-header fields following main header */ 179804c68496SJames Smart bf_set(lpfc_mbox_hdr_opcode, 179904c68496SJames Smart &sli4_config->header.cfg_shdr.request, opcode); 180004c68496SJames Smart bf_set(lpfc_mbox_hdr_subsystem, 180104c68496SJames Smart &sli4_config->header.cfg_shdr.request, subsystem); 1802fedd3b7bSJames Smart sli4_config->header.cfg_shdr.request.request_length = 1803fedd3b7bSJames Smart length - LPFC_MBX_CMD_HDR_LENGTH; 180404c68496SJames Smart return length; 180504c68496SJames Smart } 180604c68496SJames Smart 18076d368e53SJames Smart /* Setup for the non-embedded mbox command */ 18089589b062SJames Smart pcount = (SLI4_PAGE_ALIGN(length))/SLI4_PAGE_SIZE; 180904c68496SJames Smart pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ? 181004c68496SJames Smart LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount; 181104c68496SJames Smart /* Allocate record for keeping SGE virtual addresses */ 18126d368e53SJames Smart mbox->sge_array = kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt), 181304c68496SJames Smart GFP_KERNEL); 18146a9c52cfSJames Smart if (!mbox->sge_array) { 18156a9c52cfSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, 18166a9c52cfSJames Smart "2527 Failed to allocate non-embedded SGE " 18176a9c52cfSJames Smart "array.\n"); 181804c68496SJames Smart return 0; 18196a9c52cfSJames Smart } 182004c68496SJames Smart for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) { 182104c68496SJames Smart /* The DMA memory is always allocated in the length of a 182204c68496SJames Smart * page even though the last SGE might not fill up to a 182349198b37SJames Smart * page, this is used as a priori size of SLI4_PAGE_SIZE for 182404c68496SJames Smart * the later DMA memory free. 182504c68496SJames Smart */ 18261aee383dSJoe Perches viraddr = dma_zalloc_coherent(&phba->pcidev->dev, 18271aee383dSJoe Perches SLI4_PAGE_SIZE, &phyaddr, 18281aee383dSJoe Perches GFP_KERNEL); 182904c68496SJames Smart /* In case of malloc fails, proceed with whatever we have */ 183004c68496SJames Smart if (!viraddr) 183104c68496SJames Smart break; 183204c68496SJames Smart mbox->sge_array->addr[pagen] = viraddr; 183304c68496SJames Smart /* Keep the first page for later sub-header construction */ 183404c68496SJames Smart if (pagen == 0) 183504c68496SJames Smart cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr; 183604c68496SJames Smart resid_len = length - alloc_len; 183749198b37SJames Smart if (resid_len > SLI4_PAGE_SIZE) { 183804c68496SJames Smart lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, 183949198b37SJames Smart SLI4_PAGE_SIZE); 184049198b37SJames Smart alloc_len += SLI4_PAGE_SIZE; 184104c68496SJames Smart } else { 184204c68496SJames Smart lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, 184304c68496SJames Smart resid_len); 184404c68496SJames Smart alloc_len = length; 184504c68496SJames Smart } 184604c68496SJames Smart } 184704c68496SJames Smart 184804c68496SJames Smart /* Set up main header fields in mailbox command */ 184904c68496SJames Smart sli4_config->header.cfg_mhdr.payload_length = alloc_len; 185004c68496SJames Smart bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen); 185104c68496SJames Smart 185204c68496SJames Smart /* Set up sub-header fields into the first page */ 185304c68496SJames Smart if (pagen > 0) { 185404c68496SJames Smart bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode); 185504c68496SJames Smart bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem); 185604c68496SJames Smart cfg_shdr->request.request_length = 185704c68496SJames Smart alloc_len - sizeof(union lpfc_sli4_cfg_shdr); 185804c68496SJames Smart } 185904c68496SJames Smart /* The sub-header is in DMA memory, which needs endian converstion */ 186072100cc4SJames Smart if (cfg_shdr) 186104c68496SJames Smart lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr, 186204c68496SJames Smart sizeof(union lpfc_sli4_cfg_shdr)); 186304c68496SJames Smart return alloc_len; 186404c68496SJames Smart } 186504c68496SJames Smart 186604c68496SJames Smart /** 18676d368e53SJames Smart * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent. 18686d368e53SJames Smart * @phba: pointer to lpfc hba data structure. 18696d368e53SJames Smart * @mbox: pointer to an allocated lpfc mbox resource. 18706d368e53SJames Smart * @exts_count: the number of extents, if required, to allocate. 18716d368e53SJames Smart * @rsrc_type: the resource extent type. 18726d368e53SJames Smart * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED. 18736d368e53SJames Smart * 18746d368e53SJames Smart * This routine completes the subcommand header for SLI4 resource extent 18756d368e53SJames Smart * mailbox commands. It is called after lpfc_sli4_config. The caller must 18766d368e53SJames Smart * pass an allocated mailbox and the attributes required to initialize the 18776d368e53SJames Smart * mailbox correctly. 18786d368e53SJames Smart * 18796d368e53SJames Smart * Return: the actual length of the mbox command allocated. 18806d368e53SJames Smart **/ 18816d368e53SJames Smart int 18826d368e53SJames Smart lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox, 18836d368e53SJames Smart uint16_t exts_count, uint16_t rsrc_type, bool emb) 18846d368e53SJames Smart { 18856d368e53SJames Smart uint8_t opcode = 0; 18866d368e53SJames Smart struct lpfc_mbx_nembed_rsrc_extent *n_rsrc_extnt = NULL; 18876d368e53SJames Smart void *virtaddr = NULL; 18886d368e53SJames Smart 18896d368e53SJames Smart /* Set up SLI4 ioctl command header fields */ 18906d368e53SJames Smart if (emb == LPFC_SLI4_MBX_NEMBED) { 18916d368e53SJames Smart /* Get the first SGE entry from the non-embedded DMA memory */ 18926d368e53SJames Smart virtaddr = mbox->sge_array->addr[0]; 18936d368e53SJames Smart if (virtaddr == NULL) 18946d368e53SJames Smart return 1; 18956d368e53SJames Smart n_rsrc_extnt = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; 18966d368e53SJames Smart } 18976d368e53SJames Smart 18986d368e53SJames Smart /* 18996d368e53SJames Smart * The resource type is common to all extent Opcodes and resides in the 19006d368e53SJames Smart * same position. 19016d368e53SJames Smart */ 19026d368e53SJames Smart if (emb == LPFC_SLI4_MBX_EMBED) 19036d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_type, 19046d368e53SJames Smart &mbox->u.mqe.un.alloc_rsrc_extents.u.req, 19056d368e53SJames Smart rsrc_type); 19066d368e53SJames Smart else { 19076d368e53SJames Smart /* This is DMA data. Byteswap is required. */ 19086d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_type, 19096d368e53SJames Smart n_rsrc_extnt, rsrc_type); 19106d368e53SJames Smart lpfc_sli_pcimem_bcopy(&n_rsrc_extnt->word4, 19116d368e53SJames Smart &n_rsrc_extnt->word4, 19126d368e53SJames Smart sizeof(uint32_t)); 19136d368e53SJames Smart } 19146d368e53SJames Smart 19156d368e53SJames Smart /* Complete the initialization for the particular Opcode. */ 1916a183a15fSJames Smart opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox); 19176d368e53SJames Smart switch (opcode) { 19186d368e53SJames Smart case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT: 19196d368e53SJames Smart if (emb == LPFC_SLI4_MBX_EMBED) 19206d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_cnt, 19216d368e53SJames Smart &mbox->u.mqe.un.alloc_rsrc_extents.u.req, 19226d368e53SJames Smart exts_count); 19236d368e53SJames Smart else 19246d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_cnt, 19256d368e53SJames Smart n_rsrc_extnt, exts_count); 19266d368e53SJames Smart break; 19276d368e53SJames Smart case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT: 19286d368e53SJames Smart case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO: 19296d368e53SJames Smart case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT: 19306d368e53SJames Smart /* Initialization is complete.*/ 19316d368e53SJames Smart break; 19326d368e53SJames Smart default: 19336d368e53SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, 19346d368e53SJames Smart "2929 Resource Extent Opcode x%x is " 19356d368e53SJames Smart "unsupported\n", opcode); 19366d368e53SJames Smart return 1; 19376d368e53SJames Smart } 19386d368e53SJames Smart 19396d368e53SJames Smart return 0; 19406d368e53SJames Smart } 19416d368e53SJames Smart 19426d368e53SJames Smart /** 1943a183a15fSJames Smart * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd 194404c68496SJames Smart * @phba: pointer to lpfc hba data structure. 1945a183a15fSJames Smart * @mbox: pointer to lpfc mbox command queue entry. 194604c68496SJames Smart * 1947a183a15fSJames Smart * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox 1948a183a15fSJames Smart * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the 1949a183a15fSJames Smart * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall 1950a183a15fSJames Smart * be returned. 195104c68496SJames Smart **/ 195204c68496SJames Smart uint8_t 1953a183a15fSJames Smart lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) 195404c68496SJames Smart { 195504c68496SJames Smart struct lpfc_mbx_sli4_config *sli4_cfg; 195604c68496SJames Smart union lpfc_sli4_cfg_shdr *cfg_shdr; 195704c68496SJames Smart 195804c68496SJames Smart if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) 1959a183a15fSJames Smart return LPFC_MBOX_SUBSYSTEM_NA; 1960a183a15fSJames Smart sli4_cfg = &mbox->u.mqe.un.sli4_config; 1961a183a15fSJames Smart 1962a183a15fSJames Smart /* For embedded mbox command, get opcode from embedded sub-header*/ 1963a183a15fSJames Smart if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { 1964a183a15fSJames Smart cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; 1965a183a15fSJames Smart return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request); 1966a183a15fSJames Smart } 1967a183a15fSJames Smart 1968a183a15fSJames Smart /* For non-embedded mbox command, get opcode from first dma page */ 1969a183a15fSJames Smart if (unlikely(!mbox->sge_array)) 1970a183a15fSJames Smart return LPFC_MBOX_SUBSYSTEM_NA; 1971a183a15fSJames Smart cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; 1972a183a15fSJames Smart return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request); 1973a183a15fSJames Smart } 1974a183a15fSJames Smart 1975a183a15fSJames Smart /** 1976a183a15fSJames Smart * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd 1977a183a15fSJames Smart * @phba: pointer to lpfc hba data structure. 1978a183a15fSJames Smart * @mbox: pointer to lpfc mbox command queue entry. 1979a183a15fSJames Smart * 1980a183a15fSJames Smart * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox 1981a183a15fSJames Smart * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if 1982a183a15fSJames Smart * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be 1983a183a15fSJames Smart * returned. 1984a183a15fSJames Smart **/ 1985a183a15fSJames Smart uint8_t 1986a183a15fSJames Smart lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) 1987a183a15fSJames Smart { 1988a183a15fSJames Smart struct lpfc_mbx_sli4_config *sli4_cfg; 1989a183a15fSJames Smart union lpfc_sli4_cfg_shdr *cfg_shdr; 1990a183a15fSJames Smart 1991a183a15fSJames Smart if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) 1992a183a15fSJames Smart return LPFC_MBOX_OPCODE_NA; 199304c68496SJames Smart sli4_cfg = &mbox->u.mqe.un.sli4_config; 199404c68496SJames Smart 199504c68496SJames Smart /* For embedded mbox command, get opcode from embedded sub-header*/ 199604c68496SJames Smart if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { 199704c68496SJames Smart cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; 199804c68496SJames Smart return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); 199904c68496SJames Smart } 200004c68496SJames Smart 200104c68496SJames Smart /* For non-embedded mbox command, get opcode from first dma page */ 200204c68496SJames Smart if (unlikely(!mbox->sge_array)) 2003a183a15fSJames Smart return LPFC_MBOX_OPCODE_NA; 200404c68496SJames Smart cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; 200504c68496SJames Smart return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); 200604c68496SJames Smart } 200704c68496SJames Smart 200804c68496SJames Smart /** 20090c9ab6f5SJames Smart * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd 2010ecfd03c6SJames Smart * @phba: pointer to lpfc hba data structure. 2011ecfd03c6SJames Smart * @fcf_index: index to fcf table. 2012ecfd03c6SJames Smart * 2013ecfd03c6SJames Smart * This routine routine allocates and constructs non-embedded mailbox command 201425985edcSLucas De Marchi * for reading a FCF table entry referred by @fcf_index. 2015ecfd03c6SJames Smart * 2016ecfd03c6SJames Smart * Return: pointer to the mailbox command constructed if successful, otherwise 2017ecfd03c6SJames Smart * NULL. 2018ecfd03c6SJames Smart **/ 2019ecfd03c6SJames Smart int 20200c9ab6f5SJames Smart lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba, 2021ecfd03c6SJames Smart struct lpfcMboxq *mboxq, 2022ecfd03c6SJames Smart uint16_t fcf_index) 2023ecfd03c6SJames Smart { 2024ecfd03c6SJames Smart void *virt_addr; 2025ecfd03c6SJames Smart uint8_t *bytep; 2026ecfd03c6SJames Smart struct lpfc_mbx_sge sge; 2027ecfd03c6SJames Smart uint32_t alloc_len, req_len; 2028ecfd03c6SJames Smart struct lpfc_mbx_read_fcf_tbl *read_fcf; 2029ecfd03c6SJames Smart 2030ecfd03c6SJames Smart if (!mboxq) 2031ecfd03c6SJames Smart return -ENOMEM; 2032ecfd03c6SJames Smart 2033ecfd03c6SJames Smart req_len = sizeof(struct fcf_record) + 2034ecfd03c6SJames Smart sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t); 2035ecfd03c6SJames Smart 2036ecfd03c6SJames Smart /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */ 2037ecfd03c6SJames Smart alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, 2038ecfd03c6SJames Smart LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len, 2039ecfd03c6SJames Smart LPFC_SLI4_MBX_NEMBED); 2040ecfd03c6SJames Smart 2041ecfd03c6SJames Smart if (alloc_len < req_len) { 2042ecfd03c6SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, 2043ecfd03c6SJames Smart "0291 Allocated DMA memory size (x%x) is " 2044ecfd03c6SJames Smart "less than the requested DMA memory " 2045ecfd03c6SJames Smart "size (x%x)\n", alloc_len, req_len); 2046ecfd03c6SJames Smart return -ENOMEM; 2047ecfd03c6SJames Smart } 2048ecfd03c6SJames Smart 2049ecfd03c6SJames Smart /* Get the first SGE entry from the non-embedded DMA memory. This 2050ecfd03c6SJames Smart * routine only uses a single SGE. 2051ecfd03c6SJames Smart */ 2052ecfd03c6SJames Smart lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); 2053ecfd03c6SJames Smart virt_addr = mboxq->sge_array->addr[0]; 2054ecfd03c6SJames Smart read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; 2055ecfd03c6SJames Smart 2056ecfd03c6SJames Smart /* Set up command fields */ 2057ecfd03c6SJames Smart bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index); 2058ecfd03c6SJames Smart /* Perform necessary endian conversion */ 2059ecfd03c6SJames Smart bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); 2060ecfd03c6SJames Smart lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t)); 2061ecfd03c6SJames Smart 2062ecfd03c6SJames Smart return 0; 2063ecfd03c6SJames Smart } 2064ecfd03c6SJames Smart 2065ecfd03c6SJames Smart /** 206604c68496SJames Smart * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox 206704c68496SJames Smart * @mboxq: pointer to lpfc mbox command. 206804c68496SJames Smart * 206904c68496SJames Smart * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES 207004c68496SJames Smart * mailbox command. 207104c68496SJames Smart **/ 207204c68496SJames Smart void 207304c68496SJames Smart lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq) 207404c68496SJames Smart { 207504c68496SJames Smart /* Set up SLI4 mailbox command header fields */ 207604c68496SJames Smart memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); 207704c68496SJames Smart bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS); 207804c68496SJames Smart 207904c68496SJames Smart /* Set up host requested features. */ 208004c68496SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1); 2081fedd3b7bSJames Smart bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1); 208204c68496SJames Smart 208304c68496SJames Smart /* Enable DIF (block guard) only if configured to do so. */ 208404c68496SJames Smart if (phba->cfg_enable_bg) 208504c68496SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1); 208604c68496SJames Smart 208704c68496SJames Smart /* Enable NPIV only if configured to do so. */ 208804c68496SJames Smart if (phba->max_vpi && phba->cfg_enable_npiv) 208904c68496SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1); 209004c68496SJames Smart 209186c67379SJames Smart if (phba->nvmet_support) { 20922d7dbc4cSJames Smart bf_set(lpfc_mbx_rq_ftr_rq_mrqp, &mboxq->u.mqe.un.req_ftrs, 1); 209386c67379SJames Smart /* iaab/iaar NOT set for now */ 209486c67379SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_iaab, &mboxq->u.mqe.un.req_ftrs, 0); 209586c67379SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_iaar, &mboxq->u.mqe.un.req_ftrs, 0); 209686c67379SJames Smart } 209704c68496SJames Smart return; 209804c68496SJames Smart } 209904c68496SJames Smart 210004c68496SJames Smart /** 210104c68496SJames Smart * lpfc_init_vfi - Initialize the INIT_VFI mailbox command 210204c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 210304c68496SJames Smart * @vport: Vport associated with the VF. 210404c68496SJames Smart * 210504c68496SJames Smart * This routine initializes @mbox to all zeros and then fills in the mailbox 210604c68496SJames Smart * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI 210704c68496SJames Smart * in the context of an FCF. The driver issues this command to setup a VFI 210804c68496SJames Smart * before issuing a FLOGI to login to the VSAN. The driver should also issue a 210904c68496SJames Smart * REG_VFI after a successful VSAN login. 211004c68496SJames Smart **/ 211104c68496SJames Smart void 211204c68496SJames Smart lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) 211304c68496SJames Smart { 211404c68496SJames Smart struct lpfc_mbx_init_vfi *init_vfi; 211504c68496SJames Smart 211604c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 211776a95d75SJames Smart mbox->vport = vport; 211804c68496SJames Smart init_vfi = &mbox->u.mqe.un.init_vfi; 211904c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI); 212004c68496SJames Smart bf_set(lpfc_init_vfi_vr, init_vfi, 1); 212104c68496SJames Smart bf_set(lpfc_init_vfi_vt, init_vfi, 1); 212276a95d75SJames Smart bf_set(lpfc_init_vfi_vp, init_vfi, 1); 21236d368e53SJames Smart bf_set(lpfc_init_vfi_vfi, init_vfi, 21246d368e53SJames Smart vport->phba->sli4_hba.vfi_ids[vport->vfi]); 21257851fe2cSJames Smart bf_set(lpfc_init_vfi_vpi, init_vfi, 21266d368e53SJames Smart vport->phba->vpi_ids[vport->vpi]); 21276d368e53SJames Smart bf_set(lpfc_init_vfi_fcfi, init_vfi, 21286d368e53SJames Smart vport->phba->fcf.fcfi); 212904c68496SJames Smart } 213004c68496SJames Smart 213104c68496SJames Smart /** 213204c68496SJames Smart * lpfc_reg_vfi - Initialize the REG_VFI mailbox command 213304c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 213404c68496SJames Smart * @vport: vport associated with the VF. 213504c68496SJames Smart * @phys: BDE DMA bus address used to send the service parameters to the HBA. 213604c68496SJames Smart * 213704c68496SJames Smart * This routine initializes @mbox to all zeros and then fills in the mailbox 213804c68496SJames Smart * fields from @vport, and uses @buf as a DMAable buffer to send the vport's 213904c68496SJames Smart * fc service parameters to the HBA for this VFI. REG_VFI configures virtual 214004c68496SJames Smart * fabrics identified by VFI in the context of an FCF. 214104c68496SJames Smart **/ 214204c68496SJames Smart void 214304c68496SJames Smart lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys) 214404c68496SJames Smart { 214504c68496SJames Smart struct lpfc_mbx_reg_vfi *reg_vfi; 2146ae05ebe3SJames Smart struct lpfc_hba *phba = vport->phba; 214744fd7fe3SJames Smart uint8_t bbscn_fabric = 0, bbscn_max = 0, bbscn_def = 0; 214804c68496SJames Smart 214904c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 215004c68496SJames Smart reg_vfi = &mbox->u.mqe.un.reg_vfi; 215104c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI); 215204c68496SJames Smart bf_set(lpfc_reg_vfi_vp, reg_vfi, 1); 21536d368e53SJames Smart bf_set(lpfc_reg_vfi_vfi, reg_vfi, 2154ae05ebe3SJames Smart phba->sli4_hba.vfi_ids[vport->vfi]); 2155ae05ebe3SJames Smart bf_set(lpfc_reg_vfi_fcfi, reg_vfi, phba->fcf.fcfi); 2156ae05ebe3SJames Smart bf_set(lpfc_reg_vfi_vpi, reg_vfi, phba->vpi_ids[vport->vpi]); 2157c868595dSJames Smart memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name)); 2158c868595dSJames Smart reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]); 2159c868595dSJames Smart reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]); 2160ae05ebe3SJames Smart reg_vfi->e_d_tov = phba->fc_edtov; 2161ae05ebe3SJames Smart reg_vfi->r_a_tov = phba->fc_ratov; 2162ae09c765SJames Smart if (phys) { 216304c68496SJames Smart reg_vfi->bde.addrHigh = putPaddrHigh(phys); 216404c68496SJames Smart reg_vfi->bde.addrLow = putPaddrLow(phys); 216504c68496SJames Smart reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam); 216604c68496SJames Smart reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 2167ae09c765SJames Smart } 216804c68496SJames Smart bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID); 2169ae05ebe3SJames Smart 2170ae05ebe3SJames Smart /* Only FC supports upd bit */ 2171ae05ebe3SJames Smart if ((phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) && 2172e74c03c8SJames Smart (vport->fc_flag & FC_VFI_REGISTERED) && 2173e74c03c8SJames Smart (!phba->fc_topology_changed)) { 2174ae05ebe3SJames Smart bf_set(lpfc_reg_vfi_vp, reg_vfi, 0); 2175ae05ebe3SJames Smart bf_set(lpfc_reg_vfi_upd, reg_vfi, 1); 2176ae05ebe3SJames Smart } 217744fd7fe3SJames Smart 217844fd7fe3SJames Smart bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 0); 217944fd7fe3SJames Smart bf_set(lpfc_reg_vfi_bbscn, reg_vfi, 0); 218044fd7fe3SJames Smart bbscn_fabric = (phba->fc_fabparam.cmn.bbRcvSizeMsb >> 4) & 0xF; 218144fd7fe3SJames Smart 218244fd7fe3SJames Smart if (phba->bbcredit_support && phba->cfg_enable_bbcr && 218344fd7fe3SJames Smart bbscn_fabric != 0) { 218444fd7fe3SJames Smart bbscn_max = bf_get(lpfc_bbscn_max, 218544fd7fe3SJames Smart &phba->sli4_hba.bbscn_params); 218644fd7fe3SJames Smart if (bbscn_fabric <= bbscn_max) { 218744fd7fe3SJames Smart bbscn_def = bf_get(lpfc_bbscn_def, 218844fd7fe3SJames Smart &phba->sli4_hba.bbscn_params); 218944fd7fe3SJames Smart 219044fd7fe3SJames Smart if (bbscn_fabric > bbscn_def) 219144fd7fe3SJames Smart bf_set(lpfc_reg_vfi_bbscn, reg_vfi, 219244fd7fe3SJames Smart bbscn_fabric); 219344fd7fe3SJames Smart else 219444fd7fe3SJames Smart bf_set(lpfc_reg_vfi_bbscn, reg_vfi, bbscn_def); 219544fd7fe3SJames Smart 219644fd7fe3SJames Smart bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 1); 219744fd7fe3SJames Smart } 219844fd7fe3SJames Smart } 21991b51197dSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_MBOX, 22001b51197dSJames Smart "3134 Register VFI, mydid:x%x, fcfi:%d, " 2201e74c03c8SJames Smart " vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x" 220244fd7fe3SJames Smart " port_state:x%x topology chg:%d bbscn_fabric :%d\n", 22031b51197dSJames Smart vport->fc_myDID, 2204ae05ebe3SJames Smart phba->fcf.fcfi, 2205ae05ebe3SJames Smart phba->sli4_hba.vfi_ids[vport->vfi], 2206ae05ebe3SJames Smart phba->vpi_ids[vport->vpi], 2207e74c03c8SJames Smart reg_vfi->wwn[0], reg_vfi->wwn[1], vport->fc_flag, 220844fd7fe3SJames Smart vport->port_state, phba->fc_topology_changed, 220944fd7fe3SJames Smart bbscn_fabric); 221004c68496SJames Smart } 221104c68496SJames Smart 221204c68496SJames Smart /** 221304c68496SJames Smart * lpfc_init_vpi - Initialize the INIT_VPI mailbox command 22141c6834a7SJames Smart * @phba: pointer to the hba structure to init the VPI for. 221504c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 221604c68496SJames Smart * @vpi: VPI to be initialized. 221704c68496SJames Smart * 221804c68496SJames Smart * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the 221904c68496SJames Smart * command to activate a virtual N_Port. The HBA assigns a MAC address to use 222004c68496SJames Smart * with the virtual N Port. The SLI Host issues this command before issuing a 222104c68496SJames Smart * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a 222204c68496SJames Smart * successful virtual NPort login. 222304c68496SJames Smart **/ 222404c68496SJames Smart void 22251c6834a7SJames Smart lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi) 222604c68496SJames Smart { 222704c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 222804c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI); 22291c6834a7SJames Smart bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi, 22306d368e53SJames Smart phba->vpi_ids[vpi]); 22311c6834a7SJames Smart bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi, 22326d368e53SJames Smart phba->sli4_hba.vfi_ids[phba->pport->vfi]); 223304c68496SJames Smart } 223404c68496SJames Smart 223504c68496SJames Smart /** 223604c68496SJames Smart * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command 223704c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 22386669f9bbSJames Smart * @vport: vport associated with the VF. 223904c68496SJames Smart * 224004c68496SJames Smart * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric 224104c68496SJames Smart * (logical NPort) into the inactive state. The SLI Host must have logged out 224204c68496SJames Smart * and unregistered all remote N_Ports to abort any activity on the virtual 224304c68496SJames Smart * fabric. The SLI Port posts the mailbox response after marking the virtual 224404c68496SJames Smart * fabric inactive. 224504c68496SJames Smart **/ 224604c68496SJames Smart void 22476669f9bbSJames Smart lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) 224804c68496SJames Smart { 224904c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 225004c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI); 22516669f9bbSJames Smart bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi, 22526d368e53SJames Smart vport->phba->sli4_hba.vfi_ids[vport->vfi]); 225304c68496SJames Smart } 225404c68496SJames Smart 225504c68496SJames Smart /** 2256026abb87SJames Smart * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23 225704c68496SJames Smart * @phba: pointer to the hba structure containing. 225804c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 225904c68496SJames Smart * 2260026abb87SJames Smart * This function create a SLI4 dump mailbox command to dump configure 2261026abb87SJames Smart * region 23. 226204c68496SJames Smart **/ 226304c68496SJames Smart int 2264026abb87SJames Smart lpfc_sli4_dump_cfg_rg23(struct lpfc_hba *phba, struct lpfcMboxq *mbox) 226504c68496SJames Smart { 226604c68496SJames Smart struct lpfc_dmabuf *mp = NULL; 226704c68496SJames Smart MAILBOX_t *mb; 226804c68496SJames Smart 226904c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 227004c68496SJames Smart mb = &mbox->u.mb; 227104c68496SJames Smart 227204c68496SJames Smart mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 227304c68496SJames Smart if (mp) 227404c68496SJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 227504c68496SJames Smart 227604c68496SJames Smart if (!mp || !mp->virt) { 227704c68496SJames Smart kfree(mp); 2278026abb87SJames Smart /* dump config region 23 failed to allocate memory */ 227904c68496SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 2280026abb87SJames Smart "2569 lpfc dump config region 23: memory" 228104c68496SJames Smart " allocation failed\n"); 228204c68496SJames Smart return 1; 228304c68496SJames Smart } 228404c68496SJames Smart 228504c68496SJames Smart memset(mp->virt, 0, LPFC_BPL_SIZE); 228604c68496SJames Smart INIT_LIST_HEAD(&mp->list); 228704c68496SJames Smart 228804c68496SJames Smart /* save address for completion */ 228904c68496SJames Smart mbox->context1 = (uint8_t *) mp; 229004c68496SJames Smart 229104c68496SJames Smart mb->mbxCommand = MBX_DUMP_MEMORY; 229204c68496SJames Smart mb->un.varDmp.type = DMP_NV_PARAMS; 2293a0c87cbdSJames Smart mb->un.varDmp.region_id = DMP_REGION_23; 2294a0c87cbdSJames Smart mb->un.varDmp.sli4_length = DMP_RGN23_SIZE; 229504c68496SJames Smart mb->un.varWords[3] = putPaddrLow(mp->phys); 229604c68496SJames Smart mb->un.varWords[4] = putPaddrHigh(mp->phys); 229704c68496SJames Smart return 0; 229804c68496SJames Smart } 229904c68496SJames Smart 2300bd4b3e5cSBaoyou Xie static void 230186478875SJames Smart lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) 230286478875SJames Smart { 230386478875SJames Smart MAILBOX_t *mb; 230486478875SJames Smart int rc = FAILURE; 230586478875SJames Smart struct lpfc_rdp_context *rdp_context = 230686478875SJames Smart (struct lpfc_rdp_context *)(mboxq->context2); 230786478875SJames Smart 230886478875SJames Smart mb = &mboxq->u.mb; 230986478875SJames Smart if (mb->mbxStatus) 231086478875SJames Smart goto mbx_failed; 231186478875SJames Smart 231286478875SJames Smart memcpy(&rdp_context->link_stat, &mb->un.varRdLnk, sizeof(READ_LNK_VAR)); 231386478875SJames Smart 231486478875SJames Smart rc = SUCCESS; 231586478875SJames Smart 231686478875SJames Smart mbx_failed: 231786478875SJames Smart lpfc_sli4_mbox_cmd_free(phba, mboxq); 231886478875SJames Smart rdp_context->cmpl(phba, rdp_context, rc); 231986478875SJames Smart } 232086478875SJames Smart 2321bd4b3e5cSBaoyou Xie static void 232286478875SJames Smart lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) 232386478875SJames Smart { 232486478875SJames Smart struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) mbox->context1; 232586478875SJames Smart struct lpfc_rdp_context *rdp_context = 232686478875SJames Smart (struct lpfc_rdp_context *)(mbox->context2); 232786478875SJames Smart 232886478875SJames Smart if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) 2329612872caSJohannes Thumshirn goto error_mbuf_free; 233086478875SJames Smart 233186478875SJames Smart lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2, 233286478875SJames Smart DMP_SFF_PAGE_A2_SIZE); 233386478875SJames Smart 233486478875SJames Smart /* We don't need dma buffer for link stat. */ 233586478875SJames Smart lpfc_mbuf_free(phba, mp->virt, mp->phys); 233686478875SJames Smart kfree(mp); 233786478875SJames Smart 233886478875SJames Smart memset(mbox, 0, sizeof(*mbox)); 233986478875SJames Smart lpfc_read_lnk_stat(phba, mbox); 234086478875SJames Smart mbox->vport = rdp_context->ndlp->vport; 234186478875SJames Smart mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_link_stat; 234286478875SJames Smart mbox->context2 = (struct lpfc_rdp_context *) rdp_context; 234386478875SJames Smart if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == MBX_NOT_FINISHED) 2344612872caSJohannes Thumshirn goto error_cmd_free; 234586478875SJames Smart 234686478875SJames Smart return; 234786478875SJames Smart 2348612872caSJohannes Thumshirn error_mbuf_free: 234986478875SJames Smart lpfc_mbuf_free(phba, mp->virt, mp->phys); 235086478875SJames Smart kfree(mp); 2351612872caSJohannes Thumshirn error_cmd_free: 235286478875SJames Smart lpfc_sli4_mbox_cmd_free(phba, mbox); 235386478875SJames Smart rdp_context->cmpl(phba, rdp_context, FAILURE); 235486478875SJames Smart } 235586478875SJames Smart 235686478875SJames Smart void 235786478875SJames Smart lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) 235886478875SJames Smart { 235986478875SJames Smart int rc; 236086478875SJames Smart struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (mbox->context1); 236186478875SJames Smart struct lpfc_rdp_context *rdp_context = 236286478875SJames Smart (struct lpfc_rdp_context *)(mbox->context2); 236386478875SJames Smart 236486478875SJames Smart if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) 236586478875SJames Smart goto error; 236686478875SJames Smart 236786478875SJames Smart lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0, 236886478875SJames Smart DMP_SFF_PAGE_A0_SIZE); 236986478875SJames Smart 237086478875SJames Smart memset(mbox, 0, sizeof(*mbox)); 237186478875SJames Smart 237286478875SJames Smart memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE); 237386478875SJames Smart INIT_LIST_HEAD(&mp->list); 237486478875SJames Smart 237586478875SJames Smart /* save address for completion */ 237686478875SJames Smart mbox->context1 = mp; 237786478875SJames Smart mbox->vport = rdp_context->ndlp->vport; 237886478875SJames Smart 237986478875SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY); 238086478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_type, 238186478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD); 238286478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_link, 238386478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port); 238486478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_page_no, 238586478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2); 238686478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_length, 238786478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE); 238886478875SJames Smart mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys); 238986478875SJames Smart mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys); 239086478875SJames Smart 239186478875SJames Smart mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a2; 239286478875SJames Smart mbox->context2 = (struct lpfc_rdp_context *) rdp_context; 239386478875SJames Smart rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 239486478875SJames Smart if (rc == MBX_NOT_FINISHED) 239586478875SJames Smart goto error; 239686478875SJames Smart 239786478875SJames Smart return; 239886478875SJames Smart 239986478875SJames Smart error: 240086478875SJames Smart lpfc_mbuf_free(phba, mp->virt, mp->phys); 240186478875SJames Smart kfree(mp); 240286478875SJames Smart lpfc_sli4_mbox_cmd_free(phba, mbox); 240386478875SJames Smart rdp_context->cmpl(phba, rdp_context, FAILURE); 240486478875SJames Smart } 240586478875SJames Smart 240686478875SJames Smart 240786478875SJames Smart /* 240886478875SJames Smart * lpfc_sli4_dump_sfp_pagea0 - Dump sli4 read SFP Diagnostic. 240986478875SJames Smart * @phba: pointer to the hba structure containing. 241086478875SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 241186478875SJames Smart * 241286478875SJames Smart * This function create a SLI4 dump mailbox command to dump configure 241386478875SJames Smart * type 3 page 0xA0. 241486478875SJames Smart */ 241586478875SJames Smart int 241686478875SJames Smart lpfc_sli4_dump_page_a0(struct lpfc_hba *phba, struct lpfcMboxq *mbox) 241786478875SJames Smart { 241886478875SJames Smart struct lpfc_dmabuf *mp = NULL; 241986478875SJames Smart 242086478875SJames Smart memset(mbox, 0, sizeof(*mbox)); 242186478875SJames Smart 242286478875SJames Smart mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 242386478875SJames Smart if (mp) 242486478875SJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 242586478875SJames Smart if (!mp || !mp->virt) { 242686478875SJames Smart kfree(mp); 242786478875SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 242886478875SJames Smart "3569 dump type 3 page 0xA0 allocation failed\n"); 242986478875SJames Smart return 1; 243086478875SJames Smart } 243186478875SJames Smart 243286478875SJames Smart memset(mp->virt, 0, LPFC_BPL_SIZE); 243386478875SJames Smart INIT_LIST_HEAD(&mp->list); 243486478875SJames Smart 243586478875SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY); 243686478875SJames Smart /* save address for completion */ 243786478875SJames Smart mbox->context1 = mp; 243886478875SJames Smart 243986478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_type, 244086478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD); 244186478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_link, 244286478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port); 244386478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_page_no, 244486478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A0); 244586478875SJames Smart bf_set(lpfc_mbx_memory_dump_type3_length, 244686478875SJames Smart &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE); 244786478875SJames Smart mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys); 244886478875SJames Smart mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys); 244986478875SJames Smart 245086478875SJames Smart return 0; 245186478875SJames Smart } 245286478875SJames Smart 245304c68496SJames Smart /** 245404c68496SJames Smart * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command 245504c68496SJames Smart * @phba: pointer to the hba structure containing the FCF index and RQ ID. 245604c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 245704c68496SJames Smart * 245804c68496SJames Smart * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The 245904c68496SJames Smart * SLI Host uses the command to activate an FCF after it has acquired FCF 246004c68496SJames Smart * information via a READ_FCF mailbox command. This mailbox command also is used 246104c68496SJames Smart * to indicate where received unsolicited frames from this FCF will be sent. By 246204c68496SJames Smart * default this routine will set up the FCF to forward all unsolicited frames 246304c68496SJames Smart * the the RQ ID passed in the @phba. This can be overridden by the caller for 246404c68496SJames Smart * more complicated setups. 246504c68496SJames Smart **/ 246604c68496SJames Smart void 246704c68496SJames Smart lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox) 246804c68496SJames Smart { 246904c68496SJames Smart struct lpfc_mbx_reg_fcfi *reg_fcfi; 247004c68496SJames Smart 247104c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 247204c68496SJames Smart reg_fcfi = &mbox->u.mqe.un.reg_fcfi; 247304c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI); 2474895427bdSJames Smart if (phba->nvmet_support == 0) { 2475895427bdSJames Smart bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, 2476895427bdSJames Smart phba->sli4_hba.hdr_rq->queue_id); 2477895427bdSJames Smart /* Match everything - rq_id0 */ 2478895427bdSJames Smart bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, 0); 2479895427bdSJames Smart bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0); 2480895427bdSJames Smart bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi, 0); 2481895427bdSJames Smart bf_set(lpfc_reg_fcfi_rctl_mask0, reg_fcfi, 0); 2482895427bdSJames Smart 248304c68496SJames Smart bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID); 2484895427bdSJames Smart 2485895427bdSJames Smart /* addr mode is bit wise inverted value of fcf addr_mode */ 2486895427bdSJames Smart bf_set(lpfc_reg_fcfi_mam, reg_fcfi, 2487895427bdSJames Smart (~phba->fcf.addr_mode) & 0x3); 24882d7dbc4cSJames Smart } else { 24892d7dbc4cSJames Smart /* This is ONLY for NVMET MRQ == 1 */ 24902d7dbc4cSJames Smart if (phba->cfg_nvmet_mrq != 1) 24912d7dbc4cSJames Smart return; 24922d7dbc4cSJames Smart 24932d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, 24942d7dbc4cSJames Smart phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id); 24952d7dbc4cSJames Smart /* Match type FCP - rq_id0 */ 24962d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, FC_TYPE_FCP); 24972d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0xff); 24982d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi, 24992d7dbc4cSJames Smart FC_RCTL_DD_UNSOL_CMD); 25002d7dbc4cSJames Smart 25012d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, 25022d7dbc4cSJames Smart phba->sli4_hba.hdr_rq->queue_id); 25032d7dbc4cSJames Smart /* Match everything else - rq_id1 */ 25042d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_type_match1, reg_fcfi, 0); 25052d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_type_mask1, reg_fcfi, 0); 25062d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_rctl_match1, reg_fcfi, 0); 25072d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_rctl_mask1, reg_fcfi, 0); 2508895427bdSJames Smart } 250904c68496SJames Smart bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID); 251004c68496SJames Smart bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID); 2511ecfd03c6SJames Smart bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, 2512ecfd03c6SJames Smart phba->fcf.current_rec.fcf_indx); 25133804dc84SJames Smart if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) { 251404c68496SJames Smart bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1); 2515ecfd03c6SJames Smart bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, 2516ecfd03c6SJames Smart phba->fcf.current_rec.vlan_id); 251704c68496SJames Smart } 251804c68496SJames Smart } 251904c68496SJames Smart 252004c68496SJames Smart /** 25212d7dbc4cSJames Smart * lpfc_reg_fcfi_mrq - Initialize the REG_FCFI_MRQ mailbox command 25222d7dbc4cSJames Smart * @phba: pointer to the hba structure containing the FCF index and RQ ID. 25232d7dbc4cSJames Smart * @mbox: pointer to lpfc mbox command to initialize. 25242d7dbc4cSJames Smart * @mode: 0 to register FCFI, 1 to register MRQs 25252d7dbc4cSJames Smart * 25262d7dbc4cSJames Smart * The REG_FCFI_MRQ mailbox command supports Fibre Channel Forwarders (FCFs). 25272d7dbc4cSJames Smart * The SLI Host uses the command to activate an FCF after it has acquired FCF 25282d7dbc4cSJames Smart * information via a READ_FCF mailbox command. This mailbox command also is used 25292d7dbc4cSJames Smart * to indicate where received unsolicited frames from this FCF will be sent. By 25302d7dbc4cSJames Smart * default this routine will set up the FCF to forward all unsolicited frames 25312d7dbc4cSJames Smart * the the RQ ID passed in the @phba. This can be overridden by the caller for 25322d7dbc4cSJames Smart * more complicated setups. 25332d7dbc4cSJames Smart **/ 25342d7dbc4cSJames Smart void 25352d7dbc4cSJames Smart lpfc_reg_fcfi_mrq(struct lpfc_hba *phba, struct lpfcMboxq *mbox, int mode) 25362d7dbc4cSJames Smart { 25372d7dbc4cSJames Smart struct lpfc_mbx_reg_fcfi_mrq *reg_fcfi; 25382d7dbc4cSJames Smart 25392d7dbc4cSJames Smart /* This is ONLY for MRQ */ 25402d7dbc4cSJames Smart if (phba->cfg_nvmet_mrq <= 1) 25412d7dbc4cSJames Smart return; 25422d7dbc4cSJames Smart 25432d7dbc4cSJames Smart memset(mbox, 0, sizeof(*mbox)); 25442d7dbc4cSJames Smart reg_fcfi = &mbox->u.mqe.un.reg_fcfi_mrq; 25452d7dbc4cSJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI_MRQ); 25462d7dbc4cSJames Smart if (mode == 0) { 25472d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_info_index, reg_fcfi, 25482d7dbc4cSJames Smart phba->fcf.current_rec.fcf_indx); 25492d7dbc4cSJames Smart if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) { 25502d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_vv, reg_fcfi, 1); 25512d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_vlan_tag, reg_fcfi, 25522d7dbc4cSJames Smart phba->fcf.current_rec.vlan_id); 25532d7dbc4cSJames Smart } 25542d7dbc4cSJames Smart return; 25552d7dbc4cSJames Smart } 25562d7dbc4cSJames Smart 25572d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rq_id0, reg_fcfi, 25582d7dbc4cSJames Smart phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id); 25592d7dbc4cSJames Smart /* Match NVME frames of type FCP (protocol NVME) - rq_id0 */ 25602d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_type_match0, reg_fcfi, FC_TYPE_FCP); 25612d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_type_mask0, reg_fcfi, 0xff); 25622d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rctl_match0, reg_fcfi, FC_RCTL_DD_UNSOL_CMD); 25632d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rctl_mask0, reg_fcfi, 0xff); 25642d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_ptc0, reg_fcfi, 1); 25652d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_pt0, reg_fcfi, 1); 25662d7dbc4cSJames Smart 25672d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_policy, reg_fcfi, 3); /* NVME connection id */ 25682d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_mode, reg_fcfi, 1); 25692d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_filter, reg_fcfi, 1); /* rq_id0 */ 25702d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_npairs, reg_fcfi, phba->cfg_nvmet_mrq); 25712d7dbc4cSJames Smart 25722d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rq_id1, reg_fcfi, 25732d7dbc4cSJames Smart phba->sli4_hba.hdr_rq->queue_id); 25742d7dbc4cSJames Smart /* Match everything - rq_id1 */ 25752d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_type_match1, reg_fcfi, 0); 25762d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_type_mask1, reg_fcfi, 0); 25772d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rctl_match1, reg_fcfi, 0); 25782d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rctl_mask1, reg_fcfi, 0); 25792d7dbc4cSJames Smart 25802d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rq_id2, reg_fcfi, REG_FCF_INVALID_QID); 25812d7dbc4cSJames Smart bf_set(lpfc_reg_fcfi_mrq_rq_id3, reg_fcfi, REG_FCF_INVALID_QID); 25822d7dbc4cSJames Smart } 25832d7dbc4cSJames Smart 25842d7dbc4cSJames Smart /** 258504c68496SJames Smart * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command 258604c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 258704c68496SJames Smart * @fcfi: FCFI to be unregistered. 258804c68496SJames Smart * 258904c68496SJames Smart * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). 259004c68496SJames Smart * The SLI Host uses the command to inactivate an FCFI. 259104c68496SJames Smart **/ 259204c68496SJames Smart void 259304c68496SJames Smart lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi) 259404c68496SJames Smart { 259504c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 259604c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI); 259704c68496SJames Smart bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi); 259804c68496SJames Smart } 259904c68496SJames Smart 260004c68496SJames Smart /** 260104c68496SJames Smart * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command 260204c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 260304c68496SJames Smart * @ndlp: The nodelist structure that describes the RPI to resume. 260404c68496SJames Smart * 260504c68496SJames Smart * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a 260604c68496SJames Smart * link event. 260704c68496SJames Smart **/ 260804c68496SJames Smart void 260904c68496SJames Smart lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp) 261004c68496SJames Smart { 26116d368e53SJames Smart struct lpfc_hba *phba = ndlp->phba; 261204c68496SJames Smart struct lpfc_mbx_resume_rpi *resume_rpi; 261304c68496SJames Smart 261404c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 261504c68496SJames Smart resume_rpi = &mbox->u.mqe.un.resume_rpi; 261604c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI); 26176d368e53SJames Smart bf_set(lpfc_resume_rpi_index, resume_rpi, 26186d368e53SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 26198fa38513SJames Smart bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI); 26208fa38513SJames Smart resume_rpi->event_tag = ndlp->phba->fc_eventTag; 262104c68496SJames Smart } 262228baac74SJames Smart 262328baac74SJames Smart /** 262428baac74SJames Smart * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages 262528baac74SJames Smart * mailbox command. 262628baac74SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 262728baac74SJames Smart * 262828baac74SJames Smart * The PORT_CAPABILITIES supported pages mailbox command is issued to 262928baac74SJames Smart * retrieve the particular feature pages supported by the port. 263028baac74SJames Smart **/ 263128baac74SJames Smart void 263228baac74SJames Smart lpfc_supported_pages(struct lpfcMboxq *mbox) 263328baac74SJames Smart { 263428baac74SJames Smart struct lpfc_mbx_supp_pages *supp_pages; 263528baac74SJames Smart 263628baac74SJames Smart memset(mbox, 0, sizeof(*mbox)); 263728baac74SJames Smart supp_pages = &mbox->u.mqe.un.supp_pages; 263828baac74SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES); 263928baac74SJames Smart bf_set(cpn, supp_pages, LPFC_SUPP_PAGES); 264028baac74SJames Smart } 264128baac74SJames Smart 264228baac74SJames Smart /** 2643fedd3b7bSJames Smart * lpfc_pc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params mbox cmd. 264428baac74SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 264528baac74SJames Smart * 264628baac74SJames Smart * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to 264728baac74SJames Smart * retrieve the particular SLI4 features supported by the port. 264828baac74SJames Smart **/ 264928baac74SJames Smart void 2650fedd3b7bSJames Smart lpfc_pc_sli4_params(struct lpfcMboxq *mbox) 265128baac74SJames Smart { 2652fedd3b7bSJames Smart struct lpfc_mbx_pc_sli4_params *sli4_params; 265328baac74SJames Smart 265428baac74SJames Smart memset(mbox, 0, sizeof(*mbox)); 265528baac74SJames Smart sli4_params = &mbox->u.mqe.un.sli4_params; 265628baac74SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES); 265728baac74SJames Smart bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS); 265828baac74SJames Smart } 2659