lpfc_ct.c 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * *
  10. * This program is free software; you can redistribute it and/or *
  11. * modify it under the terms of version 2 of the GNU General *
  12. * Public License as published by the Free Software Foundation. *
  13. * This program is distributed in the hope that it will be useful. *
  14. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  15. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  16. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  17. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  18. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  19. * more details, a copy of which can be found in the file COPYING *
  20. * included with this package. *
  21. *******************************************************************/
  22. /*
  23. * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
  24. */
  25. #include <linux/blkdev.h>
  26. #include <linux/pci.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/slab.h>
  29. #include <linux/utsname.h>
  30. #include <scsi/scsi.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include <scsi/fc/fc_fs.h>
  35. #include "lpfc_hw4.h"
  36. #include "lpfc_hw.h"
  37. #include "lpfc_sli.h"
  38. #include "lpfc_sli4.h"
  39. #include "lpfc_nl.h"
  40. #include "lpfc_disc.h"
  41. #include "lpfc.h"
  42. #include "lpfc_scsi.h"
  43. #include "lpfc_logmsg.h"
  44. #include "lpfc_crtn.h"
  45. #include "lpfc_version.h"
  46. #include "lpfc_vport.h"
  47. #include "lpfc_debugfs.h"
  48. /* FDMI Port Speed definitions - FC-GS-7 */
  49. #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
  50. #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
  51. #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
  52. #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
  53. #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
  54. #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
  55. #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
  56. #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
  57. #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
  58. #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
  59. #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
  60. #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
  61. #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
  62. #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
  63. #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
  64. #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
  65. #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
  66. #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
  67. #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
  68. #define FOURBYTES 4
  69. static char *lpfc_release_version = LPFC_DRIVER_VERSION;
  70. static void
  71. lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  72. struct lpfc_iocbq *rspiocb);
  73. static void
  74. lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  75. struct lpfc_dmabuf *mp, uint32_t size)
  76. {
  77. if (!mp) {
  78. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  79. "0146 Ignoring unsolicited CT No HBQ "
  80. "status = x%x\n",
  81. get_job_ulpstatus(phba, piocbq));
  82. }
  83. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  84. "0145 Ignoring unsolicited CT HBQ Size:%d "
  85. "status = x%x\n",
  86. size, get_job_ulpstatus(phba, piocbq));
  87. }
  88. static void
  89. lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  90. struct lpfc_dmabuf *mp, uint32_t size)
  91. {
  92. lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
  93. }
  94. /**
  95. * lpfc_ct_unsol_cmpl : Completion callback function for unsol ct commands
  96. * @phba : pointer to lpfc hba data structure.
  97. * @cmdiocb : pointer to lpfc command iocb data structure.
  98. * @rspiocb : pointer to lpfc response iocb data structure.
  99. *
  100. * This routine is the callback function for issuing unsol ct reject command.
  101. * The memory allocated in the reject command path is freed up here.
  102. **/
  103. static void
  104. lpfc_ct_unsol_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  105. struct lpfc_iocbq *rspiocb)
  106. {
  107. struct lpfc_nodelist *ndlp;
  108. struct lpfc_dmabuf *mp, *bmp;
  109. ndlp = cmdiocb->ndlp;
  110. if (ndlp)
  111. lpfc_nlp_put(ndlp);
  112. mp = cmdiocb->rsp_dmabuf;
  113. bmp = cmdiocb->bpl_dmabuf;
  114. if (mp) {
  115. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  116. kfree(mp);
  117. cmdiocb->rsp_dmabuf = NULL;
  118. }
  119. if (bmp) {
  120. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  121. kfree(bmp);
  122. cmdiocb->bpl_dmabuf = NULL;
  123. }
  124. lpfc_sli_release_iocbq(phba, cmdiocb);
  125. }
  126. /**
  127. * lpfc_ct_reject_event - Issue reject for unhandled CT MIB commands
  128. * @ndlp: pointer to a node-list data structure.
  129. * @ct_req: pointer to the CT request data structure.
  130. * @ulp_context: context of received UNSOL CT command
  131. * @ox_id: ox_id of the UNSOL CT command
  132. *
  133. * This routine is invoked by the lpfc_ct_handle_mibreq routine for sending
  134. * a reject response. Reject response is sent for the unhandled commands.
  135. **/
  136. static void
  137. lpfc_ct_reject_event(struct lpfc_nodelist *ndlp,
  138. struct lpfc_sli_ct_request *ct_req,
  139. u16 ulp_context, u16 ox_id)
  140. {
  141. struct lpfc_vport *vport = ndlp->vport;
  142. struct lpfc_hba *phba = vport->phba;
  143. struct lpfc_sli_ct_request *ct_rsp;
  144. struct lpfc_iocbq *cmdiocbq = NULL;
  145. struct lpfc_dmabuf *bmp = NULL;
  146. struct lpfc_dmabuf *mp = NULL;
  147. struct ulp_bde64 *bpl;
  148. u8 rc = 0;
  149. u32 tmo;
  150. /* fill in BDEs for command */
  151. mp = kmalloc(sizeof(*mp), GFP_KERNEL);
  152. if (!mp) {
  153. rc = 1;
  154. goto ct_exit;
  155. }
  156. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp->phys);
  157. if (!mp->virt) {
  158. rc = 2;
  159. goto ct_free_mp;
  160. }
  161. /* Allocate buffer for Buffer ptr list */
  162. bmp = kmalloc(sizeof(*bmp), GFP_KERNEL);
  163. if (!bmp) {
  164. rc = 3;
  165. goto ct_free_mpvirt;
  166. }
  167. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &bmp->phys);
  168. if (!bmp->virt) {
  169. rc = 4;
  170. goto ct_free_bmp;
  171. }
  172. INIT_LIST_HEAD(&mp->list);
  173. INIT_LIST_HEAD(&bmp->list);
  174. bpl = (struct ulp_bde64 *)bmp->virt;
  175. memset(bpl, 0, sizeof(struct ulp_bde64));
  176. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
  177. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
  178. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  179. bpl->tus.f.bdeSize = (LPFC_CT_PREAMBLE - 4);
  180. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  181. ct_rsp = (struct lpfc_sli_ct_request *)mp->virt;
  182. memset(ct_rsp, 0, sizeof(struct lpfc_sli_ct_request));
  183. ct_rsp->RevisionId.bits.Revision = SLI_CT_REVISION;
  184. ct_rsp->RevisionId.bits.InId = 0;
  185. ct_rsp->FsType = ct_req->FsType;
  186. ct_rsp->FsSubType = ct_req->FsSubType;
  187. ct_rsp->CommandResponse.bits.Size = 0;
  188. ct_rsp->CommandResponse.bits.CmdRsp =
  189. cpu_to_be16(SLI_CT_RESPONSE_FS_RJT);
  190. ct_rsp->ReasonCode = SLI_CT_REQ_NOT_SUPPORTED;
  191. ct_rsp->Explanation = SLI_CT_NO_ADDITIONAL_EXPL;
  192. cmdiocbq = lpfc_sli_get_iocbq(phba);
  193. if (!cmdiocbq) {
  194. rc = 5;
  195. goto ct_free_bmpvirt;
  196. }
  197. if (phba->sli_rev == LPFC_SLI_REV4) {
  198. lpfc_sli_prep_xmit_seq64(phba, cmdiocbq, bmp,
  199. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
  200. ox_id, 1, FC_RCTL_DD_SOL_CTL, 1,
  201. CMD_XMIT_SEQUENCE64_WQE);
  202. } else {
  203. lpfc_sli_prep_xmit_seq64(phba, cmdiocbq, bmp, 0, ulp_context, 1,
  204. FC_RCTL_DD_SOL_CTL, 1,
  205. CMD_XMIT_SEQUENCE64_CX);
  206. }
  207. /* Save for completion so we can release these resources */
  208. cmdiocbq->rsp_dmabuf = mp;
  209. cmdiocbq->bpl_dmabuf = bmp;
  210. cmdiocbq->cmd_cmpl = lpfc_ct_unsol_cmpl;
  211. tmo = (3 * phba->fc_ratov);
  212. cmdiocbq->retry = 0;
  213. cmdiocbq->vport = vport;
  214. cmdiocbq->drvrTimeout = tmo + LPFC_DRVR_TIMEOUT;
  215. cmdiocbq->ndlp = lpfc_nlp_get(ndlp);
  216. if (!cmdiocbq->ndlp)
  217. goto ct_no_ndlp;
  218. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
  219. if (rc) {
  220. lpfc_nlp_put(ndlp);
  221. goto ct_no_ndlp;
  222. }
  223. return;
  224. ct_no_ndlp:
  225. rc = 6;
  226. lpfc_sli_release_iocbq(phba, cmdiocbq);
  227. ct_free_bmpvirt:
  228. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  229. ct_free_bmp:
  230. kfree(bmp);
  231. ct_free_mpvirt:
  232. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  233. ct_free_mp:
  234. kfree(mp);
  235. ct_exit:
  236. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  237. "6440 Unsol CT: Rsp err %d Data: x%x\n",
  238. rc, vport->fc_flag);
  239. }
  240. /**
  241. * lpfc_ct_handle_mibreq - Process an unsolicited CT MIB request data buffer
  242. * @phba: pointer to lpfc hba data structure.
  243. * @ctiocbq: pointer to lpfc CT command iocb data structure.
  244. *
  245. * This routine is used for processing the IOCB associated with a unsolicited
  246. * CT MIB request. It first determines whether there is an existing ndlp that
  247. * matches the DID from the unsolicited IOCB. If not, it will return.
  248. **/
  249. static void
  250. lpfc_ct_handle_mibreq(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocbq)
  251. {
  252. struct lpfc_sli_ct_request *ct_req;
  253. struct lpfc_nodelist *ndlp = NULL;
  254. struct lpfc_vport *vport = ctiocbq->vport;
  255. u32 ulp_status = get_job_ulpstatus(phba, ctiocbq);
  256. u32 ulp_word4 = get_job_word4(phba, ctiocbq);
  257. u32 did;
  258. u32 mi_cmd;
  259. did = bf_get(els_rsp64_sid, &ctiocbq->wqe.xmit_els_rsp);
  260. if (ulp_status) {
  261. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  262. "6438 Unsol CT: status:x%x/x%x did : x%x\n",
  263. ulp_status, ulp_word4, did);
  264. return;
  265. }
  266. /* Ignore traffic received during vport shutdown */
  267. if (vport->fc_flag & FC_UNLOADING)
  268. return;
  269. ndlp = lpfc_findnode_did(vport, did);
  270. if (!ndlp) {
  271. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  272. "6439 Unsol CT: NDLP Not Found for DID : x%x",
  273. did);
  274. return;
  275. }
  276. ct_req = (struct lpfc_sli_ct_request *)ctiocbq->cmd_dmabuf->virt;
  277. mi_cmd = ct_req->CommandResponse.bits.CmdRsp;
  278. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  279. "6442 : MI Cmd : x%x Not Supported\n", mi_cmd);
  280. lpfc_ct_reject_event(ndlp, ct_req,
  281. bf_get(wqe_ctxt_tag,
  282. &ctiocbq->wqe.xmit_els_rsp.wqe_com),
  283. bf_get(wqe_rcvoxid,
  284. &ctiocbq->wqe.xmit_els_rsp.wqe_com));
  285. }
  286. /**
  287. * lpfc_ct_unsol_event - Process an unsolicited event from a ct sli ring
  288. * @phba: pointer to lpfc hba data structure.
  289. * @pring: pointer to a SLI ring.
  290. * @ctiocbq: pointer to lpfc ct iocb data structure.
  291. *
  292. * This routine is used to process an unsolicited event received from a SLI
  293. * (Service Level Interface) ring. The actual processing of the data buffer
  294. * associated with the unsolicited event is done by invoking appropriate routine
  295. * after properly set up the iocb buffer from the SLI ring on which the
  296. * unsolicited event was received.
  297. **/
  298. void
  299. lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  300. struct lpfc_iocbq *ctiocbq)
  301. {
  302. struct lpfc_dmabuf *mp = NULL;
  303. IOCB_t *icmd = &ctiocbq->iocb;
  304. int i;
  305. struct lpfc_iocbq *iocbq;
  306. struct lpfc_iocbq *iocb;
  307. dma_addr_t dma_addr;
  308. uint32_t size;
  309. struct list_head head;
  310. struct lpfc_sli_ct_request *ct_req;
  311. struct lpfc_dmabuf *bdeBuf1 = ctiocbq->cmd_dmabuf;
  312. struct lpfc_dmabuf *bdeBuf2 = ctiocbq->bpl_dmabuf;
  313. u32 status, parameter, bde_count = 0;
  314. struct lpfc_wcqe_complete *wcqe_cmpl = NULL;
  315. ctiocbq->cmd_dmabuf = NULL;
  316. ctiocbq->rsp_dmabuf = NULL;
  317. ctiocbq->bpl_dmabuf = NULL;
  318. wcqe_cmpl = &ctiocbq->wcqe_cmpl;
  319. status = get_job_ulpstatus(phba, ctiocbq);
  320. parameter = get_job_word4(phba, ctiocbq);
  321. if (phba->sli_rev == LPFC_SLI_REV4)
  322. bde_count = wcqe_cmpl->word3;
  323. else
  324. bde_count = icmd->ulpBdeCount;
  325. if (unlikely(status == IOSTAT_NEED_BUFFER)) {
  326. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  327. } else if ((status == IOSTAT_LOCAL_REJECT) &&
  328. ((parameter & IOERR_PARAM_MASK) ==
  329. IOERR_RCV_BUFFER_WAITING)) {
  330. /* Not enough posted buffers; Try posting more buffers */
  331. phba->fc_stat.NoRcvBuf++;
  332. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  333. lpfc_sli3_post_buffer(phba, pring, 2);
  334. return;
  335. }
  336. /* If there are no BDEs associated
  337. * with this IOCB, there is nothing to do.
  338. */
  339. if (bde_count == 0)
  340. return;
  341. ctiocbq->cmd_dmabuf = bdeBuf1;
  342. if (bde_count == 2)
  343. ctiocbq->bpl_dmabuf = bdeBuf2;
  344. ct_req = (struct lpfc_sli_ct_request *)ctiocbq->cmd_dmabuf->virt;
  345. if (ct_req->FsType == SLI_CT_MANAGEMENT_SERVICE &&
  346. ct_req->FsSubType == SLI_CT_MIB_Subtypes) {
  347. lpfc_ct_handle_mibreq(phba, ctiocbq);
  348. } else {
  349. if (!lpfc_bsg_ct_unsol_event(phba, pring, ctiocbq))
  350. return;
  351. }
  352. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  353. INIT_LIST_HEAD(&head);
  354. list_add_tail(&head, &ctiocbq->list);
  355. list_for_each_entry(iocb, &head, list) {
  356. if (phba->sli_rev == LPFC_SLI_REV4)
  357. bde_count = iocb->wcqe_cmpl.word3;
  358. else
  359. bde_count = iocb->iocb.ulpBdeCount;
  360. if (!bde_count)
  361. continue;
  362. bdeBuf1 = iocb->cmd_dmabuf;
  363. iocb->cmd_dmabuf = NULL;
  364. if (phba->sli_rev == LPFC_SLI_REV4)
  365. size = iocb->wqe.gen_req.bde.tus.f.bdeSize;
  366. else
  367. size = iocb->iocb.un.cont64[0].tus.f.bdeSize;
  368. lpfc_ct_unsol_buffer(phba, ctiocbq, bdeBuf1, size);
  369. lpfc_in_buf_free(phba, bdeBuf1);
  370. if (bde_count == 2) {
  371. bdeBuf2 = iocb->bpl_dmabuf;
  372. iocb->bpl_dmabuf = NULL;
  373. if (phba->sli_rev == LPFC_SLI_REV4)
  374. size = iocb->unsol_rcv_len;
  375. else
  376. size = iocb->iocb.unsli3.rcvsli3.bde2.tus.f.bdeSize;
  377. lpfc_ct_unsol_buffer(phba, ctiocbq, bdeBuf2,
  378. size);
  379. lpfc_in_buf_free(phba, bdeBuf2);
  380. }
  381. }
  382. list_del(&head);
  383. } else {
  384. INIT_LIST_HEAD(&head);
  385. list_add_tail(&head, &ctiocbq->list);
  386. list_for_each_entry(iocbq, &head, list) {
  387. icmd = &iocbq->iocb;
  388. if (icmd->ulpBdeCount == 0)
  389. lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
  390. for (i = 0; i < icmd->ulpBdeCount; i++) {
  391. dma_addr = getPaddr(icmd->un.cont64[i].addrHigh,
  392. icmd->un.cont64[i].addrLow);
  393. mp = lpfc_sli_ringpostbuf_get(phba, pring,
  394. dma_addr);
  395. size = icmd->un.cont64[i].tus.f.bdeSize;
  396. lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
  397. lpfc_in_buf_free(phba, mp);
  398. }
  399. lpfc_sli3_post_buffer(phba, pring, i);
  400. }
  401. list_del(&head);
  402. }
  403. }
  404. /**
  405. * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
  406. * @phba: Pointer to HBA context object.
  407. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  408. *
  409. * This function serves as the upper level protocol abort handler for CT
  410. * protocol.
  411. *
  412. * Return 1 if abort has been handled, 0 otherwise.
  413. **/
  414. int
  415. lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
  416. {
  417. int handled;
  418. /* CT upper level goes through BSG */
  419. handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
  420. return handled;
  421. }
  422. static void
  423. lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
  424. {
  425. struct lpfc_dmabuf *mlast, *next_mlast;
  426. list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
  427. lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
  428. list_del(&mlast->list);
  429. kfree(mlast);
  430. }
  431. lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
  432. kfree(mlist);
  433. return;
  434. }
  435. static struct lpfc_dmabuf *
  436. lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
  437. uint32_t size, int *entries)
  438. {
  439. struct lpfc_dmabuf *mlist = NULL;
  440. struct lpfc_dmabuf *mp;
  441. int cnt, i = 0;
  442. /* We get chunks of FCELSSIZE */
  443. cnt = size > FCELSSIZE ? FCELSSIZE: size;
  444. while (size) {
  445. /* Allocate buffer for rsp payload */
  446. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  447. if (!mp) {
  448. if (mlist)
  449. lpfc_free_ct_rsp(phba, mlist);
  450. return NULL;
  451. }
  452. INIT_LIST_HEAD(&mp->list);
  453. if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
  454. cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
  455. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  456. else
  457. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  458. if (!mp->virt) {
  459. kfree(mp);
  460. if (mlist)
  461. lpfc_free_ct_rsp(phba, mlist);
  462. return NULL;
  463. }
  464. /* Queue it to a linked list */
  465. if (!mlist)
  466. mlist = mp;
  467. else
  468. list_add_tail(&mp->list, &mlist->list);
  469. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
  470. /* build buffer ptr list for IOCB */
  471. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  472. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  473. bpl->tus.f.bdeSize = (uint16_t) cnt;
  474. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  475. bpl++;
  476. i++;
  477. size -= cnt;
  478. }
  479. *entries = i;
  480. return mlist;
  481. }
  482. int
  483. lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
  484. {
  485. struct lpfc_dmabuf *buf_ptr;
  486. /* IOCBQ job structure gets cleaned during release. Just release
  487. * the dma buffers here.
  488. */
  489. if (ctiocb->cmd_dmabuf) {
  490. buf_ptr = ctiocb->cmd_dmabuf;
  491. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  492. kfree(buf_ptr);
  493. ctiocb->cmd_dmabuf = NULL;
  494. }
  495. if (ctiocb->rsp_dmabuf) {
  496. lpfc_free_ct_rsp(phba, ctiocb->rsp_dmabuf);
  497. ctiocb->rsp_dmabuf = NULL;
  498. }
  499. if (ctiocb->bpl_dmabuf) {
  500. buf_ptr = ctiocb->bpl_dmabuf;
  501. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  502. kfree(buf_ptr);
  503. ctiocb->bpl_dmabuf = NULL;
  504. }
  505. lpfc_sli_release_iocbq(phba, ctiocb);
  506. return 0;
  507. }
  508. /*
  509. * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
  510. * @vport: pointer to a host virtual N_Port data structure.
  511. * @bmp: Pointer to BPL for SLI command
  512. * @inp: Pointer to data buffer for response data.
  513. * @outp: Pointer to data buffer that hold the CT command.
  514. * @cmpl: completion routine to call when command completes
  515. * @ndlp: Destination NPort nodelist entry
  516. *
  517. * This function as the final part for issuing a CT command.
  518. */
  519. static int
  520. lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
  521. struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
  522. void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
  523. struct lpfc_iocbq *),
  524. struct lpfc_nodelist *ndlp, uint32_t event_tag, uint32_t num_entry,
  525. uint32_t tmo, uint8_t retry)
  526. {
  527. struct lpfc_hba *phba = vport->phba;
  528. struct lpfc_iocbq *geniocb;
  529. int rc;
  530. u16 ulp_context;
  531. /* Allocate buffer for command iocb */
  532. geniocb = lpfc_sli_get_iocbq(phba);
  533. if (geniocb == NULL)
  534. return 1;
  535. /* Update the num_entry bde count */
  536. geniocb->num_bdes = num_entry;
  537. geniocb->bpl_dmabuf = bmp;
  538. /* Save for completion so we can release these resources */
  539. geniocb->cmd_dmabuf = inp;
  540. geniocb->rsp_dmabuf = outp;
  541. geniocb->event_tag = event_tag;
  542. if (!tmo) {
  543. /* FC spec states we need 3 * ratov for CT requests */
  544. tmo = (3 * phba->fc_ratov);
  545. }
  546. if (phba->sli_rev == LPFC_SLI_REV4)
  547. ulp_context = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  548. else
  549. ulp_context = ndlp->nlp_rpi;
  550. lpfc_sli_prep_gen_req(phba, geniocb, bmp, ulp_context, num_entry, tmo);
  551. /* Issue GEN REQ IOCB for NPORT <did> */
  552. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  553. "0119 Issue GEN REQ IOCB to NPORT x%x "
  554. "Data: x%x x%x\n",
  555. ndlp->nlp_DID, geniocb->iotag,
  556. vport->port_state);
  557. geniocb->cmd_cmpl = cmpl;
  558. geniocb->drvrTimeout = tmo + LPFC_DRVR_TIMEOUT;
  559. geniocb->vport = vport;
  560. geniocb->retry = retry;
  561. geniocb->ndlp = lpfc_nlp_get(ndlp);
  562. if (!geniocb->ndlp)
  563. goto out;
  564. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
  565. if (rc == IOCB_ERROR) {
  566. lpfc_nlp_put(ndlp);
  567. goto out;
  568. }
  569. return 0;
  570. out:
  571. lpfc_sli_release_iocbq(phba, geniocb);
  572. return 1;
  573. }
  574. /*
  575. * lpfc_ct_cmd - Build and issue a CT command
  576. * @vport: pointer to a host virtual N_Port data structure.
  577. * @inmp: Pointer to data buffer for response data.
  578. * @bmp: Pointer to BPL for SLI command
  579. * @ndlp: Destination NPort nodelist entry
  580. * @cmpl: completion routine to call when command completes
  581. *
  582. * This function is called for issuing a CT command.
  583. */
  584. static int
  585. lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
  586. struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
  587. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  588. struct lpfc_iocbq *),
  589. uint32_t rsp_size, uint8_t retry)
  590. {
  591. struct lpfc_hba *phba = vport->phba;
  592. struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
  593. struct lpfc_dmabuf *outmp;
  594. int cnt = 0, status;
  595. int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
  596. CommandResponse.bits.CmdRsp;
  597. bpl++; /* Skip past ct request */
  598. /* Put buffer(s) for ct rsp in bpl */
  599. outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
  600. if (!outmp)
  601. return -ENOMEM;
  602. /*
  603. * Form the CT IOCB. The total number of BDEs in this IOCB
  604. * is the single command plus response count from
  605. * lpfc_alloc_ct_rsp.
  606. */
  607. cnt += 1;
  608. status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp,
  609. phba->fc_eventTag, cnt, 0, retry);
  610. if (status) {
  611. lpfc_free_ct_rsp(phba, outmp);
  612. return -ENOMEM;
  613. }
  614. return 0;
  615. }
  616. struct lpfc_vport *
  617. lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
  618. struct lpfc_vport *vport_curr;
  619. unsigned long flags;
  620. spin_lock_irqsave(&phba->port_list_lock, flags);
  621. list_for_each_entry(vport_curr, &phba->port_list, listentry) {
  622. if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
  623. spin_unlock_irqrestore(&phba->port_list_lock, flags);
  624. return vport_curr;
  625. }
  626. }
  627. spin_unlock_irqrestore(&phba->port_list_lock, flags);
  628. return NULL;
  629. }
  630. static void
  631. lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
  632. {
  633. struct lpfc_nodelist *ndlp;
  634. if ((vport->port_type != LPFC_NPIV_PORT) ||
  635. !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
  636. ndlp = lpfc_setup_disc_node(vport, Did);
  637. if (ndlp) {
  638. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  639. "Parse GID_FTrsp: did:x%x flg:x%x x%x",
  640. Did, ndlp->nlp_flag, vport->fc_flag);
  641. /* By default, the driver expects to support FCP FC4 */
  642. if (fc4_type == FC_TYPE_FCP)
  643. ndlp->nlp_fc4_type |= NLP_FC4_FCP;
  644. if (fc4_type == FC_TYPE_NVME)
  645. ndlp->nlp_fc4_type |= NLP_FC4_NVME;
  646. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  647. "0238 Process x%06x NameServer Rsp "
  648. "Data: x%x x%x x%x x%x x%x\n", Did,
  649. ndlp->nlp_flag, ndlp->nlp_fc4_type,
  650. ndlp->nlp_state, vport->fc_flag,
  651. vport->fc_rscn_id_cnt);
  652. /* if ndlp needs to be discovered and prior
  653. * state of ndlp hit devloss, change state to
  654. * allow rediscovery.
  655. */
  656. if (ndlp->nlp_flag & NLP_NPR_2B_DISC &&
  657. ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  658. lpfc_nlp_set_state(vport, ndlp,
  659. NLP_STE_NPR_NODE);
  660. }
  661. } else {
  662. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  663. "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
  664. Did, vport->fc_flag, vport->fc_rscn_id_cnt);
  665. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  666. "0239 Skip x%06x NameServer Rsp "
  667. "Data: x%x x%x x%px\n",
  668. Did, vport->fc_flag,
  669. vport->fc_rscn_id_cnt, ndlp);
  670. }
  671. } else {
  672. if (!(vport->fc_flag & FC_RSCN_MODE) ||
  673. lpfc_rscn_payload_check(vport, Did)) {
  674. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  675. "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
  676. Did, vport->fc_flag, vport->fc_rscn_id_cnt);
  677. /*
  678. * This NPortID was previously a FCP/NVMe target,
  679. * Don't even bother to send GFF_ID.
  680. */
  681. ndlp = lpfc_findnode_did(vport, Did);
  682. if (ndlp &&
  683. (ndlp->nlp_type &
  684. (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
  685. if (fc4_type == FC_TYPE_FCP)
  686. ndlp->nlp_fc4_type |= NLP_FC4_FCP;
  687. if (fc4_type == FC_TYPE_NVME)
  688. ndlp->nlp_fc4_type |= NLP_FC4_NVME;
  689. lpfc_setup_disc_node(vport, Did);
  690. } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
  691. 0, Did) == 0)
  692. vport->num_disc_nodes++;
  693. else
  694. lpfc_setup_disc_node(vport, Did);
  695. } else {
  696. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  697. "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
  698. Did, vport->fc_flag, vport->fc_rscn_id_cnt);
  699. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  700. "0245 Skip x%06x NameServer Rsp "
  701. "Data: x%x x%x\n", Did,
  702. vport->fc_flag,
  703. vport->fc_rscn_id_cnt);
  704. }
  705. }
  706. }
  707. static void
  708. lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
  709. {
  710. struct lpfc_hba *phba = vport->phba;
  711. struct lpfc_nodelist *ndlp = NULL;
  712. char *str;
  713. if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT)
  714. str = "GID_FT";
  715. else
  716. str = "GID_PT";
  717. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  718. "6430 Process %s rsp for %08x type %x %s %s\n",
  719. str, Did, fc4_type,
  720. (fc4_type == FC_TYPE_FCP) ? "FCP" : " ",
  721. (fc4_type == FC_TYPE_NVME) ? "NVME" : " ");
  722. /*
  723. * To conserve rpi's, filter out addresses for other
  724. * vports on the same physical HBAs.
  725. */
  726. if (Did != vport->fc_myDID &&
  727. (!lpfc_find_vport_by_did(phba, Did) ||
  728. vport->cfg_peer_port_login)) {
  729. if (!phba->nvmet_support) {
  730. /* FCPI/NVMEI path. Process Did */
  731. lpfc_prep_node_fc4type(vport, Did, fc4_type);
  732. return;
  733. }
  734. /* NVMET path. NVMET only cares about NVMEI nodes. */
  735. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  736. if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
  737. ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
  738. continue;
  739. spin_lock_irq(&ndlp->lock);
  740. if (ndlp->nlp_DID == Did)
  741. ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
  742. else
  743. ndlp->nlp_flag |= NLP_NVMET_RECOV;
  744. spin_unlock_irq(&ndlp->lock);
  745. }
  746. }
  747. }
  748. static int
  749. lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
  750. uint32_t Size)
  751. {
  752. struct lpfc_sli_ct_request *Response =
  753. (struct lpfc_sli_ct_request *) mp->virt;
  754. struct lpfc_dmabuf *mlast, *next_mp;
  755. uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
  756. uint32_t Did, CTentry;
  757. int Cnt;
  758. struct list_head head;
  759. struct lpfc_nodelist *ndlp = NULL;
  760. lpfc_set_disctmo(vport);
  761. vport->num_disc_nodes = 0;
  762. vport->fc_ns_retry = 0;
  763. list_add_tail(&head, &mp->list);
  764. list_for_each_entry_safe(mp, next_mp, &head, list) {
  765. mlast = mp;
  766. Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
  767. Size -= Cnt;
  768. if (!ctptr) {
  769. ctptr = (uint32_t *) mlast->virt;
  770. } else
  771. Cnt -= 16; /* subtract length of CT header */
  772. /* Loop through entire NameServer list of DIDs */
  773. while (Cnt >= sizeof(uint32_t)) {
  774. /* Get next DID from NameServer List */
  775. CTentry = *ctptr++;
  776. Did = ((be32_to_cpu(CTentry)) & Mask_DID);
  777. lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
  778. if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
  779. goto nsout1;
  780. Cnt -= sizeof(uint32_t);
  781. }
  782. ctptr = NULL;
  783. }
  784. /* All GID_FT entries processed. If the driver is running in
  785. * in target mode, put impacted nodes into recovery and drop
  786. * the RPI to flush outstanding IO.
  787. */
  788. if (vport->phba->nvmet_support) {
  789. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  790. if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
  791. continue;
  792. lpfc_disc_state_machine(vport, ndlp, NULL,
  793. NLP_EVT_DEVICE_RECOVERY);
  794. spin_lock_irq(&ndlp->lock);
  795. ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
  796. spin_unlock_irq(&ndlp->lock);
  797. }
  798. }
  799. nsout1:
  800. list_del(&head);
  801. return 0;
  802. }
  803. static void
  804. lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  805. struct lpfc_iocbq *rspiocb)
  806. {
  807. struct lpfc_vport *vport = cmdiocb->vport;
  808. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  809. struct lpfc_dmabuf *outp;
  810. struct lpfc_dmabuf *inp;
  811. struct lpfc_sli_ct_request *CTrsp;
  812. struct lpfc_sli_ct_request *CTreq;
  813. struct lpfc_nodelist *ndlp;
  814. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  815. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  816. int rc, type;
  817. /* First save ndlp, before we overwrite it */
  818. ndlp = cmdiocb->ndlp;
  819. /* we pass cmdiocb to state machine which needs rspiocb as well */
  820. cmdiocb->rsp_iocb = rspiocb;
  821. inp = cmdiocb->cmd_dmabuf;
  822. outp = cmdiocb->rsp_dmabuf;
  823. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  824. "GID_FT cmpl: status:x%x/x%x rtry:%d",
  825. ulp_status, ulp_word4, vport->fc_ns_retry);
  826. /* Ignore response if link flipped after this request was made */
  827. if (cmdiocb->event_tag != phba->fc_eventTag) {
  828. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  829. "9043 Event tag mismatch. Ignoring NS rsp\n");
  830. goto out;
  831. }
  832. /* Don't bother processing response if vport is being torn down. */
  833. if (vport->load_flag & FC_UNLOADING) {
  834. if (vport->fc_flag & FC_RSCN_MODE)
  835. lpfc_els_flush_rscn(vport);
  836. goto out;
  837. }
  838. if (lpfc_els_chk_latt(vport)) {
  839. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  840. "0216 Link event during NS query\n");
  841. if (vport->fc_flag & FC_RSCN_MODE)
  842. lpfc_els_flush_rscn(vport);
  843. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  844. goto out;
  845. }
  846. if (lpfc_error_lost_link(ulp_status, ulp_word4)) {
  847. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  848. "0226 NS query failed due to link event: "
  849. "ulp_status x%x ulp_word4 x%x fc_flag x%x "
  850. "port_state x%x gidft_inp x%x\n",
  851. ulp_status, ulp_word4, vport->fc_flag,
  852. vport->port_state, vport->gidft_inp);
  853. if (vport->fc_flag & FC_RSCN_MODE)
  854. lpfc_els_flush_rscn(vport);
  855. if (vport->gidft_inp)
  856. vport->gidft_inp--;
  857. goto out;
  858. }
  859. spin_lock_irq(shost->host_lock);
  860. if (vport->fc_flag & FC_RSCN_DEFERRED) {
  861. vport->fc_flag &= ~FC_RSCN_DEFERRED;
  862. spin_unlock_irq(shost->host_lock);
  863. /* This is a GID_FT completing so the gidft_inp counter was
  864. * incremented before the GID_FT was issued to the wire.
  865. */
  866. if (vport->gidft_inp)
  867. vport->gidft_inp--;
  868. /*
  869. * Skip processing the NS response
  870. * Re-issue the NS cmd
  871. */
  872. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  873. "0151 Process Deferred RSCN Data: x%x x%x\n",
  874. vport->fc_flag, vport->fc_rscn_id_cnt);
  875. lpfc_els_handle_rscn(vport);
  876. goto out;
  877. }
  878. spin_unlock_irq(shost->host_lock);
  879. if (ulp_status) {
  880. /* Check for retry */
  881. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  882. if (ulp_status != IOSTAT_LOCAL_REJECT ||
  883. (ulp_word4 & IOERR_PARAM_MASK) !=
  884. IOERR_NO_RESOURCES)
  885. vport->fc_ns_retry++;
  886. type = lpfc_get_gidft_type(vport, cmdiocb);
  887. if (type == 0)
  888. goto out;
  889. /* CT command is being retried */
  890. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  891. vport->fc_ns_retry, type);
  892. if (rc == 0)
  893. goto out;
  894. else { /* Unable to send NS cmd */
  895. if (vport->gidft_inp)
  896. vport->gidft_inp--;
  897. }
  898. }
  899. if (vport->fc_flag & FC_RSCN_MODE)
  900. lpfc_els_flush_rscn(vport);
  901. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  902. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  903. "0257 GID_FT Query error: 0x%x 0x%x\n",
  904. ulp_status, vport->fc_ns_retry);
  905. } else {
  906. /* Good status, continue checking */
  907. CTreq = (struct lpfc_sli_ct_request *) inp->virt;
  908. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  909. if (CTrsp->CommandResponse.bits.CmdRsp ==
  910. cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
  911. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  912. "0208 NameServer Rsp Data: x%x x%x "
  913. "x%x x%x sz x%x\n",
  914. vport->fc_flag,
  915. CTreq->un.gid.Fc4Type,
  916. vport->num_disc_nodes,
  917. vport->gidft_inp,
  918. get_job_data_placed(phba, rspiocb));
  919. lpfc_ns_rsp(vport,
  920. outp,
  921. CTreq->un.gid.Fc4Type,
  922. get_job_data_placed(phba, rspiocb));
  923. } else if (CTrsp->CommandResponse.bits.CmdRsp ==
  924. be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  925. /* NameServer Rsp Error */
  926. if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
  927. && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
  928. lpfc_printf_vlog(vport, KERN_INFO,
  929. LOG_DISCOVERY,
  930. "0269 No NameServer Entries "
  931. "Data: x%x x%x x%x x%x\n",
  932. CTrsp->CommandResponse.bits.CmdRsp,
  933. (uint32_t) CTrsp->ReasonCode,
  934. (uint32_t) CTrsp->Explanation,
  935. vport->fc_flag);
  936. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  937. "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
  938. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  939. (uint32_t) CTrsp->ReasonCode,
  940. (uint32_t) CTrsp->Explanation);
  941. } else {
  942. lpfc_printf_vlog(vport, KERN_INFO,
  943. LOG_DISCOVERY,
  944. "0240 NameServer Rsp Error "
  945. "Data: x%x x%x x%x x%x\n",
  946. CTrsp->CommandResponse.bits.CmdRsp,
  947. (uint32_t) CTrsp->ReasonCode,
  948. (uint32_t) CTrsp->Explanation,
  949. vport->fc_flag);
  950. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  951. "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
  952. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  953. (uint32_t) CTrsp->ReasonCode,
  954. (uint32_t) CTrsp->Explanation);
  955. }
  956. } else {
  957. /* NameServer Rsp Error */
  958. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  959. "0241 NameServer Rsp Error "
  960. "Data: x%x x%x x%x x%x\n",
  961. CTrsp->CommandResponse.bits.CmdRsp,
  962. (uint32_t) CTrsp->ReasonCode,
  963. (uint32_t) CTrsp->Explanation,
  964. vport->fc_flag);
  965. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  966. "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
  967. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  968. (uint32_t) CTrsp->ReasonCode,
  969. (uint32_t) CTrsp->Explanation);
  970. }
  971. if (vport->gidft_inp)
  972. vport->gidft_inp--;
  973. }
  974. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  975. "4216 GID_FT cmpl inp %d disc %d\n",
  976. vport->gidft_inp, vport->num_disc_nodes);
  977. /* Link up / RSCN discovery */
  978. if ((vport->num_disc_nodes == 0) &&
  979. (vport->gidft_inp == 0)) {
  980. /*
  981. * The driver has cycled through all Nports in the RSCN payload.
  982. * Complete the handling by cleaning up and marking the
  983. * current driver state.
  984. */
  985. if (vport->port_state >= LPFC_DISC_AUTH) {
  986. if (vport->fc_flag & FC_RSCN_MODE) {
  987. lpfc_els_flush_rscn(vport);
  988. spin_lock_irq(shost->host_lock);
  989. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  990. spin_unlock_irq(shost->host_lock);
  991. }
  992. else
  993. lpfc_els_flush_rscn(vport);
  994. }
  995. lpfc_disc_start(vport);
  996. }
  997. out:
  998. lpfc_ct_free_iocb(phba, cmdiocb);
  999. lpfc_nlp_put(ndlp);
  1000. return;
  1001. }
  1002. static void
  1003. lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1004. struct lpfc_iocbq *rspiocb)
  1005. {
  1006. struct lpfc_vport *vport = cmdiocb->vport;
  1007. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1008. struct lpfc_dmabuf *outp;
  1009. struct lpfc_dmabuf *inp;
  1010. struct lpfc_sli_ct_request *CTrsp;
  1011. struct lpfc_sli_ct_request *CTreq;
  1012. struct lpfc_nodelist *ndlp;
  1013. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1014. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  1015. int rc;
  1016. /* First save ndlp, before we overwrite it */
  1017. ndlp = cmdiocb->ndlp;
  1018. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1019. cmdiocb->rsp_iocb = rspiocb;
  1020. inp = cmdiocb->cmd_dmabuf;
  1021. outp = cmdiocb->rsp_dmabuf;
  1022. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1023. "GID_PT cmpl: status:x%x/x%x rtry:%d",
  1024. ulp_status, ulp_word4,
  1025. vport->fc_ns_retry);
  1026. /* Ignore response if link flipped after this request was made */
  1027. if (cmdiocb->event_tag != phba->fc_eventTag) {
  1028. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1029. "9044 Event tag mismatch. Ignoring NS rsp\n");
  1030. goto out;
  1031. }
  1032. /* Don't bother processing response if vport is being torn down. */
  1033. if (vport->load_flag & FC_UNLOADING) {
  1034. if (vport->fc_flag & FC_RSCN_MODE)
  1035. lpfc_els_flush_rscn(vport);
  1036. goto out;
  1037. }
  1038. if (lpfc_els_chk_latt(vport)) {
  1039. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1040. "4108 Link event during NS query\n");
  1041. if (vport->fc_flag & FC_RSCN_MODE)
  1042. lpfc_els_flush_rscn(vport);
  1043. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1044. goto out;
  1045. }
  1046. if (lpfc_error_lost_link(ulp_status, ulp_word4)) {
  1047. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1048. "4166 NS query failed due to link event: "
  1049. "ulp_status x%x ulp_word4 x%x fc_flag x%x "
  1050. "port_state x%x gidft_inp x%x\n",
  1051. ulp_status, ulp_word4, vport->fc_flag,
  1052. vport->port_state, vport->gidft_inp);
  1053. if (vport->fc_flag & FC_RSCN_MODE)
  1054. lpfc_els_flush_rscn(vport);
  1055. if (vport->gidft_inp)
  1056. vport->gidft_inp--;
  1057. goto out;
  1058. }
  1059. spin_lock_irq(shost->host_lock);
  1060. if (vport->fc_flag & FC_RSCN_DEFERRED) {
  1061. vport->fc_flag &= ~FC_RSCN_DEFERRED;
  1062. spin_unlock_irq(shost->host_lock);
  1063. /* This is a GID_PT completing so the gidft_inp counter was
  1064. * incremented before the GID_PT was issued to the wire.
  1065. */
  1066. if (vport->gidft_inp)
  1067. vport->gidft_inp--;
  1068. /*
  1069. * Skip processing the NS response
  1070. * Re-issue the NS cmd
  1071. */
  1072. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1073. "4167 Process Deferred RSCN Data: x%x x%x\n",
  1074. vport->fc_flag, vport->fc_rscn_id_cnt);
  1075. lpfc_els_handle_rscn(vport);
  1076. goto out;
  1077. }
  1078. spin_unlock_irq(shost->host_lock);
  1079. if (ulp_status) {
  1080. /* Check for retry */
  1081. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  1082. if (ulp_status != IOSTAT_LOCAL_REJECT ||
  1083. (ulp_word4 & IOERR_PARAM_MASK) !=
  1084. IOERR_NO_RESOURCES)
  1085. vport->fc_ns_retry++;
  1086. /* CT command is being retried */
  1087. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
  1088. vport->fc_ns_retry, GID_PT_N_PORT);
  1089. if (rc == 0)
  1090. goto out;
  1091. else { /* Unable to send NS cmd */
  1092. if (vport->gidft_inp)
  1093. vport->gidft_inp--;
  1094. }
  1095. }
  1096. if (vport->fc_flag & FC_RSCN_MODE)
  1097. lpfc_els_flush_rscn(vport);
  1098. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1099. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1100. "4103 GID_FT Query error: 0x%x 0x%x\n",
  1101. ulp_status, vport->fc_ns_retry);
  1102. } else {
  1103. /* Good status, continue checking */
  1104. CTreq = (struct lpfc_sli_ct_request *)inp->virt;
  1105. CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
  1106. if (CTrsp->CommandResponse.bits.CmdRsp ==
  1107. cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
  1108. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1109. "4105 NameServer Rsp Data: x%x x%x "
  1110. "x%x x%x sz x%x\n",
  1111. vport->fc_flag,
  1112. CTreq->un.gid.Fc4Type,
  1113. vport->num_disc_nodes,
  1114. vport->gidft_inp,
  1115. get_job_data_placed(phba, rspiocb));
  1116. lpfc_ns_rsp(vport,
  1117. outp,
  1118. CTreq->un.gid.Fc4Type,
  1119. get_job_data_placed(phba, rspiocb));
  1120. } else if (CTrsp->CommandResponse.bits.CmdRsp ==
  1121. be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  1122. /* NameServer Rsp Error */
  1123. if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
  1124. && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
  1125. lpfc_printf_vlog(
  1126. vport, KERN_INFO, LOG_DISCOVERY,
  1127. "4106 No NameServer Entries "
  1128. "Data: x%x x%x x%x x%x\n",
  1129. CTrsp->CommandResponse.bits.CmdRsp,
  1130. (uint32_t)CTrsp->ReasonCode,
  1131. (uint32_t)CTrsp->Explanation,
  1132. vport->fc_flag);
  1133. lpfc_debugfs_disc_trc(
  1134. vport, LPFC_DISC_TRC_CT,
  1135. "GID_PT no entry cmd:x%x rsn:x%x exp:x%x",
  1136. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  1137. (uint32_t)CTrsp->ReasonCode,
  1138. (uint32_t)CTrsp->Explanation);
  1139. } else {
  1140. lpfc_printf_vlog(
  1141. vport, KERN_INFO, LOG_DISCOVERY,
  1142. "4107 NameServer Rsp Error "
  1143. "Data: x%x x%x x%x x%x\n",
  1144. CTrsp->CommandResponse.bits.CmdRsp,
  1145. (uint32_t)CTrsp->ReasonCode,
  1146. (uint32_t)CTrsp->Explanation,
  1147. vport->fc_flag);
  1148. lpfc_debugfs_disc_trc(
  1149. vport, LPFC_DISC_TRC_CT,
  1150. "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
  1151. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  1152. (uint32_t)CTrsp->ReasonCode,
  1153. (uint32_t)CTrsp->Explanation);
  1154. }
  1155. } else {
  1156. /* NameServer Rsp Error */
  1157. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1158. "4109 NameServer Rsp Error "
  1159. "Data: x%x x%x x%x x%x\n",
  1160. CTrsp->CommandResponse.bits.CmdRsp,
  1161. (uint32_t)CTrsp->ReasonCode,
  1162. (uint32_t)CTrsp->Explanation,
  1163. vport->fc_flag);
  1164. lpfc_debugfs_disc_trc(
  1165. vport, LPFC_DISC_TRC_CT,
  1166. "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
  1167. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  1168. (uint32_t)CTrsp->ReasonCode,
  1169. (uint32_t)CTrsp->Explanation);
  1170. }
  1171. if (vport->gidft_inp)
  1172. vport->gidft_inp--;
  1173. }
  1174. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1175. "6450 GID_PT cmpl inp %d disc %d\n",
  1176. vport->gidft_inp, vport->num_disc_nodes);
  1177. /* Link up / RSCN discovery */
  1178. if ((vport->num_disc_nodes == 0) &&
  1179. (vport->gidft_inp == 0)) {
  1180. /*
  1181. * The driver has cycled through all Nports in the RSCN payload.
  1182. * Complete the handling by cleaning up and marking the
  1183. * current driver state.
  1184. */
  1185. if (vport->port_state >= LPFC_DISC_AUTH) {
  1186. if (vport->fc_flag & FC_RSCN_MODE) {
  1187. lpfc_els_flush_rscn(vport);
  1188. spin_lock_irq(shost->host_lock);
  1189. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  1190. spin_unlock_irq(shost->host_lock);
  1191. } else {
  1192. lpfc_els_flush_rscn(vport);
  1193. }
  1194. }
  1195. lpfc_disc_start(vport);
  1196. }
  1197. out:
  1198. lpfc_ct_free_iocb(phba, cmdiocb);
  1199. lpfc_nlp_put(ndlp);
  1200. }
  1201. static void
  1202. lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1203. struct lpfc_iocbq *rspiocb)
  1204. {
  1205. struct lpfc_vport *vport = cmdiocb->vport;
  1206. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1207. struct lpfc_dmabuf *inp = cmdiocb->cmd_dmabuf;
  1208. struct lpfc_dmabuf *outp = cmdiocb->rsp_dmabuf;
  1209. struct lpfc_sli_ct_request *CTrsp;
  1210. int did, rc, retry;
  1211. uint8_t fbits;
  1212. struct lpfc_nodelist *ndlp = NULL, *free_ndlp = NULL;
  1213. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1214. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  1215. did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
  1216. did = be32_to_cpu(did);
  1217. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1218. "GFF_ID cmpl: status:x%x/x%x did:x%x",
  1219. ulp_status, ulp_word4, did);
  1220. /* Ignore response if link flipped after this request was made */
  1221. if (cmdiocb->event_tag != phba->fc_eventTag) {
  1222. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1223. "9045 Event tag mismatch. Ignoring NS rsp\n");
  1224. goto iocb_free;
  1225. }
  1226. if (ulp_status == IOSTAT_SUCCESS) {
  1227. /* Good status, continue checking */
  1228. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  1229. fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
  1230. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1231. "6431 Process GFF_ID rsp for %08x "
  1232. "fbits %02x %s %s\n",
  1233. did, fbits,
  1234. (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ",
  1235. (fbits & FC4_FEATURE_TARGET) ? "Target" : " ");
  1236. if (CTrsp->CommandResponse.bits.CmdRsp ==
  1237. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  1238. if ((fbits & FC4_FEATURE_INIT) &&
  1239. !(fbits & FC4_FEATURE_TARGET)) {
  1240. lpfc_printf_vlog(vport, KERN_INFO,
  1241. LOG_DISCOVERY,
  1242. "0270 Skip x%x GFF "
  1243. "NameServer Rsp Data: (init) "
  1244. "x%x x%x\n", did, fbits,
  1245. vport->fc_rscn_id_cnt);
  1246. goto out;
  1247. }
  1248. }
  1249. }
  1250. else {
  1251. /* Check for retry */
  1252. if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
  1253. retry = 1;
  1254. if (ulp_status == IOSTAT_LOCAL_REJECT) {
  1255. switch ((ulp_word4 &
  1256. IOERR_PARAM_MASK)) {
  1257. case IOERR_NO_RESOURCES:
  1258. /* We don't increment the retry
  1259. * count for this case.
  1260. */
  1261. break;
  1262. case IOERR_LINK_DOWN:
  1263. case IOERR_SLI_ABORTED:
  1264. case IOERR_SLI_DOWN:
  1265. retry = 0;
  1266. break;
  1267. default:
  1268. cmdiocb->retry++;
  1269. }
  1270. }
  1271. else
  1272. cmdiocb->retry++;
  1273. if (retry) {
  1274. /* CT command is being retried */
  1275. rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
  1276. cmdiocb->retry, did);
  1277. if (rc == 0) {
  1278. /* success */
  1279. free_ndlp = cmdiocb->ndlp;
  1280. lpfc_ct_free_iocb(phba, cmdiocb);
  1281. lpfc_nlp_put(free_ndlp);
  1282. return;
  1283. }
  1284. }
  1285. }
  1286. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1287. "0267 NameServer GFF Rsp "
  1288. "x%x Error (%d %d) Data: x%x x%x\n",
  1289. did, ulp_status, ulp_word4,
  1290. vport->fc_flag, vport->fc_rscn_id_cnt);
  1291. }
  1292. /* This is a target port, unregistered port, or the GFF_ID failed */
  1293. ndlp = lpfc_setup_disc_node(vport, did);
  1294. if (ndlp) {
  1295. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1296. "0242 Process x%x GFF "
  1297. "NameServer Rsp Data: x%x x%x x%x\n",
  1298. did, ndlp->nlp_flag, vport->fc_flag,
  1299. vport->fc_rscn_id_cnt);
  1300. } else {
  1301. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1302. "0243 Skip x%x GFF "
  1303. "NameServer Rsp Data: x%x x%x\n", did,
  1304. vport->fc_flag, vport->fc_rscn_id_cnt);
  1305. }
  1306. out:
  1307. /* Link up / RSCN discovery */
  1308. if (vport->num_disc_nodes)
  1309. vport->num_disc_nodes--;
  1310. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1311. "6451 GFF_ID cmpl inp %d disc %d\n",
  1312. vport->gidft_inp, vport->num_disc_nodes);
  1313. if (vport->num_disc_nodes == 0) {
  1314. /*
  1315. * The driver has cycled through all Nports in the RSCN payload.
  1316. * Complete the handling by cleaning up and marking the
  1317. * current driver state.
  1318. */
  1319. if (vport->port_state >= LPFC_DISC_AUTH) {
  1320. if (vport->fc_flag & FC_RSCN_MODE) {
  1321. lpfc_els_flush_rscn(vport);
  1322. spin_lock_irq(shost->host_lock);
  1323. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  1324. spin_unlock_irq(shost->host_lock);
  1325. }
  1326. else
  1327. lpfc_els_flush_rscn(vport);
  1328. }
  1329. lpfc_disc_start(vport);
  1330. }
  1331. iocb_free:
  1332. free_ndlp = cmdiocb->ndlp;
  1333. lpfc_ct_free_iocb(phba, cmdiocb);
  1334. lpfc_nlp_put(free_ndlp);
  1335. return;
  1336. }
  1337. static void
  1338. lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1339. struct lpfc_iocbq *rspiocb)
  1340. {
  1341. struct lpfc_vport *vport = cmdiocb->vport;
  1342. struct lpfc_dmabuf *inp = cmdiocb->cmd_dmabuf;
  1343. struct lpfc_dmabuf *outp = cmdiocb->rsp_dmabuf;
  1344. struct lpfc_sli_ct_request *CTrsp;
  1345. int did;
  1346. struct lpfc_nodelist *ndlp = NULL;
  1347. struct lpfc_nodelist *ns_ndlp = cmdiocb->ndlp;
  1348. uint32_t fc4_data_0, fc4_data_1;
  1349. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1350. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  1351. did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
  1352. did = be32_to_cpu(did);
  1353. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1354. "GFT_ID cmpl: status:x%x/x%x did:x%x",
  1355. ulp_status, ulp_word4, did);
  1356. /* Ignore response if link flipped after this request was made */
  1357. if ((uint32_t)cmdiocb->event_tag != phba->fc_eventTag) {
  1358. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1359. "9046 Event tag mismatch. Ignoring NS rsp\n");
  1360. goto out;
  1361. }
  1362. if (ulp_status == IOSTAT_SUCCESS) {
  1363. /* Good status, continue checking */
  1364. CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
  1365. fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
  1366. fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
  1367. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1368. "6432 Process GFT_ID rsp for %08x "
  1369. "Data %08x %08x %s %s\n",
  1370. did, fc4_data_0, fc4_data_1,
  1371. (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ?
  1372. "FCP" : " ",
  1373. (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ?
  1374. "NVME" : " ");
  1375. /* Lookup the NPort_ID queried in the GFT_ID and find the
  1376. * driver's local node. It's an error if the driver
  1377. * doesn't have one.
  1378. */
  1379. ndlp = lpfc_findnode_did(vport, did);
  1380. if (ndlp) {
  1381. /* The bitmask value for FCP and NVME FCP types is
  1382. * the same because they are 32 bits distant from
  1383. * each other in word0 and word0.
  1384. */
  1385. if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
  1386. ndlp->nlp_fc4_type |= NLP_FC4_FCP;
  1387. if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
  1388. ndlp->nlp_fc4_type |= NLP_FC4_NVME;
  1389. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1390. "3064 Setting ndlp x%px, DID x%06x "
  1391. "with FC4 x%08x, Data: x%08x x%08x "
  1392. "%d\n",
  1393. ndlp, did, ndlp->nlp_fc4_type,
  1394. FC_TYPE_FCP, FC_TYPE_NVME,
  1395. ndlp->nlp_state);
  1396. if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE &&
  1397. ndlp->nlp_fc4_type) {
  1398. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1399. lpfc_nlp_set_state(vport, ndlp,
  1400. NLP_STE_PRLI_ISSUE);
  1401. lpfc_issue_els_prli(vport, ndlp, 0);
  1402. } else if (!ndlp->nlp_fc4_type) {
  1403. /* If fc4 type is still unknown, then LOGO */
  1404. lpfc_printf_vlog(vport, KERN_INFO,
  1405. LOG_DISCOVERY,
  1406. "6443 Sending LOGO ndlp x%px,"
  1407. "DID x%06x with fc4_type: "
  1408. "x%08x, state: %d\n",
  1409. ndlp, did, ndlp->nlp_fc4_type,
  1410. ndlp->nlp_state);
  1411. lpfc_issue_els_logo(vport, ndlp, 0);
  1412. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1413. lpfc_nlp_set_state(vport, ndlp,
  1414. NLP_STE_NPR_NODE);
  1415. }
  1416. }
  1417. } else
  1418. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1419. "3065 GFT_ID failed x%08x\n", ulp_status);
  1420. out:
  1421. lpfc_ct_free_iocb(phba, cmdiocb);
  1422. lpfc_nlp_put(ns_ndlp);
  1423. }
  1424. static void
  1425. lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1426. struct lpfc_iocbq *rspiocb)
  1427. {
  1428. struct lpfc_vport *vport = cmdiocb->vport;
  1429. struct lpfc_dmabuf *inp;
  1430. struct lpfc_dmabuf *outp;
  1431. struct lpfc_sli_ct_request *CTrsp;
  1432. struct lpfc_nodelist *ndlp;
  1433. int cmdcode, rc;
  1434. uint8_t retry;
  1435. uint32_t latt;
  1436. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1437. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  1438. /* First save ndlp, before we overwrite it */
  1439. ndlp = cmdiocb->ndlp;
  1440. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1441. cmdiocb->rsp_iocb = rspiocb;
  1442. inp = cmdiocb->cmd_dmabuf;
  1443. outp = cmdiocb->rsp_dmabuf;
  1444. cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
  1445. CommandResponse.bits.CmdRsp);
  1446. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  1447. latt = lpfc_els_chk_latt(vport);
  1448. /* RFT request completes status <ulp_status> CmdRsp <CmdRsp> */
  1449. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1450. "0209 CT Request completes, latt %d, "
  1451. "ulp_status x%x CmdRsp x%x, Context x%x, Tag x%x\n",
  1452. latt, ulp_status,
  1453. CTrsp->CommandResponse.bits.CmdRsp,
  1454. get_job_ulpcontext(phba, cmdiocb), cmdiocb->iotag);
  1455. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1456. "CT cmd cmpl: status:x%x/x%x cmd:x%x",
  1457. ulp_status, ulp_word4, cmdcode);
  1458. if (ulp_status) {
  1459. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1460. "0268 NS cmd x%x Error (x%x x%x)\n",
  1461. cmdcode, ulp_status, ulp_word4);
  1462. if (ulp_status == IOSTAT_LOCAL_REJECT &&
  1463. (((ulp_word4 & IOERR_PARAM_MASK) ==
  1464. IOERR_SLI_DOWN) ||
  1465. ((ulp_word4 & IOERR_PARAM_MASK) ==
  1466. IOERR_SLI_ABORTED)))
  1467. goto out;
  1468. retry = cmdiocb->retry;
  1469. if (retry >= LPFC_MAX_NS_RETRY)
  1470. goto out;
  1471. retry++;
  1472. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1473. "0250 Retrying NS cmd %x\n", cmdcode);
  1474. rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
  1475. if (rc == 0)
  1476. goto out;
  1477. }
  1478. out:
  1479. lpfc_ct_free_iocb(phba, cmdiocb);
  1480. lpfc_nlp_put(ndlp);
  1481. return;
  1482. }
  1483. static void
  1484. lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1485. struct lpfc_iocbq *rspiocb)
  1486. {
  1487. struct lpfc_vport *vport = cmdiocb->vport;
  1488. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1489. if (ulp_status == IOSTAT_SUCCESS) {
  1490. struct lpfc_dmabuf *outp;
  1491. struct lpfc_sli_ct_request *CTrsp;
  1492. outp = cmdiocb->rsp_dmabuf;
  1493. CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
  1494. if (CTrsp->CommandResponse.bits.CmdRsp ==
  1495. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  1496. vport->ct_flags |= FC_CT_RFT_ID;
  1497. }
  1498. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1499. return;
  1500. }
  1501. static void
  1502. lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1503. struct lpfc_iocbq *rspiocb)
  1504. {
  1505. struct lpfc_vport *vport = cmdiocb->vport;
  1506. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1507. if (ulp_status == IOSTAT_SUCCESS) {
  1508. struct lpfc_dmabuf *outp;
  1509. struct lpfc_sli_ct_request *CTrsp;
  1510. outp = cmdiocb->rsp_dmabuf;
  1511. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  1512. if (CTrsp->CommandResponse.bits.CmdRsp ==
  1513. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  1514. vport->ct_flags |= FC_CT_RNN_ID;
  1515. }
  1516. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1517. return;
  1518. }
  1519. static void
  1520. lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1521. struct lpfc_iocbq *rspiocb)
  1522. {
  1523. struct lpfc_vport *vport = cmdiocb->vport;
  1524. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1525. if (ulp_status == IOSTAT_SUCCESS) {
  1526. struct lpfc_dmabuf *outp;
  1527. struct lpfc_sli_ct_request *CTrsp;
  1528. outp = cmdiocb->rsp_dmabuf;
  1529. CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
  1530. if (CTrsp->CommandResponse.bits.CmdRsp ==
  1531. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  1532. vport->ct_flags |= FC_CT_RSPN_ID;
  1533. }
  1534. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1535. return;
  1536. }
  1537. static void
  1538. lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1539. struct lpfc_iocbq *rspiocb)
  1540. {
  1541. struct lpfc_vport *vport = cmdiocb->vport;
  1542. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1543. if (ulp_status == IOSTAT_SUCCESS) {
  1544. struct lpfc_dmabuf *outp;
  1545. struct lpfc_sli_ct_request *CTrsp;
  1546. outp = cmdiocb->rsp_dmabuf;
  1547. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  1548. if (CTrsp->CommandResponse.bits.CmdRsp ==
  1549. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  1550. vport->ct_flags |= FC_CT_RSNN_NN;
  1551. }
  1552. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1553. return;
  1554. }
  1555. static void
  1556. lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1557. struct lpfc_iocbq *rspiocb)
  1558. {
  1559. struct lpfc_vport *vport = cmdiocb->vport;
  1560. /* even if it fails we will act as though it succeeded. */
  1561. vport->ct_flags = 0;
  1562. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1563. return;
  1564. }
  1565. static void
  1566. lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1567. struct lpfc_iocbq *rspiocb)
  1568. {
  1569. struct lpfc_vport *vport = cmdiocb->vport;
  1570. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1571. if (ulp_status == IOSTAT_SUCCESS) {
  1572. struct lpfc_dmabuf *outp;
  1573. struct lpfc_sli_ct_request *CTrsp;
  1574. outp = cmdiocb->rsp_dmabuf;
  1575. CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
  1576. if (CTrsp->CommandResponse.bits.CmdRsp ==
  1577. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  1578. vport->ct_flags |= FC_CT_RFF_ID;
  1579. }
  1580. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1581. return;
  1582. }
  1583. /*
  1584. * Although the symbolic port name is thought to be an integer
  1585. * as of January 18, 2016, leave it as a string until more of
  1586. * the record state becomes defined.
  1587. */
  1588. int
  1589. lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
  1590. size_t size)
  1591. {
  1592. int n;
  1593. /*
  1594. * Use the lpfc board number as the Symbolic Port
  1595. * Name object. NPIV is not in play so this integer
  1596. * value is sufficient and unique per FC-ID.
  1597. */
  1598. n = scnprintf(symbol, size, "%d", vport->phba->brd_no);
  1599. return n;
  1600. }
  1601. int
  1602. lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
  1603. size_t size)
  1604. {
  1605. char fwrev[FW_REV_STR_SIZE] = {0};
  1606. char tmp[MAXHOSTNAMELEN] = {0};
  1607. memset(symbol, 0, size);
  1608. scnprintf(tmp, sizeof(tmp), "Emulex %s", vport->phba->ModelName);
  1609. if (strlcat(symbol, tmp, size) >= size)
  1610. goto buffer_done;
  1611. lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
  1612. scnprintf(tmp, sizeof(tmp), " FV%s", fwrev);
  1613. if (strlcat(symbol, tmp, size) >= size)
  1614. goto buffer_done;
  1615. scnprintf(tmp, sizeof(tmp), " DV%s", lpfc_release_version);
  1616. if (strlcat(symbol, tmp, size) >= size)
  1617. goto buffer_done;
  1618. scnprintf(tmp, sizeof(tmp), " HN:%s", vport->phba->os_host_name);
  1619. if (strlcat(symbol, tmp, size) >= size)
  1620. goto buffer_done;
  1621. /* Note :- OS name is "Linux" */
  1622. scnprintf(tmp, sizeof(tmp), " OS:%s", init_utsname()->sysname);
  1623. strlcat(symbol, tmp, size);
  1624. buffer_done:
  1625. return strnlen(symbol, size);
  1626. }
  1627. static uint32_t
  1628. lpfc_find_map_node(struct lpfc_vport *vport)
  1629. {
  1630. struct lpfc_nodelist *ndlp, *next_ndlp;
  1631. struct Scsi_Host *shost;
  1632. uint32_t cnt = 0;
  1633. shost = lpfc_shost_from_vport(vport);
  1634. spin_lock_irq(shost->host_lock);
  1635. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1636. if (ndlp->nlp_type & NLP_FABRIC)
  1637. continue;
  1638. if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
  1639. (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
  1640. cnt++;
  1641. }
  1642. spin_unlock_irq(shost->host_lock);
  1643. return cnt;
  1644. }
  1645. /*
  1646. * This routine will return the FC4 Type associated with the CT
  1647. * GID_FT command.
  1648. */
  1649. int
  1650. lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
  1651. {
  1652. struct lpfc_sli_ct_request *CtReq;
  1653. struct lpfc_dmabuf *mp;
  1654. uint32_t type;
  1655. mp = cmdiocb->cmd_dmabuf;
  1656. if (mp == NULL)
  1657. return 0;
  1658. CtReq = (struct lpfc_sli_ct_request *)mp->virt;
  1659. type = (uint32_t)CtReq->un.gid.Fc4Type;
  1660. if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
  1661. return 0;
  1662. return type;
  1663. }
  1664. /*
  1665. * lpfc_ns_cmd
  1666. * Description:
  1667. * Issue Cmd to NameServer
  1668. * SLI_CTNS_GID_FT
  1669. * LI_CTNS_RFT_ID
  1670. */
  1671. int
  1672. lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
  1673. uint8_t retry, uint32_t context)
  1674. {
  1675. struct lpfc_nodelist * ndlp;
  1676. struct lpfc_hba *phba = vport->phba;
  1677. struct lpfc_dmabuf *mp, *bmp;
  1678. struct lpfc_sli_ct_request *CtReq;
  1679. struct ulp_bde64 *bpl;
  1680. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  1681. struct lpfc_iocbq *) = NULL;
  1682. uint32_t *ptr;
  1683. uint32_t rsp_size = 1024;
  1684. size_t size;
  1685. int rc = 0;
  1686. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  1687. if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
  1688. rc=1;
  1689. goto ns_cmd_exit;
  1690. }
  1691. /* fill in BDEs for command */
  1692. /* Allocate buffer for command payload */
  1693. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1694. if (!mp) {
  1695. rc=2;
  1696. goto ns_cmd_exit;
  1697. }
  1698. INIT_LIST_HEAD(&mp->list);
  1699. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  1700. if (!mp->virt) {
  1701. rc=3;
  1702. goto ns_cmd_free_mp;
  1703. }
  1704. /* Allocate buffer for Buffer ptr list */
  1705. bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1706. if (!bmp) {
  1707. rc=4;
  1708. goto ns_cmd_free_mpvirt;
  1709. }
  1710. INIT_LIST_HEAD(&bmp->list);
  1711. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
  1712. if (!bmp->virt) {
  1713. rc=5;
  1714. goto ns_cmd_free_bmp;
  1715. }
  1716. /* NameServer Req */
  1717. lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
  1718. "0236 NameServer Req Data: x%x x%x x%x x%x\n",
  1719. cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
  1720. context);
  1721. bpl = (struct ulp_bde64 *) bmp->virt;
  1722. memset(bpl, 0, sizeof(struct ulp_bde64));
  1723. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  1724. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  1725. bpl->tus.f.bdeFlags = 0;
  1726. if (cmdcode == SLI_CTNS_GID_FT)
  1727. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  1728. else if (cmdcode == SLI_CTNS_GID_PT)
  1729. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  1730. else if (cmdcode == SLI_CTNS_GFF_ID)
  1731. bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
  1732. else if (cmdcode == SLI_CTNS_GFT_ID)
  1733. bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
  1734. else if (cmdcode == SLI_CTNS_RFT_ID)
  1735. bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
  1736. else if (cmdcode == SLI_CTNS_RNN_ID)
  1737. bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
  1738. else if (cmdcode == SLI_CTNS_RSPN_ID)
  1739. bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
  1740. else if (cmdcode == SLI_CTNS_RSNN_NN)
  1741. bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
  1742. else if (cmdcode == SLI_CTNS_DA_ID)
  1743. bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
  1744. else if (cmdcode == SLI_CTNS_RFF_ID)
  1745. bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
  1746. else
  1747. bpl->tus.f.bdeSize = 0;
  1748. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1749. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  1750. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  1751. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  1752. CtReq->RevisionId.bits.InId = 0;
  1753. CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
  1754. CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
  1755. CtReq->CommandResponse.bits.Size = 0;
  1756. switch (cmdcode) {
  1757. case SLI_CTNS_GID_FT:
  1758. CtReq->CommandResponse.bits.CmdRsp =
  1759. cpu_to_be16(SLI_CTNS_GID_FT);
  1760. CtReq->un.gid.Fc4Type = context;
  1761. if (vport->port_state < LPFC_NS_QRY)
  1762. vport->port_state = LPFC_NS_QRY;
  1763. lpfc_set_disctmo(vport);
  1764. cmpl = lpfc_cmpl_ct_cmd_gid_ft;
  1765. rsp_size = FC_MAX_NS_RSP;
  1766. break;
  1767. case SLI_CTNS_GID_PT:
  1768. CtReq->CommandResponse.bits.CmdRsp =
  1769. cpu_to_be16(SLI_CTNS_GID_PT);
  1770. CtReq->un.gid.PortType = context;
  1771. if (vport->port_state < LPFC_NS_QRY)
  1772. vport->port_state = LPFC_NS_QRY;
  1773. lpfc_set_disctmo(vport);
  1774. cmpl = lpfc_cmpl_ct_cmd_gid_pt;
  1775. rsp_size = FC_MAX_NS_RSP;
  1776. break;
  1777. case SLI_CTNS_GFF_ID:
  1778. CtReq->CommandResponse.bits.CmdRsp =
  1779. cpu_to_be16(SLI_CTNS_GFF_ID);
  1780. CtReq->un.gff.PortId = cpu_to_be32(context);
  1781. cmpl = lpfc_cmpl_ct_cmd_gff_id;
  1782. break;
  1783. case SLI_CTNS_GFT_ID:
  1784. CtReq->CommandResponse.bits.CmdRsp =
  1785. cpu_to_be16(SLI_CTNS_GFT_ID);
  1786. CtReq->un.gft.PortId = cpu_to_be32(context);
  1787. cmpl = lpfc_cmpl_ct_cmd_gft_id;
  1788. break;
  1789. case SLI_CTNS_RFT_ID:
  1790. vport->ct_flags &= ~FC_CT_RFT_ID;
  1791. CtReq->CommandResponse.bits.CmdRsp =
  1792. cpu_to_be16(SLI_CTNS_RFT_ID);
  1793. CtReq->un.rft.port_id = cpu_to_be32(vport->fc_myDID);
  1794. /* Register Application Services type if vmid enabled. */
  1795. if (phba->cfg_vmid_app_header)
  1796. CtReq->un.rft.app_serv_reg =
  1797. cpu_to_be32(RFT_APP_SERV_REG);
  1798. /* Register FC4 FCP type if enabled. */
  1799. if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
  1800. vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
  1801. CtReq->un.rft.fcp_reg = cpu_to_be32(RFT_FCP_REG);
  1802. /* Register NVME type if enabled. */
  1803. if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
  1804. vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
  1805. CtReq->un.rft.nvme_reg = cpu_to_be32(RFT_NVME_REG);
  1806. ptr = (uint32_t *)CtReq;
  1807. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1808. "6433 Issue RFT (%s %s %s): %08x %08x %08x "
  1809. "%08x %08x %08x %08x %08x\n",
  1810. CtReq->un.rft.fcp_reg ? "FCP" : " ",
  1811. CtReq->un.rft.nvme_reg ? "NVME" : " ",
  1812. CtReq->un.rft.app_serv_reg ? "APPS" : " ",
  1813. *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
  1814. *(ptr + 4), *(ptr + 5),
  1815. *(ptr + 6), *(ptr + 7));
  1816. cmpl = lpfc_cmpl_ct_cmd_rft_id;
  1817. break;
  1818. case SLI_CTNS_RNN_ID:
  1819. vport->ct_flags &= ~FC_CT_RNN_ID;
  1820. CtReq->CommandResponse.bits.CmdRsp =
  1821. cpu_to_be16(SLI_CTNS_RNN_ID);
  1822. CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
  1823. memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
  1824. sizeof(struct lpfc_name));
  1825. cmpl = lpfc_cmpl_ct_cmd_rnn_id;
  1826. break;
  1827. case SLI_CTNS_RSPN_ID:
  1828. vport->ct_flags &= ~FC_CT_RSPN_ID;
  1829. CtReq->CommandResponse.bits.CmdRsp =
  1830. cpu_to_be16(SLI_CTNS_RSPN_ID);
  1831. CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
  1832. size = sizeof(CtReq->un.rspn.symbname);
  1833. CtReq->un.rspn.len =
  1834. lpfc_vport_symbolic_port_name(vport,
  1835. CtReq->un.rspn.symbname, size);
  1836. cmpl = lpfc_cmpl_ct_cmd_rspn_id;
  1837. break;
  1838. case SLI_CTNS_RSNN_NN:
  1839. vport->ct_flags &= ~FC_CT_RSNN_NN;
  1840. CtReq->CommandResponse.bits.CmdRsp =
  1841. cpu_to_be16(SLI_CTNS_RSNN_NN);
  1842. memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
  1843. sizeof(struct lpfc_name));
  1844. size = sizeof(CtReq->un.rsnn.symbname);
  1845. CtReq->un.rsnn.len =
  1846. lpfc_vport_symbolic_node_name(vport,
  1847. CtReq->un.rsnn.symbname, size);
  1848. cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
  1849. break;
  1850. case SLI_CTNS_DA_ID:
  1851. /* Implement DA_ID Nameserver request */
  1852. CtReq->CommandResponse.bits.CmdRsp =
  1853. cpu_to_be16(SLI_CTNS_DA_ID);
  1854. CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
  1855. cmpl = lpfc_cmpl_ct_cmd_da_id;
  1856. break;
  1857. case SLI_CTNS_RFF_ID:
  1858. vport->ct_flags &= ~FC_CT_RFF_ID;
  1859. CtReq->CommandResponse.bits.CmdRsp =
  1860. cpu_to_be16(SLI_CTNS_RFF_ID);
  1861. CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
  1862. CtReq->un.rff.fbits = FC4_FEATURE_INIT;
  1863. /* The driver always supports FC_TYPE_FCP. However, the
  1864. * caller can specify NVME (type x28) as well. But only
  1865. * these that FC4 type is supported.
  1866. */
  1867. if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
  1868. (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
  1869. (context == FC_TYPE_NVME)) {
  1870. if ((vport == phba->pport) && phba->nvmet_support) {
  1871. CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
  1872. FC4_FEATURE_NVME_DISC);
  1873. lpfc_nvmet_update_targetport(phba);
  1874. } else {
  1875. lpfc_nvme_update_localport(vport);
  1876. }
  1877. CtReq->un.rff.type_code = context;
  1878. } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
  1879. (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
  1880. (context == FC_TYPE_FCP))
  1881. CtReq->un.rff.type_code = context;
  1882. else
  1883. goto ns_cmd_free_bmpvirt;
  1884. ptr = (uint32_t *)CtReq;
  1885. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1886. "6434 Issue RFF (%s): %08x %08x %08x %08x "
  1887. "%08x %08x %08x %08x\n",
  1888. (context == FC_TYPE_NVME) ? "NVME" : "FCP",
  1889. *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
  1890. *(ptr + 4), *(ptr + 5),
  1891. *(ptr + 6), *(ptr + 7));
  1892. cmpl = lpfc_cmpl_ct_cmd_rff_id;
  1893. break;
  1894. }
  1895. /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  1896. * to hold ndlp reference for the corresponding callback function.
  1897. */
  1898. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
  1899. /* On success, The cmpl function will free the buffers */
  1900. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1901. "Issue CT cmd: cmd:x%x did:x%x",
  1902. cmdcode, ndlp->nlp_DID, 0);
  1903. return 0;
  1904. }
  1905. rc=6;
  1906. ns_cmd_free_bmpvirt:
  1907. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1908. ns_cmd_free_bmp:
  1909. kfree(bmp);
  1910. ns_cmd_free_mpvirt:
  1911. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1912. ns_cmd_free_mp:
  1913. kfree(mp);
  1914. ns_cmd_exit:
  1915. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1916. "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
  1917. cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
  1918. return 1;
  1919. }
  1920. /**
  1921. * lpfc_fdmi_rprt_defer - Check for any deferred FDMI RPRT commands
  1922. * @phba: Pointer to HBA context object.
  1923. * @mask: Initial port attributes mask
  1924. *
  1925. * This function checks to see if any vports have deferred their FDMI RPRT.
  1926. * A vports RPRT may be deferred if it is issued before the primary ports
  1927. * RHBA completes.
  1928. */
  1929. static void
  1930. lpfc_fdmi_rprt_defer(struct lpfc_hba *phba, uint32_t mask)
  1931. {
  1932. struct lpfc_vport **vports;
  1933. struct lpfc_vport *vport;
  1934. struct lpfc_nodelist *ndlp;
  1935. int i;
  1936. phba->hba_flag |= HBA_RHBA_CMPL;
  1937. vports = lpfc_create_vport_work_array(phba);
  1938. if (vports) {
  1939. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  1940. vport = vports[i];
  1941. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  1942. if (!ndlp)
  1943. continue;
  1944. if (vport->ct_flags & FC_CT_RPRT_DEFER) {
  1945. vport->ct_flags &= ~FC_CT_RPRT_DEFER;
  1946. vport->fdmi_port_mask = mask;
  1947. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
  1948. }
  1949. }
  1950. }
  1951. lpfc_destroy_vport_work_array(phba, vports);
  1952. }
  1953. /**
  1954. * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
  1955. * @phba: Pointer to HBA context object.
  1956. * @cmdiocb: Pointer to the command IOCBQ.
  1957. * @rspiocb: Pointer to the response IOCBQ.
  1958. *
  1959. * This function to handle the completion of a driver initiated FDMI
  1960. * CT command issued during discovery.
  1961. */
  1962. static void
  1963. lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1964. struct lpfc_iocbq *rspiocb)
  1965. {
  1966. struct lpfc_vport *vport = cmdiocb->vport;
  1967. struct lpfc_dmabuf *inp = cmdiocb->cmd_dmabuf;
  1968. struct lpfc_dmabuf *outp = cmdiocb->rsp_dmabuf;
  1969. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  1970. struct lpfc_sli_ct_request *CTrsp = outp->virt;
  1971. uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  1972. uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
  1973. struct lpfc_nodelist *ndlp, *free_ndlp = NULL;
  1974. uint32_t latt, cmd, err;
  1975. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1976. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  1977. latt = lpfc_els_chk_latt(vport);
  1978. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1979. "FDMI cmpl: status:x%x/x%x latt:%d",
  1980. ulp_status, ulp_word4, latt);
  1981. if (latt || ulp_status) {
  1982. /* Look for a retryable error */
  1983. if (ulp_status == IOSTAT_LOCAL_REJECT) {
  1984. switch ((ulp_word4 & IOERR_PARAM_MASK)) {
  1985. case IOERR_SLI_ABORTED:
  1986. case IOERR_SLI_DOWN:
  1987. /* Driver aborted this IO. No retry as error
  1988. * is likely Offline->Online or some adapter
  1989. * error. Recovery will try again.
  1990. */
  1991. break;
  1992. case IOERR_ABORT_IN_PROGRESS:
  1993. case IOERR_SEQUENCE_TIMEOUT:
  1994. case IOERR_ILLEGAL_FRAME:
  1995. case IOERR_NO_RESOURCES:
  1996. case IOERR_ILLEGAL_COMMAND:
  1997. cmdiocb->retry++;
  1998. if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
  1999. break;
  2000. /* Retry the same FDMI command */
  2001. err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
  2002. cmdiocb, 0);
  2003. if (err == IOCB_ERROR)
  2004. break;
  2005. return;
  2006. default:
  2007. break;
  2008. }
  2009. }
  2010. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2011. "0229 FDMI cmd %04x failed, latt = %d "
  2012. "ulp_status: x%x, rid x%x\n",
  2013. be16_to_cpu(fdmi_cmd), latt, ulp_status,
  2014. ulp_word4);
  2015. }
  2016. free_ndlp = cmdiocb->ndlp;
  2017. lpfc_ct_free_iocb(phba, cmdiocb);
  2018. lpfc_nlp_put(free_ndlp);
  2019. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  2020. if (!ndlp)
  2021. return;
  2022. /* Check for a CT LS_RJT response */
  2023. cmd = be16_to_cpu(fdmi_cmd);
  2024. if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
  2025. /* FDMI rsp failed */
  2026. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY | LOG_ELS,
  2027. "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
  2028. /* Should we fallback to FDMI-2 / FDMI-1 ? */
  2029. switch (cmd) {
  2030. case SLI_MGMT_RHBA:
  2031. if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
  2032. /* Fallback to FDMI-1 for HBA attributes */
  2033. vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
  2034. /* If HBA attributes are FDMI1, so should
  2035. * port attributes be for consistency.
  2036. */
  2037. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  2038. /* Start over */
  2039. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
  2040. }
  2041. return;
  2042. case SLI_MGMT_RPRT:
  2043. if (vport->port_type != LPFC_PHYSICAL_PORT) {
  2044. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2045. if (!ndlp)
  2046. return;
  2047. }
  2048. if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
  2049. /* Fallback to FDMI-1 */
  2050. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  2051. /* Start over */
  2052. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  2053. return;
  2054. }
  2055. if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
  2056. vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
  2057. /* Retry the same command */
  2058. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  2059. }
  2060. return;
  2061. case SLI_MGMT_RPA:
  2062. /* No retry on Vendor, RPA only done on physical port */
  2063. if (phba->link_flag & LS_CT_VEN_RPA) {
  2064. phba->link_flag &= ~LS_CT_VEN_RPA;
  2065. if (phba->cmf_active_mode == LPFC_CFG_OFF)
  2066. return;
  2067. lpfc_printf_log(phba, KERN_WARNING,
  2068. LOG_DISCOVERY | LOG_ELS,
  2069. "6460 VEN FDMI RPA RJT\n");
  2070. return;
  2071. }
  2072. if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
  2073. /* Fallback to FDMI-1 */
  2074. vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
  2075. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  2076. /* Start over */
  2077. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
  2078. return;
  2079. }
  2080. if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
  2081. vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
  2082. /* Retry the same command */
  2083. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  2084. }
  2085. return;
  2086. }
  2087. }
  2088. /*
  2089. * On success, need to cycle thru FDMI registration for discovery
  2090. * DHBA -> DPRT -> RHBA -> RPA (physical port)
  2091. * DPRT -> RPRT (vports)
  2092. */
  2093. switch (cmd) {
  2094. case SLI_MGMT_RHBA:
  2095. /* Check for any RPRTs deferred till after RHBA completes */
  2096. lpfc_fdmi_rprt_defer(phba, vport->fdmi_port_mask);
  2097. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
  2098. break;
  2099. case SLI_MGMT_DHBA:
  2100. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
  2101. break;
  2102. case SLI_MGMT_DPRT:
  2103. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  2104. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
  2105. } else {
  2106. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2107. if (!ndlp)
  2108. return;
  2109. /* Only issue a RPRT for the vport if the RHBA
  2110. * for the physical port completes successfully.
  2111. * We may have to defer the RPRT accordingly.
  2112. */
  2113. if (phba->hba_flag & HBA_RHBA_CMPL) {
  2114. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
  2115. } else {
  2116. lpfc_printf_vlog(vport, KERN_INFO,
  2117. LOG_DISCOVERY,
  2118. "6078 RPRT deferred\n");
  2119. vport->ct_flags |= FC_CT_RPRT_DEFER;
  2120. }
  2121. }
  2122. break;
  2123. case SLI_MGMT_RPA:
  2124. if (vport->port_type == LPFC_PHYSICAL_PORT &&
  2125. phba->sli4_hba.pc_sli4_params.mi_ver) {
  2126. /* mi is only for the phyical port, no vports */
  2127. if (phba->link_flag & LS_CT_VEN_RPA) {
  2128. lpfc_printf_vlog(vport, KERN_INFO,
  2129. LOG_DISCOVERY | LOG_ELS |
  2130. LOG_CGN_MGMT,
  2131. "6449 VEN RPA FDMI Success\n");
  2132. phba->link_flag &= ~LS_CT_VEN_RPA;
  2133. break;
  2134. }
  2135. lpfc_printf_log(phba, KERN_INFO,
  2136. LOG_DISCOVERY | LOG_CGN_MGMT,
  2137. "6210 Issue Vendor MI FDMI %x\n",
  2138. phba->sli4_hba.pc_sli4_params.mi_ver);
  2139. /* CGN is only for the physical port, no vports */
  2140. if (lpfc_fdmi_cmd(vport, ndlp, cmd,
  2141. LPFC_FDMI_VENDOR_ATTR_mi) == 0)
  2142. phba->link_flag |= LS_CT_VEN_RPA;
  2143. lpfc_printf_log(phba, KERN_INFO,
  2144. LOG_DISCOVERY | LOG_ELS,
  2145. "6458 Send MI FDMI:%x Flag x%x\n",
  2146. phba->sli4_hba.pc_sli4_params.mi_ver,
  2147. phba->link_flag);
  2148. } else {
  2149. lpfc_printf_log(phba, KERN_INFO,
  2150. LOG_DISCOVERY | LOG_ELS,
  2151. "6459 No FDMI VEN MI support - "
  2152. "RPA Success\n");
  2153. }
  2154. break;
  2155. }
  2156. return;
  2157. }
  2158. /**
  2159. * lpfc_fdmi_change_check - Check for changed FDMI parameters
  2160. * @vport: pointer to a host virtual N_Port data structure.
  2161. *
  2162. * Check how many mapped NPorts we are connected to
  2163. * Check if our hostname changed
  2164. * Called from hbeat timeout routine to check if any FDMI parameters
  2165. * changed. If so, re-register those Attributes.
  2166. */
  2167. void
  2168. lpfc_fdmi_change_check(struct lpfc_vport *vport)
  2169. {
  2170. struct lpfc_hba *phba = vport->phba;
  2171. struct lpfc_nodelist *ndlp;
  2172. uint16_t cnt;
  2173. if (!lpfc_is_link_up(phba))
  2174. return;
  2175. /* Must be connected to a Fabric */
  2176. if (!(vport->fc_flag & FC_FABRIC))
  2177. return;
  2178. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  2179. if (!ndlp)
  2180. return;
  2181. /* Check if system hostname changed */
  2182. if (strcmp(phba->os_host_name, init_utsname()->nodename)) {
  2183. memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
  2184. scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
  2185. init_utsname()->nodename);
  2186. lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
  2187. /* Since this effects multiple HBA and PORT attributes, we need
  2188. * de-register and go thru the whole FDMI registration cycle.
  2189. * DHBA -> DPRT -> RHBA -> RPA (physical port)
  2190. * DPRT -> RPRT (vports)
  2191. */
  2192. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  2193. /* For extra Vendor RPA */
  2194. phba->link_flag &= ~LS_CT_VEN_RPA;
  2195. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
  2196. } else {
  2197. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2198. if (!ndlp)
  2199. return;
  2200. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
  2201. }
  2202. /* Since this code path registers all the port attributes
  2203. * we can just return without further checking.
  2204. */
  2205. return;
  2206. }
  2207. if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
  2208. return;
  2209. /* Check if the number of mapped NPorts changed */
  2210. cnt = lpfc_find_map_node(vport);
  2211. if (cnt == vport->fdmi_num_disc)
  2212. return;
  2213. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  2214. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
  2215. LPFC_FDMI_PORT_ATTR_num_disc);
  2216. } else {
  2217. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2218. if (!ndlp)
  2219. return;
  2220. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
  2221. LPFC_FDMI_PORT_ATTR_num_disc);
  2222. }
  2223. }
  2224. static inline int
  2225. lpfc_fdmi_set_attr_u32(void *attr, uint16_t attrtype, uint32_t attrval)
  2226. {
  2227. struct lpfc_fdmi_attr_u32 *ae = attr;
  2228. int size = sizeof(*ae);
  2229. ae->type = cpu_to_be16(attrtype);
  2230. ae->len = cpu_to_be16(size);
  2231. ae->value_u32 = cpu_to_be32(attrval);
  2232. return size;
  2233. }
  2234. static inline int
  2235. lpfc_fdmi_set_attr_wwn(void *attr, uint16_t attrtype, struct lpfc_name *wwn)
  2236. {
  2237. struct lpfc_fdmi_attr_wwn *ae = attr;
  2238. int size = sizeof(*ae);
  2239. ae->type = cpu_to_be16(attrtype);
  2240. ae->len = cpu_to_be16(size);
  2241. /* WWN's assumed to be bytestreams - Big Endian presentation */
  2242. memcpy(ae->name, wwn,
  2243. min_t(size_t, sizeof(struct lpfc_name), sizeof(__be64)));
  2244. return size;
  2245. }
  2246. static inline int
  2247. lpfc_fdmi_set_attr_fullwwn(void *attr, uint16_t attrtype,
  2248. struct lpfc_name *wwnn, struct lpfc_name *wwpn)
  2249. {
  2250. struct lpfc_fdmi_attr_fullwwn *ae = attr;
  2251. u8 *nname = ae->nname;
  2252. u8 *pname = ae->pname;
  2253. int size = sizeof(*ae);
  2254. ae->type = cpu_to_be16(attrtype);
  2255. ae->len = cpu_to_be16(size);
  2256. /* WWN's assumed to be bytestreams - Big Endian presentation */
  2257. memcpy(nname, wwnn,
  2258. min_t(size_t, sizeof(struct lpfc_name), sizeof(__be64)));
  2259. memcpy(pname, wwpn,
  2260. min_t(size_t, sizeof(struct lpfc_name), sizeof(__be64)));
  2261. return size;
  2262. }
  2263. static inline int
  2264. lpfc_fdmi_set_attr_string(void *attr, uint16_t attrtype, char *attrstring)
  2265. {
  2266. struct lpfc_fdmi_attr_string *ae = attr;
  2267. int len, size;
  2268. /*
  2269. * We are trusting the caller that if a fdmi string field
  2270. * is capped at 64 bytes, the caller passes in a string of
  2271. * 64 bytes or less.
  2272. */
  2273. strncpy(ae->value_string, attrstring, sizeof(ae->value_string));
  2274. len = strnlen(ae->value_string, sizeof(ae->value_string));
  2275. /* round string length to a 32bit boundary. Ensure there's a NULL */
  2276. len += (len & 3) ? (4 - (len & 3)) : 4;
  2277. /* size is Type/Len (4 bytes) plus string length */
  2278. size = FOURBYTES + len;
  2279. ae->type = cpu_to_be16(attrtype);
  2280. ae->len = cpu_to_be16(size);
  2281. return size;
  2282. }
  2283. /* Bitfields for FC4 Types that can be reported */
  2284. #define ATTR_FC4_CT 0x00000001
  2285. #define ATTR_FC4_FCP 0x00000002
  2286. #define ATTR_FC4_NVME 0x00000004
  2287. static inline int
  2288. lpfc_fdmi_set_attr_fc4types(void *attr, uint16_t attrtype, uint32_t typemask)
  2289. {
  2290. struct lpfc_fdmi_attr_fc4types *ae = attr;
  2291. int size = sizeof(*ae);
  2292. ae->type = cpu_to_be16(attrtype);
  2293. ae->len = cpu_to_be16(size);
  2294. if (typemask & ATTR_FC4_FCP)
  2295. ae->value_types[2] = 0x01; /* Type 0x8 - FCP */
  2296. if (typemask & ATTR_FC4_CT)
  2297. ae->value_types[7] = 0x01; /* Type 0x20 - CT */
  2298. if (typemask & ATTR_FC4_NVME)
  2299. ae->value_types[6] = 0x01; /* Type 0x28 - NVME */
  2300. return size;
  2301. }
  2302. /* Routines for all individual HBA attributes */
  2303. static int
  2304. lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, void *attr)
  2305. {
  2306. return lpfc_fdmi_set_attr_wwn(attr, RHBA_NODENAME,
  2307. &vport->fc_sparam.nodeName);
  2308. }
  2309. static int
  2310. lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport, void *attr)
  2311. {
  2312. /* This string MUST be consistent with other FC platforms
  2313. * supported by Broadcom.
  2314. */
  2315. return lpfc_fdmi_set_attr_string(attr, RHBA_MANUFACTURER,
  2316. "Emulex Corporation");
  2317. }
  2318. static int
  2319. lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, void *attr)
  2320. {
  2321. struct lpfc_hba *phba = vport->phba;
  2322. return lpfc_fdmi_set_attr_string(attr, RHBA_SERIAL_NUMBER,
  2323. phba->SerialNumber);
  2324. }
  2325. static int
  2326. lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport, void *attr)
  2327. {
  2328. struct lpfc_hba *phba = vport->phba;
  2329. return lpfc_fdmi_set_attr_string(attr, RHBA_MODEL,
  2330. phba->ModelName);
  2331. }
  2332. static int
  2333. lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport, void *attr)
  2334. {
  2335. struct lpfc_hba *phba = vport->phba;
  2336. return lpfc_fdmi_set_attr_string(attr, RHBA_MODEL_DESCRIPTION,
  2337. phba->ModelDesc);
  2338. }
  2339. static int
  2340. lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport, void *attr)
  2341. {
  2342. struct lpfc_hba *phba = vport->phba;
  2343. lpfc_vpd_t *vp = &phba->vpd;
  2344. char buf[16] = { 0 };
  2345. snprintf(buf, sizeof(buf), "%08x", vp->rev.biuRev);
  2346. return lpfc_fdmi_set_attr_string(attr, RHBA_HARDWARE_VERSION, buf);
  2347. }
  2348. static int
  2349. lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport, void *attr)
  2350. {
  2351. return lpfc_fdmi_set_attr_string(attr, RHBA_DRIVER_VERSION,
  2352. lpfc_release_version);
  2353. }
  2354. static int
  2355. lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport, void *attr)
  2356. {
  2357. struct lpfc_hba *phba = vport->phba;
  2358. char buf[64] = { 0 };
  2359. if (phba->sli_rev == LPFC_SLI_REV4) {
  2360. lpfc_decode_firmware_rev(phba, buf, 1);
  2361. return lpfc_fdmi_set_attr_string(attr, RHBA_OPTION_ROM_VERSION,
  2362. buf);
  2363. }
  2364. return lpfc_fdmi_set_attr_string(attr, RHBA_OPTION_ROM_VERSION,
  2365. phba->OptionROMVersion);
  2366. }
  2367. static int
  2368. lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport, void *attr)
  2369. {
  2370. struct lpfc_hba *phba = vport->phba;
  2371. char buf[64] = { 0 };
  2372. lpfc_decode_firmware_rev(phba, buf, 1);
  2373. return lpfc_fdmi_set_attr_string(attr, RHBA_FIRMWARE_VERSION, buf);
  2374. }
  2375. static int
  2376. lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport, void *attr)
  2377. {
  2378. char buf[256] = { 0 };
  2379. snprintf(buf, sizeof(buf), "%s %s %s",
  2380. init_utsname()->sysname,
  2381. init_utsname()->release,
  2382. init_utsname()->version);
  2383. return lpfc_fdmi_set_attr_string(attr, RHBA_OS_NAME_VERSION, buf);
  2384. }
  2385. static int
  2386. lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport, void *attr)
  2387. {
  2388. return lpfc_fdmi_set_attr_u32(attr, RHBA_MAX_CT_PAYLOAD_LEN,
  2389. LPFC_MAX_CT_SIZE);
  2390. }
  2391. static int
  2392. lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport, void *attr)
  2393. {
  2394. char buf[256] = { 0 };
  2395. lpfc_vport_symbolic_node_name(vport, buf, sizeof(buf));
  2396. return lpfc_fdmi_set_attr_string(attr, RHBA_SYM_NODENAME, buf);
  2397. }
  2398. static int
  2399. lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport, void *attr)
  2400. {
  2401. return lpfc_fdmi_set_attr_u32(attr, RHBA_VENDOR_INFO, 0);
  2402. }
  2403. static int
  2404. lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport, void *attr)
  2405. {
  2406. /* Each driver instance corresponds to a single port */
  2407. return lpfc_fdmi_set_attr_u32(attr, RHBA_NUM_PORTS, 1);
  2408. }
  2409. static int
  2410. lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport, void *attr)
  2411. {
  2412. return lpfc_fdmi_set_attr_wwn(attr, RHBA_FABRIC_WWNN,
  2413. &vport->fabric_nodename);
  2414. }
  2415. static int
  2416. lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport, void *attr)
  2417. {
  2418. struct lpfc_hba *phba = vport->phba;
  2419. return lpfc_fdmi_set_attr_string(attr, RHBA_BIOS_VERSION,
  2420. phba->BIOSVersion);
  2421. }
  2422. static int
  2423. lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport, void *attr)
  2424. {
  2425. /* Driver doesn't have access to this information */
  2426. return lpfc_fdmi_set_attr_u32(attr, RHBA_BIOS_STATE, 0);
  2427. }
  2428. static int
  2429. lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport, void *attr)
  2430. {
  2431. return lpfc_fdmi_set_attr_string(attr, RHBA_VENDOR_ID, "EMULEX");
  2432. }
  2433. /*
  2434. * Routines for all individual PORT attributes
  2435. */
  2436. static int
  2437. lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport, void *attr)
  2438. {
  2439. struct lpfc_hba *phba = vport->phba;
  2440. u32 fc4types;
  2441. fc4types = (ATTR_FC4_CT | ATTR_FC4_FCP);
  2442. /* Check to see if Firmware supports NVME and on physical port */
  2443. if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) &&
  2444. phba->sli4_hba.pc_sli4_params.nvme)
  2445. fc4types |= ATTR_FC4_NVME;
  2446. return lpfc_fdmi_set_attr_fc4types(attr, RPRT_SUPPORTED_FC4_TYPES,
  2447. fc4types);
  2448. }
  2449. static int
  2450. lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport, void *attr)
  2451. {
  2452. struct lpfc_hba *phba = vport->phba;
  2453. u32 speeds = 0;
  2454. u32 tcfg;
  2455. u8 i, cnt;
  2456. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  2457. cnt = 0;
  2458. if (phba->sli_rev == LPFC_SLI_REV4) {
  2459. tcfg = phba->sli4_hba.conf_trunk;
  2460. for (i = 0; i < 4; i++, tcfg >>= 1)
  2461. if (tcfg & 1)
  2462. cnt++;
  2463. }
  2464. if (cnt > 2) { /* 4 lane trunk group */
  2465. if (phba->lmt & LMT_64Gb)
  2466. speeds |= HBA_PORTSPEED_256GFC;
  2467. if (phba->lmt & LMT_32Gb)
  2468. speeds |= HBA_PORTSPEED_128GFC;
  2469. if (phba->lmt & LMT_16Gb)
  2470. speeds |= HBA_PORTSPEED_64GFC;
  2471. } else if (cnt) { /* 2 lane trunk group */
  2472. if (phba->lmt & LMT_128Gb)
  2473. speeds |= HBA_PORTSPEED_256GFC;
  2474. if (phba->lmt & LMT_64Gb)
  2475. speeds |= HBA_PORTSPEED_128GFC;
  2476. if (phba->lmt & LMT_32Gb)
  2477. speeds |= HBA_PORTSPEED_64GFC;
  2478. if (phba->lmt & LMT_16Gb)
  2479. speeds |= HBA_PORTSPEED_32GFC;
  2480. } else {
  2481. if (phba->lmt & LMT_256Gb)
  2482. speeds |= HBA_PORTSPEED_256GFC;
  2483. if (phba->lmt & LMT_128Gb)
  2484. speeds |= HBA_PORTSPEED_128GFC;
  2485. if (phba->lmt & LMT_64Gb)
  2486. speeds |= HBA_PORTSPEED_64GFC;
  2487. if (phba->lmt & LMT_32Gb)
  2488. speeds |= HBA_PORTSPEED_32GFC;
  2489. if (phba->lmt & LMT_16Gb)
  2490. speeds |= HBA_PORTSPEED_16GFC;
  2491. if (phba->lmt & LMT_10Gb)
  2492. speeds |= HBA_PORTSPEED_10GFC;
  2493. if (phba->lmt & LMT_8Gb)
  2494. speeds |= HBA_PORTSPEED_8GFC;
  2495. if (phba->lmt & LMT_4Gb)
  2496. speeds |= HBA_PORTSPEED_4GFC;
  2497. if (phba->lmt & LMT_2Gb)
  2498. speeds |= HBA_PORTSPEED_2GFC;
  2499. if (phba->lmt & LMT_1Gb)
  2500. speeds |= HBA_PORTSPEED_1GFC;
  2501. }
  2502. } else {
  2503. /* FCoE links support only one speed */
  2504. switch (phba->fc_linkspeed) {
  2505. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  2506. speeds = HBA_PORTSPEED_10GE;
  2507. break;
  2508. case LPFC_ASYNC_LINK_SPEED_25GBPS:
  2509. speeds = HBA_PORTSPEED_25GE;
  2510. break;
  2511. case LPFC_ASYNC_LINK_SPEED_40GBPS:
  2512. speeds = HBA_PORTSPEED_40GE;
  2513. break;
  2514. case LPFC_ASYNC_LINK_SPEED_100GBPS:
  2515. speeds = HBA_PORTSPEED_100GE;
  2516. break;
  2517. }
  2518. }
  2519. return lpfc_fdmi_set_attr_u32(attr, RPRT_SUPPORTED_SPEED, speeds);
  2520. }
  2521. static int
  2522. lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport, void *attr)
  2523. {
  2524. struct lpfc_hba *phba = vport->phba;
  2525. u32 speeds = 0;
  2526. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  2527. switch (phba->fc_linkspeed) {
  2528. case LPFC_LINK_SPEED_1GHZ:
  2529. speeds = HBA_PORTSPEED_1GFC;
  2530. break;
  2531. case LPFC_LINK_SPEED_2GHZ:
  2532. speeds = HBA_PORTSPEED_2GFC;
  2533. break;
  2534. case LPFC_LINK_SPEED_4GHZ:
  2535. speeds = HBA_PORTSPEED_4GFC;
  2536. break;
  2537. case LPFC_LINK_SPEED_8GHZ:
  2538. speeds = HBA_PORTSPEED_8GFC;
  2539. break;
  2540. case LPFC_LINK_SPEED_10GHZ:
  2541. speeds = HBA_PORTSPEED_10GFC;
  2542. break;
  2543. case LPFC_LINK_SPEED_16GHZ:
  2544. speeds = HBA_PORTSPEED_16GFC;
  2545. break;
  2546. case LPFC_LINK_SPEED_32GHZ:
  2547. speeds = HBA_PORTSPEED_32GFC;
  2548. break;
  2549. case LPFC_LINK_SPEED_64GHZ:
  2550. speeds = HBA_PORTSPEED_64GFC;
  2551. break;
  2552. case LPFC_LINK_SPEED_128GHZ:
  2553. speeds = HBA_PORTSPEED_128GFC;
  2554. break;
  2555. case LPFC_LINK_SPEED_256GHZ:
  2556. speeds = HBA_PORTSPEED_256GFC;
  2557. break;
  2558. default:
  2559. speeds = HBA_PORTSPEED_UNKNOWN;
  2560. break;
  2561. }
  2562. } else {
  2563. switch (phba->fc_linkspeed) {
  2564. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  2565. speeds = HBA_PORTSPEED_10GE;
  2566. break;
  2567. case LPFC_ASYNC_LINK_SPEED_25GBPS:
  2568. speeds = HBA_PORTSPEED_25GE;
  2569. break;
  2570. case LPFC_ASYNC_LINK_SPEED_40GBPS:
  2571. speeds = HBA_PORTSPEED_40GE;
  2572. break;
  2573. case LPFC_ASYNC_LINK_SPEED_100GBPS:
  2574. speeds = HBA_PORTSPEED_100GE;
  2575. break;
  2576. default:
  2577. speeds = HBA_PORTSPEED_UNKNOWN;
  2578. break;
  2579. }
  2580. }
  2581. return lpfc_fdmi_set_attr_u32(attr, RPRT_PORT_SPEED, speeds);
  2582. }
  2583. static int
  2584. lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport, void *attr)
  2585. {
  2586. struct serv_parm *hsp = (struct serv_parm *)&vport->fc_sparam;
  2587. return lpfc_fdmi_set_attr_u32(attr, RPRT_MAX_FRAME_SIZE,
  2588. (((uint32_t)hsp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  2589. (uint32_t)hsp->cmn.bbRcvSizeLsb);
  2590. }
  2591. static int
  2592. lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport, void *attr)
  2593. {
  2594. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2595. char buf[64] = { 0 };
  2596. snprintf(buf, sizeof(buf), "/sys/class/scsi_host/host%d",
  2597. shost->host_no);
  2598. return lpfc_fdmi_set_attr_string(attr, RPRT_OS_DEVICE_NAME, buf);
  2599. }
  2600. static int
  2601. lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport, void *attr)
  2602. {
  2603. char buf[64] = { 0 };
  2604. scnprintf(buf, sizeof(buf), "%s", vport->phba->os_host_name);
  2605. return lpfc_fdmi_set_attr_string(attr, RPRT_HOST_NAME, buf);
  2606. }
  2607. static int
  2608. lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport, void *attr)
  2609. {
  2610. return lpfc_fdmi_set_attr_wwn(attr, RPRT_NODENAME,
  2611. &vport->fc_sparam.nodeName);
  2612. }
  2613. static int
  2614. lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport, void *attr)
  2615. {
  2616. return lpfc_fdmi_set_attr_wwn(attr, RPRT_PORTNAME,
  2617. &vport->fc_sparam.portName);
  2618. }
  2619. static int
  2620. lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport, void *attr)
  2621. {
  2622. char buf[256] = { 0 };
  2623. lpfc_vport_symbolic_port_name(vport, buf, sizeof(buf));
  2624. return lpfc_fdmi_set_attr_string(attr, RPRT_SYM_PORTNAME, buf);
  2625. }
  2626. static int
  2627. lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport, void *attr)
  2628. {
  2629. struct lpfc_hba *phba = vport->phba;
  2630. return lpfc_fdmi_set_attr_u32(attr, RPRT_PORT_TYPE,
  2631. (phba->fc_topology == LPFC_TOPOLOGY_LOOP) ?
  2632. LPFC_FDMI_PORTTYPE_NLPORT :
  2633. LPFC_FDMI_PORTTYPE_NPORT);
  2634. }
  2635. static int
  2636. lpfc_fdmi_port_attr_class(struct lpfc_vport *vport, void *attr)
  2637. {
  2638. return lpfc_fdmi_set_attr_u32(attr, RPRT_SUPPORTED_CLASS,
  2639. FC_COS_CLASS2 | FC_COS_CLASS3);
  2640. }
  2641. static int
  2642. lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport, void *attr)
  2643. {
  2644. return lpfc_fdmi_set_attr_wwn(attr, RPRT_FABRICNAME,
  2645. &vport->fabric_portname);
  2646. }
  2647. static int
  2648. lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport, void *attr)
  2649. {
  2650. struct lpfc_hba *phba = vport->phba;
  2651. u32 fc4types;
  2652. fc4types = (ATTR_FC4_CT | ATTR_FC4_FCP);
  2653. /* Check to see if NVME is configured or not */
  2654. if (vport == phba->pport &&
  2655. phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
  2656. fc4types |= ATTR_FC4_NVME;
  2657. return lpfc_fdmi_set_attr_fc4types(attr, RPRT_ACTIVE_FC4_TYPES,
  2658. fc4types);
  2659. }
  2660. static int
  2661. lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport, void *attr)
  2662. {
  2663. return lpfc_fdmi_set_attr_u32(attr, RPRT_PORT_STATE,
  2664. LPFC_FDMI_PORTSTATE_ONLINE);
  2665. }
  2666. static int
  2667. lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport, void *attr)
  2668. {
  2669. vport->fdmi_num_disc = lpfc_find_map_node(vport);
  2670. return lpfc_fdmi_set_attr_u32(attr, RPRT_DISC_PORT,
  2671. vport->fdmi_num_disc);
  2672. }
  2673. static int
  2674. lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport, void *attr)
  2675. {
  2676. return lpfc_fdmi_set_attr_u32(attr, RPRT_PORT_ID, vport->fc_myDID);
  2677. }
  2678. static int
  2679. lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport, void *attr)
  2680. {
  2681. return lpfc_fdmi_set_attr_string(attr, RPRT_SMART_SERVICE,
  2682. "Smart SAN Initiator");
  2683. }
  2684. static int
  2685. lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport, void *attr)
  2686. {
  2687. return lpfc_fdmi_set_attr_fullwwn(attr, RPRT_SMART_GUID,
  2688. &vport->fc_sparam.nodeName,
  2689. &vport->fc_sparam.portName);
  2690. }
  2691. static int
  2692. lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport, void *attr)
  2693. {
  2694. return lpfc_fdmi_set_attr_string(attr, RPRT_SMART_VERSION,
  2695. "Smart SAN Version 2.0");
  2696. }
  2697. static int
  2698. lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport, void *attr)
  2699. {
  2700. struct lpfc_hba *phba = vport->phba;
  2701. return lpfc_fdmi_set_attr_string(attr, RPRT_SMART_MODEL,
  2702. phba->ModelName);
  2703. }
  2704. static int
  2705. lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport, void *attr)
  2706. {
  2707. /* SRIOV (type 3) is not supported */
  2708. return lpfc_fdmi_set_attr_u32(attr, RPRT_SMART_PORT_INFO,
  2709. (vport->vpi) ? 2 /* NPIV */ : 1 /* Physical */);
  2710. }
  2711. static int
  2712. lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport, void *attr)
  2713. {
  2714. return lpfc_fdmi_set_attr_u32(attr, RPRT_SMART_QOS, 0);
  2715. }
  2716. static int
  2717. lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport, void *attr)
  2718. {
  2719. return lpfc_fdmi_set_attr_u32(attr, RPRT_SMART_SECURITY, 1);
  2720. }
  2721. static int
  2722. lpfc_fdmi_vendor_attr_mi(struct lpfc_vport *vport, void *attr)
  2723. {
  2724. struct lpfc_hba *phba = vport->phba;
  2725. char buf[32] = { 0 };
  2726. sprintf(buf, "ELXE2EM:%04d", phba->sli4_hba.pc_sli4_params.mi_ver);
  2727. return lpfc_fdmi_set_attr_string(attr, RPRT_VENDOR_MI, buf);
  2728. }
  2729. /* RHBA attribute jump table */
  2730. int (*lpfc_fdmi_hba_action[])
  2731. (struct lpfc_vport *vport, void *attrbuf) = {
  2732. /* Action routine Mask bit Attribute type */
  2733. lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
  2734. lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
  2735. lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
  2736. lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
  2737. lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
  2738. lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
  2739. lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
  2740. lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
  2741. lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
  2742. lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
  2743. lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
  2744. lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
  2745. lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
  2746. lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
  2747. lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
  2748. lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
  2749. lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
  2750. lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
  2751. };
  2752. /* RPA / RPRT attribute jump table */
  2753. int (*lpfc_fdmi_port_action[])
  2754. (struct lpfc_vport *vport, void *attrbuf) = {
  2755. /* Action routine Mask bit Attribute type */
  2756. lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
  2757. lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
  2758. lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
  2759. lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
  2760. lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
  2761. lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
  2762. lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
  2763. lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
  2764. lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
  2765. lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
  2766. lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
  2767. lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
  2768. lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
  2769. lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
  2770. lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
  2771. lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
  2772. lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
  2773. lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
  2774. lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
  2775. lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
  2776. lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
  2777. lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
  2778. lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
  2779. lpfc_fdmi_vendor_attr_mi, /* bit23 RPRT_VENDOR_MI */
  2780. };
  2781. /**
  2782. * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
  2783. * @vport: pointer to a host virtual N_Port data structure.
  2784. * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
  2785. * @cmdcode: FDMI command to send
  2786. * @new_mask: Mask of HBA or PORT Attributes to send
  2787. *
  2788. * Builds and sends a FDMI command using the CT subsystem.
  2789. */
  2790. int
  2791. lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2792. int cmdcode, uint32_t new_mask)
  2793. {
  2794. struct lpfc_hba *phba = vport->phba;
  2795. struct lpfc_dmabuf *rq, *rsp;
  2796. struct lpfc_sli_ct_request *CtReq;
  2797. struct ulp_bde64_le *bde;
  2798. uint32_t bit_pos;
  2799. uint32_t size, addsz;
  2800. uint32_t rsp_size;
  2801. uint32_t mask;
  2802. struct lpfc_fdmi_reg_hba *rh;
  2803. struct lpfc_fdmi_port_entry *pe;
  2804. struct lpfc_fdmi_reg_portattr *pab = NULL, *base = NULL;
  2805. struct lpfc_fdmi_attr_block *ab = NULL;
  2806. int (*func)(struct lpfc_vport *vport, void *attrbuf);
  2807. void (*cmpl)(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2808. struct lpfc_iocbq *rspiocb);
  2809. if (!ndlp)
  2810. return 0;
  2811. cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
  2812. /* fill in BDEs for command */
  2813. /* Allocate buffer for command payload */
  2814. rq = kmalloc(sizeof(*rq), GFP_KERNEL);
  2815. if (!rq)
  2816. goto fdmi_cmd_exit;
  2817. rq->virt = lpfc_mbuf_alloc(phba, 0, &rq->phys);
  2818. if (!rq->virt)
  2819. goto fdmi_cmd_free_rq;
  2820. /* Allocate buffer for Buffer ptr list */
  2821. rsp = kmalloc(sizeof(*rsp), GFP_KERNEL);
  2822. if (!rsp)
  2823. goto fdmi_cmd_free_rqvirt;
  2824. rsp->virt = lpfc_mbuf_alloc(phba, 0, &rsp->phys);
  2825. if (!rsp->virt)
  2826. goto fdmi_cmd_free_rsp;
  2827. INIT_LIST_HEAD(&rq->list);
  2828. INIT_LIST_HEAD(&rsp->list);
  2829. /* mbuf buffers are 1K in length - aka LPFC_BPL_SIZE */
  2830. memset(rq->virt, 0, LPFC_BPL_SIZE);
  2831. rsp_size = LPFC_BPL_SIZE;
  2832. /* FDMI request */
  2833. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2834. "0218 FDMI Request x%x mask x%x Data: x%x x%x x%x\n",
  2835. cmdcode, new_mask, vport->fdmi_port_mask,
  2836. vport->fc_flag, vport->port_state);
  2837. CtReq = (struct lpfc_sli_ct_request *)rq->virt;
  2838. /* First populate the CT_IU preamble */
  2839. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  2840. CtReq->RevisionId.bits.InId = 0;
  2841. CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  2842. CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
  2843. CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
  2844. size = 0;
  2845. /* Next fill in the specific FDMI cmd information */
  2846. switch (cmdcode) {
  2847. case SLI_MGMT_RHAT:
  2848. case SLI_MGMT_RHBA:
  2849. rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un;
  2850. /* HBA Identifier */
  2851. memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
  2852. sizeof(struct lpfc_name));
  2853. size += sizeof(struct lpfc_fdmi_hba_ident);
  2854. if (cmdcode == SLI_MGMT_RHBA) {
  2855. /* Registered Port List */
  2856. /* One entry (port) per adapter */
  2857. rh->rpl.EntryCnt = cpu_to_be32(1);
  2858. memcpy(&rh->rpl.pe.PortName,
  2859. &phba->pport->fc_sparam.portName,
  2860. sizeof(struct lpfc_name));
  2861. size += sizeof(struct lpfc_fdmi_reg_port_list);
  2862. }
  2863. ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
  2864. ab->EntryCnt = 0;
  2865. size += FOURBYTES; /* add length of EntryCnt field */
  2866. bit_pos = 0;
  2867. if (new_mask)
  2868. mask = new_mask;
  2869. else
  2870. mask = vport->fdmi_hba_mask;
  2871. /* Mask will dictate what attributes to build in the request */
  2872. while (mask) {
  2873. if (mask & 0x1) {
  2874. func = lpfc_fdmi_hba_action[bit_pos];
  2875. addsz = func(vport, ((uint8_t *)rh + size));
  2876. if (addsz) {
  2877. ab->EntryCnt++;
  2878. size += addsz;
  2879. }
  2880. /* check if another attribute fits */
  2881. if ((size + FDMI_MAX_ATTRLEN) >
  2882. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  2883. goto hba_out;
  2884. }
  2885. mask = mask >> 1;
  2886. bit_pos++;
  2887. }
  2888. hba_out:
  2889. ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
  2890. /* Total size */
  2891. size += GID_REQUEST_SZ - 4;
  2892. break;
  2893. case SLI_MGMT_RPRT:
  2894. if (vport->port_type != LPFC_PHYSICAL_PORT) {
  2895. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2896. if (!ndlp)
  2897. return 0;
  2898. }
  2899. fallthrough;
  2900. case SLI_MGMT_RPA:
  2901. /* Store base ptr right after preamble */
  2902. base = (struct lpfc_fdmi_reg_portattr *)&CtReq->un;
  2903. if (cmdcode == SLI_MGMT_RPRT) {
  2904. rh = (struct lpfc_fdmi_reg_hba *)base;
  2905. /* HBA Identifier */
  2906. memcpy(&rh->hi.PortName,
  2907. &phba->pport->fc_sparam.portName,
  2908. sizeof(struct lpfc_name));
  2909. pab = (struct lpfc_fdmi_reg_portattr *)
  2910. ((uint8_t *)base + sizeof(struct lpfc_name));
  2911. size += sizeof(struct lpfc_name);
  2912. } else {
  2913. pab = base;
  2914. }
  2915. memcpy((uint8_t *)&pab->PortName,
  2916. (uint8_t *)&vport->fc_sparam.portName,
  2917. sizeof(struct lpfc_name));
  2918. pab->ab.EntryCnt = 0;
  2919. /* add length of name and EntryCnt field */
  2920. size += sizeof(struct lpfc_name) + FOURBYTES;
  2921. bit_pos = 0;
  2922. if (new_mask)
  2923. mask = new_mask;
  2924. else
  2925. mask = vport->fdmi_port_mask;
  2926. /* Mask will dictate what attributes to build in the request */
  2927. while (mask) {
  2928. if (mask & 0x1) {
  2929. func = lpfc_fdmi_port_action[bit_pos];
  2930. addsz = func(vport, ((uint8_t *)base + size));
  2931. if (addsz) {
  2932. pab->ab.EntryCnt++;
  2933. size += addsz;
  2934. }
  2935. /* check if another attribute fits */
  2936. if ((size + FDMI_MAX_ATTRLEN) >
  2937. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  2938. goto port_out;
  2939. }
  2940. mask = mask >> 1;
  2941. bit_pos++;
  2942. }
  2943. port_out:
  2944. pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
  2945. size += GID_REQUEST_SZ - 4;
  2946. break;
  2947. case SLI_MGMT_GHAT:
  2948. case SLI_MGMT_GRPL:
  2949. rsp_size = FC_MAX_NS_RSP;
  2950. fallthrough;
  2951. case SLI_MGMT_DHBA:
  2952. case SLI_MGMT_DHAT:
  2953. pe = (struct lpfc_fdmi_port_entry *)&CtReq->un;
  2954. memcpy((uint8_t *)&pe->PortName,
  2955. (uint8_t *)&vport->fc_sparam.portName,
  2956. sizeof(struct lpfc_name));
  2957. size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
  2958. break;
  2959. case SLI_MGMT_GPAT:
  2960. case SLI_MGMT_GPAS:
  2961. rsp_size = FC_MAX_NS_RSP;
  2962. fallthrough;
  2963. case SLI_MGMT_DPRT:
  2964. if (vport->port_type != LPFC_PHYSICAL_PORT) {
  2965. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2966. if (!ndlp)
  2967. return 0;
  2968. }
  2969. fallthrough;
  2970. case SLI_MGMT_DPA:
  2971. pe = (struct lpfc_fdmi_port_entry *)&CtReq->un;
  2972. memcpy((uint8_t *)&pe->PortName,
  2973. (uint8_t *)&vport->fc_sparam.portName,
  2974. sizeof(struct lpfc_name));
  2975. size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
  2976. break;
  2977. case SLI_MGMT_GRHL:
  2978. size = GID_REQUEST_SZ - 4;
  2979. break;
  2980. default:
  2981. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  2982. "0298 FDMI cmdcode x%x not supported\n",
  2983. cmdcode);
  2984. goto fdmi_cmd_free_rspvirt;
  2985. }
  2986. CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
  2987. bde = (struct ulp_bde64_le *)rsp->virt;
  2988. bde->addr_high = cpu_to_le32(putPaddrHigh(rq->phys));
  2989. bde->addr_low = cpu_to_le32(putPaddrLow(rq->phys));
  2990. bde->type_size = cpu_to_le32(ULP_BDE64_TYPE_BDE_64 <<
  2991. ULP_BDE64_TYPE_SHIFT);
  2992. bde->type_size |= cpu_to_le32(size);
  2993. /*
  2994. * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  2995. * to hold ndlp reference for the corresponding callback function.
  2996. */
  2997. if (!lpfc_ct_cmd(vport, rq, rsp, ndlp, cmpl, rsp_size, 0))
  2998. return 0;
  2999. fdmi_cmd_free_rspvirt:
  3000. lpfc_mbuf_free(phba, rsp->virt, rsp->phys);
  3001. fdmi_cmd_free_rsp:
  3002. kfree(rsp);
  3003. fdmi_cmd_free_rqvirt:
  3004. lpfc_mbuf_free(phba, rq->virt, rq->phys);
  3005. fdmi_cmd_free_rq:
  3006. kfree(rq);
  3007. fdmi_cmd_exit:
  3008. /* Issue FDMI request failed */
  3009. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3010. "0244 Issue FDMI request failed Data: x%x\n",
  3011. cmdcode);
  3012. return 1;
  3013. }
  3014. /**
  3015. * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
  3016. * @t: Context object of the timer.
  3017. *
  3018. * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
  3019. * the worker thread.
  3020. **/
  3021. void
  3022. lpfc_delayed_disc_tmo(struct timer_list *t)
  3023. {
  3024. struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
  3025. struct lpfc_hba *phba = vport->phba;
  3026. uint32_t tmo_posted;
  3027. unsigned long iflag;
  3028. spin_lock_irqsave(&vport->work_port_lock, iflag);
  3029. tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
  3030. if (!tmo_posted)
  3031. vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
  3032. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  3033. if (!tmo_posted)
  3034. lpfc_worker_wake_up(phba);
  3035. return;
  3036. }
  3037. /**
  3038. * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
  3039. * handle delayed discovery.
  3040. * @vport: pointer to a host virtual N_Port data structure.
  3041. *
  3042. * This function start nport discovery of the vport.
  3043. **/
  3044. void
  3045. lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
  3046. {
  3047. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3048. spin_lock_irq(shost->host_lock);
  3049. if (!(vport->fc_flag & FC_DISC_DELAYED)) {
  3050. spin_unlock_irq(shost->host_lock);
  3051. return;
  3052. }
  3053. vport->fc_flag &= ~FC_DISC_DELAYED;
  3054. spin_unlock_irq(shost->host_lock);
  3055. lpfc_do_scr_ns_plogi(vport->phba, vport);
  3056. }
  3057. void
  3058. lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
  3059. {
  3060. struct lpfc_sli *psli = &phba->sli;
  3061. lpfc_vpd_t *vp = &phba->vpd;
  3062. uint32_t b1, b2, b3, b4, i, rev;
  3063. char c;
  3064. uint32_t *ptr, str[4];
  3065. uint8_t *fwname;
  3066. if (phba->sli_rev == LPFC_SLI_REV4)
  3067. snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
  3068. else if (vp->rev.rBit) {
  3069. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  3070. rev = vp->rev.sli2FwRev;
  3071. else
  3072. rev = vp->rev.sli1FwRev;
  3073. b1 = (rev & 0x0000f000) >> 12;
  3074. b2 = (rev & 0x00000f00) >> 8;
  3075. b3 = (rev & 0x000000c0) >> 6;
  3076. b4 = (rev & 0x00000030) >> 4;
  3077. switch (b4) {
  3078. case 0:
  3079. c = 'N';
  3080. break;
  3081. case 1:
  3082. c = 'A';
  3083. break;
  3084. case 2:
  3085. c = 'B';
  3086. break;
  3087. case 3:
  3088. c = 'X';
  3089. break;
  3090. default:
  3091. c = 0;
  3092. break;
  3093. }
  3094. b4 = (rev & 0x0000000f);
  3095. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  3096. fwname = vp->rev.sli2FwName;
  3097. else
  3098. fwname = vp->rev.sli1FwName;
  3099. for (i = 0; i < 16; i++)
  3100. if (fwname[i] == 0x20)
  3101. fwname[i] = 0;
  3102. ptr = (uint32_t*)fwname;
  3103. for (i = 0; i < 3; i++)
  3104. str[i] = be32_to_cpu(*ptr++);
  3105. if (c == 0) {
  3106. if (flag)
  3107. sprintf(fwrevision, "%d.%d%d (%s)",
  3108. b1, b2, b3, (char *)str);
  3109. else
  3110. sprintf(fwrevision, "%d.%d%d", b1,
  3111. b2, b3);
  3112. } else {
  3113. if (flag)
  3114. sprintf(fwrevision, "%d.%d%d%c%d (%s)",
  3115. b1, b2, b3, c,
  3116. b4, (char *)str);
  3117. else
  3118. sprintf(fwrevision, "%d.%d%d%c%d",
  3119. b1, b2, b3, c, b4);
  3120. }
  3121. } else {
  3122. rev = vp->rev.smFwRev;
  3123. b1 = (rev & 0xff000000) >> 24;
  3124. b2 = (rev & 0x00f00000) >> 20;
  3125. b3 = (rev & 0x000f0000) >> 16;
  3126. c = (rev & 0x0000ff00) >> 8;
  3127. b4 = (rev & 0x000000ff);
  3128. sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
  3129. }
  3130. return;
  3131. }
  3132. static void
  3133. lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3134. struct lpfc_iocbq *rspiocb)
  3135. {
  3136. struct lpfc_vport *vport = cmdiocb->vport;
  3137. struct lpfc_dmabuf *inp = cmdiocb->cmd_dmabuf;
  3138. struct lpfc_dmabuf *outp = cmdiocb->rsp_dmabuf;
  3139. struct lpfc_sli_ct_request *ctcmd = inp->virt;
  3140. struct lpfc_sli_ct_request *ctrsp = outp->virt;
  3141. u16 rsp = ctrsp->CommandResponse.bits.CmdRsp;
  3142. struct app_id_object *app;
  3143. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  3144. u32 cmd, hash, bucket;
  3145. struct lpfc_vmid *vmp, *cur;
  3146. u8 *data = outp->virt;
  3147. int i;
  3148. cmd = be16_to_cpu(ctcmd->CommandResponse.bits.CmdRsp);
  3149. if (cmd == SLI_CTAS_DALLAPP_ID)
  3150. lpfc_ct_free_iocb(phba, cmdiocb);
  3151. if (lpfc_els_chk_latt(vport) || get_job_ulpstatus(phba, rspiocb)) {
  3152. if (cmd != SLI_CTAS_DALLAPP_ID)
  3153. goto free_res;
  3154. }
  3155. /* Check for a CT LS_RJT response */
  3156. if (rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  3157. if (cmd != SLI_CTAS_DALLAPP_ID)
  3158. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
  3159. "3306 VMID FS_RJT Data: x%x x%x x%x\n",
  3160. cmd, ctrsp->ReasonCode,
  3161. ctrsp->Explanation);
  3162. if ((cmd != SLI_CTAS_DALLAPP_ID) ||
  3163. (ctrsp->ReasonCode != SLI_CT_UNABLE_TO_PERFORM_REQ) ||
  3164. (ctrsp->Explanation != SLI_CT_APP_ID_NOT_AVAILABLE)) {
  3165. /* If DALLAPP_ID failed retry later */
  3166. if (cmd == SLI_CTAS_DALLAPP_ID)
  3167. vport->load_flag |= FC_DEREGISTER_ALL_APP_ID;
  3168. goto free_res;
  3169. }
  3170. }
  3171. switch (cmd) {
  3172. case SLI_CTAS_RAPP_IDENT:
  3173. app = (struct app_id_object *)(RAPP_IDENT_OFFSET + data);
  3174. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
  3175. "6712 RAPP_IDENT app id %d port id x%x id "
  3176. "len %d\n", be32_to_cpu(app->app_id),
  3177. be32_to_cpu(app->port_id),
  3178. app->obj.entity_id_len);
  3179. if (app->obj.entity_id_len == 0 || app->port_id == 0)
  3180. goto free_res;
  3181. hash = lpfc_vmid_hash_fn(app->obj.entity_id,
  3182. app->obj.entity_id_len);
  3183. vmp = lpfc_get_vmid_from_hashtable(vport, hash,
  3184. app->obj.entity_id);
  3185. if (vmp) {
  3186. write_lock(&vport->vmid_lock);
  3187. vmp->un.app_id = be32_to_cpu(app->app_id);
  3188. vmp->flag |= LPFC_VMID_REGISTERED;
  3189. vmp->flag &= ~LPFC_VMID_REQ_REGISTER;
  3190. write_unlock(&vport->vmid_lock);
  3191. /* Set IN USE flag */
  3192. vport->vmid_flag |= LPFC_VMID_IN_USE;
  3193. } else {
  3194. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
  3195. "6901 No entry found %s hash %d\n",
  3196. app->obj.entity_id, hash);
  3197. }
  3198. break;
  3199. case SLI_CTAS_DAPP_IDENT:
  3200. app = (struct app_id_object *)(DAPP_IDENT_OFFSET + data);
  3201. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
  3202. "6713 DAPP_IDENT app id %d port id x%x\n",
  3203. be32_to_cpu(app->app_id),
  3204. be32_to_cpu(app->port_id));
  3205. break;
  3206. case SLI_CTAS_DALLAPP_ID:
  3207. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
  3208. "8856 Deregistered all app ids\n");
  3209. read_lock(&vport->vmid_lock);
  3210. for (i = 0; i < phba->cfg_max_vmid; i++) {
  3211. vmp = &vport->vmid[i];
  3212. if (vmp->flag != LPFC_VMID_SLOT_FREE)
  3213. memset(vmp, 0, sizeof(struct lpfc_vmid));
  3214. }
  3215. read_unlock(&vport->vmid_lock);
  3216. /* for all elements in the hash table */
  3217. if (!hash_empty(vport->hash_table))
  3218. hash_for_each(vport->hash_table, bucket, cur, hnode)
  3219. hash_del(&cur->hnode);
  3220. vport->load_flag |= FC_ALLOW_VMID;
  3221. break;
  3222. default:
  3223. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
  3224. "8857 Invalid command code\n");
  3225. }
  3226. free_res:
  3227. lpfc_ct_free_iocb(phba, cmdiocb);
  3228. lpfc_nlp_put(ndlp);
  3229. }
  3230. /**
  3231. * lpfc_vmid_cmd - Build and send a FDMI cmd to the specified NPort
  3232. * @vport: pointer to a host virtual N_Port data structure.
  3233. * @cmdcode: application server command code to send
  3234. * @vmid: pointer to vmid info structure
  3235. *
  3236. * Builds and sends a FDMI command using the CT subsystem.
  3237. */
  3238. int
  3239. lpfc_vmid_cmd(struct lpfc_vport *vport,
  3240. int cmdcode, struct lpfc_vmid *vmid)
  3241. {
  3242. struct lpfc_hba *phba = vport->phba;
  3243. struct lpfc_dmabuf *mp, *bmp;
  3244. struct lpfc_sli_ct_request *ctreq;
  3245. struct ulp_bde64 *bpl;
  3246. u32 size;
  3247. u32 rsp_size;
  3248. u8 *data;
  3249. struct lpfc_vmid_rapp_ident_list *rap;
  3250. struct lpfc_vmid_dapp_ident_list *dap;
  3251. u8 retry = 0;
  3252. struct lpfc_nodelist *ndlp;
  3253. void (*cmpl)(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3254. struct lpfc_iocbq *rspiocb);
  3255. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  3256. if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
  3257. return 0;
  3258. cmpl = lpfc_cmpl_ct_cmd_vmid;
  3259. /* fill in BDEs for command */
  3260. /* Allocate buffer for command payload */
  3261. mp = kmalloc(sizeof(*mp), GFP_KERNEL);
  3262. if (!mp)
  3263. goto vmid_free_mp_exit;
  3264. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  3265. if (!mp->virt)
  3266. goto vmid_free_mp_virt_exit;
  3267. /* Allocate buffer for Buffer ptr list */
  3268. bmp = kmalloc(sizeof(*bmp), GFP_KERNEL);
  3269. if (!bmp)
  3270. goto vmid_free_bmp_exit;
  3271. bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
  3272. if (!bmp->virt)
  3273. goto vmid_free_bmp_virt_exit;
  3274. INIT_LIST_HEAD(&mp->list);
  3275. INIT_LIST_HEAD(&bmp->list);
  3276. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3277. "3275 VMID Request Data: x%x x%x x%x\n",
  3278. vport->fc_flag, vport->port_state, cmdcode);
  3279. ctreq = (struct lpfc_sli_ct_request *)mp->virt;
  3280. data = mp->virt;
  3281. /* First populate the CT_IU preamble */
  3282. memset(data, 0, LPFC_BPL_SIZE);
  3283. ctreq->RevisionId.bits.Revision = SLI_CT_REVISION;
  3284. ctreq->RevisionId.bits.InId = 0;
  3285. ctreq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  3286. ctreq->FsSubType = SLI_CT_APP_SEV_Subtypes;
  3287. ctreq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
  3288. rsp_size = LPFC_BPL_SIZE;
  3289. size = 0;
  3290. switch (cmdcode) {
  3291. case SLI_CTAS_RAPP_IDENT:
  3292. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
  3293. "1329 RAPP_IDENT for %s\n", vmid->host_vmid);
  3294. ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
  3295. rap = (struct lpfc_vmid_rapp_ident_list *)
  3296. (DAPP_IDENT_OFFSET + data);
  3297. rap->no_of_objects = cpu_to_be32(1);
  3298. rap->obj[0].entity_id_len = vmid->vmid_len;
  3299. memcpy(rap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len);
  3300. size = RAPP_IDENT_OFFSET +
  3301. sizeof(struct lpfc_vmid_rapp_ident_list);
  3302. retry = 1;
  3303. break;
  3304. case SLI_CTAS_GALLAPPIA_ID:
  3305. ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
  3306. size = GALLAPPIA_ID_SIZE;
  3307. break;
  3308. case SLI_CTAS_DAPP_IDENT:
  3309. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
  3310. "1469 DAPP_IDENT for %s\n", vmid->host_vmid);
  3311. ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
  3312. dap = (struct lpfc_vmid_dapp_ident_list *)
  3313. (DAPP_IDENT_OFFSET + data);
  3314. dap->no_of_objects = cpu_to_be32(1);
  3315. dap->obj[0].entity_id_len = vmid->vmid_len;
  3316. memcpy(dap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len);
  3317. size = DAPP_IDENT_OFFSET +
  3318. sizeof(struct lpfc_vmid_dapp_ident_list);
  3319. write_lock(&vport->vmid_lock);
  3320. vmid->flag &= ~LPFC_VMID_REGISTERED;
  3321. write_unlock(&vport->vmid_lock);
  3322. retry = 1;
  3323. break;
  3324. case SLI_CTAS_DALLAPP_ID:
  3325. ctreq->un.PortID = cpu_to_be32(vport->fc_myDID);
  3326. size = DALLAPP_ID_SIZE;
  3327. break;
  3328. default:
  3329. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
  3330. "7062 VMID cmdcode x%x not supported\n",
  3331. cmdcode);
  3332. goto vmid_free_all_mem;
  3333. }
  3334. ctreq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
  3335. bpl = (struct ulp_bde64 *)bmp->virt;
  3336. bpl->addrHigh = putPaddrHigh(mp->phys);
  3337. bpl->addrLow = putPaddrLow(mp->phys);
  3338. bpl->tus.f.bdeFlags = 0;
  3339. bpl->tus.f.bdeSize = size;
  3340. /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  3341. * to hold ndlp reference for the corresponding callback function.
  3342. */
  3343. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry))
  3344. return 0;
  3345. vmid_free_all_mem:
  3346. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  3347. vmid_free_bmp_virt_exit:
  3348. kfree(bmp);
  3349. vmid_free_bmp_exit:
  3350. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3351. vmid_free_mp_virt_exit:
  3352. kfree(mp);
  3353. vmid_free_mp_exit:
  3354. /* Issue CT request failed */
  3355. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
  3356. "3276 VMID CT request failed Data: x%x\n", cmdcode);
  3357. return -EIO;
  3358. }