1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139 |
- /*******************************************************************
- * This file is part of the Emulex Linux Device Driver for *
- * Fibre Channel Host Bus Adapters. *
- * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term *
- * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
- * Copyright (C) 2004-2016 Emulex. All rights reserved. *
- * EMULEX and SLI are trademarks of Emulex. *
- * www.broadcom.com *
- * Portions Copyright (C) 2004-2005 Christoph Hellwig *
- * *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of version 2 of the GNU General *
- * Public License as published by the Free Software Foundation. *
- * This program is distributed in the hope that it will be useful. *
- * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
- * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
- * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
- * TO BE LEGALLY INVALID. See the GNU General Public License for *
- * more details, a copy of which can be found in the file COPYING *
- * included with this package. *
- *******************************************************************/
- #include <linux/blkdev.h>
- #include <linux/pci.h>
- #include <linux/slab.h>
- #include <linux/interrupt.h>
- #include <scsi/scsi.h>
- #include <scsi/scsi_device.h>
- #include <scsi/scsi_host.h>
- #include <scsi/scsi_transport_fc.h>
- #include <scsi/fc/fc_fs.h>
- #include "lpfc_hw4.h"
- #include "lpfc_hw.h"
- #include "lpfc_sli.h"
- #include "lpfc_sli4.h"
- #include "lpfc_nl.h"
- #include "lpfc_disc.h"
- #include "lpfc.h"
- #include "lpfc_scsi.h"
- #include "lpfc_nvme.h"
- #include "lpfc_logmsg.h"
- #include "lpfc_crtn.h"
- #include "lpfc_vport.h"
- #include "lpfc_debugfs.h"
- /* Called to verify a rcv'ed ADISC was intended for us. */
- static int
- lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- struct lpfc_name *nn, struct lpfc_name *pn)
- {
- /* First, we MUST have a RPI registered */
- if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
- return 0;
- /* Compare the ADISC rsp WWNN / WWPN matches our internal node
- * table entry for that node.
- */
- if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
- return 0;
- if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
- return 0;
- /* we match, return success */
- return 1;
- }
- int
- lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- struct serv_parm *sp, uint32_t class, int flogi)
- {
- volatile struct serv_parm *hsp = &vport->fc_sparam;
- uint16_t hsp_value, ssp_value = 0;
- /*
- * The receive data field size and buffer-to-buffer receive data field
- * size entries are 16 bits but are represented as two 8-bit fields in
- * the driver data structure to account for rsvd bits and other control
- * bits. Reconstruct and compare the fields as a 16-bit values before
- * correcting the byte values.
- */
- if (sp->cls1.classValid) {
- if (!flogi) {
- hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
- hsp->cls1.rcvDataSizeLsb);
- ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
- sp->cls1.rcvDataSizeLsb);
- if (!ssp_value)
- goto bad_service_param;
- if (ssp_value > hsp_value) {
- sp->cls1.rcvDataSizeLsb =
- hsp->cls1.rcvDataSizeLsb;
- sp->cls1.rcvDataSizeMsb =
- hsp->cls1.rcvDataSizeMsb;
- }
- }
- } else if (class == CLASS1)
- goto bad_service_param;
- if (sp->cls2.classValid) {
- if (!flogi) {
- hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
- hsp->cls2.rcvDataSizeLsb);
- ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
- sp->cls2.rcvDataSizeLsb);
- if (!ssp_value)
- goto bad_service_param;
- if (ssp_value > hsp_value) {
- sp->cls2.rcvDataSizeLsb =
- hsp->cls2.rcvDataSizeLsb;
- sp->cls2.rcvDataSizeMsb =
- hsp->cls2.rcvDataSizeMsb;
- }
- }
- } else if (class == CLASS2)
- goto bad_service_param;
- if (sp->cls3.classValid) {
- if (!flogi) {
- hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
- hsp->cls3.rcvDataSizeLsb);
- ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
- sp->cls3.rcvDataSizeLsb);
- if (!ssp_value)
- goto bad_service_param;
- if (ssp_value > hsp_value) {
- sp->cls3.rcvDataSizeLsb =
- hsp->cls3.rcvDataSizeLsb;
- sp->cls3.rcvDataSizeMsb =
- hsp->cls3.rcvDataSizeMsb;
- }
- }
- } else if (class == CLASS3)
- goto bad_service_param;
- /*
- * Preserve the upper four bits of the MSB from the PLOGI response.
- * These bits contain the Buffer-to-Buffer State Change Number
- * from the target and need to be passed to the FW.
- */
- hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
- ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
- if (ssp_value > hsp_value) {
- sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
- sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
- (hsp->cmn.bbRcvSizeMsb & 0x0F);
- }
- memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
- memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
- return 1;
- bad_service_param:
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0207 Device %x "
- "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
- "invalid service parameters. Ignoring device.\n",
- ndlp->nlp_DID,
- sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
- sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
- sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
- sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
- return 0;
- }
- static void *
- lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
- struct lpfc_iocbq *rspiocb)
- {
- struct lpfc_dmabuf *pcmd, *prsp;
- uint32_t *lp;
- void *ptr = NULL;
- u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
- pcmd = cmdiocb->cmd_dmabuf;
- /* For lpfc_els_abort, cmd_dmabuf could be zero'ed to delay
- * freeing associated memory till after ABTS completes.
- */
- if (pcmd) {
- prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
- list);
- if (prsp) {
- lp = (uint32_t *) prsp->virt;
- ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
- }
- } else {
- /* Force ulp_status error since we are returning NULL ptr */
- if (!(ulp_status)) {
- if (phba->sli_rev == LPFC_SLI_REV4) {
- bf_set(lpfc_wcqe_c_status, &rspiocb->wcqe_cmpl,
- IOSTAT_LOCAL_REJECT);
- rspiocb->wcqe_cmpl.parameter = IOERR_SLI_ABORTED;
- } else {
- rspiocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
- rspiocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
- }
- }
- ptr = NULL;
- }
- return ptr;
- }
- /*
- * Free resources / clean up outstanding I/Os
- * associated with a LPFC_NODELIST entry. This
- * routine effectively results in a "software abort".
- */
- void
- lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
- {
- LIST_HEAD(abort_list);
- struct lpfc_sli_ring *pring;
- struct lpfc_iocbq *iocb, *next_iocb;
- pring = lpfc_phba_elsring(phba);
- /* In case of error recovery path, we might have a NULL pring here */
- if (unlikely(!pring))
- return;
- /* Abort outstanding I/O on NPort <nlp_DID> */
- lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
- "2819 Abort outstanding I/O on NPort x%x "
- "Data: x%x x%x x%x\n",
- ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
- ndlp->nlp_rpi);
- /* Clean up all fabric IOs first.*/
- lpfc_fabric_abort_nport(ndlp);
- /*
- * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
- * of all ELS IOs that need an ABTS. The IOs need to stay on the
- * txcmplq so that the abort operation completes them successfully.
- */
- spin_lock_irq(&phba->hbalock);
- if (phba->sli_rev == LPFC_SLI_REV4)
- spin_lock(&pring->ring_lock);
- list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
- /* Add to abort_list on on NDLP match. */
- if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
- list_add_tail(&iocb->dlist, &abort_list);
- }
- if (phba->sli_rev == LPFC_SLI_REV4)
- spin_unlock(&pring->ring_lock);
- spin_unlock_irq(&phba->hbalock);
- /* Abort the targeted IOs and remove them from the abort list. */
- list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) {
- spin_lock_irq(&phba->hbalock);
- list_del_init(&iocb->dlist);
- lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
- spin_unlock_irq(&phba->hbalock);
- }
- /* Make sure HBA is alive */
- lpfc_issue_hb_tmo(phba);
- INIT_LIST_HEAD(&abort_list);
- /* Now process the txq */
- spin_lock_irq(&phba->hbalock);
- if (phba->sli_rev == LPFC_SLI_REV4)
- spin_lock(&pring->ring_lock);
- list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
- /* Check to see if iocb matches the nport we are looking for */
- if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
- list_del_init(&iocb->list);
- list_add_tail(&iocb->list, &abort_list);
- }
- }
- if (phba->sli_rev == LPFC_SLI_REV4)
- spin_unlock(&pring->ring_lock);
- spin_unlock_irq(&phba->hbalock);
- /* Cancel all the IOCBs from the completions list */
- lpfc_sli_cancel_iocbs(phba, &abort_list,
- IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
- lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
- }
- /* lpfc_defer_plogi_acc - Issue PLOGI ACC after reg_login completes
- * @phba: pointer to lpfc hba data structure.
- * @login_mbox: pointer to REG_RPI mailbox object
- *
- * The ACC for a rcv'ed PLOGI is deferred until AFTER the REG_RPI completes
- */
- static void
- lpfc_defer_plogi_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *login_mbox)
- {
- struct lpfc_iocbq *save_iocb;
- struct lpfc_nodelist *ndlp;
- MAILBOX_t *mb = &login_mbox->u.mb;
- int rc;
- ndlp = login_mbox->ctx_ndlp;
- save_iocb = login_mbox->context3;
- if (mb->mbxStatus == MBX_SUCCESS) {
- /* Now that REG_RPI completed successfully,
- * we can now proceed with sending the PLOGI ACC.
- */
- rc = lpfc_els_rsp_acc(login_mbox->vport, ELS_CMD_PLOGI,
- save_iocb, ndlp, NULL);
- if (rc) {
- lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
- "4576 PLOGI ACC fails pt2pt discovery: "
- "DID %x Data: %x\n", ndlp->nlp_DID, rc);
- }
- }
- /* Now process the REG_RPI cmpl */
- lpfc_mbx_cmpl_reg_login(phba, login_mbox);
- ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
- kfree(save_iocb);
- }
- static int
- lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- struct lpfc_iocbq *cmdiocb)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_dmabuf *pcmd;
- uint64_t nlp_portwwn = 0;
- uint32_t *lp;
- union lpfc_wqe128 *wqe;
- IOCB_t *icmd;
- struct serv_parm *sp;
- uint32_t ed_tov;
- LPFC_MBOXQ_t *link_mbox;
- LPFC_MBOXQ_t *login_mbox;
- struct lpfc_iocbq *save_iocb;
- struct ls_rjt stat;
- uint32_t vid, flag;
- int rc;
- u32 remote_did;
- memset(&stat, 0, sizeof (struct ls_rjt));
- pcmd = cmdiocb->cmd_dmabuf;
- lp = (uint32_t *) pcmd->virt;
- sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
- if (wwn_to_u64(sp->portName.u.wwn) == 0) {
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0140 PLOGI Reject: invalid pname\n");
- stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
- NULL);
- return 0;
- }
- if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0141 PLOGI Reject: invalid nname\n");
- stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
- NULL);
- return 0;
- }
- nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn);
- if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
- /* Reject this request because invalid parameters */
- stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
- NULL);
- return 0;
- }
- if (phba->sli_rev == LPFC_SLI_REV4)
- wqe = &cmdiocb->wqe;
- else
- icmd = &cmdiocb->iocb;
- /* PLOGI chkparm OK */
- lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
- "0114 PLOGI chkparm OK Data: x%x x%x x%x "
- "x%x x%x x%x\n",
- ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
- ndlp->nlp_rpi, vport->port_state,
- vport->fc_flag);
- if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
- ndlp->nlp_fcp_info |= CLASS2;
- else
- ndlp->nlp_fcp_info |= CLASS3;
- ndlp->nlp_class_sup = 0;
- if (sp->cls1.classValid)
- ndlp->nlp_class_sup |= FC_COS_CLASS1;
- if (sp->cls2.classValid)
- ndlp->nlp_class_sup |= FC_COS_CLASS2;
- if (sp->cls3.classValid)
- ndlp->nlp_class_sup |= FC_COS_CLASS3;
- if (sp->cls4.classValid)
- ndlp->nlp_class_sup |= FC_COS_CLASS4;
- ndlp->nlp_maxframe =
- ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
- /* if already logged in, do implicit logout */
- switch (ndlp->nlp_state) {
- case NLP_STE_NPR_NODE:
- if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
- break;
- fallthrough;
- case NLP_STE_REG_LOGIN_ISSUE:
- case NLP_STE_PRLI_ISSUE:
- case NLP_STE_UNMAPPED_NODE:
- case NLP_STE_MAPPED_NODE:
- /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
- * For target mode, execute implicit logo.
- * Fabric nodes go into NPR.
- */
- if (!(ndlp->nlp_type & NLP_FABRIC) &&
- !(phba->nvmet_support)) {
- /* Clear ndlp info, since follow up PRLI may have
- * updated ndlp information
- */
- ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
- ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
- ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
- ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
- ndlp->nlp_flag &= ~NLP_FIRSTBURST;
- lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
- ndlp, NULL);
- return 1;
- }
- if (nlp_portwwn != 0 &&
- nlp_portwwn != wwn_to_u64(sp->portName.u.wwn))
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0143 PLOGI recv'd from DID: x%x "
- "WWPN changed: old %llx new %llx\n",
- ndlp->nlp_DID,
- (unsigned long long)nlp_portwwn,
- (unsigned long long)
- wwn_to_u64(sp->portName.u.wwn));
- /* Notify transport of connectivity loss to trigger cleanup. */
- if (phba->nvmet_support &&
- ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
- lpfc_nvmet_invalidate_host(phba, ndlp);
- ndlp->nlp_prev_state = ndlp->nlp_state;
- /* rport needs to be unregistered first */
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- break;
- }
- ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
- ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
- ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
- ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
- ndlp->nlp_flag &= ~NLP_FIRSTBURST;
- login_mbox = NULL;
- link_mbox = NULL;
- save_iocb = NULL;
- /* Check for Nport to NPort pt2pt protocol */
- if ((vport->fc_flag & FC_PT2PT) &&
- !(vport->fc_flag & FC_PT2PT_PLOGI)) {
- /* rcv'ed PLOGI decides what our NPortId will be */
- if (phba->sli_rev == LPFC_SLI_REV4) {
- vport->fc_myDID = bf_get(els_rsp64_sid,
- &cmdiocb->wqe.xmit_els_rsp);
- } else {
- vport->fc_myDID = icmd->un.rcvels.parmRo;
- }
- /* If there is an outstanding FLOGI, abort it now.
- * The remote NPort is not going to ACC our FLOGI
- * if its already issuing a PLOGI for pt2pt mode.
- * This indicates our FLOGI was dropped; however, we
- * must have ACCed the remote NPorts FLOGI to us
- * to make it here.
- */
- if (phba->hba_flag & HBA_FLOGI_OUTSTANDING)
- lpfc_els_abort_flogi(phba);
- ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
- if (sp->cmn.edtovResolution) {
- /* E_D_TOV ticks are in nanoseconds */
- ed_tov = (phba->fc_edtov + 999999) / 1000000;
- }
- /*
- * For pt-to-pt, use the larger EDTOV
- * RATOV = 2 * EDTOV
- */
- if (ed_tov > phba->fc_edtov)
- phba->fc_edtov = ed_tov;
- phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
- memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
- /* Issue CONFIG_LINK for SLI3 or REG_VFI for SLI4,
- * to account for updated TOV's / parameters
- */
- if (phba->sli_rev == LPFC_SLI_REV4)
- lpfc_issue_reg_vfi(vport);
- else {
- link_mbox = mempool_alloc(phba->mbox_mem_pool,
- GFP_KERNEL);
- if (!link_mbox)
- goto out;
- lpfc_config_link(phba, link_mbox);
- link_mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
- link_mbox->vport = vport;
- /* The default completion handling for CONFIG_LINK
- * does not require the ndlp so no reference is needed.
- */
- link_mbox->ctx_ndlp = ndlp;
- rc = lpfc_sli_issue_mbox(phba, link_mbox, MBX_NOWAIT);
- if (rc == MBX_NOT_FINISHED) {
- mempool_free(link_mbox, phba->mbox_mem_pool);
- goto out;
- }
- }
- lpfc_can_disctmo(vport);
- }
- ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
- if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
- sp->cmn.valid_vendor_ver_level) {
- vid = be32_to_cpu(sp->un.vv.vid);
- flag = be32_to_cpu(sp->un.vv.flags);
- if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP))
- ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
- }
- login_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!login_mbox)
- goto out;
- save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL);
- if (!save_iocb)
- goto out;
- /* Save info from cmd IOCB to be used in rsp after all mbox completes */
- memcpy((uint8_t *)save_iocb, (uint8_t *)cmdiocb,
- sizeof(struct lpfc_iocbq));
- /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
- if (phba->sli_rev == LPFC_SLI_REV4)
- lpfc_unreg_rpi(vport, ndlp);
- /* Issue REG_LOGIN first, before ACCing the PLOGI, thus we will
- * always be deferring the ACC.
- */
- if (phba->sli_rev == LPFC_SLI_REV4)
- remote_did = bf_get(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest);
- else
- remote_did = icmd->un.rcvels.remoteID;
- rc = lpfc_reg_rpi(phba, vport->vpi, remote_did,
- (uint8_t *)sp, login_mbox, ndlp->nlp_rpi);
- if (rc)
- goto out;
- login_mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
- login_mbox->vport = vport;
- /*
- * If there is an outstanding PLOGI issued, abort it before
- * sending ACC rsp for received PLOGI. If pending plogi
- * is not canceled here, the plogi will be rejected by
- * remote port and will be retried. On a configuration with
- * single discovery thread, this will cause a huge delay in
- * discovery. Also this will cause multiple state machines
- * running in parallel for this node.
- * This only applies to a fabric environment.
- */
- if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) &&
- (vport->fc_flag & FC_FABRIC)) {
- /* software abort outstanding PLOGI */
- lpfc_els_abort(phba, ndlp);
- }
- if ((vport->port_type == LPFC_NPIV_PORT &&
- vport->cfg_restrict_login)) {
- /* no deferred ACC */
- kfree(save_iocb);
- /* This is an NPIV SLI4 instance that does not need to register
- * a default RPI.
- */
- if (phba->sli_rev == LPFC_SLI_REV4) {
- lpfc_mbox_rsrc_cleanup(phba, login_mbox,
- MBOX_THD_UNLOCKED);
- login_mbox = NULL;
- } else {
- /* In order to preserve RPIs, we want to cleanup
- * the default RPI the firmware created to rcv
- * this ELS request. The only way to do this is
- * to register, then unregister the RPI.
- */
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= (NLP_RM_DFLT_RPI | NLP_ACC_REGLOGIN |
- NLP_RCV_PLOGI);
- spin_unlock_irq(&ndlp->lock);
- }
- stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
- rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
- ndlp, login_mbox);
- if (rc && login_mbox)
- lpfc_mbox_rsrc_cleanup(phba, login_mbox,
- MBOX_THD_UNLOCKED);
- return 1;
- }
- /* So the order here should be:
- * SLI3 pt2pt
- * Issue CONFIG_LINK mbox
- * CONFIG_LINK cmpl
- * SLI4 pt2pt
- * Issue REG_VFI mbox
- * REG_VFI cmpl
- * SLI4
- * Issue UNREG RPI mbx
- * UNREG RPI cmpl
- * Issue REG_RPI mbox
- * REG RPI cmpl
- * Issue PLOGI ACC
- * PLOGI ACC cmpl
- */
- login_mbox->mbox_cmpl = lpfc_defer_plogi_acc;
- login_mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
- if (!login_mbox->ctx_ndlp)
- goto out;
- login_mbox->context3 = save_iocb; /* For PLOGI ACC */
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
- spin_unlock_irq(&ndlp->lock);
- /* Start the ball rolling by issuing REG_LOGIN here */
- rc = lpfc_sli_issue_mbox(phba, login_mbox, MBX_NOWAIT);
- if (rc == MBX_NOT_FINISHED) {
- lpfc_nlp_put(ndlp);
- goto out;
- }
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
- return 1;
- out:
- kfree(save_iocb);
- if (login_mbox)
- mempool_free(login_mbox, phba->mbox_mem_pool);
- stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
- return 0;
- }
- /**
- * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
- * @phba: pointer to lpfc hba data structure.
- * @mboxq: pointer to mailbox object
- *
- * This routine is invoked to issue a completion to a rcv'ed
- * ADISC or PDISC after the paused RPI has been resumed.
- **/
- static void
- lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
- {
- struct lpfc_vport *vport;
- struct lpfc_iocbq *elsiocb;
- struct lpfc_nodelist *ndlp;
- uint32_t cmd;
- elsiocb = (struct lpfc_iocbq *)mboxq->ctx_buf;
- ndlp = (struct lpfc_nodelist *)mboxq->ctx_ndlp;
- vport = mboxq->vport;
- cmd = elsiocb->drvrTimeout;
- if (cmd == ELS_CMD_ADISC) {
- lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp);
- } else {
- lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb,
- ndlp, NULL);
- }
- /* This nlp_put pairs with lpfc_sli4_resume_rpi */
- lpfc_nlp_put(ndlp);
- kfree(elsiocb);
- mempool_free(mboxq, phba->mbox_mem_pool);
- }
- static int
- lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- struct lpfc_iocbq *cmdiocb)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *elsiocb;
- struct lpfc_dmabuf *pcmd;
- struct serv_parm *sp;
- struct lpfc_name *pnn, *ppn;
- struct ls_rjt stat;
- ADISC *ap;
- uint32_t *lp;
- uint32_t cmd;
- pcmd = cmdiocb->cmd_dmabuf;
- lp = (uint32_t *) pcmd->virt;
- cmd = *lp++;
- if (cmd == ELS_CMD_ADISC) {
- ap = (ADISC *) lp;
- pnn = (struct lpfc_name *) & ap->nodeName;
- ppn = (struct lpfc_name *) & ap->portName;
- } else {
- sp = (struct serv_parm *) lp;
- pnn = (struct lpfc_name *) & sp->nodeName;
- ppn = (struct lpfc_name *) & sp->portName;
- }
- if (get_job_ulpstatus(phba, cmdiocb) == 0 &&
- lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
- /*
- * As soon as we send ACC, the remote NPort can
- * start sending us data. Thus, for SLI4 we must
- * resume the RPI before the ACC goes out.
- */
- if (vport->phba->sli_rev == LPFC_SLI_REV4) {
- elsiocb = kmalloc(sizeof(struct lpfc_iocbq),
- GFP_KERNEL);
- if (elsiocb) {
- /* Save info from cmd IOCB used in rsp */
- memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb,
- sizeof(struct lpfc_iocbq));
- /* Save the ELS cmd */
- elsiocb->drvrTimeout = cmd;
- lpfc_sli4_resume_rpi(ndlp,
- lpfc_mbx_cmpl_resume_rpi, elsiocb);
- goto out;
- }
- }
- if (cmd == ELS_CMD_ADISC) {
- lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
- } else {
- lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb,
- ndlp, NULL);
- }
- out:
- /* If we are authenticated, move to the proper state.
- * It is possible an ADISC arrived and the remote nport
- * is already in MAPPED or UNMAPPED state. Catch this
- * condition and don't set the nlp_state again because
- * it causes an unnecessary transport unregister/register.
- *
- * Nodes marked for ADISC will move MAPPED or UNMAPPED state
- * after issuing ADISC
- */
- if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
- if ((ndlp->nlp_state != NLP_STE_MAPPED_NODE) &&
- !(ndlp->nlp_flag & NLP_NPR_ADISC))
- lpfc_nlp_set_state(vport, ndlp,
- NLP_STE_MAPPED_NODE);
- }
- return 1;
- }
- /* Reject this request because invalid parameters */
- stat.un.b.lsRjtRsvd0 = 0;
- stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
- stat.un.b.vendorUnique = 0;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
- /* 1 sec timeout */
- mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_DELAY_TMO;
- spin_unlock_irq(&ndlp->lock);
- ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
- ndlp->nlp_prev_state = ndlp->nlp_state;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- return 0;
- }
- static int
- lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
- {
- struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_vport **vports;
- int i, active_vlink_present = 0 ;
- /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
- /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
- * PLOGIs during LOGO storms from a device.
- */
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_LOGO_ACC;
- spin_unlock_irq(&ndlp->lock);
- if (els_cmd == ELS_CMD_PRLO)
- lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
- else
- lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
- /* This clause allows the initiator to ACC the LOGO back to the
- * Fabric Domain Controller. It does deliberately skip all other
- * steps because some fabrics send RDP requests after logging out
- * from the initiator.
- */
- if (ndlp->nlp_type & NLP_FABRIC &&
- ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
- return 0;
- /* Notify transport of connectivity loss to trigger cleanup. */
- if (phba->nvmet_support &&
- ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
- lpfc_nvmet_invalidate_host(phba, ndlp);
- if (ndlp->nlp_DID == Fabric_DID) {
- if (vport->port_state <= LPFC_FDISC ||
- vport->fc_flag & FC_PT2PT)
- goto out;
- lpfc_linkdown_port(vport);
- spin_lock_irq(shost->host_lock);
- vport->fc_flag |= FC_VPORT_LOGO_RCVD;
- spin_unlock_irq(shost->host_lock);
- vports = lpfc_create_vport_work_array(phba);
- if (vports) {
- for (i = 0; i <= phba->max_vports && vports[i] != NULL;
- i++) {
- if ((!(vports[i]->fc_flag &
- FC_VPORT_LOGO_RCVD)) &&
- (vports[i]->port_state > LPFC_FDISC)) {
- active_vlink_present = 1;
- break;
- }
- }
- lpfc_destroy_vport_work_array(phba, vports);
- }
- /*
- * Don't re-instantiate if vport is marked for deletion.
- * If we are here first then vport_delete is going to wait
- * for discovery to complete.
- */
- if (!(vport->load_flag & FC_UNLOADING) &&
- active_vlink_present) {
- /*
- * If there are other active VLinks present,
- * re-instantiate the Vlink using FDISC.
- */
- mod_timer(&ndlp->nlp_delayfunc,
- jiffies + msecs_to_jiffies(1000));
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_DELAY_TMO;
- spin_unlock_irq(&ndlp->lock);
- ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
- vport->port_state = LPFC_FDISC;
- } else {
- spin_lock_irq(shost->host_lock);
- phba->pport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG;
- spin_unlock_irq(shost->host_lock);
- lpfc_retry_pport_discovery(phba);
- }
- } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
- ((ndlp->nlp_type & NLP_FCP_TARGET) ||
- (ndlp->nlp_type & NLP_NVME_TARGET) ||
- (vport->fc_flag & FC_PT2PT))) ||
- (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
- /* Only try to re-login if this is NOT a Fabric Node
- * AND the remote NPORT is a FCP/NVME Target or we
- * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
- * case for LOGO as a response to ADISC behavior.
- */
- mod_timer(&ndlp->nlp_delayfunc,
- jiffies + msecs_to_jiffies(1000 * 1));
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_DELAY_TMO;
- spin_unlock_irq(&ndlp->lock);
- ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
- }
- out:
- /* Unregister from backend, could have been skipped due to ADISC */
- lpfc_nlp_unreg_node(vport, ndlp);
- ndlp->nlp_prev_state = ndlp->nlp_state;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~NLP_NPR_ADISC;
- spin_unlock_irq(&ndlp->lock);
- /* The driver has to wait until the ACC completes before it continues
- * processing the LOGO. The action will resume in
- * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
- * unreg_login, the driver waits so the ACC does not get aborted.
- */
- return 0;
- }
- static uint32_t
- lpfc_rcv_prli_support_check(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- struct lpfc_iocbq *cmdiocb)
- {
- struct ls_rjt stat;
- uint32_t *payload;
- uint32_t cmd;
- payload = cmdiocb->cmd_dmabuf->virt;
- cmd = *payload;
- if (vport->phba->nvmet_support) {
- /* Must be a NVME PRLI */
- if (cmd == ELS_CMD_PRLI)
- goto out;
- } else {
- /* Initiator mode. */
- if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI))
- goto out;
- }
- return 1;
- out:
- lpfc_printf_vlog(vport, KERN_WARNING, LOG_NVME_DISC,
- "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
- "state x%x flags x%x\n",
- cmd, ndlp->nlp_rpi, ndlp->nlp_state,
- ndlp->nlp_flag);
- memset(&stat, 0, sizeof(struct ls_rjt));
- stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
- ndlp, NULL);
- return 0;
- }
- static void
- lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- struct lpfc_iocbq *cmdiocb)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_dmabuf *pcmd;
- uint32_t *lp;
- PRLI *npr;
- struct fc_rport *rport = ndlp->rport;
- u32 roles;
- pcmd = cmdiocb->cmd_dmabuf;
- lp = (uint32_t *)pcmd->virt;
- npr = (PRLI *)((uint8_t *)lp + sizeof(uint32_t));
- if ((npr->prliType == PRLI_FCP_TYPE) ||
- (npr->prliType == PRLI_NVME_TYPE)) {
- if (npr->initiatorFunc) {
- if (npr->prliType == PRLI_FCP_TYPE)
- ndlp->nlp_type |= NLP_FCP_INITIATOR;
- if (npr->prliType == PRLI_NVME_TYPE)
- ndlp->nlp_type |= NLP_NVME_INITIATOR;
- }
- if (npr->targetFunc) {
- if (npr->prliType == PRLI_FCP_TYPE)
- ndlp->nlp_type |= NLP_FCP_TARGET;
- if (npr->prliType == PRLI_NVME_TYPE)
- ndlp->nlp_type |= NLP_NVME_TARGET;
- if (npr->writeXferRdyDis)
- ndlp->nlp_flag |= NLP_FIRSTBURST;
- }
- if (npr->Retry && ndlp->nlp_type &
- (NLP_FCP_INITIATOR | NLP_FCP_TARGET))
- ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
- if (npr->Retry && phba->nsler &&
- ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET))
- ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
- /* If this driver is in nvme target mode, set the ndlp's fc4
- * type to NVME provided the PRLI response claims NVME FC4
- * type. Target mode does not issue gft_id so doesn't get
- * the fc4 type set until now.
- */
- if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) {
- ndlp->nlp_fc4_type |= NLP_FC4_NVME;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
- }
- /* Fabric Controllers send FCP PRLI as an initiator but should
- * not get recognized as FCP type and registered with transport.
- */
- if (npr->prliType == PRLI_FCP_TYPE &&
- !(ndlp->nlp_type & NLP_FABRIC))
- ndlp->nlp_fc4_type |= NLP_FC4_FCP;
- }
- if (rport) {
- /* We need to update the rport role values */
- roles = FC_RPORT_ROLE_UNKNOWN;
- if (ndlp->nlp_type & NLP_FCP_INITIATOR)
- roles |= FC_RPORT_ROLE_FCP_INITIATOR;
- if (ndlp->nlp_type & NLP_FCP_TARGET)
- roles |= FC_RPORT_ROLE_FCP_TARGET;
- lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
- "rport rolechg: role:x%x did:x%x flg:x%x",
- roles, ndlp->nlp_DID, ndlp->nlp_flag);
- if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
- fc_remote_port_rolechg(rport, roles);
- }
- }
- static uint32_t
- lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
- {
- if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~NLP_NPR_ADISC;
- spin_unlock_irq(&ndlp->lock);
- return 0;
- }
- if (!(vport->fc_flag & FC_PT2PT)) {
- /* Check config parameter use-adisc or FCP-2 */
- if (vport->cfg_use_adisc && ((vport->fc_flag & FC_RSCN_MODE) ||
- ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) &&
- (ndlp->nlp_type & NLP_FCP_TARGET)))) {
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_NPR_ADISC;
- spin_unlock_irq(&ndlp->lock);
- return 1;
- }
- }
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~NLP_NPR_ADISC;
- spin_unlock_irq(&ndlp->lock);
- lpfc_unreg_rpi(vport, ndlp);
- return 0;
- }
- /**
- * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
- * @phba : Pointer to lpfc_hba structure.
- * @vport: Pointer to lpfc_vport structure.
- * @ndlp: Pointer to lpfc_nodelist structure.
- * @rpi : rpi to be release.
- *
- * This function will send a unreg_login mailbox command to the firmware
- * to release a rpi.
- **/
- static void
- lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp, uint16_t rpi)
- {
- LPFC_MBOXQ_t *pmb;
- int rc;
- /* If there is already an UNREG in progress for this ndlp,
- * no need to queue up another one.
- */
- if (ndlp->nlp_flag & NLP_UNREG_INP) {
- lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
- "1435 release_rpi SKIP UNREG x%x on "
- "NPort x%x deferred x%x flg x%x "
- "Data: x%px\n",
- ndlp->nlp_rpi, ndlp->nlp_DID,
- ndlp->nlp_defer_did,
- ndlp->nlp_flag, ndlp);
- return;
- }
- pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
- GFP_KERNEL);
- if (!pmb)
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "2796 mailbox memory allocation failed \n");
- else {
- lpfc_unreg_login(phba, vport->vpi, rpi, pmb);
- pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
- pmb->vport = vport;
- pmb->ctx_ndlp = lpfc_nlp_get(ndlp);
- if (!pmb->ctx_ndlp) {
- mempool_free(pmb, phba->mbox_mem_pool);
- return;
- }
- if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
- (!(vport->fc_flag & FC_OFFLINE_MODE)))
- ndlp->nlp_flag |= NLP_UNREG_INP;
- lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
- "1437 release_rpi UNREG x%x "
- "on NPort x%x flg x%x\n",
- ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
- rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
- if (rc == MBX_NOT_FINISHED) {
- lpfc_nlp_put(ndlp);
- mempool_free(pmb, phba->mbox_mem_pool);
- }
- }
- }
- static uint32_t
- lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_hba *phba;
- LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
- uint16_t rpi;
- phba = vport->phba;
- /* Release the RPI if reglogin completing */
- if (!(phba->pport->load_flag & FC_UNLOADING) &&
- (evt == NLP_EVT_CMPL_REG_LOGIN) &&
- (!pmb->u.mb.mbxStatus)) {
- rpi = pmb->u.mb.un.varWords[0];
- lpfc_release_rpi(phba, vport, ndlp, rpi);
- }
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0271 Illegal State Transition: node x%x "
- "event x%x, state x%x Data: x%x x%x\n",
- ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
- ndlp->nlp_flag);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- /* This transition is only legal if we previously
- * rcv'ed a PLOGI. Since we don't want 2 discovery threads
- * working on the same NPortID, do nothing for this thread
- * to stop it.
- */
- if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0272 Illegal State Transition: node x%x "
- "event x%x, state x%x Data: x%x x%x\n",
- ndlp->nlp_DID, evt, ndlp->nlp_state,
- ndlp->nlp_rpi, ndlp->nlp_flag);
- }
- return ndlp->nlp_state;
- }
- /* Start of Discovery State Machine routines */
- static uint32_t
- lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb;
- cmdiocb = (struct lpfc_iocbq *) arg;
- if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
- return ndlp->nlp_state;
- }
- return NLP_STE_FREED_NODE;
- }
- static uint32_t
- lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- lpfc_issue_els_logo(vport, ndlp, 0);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_LOGO_ACC;
- spin_unlock_irq(&ndlp->lock);
- lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- return NLP_STE_FREED_NODE;
- }
- static uint32_t
- lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- return NLP_STE_FREED_NODE;
- }
- static uint32_t
- lpfc_device_recov_unused_node(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocb = arg;
- struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
- uint32_t *lp = (uint32_t *) pcmd->virt;
- struct serv_parm *sp = (struct serv_parm *) (lp + 1);
- struct ls_rjt stat;
- int port_cmp;
- memset(&stat, 0, sizeof (struct ls_rjt));
- /* For a PLOGI, we only accept if our portname is less
- * than the remote portname.
- */
- phba->fc_stat.elsLogiCol++;
- port_cmp = memcmp(&vport->fc_portname, &sp->portName,
- sizeof(struct lpfc_name));
- if (port_cmp >= 0) {
- /* Reject this request because the remote node will accept
- ours */
- stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
- NULL);
- } else {
- if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
- (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
- (vport->num_disc_nodes)) {
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
- spin_unlock_irq(&ndlp->lock);
- /* Check if there are more PLOGIs to be sent */
- lpfc_more_plogi(vport);
- if (vport->num_disc_nodes == 0) {
- spin_lock_irq(shost->host_lock);
- vport->fc_flag &= ~FC_NDISC_ACTIVE;
- spin_unlock_irq(shost->host_lock);
- lpfc_can_disctmo(vport);
- lpfc_end_rscn(vport);
- }
- }
- } /* If our portname was less */
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- struct ls_rjt stat;
- memset(&stat, 0, sizeof (struct ls_rjt));
- stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
- if (vport->phba->sli_rev == LPFC_SLI_REV3)
- ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag;
- /* software abort outstanding PLOGI */
- lpfc_els_abort(vport->phba, ndlp);
- lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- /* software abort outstanding PLOGI */
- lpfc_els_abort(phba, ndlp);
- if (evt == NLP_EVT_RCV_LOGO) {
- lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
- } else {
- lpfc_issue_els_logo(vport, ndlp, 0);
- }
- /* Put ndlp in npr state set plogi timer for 1 sec */
- mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1));
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_DELAY_TMO;
- spin_unlock_irq(&ndlp->lock);
- ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
- ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocb, *rspiocb;
- struct lpfc_dmabuf *pcmd, *prsp;
- uint32_t *lp;
- uint32_t vid, flag;
- struct serv_parm *sp;
- uint32_t ed_tov;
- LPFC_MBOXQ_t *mbox;
- int rc;
- u32 ulp_status;
- u32 did;
- cmdiocb = (struct lpfc_iocbq *) arg;
- rspiocb = cmdiocb->rsp_iocb;
- ulp_status = get_job_ulpstatus(phba, rspiocb);
- if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
- /* Recovery from PLOGI collision logic */
- return ndlp->nlp_state;
- }
- if (ulp_status)
- goto out;
- pcmd = cmdiocb->cmd_dmabuf;
- prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
- if (!prsp)
- goto out;
- lp = (uint32_t *) prsp->virt;
- sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
- /* Some switches have FDMI servers returning 0 for WWN */
- if ((ndlp->nlp_DID != FDMI_DID) &&
- (wwn_to_u64(sp->portName.u.wwn) == 0 ||
- wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0142 PLOGI RSP: Invalid WWN.\n");
- goto out;
- }
- if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
- goto out;
- /* PLOGI chkparm OK */
- lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
- "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
- ndlp->nlp_DID, ndlp->nlp_state,
- ndlp->nlp_flag, ndlp->nlp_rpi);
- if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
- ndlp->nlp_fcp_info |= CLASS2;
- else
- ndlp->nlp_fcp_info |= CLASS3;
- ndlp->nlp_class_sup = 0;
- if (sp->cls1.classValid)
- ndlp->nlp_class_sup |= FC_COS_CLASS1;
- if (sp->cls2.classValid)
- ndlp->nlp_class_sup |= FC_COS_CLASS2;
- if (sp->cls3.classValid)
- ndlp->nlp_class_sup |= FC_COS_CLASS3;
- if (sp->cls4.classValid)
- ndlp->nlp_class_sup |= FC_COS_CLASS4;
- ndlp->nlp_maxframe =
- ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
- if ((vport->fc_flag & FC_PT2PT) &&
- (vport->fc_flag & FC_PT2PT_PLOGI)) {
- ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
- if (sp->cmn.edtovResolution) {
- /* E_D_TOV ticks are in nanoseconds */
- ed_tov = (phba->fc_edtov + 999999) / 1000000;
- }
- ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP;
- if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) &&
- sp->cmn.valid_vendor_ver_level) {
- vid = be32_to_cpu(sp->un.vv.vid);
- flag = be32_to_cpu(sp->un.vv.flags);
- if ((vid == LPFC_VV_EMLX_ID) &&
- (flag & LPFC_VV_SUPPRESS_RSP))
- ndlp->nlp_flag |= NLP_SUPPRESS_RSP;
- }
- /*
- * Use the larger EDTOV
- * RATOV = 2 * EDTOV for pt-to-pt
- */
- if (ed_tov > phba->fc_edtov)
- phba->fc_edtov = ed_tov;
- phba->fc_ratov = (2 * phba->fc_edtov) / 1000;
- memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
- /* Issue config_link / reg_vfi to account for updated TOV's */
- if (phba->sli_rev == LPFC_SLI_REV4) {
- lpfc_issue_reg_vfi(vport);
- } else {
- mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!mbox) {
- lpfc_printf_vlog(vport, KERN_ERR,
- LOG_TRACE_EVENT,
- "0133 PLOGI: no memory "
- "for config_link "
- "Data: x%x x%x x%x x%x\n",
- ndlp->nlp_DID, ndlp->nlp_state,
- ndlp->nlp_flag, ndlp->nlp_rpi);
- goto out;
- }
- lpfc_config_link(phba, mbox);
- mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
- mbox->vport = vport;
- rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
- if (rc == MBX_NOT_FINISHED) {
- mempool_free(mbox, phba->mbox_mem_pool);
- goto out;
- }
- }
- }
- lpfc_unreg_rpi(vport, ndlp);
- mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!mbox) {
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0018 PLOGI: no memory for reg_login "
- "Data: x%x x%x x%x x%x\n",
- ndlp->nlp_DID, ndlp->nlp_state,
- ndlp->nlp_flag, ndlp->nlp_rpi);
- goto out;
- }
- did = get_job_els_rsp64_did(phba, cmdiocb);
- if (lpfc_reg_rpi(phba, vport->vpi, did,
- (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) {
- switch (ndlp->nlp_DID) {
- case NameServer_DID:
- mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
- /* Fabric Controller Node needs these parameters. */
- memcpy(&ndlp->fc_sparam, sp, sizeof(struct serv_parm));
- break;
- case FDMI_DID:
- mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
- break;
- default:
- ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
- mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
- }
- mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
- if (!mbox->ctx_ndlp)
- goto out;
- mbox->vport = vport;
- if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
- != MBX_NOT_FINISHED) {
- lpfc_nlp_set_state(vport, ndlp,
- NLP_STE_REG_LOGIN_ISSUE);
- return ndlp->nlp_state;
- }
- if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
- ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
- /* decrement node reference count to the failed mbox
- * command
- */
- lpfc_nlp_put(ndlp);
- lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0134 PLOGI: cannot issue reg_login "
- "Data: x%x x%x x%x x%x\n",
- ndlp->nlp_DID, ndlp->nlp_state,
- ndlp->nlp_flag, ndlp->nlp_rpi);
- } else {
- mempool_free(mbox, phba->mbox_mem_pool);
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0135 PLOGI: cannot format reg_login "
- "Data: x%x x%x x%x x%x\n",
- ndlp->nlp_DID, ndlp->nlp_state,
- ndlp->nlp_flag, ndlp->nlp_rpi);
- }
- out:
- if (ndlp->nlp_DID == NameServer_DID) {
- lpfc_vport_set_state(vport, FC_VPORT_FAILED);
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0261 Cannot Register NameServer login\n");
- }
- /*
- ** In case the node reference counter does not go to zero, ensure that
- ** the stale state for the node is not processed.
- */
- ndlp->nlp_prev_state = ndlp->nlp_state;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- return NLP_STE_FREED_NODE;
- }
- static uint32_t
- lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
- {
- struct lpfc_hba *phba;
- LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
- MAILBOX_t *mb = &pmb->u.mb;
- uint16_t rpi;
- phba = vport->phba;
- /* Release the RPI */
- if (!(phba->pport->load_flag & FC_UNLOADING) &&
- !mb->mbxStatus) {
- rpi = pmb->u.mb.un.varWords[0];
- lpfc_release_rpi(phba, vport, ndlp, rpi);
- }
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_NODEV_REMOVE;
- spin_unlock_irq(&ndlp->lock);
- return ndlp->nlp_state;
- } else {
- /* software abort outstanding PLOGI */
- lpfc_els_abort(vport->phba, ndlp);
- lpfc_drop_node(vport, ndlp);
- return NLP_STE_FREED_NODE;
- }
- }
- static uint32_t
- lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- /* Don't do anything that will mess up processing of the
- * previous RSCN.
- */
- if (vport->fc_flag & FC_RSCN_DEFERRED)
- return ndlp->nlp_state;
- /* software abort outstanding PLOGI */
- lpfc_els_abort(phba, ndlp);
- ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
- spin_unlock_irq(&ndlp->lock);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocb;
- /* software abort outstanding ADISC */
- lpfc_els_abort(phba, ndlp);
- cmdiocb = (struct lpfc_iocbq *) arg;
- if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
- if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
- spin_unlock_irq(&ndlp->lock);
- if (vport->num_disc_nodes)
- lpfc_more_adisc(vport);
- }
- return ndlp->nlp_state;
- }
- ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
- lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
- lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocb;
- cmdiocb = (struct lpfc_iocbq *) arg;
- /* software abort outstanding ADISC */
- lpfc_els_abort(phba, ndlp);
- lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb;
- cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_padisc(vport, ndlp, cmdiocb);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb;
- cmdiocb = (struct lpfc_iocbq *) arg;
- /* Treat like rcv logo */
- lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocb, *rspiocb;
- ADISC *ap;
- int rc;
- u32 ulp_status;
- cmdiocb = (struct lpfc_iocbq *) arg;
- rspiocb = cmdiocb->rsp_iocb;
- ulp_status = get_job_ulpstatus(phba, rspiocb);
- ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
- if ((ulp_status) ||
- (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
- /* 1 sec timeout */
- mod_timer(&ndlp->nlp_delayfunc,
- jiffies + msecs_to_jiffies(1000));
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_DELAY_TMO;
- spin_unlock_irq(&ndlp->lock);
- ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
- ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- lpfc_unreg_rpi(vport, ndlp);
- return ndlp->nlp_state;
- }
- if (phba->sli_rev == LPFC_SLI_REV4) {
- rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL);
- if (rc) {
- /* Stay in state and retry. */
- ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
- return ndlp->nlp_state;
- }
- }
- if (ndlp->nlp_type & NLP_FCP_TARGET)
- ndlp->nlp_fc4_type |= NLP_FC4_FCP;
- if (ndlp->nlp_type & NLP_NVME_TARGET)
- ndlp->nlp_fc4_type |= NLP_FC4_NVME;
- if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) {
- ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
- } else {
- ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
- }
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_NODEV_REMOVE;
- spin_unlock_irq(&ndlp->lock);
- return ndlp->nlp_state;
- } else {
- /* software abort outstanding ADISC */
- lpfc_els_abort(vport->phba, ndlp);
- lpfc_drop_node(vport, ndlp);
- return NLP_STE_FREED_NODE;
- }
- }
- static uint32_t
- lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- /* Don't do anything that will mess up processing of the
- * previous RSCN.
- */
- if (vport->fc_flag & FC_RSCN_DEFERRED)
- return ndlp->nlp_state;
- /* software abort outstanding ADISC */
- lpfc_els_abort(phba, ndlp);
- ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
- spin_unlock_irq(&ndlp->lock);
- lpfc_disc_set_adisc(vport, ndlp);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_plogi(vport, ndlp, cmdiocb);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- struct ls_rjt stat;
- if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) {
- return ndlp->nlp_state;
- }
- if (vport->phba->nvmet_support) {
- /* NVME Target mode. Handle and respond to the PRLI and
- * transition to UNMAPPED provided the RPI has completed
- * registration.
- */
- if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
- lpfc_rcv_prli(vport, ndlp, cmdiocb);
- lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
- } else {
- /* RPI registration has not completed. Reject the PRLI
- * to prevent an illegal state transition when the
- * rpi registration does complete.
- */
- memset(&stat, 0, sizeof(struct ls_rjt));
- stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
- ndlp, NULL);
- return ndlp->nlp_state;
- }
- } else {
- /* Initiator mode. */
- lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
- }
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- LPFC_MBOXQ_t *mb;
- LPFC_MBOXQ_t *nextmb;
- struct lpfc_nodelist *ns_ndlp;
- cmdiocb = (struct lpfc_iocbq *) arg;
- /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
- if ((mb = phba->sli.mbox_active)) {
- if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
- (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
- ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
- lpfc_nlp_put(ndlp);
- mb->ctx_ndlp = NULL;
- mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
- }
- }
- spin_lock_irq(&phba->hbalock);
- list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
- if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
- (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
- ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
- lpfc_nlp_put(ndlp);
- list_del(&mb->list);
- phba->sli.mboxq_cnt--;
- lpfc_mbox_rsrc_cleanup(phba, mb, MBOX_THD_LOCKED);
- }
- }
- spin_unlock_irq(&phba->hbalock);
- /* software abort if any GID_FT is outstanding */
- if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
- ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
- if (ns_ndlp)
- lpfc_els_abort(phba, ns_ndlp);
- }
- lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_padisc(vport, ndlp, cmdiocb);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb;
- cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
- MAILBOX_t *mb = &pmb->u.mb;
- uint32_t did = mb->un.varWords[1];
- if (mb->mbxStatus) {
- /* RegLogin failed */
- lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
- "0246 RegLogin failed Data: x%x x%x x%x x%x "
- "x%x\n",
- did, mb->mbxStatus, vport->port_state,
- mb->un.varRegLogin.vpi,
- mb->un.varRegLogin.rpi);
- /*
- * If RegLogin failed due to lack of HBA resources do not
- * retry discovery.
- */
- if (mb->mbxStatus == MBXERR_RPI_FULL) {
- ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- return ndlp->nlp_state;
- }
- /* Put ndlp in npr state set plogi timer for 1 sec */
- mod_timer(&ndlp->nlp_delayfunc,
- jiffies + msecs_to_jiffies(1000 * 1));
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_DELAY_TMO;
- spin_unlock_irq(&ndlp->lock);
- ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
- lpfc_issue_els_logo(vport, ndlp, 0);
- return ndlp->nlp_state;
- }
- /* SLI4 ports have preallocated logical rpis. */
- if (phba->sli_rev < LPFC_SLI_REV4)
- ndlp->nlp_rpi = mb->un.varWords[0];
- ndlp->nlp_flag |= NLP_RPI_REGISTERED;
- /* Only if we are not a fabric nport do we issue PRLI */
- lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
- "3066 RegLogin Complete on x%x x%x x%x\n",
- did, ndlp->nlp_type, ndlp->nlp_fc4_type);
- if (!(ndlp->nlp_type & NLP_FABRIC) &&
- (phba->nvmet_support == 0)) {
- /* The driver supports FCP and NVME concurrently. If the
- * ndlp's nlp_fc4_type is still zero, the driver doesn't
- * know what PRLI to send yet. Figure that out now and
- * call PRLI depending on the outcome.
- */
- if (vport->fc_flag & FC_PT2PT) {
- /* If we are pt2pt, there is no Fabric to determine
- * the FC4 type of the remote nport. So if NVME
- * is configured try it.
- */
- ndlp->nlp_fc4_type |= NLP_FC4_FCP;
- if ((!(vport->fc_flag & FC_PT2PT_NO_NVME)) &&
- (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
- vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
- ndlp->nlp_fc4_type |= NLP_FC4_NVME;
- /* We need to update the localport also */
- lpfc_nvme_update_localport(vport);
- }
- } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
- ndlp->nlp_fc4_type |= NLP_FC4_FCP;
- } else if (ndlp->nlp_fc4_type == 0) {
- /* If we are only configured for FCP, the driver
- * should just issue PRLI for FCP. Otherwise issue
- * GFT_ID to determine if remote port supports NVME.
- */
- if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) {
- lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0,
- ndlp->nlp_DID);
- return ndlp->nlp_state;
- }
- ndlp->nlp_fc4_type = NLP_FC4_FCP;
- }
- ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
- if (lpfc_issue_els_prli(vport, ndlp, 0)) {
- lpfc_issue_els_logo(vport, ndlp, 0);
- ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- }
- } else {
- if ((vport->fc_flag & FC_PT2PT) && phba->nvmet_support)
- phba->targetport->port_id = vport->fc_myDID;
- /* Only Fabric ports should transition. NVME target
- * must complete PRLI.
- */
- if (ndlp->nlp_type & NLP_FABRIC) {
- ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
- ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
- }
- }
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_NODEV_REMOVE;
- spin_unlock_irq(&ndlp->lock);
- return ndlp->nlp_state;
- } else {
- lpfc_drop_node(vport, ndlp);
- return NLP_STE_FREED_NODE;
- }
- }
- static uint32_t
- lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- /* Don't do anything that will mess up processing of the
- * previous RSCN.
- */
- if (vport->fc_flag & FC_RSCN_DEFERRED)
- return ndlp->nlp_state;
- ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- spin_lock_irq(&ndlp->lock);
- /* If we are a target we won't immediately transition into PRLI,
- * so if REG_LOGIN already completed we don't need to ignore it.
- */
- if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) ||
- !vport->phba->nvmet_support)
- ndlp->nlp_flag |= NLP_IGNR_REG_CMPL;
- ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
- spin_unlock_irq(&ndlp->lock);
- lpfc_disc_set_adisc(vport, ndlp);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb;
- cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_plogi(vport, ndlp, cmdiocb);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
- return ndlp->nlp_state;
- lpfc_rcv_prli(vport, ndlp, cmdiocb);
- lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- /* Software abort outstanding PRLI before sending acc */
- lpfc_els_abort(vport->phba, ndlp);
- lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_padisc(vport, ndlp, cmdiocb);
- return ndlp->nlp_state;
- }
- /* This routine is envoked when we rcv a PRLO request from a nport
- * we are logged into. We should send back a PRLO rsp setting the
- * appropriate bits.
- * NEXT STATE = PRLI_ISSUE
- */
- static uint32_t
- lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb, *rspiocb;
- struct lpfc_hba *phba = vport->phba;
- PRLI *npr;
- struct lpfc_nvme_prli *nvpr;
- void *temp_ptr;
- u32 ulp_status;
- cmdiocb = (struct lpfc_iocbq *) arg;
- rspiocb = cmdiocb->rsp_iocb;
- ulp_status = get_job_ulpstatus(phba, rspiocb);
- /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
- * format is different so NULL the two PRLI types so that the
- * driver correctly gets the correct context.
- */
- npr = NULL;
- nvpr = NULL;
- temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
- if (cmdiocb->cmd_flag & LPFC_PRLI_FCP_REQ)
- npr = (PRLI *) temp_ptr;
- else if (cmdiocb->cmd_flag & LPFC_PRLI_NVME_REQ)
- nvpr = (struct lpfc_nvme_prli *) temp_ptr;
- if (ulp_status) {
- if ((vport->port_type == LPFC_NPIV_PORT) &&
- vport->cfg_restrict_login) {
- goto out;
- }
- /* Adjust the nlp_type accordingly if the PRLI failed */
- if (npr)
- ndlp->nlp_fc4_type &= ~NLP_FC4_FCP;
- if (nvpr)
- ndlp->nlp_fc4_type &= ~NLP_FC4_NVME;
- /* We can't set the DSM state till BOTH PRLIs complete */
- goto out_err;
- }
- if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
- (npr->prliType == PRLI_FCP_TYPE)) {
- lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
- "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
- npr->initiatorFunc,
- npr->targetFunc);
- if (npr->initiatorFunc)
- ndlp->nlp_type |= NLP_FCP_INITIATOR;
- if (npr->targetFunc) {
- ndlp->nlp_type |= NLP_FCP_TARGET;
- if (npr->writeXferRdyDis)
- ndlp->nlp_flag |= NLP_FIRSTBURST;
- }
- if (npr->Retry)
- ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
- } else if (nvpr &&
- (bf_get_be32(prli_acc_rsp_code, nvpr) ==
- PRLI_REQ_EXECUTED) &&
- (bf_get_be32(prli_type_code, nvpr) ==
- PRLI_NVME_TYPE)) {
- /* Complete setting up the remote ndlp personality. */
- if (bf_get_be32(prli_init, nvpr))
- ndlp->nlp_type |= NLP_NVME_INITIATOR;
- if (phba->nsler && bf_get_be32(prli_nsler, nvpr) &&
- bf_get_be32(prli_conf, nvpr))
- ndlp->nlp_nvme_info |= NLP_NVME_NSLER;
- else
- ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER;
- /* Target driver cannot solicit NVME FB. */
- if (bf_get_be32(prli_tgt, nvpr)) {
- /* Complete the nvme target roles. The transport
- * needs to know if the rport is capable of
- * discovery in addition to its role.
- */
- ndlp->nlp_type |= NLP_NVME_TARGET;
- if (bf_get_be32(prli_disc, nvpr))
- ndlp->nlp_type |= NLP_NVME_DISCOVERY;
- /*
- * If prli_fba is set, the Target supports FirstBurst.
- * If prli_fb_sz is 0, the FirstBurst size is unlimited,
- * otherwise it defines the actual size supported by
- * the NVME Target.
- */
- if ((bf_get_be32(prli_fba, nvpr) == 1) &&
- (phba->cfg_nvme_enable_fb) &&
- (!phba->nvmet_support)) {
- /* Both sides support FB. The target's first
- * burst size is a 512 byte encoded value.
- */
- ndlp->nlp_flag |= NLP_FIRSTBURST;
- ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz,
- nvpr);
- /* Expressed in units of 512 bytes */
- if (ndlp->nvme_fb_size)
- ndlp->nvme_fb_size <<=
- LPFC_NVME_FB_SHIFT;
- else
- ndlp->nvme_fb_size = LPFC_NVME_MAX_FB;
- }
- }
- lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
- "6029 NVME PRLI Cmpl w1 x%08x "
- "w4 x%08x w5 x%08x flag x%x, "
- "fcp_info x%x nlp_type x%x\n",
- be32_to_cpu(nvpr->word1),
- be32_to_cpu(nvpr->word4),
- be32_to_cpu(nvpr->word5),
- ndlp->nlp_flag, ndlp->nlp_fcp_info,
- ndlp->nlp_type);
- }
- if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
- (vport->port_type == LPFC_NPIV_PORT) &&
- vport->cfg_restrict_login) {
- out:
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_TARGET_REMOVE;
- spin_unlock_irq(&ndlp->lock);
- lpfc_issue_els_logo(vport, ndlp, 0);
- ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- return ndlp->nlp_state;
- }
- out_err:
- /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
- * are complete.
- */
- if (ndlp->fc4_prli_sent == 0) {
- ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
- if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET))
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
- else if (ndlp->nlp_type &
- (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR))
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
- } else
- lpfc_printf_vlog(vport,
- KERN_INFO, LOG_ELS,
- "3067 PRLI's still outstanding "
- "on x%06x - count %d, Pend Node Mode "
- "transition...\n",
- ndlp->nlp_DID, ndlp->fc4_prli_sent);
- return ndlp->nlp_state;
- }
- /*! lpfc_device_rm_prli_issue
- *
- * \pre
- * \post
- * \param phba
- * \param ndlp
- * \param arg
- * \param evt
- * \return uint32_t
- *
- * \b Description:
- * This routine is envoked when we a request to remove a nport we are in the
- * process of PRLIing. We should software abort outstanding prli, unreg
- * login, send a logout. We will change node state to UNUSED_NODE, put it
- * on plogi list so it can be freed when LOGO completes.
- *
- */
- static uint32_t
- lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_NODEV_REMOVE;
- spin_unlock_irq(&ndlp->lock);
- return ndlp->nlp_state;
- } else {
- /* software abort outstanding PLOGI */
- lpfc_els_abort(vport->phba, ndlp);
- lpfc_drop_node(vport, ndlp);
- return NLP_STE_FREED_NODE;
- }
- }
- /*! lpfc_device_recov_prli_issue
- *
- * \pre
- * \post
- * \param phba
- * \param ndlp
- * \param arg
- * \param evt
- * \return uint32_t
- *
- * \b Description:
- * The routine is envoked when the state of a device is unknown, like
- * during a link down. We should remove the nodelist entry from the
- * unmapped list, issue a UNREG_LOGIN, do a software abort of the
- * outstanding PRLI command, then free the node entry.
- */
- static uint32_t
- lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- /* Don't do anything that will mess up processing of the
- * previous RSCN.
- */
- if (vport->fc_flag & FC_RSCN_DEFERRED)
- return ndlp->nlp_state;
- /* software abort outstanding PRLI */
- lpfc_els_abort(phba, ndlp);
- ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
- spin_unlock_irq(&ndlp->lock);
- lpfc_disc_set_adisc(vport, ndlp);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
- struct ls_rjt stat;
- memset(&stat, 0, sizeof(struct ls_rjt));
- stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
- struct ls_rjt stat;
- memset(&stat, 0, sizeof(struct ls_rjt));
- stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_LOGO_ACC;
- spin_unlock_irq(&ndlp->lock);
- lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
- struct ls_rjt stat;
- memset(&stat, 0, sizeof(struct ls_rjt));
- stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg;
- struct ls_rjt stat;
- memset(&stat, 0, sizeof(struct ls_rjt));
- stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
- spin_unlock_irq(&ndlp->lock);
- lpfc_disc_set_adisc(vport, ndlp);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- /*
- * DevLoss has timed out and is calling for Device Remove.
- * In this case, abort the LOGO and cleanup the ndlp
- */
- lpfc_unreg_rpi(vport, ndlp);
- /* software abort outstanding PLOGI */
- lpfc_els_abort(vport->phba, ndlp);
- lpfc_drop_node(vport, ndlp);
- return NLP_STE_FREED_NODE;
- }
- static uint32_t
- lpfc_device_recov_logo_issue(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- /*
- * Device Recovery events have no meaning for a node with a LOGO
- * outstanding. The LOGO has to complete first and handle the
- * node from that point.
- */
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_plogi(vport, ndlp, cmdiocb);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
- return ndlp->nlp_state;
- lpfc_rcv_prli(vport, ndlp, cmdiocb);
- lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_padisc(vport, ndlp, cmdiocb);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_device_rm_unmap_node(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- lpfc_drop_node(vport, ndlp);
- return NLP_STE_FREED_NODE;
- }
- static uint32_t
- lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
- ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
- spin_unlock_irq(&ndlp->lock);
- lpfc_disc_set_adisc(vport, ndlp);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_plogi(vport, ndlp, cmdiocb);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb))
- return ndlp->nlp_state;
- lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_padisc(vport, ndlp, cmdiocb);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- /* flush the target */
- lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
- /* Treat like rcv logo */
- lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg,
- uint32_t evt)
- {
- lpfc_disc_set_adisc(vport, ndlp);
- ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
- ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
- spin_unlock_irq(&ndlp->lock);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- /* Ignore PLOGI if we have an outstanding LOGO */
- if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
- return ndlp->nlp_state;
- if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
- lpfc_cancel_retry_delay_tmo(vport, ndlp);
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
- spin_unlock_irq(&ndlp->lock);
- } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
- /* send PLOGI immediately, move to PLOGI issue state */
- if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
- ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
- lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
- }
- }
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- struct ls_rjt stat;
- memset(&stat, 0, sizeof (struct ls_rjt));
- stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
- stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
- lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
- if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
- /*
- * ADISC nodes will be handled in regular discovery path after
- * receiving response from NS.
- *
- * For other nodes, Send PLOGI to trigger an implicit LOGO.
- */
- if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
- ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
- lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
- }
- }
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- lpfc_rcv_padisc(vport, ndlp, cmdiocb);
- /*
- * Do not start discovery if discovery is about to start
- * or discovery in progress for this node. Starting discovery
- * here will affect the counting of discovery threads.
- */
- if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
- !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
- /*
- * ADISC nodes will be handled in regular discovery path after
- * receiving response from NS.
- *
- * For other nodes, Send PLOGI to trigger an implicit LOGO.
- */
- if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
- ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
- lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
- lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
- }
- }
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_LOGO_ACC;
- spin_unlock_irq(&ndlp->lock);
- lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
- if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
- mod_timer(&ndlp->nlp_delayfunc,
- jiffies + msecs_to_jiffies(1000 * 1));
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_DELAY_TMO;
- ndlp->nlp_flag &= ~NLP_NPR_ADISC;
- spin_unlock_irq(&ndlp->lock);
- ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
- } else {
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~NLP_NPR_ADISC;
- spin_unlock_irq(&ndlp->lock);
- }
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocb, *rspiocb;
- u32 ulp_status;
- cmdiocb = (struct lpfc_iocbq *) arg;
- rspiocb = cmdiocb->rsp_iocb;
- ulp_status = get_job_ulpstatus(phba, rspiocb);
- if (ulp_status)
- return NLP_STE_FREED_NODE;
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocb, *rspiocb;
- u32 ulp_status;
- cmdiocb = (struct lpfc_iocbq *) arg;
- rspiocb = cmdiocb->rsp_iocb;
- ulp_status = get_job_ulpstatus(phba, rspiocb);
- if (ulp_status && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
- lpfc_drop_node(vport, ndlp);
- return NLP_STE_FREED_NODE;
- }
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
- /* For the fabric port just clear the fc flags. */
- if (ndlp->nlp_DID == Fabric_DID) {
- spin_lock_irq(shost->host_lock);
- vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
- spin_unlock_irq(shost->host_lock);
- }
- lpfc_unreg_rpi(vport, ndlp);
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocb, *rspiocb;
- u32 ulp_status;
- cmdiocb = (struct lpfc_iocbq *) arg;
- rspiocb = cmdiocb->rsp_iocb;
- ulp_status = get_job_ulpstatus(phba, rspiocb);
- if (ulp_status && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
- lpfc_drop_node(vport, ndlp);
- return NLP_STE_FREED_NODE;
- }
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
- struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
- MAILBOX_t *mb = &pmb->u.mb;
- if (!mb->mbxStatus) {
- /* SLI4 ports have preallocated logical rpis. */
- if (vport->phba->sli_rev < LPFC_SLI_REV4)
- ndlp->nlp_rpi = mb->un.varWords[0];
- ndlp->nlp_flag |= NLP_RPI_REGISTERED;
- if (ndlp->nlp_flag & NLP_LOGO_ACC) {
- lpfc_unreg_rpi(vport, ndlp);
- }
- } else {
- if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
- lpfc_drop_node(vport, ndlp);
- return NLP_STE_FREED_NODE;
- }
- }
- return ndlp->nlp_state;
- }
- static uint32_t
- lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag |= NLP_NODEV_REMOVE;
- spin_unlock_irq(&ndlp->lock);
- return ndlp->nlp_state;
- }
- lpfc_drop_node(vport, ndlp);
- return NLP_STE_FREED_NODE;
- }
- static uint32_t
- lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- /* Don't do anything that will mess up processing of the
- * previous RSCN.
- */
- if (vport->fc_flag & FC_RSCN_DEFERRED)
- return ndlp->nlp_state;
- lpfc_cancel_retry_delay_tmo(vport, ndlp);
- spin_lock_irq(&ndlp->lock);
- ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
- ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
- spin_unlock_irq(&ndlp->lock);
- return ndlp->nlp_state;
- }
- /* This next section defines the NPort Discovery State Machine */
- /* There are 4 different double linked lists nodelist entries can reside on.
- * The plogi list and adisc list are used when Link Up discovery or RSCN
- * processing is needed. Each list holds the nodes that we will send PLOGI
- * or ADISC on. These lists will keep track of what nodes will be effected
- * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
- * The unmapped_list will contain all nodes that we have successfully logged
- * into at the Fibre Channel level. The mapped_list will contain all nodes
- * that are mapped FCP targets.
- */
- /*
- * The bind list is a list of undiscovered (potentially non-existent) nodes
- * that we have saved binding information on. This information is used when
- * nodes transition from the unmapped to the mapped list.
- */
- /* For UNUSED_NODE state, the node has just been allocated .
- * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
- * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
- * and put on the unmapped list. For ADISC processing, the node is taken off
- * the ADISC list and placed on either the mapped or unmapped list (depending
- * on its previous state). Once on the unmapped list, a PRLI is issued and the
- * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
- * changed to UNMAPPED_NODE. If the completion indicates a mapped
- * node, the node is taken off the unmapped list. The binding list is checked
- * for a valid binding, or a binding is automatically assigned. If binding
- * assignment is unsuccessful, the node is left on the unmapped list. If
- * binding assignment is successful, the associated binding list entry (if
- * any) is removed, and the node is placed on the mapped list.
- */
- /*
- * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
- * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
- * expire, all effected nodes will receive a DEVICE_RM event.
- */
- /*
- * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
- * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
- * check, additional nodes may be added or removed (via DEVICE_RM) to / from
- * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
- * we will first process the ADISC list. 32 entries are processed initially and
- * ADISC is initited for each one. Completions / Events for each node are
- * funnelled thru the state machine. As each node finishes ADISC processing, it
- * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
- * waiting, and the ADISC list count is identically 0, then we are done. For
- * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
- * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
- * list. 32 entries are processed initially and PLOGI is initited for each one.
- * Completions / Events for each node are funnelled thru the state machine. As
- * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
- * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
- * indentically 0, then we are done. We have now completed discovery / RSCN
- * handling. Upon completion, ALL nodes should be on either the mapped or
- * unmapped lists.
- */
- static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
- (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
- /* Action routine Event Current State */
- lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
- lpfc_rcv_els_unused_node, /* RCV_PRLI */
- lpfc_rcv_logo_unused_node, /* RCV_LOGO */
- lpfc_rcv_els_unused_node, /* RCV_ADISC */
- lpfc_rcv_els_unused_node, /* RCV_PDISC */
- lpfc_rcv_els_unused_node, /* RCV_PRLO */
- lpfc_disc_illegal, /* CMPL_PLOGI */
- lpfc_disc_illegal, /* CMPL_PRLI */
- lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
- lpfc_disc_illegal, /* CMPL_ADISC */
- lpfc_disc_illegal, /* CMPL_REG_LOGIN */
- lpfc_device_rm_unused_node, /* DEVICE_RM */
- lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */
- lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
- lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
- lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
- lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
- lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
- lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
- lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
- lpfc_disc_illegal, /* CMPL_PRLI */
- lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
- lpfc_disc_illegal, /* CMPL_ADISC */
- lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
- lpfc_device_rm_plogi_issue, /* DEVICE_RM */
- lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
- lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
- lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
- lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
- lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
- lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
- lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
- lpfc_disc_illegal, /* CMPL_PLOGI */
- lpfc_disc_illegal, /* CMPL_PRLI */
- lpfc_disc_illegal, /* CMPL_LOGO */
- lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
- lpfc_disc_illegal, /* CMPL_REG_LOGIN */
- lpfc_device_rm_adisc_issue, /* DEVICE_RM */
- lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
- lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
- lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
- lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
- lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
- lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
- lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
- lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
- lpfc_disc_illegal, /* CMPL_PRLI */
- lpfc_disc_illegal, /* CMPL_LOGO */
- lpfc_disc_illegal, /* CMPL_ADISC */
- lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
- lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
- lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
- lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
- lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
- lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
- lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
- lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
- lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
- lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
- lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
- lpfc_disc_illegal, /* CMPL_LOGO */
- lpfc_disc_illegal, /* CMPL_ADISC */
- lpfc_disc_illegal, /* CMPL_REG_LOGIN */
- lpfc_device_rm_prli_issue, /* DEVICE_RM */
- lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
- lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */
- lpfc_rcv_prli_logo_issue, /* RCV_PRLI */
- lpfc_rcv_logo_logo_issue, /* RCV_LOGO */
- lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */
- lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */
- lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */
- lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
- lpfc_disc_illegal, /* CMPL_PRLI */
- lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */
- lpfc_disc_illegal, /* CMPL_ADISC */
- lpfc_disc_illegal, /* CMPL_REG_LOGIN */
- lpfc_device_rm_logo_issue, /* DEVICE_RM */
- lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */
- lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
- lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
- lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
- lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
- lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
- lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
- lpfc_disc_illegal, /* CMPL_PLOGI */
- lpfc_disc_illegal, /* CMPL_PRLI */
- lpfc_disc_illegal, /* CMPL_LOGO */
- lpfc_disc_illegal, /* CMPL_ADISC */
- lpfc_disc_illegal, /* CMPL_REG_LOGIN */
- lpfc_device_rm_unmap_node, /* DEVICE_RM */
- lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
- lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
- lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
- lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
- lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
- lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
- lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
- lpfc_disc_illegal, /* CMPL_PLOGI */
- lpfc_disc_illegal, /* CMPL_PRLI */
- lpfc_disc_illegal, /* CMPL_LOGO */
- lpfc_disc_illegal, /* CMPL_ADISC */
- lpfc_disc_illegal, /* CMPL_REG_LOGIN */
- lpfc_disc_illegal, /* DEVICE_RM */
- lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
- lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
- lpfc_rcv_prli_npr_node, /* RCV_PRLI */
- lpfc_rcv_logo_npr_node, /* RCV_LOGO */
- lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
- lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
- lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
- lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
- lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
- lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
- lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
- lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
- lpfc_device_rm_npr_node, /* DEVICE_RM */
- lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
- };
- int
- lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
- void *arg, uint32_t evt)
- {
- uint32_t cur_state, rc;
- uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
- uint32_t);
- uint32_t got_ndlp = 0;
- uint32_t data1;
- if (lpfc_nlp_get(ndlp))
- got_ndlp = 1;
- cur_state = ndlp->nlp_state;
- data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
- ((uint32_t)ndlp->nlp_type));
- /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
- lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
- "0211 DSM in event x%x on NPort x%x in "
- "state %d rpi x%x Data: x%x x%x\n",
- evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi,
- ndlp->nlp_flag, data1);
- lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
- "DSM in: evt:%d ste:%d did:x%x",
- evt, cur_state, ndlp->nlp_DID);
- func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
- rc = (func) (vport, ndlp, arg, evt);
- /* DSM out state <rc> on NPort <nlp_DID> */
- if (got_ndlp) {
- data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) |
- ((uint32_t)ndlp->nlp_type));
- lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
- "0212 DSM out state %d on NPort x%x "
- "rpi x%x Data: x%x x%x\n",
- rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag,
- data1);
- lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
- "DSM out: ste:%d did:x%x flg:x%x",
- rc, ndlp->nlp_DID, ndlp->nlp_flag);
- /* Decrement the ndlp reference count held for this function */
- lpfc_nlp_put(ndlp);
- } else {
- lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
- "0213 DSM out state %d on NPort free\n", rc);
- lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
- "DSM out: ste:%d did:x%x flg:x%x",
- rc, 0, 0);
- }
- return rc;
- }
|