1dea3101eS /******************************************************************* 2dea3101eS * This file is part of the Emulex Linux Device Driver for * 3c44ce173SJames.Smart@Emulex.Com * Fibre Channel Host Bus Adapters. * 492c13f29SJames Smart * Copyright (C) 2004-2013 Emulex. All rights reserved. * 5c44ce173SJames.Smart@Emulex.Com * EMULEX and SLI are trademarks of Emulex. * 6dea3101eS * www.emulex.com * 7c44ce173SJames.Smart@Emulex.Com * Portions Copyright (C) 2004-2005 Christoph Hellwig * 8dea3101eS * * 9dea3101eS * This program is free software; you can redistribute it and/or * 10c44ce173SJames.Smart@Emulex.Com * modify it under the terms of version 2 of the GNU General * 11c44ce173SJames.Smart@Emulex.Com * Public License as published by the Free Software Foundation. * 12c44ce173SJames.Smart@Emulex.Com * This program is distributed in the hope that it will be useful. * 13c44ce173SJames.Smart@Emulex.Com * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 14c44ce173SJames.Smart@Emulex.Com * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 15c44ce173SJames.Smart@Emulex.Com * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 16c44ce173SJames.Smart@Emulex.Com * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 17c44ce173SJames.Smart@Emulex.Com * TO BE LEGALLY INVALID. See the GNU General Public License for * 18c44ce173SJames.Smart@Emulex.Com * more details, a copy of which can be found in the file COPYING * 19c44ce173SJames.Smart@Emulex.Com * included with this package. * 20dea3101eS *******************************************************************/ 21dea3101eS 22dea3101eS #include <linux/blkdev.h> 23dea3101eS #include <linux/pci.h> 245a0e3ad6STejun Heo #include <linux/slab.h> 25dea3101eS #include <linux/interrupt.h> 26dea3101eS 27f888ba3cSJames.Smart@Emulex.Com #include <scsi/scsi_device.h> 28f888ba3cSJames.Smart@Emulex.Com #include <scsi/scsi_transport_fc.h> 2991886523SJames.Smart@Emulex.Com #include <scsi/scsi.h> 306a9c52cfSJames Smart #include <scsi/fc/fc_fs.h> 3191886523SJames.Smart@Emulex.Com 32da0436e9SJames Smart #include "lpfc_hw4.h" 33dea3101eS #include "lpfc_hw.h" 34dea3101eS #include "lpfc_sli.h" 35da0436e9SJames Smart #include "lpfc_sli4.h" 36ea2151b4SJames Smart #include "lpfc_nl.h" 37dea3101eS #include "lpfc_disc.h" 38dea3101eS #include "lpfc_scsi.h" 39dea3101eS #include "lpfc.h" 40dea3101eS #include "lpfc_logmsg.h" 41dea3101eS #include "lpfc_crtn.h" 42dea3101eS #include "lpfc_compat.h" 43dea3101eS 44e59058c4SJames Smart /** 4521e9a0a5SJames Smart * lpfc_dump_static_vport - Dump HBA's static vport information. 4621e9a0a5SJames Smart * @phba: pointer to lpfc hba data structure. 4721e9a0a5SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 4821e9a0a5SJames Smart * @offset: offset for dumping vport info. 4921e9a0a5SJames Smart * 5021e9a0a5SJames Smart * The dump mailbox command provides a method for the device driver to obtain 5121e9a0a5SJames Smart * various types of information from the HBA device. 5221e9a0a5SJames Smart * 5321e9a0a5SJames Smart * This routine prepares the mailbox command for dumping list of static 5421e9a0a5SJames Smart * vports to be created. 5521e9a0a5SJames Smart **/ 561c6834a7SJames Smart int 5721e9a0a5SJames Smart lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, 5821e9a0a5SJames Smart uint16_t offset) 5921e9a0a5SJames Smart { 6021e9a0a5SJames Smart MAILBOX_t *mb; 611c6834a7SJames Smart struct lpfc_dmabuf *mp; 6221e9a0a5SJames Smart 6321e9a0a5SJames Smart mb = &pmb->u.mb; 6421e9a0a5SJames Smart 6521e9a0a5SJames Smart /* Setup to dump vport info region */ 6621e9a0a5SJames Smart memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 6721e9a0a5SJames Smart mb->mbxCommand = MBX_DUMP_MEMORY; 6821e9a0a5SJames Smart mb->un.varDmp.type = DMP_NV_PARAMS; 6921e9a0a5SJames Smart mb->un.varDmp.entry_index = offset; 7021e9a0a5SJames Smart mb->un.varDmp.region_id = DMP_REGION_VPORT; 7121e9a0a5SJames Smart mb->mbxOwner = OWN_HOST; 7221e9a0a5SJames Smart 731c6834a7SJames Smart /* For SLI3 HBAs data is embedded in mailbox */ 741c6834a7SJames Smart if (phba->sli_rev != LPFC_SLI_REV4) { 751c6834a7SJames Smart mb->un.varDmp.cv = 1; 761c6834a7SJames Smart mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t); 771c6834a7SJames Smart return 0; 781c6834a7SJames Smart } 791c6834a7SJames Smart 801c6834a7SJames Smart /* For SLI4 HBAs driver need to allocate memory */ 811c6834a7SJames Smart mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 821c6834a7SJames Smart if (mp) 831c6834a7SJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 841c6834a7SJames Smart 851c6834a7SJames Smart if (!mp || !mp->virt) { 861c6834a7SJames Smart kfree(mp); 871c6834a7SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, 881c6834a7SJames Smart "2605 lpfc_dump_static_vport: memory" 891c6834a7SJames Smart " allocation failed\n"); 901c6834a7SJames Smart return 1; 911c6834a7SJames Smart } 921c6834a7SJames Smart memset(mp->virt, 0, LPFC_BPL_SIZE); 931c6834a7SJames Smart INIT_LIST_HEAD(&mp->list); 941c6834a7SJames Smart /* save address for completion */ 95cdcc2343SJames Smart pmb->context1 = (uint8_t *)mp; 961c6834a7SJames Smart mb->un.varWords[3] = putPaddrLow(mp->phys); 971c6834a7SJames Smart mb->un.varWords[4] = putPaddrHigh(mp->phys); 981c6834a7SJames Smart mb->un.varDmp.sli4_length = sizeof(struct static_vport_info); 991c6834a7SJames Smart 1001c6834a7SJames Smart return 0; 10121e9a0a5SJames Smart } 10221e9a0a5SJames Smart 10321e9a0a5SJames Smart /** 104a0c87cbdSJames Smart * lpfc_down_link - Bring down HBAs link. 105e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 106e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 107a0c87cbdSJames Smart * 108a0c87cbdSJames Smart * This routine prepares a mailbox command to bring down HBA link. 109a0c87cbdSJames Smart **/ 110a0c87cbdSJames Smart void 111a0c87cbdSJames Smart lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 112a0c87cbdSJames Smart { 113a0c87cbdSJames Smart MAILBOX_t *mb; 114a0c87cbdSJames Smart memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 115a0c87cbdSJames Smart mb = &pmb->u.mb; 116a0c87cbdSJames Smart mb->mbxCommand = MBX_DOWN_LINK; 117a0c87cbdSJames Smart mb->mbxOwner = OWN_HOST; 118a0c87cbdSJames Smart } 119a0c87cbdSJames Smart 120a0c87cbdSJames Smart /** 121a0c87cbdSJames Smart * lpfc_dump_mem - Prepare a mailbox command for reading a region. 122a0c87cbdSJames Smart * @phba: pointer to lpfc hba data structure. 123a0c87cbdSJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 124a0c87cbdSJames Smart * @offset: offset into the region. 125a0c87cbdSJames Smart * @region_id: config region id. 126e59058c4SJames Smart * 127e59058c4SJames Smart * The dump mailbox command provides a method for the device driver to obtain 128e59058c4SJames Smart * various types of information from the HBA device. 129e59058c4SJames Smart * 130a0c87cbdSJames Smart * This routine prepares the mailbox command for dumping HBA's config region. 131e59058c4SJames Smart **/ 132dea3101eS void 133a0c87cbdSJames Smart lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset, 134a0c87cbdSJames Smart uint16_t region_id) 135dea3101eS { 136dea3101eS MAILBOX_t *mb; 137dea3101eS void *ctx; 138dea3101eS 13904c68496SJames Smart mb = &pmb->u.mb; 140dea3101eS ctx = pmb->context2; 141dea3101eS 142dea3101eS /* Setup to dump VPD region */ 143dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 144dea3101eS mb->mbxCommand = MBX_DUMP_MEMORY; 145dea3101eS mb->un.varDmp.cv = 1; 146dea3101eS mb->un.varDmp.type = DMP_NV_PARAMS; 147dea3101eS mb->un.varDmp.entry_index = offset; 148a0c87cbdSJames Smart mb->un.varDmp.region_id = region_id; 149dea3101eS mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t)); 150dea3101eS mb->un.varDmp.co = 0; 151dea3101eS mb->un.varDmp.resp_offset = 0; 152dea3101eS pmb->context2 = ctx; 153dea3101eS mb->mbxOwner = OWN_HOST; 154dea3101eS return; 155dea3101eS } 156dea3101eS 157e59058c4SJames Smart /** 1583621a710SJames Smart * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params 15997207482SJames Smart * @phba: pointer to lpfc hba data structure. 16097207482SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1613621a710SJames Smart * 16297207482SJames Smart * This function create a dump memory mailbox command to dump wake up 16397207482SJames Smart * parameters. 16497207482SJames Smart */ 16597207482SJames Smart void 16697207482SJames Smart lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 16797207482SJames Smart { 16897207482SJames Smart MAILBOX_t *mb; 16997207482SJames Smart void *ctx; 17097207482SJames Smart 17104c68496SJames Smart mb = &pmb->u.mb; 17297207482SJames Smart /* Save context so that we can restore after memset */ 17397207482SJames Smart ctx = pmb->context2; 17497207482SJames Smart 17597207482SJames Smart /* Setup to dump VPD region */ 17697207482SJames Smart memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 17797207482SJames Smart mb->mbxCommand = MBX_DUMP_MEMORY; 17897207482SJames Smart mb->mbxOwner = OWN_HOST; 17997207482SJames Smart mb->un.varDmp.cv = 1; 18097207482SJames Smart mb->un.varDmp.type = DMP_NV_PARAMS; 1811d1c296fSJames Smart if (phba->sli_rev < LPFC_SLI_REV4) 18297207482SJames Smart mb->un.varDmp.entry_index = 0; 18397207482SJames Smart mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID; 18497207482SJames Smart mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE; 18597207482SJames Smart mb->un.varDmp.co = 0; 18697207482SJames Smart mb->un.varDmp.resp_offset = 0; 18797207482SJames Smart pmb->context2 = ctx; 18897207482SJames Smart return; 18997207482SJames Smart } 19097207482SJames Smart 19197207482SJames Smart /** 1923621a710SJames Smart * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param 193e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 194e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 195e59058c4SJames Smart * 196e59058c4SJames Smart * The read NVRAM mailbox command returns the HBA's non-volatile parameters 197e59058c4SJames Smart * that are used as defaults when the Fibre Channel link is brought on-line. 198e59058c4SJames Smart * 199e59058c4SJames Smart * This routine prepares the mailbox command for reading information stored 200e59058c4SJames Smart * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN. 201e59058c4SJames Smart **/ 202dea3101eS void 203dea3101eS lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 204dea3101eS { 205dea3101eS MAILBOX_t *mb; 206dea3101eS 20704c68496SJames Smart mb = &pmb->u.mb; 208dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 209dea3101eS mb->mbxCommand = MBX_READ_NV; 210dea3101eS mb->mbxOwner = OWN_HOST; 211dea3101eS return; 212dea3101eS } 213dea3101eS 214e59058c4SJames Smart /** 2153621a710SJames Smart * lpfc_config_async - Prepare a mailbox command for enabling HBA async event 216e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 217e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 218e59058c4SJames Smart * @ring: ring number for the asynchronous event to be configured. 219e59058c4SJames Smart * 220e59058c4SJames Smart * The asynchronous event enable mailbox command is used to enable the 221e59058c4SJames Smart * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and 222e59058c4SJames Smart * specifies the default ring to which events are posted. 223e59058c4SJames Smart * 224e59058c4SJames Smart * This routine prepares the mailbox command for enabling HBA asynchronous 225e59058c4SJames Smart * event support on a IOCB ring. 226e59058c4SJames Smart **/ 22757127f15SJames Smart void 22857127f15SJames Smart lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, 22957127f15SJames Smart uint32_t ring) 23057127f15SJames Smart { 23157127f15SJames Smart MAILBOX_t *mb; 23257127f15SJames Smart 23304c68496SJames Smart mb = &pmb->u.mb; 23457127f15SJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 23557127f15SJames Smart mb->mbxCommand = MBX_ASYNCEVT_ENABLE; 23657127f15SJames Smart mb->un.varCfgAsyncEvent.ring = ring; 23757127f15SJames Smart mb->mbxOwner = OWN_HOST; 23857127f15SJames Smart return; 23957127f15SJames Smart } 24057127f15SJames Smart 241e59058c4SJames Smart /** 2423621a710SJames Smart * lpfc_heart_beat - Prepare a mailbox command for heart beat 243e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 244e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 245e59058c4SJames Smart * 246e59058c4SJames Smart * The heart beat mailbox command is used to detect an unresponsive HBA, which 247e59058c4SJames Smart * is defined as any device where no error attention is sent and both mailbox 248e59058c4SJames Smart * and rings are not processed. 249e59058c4SJames Smart * 250e59058c4SJames Smart * This routine prepares the mailbox command for issuing a heart beat in the 251e59058c4SJames Smart * form of mailbox command to the HBA. The timely completion of the heart 252e59058c4SJames Smart * beat mailbox command indicates the health of the HBA. 253e59058c4SJames Smart **/ 254858c9f6cSJames Smart void 255858c9f6cSJames Smart lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 256858c9f6cSJames Smart { 257858c9f6cSJames Smart MAILBOX_t *mb; 258858c9f6cSJames Smart 25904c68496SJames Smart mb = &pmb->u.mb; 260858c9f6cSJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 261858c9f6cSJames Smart mb->mbxCommand = MBX_HEARTBEAT; 262858c9f6cSJames Smart mb->mbxOwner = OWN_HOST; 263858c9f6cSJames Smart return; 264858c9f6cSJames Smart } 265858c9f6cSJames Smart 266e59058c4SJames Smart /** 26776a95d75SJames Smart * lpfc_read_topology - Prepare a mailbox command for reading HBA topology 268e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 269e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 270e59058c4SJames Smart * @mp: DMA buffer memory for reading the link attention information into. 271e59058c4SJames Smart * 27276a95d75SJames Smart * The read topology mailbox command is issued to read the link topology 27376a95d75SJames Smart * information indicated by the HBA port when the Link Event bit of the Host 27476a95d75SJames Smart * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link 27576a95d75SJames Smart * Attention ACQE is received from the port (For SLI-4). A Link Event 276e59058c4SJames Smart * Attention occurs based on an exception detected at the Fibre Channel link 277e59058c4SJames Smart * interface. 278e59058c4SJames Smart * 27976a95d75SJames Smart * This routine prepares the mailbox command for reading HBA link topology 280e59058c4SJames Smart * information. A DMA memory has been set aside and address passed to the 281e59058c4SJames Smart * HBA through @mp for the HBA to DMA link attention information into the 282e59058c4SJames Smart * memory as part of the execution of the mailbox command. 283e59058c4SJames Smart * 284e59058c4SJames Smart * Return codes 285e59058c4SJames Smart * 0 - Success (currently always return 0) 286e59058c4SJames Smart **/ 287dea3101eS int 28876a95d75SJames Smart lpfc_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, 28976a95d75SJames Smart struct lpfc_dmabuf *mp) 290dea3101eS { 291dea3101eS MAILBOX_t *mb; 292dea3101eS struct lpfc_sli *psli; 293dea3101eS 294dea3101eS psli = &phba->sli; 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; 379dea3101eS mb->un.varCfgLnk.citov = phba->fc_citov; 380dea3101eS 3811d1c296fSJames Smart if (phba->cfg_ack0 && (phba->sli_rev < LPFC_SLI_REV4)) 382dea3101eS mb->un.varCfgLnk.ack0_enable = 1; 383dea3101eS 384dea3101eS mb->mbxCommand = MBX_CONFIG_LINK; 385dea3101eS mb->mbxOwner = OWN_HOST; 386dea3101eS return; 387dea3101eS } 388dea3101eS 389e59058c4SJames Smart /** 3903621a710SJames Smart * lpfc_config_msi - Prepare a mailbox command for configuring msi-x 3919399627fSJames Smart * @phba: pointer to lpfc hba data structure. 3929399627fSJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 3939399627fSJames Smart * 3949399627fSJames Smart * The configure MSI-X mailbox command is used to configure the HBA's SLI-3 3959399627fSJames Smart * MSI-X multi-message interrupt vector association to interrupt attention 3969399627fSJames Smart * conditions. 3979399627fSJames Smart * 3989399627fSJames Smart * Return codes 3999399627fSJames Smart * 0 - Success 4009399627fSJames Smart * -EINVAL - Failure 4019399627fSJames Smart **/ 4029399627fSJames Smart int 4039399627fSJames Smart lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 4049399627fSJames Smart { 40504c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 4069399627fSJames Smart uint32_t attentionConditions[2]; 4079399627fSJames Smart 4089399627fSJames Smart /* Sanity check */ 4099399627fSJames Smart if (phba->cfg_use_msi != 2) { 4109399627fSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4119399627fSJames Smart "0475 Not configured for supporting MSI-X " 4129399627fSJames Smart "cfg_use_msi: 0x%x\n", phba->cfg_use_msi); 4139399627fSJames Smart return -EINVAL; 4149399627fSJames Smart } 4159399627fSJames Smart 4169399627fSJames Smart if (phba->sli_rev < 3) { 4179399627fSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4189399627fSJames Smart "0476 HBA not supporting SLI-3 or later " 4199399627fSJames Smart "SLI Revision: 0x%x\n", phba->sli_rev); 4209399627fSJames Smart return -EINVAL; 4219399627fSJames Smart } 4229399627fSJames Smart 4239399627fSJames Smart /* Clear mailbox command fields */ 4249399627fSJames Smart memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 4259399627fSJames Smart 4269399627fSJames Smart /* 4279399627fSJames Smart * SLI-3, Message Signaled Interrupt Fearure. 4289399627fSJames Smart */ 4299399627fSJames Smart 4309399627fSJames Smart /* Multi-message attention configuration */ 4319399627fSJames Smart attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT | 4329399627fSJames Smart HA_LATT | HA_MBATT); 4339399627fSJames Smart attentionConditions[1] = 0; 4349399627fSJames Smart 4359399627fSJames Smart mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0]; 4369399627fSJames Smart mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1]; 4379399627fSJames Smart 4389399627fSJames Smart /* 4399399627fSJames Smart * Set up message number to HA bit association 4409399627fSJames Smart */ 4419399627fSJames Smart #ifdef __BIG_ENDIAN_BITFIELD 4429399627fSJames Smart /* RA0 (FCP Ring) */ 4439399627fSJames Smart mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1; 4449399627fSJames Smart /* RA1 (Other Protocol Extra Ring) */ 4459399627fSJames Smart mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1; 4469399627fSJames Smart #else /* __LITTLE_ENDIAN_BITFIELD */ 4479399627fSJames Smart /* RA0 (FCP Ring) */ 4489399627fSJames Smart mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1; 4499399627fSJames Smart /* RA1 (Other Protocol Extra Ring) */ 4509399627fSJames Smart mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1; 4519399627fSJames Smart #endif 4529399627fSJames Smart /* Multi-message interrupt autoclear configuration*/ 4539399627fSJames Smart mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0]; 4549399627fSJames Smart mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1]; 4559399627fSJames Smart 4569399627fSJames Smart /* For now, HBA autoclear does not work reliably, disable it */ 4579399627fSJames Smart mb->un.varCfgMSI.autoClearHA[0] = 0; 4589399627fSJames Smart mb->un.varCfgMSI.autoClearHA[1] = 0; 4599399627fSJames Smart 4609399627fSJames Smart /* Set command and owner bit */ 4619399627fSJames Smart mb->mbxCommand = MBX_CONFIG_MSI; 4629399627fSJames Smart mb->mbxOwner = OWN_HOST; 4639399627fSJames Smart 4649399627fSJames Smart return 0; 4659399627fSJames Smart } 4669399627fSJames Smart 4679399627fSJames Smart /** 4683621a710SJames Smart * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA 469e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 470e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 471e59058c4SJames Smart * @topology: the link topology for the link to be initialized to. 472e59058c4SJames Smart * @linkspeed: the link speed for the link to be initialized to. 473e59058c4SJames Smart * 474e59058c4SJames Smart * The initialize link mailbox command is used to initialize the Fibre 475e59058c4SJames Smart * Channel link. This command must follow a configure port command that 476e59058c4SJames Smart * establishes the mode of operation. 477e59058c4SJames Smart * 478e59058c4SJames Smart * This routine prepares the mailbox command for initializing link on a HBA 479e59058c4SJames Smart * with the specified link topology and speed. 480e59058c4SJames Smart **/ 481dea3101eS void 482dea3101eS lpfc_init_link(struct lpfc_hba * phba, 483dea3101eS LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed) 484dea3101eS { 485dea3101eS lpfc_vpd_t *vpd; 486dea3101eS struct lpfc_sli *psli; 487dea3101eS MAILBOX_t *mb; 488dea3101eS 48904c68496SJames Smart mb = &pmb->u.mb; 490dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 491dea3101eS 492dea3101eS psli = &phba->sli; 493dea3101eS switch (topology) { 494dea3101eS case FLAGS_TOPOLOGY_MODE_LOOP_PT: 495dea3101eS mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; 496dea3101eS mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; 497dea3101eS break; 498dea3101eS case FLAGS_TOPOLOGY_MODE_PT_PT: 499dea3101eS mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; 500dea3101eS break; 501dea3101eS case FLAGS_TOPOLOGY_MODE_LOOP: 502dea3101eS mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; 503dea3101eS break; 504dea3101eS case FLAGS_TOPOLOGY_MODE_PT_LOOP: 505dea3101eS mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; 506dea3101eS mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; 507dea3101eS break; 508367c2713SJamie Wellnitz case FLAGS_LOCAL_LB: 509367c2713SJamie Wellnitz mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB; 510367c2713SJamie Wellnitz break; 511dea3101eS } 512dea3101eS 5134b0b91d4SJames Smart /* Enable asynchronous ABTS responses from firmware */ 5144b0b91d4SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT; 5154b0b91d4SJames Smart 516dea3101eS /* NEW_FEATURE 517dea3101eS * Setting up the link speed 518dea3101eS */ 519dea3101eS vpd = &phba->vpd; 520dea3101eS if (vpd->rev.feaLevelHigh >= 0x02){ 521dea3101eS switch(linkspeed){ 52276a95d75SJames Smart case LPFC_USER_LINK_SPEED_1G: 52376a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 52476a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_1G; 525dea3101eS break; 52676a95d75SJames Smart case LPFC_USER_LINK_SPEED_2G: 52776a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 52876a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_2G; 52976a95d75SJames Smart break; 53076a95d75SJames Smart case LPFC_USER_LINK_SPEED_4G: 53176a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 53276a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_4G; 53376a95d75SJames Smart break; 53476a95d75SJames Smart case LPFC_USER_LINK_SPEED_8G: 53576a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 53676a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_8G; 53776a95d75SJames Smart break; 53876a95d75SJames Smart case LPFC_USER_LINK_SPEED_10G: 53976a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 54076a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_10G; 54176a95d75SJames Smart break; 54276a95d75SJames Smart case LPFC_USER_LINK_SPEED_16G: 54376a95d75SJames Smart mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; 54476a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_16G; 54576a95d75SJames Smart break; 54676a95d75SJames Smart case LPFC_USER_LINK_SPEED_AUTO: 547dea3101eS default: 54876a95d75SJames Smart mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; 549dea3101eS break; 550dea3101eS } 551dea3101eS 552dea3101eS } 553dea3101eS else 554dea3101eS mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; 555dea3101eS 556dea3101eS mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK; 557dea3101eS mb->mbxOwner = OWN_HOST; 558dea3101eS mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA; 559dea3101eS return; 560dea3101eS } 561dea3101eS 562e59058c4SJames Smart /** 5633621a710SJames Smart * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters 564e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 565e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 566e59058c4SJames Smart * @vpi: virtual N_Port identifier. 567e59058c4SJames Smart * 568e59058c4SJames Smart * The read service parameter mailbox command is used to read the HBA port 569e59058c4SJames Smart * service parameters. The service parameters are read into the buffer 570e59058c4SJames Smart * specified directly by a BDE in the mailbox command. These service 571e59058c4SJames Smart * parameters may then be used to build the payload of an N_Port/F_POrt 572e59058c4SJames Smart * login request and reply (LOGI/ACC). 573e59058c4SJames Smart * 574e59058c4SJames Smart * This routine prepares the mailbox command for reading HBA port service 575e59058c4SJames Smart * parameters. The DMA memory is allocated in this function and the addresses 576e59058c4SJames Smart * are populated into the mailbox command for the HBA to DMA the service 577e59058c4SJames Smart * parameters into. 578e59058c4SJames Smart * 579e59058c4SJames Smart * Return codes 580e59058c4SJames Smart * 0 - Success 581e59058c4SJames Smart * 1 - DMA memory allocation failed 582e59058c4SJames Smart **/ 583dea3101eS int 58492d7f7b0SJames Smart lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi) 585dea3101eS { 586dea3101eS struct lpfc_dmabuf *mp; 587dea3101eS MAILBOX_t *mb; 588dea3101eS struct lpfc_sli *psli; 589dea3101eS 590dea3101eS psli = &phba->sli; 59104c68496SJames Smart mb = &pmb->u.mb; 592dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 593dea3101eS 594dea3101eS mb->mbxOwner = OWN_HOST; 595dea3101eS 596dea3101eS /* Get a buffer to hold the HBAs Service Parameters */ 597dea3101eS 59898c9ea5cSJames Smart mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); 59998c9ea5cSJames Smart if (mp) 60098c9ea5cSJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 60198c9ea5cSJames Smart if (!mp || !mp->virt) { 602dea3101eS kfree(mp); 603dea3101eS mb->mbxCommand = MBX_READ_SPARM64; 604dea3101eS /* READ_SPARAM: no buffers */ 605e8b62011SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 606e8b62011SJames Smart "0301 READ_SPARAM: no buffers\n"); 60792d7f7b0SJames Smart return (1); 608dea3101eS } 609dea3101eS INIT_LIST_HEAD(&mp->list); 610dea3101eS mb->mbxCommand = MBX_READ_SPARM64; 611dea3101eS mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); 612dea3101eS mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys); 613dea3101eS mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys); 6146d368e53SJames Smart if (phba->sli_rev >= LPFC_SLI_REV3) 6156d368e53SJames Smart mb->un.varRdSparm.vpi = phba->vpi_ids[vpi]; 616dea3101eS 617dea3101eS /* save address for completion */ 618dea3101eS pmb->context1 = mp; 619dea3101eS 62092d7f7b0SJames Smart return (0); 621dea3101eS } 622dea3101eS 623e59058c4SJames Smart /** 6243621a710SJames Smart * lpfc_unreg_did - Prepare a mailbox command for unregistering DID 625e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 626e59058c4SJames Smart * @vpi: virtual N_Port identifier. 627e59058c4SJames Smart * @did: remote port identifier. 628e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 629e59058c4SJames Smart * 630e59058c4SJames Smart * The unregister DID mailbox command is used to unregister an N_Port/F_Port 631e59058c4SJames Smart * login for an unknown RPI by specifying the DID of a remote port. This 632e59058c4SJames Smart * command frees an RPI context in the HBA port. This has the effect of 633e59058c4SJames Smart * performing an implicit N_Port/F_Port logout. 634e59058c4SJames Smart * 635e59058c4SJames Smart * This routine prepares the mailbox command for unregistering a remote 636e59058c4SJames Smart * N_Port/F_Port (DID) login. 637e59058c4SJames Smart **/ 638dea3101eS void 63992d7f7b0SJames Smart lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did, 64092d7f7b0SJames Smart LPFC_MBOXQ_t * pmb) 641dea3101eS { 642dea3101eS MAILBOX_t *mb; 643dea3101eS 64404c68496SJames Smart mb = &pmb->u.mb; 645dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 646dea3101eS 647dea3101eS mb->un.varUnregDID.did = did; 64892d7f7b0SJames Smart mb->un.varUnregDID.vpi = vpi; 6496d368e53SJames Smart if ((vpi != 0xffff) && 6506d368e53SJames Smart (phba->sli_rev == LPFC_SLI_REV4)) 6516d368e53SJames Smart mb->un.varUnregDID.vpi = phba->vpi_ids[vpi]; 652dea3101eS 653dea3101eS mb->mbxCommand = MBX_UNREG_D_ID; 654dea3101eS mb->mbxOwner = OWN_HOST; 655dea3101eS return; 656dea3101eS } 657dea3101eS 658e59058c4SJames Smart /** 6593621a710SJames Smart * lpfc_read_config - Prepare a mailbox command for reading HBA configuration 660e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 661e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 662e59058c4SJames Smart * 663e59058c4SJames Smart * The read configuration mailbox command is used to read the HBA port 664e59058c4SJames Smart * configuration parameters. This mailbox command provides a method for 665e59058c4SJames Smart * seeing any parameters that may have changed via various configuration 666e59058c4SJames Smart * mailbox commands. 667e59058c4SJames Smart * 668e59058c4SJames Smart * This routine prepares the mailbox command for reading out HBA configuration 669e59058c4SJames Smart * parameters. 670e59058c4SJames Smart **/ 671dea3101eS void 672dea3101eS lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 673dea3101eS { 674dea3101eS MAILBOX_t *mb; 675dea3101eS 67604c68496SJames Smart mb = &pmb->u.mb; 677dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 678dea3101eS 679dea3101eS mb->mbxCommand = MBX_READ_CONFIG; 680dea3101eS mb->mbxOwner = OWN_HOST; 681dea3101eS return; 682dea3101eS } 683dea3101eS 684e59058c4SJames Smart /** 6853621a710SJames Smart * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats 686e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 687e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 688e59058c4SJames Smart * 689e59058c4SJames Smart * The read link status mailbox command is used to read the link status from 690e59058c4SJames Smart * the HBA. Link status includes all link-related error counters. These 691e59058c4SJames Smart * counters are maintained by the HBA and originated in the link hardware 692e59058c4SJames Smart * unit. Note that all of these counters wrap. 693e59058c4SJames Smart * 694e59058c4SJames Smart * This routine prepares the mailbox command for reading out HBA link status. 695e59058c4SJames Smart **/ 6967bb3b137SJamie Wellnitz void 6977bb3b137SJamie Wellnitz lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 6987bb3b137SJamie Wellnitz { 6997bb3b137SJamie Wellnitz MAILBOX_t *mb; 7007bb3b137SJamie Wellnitz 70104c68496SJames Smart mb = &pmb->u.mb; 7027bb3b137SJamie Wellnitz memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 7037bb3b137SJamie Wellnitz 7047bb3b137SJamie Wellnitz mb->mbxCommand = MBX_READ_LNK_STAT; 7057bb3b137SJamie Wellnitz mb->mbxOwner = OWN_HOST; 7067bb3b137SJamie Wellnitz return; 7077bb3b137SJamie Wellnitz } 7087bb3b137SJamie Wellnitz 709e59058c4SJames Smart /** 71004c68496SJames Smart * lpfc_reg_rpi - Prepare a mailbox command for registering remote login 711e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 712e59058c4SJames Smart * @vpi: virtual N_Port identifier. 713e59058c4SJames Smart * @did: remote port identifier. 714e59058c4SJames Smart * @param: pointer to memory holding the server parameters. 715e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 7164042629eSJames Smart * @rpi: the rpi to use in the registration (usually only used for SLI4. 717e59058c4SJames Smart * 718e59058c4SJames Smart * The registration login mailbox command is used to register an N_Port or 719e59058c4SJames Smart * F_Port login. This registration allows the HBA to cache the remote N_Port 720e59058c4SJames Smart * service parameters internally and thereby make the appropriate FC-2 721e59058c4SJames Smart * decisions. The remote port service parameters are handed off by the driver 722e59058c4SJames Smart * to the HBA using a descriptor entry that directly identifies a buffer in 723e59058c4SJames Smart * host memory. In exchange, the HBA returns an RPI identifier. 724e59058c4SJames Smart * 725e59058c4SJames Smart * This routine prepares the mailbox command for registering remote port login. 726e59058c4SJames Smart * The function allocates DMA buffer for passing the service parameters to the 727e59058c4SJames Smart * HBA with the mailbox command. 728e59058c4SJames Smart * 729e59058c4SJames Smart * Return codes 730e59058c4SJames Smart * 0 - Success 731e59058c4SJames Smart * 1 - DMA memory allocation failed 732e59058c4SJames Smart **/ 733dea3101eS int 73404c68496SJames Smart lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did, 7354042629eSJames Smart uint8_t *param, LPFC_MBOXQ_t *pmb, uint16_t rpi) 736dea3101eS { 73704c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 738dea3101eS uint8_t *sparam; 739dea3101eS struct lpfc_dmabuf *mp; 740dea3101eS 741dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 742dea3101eS 743dea3101eS mb->un.varRegLogin.rpi = 0; 7446d368e53SJames Smart if (phba->sli_rev == LPFC_SLI_REV4) 7456d368e53SJames Smart mb->un.varRegLogin.rpi = phba->sli4_hba.rpi_ids[rpi]; 7466d368e53SJames Smart if (phba->sli_rev >= LPFC_SLI_REV3) 7476d368e53SJames Smart mb->un.varRegLogin.vpi = phba->vpi_ids[vpi]; 748dea3101eS mb->un.varRegLogin.did = did; 749dea3101eS mb->mbxOwner = OWN_HOST; 750dea3101eS /* Get a buffer to hold NPorts Service Parameters */ 75198c9ea5cSJames Smart mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); 75298c9ea5cSJames Smart if (mp) 75398c9ea5cSJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 75498c9ea5cSJames Smart if (!mp || !mp->virt) { 755dea3101eS kfree(mp); 756dea3101eS mb->mbxCommand = MBX_REG_LOGIN64; 757dea3101eS /* REG_LOGIN: no buffers */ 75892d7f7b0SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 759e8b62011SJames Smart "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, " 7604042629eSJames Smart "rpi x%x\n", vpi, did, rpi); 7616d368e53SJames Smart return 1; 762dea3101eS } 763dea3101eS INIT_LIST_HEAD(&mp->list); 764dea3101eS sparam = mp->virt; 765dea3101eS 766dea3101eS /* Copy param's into a new buffer */ 767dea3101eS memcpy(sparam, param, sizeof (struct serv_parm)); 768dea3101eS 769dea3101eS /* save address for completion */ 770dea3101eS pmb->context1 = (uint8_t *) mp; 771dea3101eS 772dea3101eS mb->mbxCommand = MBX_REG_LOGIN64; 773dea3101eS mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); 774dea3101eS mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys); 775dea3101eS mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys); 776dea3101eS 7776d368e53SJames Smart return 0; 778dea3101eS } 779dea3101eS 780e59058c4SJames Smart /** 7813621a710SJames Smart * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login 782e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 783e59058c4SJames Smart * @vpi: virtual N_Port identifier. 784e59058c4SJames Smart * @rpi: remote port identifier 785e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 786e59058c4SJames Smart * 787e59058c4SJames Smart * The unregistration login mailbox command is used to unregister an N_Port 788e59058c4SJames Smart * or F_Port login. This command frees an RPI context in the HBA. It has the 789e59058c4SJames Smart * effect of performing an implicit N_Port/F_Port logout. 790e59058c4SJames Smart * 791e59058c4SJames Smart * This routine prepares the mailbox command for unregistering remote port 792e59058c4SJames Smart * login. 7936d368e53SJames Smart * 7946d368e53SJames Smart * For SLI4 ports, the rpi passed to this function must be the physical 7956d368e53SJames Smart * rpi value, not the logical index. 796e59058c4SJames Smart **/ 797dea3101eS void 79892d7f7b0SJames Smart lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi, 79992d7f7b0SJames Smart LPFC_MBOXQ_t * pmb) 800dea3101eS { 801dea3101eS MAILBOX_t *mb; 802dea3101eS 80304c68496SJames Smart mb = &pmb->u.mb; 804dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 805dea3101eS 8066d368e53SJames Smart mb->un.varUnregLogin.rpi = rpi; 807dea3101eS mb->un.varUnregLogin.rsvd1 = 0; 8086d368e53SJames Smart if (phba->sli_rev >= LPFC_SLI_REV3) 8096d368e53SJames Smart mb->un.varUnregLogin.vpi = phba->vpi_ids[vpi]; 810dea3101eS 811dea3101eS mb->mbxCommand = MBX_UNREG_LOGIN; 812dea3101eS mb->mbxOwner = OWN_HOST; 81304c68496SJames Smart 814dea3101eS return; 815dea3101eS } 816dea3101eS 817e59058c4SJames Smart /** 8185af5eee7SJames Smart * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA. 8195af5eee7SJames Smart * @vport: pointer to a vport object. 8205af5eee7SJames Smart * 8215af5eee7SJames Smart * This routine sends mailbox command to unregister all active RPIs for 8225af5eee7SJames Smart * a vport. 8235af5eee7SJames Smart **/ 8245af5eee7SJames Smart void 8255af5eee7SJames Smart lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport) 8265af5eee7SJames Smart { 8275af5eee7SJames Smart struct lpfc_hba *phba = vport->phba; 8285af5eee7SJames Smart LPFC_MBOXQ_t *mbox; 8295af5eee7SJames Smart int rc; 8305af5eee7SJames Smart 8315af5eee7SJames Smart mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 8325af5eee7SJames Smart if (mbox) { 8336d368e53SJames Smart /* 8346d368e53SJames Smart * For SLI4 functions, the rpi field is overloaded for 8356d368e53SJames Smart * the vport context unreg all. This routine passes 8366d368e53SJames Smart * 0 for the rpi field in lpfc_unreg_login for compatibility 8376d368e53SJames Smart * with SLI3 and then overrides the rpi field with the 8386d368e53SJames Smart * expected value for SLI4. 8396d368e53SJames Smart */ 8406d368e53SJames Smart lpfc_unreg_login(phba, vport->vpi, phba->vpi_ids[vport->vpi], 8416d368e53SJames Smart mbox); 8425af5eee7SJames Smart mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000; 8435af5eee7SJames Smart mbox->vport = vport; 8445af5eee7SJames Smart mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 8455af5eee7SJames Smart mbox->context1 = NULL; 8465af5eee7SJames Smart rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 8475af5eee7SJames Smart if (rc == MBX_NOT_FINISHED) 8485af5eee7SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 8495af5eee7SJames Smart } 8505af5eee7SJames Smart } 8515af5eee7SJames Smart 8525af5eee7SJames Smart /** 8533621a710SJames Smart * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier 854e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 855e59058c4SJames Smart * @vpi: virtual N_Port identifier. 856e59058c4SJames Smart * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port). 857e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 858e59058c4SJames Smart * 859e59058c4SJames Smart * The registration vport identifier mailbox command is used to activate a 860e59058c4SJames Smart * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the 861e59058c4SJames Smart * N_Port_ID against the information in the selected virtual N_Port context 862e59058c4SJames Smart * block and marks it active to allow normal processing of IOCB commands and 863e59058c4SJames Smart * received unsolicited exchanges. 864e59058c4SJames Smart * 865e59058c4SJames Smart * This routine prepares the mailbox command for registering a virtual N_Port. 866e59058c4SJames Smart **/ 86792d7f7b0SJames Smart void 86804c68496SJames Smart lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb) 86992d7f7b0SJames Smart { 87004c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 87138b92ef8SJames Smart struct lpfc_hba *phba = vport->phba; 87292d7f7b0SJames Smart 87392d7f7b0SJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 87438b92ef8SJames Smart /* 87538b92ef8SJames Smart * Set the re-reg VPI bit for f/w to update the MAC address. 87638b92ef8SJames Smart */ 87738b92ef8SJames Smart if ((phba->sli_rev == LPFC_SLI_REV4) && 87838b92ef8SJames Smart !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) 87938b92ef8SJames Smart mb->un.varRegVpi.upd = 1; 8806d368e53SJames Smart 8816d368e53SJames Smart mb->un.varRegVpi.vpi = phba->vpi_ids[vport->vpi]; 88204c68496SJames Smart mb->un.varRegVpi.sid = vport->fc_myDID; 8836d368e53SJames Smart if (phba->sli_rev == LPFC_SLI_REV4) 8846d368e53SJames Smart mb->un.varRegVpi.vfi = phba->sli4_hba.vfi_ids[vport->vfi]; 8856d368e53SJames Smart else 88604c68496SJames Smart mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base; 887c868595dSJames Smart memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname, 888c868595dSJames Smart sizeof(struct lpfc_name)); 889c868595dSJames Smart mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]); 890c868595dSJames Smart mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]); 89192d7f7b0SJames Smart 89292d7f7b0SJames Smart mb->mbxCommand = MBX_REG_VPI; 89392d7f7b0SJames Smart mb->mbxOwner = OWN_HOST; 89492d7f7b0SJames Smart return; 89592d7f7b0SJames Smart 89692d7f7b0SJames Smart } 89792d7f7b0SJames Smart 898e59058c4SJames Smart /** 8993621a710SJames Smart * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id 900e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 901e59058c4SJames Smart * @vpi: virtual N_Port identifier. 902e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 903e59058c4SJames Smart * 904e59058c4SJames Smart * The unregistration vport identifier mailbox command is used to inactivate 905e59058c4SJames Smart * a virtual N_Port. The driver must have logged out and unregistered all 906e59058c4SJames Smart * remote N_Ports to abort any activity on the virtual N_Port. The HBA will 907e59058c4SJames Smart * unregisters any default RPIs associated with the specified vpi, aborting 908e59058c4SJames Smart * any active exchanges. The HBA will post the mailbox response after making 909e59058c4SJames Smart * the virtual N_Port inactive. 910e59058c4SJames Smart * 911e59058c4SJames Smart * This routine prepares the mailbox command for unregistering a virtual 912e59058c4SJames Smart * N_Port. 913e59058c4SJames Smart **/ 91492d7f7b0SJames Smart void 91592d7f7b0SJames Smart lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb) 91692d7f7b0SJames Smart { 91704c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 91892d7f7b0SJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 91992d7f7b0SJames Smart 9206d368e53SJames Smart if (phba->sli_rev == LPFC_SLI_REV3) 9216d368e53SJames Smart mb->un.varUnregVpi.vpi = phba->vpi_ids[vpi]; 9226d368e53SJames Smart else if (phba->sli_rev >= LPFC_SLI_REV4) 9236d368e53SJames Smart mb->un.varUnregVpi.sli4_vpi = phba->vpi_ids[vpi]; 92492d7f7b0SJames Smart 92592d7f7b0SJames Smart mb->mbxCommand = MBX_UNREG_VPI; 92692d7f7b0SJames Smart mb->mbxOwner = OWN_HOST; 92792d7f7b0SJames Smart return; 92892d7f7b0SJames Smart 92992d7f7b0SJames Smart } 93092d7f7b0SJames Smart 931e59058c4SJames Smart /** 9323621a710SJames Smart * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB) 933e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 934e59058c4SJames Smart * 935e59058c4SJames Smart * This routine sets up and initializes the IOCB rings in the Port Control 936e59058c4SJames Smart * Block (PCB). 937e59058c4SJames Smart **/ 938dea3101eS static void 939dea3101eS lpfc_config_pcb_setup(struct lpfc_hba * phba) 940dea3101eS { 941dea3101eS struct lpfc_sli *psli = &phba->sli; 942dea3101eS struct lpfc_sli_ring *pring; 94334b02dcdSJames Smart PCB_t *pcbp = phba->pcb; 944dea3101eS dma_addr_t pdma_addr; 945dea3101eS uint32_t offset; 9462e0fef85SJames Smart uint32_t iocbCnt = 0; 947dea3101eS int i; 948dea3101eS 949dea3101eS pcbp->maxRing = (psli->num_rings - 1); 950dea3101eS 951dea3101eS for (i = 0; i < psli->num_rings; i++) { 952dea3101eS pring = &psli->ring[i]; 9532e0fef85SJames Smart 9547e56aa25SJames Smart pring->sli.sli3.sizeCiocb = 9557e56aa25SJames Smart phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE : 956ed957684SJames Smart SLI2_IOCB_CMD_SIZE; 9577e56aa25SJames Smart pring->sli.sli3.sizeRiocb = 9587e56aa25SJames Smart phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE : 959ed957684SJames Smart SLI2_IOCB_RSP_SIZE; 960dea3101eS /* A ring MUST have both cmd and rsp entries defined to be 961dea3101eS valid */ 9627e56aa25SJames Smart if ((pring->sli.sli3.numCiocb == 0) || 9637e56aa25SJames Smart (pring->sli.sli3.numRiocb == 0)) { 964dea3101eS pcbp->rdsc[i].cmdEntries = 0; 965dea3101eS pcbp->rdsc[i].rspEntries = 0; 966dea3101eS pcbp->rdsc[i].cmdAddrHigh = 0; 967dea3101eS pcbp->rdsc[i].rspAddrHigh = 0; 968dea3101eS pcbp->rdsc[i].cmdAddrLow = 0; 969dea3101eS pcbp->rdsc[i].rspAddrLow = 0; 9707e56aa25SJames Smart pring->sli.sli3.cmdringaddr = NULL; 9717e56aa25SJames Smart pring->sli.sli3.rspringaddr = NULL; 972dea3101eS continue; 973dea3101eS } 974dea3101eS /* Command ring setup for ring */ 9757e56aa25SJames Smart pring->sli.sli3.cmdringaddr = (void *)&phba->IOCBs[iocbCnt]; 9767e56aa25SJames Smart pcbp->rdsc[i].cmdEntries = pring->sli.sli3.numCiocb; 977dea3101eS 97834b02dcdSJames Smart offset = (uint8_t *) &phba->IOCBs[iocbCnt] - 97934b02dcdSJames Smart (uint8_t *) phba->slim2p.virt; 98034b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 981dea3101eS pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr); 982dea3101eS pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr); 9837e56aa25SJames Smart iocbCnt += pring->sli.sli3.numCiocb; 984dea3101eS 985dea3101eS /* Response ring setup for ring */ 9867e56aa25SJames Smart pring->sli.sli3.rspringaddr = (void *) &phba->IOCBs[iocbCnt]; 987dea3101eS 9887e56aa25SJames Smart pcbp->rdsc[i].rspEntries = pring->sli.sli3.numRiocb; 98934b02dcdSJames Smart offset = (uint8_t *)&phba->IOCBs[iocbCnt] - 99034b02dcdSJames Smart (uint8_t *)phba->slim2p.virt; 99134b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 992dea3101eS pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr); 993dea3101eS pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr); 9947e56aa25SJames Smart iocbCnt += pring->sli.sli3.numRiocb; 995dea3101eS } 996dea3101eS } 997dea3101eS 998e59058c4SJames Smart /** 9993621a710SJames Smart * lpfc_read_rev - Prepare a mailbox command for reading HBA revision 1000e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1001e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1002e59058c4SJames Smart * 1003e59058c4SJames Smart * The read revision mailbox command is used to read the revision levels of 1004e59058c4SJames Smart * the HBA components. These components include hardware units, resident 1005e59058c4SJames Smart * firmware, and available firmware. HBAs that supports SLI-3 mode of 1006e59058c4SJames Smart * operation provide different response information depending on the version 1007e59058c4SJames Smart * requested by the driver. 1008e59058c4SJames Smart * 1009e59058c4SJames Smart * This routine prepares the mailbox command for reading HBA revision 1010e59058c4SJames Smart * information. 1011e59058c4SJames Smart **/ 1012dea3101eS void 1013dea3101eS lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 1014dea3101eS { 101504c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1016dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 1017dea3101eS mb->un.varRdRev.cv = 1; 1018ed957684SJames Smart mb->un.varRdRev.v3req = 1; /* Request SLI3 info */ 1019dea3101eS mb->mbxCommand = MBX_READ_REV; 1020dea3101eS mb->mbxOwner = OWN_HOST; 1021dea3101eS return; 1022dea3101eS } 1023dea3101eS 1024d7c47992SJames Smart void 1025d7c47992SJames Smart lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 1026d7c47992SJames Smart { 1027d7c47992SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1028d7c47992SJames Smart struct lpfc_mqe *mqe; 1029d7c47992SJames Smart 1030d7c47992SJames Smart switch (mb->mbxCommand) { 1031d7c47992SJames Smart case MBX_READ_REV: 1032d7c47992SJames Smart mqe = &pmb->u.mqe; 1033d7c47992SJames Smart lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name, 1034d7c47992SJames Smart mqe->un.read_rev.fw_name, 16); 1035d7c47992SJames Smart lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name, 1036d7c47992SJames Smart mqe->un.read_rev.ulp_fw_name, 16); 1037d7c47992SJames Smart break; 1038d7c47992SJames Smart default: 1039d7c47992SJames Smart break; 1040d7c47992SJames Smart } 1041d7c47992SJames Smart return; 1042d7c47992SJames Smart } 1043d7c47992SJames Smart 1044e59058c4SJames Smart /** 10453621a710SJames Smart * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2 1046e59058c4SJames Smart * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. 1047e59058c4SJames Smart * @hbq_desc: pointer to the HBQ selection profile descriptor. 1048e59058c4SJames Smart * 1049e59058c4SJames Smart * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA 1050e59058c4SJames Smart * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs 1051e59058c4SJames Smart * the Sequence Length Test using the fields in the Selection Profile 2 1052e59058c4SJames Smart * extension in words 20:31. 1053e59058c4SJames Smart **/ 1054ed957684SJames Smart static void 1055ed957684SJames Smart lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb, 1056ed957684SJames Smart struct lpfc_hbq_init *hbq_desc) 1057ed957684SJames Smart { 1058ed957684SJames Smart hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt; 1059ed957684SJames Smart hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen; 1060ed957684SJames Smart hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff; 1061ed957684SJames Smart } 1062ed957684SJames Smart 1063e59058c4SJames Smart /** 10643621a710SJames Smart * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3 1065e59058c4SJames Smart * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. 1066e59058c4SJames Smart * @hbq_desc: pointer to the HBQ selection profile descriptor. 1067e59058c4SJames Smart * 1068e59058c4SJames Smart * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA 1069e59058c4SJames Smart * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs 1070e59058c4SJames Smart * the Sequence Length Test and Byte Field Test using the fields in the 1071e59058c4SJames Smart * Selection Profile 3 extension in words 20:31. 1072e59058c4SJames Smart **/ 1073ed957684SJames Smart static void 1074ed957684SJames Smart lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb, 1075ed957684SJames Smart struct lpfc_hbq_init *hbq_desc) 1076ed957684SJames Smart { 1077ed957684SJames Smart hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt; 1078ed957684SJames Smart hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen; 1079ed957684SJames Smart hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff; 1080ed957684SJames Smart hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff; 1081ed957684SJames Smart memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch, 1082ed957684SJames Smart sizeof(hbqmb->profiles.profile3.cmdmatch)); 1083ed957684SJames Smart } 1084ed957684SJames Smart 1085e59058c4SJames Smart /** 10863621a710SJames Smart * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5 1087e59058c4SJames Smart * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. 1088e59058c4SJames Smart * @hbq_desc: pointer to the HBQ selection profile descriptor. 1089e59058c4SJames Smart * 1090e59058c4SJames Smart * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The 1091e59058c4SJames Smart * HBA tests the initial frame of an incoming sequence using the frame's 1092e59058c4SJames Smart * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test 1093e59058c4SJames Smart * and Byte Field Test using the fields in the Selection Profile 5 extension 1094e59058c4SJames Smart * words 20:31. 1095e59058c4SJames Smart **/ 1096ed957684SJames Smart static void 1097ed957684SJames Smart lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb, 1098ed957684SJames Smart struct lpfc_hbq_init *hbq_desc) 1099ed957684SJames Smart { 1100ed957684SJames Smart hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt; 1101ed957684SJames Smart hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen; 1102ed957684SJames Smart hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff; 1103ed957684SJames Smart hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff; 1104ed957684SJames Smart memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch, 1105ed957684SJames Smart sizeof(hbqmb->profiles.profile5.cmdmatch)); 1106ed957684SJames Smart } 1107ed957684SJames Smart 1108e59058c4SJames Smart /** 11093621a710SJames Smart * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ 1110e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1111e59058c4SJames Smart * @id: HBQ identifier. 1112e59058c4SJames Smart * @hbq_desc: pointer to the HBA descriptor data structure. 1113e59058c4SJames Smart * @hbq_entry_index: index of the HBQ entry data structures. 1114e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1115e59058c4SJames Smart * 1116e59058c4SJames Smart * The configure HBQ (Host Buffer Queue) mailbox command is used to configure 1117e59058c4SJames Smart * an HBQ. The configuration binds events that require buffers to a particular 1118e59058c4SJames Smart * ring and HBQ based on a selection profile. 1119e59058c4SJames Smart * 1120e59058c4SJames Smart * This routine prepares the mailbox command for configuring an HBQ. 1121e59058c4SJames Smart **/ 1122ed957684SJames Smart void 112351ef4c26SJames Smart lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id, 112451ef4c26SJames Smart struct lpfc_hbq_init *hbq_desc, 1125ed957684SJames Smart uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb) 1126ed957684SJames Smart { 1127ed957684SJames Smart int i; 112804c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1129ed957684SJames Smart struct config_hbq_var *hbqmb = &mb->un.varCfgHbq; 1130ed957684SJames Smart 1131ed957684SJames Smart memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 113251ef4c26SJames Smart hbqmb->hbqId = id; 1133ed957684SJames Smart hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */ 1134ed957684SJames Smart hbqmb->recvNotify = hbq_desc->rn; /* Receive 1135ed957684SJames Smart * Notification */ 1136ed957684SJames Smart hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks 1137ed957684SJames Smart * # in words 0-19 */ 1138ed957684SJames Smart hbqmb->profile = hbq_desc->profile; /* Selection profile: 1139ed957684SJames Smart * 0 = all, 1140ed957684SJames Smart * 7 = logentry */ 1141ed957684SJames Smart hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring 1142ed957684SJames Smart * e.g. Ring0=b0001, 1143ed957684SJames Smart * ring2=b0100 */ 1144ed957684SJames Smart hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4 1145ed957684SJames Smart * or 5 */ 1146ed957684SJames Smart hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this 1147ed957684SJames Smart * HBQ will be used 1148ed957684SJames Smart * for LogEntry 1149ed957684SJames Smart * buffers */ 1150ed957684SJames Smart hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) + 1151ed957684SJames Smart hbq_entry_index * sizeof(struct lpfc_hbq_entry); 1152ed957684SJames Smart hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys); 1153ed957684SJames Smart 1154ed957684SJames Smart mb->mbxCommand = MBX_CONFIG_HBQ; 1155ed957684SJames Smart mb->mbxOwner = OWN_HOST; 1156ed957684SJames Smart 1157ed957684SJames Smart /* Copy info for profiles 2,3,5. Other 1158ed957684SJames Smart * profiles this area is reserved 1159ed957684SJames Smart */ 1160ed957684SJames Smart if (hbq_desc->profile == 2) 1161ed957684SJames Smart lpfc_build_hbq_profile2(hbqmb, hbq_desc); 1162ed957684SJames Smart else if (hbq_desc->profile == 3) 1163ed957684SJames Smart lpfc_build_hbq_profile3(hbqmb, hbq_desc); 1164ed957684SJames Smart else if (hbq_desc->profile == 5) 1165ed957684SJames Smart lpfc_build_hbq_profile5(hbqmb, hbq_desc); 1166ed957684SJames Smart 1167ed957684SJames Smart /* Return if no rctl / type masks for this HBQ */ 1168ed957684SJames Smart if (!hbq_desc->mask_count) 1169ed957684SJames Smart return; 1170ed957684SJames Smart 1171ed957684SJames Smart /* Otherwise we setup specific rctl / type masks for this HBQ */ 1172ed957684SJames Smart for (i = 0; i < hbq_desc->mask_count; i++) { 1173ed957684SJames Smart hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch; 1174ed957684SJames Smart hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask; 1175ed957684SJames Smart hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch; 1176ed957684SJames Smart hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask; 1177ed957684SJames Smart } 1178ed957684SJames Smart 1179ed957684SJames Smart return; 1180ed957684SJames Smart } 1181ed957684SJames Smart 1182e59058c4SJames Smart /** 11833621a710SJames Smart * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring 1184e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1185e59058c4SJames Smart * @ring: 1186e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1187e59058c4SJames Smart * 1188e59058c4SJames Smart * The configure ring mailbox command is used to configure an IOCB ring. This 1189e59058c4SJames Smart * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the 1190e59058c4SJames Smart * ring. This is used to map incoming sequences to a particular ring whose 1191e59058c4SJames Smart * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not 1192e59058c4SJames Smart * attempt to configure a ring whose number is greater than the number 1193e59058c4SJames Smart * specified in the Port Control Block (PCB). It is an error to issue the 1194e59058c4SJames Smart * configure ring command more than once with the same ring number. The HBA 1195e59058c4SJames Smart * returns an error if the driver attempts this. 1196e59058c4SJames Smart * 1197e59058c4SJames Smart * This routine prepares the mailbox command for configuring IOCB ring. 1198e59058c4SJames Smart **/ 1199dea3101eS void 1200dea3101eS lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb) 1201dea3101eS { 1202dea3101eS int i; 120304c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1204dea3101eS struct lpfc_sli *psli; 1205dea3101eS struct lpfc_sli_ring *pring; 1206dea3101eS 1207dea3101eS memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 1208dea3101eS 1209dea3101eS mb->un.varCfgRing.ring = ring; 1210dea3101eS mb->un.varCfgRing.maxOrigXchg = 0; 1211dea3101eS mb->un.varCfgRing.maxRespXchg = 0; 1212dea3101eS mb->un.varCfgRing.recvNotify = 1; 1213dea3101eS 1214dea3101eS psli = &phba->sli; 1215dea3101eS pring = &psli->ring[ring]; 1216dea3101eS mb->un.varCfgRing.numMask = pring->num_mask; 1217dea3101eS mb->mbxCommand = MBX_CONFIG_RING; 1218dea3101eS mb->mbxOwner = OWN_HOST; 1219dea3101eS 1220dea3101eS /* Is this ring configured for a specific profile */ 1221dea3101eS if (pring->prt[0].profile) { 1222dea3101eS mb->un.varCfgRing.profile = pring->prt[0].profile; 1223dea3101eS return; 1224dea3101eS } 1225dea3101eS 1226dea3101eS /* Otherwise we setup specific rctl / type masks for this ring */ 1227dea3101eS for (i = 0; i < pring->num_mask; i++) { 1228dea3101eS mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl; 12296a9c52cfSJames Smart if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ) 1230dea3101eS mb->un.varCfgRing.rrRegs[i].rmask = 0xff; 1231dea3101eS else 1232dea3101eS mb->un.varCfgRing.rrRegs[i].rmask = 0xfe; 1233dea3101eS mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type; 1234dea3101eS mb->un.varCfgRing.rrRegs[i].tmask = 0xff; 1235dea3101eS } 1236dea3101eS 1237dea3101eS return; 1238dea3101eS } 1239dea3101eS 1240e59058c4SJames Smart /** 12413621a710SJames Smart * lpfc_config_port - Prepare a mailbox command for configuring port 1242e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1243e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1244e59058c4SJames Smart * 1245e59058c4SJames Smart * The configure port mailbox command is used to identify the Port Control 1246e59058c4SJames Smart * Block (PCB) in the driver memory. After this command is issued, the 1247e59058c4SJames Smart * driver must not access the mailbox in the HBA without first resetting 1248e59058c4SJames Smart * the HBA. The HBA may copy the PCB information to internal storage for 1249e59058c4SJames Smart * subsequent use; the driver can not change the PCB information unless it 1250e59058c4SJames Smart * resets the HBA. 1251e59058c4SJames Smart * 1252e59058c4SJames Smart * This routine prepares the mailbox command for configuring port. 1253e59058c4SJames Smart **/ 1254dea3101eS void 1255dea3101eS lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 1256dea3101eS { 1257ed957684SJames Smart MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr; 125804c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 1259dea3101eS dma_addr_t pdma_addr; 1260dea3101eS uint32_t bar_low, bar_high; 1261dea3101eS size_t offset; 12624cc2da1dSJames.Smart@Emulex.Com struct lpfc_hgp hgp; 1263f91b392cSJames.Smart@Emulex.Com int i; 1264ed957684SJames Smart uint32_t pgp_offset; 1265dea3101eS 1266dea3101eS memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 1267dea3101eS mb->mbxCommand = MBX_CONFIG_PORT; 1268dea3101eS mb->mbxOwner = OWN_HOST; 1269dea3101eS 1270dea3101eS mb->un.varCfgPort.pcbLen = sizeof(PCB_t); 1271dea3101eS 127234b02dcdSJames Smart offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt; 127334b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 1274dea3101eS mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr); 1275dea3101eS mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr); 1276dea3101eS 127797207482SJames Smart /* Always Host Group Pointer is in SLIM */ 127897207482SJames Smart mb->un.varCfgPort.hps = 1; 127997207482SJames Smart 1280ed957684SJames Smart /* If HBA supports SLI=3 ask for it */ 1281ed957684SJames Smart 128204c68496SJames Smart if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) { 1283e2a0a9d6SJames Smart if (phba->cfg_enable_bg) 1284e2a0a9d6SJames Smart mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */ 1285ab56dc2eSJames Smart if (phba->cfg_enable_dss) 128604c68496SJames Smart mb->un.varCfgPort.cdss = 1; /* Configure Security */ 1287ed957684SJames Smart mb->un.varCfgPort.cerbm = 1; /* Request HBQs */ 128834b02dcdSJames Smart mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */ 128951ef4c26SJames Smart mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count(); 129078b2d852SJames Smart if (phba->max_vpi && phba->cfg_enable_npiv && 129192d7f7b0SJames Smart phba->vpd.sli3Feat.cmv) { 129204c68496SJames Smart mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI; 129392d7f7b0SJames Smart mb->un.varCfgPort.cmv = 1; 129492d7f7b0SJames Smart } else 129592d7f7b0SJames Smart mb->un.varCfgPort.max_vpi = phba->max_vpi = 0; 129692d7f7b0SJames Smart } else 129704c68496SJames Smart phba->sli_rev = LPFC_SLI_REV2; 129892d7f7b0SJames Smart mb->un.varCfgPort.sli_mode = phba->sli_rev; 1299ed957684SJames Smart 1300cb69f7deSJames Smart /* If this is an SLI3 port, configure async status notification. */ 1301cb69f7deSJames Smart if (phba->sli_rev == LPFC_SLI_REV3) 1302cb69f7deSJames Smart mb->un.varCfgPort.casabt = 1; 1303cb69f7deSJames Smart 1304dea3101eS /* Now setup pcb */ 130534b02dcdSJames Smart phba->pcb->type = TYPE_NATIVE_SLI2; 130634b02dcdSJames Smart phba->pcb->feature = FEATURE_INITIAL_SLI2; 1307dea3101eS 1308dea3101eS /* Setup Mailbox pointers */ 13097a470277SJames Smart phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE; 131034b02dcdSJames Smart offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt; 131134b02dcdSJames Smart pdma_addr = phba->slim2p.phys + offset; 131234b02dcdSJames Smart phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr); 131334b02dcdSJames Smart phba->pcb->mbAddrLow = putPaddrLow(pdma_addr); 1314dea3101eS 1315dea3101eS /* 1316dea3101eS * Setup Host Group ring pointer. 1317dea3101eS * 1318dea3101eS * For efficiency reasons, the ring get/put pointers can be 1319dea3101eS * placed in adapter memory (SLIM) rather than in host memory. 1320dea3101eS * This allows firmware to avoid PCI reads/writes when updating 1321dea3101eS * and checking pointers. 1322dea3101eS * 1323dea3101eS * The firmware recognizes the use of SLIM memory by comparing 1324dea3101eS * the address of the get/put pointers structure with that of 1325dea3101eS * the SLIM BAR (BAR0). 1326dea3101eS * 1327dea3101eS * Caution: be sure to use the PCI config space value of BAR0/BAR1 1328dea3101eS * (the hardware's view of the base address), not the OS's 1329dea3101eS * value of pci_resource_start() as the OS value may be a cookie 1330dea3101eS * for ioremap/iomap. 1331dea3101eS */ 1332dea3101eS 1333dea3101eS 1334dea3101eS pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low); 1335dea3101eS pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high); 1336dea3101eS 1337ed957684SJames Smart /* 1338ed957684SJames Smart * Set up HGP - Port Memory 1339ed957684SJames Smart * 1340ed957684SJames Smart * The port expects the host get/put pointers to reside in memory 1341ed957684SJames Smart * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes) 1342ed957684SJames Smart * area of SLIM. In SLI-2 mode, there's an additional 16 reserved 1343ed957684SJames Smart * words (0x40 bytes). This area is not reserved if HBQs are 1344ed957684SJames Smart * configured in SLI-3. 1345ed957684SJames Smart * 1346ed957684SJames Smart * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80 1347ed957684SJames Smart * RR0Get 0xc4 0x84 1348ed957684SJames Smart * CR1Put 0xc8 0x88 1349ed957684SJames Smart * RR1Get 0xcc 0x8c 1350ed957684SJames Smart * CR2Put 0xd0 0x90 1351ed957684SJames Smart * RR2Get 0xd4 0x94 1352ed957684SJames Smart * CR3Put 0xd8 0x98 1353ed957684SJames Smart * RR3Get 0xdc 0x9c 1354ed957684SJames Smart * 1355ed957684SJames Smart * Reserved 0xa0-0xbf 1356ed957684SJames Smart * If HBQs configured: 1357ed957684SJames Smart * HBQ 0 Put ptr 0xc0 1358ed957684SJames Smart * HBQ 1 Put ptr 0xc4 1359ed957684SJames Smart * HBQ 2 Put ptr 0xc8 1360ed957684SJames Smart * ...... 1361ed957684SJames Smart * HBQ(M-1)Put Pointer 0xc0+(M-1)*4 1362ed957684SJames Smart * 1363ed957684SJames Smart */ 1364ed957684SJames Smart 13657a470277SJames Smart if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) { 13667a470277SJames Smart phba->host_gp = &phba->mbox->us.s2.host[0]; 13677a470277SJames Smart phba->hbq_put = NULL; 13687a470277SJames Smart offset = (uint8_t *)&phba->mbox->us.s2.host - 13697a470277SJames Smart (uint8_t *)phba->slim2p.virt; 13707a470277SJames Smart pdma_addr = phba->slim2p.phys + offset; 13717a470277SJames Smart phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr); 13727a470277SJames Smart phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr); 13737a470277SJames Smart } else { 13747a470277SJames Smart /* Always Host Group Pointer is in SLIM */ 13757a470277SJames Smart mb->un.varCfgPort.hps = 1; 13767a470277SJames Smart 1377ed957684SJames Smart if (phba->sli_rev == 3) { 1378ed957684SJames Smart phba->host_gp = &mb_slim->us.s3.host[0]; 1379ed957684SJames Smart phba->hbq_put = &mb_slim->us.s3.hbq_put[0]; 1380ed957684SJames Smart } else { 1381ed957684SJames Smart phba->host_gp = &mb_slim->us.s2.host[0]; 1382ed957684SJames Smart phba->hbq_put = NULL; 1383ed957684SJames Smart } 1384dea3101eS 1385dea3101eS /* mask off BAR0's flag bits 0 - 3 */ 138634b02dcdSJames Smart phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) + 1387ed957684SJames Smart (void __iomem *)phba->host_gp - 1388ed957684SJames Smart (void __iomem *)phba->MBslimaddr; 1389dea3101eS if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64) 139034b02dcdSJames Smart phba->pcb->hgpAddrHigh = bar_high; 1391dea3101eS else 139234b02dcdSJames Smart phba->pcb->hgpAddrHigh = 0; 1393dea3101eS /* write HGP data to SLIM at the required longword offset */ 13944cc2da1dSJames.Smart@Emulex.Com memset(&hgp, 0, sizeof(struct lpfc_hgp)); 1395f91b392cSJames.Smart@Emulex.Com 1396f91b392cSJames.Smart@Emulex.Com for (i = 0; i < phba->sli.num_rings; i++) { 1397ed957684SJames Smart lpfc_memcpy_to_slim(phba->host_gp + i, &hgp, 1398ed957684SJames Smart sizeof(*phba->host_gp)); 1399f91b392cSJames.Smart@Emulex.Com } 14007a470277SJames Smart } 1401dea3101eS 14028f34f4ceSJames Smart /* Setup Port Group offset */ 14038f34f4ceSJames Smart if (phba->sli_rev == 3) 140434b02dcdSJames Smart pgp_offset = offsetof(struct lpfc_sli2_slim, 140534b02dcdSJames Smart mbx.us.s3_pgp.port); 14068f34f4ceSJames Smart else 140734b02dcdSJames Smart pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port); 140834b02dcdSJames Smart pdma_addr = phba->slim2p.phys + pgp_offset; 140934b02dcdSJames Smart phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr); 141034b02dcdSJames Smart phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr); 1411dea3101eS 1412dea3101eS /* Use callback routine to setp rings in the pcb */ 1413dea3101eS lpfc_config_pcb_setup(phba); 1414dea3101eS 1415dea3101eS /* special handling for LC HBAs */ 1416dea3101eS if (lpfc_is_LC_HBA(phba->pcidev->device)) { 1417dea3101eS uint32_t hbainit[5]; 1418dea3101eS 1419dea3101eS lpfc_hba_init(phba, hbainit); 1420dea3101eS 1421dea3101eS memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20); 1422dea3101eS } 1423dea3101eS 1424dea3101eS /* Swap PCB if needed */ 142534b02dcdSJames Smart lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t)); 1426dea3101eS } 1427dea3101eS 1428e59058c4SJames Smart /** 14293621a710SJames Smart * lpfc_kill_board - Prepare a mailbox command for killing board 1430e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1431e59058c4SJames Smart * @pmb: pointer to the driver internal queue element for mailbox command. 1432e59058c4SJames Smart * 1433e59058c4SJames Smart * The kill board mailbox command is used to tell firmware to perform a 1434e59058c4SJames Smart * graceful shutdown of a channel on a specified board to prepare for reset. 1435e59058c4SJames Smart * When the kill board mailbox command is received, the ER3 bit is set to 1 1436e59058c4SJames Smart * in the Host Status register and the ER Attention bit is set to 1 in the 1437e59058c4SJames Smart * Host Attention register of the HBA function that received the kill board 1438e59058c4SJames Smart * command. 1439e59058c4SJames Smart * 1440e59058c4SJames Smart * This routine prepares the mailbox command for killing the board in 1441e59058c4SJames Smart * preparation for a graceful shutdown. 1442e59058c4SJames Smart **/ 1443dea3101eS void 144441415862SJamie Wellnitz lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 144541415862SJamie Wellnitz { 144604c68496SJames Smart MAILBOX_t *mb = &pmb->u.mb; 144741415862SJamie Wellnitz 144841415862SJamie Wellnitz memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 144941415862SJamie Wellnitz mb->mbxCommand = MBX_KILL_BOARD; 145041415862SJamie Wellnitz mb->mbxOwner = OWN_HOST; 145141415862SJamie Wellnitz return; 145241415862SJamie Wellnitz } 145341415862SJamie Wellnitz 1454e59058c4SJames Smart /** 14553621a710SJames Smart * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue 1456e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1457e59058c4SJames Smart * @mbq: pointer to the driver internal queue element for mailbox command. 1458e59058c4SJames Smart * 1459e59058c4SJames Smart * Driver maintains a internal mailbox command queue implemented as a linked 1460e59058c4SJames Smart * list. When a mailbox command is issued, it shall be put into the mailbox 1461e59058c4SJames Smart * command queue such that they shall be processed orderly as HBA can process 1462e59058c4SJames Smart * one mailbox command at a time. 1463e59058c4SJames Smart **/ 146441415862SJamie Wellnitz void 1465dea3101eS lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) 1466dea3101eS { 1467dea3101eS struct lpfc_sli *psli; 1468dea3101eS 1469dea3101eS psli = &phba->sli; 1470dea3101eS 1471dea3101eS list_add_tail(&mbq->list, &psli->mboxq); 1472dea3101eS 1473dea3101eS psli->mboxq_cnt++; 1474dea3101eS 1475dea3101eS return; 1476dea3101eS } 1477dea3101eS 1478e59058c4SJames Smart /** 14793621a710SJames Smart * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue 1480e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1481e59058c4SJames Smart * 1482e59058c4SJames Smart * Driver maintains a internal mailbox command queue implemented as a linked 1483e59058c4SJames Smart * list. When a mailbox command is issued, it shall be put into the mailbox 1484e59058c4SJames Smart * command queue such that they shall be processed orderly as HBA can process 1485e59058c4SJames Smart * one mailbox command at a time. After HBA finished processing a mailbox 1486e59058c4SJames Smart * command, the driver will remove a pending mailbox command from the head of 1487e59058c4SJames Smart * the mailbox command queue and send to the HBA for processing. 1488e59058c4SJames Smart * 1489e59058c4SJames Smart * Return codes 1490e59058c4SJames Smart * pointer to the driver internal queue element for mailbox command. 1491e59058c4SJames Smart **/ 1492dea3101eS LPFC_MBOXQ_t * 1493dea3101eS lpfc_mbox_get(struct lpfc_hba * phba) 1494dea3101eS { 1495dea3101eS LPFC_MBOXQ_t *mbq = NULL; 1496dea3101eS struct lpfc_sli *psli = &phba->sli; 1497dea3101eS 14982e0fef85SJames Smart list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list); 149992d7f7b0SJames Smart if (mbq) 1500dea3101eS psli->mboxq_cnt--; 1501dea3101eS 1502dea3101eS return mbq; 1503dea3101eS } 1504a309a6b6SJames Smart 1505e59058c4SJames Smart /** 150604c68496SJames Smart * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list 150704c68496SJames Smart * @phba: pointer to lpfc hba data structure. 150804c68496SJames Smart * @mbq: pointer to the driver internal queue element for mailbox command. 150904c68496SJames Smart * 151004c68496SJames Smart * This routine put the completed mailbox command into the mailbox command 151104c68496SJames Smart * complete list. This is the unlocked version of the routine. The mailbox 151204c68496SJames Smart * complete list is used by the driver worker thread to process mailbox 151304c68496SJames Smart * complete callback functions outside the driver interrupt handler. 151404c68496SJames Smart **/ 151504c68496SJames Smart void 151604c68496SJames Smart __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) 151704c68496SJames Smart { 151804c68496SJames Smart list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl); 151904c68496SJames Smart } 152004c68496SJames Smart 152104c68496SJames Smart /** 15223621a710SJames Smart * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list 1523e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1524e59058c4SJames Smart * @mbq: pointer to the driver internal queue element for mailbox command. 1525e59058c4SJames Smart * 1526e59058c4SJames Smart * This routine put the completed mailbox command into the mailbox command 152704c68496SJames Smart * complete list. This is the locked version of the routine. The mailbox 152804c68496SJames Smart * complete list is used by the driver worker thread to process mailbox 152904c68496SJames Smart * complete callback functions outside the driver interrupt handler. 1530e59058c4SJames Smart **/ 153192d7f7b0SJames Smart void 153292d7f7b0SJames Smart lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) 153392d7f7b0SJames Smart { 15345b75da2fSJames Smart unsigned long iflag; 15355b75da2fSJames Smart 1536b1c11812SJoe Perches /* This function expects to be called from interrupt context */ 15375b75da2fSJames Smart spin_lock_irqsave(&phba->hbalock, iflag); 153804c68496SJames Smart __lpfc_mbox_cmpl_put(phba, mbq); 15395b75da2fSJames Smart spin_unlock_irqrestore(&phba->hbalock, iflag); 154092d7f7b0SJames Smart return; 154192d7f7b0SJames Smart } 154292d7f7b0SJames Smart 1543e59058c4SJames Smart /** 154404c68496SJames Smart * lpfc_mbox_cmd_check - Check the validality of a mailbox command 154504c68496SJames Smart * @phba: pointer to lpfc hba data structure. 154604c68496SJames Smart * @mboxq: pointer to the driver internal queue element for mailbox command. 154704c68496SJames Smart * 154804c68496SJames Smart * This routine is to check whether a mailbox command is valid to be issued. 154904c68496SJames Smart * This check will be performed by both the mailbox issue API when a client 155004c68496SJames Smart * is to issue a mailbox command to the mailbox transport. 155104c68496SJames Smart * 155204c68496SJames Smart * Return 0 - pass the check, -ENODEV - fail the check 155304c68496SJames Smart **/ 155404c68496SJames Smart int 155504c68496SJames Smart lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) 155604c68496SJames Smart { 155704c68496SJames Smart /* Mailbox command that have a completion handler must also have a 155804c68496SJames Smart * vport specified. 155904c68496SJames Smart */ 156004c68496SJames Smart if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl && 156104c68496SJames Smart mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) { 156204c68496SJames Smart if (!mboxq->vport) { 156304c68496SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT, 156404c68496SJames Smart "1814 Mbox x%x failed, no vport\n", 156504c68496SJames Smart mboxq->u.mb.mbxCommand); 156604c68496SJames Smart dump_stack(); 156704c68496SJames Smart return -ENODEV; 156804c68496SJames Smart } 156904c68496SJames Smart } 157004c68496SJames Smart return 0; 157104c68496SJames Smart } 157204c68496SJames Smart 157304c68496SJames Smart /** 157404c68496SJames Smart * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command 157504c68496SJames Smart * @phba: pointer to lpfc hba data structure. 157604c68496SJames Smart * 157704c68496SJames Smart * This routine is to check whether the HBA device is ready for posting a 157804c68496SJames Smart * mailbox command. It is used by the mailbox transport API at the time the 157904c68496SJames Smart * to post a mailbox command to the device. 158004c68496SJames Smart * 158104c68496SJames Smart * Return 0 - pass the check, -ENODEV - fail the check 158204c68496SJames Smart **/ 158304c68496SJames Smart int 158404c68496SJames Smart lpfc_mbox_dev_check(struct lpfc_hba *phba) 158504c68496SJames Smart { 158604c68496SJames Smart /* If the PCI channel is in offline state, do not issue mbox */ 158704c68496SJames Smart if (unlikely(pci_channel_offline(phba->pcidev))) 158804c68496SJames Smart return -ENODEV; 158904c68496SJames Smart 159004c68496SJames Smart /* If the HBA is in error state, do not issue mbox */ 159104c68496SJames Smart if (phba->link_state == LPFC_HBA_ERROR) 159204c68496SJames Smart return -ENODEV; 159304c68496SJames Smart 159404c68496SJames Smart return 0; 159504c68496SJames Smart } 159604c68496SJames Smart 159704c68496SJames Smart /** 15983621a710SJames Smart * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value 1599e59058c4SJames Smart * @phba: pointer to lpfc hba data structure. 1600e59058c4SJames Smart * @cmd: mailbox command code. 1601e59058c4SJames Smart * 1602e59058c4SJames Smart * This routine retrieves the proper timeout value according to the mailbox 1603e59058c4SJames Smart * command code. 1604e59058c4SJames Smart * 1605e59058c4SJames Smart * Return codes 1606e59058c4SJames Smart * Timeout value to be used for the given mailbox command 1607e59058c4SJames Smart **/ 1608a309a6b6SJames Smart int 1609a183a15fSJames Smart lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) 1610a309a6b6SJames Smart { 1611a183a15fSJames Smart MAILBOX_t *mbox = &mboxq->u.mb; 1612a183a15fSJames Smart uint8_t subsys, opcode; 1613a183a15fSJames Smart 1614a183a15fSJames Smart switch (mbox->mbxCommand) { 1615a309a6b6SJames Smart case MBX_WRITE_NV: /* 0x03 */ 1616940eb687SJames Smart case MBX_DUMP_MEMORY: /* 0x17 */ 1617a309a6b6SJames Smart case MBX_UPDATE_CFG: /* 0x1B */ 1618a309a6b6SJames Smart case MBX_DOWN_LOAD: /* 0x1C */ 1619a309a6b6SJames Smart case MBX_DEL_LD_ENTRY: /* 0x1D */ 1620940eb687SJames Smart case MBX_WRITE_VPARMS: /* 0x32 */ 1621a309a6b6SJames Smart case MBX_LOAD_AREA: /* 0x81 */ 162209372820SJames Smart case MBX_WRITE_WWN: /* 0x98 */ 1623a309a6b6SJames Smart case MBX_LOAD_EXP_ROM: /* 0x9C */ 1624940eb687SJames Smart case MBX_ACCESS_VDATA: /* 0xA5 */ 1625a309a6b6SJames Smart return LPFC_MBOX_TMO_FLASH_CMD; 162604c68496SJames Smart case MBX_SLI4_CONFIG: /* 0x9b */ 1627a183a15fSJames Smart subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq); 1628a183a15fSJames Smart opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq); 1629a183a15fSJames Smart if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) { 1630a183a15fSJames Smart switch (opcode) { 1631a183a15fSJames Smart case LPFC_MBOX_OPCODE_READ_OBJECT: 1632a183a15fSJames Smart case LPFC_MBOX_OPCODE_WRITE_OBJECT: 1633a183a15fSJames Smart case LPFC_MBOX_OPCODE_READ_OBJECT_LIST: 1634a183a15fSJames Smart case LPFC_MBOX_OPCODE_DELETE_OBJECT: 1635a183a15fSJames Smart case LPFC_MBOX_OPCODE_GET_PROFILE_LIST: 1636a183a15fSJames Smart case LPFC_MBOX_OPCODE_SET_ACT_PROFILE: 1637940eb687SJames Smart case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG: 1638a183a15fSJames Smart case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG: 1639a183a15fSJames Smart case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG: 1640940eb687SJames Smart case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES: 1641940eb687SJames Smart case LPFC_MBOX_OPCODE_SEND_ACTIVATION: 1642940eb687SJames Smart case LPFC_MBOX_OPCODE_RESET_LICENSES: 1643940eb687SJames Smart case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG: 1644940eb687SJames Smart case LPFC_MBOX_OPCODE_GET_VPD_DATA: 1645940eb687SJames Smart case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG: 1646a183a15fSJames Smart return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO; 1647a183a15fSJames Smart } 1648a183a15fSJames Smart } 1649a183a15fSJames Smart if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) { 1650a183a15fSJames Smart switch (opcode) { 1651a183a15fSJames Smart case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS: 1652a183a15fSJames Smart return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO; 1653a183a15fSJames Smart } 1654a183a15fSJames Smart } 165504c68496SJames Smart return LPFC_MBOX_SLI4_CONFIG_TMO; 1656a309a6b6SJames Smart } 1657a309a6b6SJames Smart return LPFC_MBOX_TMO; 1658a309a6b6SJames Smart } 165904c68496SJames Smart 166004c68496SJames Smart /** 166104c68496SJames Smart * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command 166204c68496SJames Smart * @mbox: pointer to lpfc mbox command. 166304c68496SJames Smart * @sgentry: sge entry index. 166404c68496SJames Smart * @phyaddr: physical address for the sge 166504c68496SJames Smart * @length: Length of the sge. 166604c68496SJames Smart * 166704c68496SJames Smart * This routine sets up an entry in the non-embedded mailbox command at the sge 166804c68496SJames Smart * index location. 166904c68496SJames Smart **/ 167004c68496SJames Smart void 167104c68496SJames Smart lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry, 167204c68496SJames Smart dma_addr_t phyaddr, uint32_t length) 167304c68496SJames Smart { 167404c68496SJames Smart struct lpfc_mbx_nembed_cmd *nembed_sge; 167504c68496SJames Smart 167604c68496SJames Smart nembed_sge = (struct lpfc_mbx_nembed_cmd *) 167704c68496SJames Smart &mbox->u.mqe.un.nembed_cmd; 167804c68496SJames Smart nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr); 167904c68496SJames Smart nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr); 168004c68496SJames Smart nembed_sge->sge[sgentry].length = length; 168104c68496SJames Smart } 168204c68496SJames Smart 168304c68496SJames Smart /** 168404c68496SJames Smart * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command 168504c68496SJames Smart * @mbox: pointer to lpfc mbox command. 168604c68496SJames Smart * @sgentry: sge entry index. 168704c68496SJames Smart * 168804c68496SJames Smart * This routine gets an entry from the non-embedded mailbox command at the sge 168904c68496SJames Smart * index location. 169004c68496SJames Smart **/ 169104c68496SJames Smart void 169204c68496SJames Smart lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry, 169304c68496SJames Smart struct lpfc_mbx_sge *sge) 169404c68496SJames Smart { 169504c68496SJames Smart struct lpfc_mbx_nembed_cmd *nembed_sge; 169604c68496SJames Smart 169704c68496SJames Smart nembed_sge = (struct lpfc_mbx_nembed_cmd *) 169804c68496SJames Smart &mbox->u.mqe.un.nembed_cmd; 169904c68496SJames Smart sge->pa_lo = nembed_sge->sge[sgentry].pa_lo; 170004c68496SJames Smart sge->pa_hi = nembed_sge->sge[sgentry].pa_hi; 170104c68496SJames Smart sge->length = nembed_sge->sge[sgentry].length; 170204c68496SJames Smart } 170304c68496SJames Smart 170404c68496SJames Smart /** 170504c68496SJames Smart * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command 170604c68496SJames Smart * @phba: pointer to lpfc hba data structure. 170704c68496SJames Smart * @mbox: pointer to lpfc mbox command. 170804c68496SJames Smart * 170904c68496SJames Smart * This routine frees SLI4 specific mailbox command for sending IOCTL command. 171004c68496SJames Smart **/ 171104c68496SJames Smart void 171204c68496SJames Smart lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox) 171304c68496SJames Smart { 171404c68496SJames Smart struct lpfc_mbx_sli4_config *sli4_cfg; 171504c68496SJames Smart struct lpfc_mbx_sge sge; 171604c68496SJames Smart dma_addr_t phyaddr; 171704c68496SJames Smart uint32_t sgecount, sgentry; 171804c68496SJames Smart 171904c68496SJames Smart sli4_cfg = &mbox->u.mqe.un.sli4_config; 172004c68496SJames Smart 172104c68496SJames Smart /* For embedded mbox command, just free the mbox command */ 172204c68496SJames Smart if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { 172304c68496SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 172404c68496SJames Smart return; 172504c68496SJames Smart } 172604c68496SJames Smart 172704c68496SJames Smart /* For non-embedded mbox command, we need to free the pages first */ 172804c68496SJames Smart sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr); 172904c68496SJames Smart /* There is nothing we can do if there is no sge address array */ 173004c68496SJames Smart if (unlikely(!mbox->sge_array)) { 173104c68496SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 173204c68496SJames Smart return; 173304c68496SJames Smart } 173404c68496SJames Smart /* Each non-embedded DMA memory was allocated in the length of a page */ 173504c68496SJames Smart for (sgentry = 0; sgentry < sgecount; sgentry++) { 173604c68496SJames Smart lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge); 173704c68496SJames Smart phyaddr = getPaddr(sge.pa_hi, sge.pa_lo); 173849198b37SJames Smart dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, 173904c68496SJames Smart mbox->sge_array->addr[sgentry], phyaddr); 174004c68496SJames Smart } 174104c68496SJames Smart /* Free the sge address array memory */ 174204c68496SJames Smart kfree(mbox->sge_array); 174304c68496SJames Smart /* Finally, free the mailbox command itself */ 174404c68496SJames Smart mempool_free(mbox, phba->mbox_mem_pool); 174504c68496SJames Smart } 174604c68496SJames Smart 174704c68496SJames Smart /** 174804c68496SJames Smart * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command 174904c68496SJames Smart * @phba: pointer to lpfc hba data structure. 175004c68496SJames Smart * @mbox: pointer to lpfc mbox command. 175104c68496SJames Smart * @subsystem: The sli4 config sub mailbox subsystem. 175204c68496SJames Smart * @opcode: The sli4 config sub mailbox command opcode. 1753fedd3b7bSJames Smart * @length: Length of the sli4 config mailbox command (including sub-header). 175404c68496SJames Smart * 175504c68496SJames Smart * This routine sets up the header fields of SLI4 specific mailbox command 175604c68496SJames Smart * for sending IOCTL command. 175704c68496SJames Smart * 175804c68496SJames Smart * Return: the actual length of the mbox command allocated (mostly useful 175904c68496SJames Smart * for none embedded mailbox command). 176004c68496SJames Smart **/ 176104c68496SJames Smart int 176204c68496SJames Smart lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox, 176304c68496SJames Smart uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb) 176404c68496SJames Smart { 176504c68496SJames Smart struct lpfc_mbx_sli4_config *sli4_config; 176604c68496SJames Smart union lpfc_sli4_cfg_shdr *cfg_shdr = NULL; 176704c68496SJames Smart uint32_t alloc_len; 176804c68496SJames Smart uint32_t resid_len; 176904c68496SJames Smart uint32_t pagen, pcount; 177004c68496SJames Smart void *viraddr; 177104c68496SJames Smart dma_addr_t phyaddr; 177204c68496SJames Smart 177304c68496SJames Smart /* Set up SLI4 mailbox command header fields */ 177404c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 177504c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG); 177604c68496SJames Smart 177704c68496SJames Smart /* Set up SLI4 ioctl command header fields */ 177804c68496SJames Smart sli4_config = &mbox->u.mqe.un.sli4_config; 177904c68496SJames Smart 178004c68496SJames Smart /* Setup for the embedded mbox command */ 178104c68496SJames Smart if (emb) { 178204c68496SJames Smart /* Set up main header fields */ 178304c68496SJames Smart bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1); 1784fedd3b7bSJames Smart sli4_config->header.cfg_mhdr.payload_length = length; 178504c68496SJames Smart /* Set up sub-header fields following main header */ 178604c68496SJames Smart bf_set(lpfc_mbox_hdr_opcode, 178704c68496SJames Smart &sli4_config->header.cfg_shdr.request, opcode); 178804c68496SJames Smart bf_set(lpfc_mbox_hdr_subsystem, 178904c68496SJames Smart &sli4_config->header.cfg_shdr.request, subsystem); 1790fedd3b7bSJames Smart sli4_config->header.cfg_shdr.request.request_length = 1791fedd3b7bSJames Smart length - LPFC_MBX_CMD_HDR_LENGTH; 179204c68496SJames Smart return length; 179304c68496SJames Smart } 179404c68496SJames Smart 17956d368e53SJames Smart /* Setup for the non-embedded mbox command */ 17969589b062SJames Smart pcount = (SLI4_PAGE_ALIGN(length))/SLI4_PAGE_SIZE; 179704c68496SJames Smart pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ? 179804c68496SJames Smart LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount; 179904c68496SJames Smart /* Allocate record for keeping SGE virtual addresses */ 18006d368e53SJames Smart mbox->sge_array = kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt), 180104c68496SJames Smart GFP_KERNEL); 18026a9c52cfSJames Smart if (!mbox->sge_array) { 18036a9c52cfSJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, 18046a9c52cfSJames Smart "2527 Failed to allocate non-embedded SGE " 18056a9c52cfSJames Smart "array.\n"); 180604c68496SJames Smart return 0; 18076a9c52cfSJames Smart } 180804c68496SJames Smart for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) { 180904c68496SJames Smart /* The DMA memory is always allocated in the length of a 181004c68496SJames Smart * page even though the last SGE might not fill up to a 181149198b37SJames Smart * page, this is used as a priori size of SLI4_PAGE_SIZE for 181204c68496SJames Smart * the later DMA memory free. 181304c68496SJames Smart */ 181449198b37SJames Smart viraddr = dma_alloc_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, 181504c68496SJames Smart &phyaddr, GFP_KERNEL); 181604c68496SJames Smart /* In case of malloc fails, proceed with whatever we have */ 181704c68496SJames Smart if (!viraddr) 181804c68496SJames Smart break; 181949198b37SJames Smart memset(viraddr, 0, SLI4_PAGE_SIZE); 182004c68496SJames Smart mbox->sge_array->addr[pagen] = viraddr; 182104c68496SJames Smart /* Keep the first page for later sub-header construction */ 182204c68496SJames Smart if (pagen == 0) 182304c68496SJames Smart cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr; 182404c68496SJames Smart resid_len = length - alloc_len; 182549198b37SJames Smart if (resid_len > SLI4_PAGE_SIZE) { 182604c68496SJames Smart lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, 182749198b37SJames Smart SLI4_PAGE_SIZE); 182849198b37SJames Smart alloc_len += SLI4_PAGE_SIZE; 182904c68496SJames Smart } else { 183004c68496SJames Smart lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, 183104c68496SJames Smart resid_len); 183204c68496SJames Smart alloc_len = length; 183304c68496SJames Smart } 183404c68496SJames Smart } 183504c68496SJames Smart 183604c68496SJames Smart /* Set up main header fields in mailbox command */ 183704c68496SJames Smart sli4_config->header.cfg_mhdr.payload_length = alloc_len; 183804c68496SJames Smart bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen); 183904c68496SJames Smart 184004c68496SJames Smart /* Set up sub-header fields into the first page */ 184104c68496SJames Smart if (pagen > 0) { 184204c68496SJames Smart bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode); 184304c68496SJames Smart bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem); 184404c68496SJames Smart cfg_shdr->request.request_length = 184504c68496SJames Smart alloc_len - sizeof(union lpfc_sli4_cfg_shdr); 184604c68496SJames Smart } 184704c68496SJames Smart /* The sub-header is in DMA memory, which needs endian converstion */ 184872100cc4SJames Smart if (cfg_shdr) 184904c68496SJames Smart lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr, 185004c68496SJames Smart sizeof(union lpfc_sli4_cfg_shdr)); 185104c68496SJames Smart return alloc_len; 185204c68496SJames Smart } 185304c68496SJames Smart 185404c68496SJames Smart /** 18556d368e53SJames Smart * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent. 18566d368e53SJames Smart * @phba: pointer to lpfc hba data structure. 18576d368e53SJames Smart * @mbox: pointer to an allocated lpfc mbox resource. 18586d368e53SJames Smart * @exts_count: the number of extents, if required, to allocate. 18596d368e53SJames Smart * @rsrc_type: the resource extent type. 18606d368e53SJames Smart * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED. 18616d368e53SJames Smart * 18626d368e53SJames Smart * This routine completes the subcommand header for SLI4 resource extent 18636d368e53SJames Smart * mailbox commands. It is called after lpfc_sli4_config. The caller must 18646d368e53SJames Smart * pass an allocated mailbox and the attributes required to initialize the 18656d368e53SJames Smart * mailbox correctly. 18666d368e53SJames Smart * 18676d368e53SJames Smart * Return: the actual length of the mbox command allocated. 18686d368e53SJames Smart **/ 18696d368e53SJames Smart int 18706d368e53SJames Smart lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox, 18716d368e53SJames Smart uint16_t exts_count, uint16_t rsrc_type, bool emb) 18726d368e53SJames Smart { 18736d368e53SJames Smart uint8_t opcode = 0; 18746d368e53SJames Smart struct lpfc_mbx_nembed_rsrc_extent *n_rsrc_extnt = NULL; 18756d368e53SJames Smart void *virtaddr = NULL; 18766d368e53SJames Smart 18776d368e53SJames Smart /* Set up SLI4 ioctl command header fields */ 18786d368e53SJames Smart if (emb == LPFC_SLI4_MBX_NEMBED) { 18796d368e53SJames Smart /* Get the first SGE entry from the non-embedded DMA memory */ 18806d368e53SJames Smart virtaddr = mbox->sge_array->addr[0]; 18816d368e53SJames Smart if (virtaddr == NULL) 18826d368e53SJames Smart return 1; 18836d368e53SJames Smart n_rsrc_extnt = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; 18846d368e53SJames Smart } 18856d368e53SJames Smart 18866d368e53SJames Smart /* 18876d368e53SJames Smart * The resource type is common to all extent Opcodes and resides in the 18886d368e53SJames Smart * same position. 18896d368e53SJames Smart */ 18906d368e53SJames Smart if (emb == LPFC_SLI4_MBX_EMBED) 18916d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_type, 18926d368e53SJames Smart &mbox->u.mqe.un.alloc_rsrc_extents.u.req, 18936d368e53SJames Smart rsrc_type); 18946d368e53SJames Smart else { 18956d368e53SJames Smart /* This is DMA data. Byteswap is required. */ 18966d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_type, 18976d368e53SJames Smart n_rsrc_extnt, rsrc_type); 18986d368e53SJames Smart lpfc_sli_pcimem_bcopy(&n_rsrc_extnt->word4, 18996d368e53SJames Smart &n_rsrc_extnt->word4, 19006d368e53SJames Smart sizeof(uint32_t)); 19016d368e53SJames Smart } 19026d368e53SJames Smart 19036d368e53SJames Smart /* Complete the initialization for the particular Opcode. */ 1904a183a15fSJames Smart opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox); 19056d368e53SJames Smart switch (opcode) { 19066d368e53SJames Smart case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT: 19076d368e53SJames Smart if (emb == LPFC_SLI4_MBX_EMBED) 19086d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_cnt, 19096d368e53SJames Smart &mbox->u.mqe.un.alloc_rsrc_extents.u.req, 19106d368e53SJames Smart exts_count); 19116d368e53SJames Smart else 19126d368e53SJames Smart bf_set(lpfc_mbx_alloc_rsrc_extents_cnt, 19136d368e53SJames Smart n_rsrc_extnt, exts_count); 19146d368e53SJames Smart break; 19156d368e53SJames Smart case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT: 19166d368e53SJames Smart case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO: 19176d368e53SJames Smart case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT: 19186d368e53SJames Smart /* Initialization is complete.*/ 19196d368e53SJames Smart break; 19206d368e53SJames Smart default: 19216d368e53SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, 19226d368e53SJames Smart "2929 Resource Extent Opcode x%x is " 19236d368e53SJames Smart "unsupported\n", opcode); 19246d368e53SJames Smart return 1; 19256d368e53SJames Smart } 19266d368e53SJames Smart 19276d368e53SJames Smart return 0; 19286d368e53SJames Smart } 19296d368e53SJames Smart 19306d368e53SJames Smart /** 1931a183a15fSJames Smart * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd 193204c68496SJames Smart * @phba: pointer to lpfc hba data structure. 1933a183a15fSJames Smart * @mbox: pointer to lpfc mbox command queue entry. 193404c68496SJames Smart * 1935a183a15fSJames Smart * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox 1936a183a15fSJames Smart * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the 1937a183a15fSJames Smart * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall 1938a183a15fSJames Smart * be returned. 193904c68496SJames Smart **/ 194004c68496SJames Smart uint8_t 1941a183a15fSJames Smart lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) 194204c68496SJames Smart { 194304c68496SJames Smart struct lpfc_mbx_sli4_config *sli4_cfg; 194404c68496SJames Smart union lpfc_sli4_cfg_shdr *cfg_shdr; 194504c68496SJames Smart 194604c68496SJames Smart if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) 1947a183a15fSJames Smart return LPFC_MBOX_SUBSYSTEM_NA; 1948a183a15fSJames Smart sli4_cfg = &mbox->u.mqe.un.sli4_config; 1949a183a15fSJames Smart 1950a183a15fSJames Smart /* For embedded mbox command, get opcode from embedded sub-header*/ 1951a183a15fSJames Smart if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { 1952a183a15fSJames Smart cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; 1953a183a15fSJames Smart return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request); 1954a183a15fSJames Smart } 1955a183a15fSJames Smart 1956a183a15fSJames Smart /* For non-embedded mbox command, get opcode from first dma page */ 1957a183a15fSJames Smart if (unlikely(!mbox->sge_array)) 1958a183a15fSJames Smart return LPFC_MBOX_SUBSYSTEM_NA; 1959a183a15fSJames Smart cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; 1960a183a15fSJames Smart return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request); 1961a183a15fSJames Smart } 1962a183a15fSJames Smart 1963a183a15fSJames Smart /** 1964a183a15fSJames Smart * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd 1965a183a15fSJames Smart * @phba: pointer to lpfc hba data structure. 1966a183a15fSJames Smart * @mbox: pointer to lpfc mbox command queue entry. 1967a183a15fSJames Smart * 1968a183a15fSJames Smart * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox 1969a183a15fSJames Smart * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if 1970a183a15fSJames Smart * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be 1971a183a15fSJames Smart * returned. 1972a183a15fSJames Smart **/ 1973a183a15fSJames Smart uint8_t 1974a183a15fSJames Smart lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) 1975a183a15fSJames Smart { 1976a183a15fSJames Smart struct lpfc_mbx_sli4_config *sli4_cfg; 1977a183a15fSJames Smart union lpfc_sli4_cfg_shdr *cfg_shdr; 1978a183a15fSJames Smart 1979a183a15fSJames Smart if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) 1980a183a15fSJames Smart return LPFC_MBOX_OPCODE_NA; 198104c68496SJames Smart sli4_cfg = &mbox->u.mqe.un.sli4_config; 198204c68496SJames Smart 198304c68496SJames Smart /* For embedded mbox command, get opcode from embedded sub-header*/ 198404c68496SJames Smart if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { 198504c68496SJames Smart cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; 198604c68496SJames Smart return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); 198704c68496SJames Smart } 198804c68496SJames Smart 198904c68496SJames Smart /* For non-embedded mbox command, get opcode from first dma page */ 199004c68496SJames Smart if (unlikely(!mbox->sge_array)) 1991a183a15fSJames Smart return LPFC_MBOX_OPCODE_NA; 199204c68496SJames Smart cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; 199304c68496SJames Smart return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); 199404c68496SJames Smart } 199504c68496SJames Smart 199604c68496SJames Smart /** 19970c9ab6f5SJames Smart * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd 1998ecfd03c6SJames Smart * @phba: pointer to lpfc hba data structure. 1999ecfd03c6SJames Smart * @fcf_index: index to fcf table. 2000ecfd03c6SJames Smart * 2001ecfd03c6SJames Smart * This routine routine allocates and constructs non-embedded mailbox command 200225985edcSLucas De Marchi * for reading a FCF table entry referred by @fcf_index. 2003ecfd03c6SJames Smart * 2004ecfd03c6SJames Smart * Return: pointer to the mailbox command constructed if successful, otherwise 2005ecfd03c6SJames Smart * NULL. 2006ecfd03c6SJames Smart **/ 2007ecfd03c6SJames Smart int 20080c9ab6f5SJames Smart lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba, 2009ecfd03c6SJames Smart struct lpfcMboxq *mboxq, 2010ecfd03c6SJames Smart uint16_t fcf_index) 2011ecfd03c6SJames Smart { 2012ecfd03c6SJames Smart void *virt_addr; 2013ecfd03c6SJames Smart dma_addr_t phys_addr; 2014ecfd03c6SJames Smart uint8_t *bytep; 2015ecfd03c6SJames Smart struct lpfc_mbx_sge sge; 2016ecfd03c6SJames Smart uint32_t alloc_len, req_len; 2017ecfd03c6SJames Smart struct lpfc_mbx_read_fcf_tbl *read_fcf; 2018ecfd03c6SJames Smart 2019ecfd03c6SJames Smart if (!mboxq) 2020ecfd03c6SJames Smart return -ENOMEM; 2021ecfd03c6SJames Smart 2022ecfd03c6SJames Smart req_len = sizeof(struct fcf_record) + 2023ecfd03c6SJames Smart sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t); 2024ecfd03c6SJames Smart 2025ecfd03c6SJames Smart /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */ 2026ecfd03c6SJames Smart alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, 2027ecfd03c6SJames Smart LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len, 2028ecfd03c6SJames Smart LPFC_SLI4_MBX_NEMBED); 2029ecfd03c6SJames Smart 2030ecfd03c6SJames Smart if (alloc_len < req_len) { 2031ecfd03c6SJames Smart lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, 2032ecfd03c6SJames Smart "0291 Allocated DMA memory size (x%x) is " 2033ecfd03c6SJames Smart "less than the requested DMA memory " 2034ecfd03c6SJames Smart "size (x%x)\n", alloc_len, req_len); 2035ecfd03c6SJames Smart return -ENOMEM; 2036ecfd03c6SJames Smart } 2037ecfd03c6SJames Smart 2038ecfd03c6SJames Smart /* Get the first SGE entry from the non-embedded DMA memory. This 2039ecfd03c6SJames Smart * routine only uses a single SGE. 2040ecfd03c6SJames Smart */ 2041ecfd03c6SJames Smart lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); 2042ecfd03c6SJames Smart phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); 2043ecfd03c6SJames Smart virt_addr = mboxq->sge_array->addr[0]; 2044ecfd03c6SJames Smart read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; 2045ecfd03c6SJames Smart 2046ecfd03c6SJames Smart /* Set up command fields */ 2047ecfd03c6SJames Smart bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index); 2048ecfd03c6SJames Smart /* Perform necessary endian conversion */ 2049ecfd03c6SJames Smart bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); 2050ecfd03c6SJames Smart lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t)); 2051ecfd03c6SJames Smart 2052ecfd03c6SJames Smart return 0; 2053ecfd03c6SJames Smart } 2054ecfd03c6SJames Smart 2055ecfd03c6SJames Smart /** 205604c68496SJames Smart * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox 205704c68496SJames Smart * @mboxq: pointer to lpfc mbox command. 205804c68496SJames Smart * 205904c68496SJames Smart * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES 206004c68496SJames Smart * mailbox command. 206104c68496SJames Smart **/ 206204c68496SJames Smart void 206304c68496SJames Smart lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq) 206404c68496SJames Smart { 206504c68496SJames Smart /* Set up SLI4 mailbox command header fields */ 206604c68496SJames Smart memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); 206704c68496SJames Smart bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS); 206804c68496SJames Smart 206904c68496SJames Smart /* Set up host requested features. */ 207004c68496SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1); 2071fedd3b7bSJames Smart bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1); 207204c68496SJames Smart 207304c68496SJames Smart /* Enable DIF (block guard) only if configured to do so. */ 207404c68496SJames Smart if (phba->cfg_enable_bg) 207504c68496SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1); 207604c68496SJames Smart 207704c68496SJames Smart /* Enable NPIV only if configured to do so. */ 207804c68496SJames Smart if (phba->max_vpi && phba->cfg_enable_npiv) 207904c68496SJames Smart bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1); 208004c68496SJames Smart 208104c68496SJames Smart return; 208204c68496SJames Smart } 208304c68496SJames Smart 208404c68496SJames Smart /** 208504c68496SJames Smart * lpfc_init_vfi - Initialize the INIT_VFI mailbox command 208604c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 208704c68496SJames Smart * @vport: Vport associated with the VF. 208804c68496SJames Smart * 208904c68496SJames Smart * This routine initializes @mbox to all zeros and then fills in the mailbox 209004c68496SJames Smart * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI 209104c68496SJames Smart * in the context of an FCF. The driver issues this command to setup a VFI 209204c68496SJames Smart * before issuing a FLOGI to login to the VSAN. The driver should also issue a 209304c68496SJames Smart * REG_VFI after a successful VSAN login. 209404c68496SJames Smart **/ 209504c68496SJames Smart void 209604c68496SJames Smart lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) 209704c68496SJames Smart { 209804c68496SJames Smart struct lpfc_mbx_init_vfi *init_vfi; 209904c68496SJames Smart 210004c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 210176a95d75SJames Smart mbox->vport = vport; 210204c68496SJames Smart init_vfi = &mbox->u.mqe.un.init_vfi; 210304c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI); 210404c68496SJames Smart bf_set(lpfc_init_vfi_vr, init_vfi, 1); 210504c68496SJames Smart bf_set(lpfc_init_vfi_vt, init_vfi, 1); 210676a95d75SJames Smart bf_set(lpfc_init_vfi_vp, init_vfi, 1); 21076d368e53SJames Smart bf_set(lpfc_init_vfi_vfi, init_vfi, 21086d368e53SJames Smart vport->phba->sli4_hba.vfi_ids[vport->vfi]); 21097851fe2cSJames Smart bf_set(lpfc_init_vfi_vpi, init_vfi, 21106d368e53SJames Smart vport->phba->vpi_ids[vport->vpi]); 21116d368e53SJames Smart bf_set(lpfc_init_vfi_fcfi, init_vfi, 21126d368e53SJames Smart vport->phba->fcf.fcfi); 211304c68496SJames Smart } 211404c68496SJames Smart 211504c68496SJames Smart /** 211604c68496SJames Smart * lpfc_reg_vfi - Initialize the REG_VFI mailbox command 211704c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 211804c68496SJames Smart * @vport: vport associated with the VF. 211904c68496SJames Smart * @phys: BDE DMA bus address used to send the service parameters to the HBA. 212004c68496SJames Smart * 212104c68496SJames Smart * This routine initializes @mbox to all zeros and then fills in the mailbox 212204c68496SJames Smart * fields from @vport, and uses @buf as a DMAable buffer to send the vport's 212304c68496SJames Smart * fc service parameters to the HBA for this VFI. REG_VFI configures virtual 212404c68496SJames Smart * fabrics identified by VFI in the context of an FCF. 212504c68496SJames Smart **/ 212604c68496SJames Smart void 212704c68496SJames Smart lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys) 212804c68496SJames Smart { 212904c68496SJames Smart struct lpfc_mbx_reg_vfi *reg_vfi; 2130ae05ebe3SJames Smart struct lpfc_hba *phba = vport->phba; 213104c68496SJames Smart 213204c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 213304c68496SJames Smart reg_vfi = &mbox->u.mqe.un.reg_vfi; 213404c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI); 213504c68496SJames Smart bf_set(lpfc_reg_vfi_vp, reg_vfi, 1); 21366d368e53SJames Smart bf_set(lpfc_reg_vfi_vfi, reg_vfi, 2137ae05ebe3SJames Smart phba->sli4_hba.vfi_ids[vport->vfi]); 2138ae05ebe3SJames Smart bf_set(lpfc_reg_vfi_fcfi, reg_vfi, phba->fcf.fcfi); 2139ae05ebe3SJames Smart bf_set(lpfc_reg_vfi_vpi, reg_vfi, phba->vpi_ids[vport->vpi]); 2140c868595dSJames Smart memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name)); 2141c868595dSJames Smart reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]); 2142c868595dSJames Smart reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]); 2143ae05ebe3SJames Smart reg_vfi->e_d_tov = phba->fc_edtov; 2144ae05ebe3SJames Smart reg_vfi->r_a_tov = phba->fc_ratov; 214504c68496SJames Smart reg_vfi->bde.addrHigh = putPaddrHigh(phys); 214604c68496SJames Smart reg_vfi->bde.addrLow = putPaddrLow(phys); 214704c68496SJames Smart reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam); 214804c68496SJames Smart reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 214904c68496SJames Smart bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID); 2150ae05ebe3SJames Smart 2151ae05ebe3SJames Smart /* Only FC supports upd bit */ 2152ae05ebe3SJames Smart if ((phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) && 2153e74c03c8SJames Smart (vport->fc_flag & FC_VFI_REGISTERED) && 2154e74c03c8SJames Smart (!phba->fc_topology_changed)) { 2155ae05ebe3SJames Smart bf_set(lpfc_reg_vfi_vp, reg_vfi, 0); 2156ae05ebe3SJames Smart bf_set(lpfc_reg_vfi_upd, reg_vfi, 1); 2157ae05ebe3SJames Smart } 21581b51197dSJames Smart lpfc_printf_vlog(vport, KERN_INFO, LOG_MBOX, 21591b51197dSJames Smart "3134 Register VFI, mydid:x%x, fcfi:%d, " 2160e74c03c8SJames Smart " vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x" 2161e74c03c8SJames Smart " port_state:x%x topology chg:%d\n", 21621b51197dSJames Smart vport->fc_myDID, 2163ae05ebe3SJames Smart phba->fcf.fcfi, 2164ae05ebe3SJames Smart phba->sli4_hba.vfi_ids[vport->vfi], 2165ae05ebe3SJames Smart phba->vpi_ids[vport->vpi], 2166e74c03c8SJames Smart reg_vfi->wwn[0], reg_vfi->wwn[1], vport->fc_flag, 2167e74c03c8SJames Smart vport->port_state, phba->fc_topology_changed); 216804c68496SJames Smart } 216904c68496SJames Smart 217004c68496SJames Smart /** 217104c68496SJames Smart * lpfc_init_vpi - Initialize the INIT_VPI mailbox command 21721c6834a7SJames Smart * @phba: pointer to the hba structure to init the VPI for. 217304c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 217404c68496SJames Smart * @vpi: VPI to be initialized. 217504c68496SJames Smart * 217604c68496SJames Smart * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the 217704c68496SJames Smart * command to activate a virtual N_Port. The HBA assigns a MAC address to use 217804c68496SJames Smart * with the virtual N Port. The SLI Host issues this command before issuing a 217904c68496SJames Smart * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a 218004c68496SJames Smart * successful virtual NPort login. 218104c68496SJames Smart **/ 218204c68496SJames Smart void 21831c6834a7SJames Smart lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi) 218404c68496SJames Smart { 218504c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 218604c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI); 21871c6834a7SJames Smart bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi, 21886d368e53SJames Smart phba->vpi_ids[vpi]); 21891c6834a7SJames Smart bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi, 21906d368e53SJames Smart phba->sli4_hba.vfi_ids[phba->pport->vfi]); 219104c68496SJames Smart } 219204c68496SJames Smart 219304c68496SJames Smart /** 219404c68496SJames Smart * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command 219504c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 21966669f9bbSJames Smart * @vport: vport associated with the VF. 219704c68496SJames Smart * 219804c68496SJames Smart * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric 219904c68496SJames Smart * (logical NPort) into the inactive state. The SLI Host must have logged out 220004c68496SJames Smart * and unregistered all remote N_Ports to abort any activity on the virtual 220104c68496SJames Smart * fabric. The SLI Port posts the mailbox response after marking the virtual 220204c68496SJames Smart * fabric inactive. 220304c68496SJames Smart **/ 220404c68496SJames Smart void 22056669f9bbSJames Smart lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) 220604c68496SJames Smart { 220704c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 220804c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI); 22096669f9bbSJames Smart bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi, 22106d368e53SJames Smart vport->phba->sli4_hba.vfi_ids[vport->vfi]); 221104c68496SJames Smart } 221204c68496SJames Smart 221304c68496SJames Smart /** 2214026abb87SJames Smart * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23 221504c68496SJames Smart * @phba: pointer to the hba structure containing. 221604c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 221704c68496SJames Smart * 2218026abb87SJames Smart * This function create a SLI4 dump mailbox command to dump configure 2219026abb87SJames Smart * region 23. 222004c68496SJames Smart **/ 222104c68496SJames Smart int 2222026abb87SJames Smart lpfc_sli4_dump_cfg_rg23(struct lpfc_hba *phba, struct lpfcMboxq *mbox) 222304c68496SJames Smart { 222404c68496SJames Smart struct lpfc_dmabuf *mp = NULL; 222504c68496SJames Smart MAILBOX_t *mb; 222604c68496SJames Smart 222704c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 222804c68496SJames Smart mb = &mbox->u.mb; 222904c68496SJames Smart 223004c68496SJames Smart mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); 223104c68496SJames Smart if (mp) 223204c68496SJames Smart mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); 223304c68496SJames Smart 223404c68496SJames Smart if (!mp || !mp->virt) { 223504c68496SJames Smart kfree(mp); 2236026abb87SJames Smart /* dump config region 23 failed to allocate memory */ 223704c68496SJames Smart lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 2238026abb87SJames Smart "2569 lpfc dump config region 23: memory" 223904c68496SJames Smart " allocation failed\n"); 224004c68496SJames Smart return 1; 224104c68496SJames Smart } 224204c68496SJames Smart 224304c68496SJames Smart memset(mp->virt, 0, LPFC_BPL_SIZE); 224404c68496SJames Smart INIT_LIST_HEAD(&mp->list); 224504c68496SJames Smart 224604c68496SJames Smart /* save address for completion */ 224704c68496SJames Smart mbox->context1 = (uint8_t *) mp; 224804c68496SJames Smart 224904c68496SJames Smart mb->mbxCommand = MBX_DUMP_MEMORY; 225004c68496SJames Smart mb->un.varDmp.type = DMP_NV_PARAMS; 2251a0c87cbdSJames Smart mb->un.varDmp.region_id = DMP_REGION_23; 2252a0c87cbdSJames Smart mb->un.varDmp.sli4_length = DMP_RGN23_SIZE; 225304c68496SJames Smart mb->un.varWords[3] = putPaddrLow(mp->phys); 225404c68496SJames Smart mb->un.varWords[4] = putPaddrHigh(mp->phys); 225504c68496SJames Smart return 0; 225604c68496SJames Smart } 225704c68496SJames Smart 225804c68496SJames Smart /** 225904c68496SJames Smart * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command 226004c68496SJames Smart * @phba: pointer to the hba structure containing the FCF index and RQ ID. 226104c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 226204c68496SJames Smart * 226304c68496SJames Smart * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The 226404c68496SJames Smart * SLI Host uses the command to activate an FCF after it has acquired FCF 226504c68496SJames Smart * information via a READ_FCF mailbox command. This mailbox command also is used 226604c68496SJames Smart * to indicate where received unsolicited frames from this FCF will be sent. By 226704c68496SJames Smart * default this routine will set up the FCF to forward all unsolicited frames 226804c68496SJames Smart * the the RQ ID passed in the @phba. This can be overridden by the caller for 226904c68496SJames Smart * more complicated setups. 227004c68496SJames Smart **/ 227104c68496SJames Smart void 227204c68496SJames Smart lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox) 227304c68496SJames Smart { 227404c68496SJames Smart struct lpfc_mbx_reg_fcfi *reg_fcfi; 227504c68496SJames Smart 227604c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 227704c68496SJames Smart reg_fcfi = &mbox->u.mqe.un.reg_fcfi; 227804c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI); 227904c68496SJames Smart bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id); 228004c68496SJames Smart bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID); 228104c68496SJames Smart bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID); 228204c68496SJames Smart bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID); 2283ecfd03c6SJames Smart bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, 2284ecfd03c6SJames Smart phba->fcf.current_rec.fcf_indx); 228504c68496SJames Smart /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */ 2286ecfd03c6SJames Smart bf_set(lpfc_reg_fcfi_mam, reg_fcfi, (~phba->fcf.addr_mode) & 0x3); 22873804dc84SJames Smart if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) { 228804c68496SJames Smart bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1); 2289ecfd03c6SJames Smart bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, 2290ecfd03c6SJames Smart phba->fcf.current_rec.vlan_id); 229104c68496SJames Smart } 229204c68496SJames Smart } 229304c68496SJames Smart 229404c68496SJames Smart /** 229504c68496SJames Smart * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command 229604c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 229704c68496SJames Smart * @fcfi: FCFI to be unregistered. 229804c68496SJames Smart * 229904c68496SJames Smart * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). 230004c68496SJames Smart * The SLI Host uses the command to inactivate an FCFI. 230104c68496SJames Smart **/ 230204c68496SJames Smart void 230304c68496SJames Smart lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi) 230404c68496SJames Smart { 230504c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 230604c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI); 230704c68496SJames Smart bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi); 230804c68496SJames Smart } 230904c68496SJames Smart 231004c68496SJames Smart /** 231104c68496SJames Smart * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command 231204c68496SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 231304c68496SJames Smart * @ndlp: The nodelist structure that describes the RPI to resume. 231404c68496SJames Smart * 231504c68496SJames Smart * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a 231604c68496SJames Smart * link event. 231704c68496SJames Smart **/ 231804c68496SJames Smart void 231904c68496SJames Smart lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp) 232004c68496SJames Smart { 23216d368e53SJames Smart struct lpfc_hba *phba = ndlp->phba; 232204c68496SJames Smart struct lpfc_mbx_resume_rpi *resume_rpi; 232304c68496SJames Smart 232404c68496SJames Smart memset(mbox, 0, sizeof(*mbox)); 232504c68496SJames Smart resume_rpi = &mbox->u.mqe.un.resume_rpi; 232604c68496SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI); 23276d368e53SJames Smart bf_set(lpfc_resume_rpi_index, resume_rpi, 23286d368e53SJames Smart phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); 23298fa38513SJames Smart bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI); 23308fa38513SJames Smart resume_rpi->event_tag = ndlp->phba->fc_eventTag; 233104c68496SJames Smart } 233228baac74SJames Smart 233328baac74SJames Smart /** 233428baac74SJames Smart * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages 233528baac74SJames Smart * mailbox command. 233628baac74SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 233728baac74SJames Smart * 233828baac74SJames Smart * The PORT_CAPABILITIES supported pages mailbox command is issued to 233928baac74SJames Smart * retrieve the particular feature pages supported by the port. 234028baac74SJames Smart **/ 234128baac74SJames Smart void 234228baac74SJames Smart lpfc_supported_pages(struct lpfcMboxq *mbox) 234328baac74SJames Smart { 234428baac74SJames Smart struct lpfc_mbx_supp_pages *supp_pages; 234528baac74SJames Smart 234628baac74SJames Smart memset(mbox, 0, sizeof(*mbox)); 234728baac74SJames Smart supp_pages = &mbox->u.mqe.un.supp_pages; 234828baac74SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES); 234928baac74SJames Smart bf_set(cpn, supp_pages, LPFC_SUPP_PAGES); 235028baac74SJames Smart } 235128baac74SJames Smart 235228baac74SJames Smart /** 2353fedd3b7bSJames Smart * lpfc_pc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params mbox cmd. 235428baac74SJames Smart * @mbox: pointer to lpfc mbox command to initialize. 235528baac74SJames Smart * 235628baac74SJames Smart * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to 235728baac74SJames Smart * retrieve the particular SLI4 features supported by the port. 235828baac74SJames Smart **/ 235928baac74SJames Smart void 2360fedd3b7bSJames Smart lpfc_pc_sli4_params(struct lpfcMboxq *mbox) 236128baac74SJames Smart { 2362fedd3b7bSJames Smart struct lpfc_mbx_pc_sli4_params *sli4_params; 236328baac74SJames Smart 236428baac74SJames Smart memset(mbox, 0, sizeof(*mbox)); 236528baac74SJames Smart sli4_params = &mbox->u.mqe.un.sli4_params; 236628baac74SJames Smart bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES); 236728baac74SJames Smart bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS); 236828baac74SJames Smart } 2369