lpfc_ct.c 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2024 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%lx\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. u16 mi_cmd;
  259. did = bf_get(els_rsp64_sid, &ctiocbq->wqe.xmit_els_rsp);
  260. if (ulp_status) {
  261. lpfc_vlog_msg(vport, KERN_WARNING, 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 (test_bit(FC_UNLOADING, &vport->load_flag))
  268. return;
  269. ndlp = lpfc_findnode_did(vport, did);
  270. if (!ndlp) {
  271. lpfc_vlog_msg(vport, KERN_WARNING, 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 = be16_to_cpu(ct_req->CommandResponse.bits.CmdRsp);
  278. lpfc_vlog_msg(vport, KERN_WARNING, 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. list_del(&mlast->list);
  428. lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
  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, __be16 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 (be16_to_cpu(cmdcode) == SLI_CTNS_GID_FT ||
  454. be16_to_cpu(cmdcode) == 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. __be16 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%lx 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%lx 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%lx 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%lx x%x x%px\n",
  668. Did, vport->fc_flag,
  669. vport->fc_rscn_id_cnt, ndlp);
  670. }
  671. } else {
  672. if (!test_bit(FC_RSCN_MODE, &vport->fc_flag) ||
  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%lx 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%lx 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%lx 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 lpfc_dmabuf *outp;
  809. struct lpfc_dmabuf *inp;
  810. struct lpfc_sli_ct_request *CTrsp;
  811. struct lpfc_sli_ct_request *CTreq;
  812. struct lpfc_nodelist *ndlp;
  813. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  814. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  815. int rc, type;
  816. /* First save ndlp, before we overwrite it */
  817. ndlp = cmdiocb->ndlp;
  818. /* we pass cmdiocb to state machine which needs rspiocb as well */
  819. cmdiocb->rsp_iocb = rspiocb;
  820. inp = cmdiocb->cmd_dmabuf;
  821. outp = cmdiocb->rsp_dmabuf;
  822. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  823. "GID_FT cmpl: status:x%x/x%x rtry:%d",
  824. ulp_status, ulp_word4, vport->fc_ns_retry);
  825. /* Ignore response if link flipped after this request was made */
  826. if (cmdiocb->event_tag != phba->fc_eventTag) {
  827. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  828. "9043 Event tag mismatch. Ignoring NS rsp\n");
  829. goto out;
  830. }
  831. /* Skip processing response on pport if unloading */
  832. if (vport == phba->pport && test_bit(FC_UNLOADING, &vport->load_flag)) {
  833. if (test_bit(FC_RSCN_MODE, &vport->fc_flag))
  834. lpfc_els_flush_rscn(vport);
  835. goto out;
  836. }
  837. if (lpfc_els_chk_latt(vport)) {
  838. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  839. "0216 Link event during NS query\n");
  840. if (test_bit(FC_RSCN_MODE, &vport->fc_flag))
  841. lpfc_els_flush_rscn(vport);
  842. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  843. goto out;
  844. }
  845. if (lpfc_error_lost_link(vport, ulp_status, ulp_word4)) {
  846. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  847. "0226 NS query failed due to link event: "
  848. "ulp_status x%x ulp_word4 x%x fc_flag x%lx "
  849. "port_state x%x gidft_inp x%x\n",
  850. ulp_status, ulp_word4, vport->fc_flag,
  851. vport->port_state, vport->gidft_inp);
  852. if (test_bit(FC_RSCN_MODE, &vport->fc_flag))
  853. lpfc_els_flush_rscn(vport);
  854. if (vport->gidft_inp)
  855. vport->gidft_inp--;
  856. goto out;
  857. }
  858. if (test_and_clear_bit(FC_RSCN_DEFERRED, &vport->fc_flag)) {
  859. /* This is a GID_FT completing so the gidft_inp counter was
  860. * incremented before the GID_FT was issued to the wire.
  861. */
  862. if (vport->gidft_inp)
  863. vport->gidft_inp--;
  864. /*
  865. * Skip processing the NS response
  866. * Re-issue the NS cmd
  867. */
  868. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  869. "0151 Process Deferred RSCN Data: x%lx x%x\n",
  870. vport->fc_flag, vport->fc_rscn_id_cnt);
  871. lpfc_els_handle_rscn(vport);
  872. goto out;
  873. }
  874. if (ulp_status) {
  875. /* Check for retry */
  876. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  877. if (ulp_status != IOSTAT_LOCAL_REJECT ||
  878. (ulp_word4 & IOERR_PARAM_MASK) !=
  879. IOERR_NO_RESOURCES)
  880. vport->fc_ns_retry++;
  881. type = lpfc_get_gidft_type(vport, cmdiocb);
  882. if (type == 0)
  883. goto out;
  884. /* CT command is being retried */
  885. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  886. vport->fc_ns_retry, type);
  887. if (rc == 0)
  888. goto out;
  889. else { /* Unable to send NS cmd */
  890. if (vport->gidft_inp)
  891. vport->gidft_inp--;
  892. }
  893. }
  894. if (test_bit(FC_RSCN_MODE, &vport->fc_flag))
  895. lpfc_els_flush_rscn(vport);
  896. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  897. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  898. "0257 GID_FT Query error: 0x%x 0x%x\n",
  899. ulp_status, vport->fc_ns_retry);
  900. } else {
  901. /* Good status, continue checking */
  902. CTreq = (struct lpfc_sli_ct_request *) inp->virt;
  903. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  904. if (CTrsp->CommandResponse.bits.CmdRsp ==
  905. cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
  906. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  907. "0208 NameServer Rsp Data: x%lx x%x "
  908. "x%x x%x sz x%x\n",
  909. vport->fc_flag,
  910. CTreq->un.gid.Fc4Type,
  911. vport->num_disc_nodes,
  912. vport->gidft_inp,
  913. get_job_data_placed(phba, rspiocb));
  914. lpfc_ns_rsp(vport,
  915. outp,
  916. CTreq->un.gid.Fc4Type,
  917. get_job_data_placed(phba, rspiocb));
  918. } else if (be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp) ==
  919. SLI_CT_RESPONSE_FS_RJT) {
  920. /* NameServer Rsp Error */
  921. if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
  922. && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
  923. lpfc_printf_vlog(vport, KERN_INFO,
  924. LOG_DISCOVERY,
  925. "0269 No NameServer Entries "
  926. "Data: x%x x%x x%x x%lx\n",
  927. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  928. (uint32_t) CTrsp->ReasonCode,
  929. (uint32_t) CTrsp->Explanation,
  930. vport->fc_flag);
  931. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  932. "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
  933. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  934. (uint32_t) CTrsp->ReasonCode,
  935. (uint32_t) CTrsp->Explanation);
  936. } else {
  937. lpfc_printf_vlog(vport, KERN_INFO,
  938. LOG_DISCOVERY,
  939. "0240 NameServer Rsp Error "
  940. "Data: x%x x%x x%x x%lx\n",
  941. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  942. (uint32_t) CTrsp->ReasonCode,
  943. (uint32_t) CTrsp->Explanation,
  944. vport->fc_flag);
  945. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  946. "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
  947. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  948. (uint32_t) CTrsp->ReasonCode,
  949. (uint32_t) CTrsp->Explanation);
  950. }
  951. } else {
  952. /* NameServer Rsp Error */
  953. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  954. "0241 NameServer Rsp Error "
  955. "Data: x%x x%x x%x x%lx\n",
  956. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  957. (uint32_t) CTrsp->ReasonCode,
  958. (uint32_t) CTrsp->Explanation,
  959. vport->fc_flag);
  960. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  961. "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
  962. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  963. (uint32_t) CTrsp->ReasonCode,
  964. (uint32_t) CTrsp->Explanation);
  965. }
  966. if (vport->gidft_inp)
  967. vport->gidft_inp--;
  968. }
  969. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  970. "4216 GID_FT cmpl inp %d disc %d\n",
  971. vport->gidft_inp, vport->num_disc_nodes);
  972. /* Link up / RSCN discovery */
  973. if ((vport->num_disc_nodes == 0) &&
  974. (vport->gidft_inp == 0)) {
  975. /*
  976. * The driver has cycled through all Nports in the RSCN payload.
  977. * Complete the handling by cleaning up and marking the
  978. * current driver state.
  979. */
  980. if (vport->port_state >= LPFC_DISC_AUTH) {
  981. if (test_bit(FC_RSCN_MODE, &vport->fc_flag)) {
  982. lpfc_els_flush_rscn(vport);
  983. /* RSCN still */
  984. set_bit(FC_RSCN_MODE, &vport->fc_flag);
  985. } else {
  986. lpfc_els_flush_rscn(vport);
  987. }
  988. }
  989. lpfc_disc_start(vport);
  990. }
  991. out:
  992. lpfc_ct_free_iocb(phba, cmdiocb);
  993. lpfc_nlp_put(ndlp);
  994. return;
  995. }
  996. static void
  997. lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  998. struct lpfc_iocbq *rspiocb)
  999. {
  1000. struct lpfc_vport *vport = cmdiocb->vport;
  1001. struct lpfc_dmabuf *outp;
  1002. struct lpfc_dmabuf *inp;
  1003. struct lpfc_sli_ct_request *CTrsp;
  1004. struct lpfc_sli_ct_request *CTreq;
  1005. struct lpfc_nodelist *ndlp;
  1006. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1007. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  1008. int rc;
  1009. /* First save ndlp, before we overwrite it */
  1010. ndlp = cmdiocb->ndlp;
  1011. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1012. cmdiocb->rsp_iocb = rspiocb;
  1013. inp = cmdiocb->cmd_dmabuf;
  1014. outp = cmdiocb->rsp_dmabuf;
  1015. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1016. "GID_PT cmpl: status:x%x/x%x rtry:%d",
  1017. ulp_status, ulp_word4,
  1018. vport->fc_ns_retry);
  1019. /* Ignore response if link flipped after this request was made */
  1020. if (cmdiocb->event_tag != phba->fc_eventTag) {
  1021. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1022. "9044 Event tag mismatch. Ignoring NS rsp\n");
  1023. goto out;
  1024. }
  1025. /* Skip processing response on pport if unloading */
  1026. if (vport == phba->pport && test_bit(FC_UNLOADING, &vport->load_flag)) {
  1027. if (test_bit(FC_RSCN_MODE, &vport->fc_flag))
  1028. lpfc_els_flush_rscn(vport);
  1029. goto out;
  1030. }
  1031. if (lpfc_els_chk_latt(vport)) {
  1032. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1033. "4108 Link event during NS query\n");
  1034. if (test_bit(FC_RSCN_MODE, &vport->fc_flag))
  1035. lpfc_els_flush_rscn(vport);
  1036. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1037. goto out;
  1038. }
  1039. if (lpfc_error_lost_link(vport, ulp_status, ulp_word4)) {
  1040. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1041. "4166 NS query failed due to link event: "
  1042. "ulp_status x%x ulp_word4 x%x fc_flag x%lx "
  1043. "port_state x%x gidft_inp x%x\n",
  1044. ulp_status, ulp_word4, vport->fc_flag,
  1045. vport->port_state, vport->gidft_inp);
  1046. if (test_bit(FC_RSCN_MODE, &vport->fc_flag))
  1047. lpfc_els_flush_rscn(vport);
  1048. if (vport->gidft_inp)
  1049. vport->gidft_inp--;
  1050. goto out;
  1051. }
  1052. if (test_and_clear_bit(FC_RSCN_DEFERRED, &vport->fc_flag)) {
  1053. /* This is a GID_PT completing so the gidft_inp counter was
  1054. * incremented before the GID_PT was issued to the wire.
  1055. */
  1056. if (vport->gidft_inp)
  1057. vport->gidft_inp--;
  1058. /*
  1059. * Skip processing the NS response
  1060. * Re-issue the NS cmd
  1061. */
  1062. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1063. "4167 Process Deferred RSCN Data: x%lx x%x\n",
  1064. vport->fc_flag, vport->fc_rscn_id_cnt);
  1065. lpfc_els_handle_rscn(vport);
  1066. goto out;
  1067. }
  1068. if (ulp_status) {
  1069. /* Check for retry */
  1070. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  1071. if (ulp_status != IOSTAT_LOCAL_REJECT ||
  1072. (ulp_word4 & IOERR_PARAM_MASK) !=
  1073. IOERR_NO_RESOURCES)
  1074. vport->fc_ns_retry++;
  1075. /* CT command is being retried */
  1076. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
  1077. vport->fc_ns_retry, GID_PT_N_PORT);
  1078. if (rc == 0)
  1079. goto out;
  1080. else { /* Unable to send NS cmd */
  1081. if (vport->gidft_inp)
  1082. vport->gidft_inp--;
  1083. }
  1084. }
  1085. if (test_bit(FC_RSCN_MODE, &vport->fc_flag))
  1086. lpfc_els_flush_rscn(vport);
  1087. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1088. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1089. "4103 GID_FT Query error: 0x%x 0x%x\n",
  1090. ulp_status, vport->fc_ns_retry);
  1091. } else {
  1092. /* Good status, continue checking */
  1093. CTreq = (struct lpfc_sli_ct_request *)inp->virt;
  1094. CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
  1095. if (be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp) ==
  1096. SLI_CT_RESPONSE_FS_ACC) {
  1097. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1098. "4105 NameServer Rsp Data: x%lx x%x "
  1099. "x%x x%x sz x%x\n",
  1100. vport->fc_flag,
  1101. CTreq->un.gid.Fc4Type,
  1102. vport->num_disc_nodes,
  1103. vport->gidft_inp,
  1104. get_job_data_placed(phba, rspiocb));
  1105. lpfc_ns_rsp(vport,
  1106. outp,
  1107. CTreq->un.gid.Fc4Type,
  1108. get_job_data_placed(phba, rspiocb));
  1109. } else if (be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp) ==
  1110. SLI_CT_RESPONSE_FS_RJT) {
  1111. /* NameServer Rsp Error */
  1112. if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
  1113. && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
  1114. lpfc_printf_vlog(
  1115. vport, KERN_INFO, LOG_DISCOVERY,
  1116. "4106 No NameServer Entries "
  1117. "Data: x%x x%x x%x x%lx\n",
  1118. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  1119. (uint32_t)CTrsp->ReasonCode,
  1120. (uint32_t)CTrsp->Explanation,
  1121. vport->fc_flag);
  1122. lpfc_debugfs_disc_trc(
  1123. vport, LPFC_DISC_TRC_CT,
  1124. "GID_PT no entry cmd:x%x rsn:x%x exp:x%x",
  1125. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  1126. (uint32_t)CTrsp->ReasonCode,
  1127. (uint32_t)CTrsp->Explanation);
  1128. } else {
  1129. lpfc_printf_vlog(
  1130. vport, KERN_INFO, LOG_DISCOVERY,
  1131. "4107 NameServer Rsp Error "
  1132. "Data: x%x x%x x%x x%lx\n",
  1133. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  1134. (uint32_t)CTrsp->ReasonCode,
  1135. (uint32_t)CTrsp->Explanation,
  1136. vport->fc_flag);
  1137. lpfc_debugfs_disc_trc(
  1138. vport, LPFC_DISC_TRC_CT,
  1139. "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
  1140. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  1141. (uint32_t)CTrsp->ReasonCode,
  1142. (uint32_t)CTrsp->Explanation);
  1143. }
  1144. } else {
  1145. /* NameServer Rsp Error */
  1146. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1147. "4109 NameServer Rsp Error "
  1148. "Data: x%x x%x x%x x%lx\n",
  1149. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  1150. (uint32_t)CTrsp->ReasonCode,
  1151. (uint32_t)CTrsp->Explanation,
  1152. vport->fc_flag);
  1153. lpfc_debugfs_disc_trc(
  1154. vport, LPFC_DISC_TRC_CT,
  1155. "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
  1156. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  1157. (uint32_t)CTrsp->ReasonCode,
  1158. (uint32_t)CTrsp->Explanation);
  1159. }
  1160. if (vport->gidft_inp)
  1161. vport->gidft_inp--;
  1162. }
  1163. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1164. "6450 GID_PT cmpl inp %d disc %d\n",
  1165. vport->gidft_inp, vport->num_disc_nodes);
  1166. /* Link up / RSCN discovery */
  1167. if ((vport->num_disc_nodes == 0) &&
  1168. (vport->gidft_inp == 0)) {
  1169. /*
  1170. * The driver has cycled through all Nports in the RSCN payload.
  1171. * Complete the handling by cleaning up and marking the
  1172. * current driver state.
  1173. */
  1174. if (vport->port_state >= LPFC_DISC_AUTH) {
  1175. if (test_bit(FC_RSCN_MODE, &vport->fc_flag)) {
  1176. lpfc_els_flush_rscn(vport);
  1177. /* RSCN still */
  1178. set_bit(FC_RSCN_MODE, &vport->fc_flag);
  1179. } else {
  1180. lpfc_els_flush_rscn(vport);
  1181. }
  1182. }
  1183. lpfc_disc_start(vport);
  1184. }
  1185. out:
  1186. lpfc_ct_free_iocb(phba, cmdiocb);
  1187. lpfc_nlp_put(ndlp);
  1188. }
  1189. static void
  1190. lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1191. struct lpfc_iocbq *rspiocb)
  1192. {
  1193. struct lpfc_vport *vport = cmdiocb->vport;
  1194. struct lpfc_dmabuf *inp = cmdiocb->cmd_dmabuf;
  1195. struct lpfc_dmabuf *outp = cmdiocb->rsp_dmabuf;
  1196. struct lpfc_sli_ct_request *CTrsp;
  1197. int did, rc, retry;
  1198. uint8_t fbits;
  1199. struct lpfc_nodelist *ndlp = NULL, *free_ndlp = NULL;
  1200. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1201. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  1202. did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
  1203. did = be32_to_cpu(did);
  1204. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1205. "GFF_ID cmpl: status:x%x/x%x did:x%x",
  1206. ulp_status, ulp_word4, did);
  1207. /* Ignore response if link flipped after this request was made */
  1208. if (cmdiocb->event_tag != phba->fc_eventTag) {
  1209. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1210. "9045 Event tag mismatch. Ignoring NS rsp\n");
  1211. goto iocb_free;
  1212. }
  1213. if (ulp_status == IOSTAT_SUCCESS) {
  1214. /* Good status, continue checking */
  1215. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  1216. fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
  1217. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1218. "6431 Process GFF_ID rsp for %08x "
  1219. "fbits %02x %s %s\n",
  1220. did, fbits,
  1221. (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ",
  1222. (fbits & FC4_FEATURE_TARGET) ? "Target" : " ");
  1223. if (be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp) ==
  1224. SLI_CT_RESPONSE_FS_ACC) {
  1225. if ((fbits & FC4_FEATURE_INIT) &&
  1226. !(fbits & FC4_FEATURE_TARGET)) {
  1227. lpfc_printf_vlog(vport, KERN_INFO,
  1228. LOG_DISCOVERY,
  1229. "0270 Skip x%x GFF "
  1230. "NameServer Rsp Data: (init) "
  1231. "x%x x%x\n", did, fbits,
  1232. vport->fc_rscn_id_cnt);
  1233. goto out;
  1234. }
  1235. }
  1236. }
  1237. else {
  1238. /* Check for retry */
  1239. if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
  1240. retry = 1;
  1241. if (ulp_status == IOSTAT_LOCAL_REJECT) {
  1242. switch ((ulp_word4 &
  1243. IOERR_PARAM_MASK)) {
  1244. case IOERR_NO_RESOURCES:
  1245. /* We don't increment the retry
  1246. * count for this case.
  1247. */
  1248. break;
  1249. case IOERR_LINK_DOWN:
  1250. case IOERR_SLI_ABORTED:
  1251. case IOERR_SLI_DOWN:
  1252. retry = 0;
  1253. break;
  1254. default:
  1255. cmdiocb->retry++;
  1256. }
  1257. }
  1258. else
  1259. cmdiocb->retry++;
  1260. if (retry) {
  1261. /* CT command is being retried */
  1262. rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
  1263. cmdiocb->retry, did);
  1264. if (rc == 0) {
  1265. /* success */
  1266. free_ndlp = cmdiocb->ndlp;
  1267. lpfc_ct_free_iocb(phba, cmdiocb);
  1268. lpfc_nlp_put(free_ndlp);
  1269. return;
  1270. }
  1271. }
  1272. }
  1273. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1274. "0267 NameServer GFF Rsp "
  1275. "x%x Error (%d %d) Data: x%lx x%x\n",
  1276. did, ulp_status, ulp_word4,
  1277. vport->fc_flag, vport->fc_rscn_id_cnt);
  1278. }
  1279. /* This is a target port, unregistered port, or the GFF_ID failed */
  1280. ndlp = lpfc_setup_disc_node(vport, did);
  1281. if (ndlp) {
  1282. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1283. "0242 Process x%x GFF "
  1284. "NameServer Rsp Data: x%x x%lx x%x\n",
  1285. did, ndlp->nlp_flag, vport->fc_flag,
  1286. vport->fc_rscn_id_cnt);
  1287. } else {
  1288. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1289. "0243 Skip x%x GFF "
  1290. "NameServer Rsp Data: x%lx x%x\n", did,
  1291. vport->fc_flag, vport->fc_rscn_id_cnt);
  1292. }
  1293. out:
  1294. /* Link up / RSCN discovery */
  1295. if (vport->num_disc_nodes)
  1296. vport->num_disc_nodes--;
  1297. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1298. "6451 GFF_ID cmpl inp %d disc %d\n",
  1299. vport->gidft_inp, vport->num_disc_nodes);
  1300. if (vport->num_disc_nodes == 0) {
  1301. /*
  1302. * The driver has cycled through all Nports in the RSCN payload.
  1303. * Complete the handling by cleaning up and marking the
  1304. * current driver state.
  1305. */
  1306. if (vport->port_state >= LPFC_DISC_AUTH) {
  1307. if (test_bit(FC_RSCN_MODE, &vport->fc_flag)) {
  1308. lpfc_els_flush_rscn(vport);
  1309. /* RSCN still */
  1310. set_bit(FC_RSCN_MODE, &vport->fc_flag);
  1311. } else {
  1312. lpfc_els_flush_rscn(vport);
  1313. }
  1314. }
  1315. lpfc_disc_start(vport);
  1316. }
  1317. iocb_free:
  1318. free_ndlp = cmdiocb->ndlp;
  1319. lpfc_ct_free_iocb(phba, cmdiocb);
  1320. lpfc_nlp_put(free_ndlp);
  1321. return;
  1322. }
  1323. static void
  1324. lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1325. struct lpfc_iocbq *rspiocb)
  1326. {
  1327. struct lpfc_vport *vport = cmdiocb->vport;
  1328. struct lpfc_dmabuf *inp = cmdiocb->cmd_dmabuf;
  1329. struct lpfc_dmabuf *outp = cmdiocb->rsp_dmabuf;
  1330. struct lpfc_sli_ct_request *CTrsp;
  1331. int did;
  1332. struct lpfc_nodelist *ndlp = NULL;
  1333. struct lpfc_nodelist *ns_ndlp = cmdiocb->ndlp;
  1334. uint32_t fc4_data_0, fc4_data_1;
  1335. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1336. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  1337. did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
  1338. did = be32_to_cpu(did);
  1339. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1340. "GFT_ID cmpl: status:x%x/x%x did:x%x",
  1341. ulp_status, ulp_word4, did);
  1342. /* Ignore response if link flipped after this request was made */
  1343. if ((uint32_t)cmdiocb->event_tag != phba->fc_eventTag) {
  1344. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1345. "9046 Event tag mismatch. Ignoring NS rsp\n");
  1346. goto out;
  1347. }
  1348. if (ulp_status == IOSTAT_SUCCESS) {
  1349. /* Good status, continue checking */
  1350. CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
  1351. fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
  1352. fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
  1353. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1354. "6432 Process GFT_ID rsp for %08x "
  1355. "Data %08x %08x %s %s\n",
  1356. did, fc4_data_0, fc4_data_1,
  1357. (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ?
  1358. "FCP" : " ",
  1359. (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ?
  1360. "NVME" : " ");
  1361. /* Lookup the NPort_ID queried in the GFT_ID and find the
  1362. * driver's local node. It's an error if the driver
  1363. * doesn't have one.
  1364. */
  1365. ndlp = lpfc_findnode_did(vport, did);
  1366. if (ndlp) {
  1367. /* The bitmask value for FCP and NVME FCP types is
  1368. * the same because they are 32 bits distant from
  1369. * each other in word0 and word0.
  1370. */
  1371. if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
  1372. ndlp->nlp_fc4_type |= NLP_FC4_FCP;
  1373. if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
  1374. ndlp->nlp_fc4_type |= NLP_FC4_NVME;
  1375. lpfc_printf_vlog(vport, KERN_INFO,
  1376. LOG_DISCOVERY | LOG_NODE,
  1377. "3064 Setting ndlp x%px, DID x%06x "
  1378. "with FC4 x%08x, Data: x%08x x%08x "
  1379. "%d\n",
  1380. ndlp, did, ndlp->nlp_fc4_type,
  1381. FC_TYPE_FCP, FC_TYPE_NVME,
  1382. ndlp->nlp_state);
  1383. if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE &&
  1384. ndlp->nlp_fc4_type) {
  1385. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1386. lpfc_nlp_set_state(vport, ndlp,
  1387. NLP_STE_PRLI_ISSUE);
  1388. lpfc_issue_els_prli(vport, ndlp, 0);
  1389. } else if (!ndlp->nlp_fc4_type) {
  1390. /* If fc4 type is still unknown, then LOGO */
  1391. lpfc_printf_vlog(vport, KERN_INFO,
  1392. LOG_DISCOVERY | LOG_NODE,
  1393. "6443 Sending LOGO ndlp x%px, "
  1394. "DID x%06x with fc4_type: "
  1395. "x%08x, state: %d\n",
  1396. ndlp, did, ndlp->nlp_fc4_type,
  1397. ndlp->nlp_state);
  1398. lpfc_issue_els_logo(vport, ndlp, 0);
  1399. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  1400. lpfc_nlp_set_state(vport, ndlp,
  1401. NLP_STE_NPR_NODE);
  1402. }
  1403. }
  1404. } else
  1405. lpfc_vlog_msg(vport, KERN_WARNING, LOG_DISCOVERY,
  1406. "3065 GFT_ID status x%08x\n", ulp_status);
  1407. out:
  1408. lpfc_ct_free_iocb(phba, cmdiocb);
  1409. lpfc_nlp_put(ns_ndlp);
  1410. }
  1411. static void
  1412. lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1413. struct lpfc_iocbq *rspiocb)
  1414. {
  1415. struct lpfc_vport *vport = cmdiocb->vport;
  1416. struct lpfc_dmabuf *inp;
  1417. struct lpfc_dmabuf *outp;
  1418. struct lpfc_sli_ct_request *CTrsp;
  1419. struct lpfc_nodelist *ndlp;
  1420. int cmdcode, rc;
  1421. uint8_t retry;
  1422. uint32_t latt;
  1423. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1424. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  1425. /* First save ndlp, before we overwrite it */
  1426. ndlp = cmdiocb->ndlp;
  1427. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1428. cmdiocb->rsp_iocb = rspiocb;
  1429. inp = cmdiocb->cmd_dmabuf;
  1430. outp = cmdiocb->rsp_dmabuf;
  1431. cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
  1432. CommandResponse.bits.CmdRsp);
  1433. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  1434. latt = lpfc_els_chk_latt(vport);
  1435. /* RFT request completes status <ulp_status> CmdRsp <CmdRsp> */
  1436. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1437. "0209 CT Request completes, latt %d, "
  1438. "ulp_status x%x CmdRsp x%x, Context x%x, Tag x%x\n",
  1439. latt, ulp_status,
  1440. be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp),
  1441. get_job_ulpcontext(phba, cmdiocb), cmdiocb->iotag);
  1442. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1443. "CT cmd cmpl: status:x%x/x%x cmd:x%x",
  1444. ulp_status, ulp_word4, cmdcode);
  1445. if (ulp_status) {
  1446. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1447. "0268 NS cmd x%x Error (x%x x%x)\n",
  1448. cmdcode, ulp_status, ulp_word4);
  1449. if (ulp_status == IOSTAT_LOCAL_REJECT &&
  1450. (((ulp_word4 & IOERR_PARAM_MASK) ==
  1451. IOERR_SLI_DOWN) ||
  1452. ((ulp_word4 & IOERR_PARAM_MASK) ==
  1453. IOERR_SLI_ABORTED)))
  1454. goto out;
  1455. retry = cmdiocb->retry;
  1456. if (retry >= LPFC_MAX_NS_RETRY)
  1457. goto out;
  1458. retry++;
  1459. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1460. "0250 Retrying NS cmd %x\n", cmdcode);
  1461. rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
  1462. if (rc == 0)
  1463. goto out;
  1464. }
  1465. out:
  1466. /* If the caller wanted a synchronous DA_ID completion, signal the
  1467. * wait obj and clear flag to reset the vport.
  1468. */
  1469. if (ndlp->save_flags & NLP_WAIT_FOR_DA_ID) {
  1470. if (ndlp->da_id_waitq)
  1471. wake_up(ndlp->da_id_waitq);
  1472. }
  1473. spin_lock_irq(&ndlp->lock);
  1474. ndlp->save_flags &= ~NLP_WAIT_FOR_DA_ID;
  1475. spin_unlock_irq(&ndlp->lock);
  1476. lpfc_ct_free_iocb(phba, cmdiocb);
  1477. lpfc_nlp_put(ndlp);
  1478. return;
  1479. }
  1480. static void
  1481. lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1482. struct lpfc_iocbq *rspiocb)
  1483. {
  1484. struct lpfc_vport *vport = cmdiocb->vport;
  1485. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1486. if (ulp_status == IOSTAT_SUCCESS) {
  1487. struct lpfc_dmabuf *outp;
  1488. struct lpfc_sli_ct_request *CTrsp;
  1489. outp = cmdiocb->rsp_dmabuf;
  1490. CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
  1491. if (be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp) ==
  1492. SLI_CT_RESPONSE_FS_ACC)
  1493. vport->ct_flags |= FC_CT_RFT_ID;
  1494. }
  1495. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1496. return;
  1497. }
  1498. static void
  1499. lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1500. struct lpfc_iocbq *rspiocb)
  1501. {
  1502. struct lpfc_vport *vport = cmdiocb->vport;
  1503. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1504. if (ulp_status == IOSTAT_SUCCESS) {
  1505. struct lpfc_dmabuf *outp;
  1506. struct lpfc_sli_ct_request *CTrsp;
  1507. outp = cmdiocb->rsp_dmabuf;
  1508. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  1509. if (be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp) ==
  1510. SLI_CT_RESPONSE_FS_ACC)
  1511. vport->ct_flags |= FC_CT_RNN_ID;
  1512. }
  1513. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1514. return;
  1515. }
  1516. static void
  1517. lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1518. struct lpfc_iocbq *rspiocb)
  1519. {
  1520. struct lpfc_vport *vport = cmdiocb->vport;
  1521. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1522. if (ulp_status == IOSTAT_SUCCESS) {
  1523. struct lpfc_dmabuf *outp;
  1524. struct lpfc_sli_ct_request *CTrsp;
  1525. outp = cmdiocb->rsp_dmabuf;
  1526. CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
  1527. if (be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp) ==
  1528. SLI_CT_RESPONSE_FS_ACC)
  1529. vport->ct_flags |= FC_CT_RSPN_ID;
  1530. }
  1531. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1532. return;
  1533. }
  1534. static void
  1535. lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1536. struct lpfc_iocbq *rspiocb)
  1537. {
  1538. struct lpfc_vport *vport = cmdiocb->vport;
  1539. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1540. if (ulp_status == IOSTAT_SUCCESS) {
  1541. struct lpfc_dmabuf *outp;
  1542. struct lpfc_sli_ct_request *CTrsp;
  1543. outp = cmdiocb->rsp_dmabuf;
  1544. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  1545. if (be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp) ==
  1546. SLI_CT_RESPONSE_FS_ACC)
  1547. vport->ct_flags |= FC_CT_RSNN_NN;
  1548. }
  1549. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1550. return;
  1551. }
  1552. static void
  1553. lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1554. struct lpfc_iocbq *rspiocb)
  1555. {
  1556. struct lpfc_vport *vport = cmdiocb->vport;
  1557. /* even if it fails we will act as though it succeeded. */
  1558. vport->ct_flags = 0;
  1559. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1560. return;
  1561. }
  1562. static void
  1563. lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1564. struct lpfc_iocbq *rspiocb)
  1565. {
  1566. struct lpfc_vport *vport = cmdiocb->vport;
  1567. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1568. if (ulp_status == IOSTAT_SUCCESS) {
  1569. struct lpfc_dmabuf *outp;
  1570. struct lpfc_sli_ct_request *CTrsp;
  1571. outp = cmdiocb->rsp_dmabuf;
  1572. CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
  1573. if (be16_to_cpu(CTrsp->CommandResponse.bits.CmdRsp) ==
  1574. SLI_CT_RESPONSE_FS_ACC)
  1575. vport->ct_flags |= FC_CT_RFF_ID;
  1576. }
  1577. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1578. return;
  1579. }
  1580. /*
  1581. * Although the symbolic port name is thought to be an integer
  1582. * as of January 18, 2016, leave it as a string until more of
  1583. * the record state becomes defined.
  1584. */
  1585. int
  1586. lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
  1587. size_t size)
  1588. {
  1589. int n;
  1590. /*
  1591. * Use the lpfc board number as the Symbolic Port
  1592. * Name object. NPIV is not in play so this integer
  1593. * value is sufficient and unique per FC-ID.
  1594. */
  1595. n = scnprintf(symbol, size, "%d", vport->phba->brd_no);
  1596. return n;
  1597. }
  1598. int
  1599. lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
  1600. size_t size)
  1601. {
  1602. char fwrev[FW_REV_STR_SIZE] = {0};
  1603. char tmp[MAXHOSTNAMELEN] = {0};
  1604. memset(symbol, 0, size);
  1605. scnprintf(tmp, sizeof(tmp), "Emulex %s", vport->phba->ModelName);
  1606. if (strlcat(symbol, tmp, size) >= size)
  1607. goto buffer_done;
  1608. lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
  1609. scnprintf(tmp, sizeof(tmp), " FV%s", fwrev);
  1610. if (strlcat(symbol, tmp, size) >= size)
  1611. goto buffer_done;
  1612. scnprintf(tmp, sizeof(tmp), " DV%s", lpfc_release_version);
  1613. if (strlcat(symbol, tmp, size) >= size)
  1614. goto buffer_done;
  1615. scnprintf(tmp, sizeof(tmp), " HN:%s", vport->phba->os_host_name);
  1616. if (strlcat(symbol, tmp, size) >= size)
  1617. goto buffer_done;
  1618. /* Note :- OS name is "Linux" */
  1619. scnprintf(tmp, sizeof(tmp), " OS:%s", init_utsname()->sysname);
  1620. strlcat(symbol, tmp, size);
  1621. buffer_done:
  1622. return strnlen(symbol, size);
  1623. }
  1624. static uint32_t
  1625. lpfc_find_map_node(struct lpfc_vport *vport)
  1626. {
  1627. struct lpfc_nodelist *ndlp, *next_ndlp;
  1628. unsigned long iflags;
  1629. uint32_t cnt = 0;
  1630. spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
  1631. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1632. if (ndlp->nlp_type & NLP_FABRIC)
  1633. continue;
  1634. if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
  1635. (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
  1636. cnt++;
  1637. }
  1638. spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
  1639. return cnt;
  1640. }
  1641. /*
  1642. * This routine will return the FC4 Type associated with the CT
  1643. * GID_FT command.
  1644. */
  1645. int
  1646. lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
  1647. {
  1648. struct lpfc_sli_ct_request *CtReq;
  1649. struct lpfc_dmabuf *mp;
  1650. uint32_t type;
  1651. mp = cmdiocb->cmd_dmabuf;
  1652. if (mp == NULL)
  1653. return 0;
  1654. CtReq = (struct lpfc_sli_ct_request *)mp->virt;
  1655. type = (uint32_t)CtReq->un.gid.Fc4Type;
  1656. if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
  1657. return 0;
  1658. return type;
  1659. }
  1660. /*
  1661. * lpfc_ns_cmd
  1662. * Description:
  1663. * Issue Cmd to NameServer
  1664. * SLI_CTNS_GID_FT
  1665. * LI_CTNS_RFT_ID
  1666. */
  1667. int
  1668. lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
  1669. uint8_t retry, uint32_t context)
  1670. {
  1671. struct lpfc_nodelist * ndlp;
  1672. struct lpfc_hba *phba = vport->phba;
  1673. struct lpfc_dmabuf *mp, *bmp;
  1674. struct lpfc_sli_ct_request *CtReq;
  1675. struct ulp_bde64 *bpl;
  1676. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  1677. struct lpfc_iocbq *) = NULL;
  1678. uint32_t *ptr;
  1679. uint32_t rsp_size = 1024;
  1680. size_t size;
  1681. int rc = 0;
  1682. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  1683. if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
  1684. rc=1;
  1685. goto ns_cmd_exit;
  1686. }
  1687. /* fill in BDEs for command */
  1688. /* Allocate buffer for command payload */
  1689. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1690. if (!mp) {
  1691. rc=2;
  1692. goto ns_cmd_exit;
  1693. }
  1694. INIT_LIST_HEAD(&mp->list);
  1695. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  1696. if (!mp->virt) {
  1697. rc=3;
  1698. goto ns_cmd_free_mp;
  1699. }
  1700. /* Allocate buffer for Buffer ptr list */
  1701. bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1702. if (!bmp) {
  1703. rc=4;
  1704. goto ns_cmd_free_mpvirt;
  1705. }
  1706. INIT_LIST_HEAD(&bmp->list);
  1707. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
  1708. if (!bmp->virt) {
  1709. rc=5;
  1710. goto ns_cmd_free_bmp;
  1711. }
  1712. /* NameServer Req */
  1713. lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
  1714. "0236 NameServer Req Data: x%x x%lx x%x x%x\n",
  1715. cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
  1716. context);
  1717. bpl = (struct ulp_bde64 *) bmp->virt;
  1718. memset(bpl, 0, sizeof(struct ulp_bde64));
  1719. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  1720. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  1721. bpl->tus.f.bdeFlags = 0;
  1722. if (cmdcode == SLI_CTNS_GID_FT)
  1723. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  1724. else if (cmdcode == SLI_CTNS_GID_PT)
  1725. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  1726. else if (cmdcode == SLI_CTNS_GFF_ID)
  1727. bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
  1728. else if (cmdcode == SLI_CTNS_GFT_ID)
  1729. bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
  1730. else if (cmdcode == SLI_CTNS_RFT_ID)
  1731. bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
  1732. else if (cmdcode == SLI_CTNS_RNN_ID)
  1733. bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
  1734. else if (cmdcode == SLI_CTNS_RSPN_ID)
  1735. bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
  1736. else if (cmdcode == SLI_CTNS_RSNN_NN)
  1737. bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
  1738. else if (cmdcode == SLI_CTNS_DA_ID)
  1739. bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
  1740. else if (cmdcode == SLI_CTNS_RFF_ID)
  1741. bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
  1742. else
  1743. bpl->tus.f.bdeSize = 0;
  1744. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1745. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  1746. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  1747. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  1748. CtReq->RevisionId.bits.InId = 0;
  1749. CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
  1750. CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
  1751. CtReq->CommandResponse.bits.Size = 0;
  1752. switch (cmdcode) {
  1753. case SLI_CTNS_GID_FT:
  1754. CtReq->CommandResponse.bits.CmdRsp =
  1755. cpu_to_be16(SLI_CTNS_GID_FT);
  1756. CtReq->un.gid.Fc4Type = context;
  1757. if (vport->port_state < LPFC_NS_QRY)
  1758. vport->port_state = LPFC_NS_QRY;
  1759. lpfc_set_disctmo(vport);
  1760. cmpl = lpfc_cmpl_ct_cmd_gid_ft;
  1761. rsp_size = FC_MAX_NS_RSP;
  1762. break;
  1763. case SLI_CTNS_GID_PT:
  1764. CtReq->CommandResponse.bits.CmdRsp =
  1765. cpu_to_be16(SLI_CTNS_GID_PT);
  1766. CtReq->un.gid.PortType = context;
  1767. if (vport->port_state < LPFC_NS_QRY)
  1768. vport->port_state = LPFC_NS_QRY;
  1769. lpfc_set_disctmo(vport);
  1770. cmpl = lpfc_cmpl_ct_cmd_gid_pt;
  1771. rsp_size = FC_MAX_NS_RSP;
  1772. break;
  1773. case SLI_CTNS_GFF_ID:
  1774. CtReq->CommandResponse.bits.CmdRsp =
  1775. cpu_to_be16(SLI_CTNS_GFF_ID);
  1776. CtReq->un.gff.PortId = cpu_to_be32(context);
  1777. cmpl = lpfc_cmpl_ct_cmd_gff_id;
  1778. break;
  1779. case SLI_CTNS_GFT_ID:
  1780. CtReq->CommandResponse.bits.CmdRsp =
  1781. cpu_to_be16(SLI_CTNS_GFT_ID);
  1782. CtReq->un.gft.PortId = cpu_to_be32(context);
  1783. cmpl = lpfc_cmpl_ct_cmd_gft_id;
  1784. break;
  1785. case SLI_CTNS_RFT_ID:
  1786. vport->ct_flags &= ~FC_CT_RFT_ID;
  1787. CtReq->CommandResponse.bits.CmdRsp =
  1788. cpu_to_be16(SLI_CTNS_RFT_ID);
  1789. CtReq->un.rft.port_id = cpu_to_be32(vport->fc_myDID);
  1790. /* Register Application Services type if vmid enabled. */
  1791. if (phba->cfg_vmid_app_header)
  1792. CtReq->un.rft.app_serv_reg =
  1793. cpu_to_be32(RFT_APP_SERV_REG);
  1794. /* Register FC4 FCP type if enabled. */
  1795. if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
  1796. vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
  1797. CtReq->un.rft.fcp_reg = cpu_to_be32(RFT_FCP_REG);
  1798. /* Register NVME type if enabled. */
  1799. if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
  1800. vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
  1801. CtReq->un.rft.nvme_reg = cpu_to_be32(RFT_NVME_REG);
  1802. ptr = (uint32_t *)CtReq;
  1803. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1804. "6433 Issue RFT (%s %s %s): %08x %08x %08x "
  1805. "%08x %08x %08x %08x %08x\n",
  1806. CtReq->un.rft.fcp_reg ? "FCP" : " ",
  1807. CtReq->un.rft.nvme_reg ? "NVME" : " ",
  1808. CtReq->un.rft.app_serv_reg ? "APPS" : " ",
  1809. *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
  1810. *(ptr + 4), *(ptr + 5),
  1811. *(ptr + 6), *(ptr + 7));
  1812. cmpl = lpfc_cmpl_ct_cmd_rft_id;
  1813. break;
  1814. case SLI_CTNS_RNN_ID:
  1815. vport->ct_flags &= ~FC_CT_RNN_ID;
  1816. CtReq->CommandResponse.bits.CmdRsp =
  1817. cpu_to_be16(SLI_CTNS_RNN_ID);
  1818. CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
  1819. memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
  1820. sizeof(struct lpfc_name));
  1821. cmpl = lpfc_cmpl_ct_cmd_rnn_id;
  1822. break;
  1823. case SLI_CTNS_RSPN_ID:
  1824. vport->ct_flags &= ~FC_CT_RSPN_ID;
  1825. CtReq->CommandResponse.bits.CmdRsp =
  1826. cpu_to_be16(SLI_CTNS_RSPN_ID);
  1827. CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
  1828. size = sizeof(CtReq->un.rspn.symbname);
  1829. CtReq->un.rspn.len =
  1830. lpfc_vport_symbolic_port_name(vport,
  1831. CtReq->un.rspn.symbname, size);
  1832. cmpl = lpfc_cmpl_ct_cmd_rspn_id;
  1833. break;
  1834. case SLI_CTNS_RSNN_NN:
  1835. vport->ct_flags &= ~FC_CT_RSNN_NN;
  1836. CtReq->CommandResponse.bits.CmdRsp =
  1837. cpu_to_be16(SLI_CTNS_RSNN_NN);
  1838. memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
  1839. sizeof(struct lpfc_name));
  1840. size = sizeof(CtReq->un.rsnn.symbname);
  1841. CtReq->un.rsnn.len =
  1842. lpfc_vport_symbolic_node_name(vport,
  1843. CtReq->un.rsnn.symbname, size);
  1844. cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
  1845. break;
  1846. case SLI_CTNS_DA_ID:
  1847. /* Implement DA_ID Nameserver request */
  1848. CtReq->CommandResponse.bits.CmdRsp =
  1849. cpu_to_be16(SLI_CTNS_DA_ID);
  1850. CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
  1851. cmpl = lpfc_cmpl_ct_cmd_da_id;
  1852. break;
  1853. case SLI_CTNS_RFF_ID:
  1854. vport->ct_flags &= ~FC_CT_RFF_ID;
  1855. CtReq->CommandResponse.bits.CmdRsp =
  1856. cpu_to_be16(SLI_CTNS_RFF_ID);
  1857. CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
  1858. CtReq->un.rff.fbits = FC4_FEATURE_INIT;
  1859. /* The driver always supports FC_TYPE_FCP. However, the
  1860. * caller can specify NVME (type x28) as well. But only
  1861. * these that FC4 type is supported.
  1862. */
  1863. if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
  1864. (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
  1865. (context == FC_TYPE_NVME)) {
  1866. if ((vport == phba->pport) && phba->nvmet_support) {
  1867. CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
  1868. FC4_FEATURE_NVME_DISC);
  1869. lpfc_nvmet_update_targetport(phba);
  1870. } else {
  1871. lpfc_nvme_update_localport(vport);
  1872. }
  1873. CtReq->un.rff.type_code = context;
  1874. } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
  1875. (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
  1876. (context == FC_TYPE_FCP))
  1877. CtReq->un.rff.type_code = context;
  1878. else
  1879. goto ns_cmd_free_bmpvirt;
  1880. ptr = (uint32_t *)CtReq;
  1881. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1882. "6434 Issue RFF (%s): %08x %08x %08x %08x "
  1883. "%08x %08x %08x %08x\n",
  1884. (context == FC_TYPE_NVME) ? "NVME" : "FCP",
  1885. *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
  1886. *(ptr + 4), *(ptr + 5),
  1887. *(ptr + 6), *(ptr + 7));
  1888. cmpl = lpfc_cmpl_ct_cmd_rff_id;
  1889. break;
  1890. }
  1891. /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  1892. * to hold ndlp reference for the corresponding callback function.
  1893. */
  1894. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
  1895. /* On success, The cmpl function will free the buffers */
  1896. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1897. "Issue CT cmd: cmd:x%x did:x%x",
  1898. cmdcode, ndlp->nlp_DID, 0);
  1899. return 0;
  1900. }
  1901. rc=6;
  1902. ns_cmd_free_bmpvirt:
  1903. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1904. ns_cmd_free_bmp:
  1905. kfree(bmp);
  1906. ns_cmd_free_mpvirt:
  1907. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1908. ns_cmd_free_mp:
  1909. kfree(mp);
  1910. ns_cmd_exit:
  1911. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1912. "0266 Issue NameServer Req x%x err %d Data: x%lx "
  1913. "x%x\n",
  1914. cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
  1915. return 1;
  1916. }
  1917. /**
  1918. * lpfc_fdmi_rprt_defer - Check for any deferred FDMI RPRT commands
  1919. * @phba: Pointer to HBA context object.
  1920. * @mask: Initial port attributes mask
  1921. *
  1922. * This function checks to see if any vports have deferred their FDMI RPRT.
  1923. * A vports RPRT may be deferred if it is issued before the primary ports
  1924. * RHBA completes.
  1925. */
  1926. static void
  1927. lpfc_fdmi_rprt_defer(struct lpfc_hba *phba, uint32_t mask)
  1928. {
  1929. struct lpfc_vport **vports;
  1930. struct lpfc_vport *vport;
  1931. struct lpfc_nodelist *ndlp;
  1932. int i;
  1933. set_bit(HBA_RHBA_CMPL, &phba->hba_flag);
  1934. vports = lpfc_create_vport_work_array(phba);
  1935. if (vports) {
  1936. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  1937. vport = vports[i];
  1938. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  1939. if (!ndlp)
  1940. continue;
  1941. if (vport->ct_flags & FC_CT_RPRT_DEFER) {
  1942. vport->ct_flags &= ~FC_CT_RPRT_DEFER;
  1943. vport->fdmi_port_mask = mask;
  1944. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
  1945. }
  1946. }
  1947. }
  1948. lpfc_destroy_vport_work_array(phba, vports);
  1949. }
  1950. /**
  1951. * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
  1952. * @phba: Pointer to HBA context object.
  1953. * @cmdiocb: Pointer to the command IOCBQ.
  1954. * @rspiocb: Pointer to the response IOCBQ.
  1955. *
  1956. * This function to handle the completion of a driver initiated FDMI
  1957. * CT command issued during discovery.
  1958. */
  1959. static void
  1960. lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1961. struct lpfc_iocbq *rspiocb)
  1962. {
  1963. struct lpfc_vport *vport = cmdiocb->vport;
  1964. struct lpfc_dmabuf *inp = cmdiocb->cmd_dmabuf;
  1965. struct lpfc_dmabuf *outp = cmdiocb->rsp_dmabuf;
  1966. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  1967. struct lpfc_sli_ct_request *CTrsp = outp->virt;
  1968. __be16 fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  1969. __be16 fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
  1970. struct lpfc_nodelist *ndlp, *free_ndlp = NULL;
  1971. uint32_t latt, cmd, err;
  1972. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1973. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  1974. latt = lpfc_els_chk_latt(vport);
  1975. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1976. "FDMI cmpl: status:x%x/x%x latt:%d",
  1977. ulp_status, ulp_word4, latt);
  1978. if (latt || ulp_status) {
  1979. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  1980. "0229 FDMI cmd %04x failed, latt = %d "
  1981. "ulp_status: (x%x/x%x), sli_flag x%x\n",
  1982. be16_to_cpu(fdmi_cmd), latt, ulp_status,
  1983. ulp_word4, phba->sli.sli_flag);
  1984. /* Look for a retryable error */
  1985. if (ulp_status == IOSTAT_LOCAL_REJECT) {
  1986. switch ((ulp_word4 & IOERR_PARAM_MASK)) {
  1987. case IOERR_SLI_ABORTED:
  1988. case IOERR_SLI_DOWN:
  1989. /* Driver aborted this IO. No retry as error
  1990. * is likely Offline->Online or some adapter
  1991. * error. Recovery will try again, but if port
  1992. * is not active there's no point to continue
  1993. * issuing follow up FDMI commands.
  1994. */
  1995. if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
  1996. free_ndlp = cmdiocb->ndlp;
  1997. lpfc_ct_free_iocb(phba, cmdiocb);
  1998. lpfc_nlp_put(free_ndlp);
  1999. return;
  2000. }
  2001. break;
  2002. case IOERR_ABORT_IN_PROGRESS:
  2003. case IOERR_SEQUENCE_TIMEOUT:
  2004. case IOERR_ILLEGAL_FRAME:
  2005. case IOERR_NO_RESOURCES:
  2006. case IOERR_ILLEGAL_COMMAND:
  2007. cmdiocb->retry++;
  2008. if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
  2009. break;
  2010. /* Retry the same FDMI command */
  2011. err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
  2012. cmdiocb, 0);
  2013. if (err == IOCB_ERROR)
  2014. break;
  2015. return;
  2016. default:
  2017. break;
  2018. }
  2019. }
  2020. }
  2021. free_ndlp = cmdiocb->ndlp;
  2022. lpfc_ct_free_iocb(phba, cmdiocb);
  2023. lpfc_nlp_put(free_ndlp);
  2024. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  2025. if (!ndlp)
  2026. return;
  2027. /* Check for a CT LS_RJT response */
  2028. cmd = be16_to_cpu(fdmi_cmd);
  2029. if (be16_to_cpu(fdmi_rsp) == SLI_CT_RESPONSE_FS_RJT) {
  2030. /* Log FDMI reject */
  2031. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY | LOG_ELS,
  2032. "0220 FDMI cmd FS_RJT Data: x%x", cmd);
  2033. /* Should we fallback to FDMI-2 / FDMI-1 ? */
  2034. switch (cmd) {
  2035. case SLI_MGMT_RHBA:
  2036. if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
  2037. /* Fallback to FDMI-1 for HBA attributes */
  2038. vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
  2039. /* If HBA attributes are FDMI1, so should
  2040. * port attributes be for consistency.
  2041. */
  2042. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  2043. /* Start over */
  2044. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
  2045. }
  2046. return;
  2047. case SLI_MGMT_RPRT:
  2048. if (vport->port_type != LPFC_PHYSICAL_PORT) {
  2049. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2050. if (!ndlp)
  2051. return;
  2052. }
  2053. if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
  2054. /* Fallback to FDMI-1 */
  2055. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  2056. /* Start over */
  2057. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  2058. return;
  2059. }
  2060. if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
  2061. vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
  2062. /* Retry the same command */
  2063. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  2064. }
  2065. return;
  2066. case SLI_MGMT_RPA:
  2067. /* No retry on Vendor, RPA only done on physical port */
  2068. if (phba->link_flag & LS_CT_VEN_RPA) {
  2069. phba->link_flag &= ~LS_CT_VEN_RPA;
  2070. if (phba->cmf_active_mode == LPFC_CFG_OFF)
  2071. return;
  2072. lpfc_printf_log(phba, KERN_WARNING,
  2073. LOG_DISCOVERY | LOG_ELS,
  2074. "6460 VEN FDMI RPA RJT\n");
  2075. return;
  2076. }
  2077. if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
  2078. /* Fallback to FDMI-1 */
  2079. vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
  2080. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  2081. /* Start over */
  2082. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
  2083. return;
  2084. }
  2085. if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
  2086. vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
  2087. /* Retry the same command */
  2088. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  2089. }
  2090. return;
  2091. }
  2092. }
  2093. /*
  2094. * On success, need to cycle thru FDMI registration for discovery
  2095. * DHBA -> DPRT -> RHBA -> RPA (physical port)
  2096. * DPRT -> RPRT (vports)
  2097. */
  2098. switch (cmd) {
  2099. case SLI_MGMT_RHBA:
  2100. /* Check for any RPRTs deferred till after RHBA completes */
  2101. lpfc_fdmi_rprt_defer(phba, vport->fdmi_port_mask);
  2102. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
  2103. break;
  2104. case SLI_MGMT_DHBA:
  2105. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
  2106. break;
  2107. case SLI_MGMT_DPRT:
  2108. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  2109. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
  2110. } else {
  2111. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2112. if (!ndlp)
  2113. return;
  2114. /* Only issue a RPRT for the vport if the RHBA
  2115. * for the physical port completes successfully.
  2116. * We may have to defer the RPRT accordingly.
  2117. */
  2118. if (test_bit(HBA_RHBA_CMPL, &phba->hba_flag)) {
  2119. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
  2120. } else {
  2121. lpfc_printf_vlog(vport, KERN_INFO,
  2122. LOG_DISCOVERY,
  2123. "6078 RPRT deferred\n");
  2124. vport->ct_flags |= FC_CT_RPRT_DEFER;
  2125. }
  2126. }
  2127. break;
  2128. case SLI_MGMT_RPA:
  2129. if (vport->port_type == LPFC_PHYSICAL_PORT &&
  2130. phba->sli4_hba.pc_sli4_params.mi_ver) {
  2131. /* mi is only for the phyical port, no vports */
  2132. if (phba->link_flag & LS_CT_VEN_RPA) {
  2133. lpfc_printf_vlog(vport, KERN_INFO,
  2134. LOG_DISCOVERY | LOG_ELS |
  2135. LOG_CGN_MGMT,
  2136. "6449 VEN RPA FDMI Success\n");
  2137. phba->link_flag &= ~LS_CT_VEN_RPA;
  2138. break;
  2139. }
  2140. lpfc_printf_log(phba, KERN_INFO,
  2141. LOG_DISCOVERY | LOG_CGN_MGMT,
  2142. "6210 Issue Vendor MI FDMI %x\n",
  2143. phba->sli4_hba.pc_sli4_params.mi_ver);
  2144. /* CGN is only for the physical port, no vports */
  2145. if (lpfc_fdmi_cmd(vport, ndlp, cmd,
  2146. LPFC_FDMI_VENDOR_ATTR_mi) == 0)
  2147. phba->link_flag |= LS_CT_VEN_RPA;
  2148. lpfc_printf_log(phba, KERN_INFO,
  2149. LOG_DISCOVERY | LOG_ELS,
  2150. "6458 Send MI FDMI:%x Flag x%x\n",
  2151. phba->sli4_hba.pc_sli4_params.mi_ver,
  2152. phba->link_flag);
  2153. } else {
  2154. lpfc_printf_log(phba, KERN_INFO,
  2155. LOG_DISCOVERY | LOG_ELS,
  2156. "6459 No FDMI VEN MI support - "
  2157. "RPA Success\n");
  2158. }
  2159. break;
  2160. }
  2161. return;
  2162. }
  2163. /**
  2164. * lpfc_fdmi_change_check - Check for changed FDMI parameters
  2165. * @vport: pointer to a host virtual N_Port data structure.
  2166. *
  2167. * Check how many mapped NPorts we are connected to
  2168. * Check if our hostname changed
  2169. * Called from hbeat timeout routine to check if any FDMI parameters
  2170. * changed. If so, re-register those Attributes.
  2171. */
  2172. void
  2173. lpfc_fdmi_change_check(struct lpfc_vport *vport)
  2174. {
  2175. struct lpfc_hba *phba = vport->phba;
  2176. struct lpfc_nodelist *ndlp;
  2177. uint16_t cnt;
  2178. if (!lpfc_is_link_up(phba))
  2179. return;
  2180. /* Must be connected to a Fabric */
  2181. if (!test_bit(FC_FABRIC, &vport->fc_flag))
  2182. return;
  2183. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  2184. if (!ndlp)
  2185. return;
  2186. /* Check if system hostname changed */
  2187. if (strcmp(phba->os_host_name, init_utsname()->nodename)) {
  2188. memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
  2189. scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
  2190. init_utsname()->nodename);
  2191. lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
  2192. /* Since this effects multiple HBA and PORT attributes, we need
  2193. * de-register and go thru the whole FDMI registration cycle.
  2194. * DHBA -> DPRT -> RHBA -> RPA (physical port)
  2195. * DPRT -> RPRT (vports)
  2196. */
  2197. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  2198. /* For extra Vendor RPA */
  2199. phba->link_flag &= ~LS_CT_VEN_RPA;
  2200. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
  2201. } else {
  2202. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2203. if (!ndlp)
  2204. return;
  2205. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
  2206. }
  2207. /* Since this code path registers all the port attributes
  2208. * we can just return without further checking.
  2209. */
  2210. return;
  2211. }
  2212. if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
  2213. return;
  2214. /* Check if the number of mapped NPorts changed */
  2215. cnt = lpfc_find_map_node(vport);
  2216. if (cnt == vport->fdmi_num_disc)
  2217. return;
  2218. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  2219. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
  2220. LPFC_FDMI_PORT_ATTR_num_disc);
  2221. } else {
  2222. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2223. if (!ndlp)
  2224. return;
  2225. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
  2226. LPFC_FDMI_PORT_ATTR_num_disc);
  2227. }
  2228. }
  2229. static inline int
  2230. lpfc_fdmi_set_attr_u32(void *attr, uint16_t attrtype, uint32_t attrval)
  2231. {
  2232. struct lpfc_fdmi_attr_u32 *ae = attr;
  2233. int size = sizeof(*ae);
  2234. ae->type = cpu_to_be16(attrtype);
  2235. ae->len = cpu_to_be16(size);
  2236. ae->value_u32 = cpu_to_be32(attrval);
  2237. return size;
  2238. }
  2239. static inline int
  2240. lpfc_fdmi_set_attr_wwn(void *attr, uint16_t attrtype, struct lpfc_name *wwn)
  2241. {
  2242. struct lpfc_fdmi_attr_wwn *ae = attr;
  2243. int size = sizeof(*ae);
  2244. ae->type = cpu_to_be16(attrtype);
  2245. ae->len = cpu_to_be16(size);
  2246. /* WWN's assumed to be bytestreams - Big Endian presentation */
  2247. memcpy(ae->name, wwn,
  2248. min_t(size_t, sizeof(struct lpfc_name), sizeof(__be64)));
  2249. return size;
  2250. }
  2251. static inline int
  2252. lpfc_fdmi_set_attr_fullwwn(void *attr, uint16_t attrtype,
  2253. struct lpfc_name *wwnn, struct lpfc_name *wwpn)
  2254. {
  2255. struct lpfc_fdmi_attr_fullwwn *ae = attr;
  2256. u8 *nname = ae->nname;
  2257. u8 *pname = ae->pname;
  2258. int size = sizeof(*ae);
  2259. ae->type = cpu_to_be16(attrtype);
  2260. ae->len = cpu_to_be16(size);
  2261. /* WWN's assumed to be bytestreams - Big Endian presentation */
  2262. memcpy(nname, wwnn,
  2263. min_t(size_t, sizeof(struct lpfc_name), sizeof(__be64)));
  2264. memcpy(pname, wwpn,
  2265. min_t(size_t, sizeof(struct lpfc_name), sizeof(__be64)));
  2266. return size;
  2267. }
  2268. static inline int
  2269. lpfc_fdmi_set_attr_string(void *attr, uint16_t attrtype, char *attrstring)
  2270. {
  2271. struct lpfc_fdmi_attr_string *ae = attr;
  2272. int len, size;
  2273. /*
  2274. * We are trusting the caller that if a fdmi string field
  2275. * is capped at 64 bytes, the caller passes in a string of
  2276. * 64 bytes or less.
  2277. */
  2278. strscpy(ae->value_string, attrstring, sizeof(ae->value_string));
  2279. len = strnlen(ae->value_string, sizeof(ae->value_string));
  2280. /* round string length to a 32bit boundary */
  2281. len += (len & 3) ? (4 - (len & 3)) : 4;
  2282. /* size is Type/Len (4 bytes) plus string length */
  2283. size = FOURBYTES + len;
  2284. ae->type = cpu_to_be16(attrtype);
  2285. ae->len = cpu_to_be16(size);
  2286. return size;
  2287. }
  2288. /* Bitfields for FC4 Types that can be reported */
  2289. #define ATTR_FC4_CT 0x00000001
  2290. #define ATTR_FC4_FCP 0x00000002
  2291. #define ATTR_FC4_NVME 0x00000004
  2292. static inline int
  2293. lpfc_fdmi_set_attr_fc4types(void *attr, uint16_t attrtype, uint32_t typemask)
  2294. {
  2295. struct lpfc_fdmi_attr_fc4types *ae = attr;
  2296. int size = sizeof(*ae);
  2297. ae->type = cpu_to_be16(attrtype);
  2298. ae->len = cpu_to_be16(size);
  2299. if (typemask & ATTR_FC4_FCP)
  2300. ae->value_types[2] = 0x01; /* Type 0x8 - FCP */
  2301. if (typemask & ATTR_FC4_CT)
  2302. ae->value_types[7] = 0x01; /* Type 0x20 - CT */
  2303. if (typemask & ATTR_FC4_NVME)
  2304. ae->value_types[6] = 0x01; /* Type 0x28 - NVME */
  2305. return size;
  2306. }
  2307. /* Routines for all individual HBA attributes */
  2308. static int
  2309. lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, void *attr)
  2310. {
  2311. return lpfc_fdmi_set_attr_wwn(attr, RHBA_NODENAME,
  2312. &vport->fc_sparam.nodeName);
  2313. }
  2314. static int
  2315. lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport, void *attr)
  2316. {
  2317. /* This string MUST be consistent with other FC platforms
  2318. * supported by Broadcom.
  2319. */
  2320. return lpfc_fdmi_set_attr_string(attr, RHBA_MANUFACTURER,
  2321. "Emulex Corporation");
  2322. }
  2323. static int
  2324. lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, void *attr)
  2325. {
  2326. struct lpfc_hba *phba = vport->phba;
  2327. return lpfc_fdmi_set_attr_string(attr, RHBA_SERIAL_NUMBER,
  2328. phba->SerialNumber);
  2329. }
  2330. static int
  2331. lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport, void *attr)
  2332. {
  2333. struct lpfc_hba *phba = vport->phba;
  2334. return lpfc_fdmi_set_attr_string(attr, RHBA_MODEL,
  2335. phba->ModelName);
  2336. }
  2337. static int
  2338. lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport, void *attr)
  2339. {
  2340. struct lpfc_hba *phba = vport->phba;
  2341. return lpfc_fdmi_set_attr_string(attr, RHBA_MODEL_DESCRIPTION,
  2342. phba->ModelDesc);
  2343. }
  2344. static int
  2345. lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport, void *attr)
  2346. {
  2347. struct lpfc_hba *phba = vport->phba;
  2348. lpfc_vpd_t *vp = &phba->vpd;
  2349. char buf[16] = { 0 };
  2350. snprintf(buf, sizeof(buf), "%08x", vp->rev.biuRev);
  2351. return lpfc_fdmi_set_attr_string(attr, RHBA_HARDWARE_VERSION, buf);
  2352. }
  2353. static int
  2354. lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport, void *attr)
  2355. {
  2356. return lpfc_fdmi_set_attr_string(attr, RHBA_DRIVER_VERSION,
  2357. lpfc_release_version);
  2358. }
  2359. static int
  2360. lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport, void *attr)
  2361. {
  2362. struct lpfc_hba *phba = vport->phba;
  2363. char buf[64] = { 0 };
  2364. if (phba->sli_rev == LPFC_SLI_REV4) {
  2365. lpfc_decode_firmware_rev(phba, buf, 1);
  2366. return lpfc_fdmi_set_attr_string(attr, RHBA_OPTION_ROM_VERSION,
  2367. buf);
  2368. }
  2369. return lpfc_fdmi_set_attr_string(attr, RHBA_OPTION_ROM_VERSION,
  2370. phba->OptionROMVersion);
  2371. }
  2372. static int
  2373. lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport, void *attr)
  2374. {
  2375. struct lpfc_hba *phba = vport->phba;
  2376. char buf[64] = { 0 };
  2377. lpfc_decode_firmware_rev(phba, buf, 1);
  2378. return lpfc_fdmi_set_attr_string(attr, RHBA_FIRMWARE_VERSION, buf);
  2379. }
  2380. static int
  2381. lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport, void *attr)
  2382. {
  2383. char buf[256] = { 0 };
  2384. snprintf(buf, sizeof(buf), "%s %s %s",
  2385. init_utsname()->sysname,
  2386. init_utsname()->release,
  2387. init_utsname()->version);
  2388. return lpfc_fdmi_set_attr_string(attr, RHBA_OS_NAME_VERSION, buf);
  2389. }
  2390. static int
  2391. lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport, void *attr)
  2392. {
  2393. return lpfc_fdmi_set_attr_u32(attr, RHBA_MAX_CT_PAYLOAD_LEN,
  2394. LPFC_MAX_CT_SIZE);
  2395. }
  2396. static int
  2397. lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport, void *attr)
  2398. {
  2399. char buf[256] = { 0 };
  2400. lpfc_vport_symbolic_node_name(vport, buf, sizeof(buf));
  2401. return lpfc_fdmi_set_attr_string(attr, RHBA_SYM_NODENAME, buf);
  2402. }
  2403. static int
  2404. lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport, void *attr)
  2405. {
  2406. return lpfc_fdmi_set_attr_u32(attr, RHBA_VENDOR_INFO, 0);
  2407. }
  2408. static int
  2409. lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport, void *attr)
  2410. {
  2411. /* Each driver instance corresponds to a single port */
  2412. return lpfc_fdmi_set_attr_u32(attr, RHBA_NUM_PORTS, 1);
  2413. }
  2414. static int
  2415. lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport, void *attr)
  2416. {
  2417. return lpfc_fdmi_set_attr_wwn(attr, RHBA_FABRIC_WWNN,
  2418. &vport->fabric_nodename);
  2419. }
  2420. static int
  2421. lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport, void *attr)
  2422. {
  2423. struct lpfc_hba *phba = vport->phba;
  2424. return lpfc_fdmi_set_attr_string(attr, RHBA_BIOS_VERSION,
  2425. phba->BIOSVersion);
  2426. }
  2427. static int
  2428. lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport, void *attr)
  2429. {
  2430. /* Driver doesn't have access to this information */
  2431. return lpfc_fdmi_set_attr_u32(attr, RHBA_BIOS_STATE, 0);
  2432. }
  2433. static int
  2434. lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport, void *attr)
  2435. {
  2436. return lpfc_fdmi_set_attr_string(attr, RHBA_VENDOR_ID, "EMULEX");
  2437. }
  2438. /*
  2439. * Routines for all individual PORT attributes
  2440. */
  2441. static int
  2442. lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport, void *attr)
  2443. {
  2444. struct lpfc_hba *phba = vport->phba;
  2445. u32 fc4types;
  2446. fc4types = (ATTR_FC4_CT | ATTR_FC4_FCP);
  2447. /* Check to see if Firmware supports NVME and on physical port */
  2448. if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) &&
  2449. phba->sli4_hba.pc_sli4_params.nvme)
  2450. fc4types |= ATTR_FC4_NVME;
  2451. return lpfc_fdmi_set_attr_fc4types(attr, RPRT_SUPPORTED_FC4_TYPES,
  2452. fc4types);
  2453. }
  2454. static int
  2455. lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport, void *attr)
  2456. {
  2457. struct lpfc_hba *phba = vport->phba;
  2458. u32 speeds = 0;
  2459. u32 tcfg;
  2460. u8 i, cnt;
  2461. if (!test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
  2462. cnt = 0;
  2463. if (phba->sli_rev == LPFC_SLI_REV4) {
  2464. tcfg = phba->sli4_hba.conf_trunk;
  2465. for (i = 0; i < 4; i++, tcfg >>= 1)
  2466. if (tcfg & 1)
  2467. cnt++;
  2468. }
  2469. if (cnt > 2) { /* 4 lane trunk group */
  2470. if (phba->lmt & LMT_64Gb)
  2471. speeds |= HBA_PORTSPEED_256GFC;
  2472. if (phba->lmt & LMT_32Gb)
  2473. speeds |= HBA_PORTSPEED_128GFC;
  2474. if (phba->lmt & LMT_16Gb)
  2475. speeds |= HBA_PORTSPEED_64GFC;
  2476. } else if (cnt) { /* 2 lane trunk group */
  2477. if (phba->lmt & LMT_128Gb)
  2478. speeds |= HBA_PORTSPEED_256GFC;
  2479. if (phba->lmt & LMT_64Gb)
  2480. speeds |= HBA_PORTSPEED_128GFC;
  2481. if (phba->lmt & LMT_32Gb)
  2482. speeds |= HBA_PORTSPEED_64GFC;
  2483. if (phba->lmt & LMT_16Gb)
  2484. speeds |= HBA_PORTSPEED_32GFC;
  2485. } else {
  2486. if (phba->lmt & LMT_256Gb)
  2487. speeds |= HBA_PORTSPEED_256GFC;
  2488. if (phba->lmt & LMT_128Gb)
  2489. speeds |= HBA_PORTSPEED_128GFC;
  2490. if (phba->lmt & LMT_64Gb)
  2491. speeds |= HBA_PORTSPEED_64GFC;
  2492. if (phba->lmt & LMT_32Gb)
  2493. speeds |= HBA_PORTSPEED_32GFC;
  2494. if (phba->lmt & LMT_16Gb)
  2495. speeds |= HBA_PORTSPEED_16GFC;
  2496. if (phba->lmt & LMT_10Gb)
  2497. speeds |= HBA_PORTSPEED_10GFC;
  2498. if (phba->lmt & LMT_8Gb)
  2499. speeds |= HBA_PORTSPEED_8GFC;
  2500. if (phba->lmt & LMT_4Gb)
  2501. speeds |= HBA_PORTSPEED_4GFC;
  2502. if (phba->lmt & LMT_2Gb)
  2503. speeds |= HBA_PORTSPEED_2GFC;
  2504. if (phba->lmt & LMT_1Gb)
  2505. speeds |= HBA_PORTSPEED_1GFC;
  2506. }
  2507. } else {
  2508. /* FCoE links support only one speed */
  2509. switch (phba->fc_linkspeed) {
  2510. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  2511. speeds = HBA_PORTSPEED_10GE;
  2512. break;
  2513. case LPFC_ASYNC_LINK_SPEED_25GBPS:
  2514. speeds = HBA_PORTSPEED_25GE;
  2515. break;
  2516. case LPFC_ASYNC_LINK_SPEED_40GBPS:
  2517. speeds = HBA_PORTSPEED_40GE;
  2518. break;
  2519. case LPFC_ASYNC_LINK_SPEED_100GBPS:
  2520. speeds = HBA_PORTSPEED_100GE;
  2521. break;
  2522. }
  2523. }
  2524. return lpfc_fdmi_set_attr_u32(attr, RPRT_SUPPORTED_SPEED, speeds);
  2525. }
  2526. static int
  2527. lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport, void *attr)
  2528. {
  2529. struct lpfc_hba *phba = vport->phba;
  2530. u32 speeds = 0;
  2531. if (!test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
  2532. switch (phba->fc_linkspeed) {
  2533. case LPFC_LINK_SPEED_1GHZ:
  2534. speeds = HBA_PORTSPEED_1GFC;
  2535. break;
  2536. case LPFC_LINK_SPEED_2GHZ:
  2537. speeds = HBA_PORTSPEED_2GFC;
  2538. break;
  2539. case LPFC_LINK_SPEED_4GHZ:
  2540. speeds = HBA_PORTSPEED_4GFC;
  2541. break;
  2542. case LPFC_LINK_SPEED_8GHZ:
  2543. speeds = HBA_PORTSPEED_8GFC;
  2544. break;
  2545. case LPFC_LINK_SPEED_10GHZ:
  2546. speeds = HBA_PORTSPEED_10GFC;
  2547. break;
  2548. case LPFC_LINK_SPEED_16GHZ:
  2549. speeds = HBA_PORTSPEED_16GFC;
  2550. break;
  2551. case LPFC_LINK_SPEED_32GHZ:
  2552. speeds = HBA_PORTSPEED_32GFC;
  2553. break;
  2554. case LPFC_LINK_SPEED_64GHZ:
  2555. speeds = HBA_PORTSPEED_64GFC;
  2556. break;
  2557. case LPFC_LINK_SPEED_128GHZ:
  2558. speeds = HBA_PORTSPEED_128GFC;
  2559. break;
  2560. case LPFC_LINK_SPEED_256GHZ:
  2561. speeds = HBA_PORTSPEED_256GFC;
  2562. break;
  2563. default:
  2564. speeds = HBA_PORTSPEED_UNKNOWN;
  2565. break;
  2566. }
  2567. } else {
  2568. switch (phba->fc_linkspeed) {
  2569. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  2570. speeds = HBA_PORTSPEED_10GE;
  2571. break;
  2572. case LPFC_ASYNC_LINK_SPEED_25GBPS:
  2573. speeds = HBA_PORTSPEED_25GE;
  2574. break;
  2575. case LPFC_ASYNC_LINK_SPEED_40GBPS:
  2576. speeds = HBA_PORTSPEED_40GE;
  2577. break;
  2578. case LPFC_ASYNC_LINK_SPEED_100GBPS:
  2579. speeds = HBA_PORTSPEED_100GE;
  2580. break;
  2581. default:
  2582. speeds = HBA_PORTSPEED_UNKNOWN;
  2583. break;
  2584. }
  2585. }
  2586. return lpfc_fdmi_set_attr_u32(attr, RPRT_PORT_SPEED, speeds);
  2587. }
  2588. static int
  2589. lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport, void *attr)
  2590. {
  2591. struct serv_parm *hsp = (struct serv_parm *)&vport->fc_sparam;
  2592. return lpfc_fdmi_set_attr_u32(attr, RPRT_MAX_FRAME_SIZE,
  2593. (((uint32_t)hsp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  2594. (uint32_t)hsp->cmn.bbRcvSizeLsb);
  2595. }
  2596. static int
  2597. lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport, void *attr)
  2598. {
  2599. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2600. char buf[64] = { 0 };
  2601. snprintf(buf, sizeof(buf), "/sys/class/scsi_host/host%d",
  2602. shost->host_no);
  2603. return lpfc_fdmi_set_attr_string(attr, RPRT_OS_DEVICE_NAME, buf);
  2604. }
  2605. static int
  2606. lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport, void *attr)
  2607. {
  2608. char buf[64] = { 0 };
  2609. scnprintf(buf, sizeof(buf), "%s", vport->phba->os_host_name);
  2610. return lpfc_fdmi_set_attr_string(attr, RPRT_HOST_NAME, buf);
  2611. }
  2612. static int
  2613. lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport, void *attr)
  2614. {
  2615. return lpfc_fdmi_set_attr_wwn(attr, RPRT_NODENAME,
  2616. &vport->fc_sparam.nodeName);
  2617. }
  2618. static int
  2619. lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport, void *attr)
  2620. {
  2621. return lpfc_fdmi_set_attr_wwn(attr, RPRT_PORTNAME,
  2622. &vport->fc_sparam.portName);
  2623. }
  2624. static int
  2625. lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport, void *attr)
  2626. {
  2627. char buf[256] = { 0 };
  2628. lpfc_vport_symbolic_port_name(vport, buf, sizeof(buf));
  2629. return lpfc_fdmi_set_attr_string(attr, RPRT_SYM_PORTNAME, buf);
  2630. }
  2631. static int
  2632. lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport, void *attr)
  2633. {
  2634. struct lpfc_hba *phba = vport->phba;
  2635. return lpfc_fdmi_set_attr_u32(attr, RPRT_PORT_TYPE,
  2636. (phba->fc_topology == LPFC_TOPOLOGY_LOOP) ?
  2637. LPFC_FDMI_PORTTYPE_NLPORT :
  2638. LPFC_FDMI_PORTTYPE_NPORT);
  2639. }
  2640. static int
  2641. lpfc_fdmi_port_attr_class(struct lpfc_vport *vport, void *attr)
  2642. {
  2643. return lpfc_fdmi_set_attr_u32(attr, RPRT_SUPPORTED_CLASS,
  2644. FC_COS_CLASS2 | FC_COS_CLASS3);
  2645. }
  2646. static int
  2647. lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport, void *attr)
  2648. {
  2649. return lpfc_fdmi_set_attr_wwn(attr, RPRT_FABRICNAME,
  2650. &vport->fabric_portname);
  2651. }
  2652. static int
  2653. lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport, void *attr)
  2654. {
  2655. struct lpfc_hba *phba = vport->phba;
  2656. u32 fc4types;
  2657. fc4types = (ATTR_FC4_CT | ATTR_FC4_FCP);
  2658. /* Check to see if NVME is configured or not */
  2659. if (vport == phba->pport &&
  2660. phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
  2661. fc4types |= ATTR_FC4_NVME;
  2662. return lpfc_fdmi_set_attr_fc4types(attr, RPRT_ACTIVE_FC4_TYPES,
  2663. fc4types);
  2664. }
  2665. static int
  2666. lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport, void *attr)
  2667. {
  2668. return lpfc_fdmi_set_attr_u32(attr, RPRT_PORT_STATE,
  2669. LPFC_FDMI_PORTSTATE_ONLINE);
  2670. }
  2671. static int
  2672. lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport, void *attr)
  2673. {
  2674. vport->fdmi_num_disc = lpfc_find_map_node(vport);
  2675. return lpfc_fdmi_set_attr_u32(attr, RPRT_DISC_PORT,
  2676. vport->fdmi_num_disc);
  2677. }
  2678. static int
  2679. lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport, void *attr)
  2680. {
  2681. return lpfc_fdmi_set_attr_u32(attr, RPRT_PORT_ID, vport->fc_myDID);
  2682. }
  2683. static int
  2684. lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport, void *attr)
  2685. {
  2686. return lpfc_fdmi_set_attr_string(attr, RPRT_SMART_SERVICE,
  2687. "Smart SAN Initiator");
  2688. }
  2689. static int
  2690. lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport, void *attr)
  2691. {
  2692. return lpfc_fdmi_set_attr_fullwwn(attr, RPRT_SMART_GUID,
  2693. &vport->fc_sparam.nodeName,
  2694. &vport->fc_sparam.portName);
  2695. }
  2696. static int
  2697. lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport, void *attr)
  2698. {
  2699. return lpfc_fdmi_set_attr_string(attr, RPRT_SMART_VERSION,
  2700. "Smart SAN Version 2.0");
  2701. }
  2702. static int
  2703. lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport, void *attr)
  2704. {
  2705. struct lpfc_hba *phba = vport->phba;
  2706. return lpfc_fdmi_set_attr_string(attr, RPRT_SMART_MODEL,
  2707. phba->ModelName);
  2708. }
  2709. static int
  2710. lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport, void *attr)
  2711. {
  2712. /* SRIOV (type 3) is not supported */
  2713. return lpfc_fdmi_set_attr_u32(attr, RPRT_SMART_PORT_INFO,
  2714. (vport->vpi) ? 2 /* NPIV */ : 1 /* Physical */);
  2715. }
  2716. static int
  2717. lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport, void *attr)
  2718. {
  2719. return lpfc_fdmi_set_attr_u32(attr, RPRT_SMART_QOS, 0);
  2720. }
  2721. static int
  2722. lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport, void *attr)
  2723. {
  2724. return lpfc_fdmi_set_attr_u32(attr, RPRT_SMART_SECURITY, 1);
  2725. }
  2726. static int
  2727. lpfc_fdmi_vendor_attr_mi(struct lpfc_vport *vport, void *attr)
  2728. {
  2729. struct lpfc_hba *phba = vport->phba;
  2730. char buf[32] = { 0 };
  2731. sprintf(buf, "ELXE2EM:%04d", phba->sli4_hba.pc_sli4_params.mi_ver);
  2732. return lpfc_fdmi_set_attr_string(attr, RPRT_VENDOR_MI, buf);
  2733. }
  2734. /* RHBA attribute jump table */
  2735. static int (*lpfc_fdmi_hba_action[])
  2736. (struct lpfc_vport *vport, void *attrbuf) = {
  2737. /* Action routine Mask bit Attribute type */
  2738. lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
  2739. lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
  2740. lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
  2741. lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
  2742. lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
  2743. lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
  2744. lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
  2745. lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
  2746. lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
  2747. lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
  2748. lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
  2749. lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
  2750. lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
  2751. lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
  2752. lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
  2753. lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
  2754. lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
  2755. lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
  2756. };
  2757. /* RPA / RPRT attribute jump table */
  2758. static int (*lpfc_fdmi_port_action[])
  2759. (struct lpfc_vport *vport, void *attrbuf) = {
  2760. /* Action routine Mask bit Attribute type */
  2761. lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
  2762. lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
  2763. lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
  2764. lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
  2765. lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
  2766. lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
  2767. lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
  2768. lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
  2769. lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
  2770. lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
  2771. lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
  2772. lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
  2773. lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
  2774. lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
  2775. lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
  2776. lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
  2777. lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
  2778. lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
  2779. lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
  2780. lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
  2781. lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
  2782. lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
  2783. lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
  2784. lpfc_fdmi_vendor_attr_mi, /* bit23 RPRT_VENDOR_MI */
  2785. };
  2786. /**
  2787. * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
  2788. * @vport: pointer to a host virtual N_Port data structure.
  2789. * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
  2790. * @cmdcode: FDMI command to send
  2791. * @new_mask: Mask of HBA or PORT Attributes to send
  2792. *
  2793. * Builds and sends a FDMI command using the CT subsystem.
  2794. */
  2795. int
  2796. lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2797. int cmdcode, uint32_t new_mask)
  2798. {
  2799. struct lpfc_hba *phba = vport->phba;
  2800. struct lpfc_dmabuf *rq, *rsp;
  2801. struct lpfc_sli_ct_request *CtReq;
  2802. struct ulp_bde64_le *bde;
  2803. uint32_t bit_pos;
  2804. uint32_t size, addsz;
  2805. uint32_t rsp_size;
  2806. uint32_t mask;
  2807. struct lpfc_fdmi_reg_hba *rh;
  2808. struct lpfc_fdmi_port_entry *pe;
  2809. struct lpfc_fdmi_reg_portattr *pab = NULL, *base = NULL;
  2810. struct lpfc_fdmi_attr_block *ab = NULL;
  2811. int (*func)(struct lpfc_vport *vport, void *attrbuf);
  2812. void (*cmpl)(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2813. struct lpfc_iocbq *rspiocb);
  2814. if (!ndlp)
  2815. return 0;
  2816. cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
  2817. /* fill in BDEs for command */
  2818. /* Allocate buffer for command payload */
  2819. rq = kmalloc(sizeof(*rq), GFP_KERNEL);
  2820. if (!rq)
  2821. goto fdmi_cmd_exit;
  2822. rq->virt = lpfc_mbuf_alloc(phba, 0, &rq->phys);
  2823. if (!rq->virt)
  2824. goto fdmi_cmd_free_rq;
  2825. /* Allocate buffer for Buffer ptr list */
  2826. rsp = kmalloc(sizeof(*rsp), GFP_KERNEL);
  2827. if (!rsp)
  2828. goto fdmi_cmd_free_rqvirt;
  2829. rsp->virt = lpfc_mbuf_alloc(phba, 0, &rsp->phys);
  2830. if (!rsp->virt)
  2831. goto fdmi_cmd_free_rsp;
  2832. INIT_LIST_HEAD(&rq->list);
  2833. INIT_LIST_HEAD(&rsp->list);
  2834. /* mbuf buffers are 1K in length - aka LPFC_BPL_SIZE */
  2835. memset(rq->virt, 0, LPFC_BPL_SIZE);
  2836. rsp_size = LPFC_BPL_SIZE;
  2837. /* FDMI request */
  2838. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2839. "0218 FDMI Request x%x mask x%x Data: x%x x%lx x%x\n",
  2840. cmdcode, new_mask, vport->fdmi_port_mask,
  2841. vport->fc_flag, vport->port_state);
  2842. CtReq = (struct lpfc_sli_ct_request *)rq->virt;
  2843. /* First populate the CT_IU preamble */
  2844. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  2845. CtReq->RevisionId.bits.InId = 0;
  2846. CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  2847. CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
  2848. CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
  2849. size = 0;
  2850. /* Next fill in the specific FDMI cmd information */
  2851. switch (cmdcode) {
  2852. case SLI_MGMT_RHAT:
  2853. case SLI_MGMT_RHBA:
  2854. rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un;
  2855. /* HBA Identifier */
  2856. memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
  2857. sizeof(struct lpfc_name));
  2858. size += sizeof(struct lpfc_fdmi_hba_ident);
  2859. if (cmdcode == SLI_MGMT_RHBA) {
  2860. /* Registered Port List */
  2861. /* One entry (port) per adapter */
  2862. rh->rpl.EntryCnt = cpu_to_be32(1);
  2863. memcpy(&rh->rpl.pe.PortName,
  2864. &phba->pport->fc_sparam.portName,
  2865. sizeof(struct lpfc_name));
  2866. size += sizeof(struct lpfc_fdmi_reg_port_list);
  2867. }
  2868. ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
  2869. ab->EntryCnt = 0;
  2870. size += FOURBYTES; /* add length of EntryCnt field */
  2871. bit_pos = 0;
  2872. if (new_mask)
  2873. mask = new_mask;
  2874. else
  2875. mask = vport->fdmi_hba_mask;
  2876. /* Mask will dictate what attributes to build in the request */
  2877. while (mask) {
  2878. if (mask & 0x1) {
  2879. func = lpfc_fdmi_hba_action[bit_pos];
  2880. addsz = func(vport, ((uint8_t *)rh + size));
  2881. if (addsz) {
  2882. ab->EntryCnt++;
  2883. size += addsz;
  2884. }
  2885. /* check if another attribute fits */
  2886. if ((size + FDMI_MAX_ATTRLEN) >
  2887. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  2888. goto hba_out;
  2889. }
  2890. mask = mask >> 1;
  2891. bit_pos++;
  2892. }
  2893. hba_out:
  2894. ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
  2895. /* Total size */
  2896. size += GID_REQUEST_SZ - 4;
  2897. break;
  2898. case SLI_MGMT_RPRT:
  2899. if (vport->port_type != LPFC_PHYSICAL_PORT) {
  2900. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2901. if (!ndlp)
  2902. return 0;
  2903. }
  2904. fallthrough;
  2905. case SLI_MGMT_RPA:
  2906. /* Store base ptr right after preamble */
  2907. base = (struct lpfc_fdmi_reg_portattr *)&CtReq->un;
  2908. if (cmdcode == SLI_MGMT_RPRT) {
  2909. rh = (struct lpfc_fdmi_reg_hba *)base;
  2910. /* HBA Identifier */
  2911. memcpy(&rh->hi.PortName,
  2912. &phba->pport->fc_sparam.portName,
  2913. sizeof(struct lpfc_name));
  2914. pab = (struct lpfc_fdmi_reg_portattr *)
  2915. ((uint8_t *)base + sizeof(struct lpfc_name));
  2916. size += sizeof(struct lpfc_name);
  2917. } else {
  2918. pab = base;
  2919. }
  2920. memcpy((uint8_t *)&pab->PortName,
  2921. (uint8_t *)&vport->fc_sparam.portName,
  2922. sizeof(struct lpfc_name));
  2923. pab->ab.EntryCnt = 0;
  2924. /* add length of name and EntryCnt field */
  2925. size += sizeof(struct lpfc_name) + FOURBYTES;
  2926. bit_pos = 0;
  2927. if (new_mask)
  2928. mask = new_mask;
  2929. else
  2930. mask = vport->fdmi_port_mask;
  2931. /* Mask will dictate what attributes to build in the request */
  2932. while (mask) {
  2933. if (mask & 0x1) {
  2934. func = lpfc_fdmi_port_action[bit_pos];
  2935. addsz = func(vport, ((uint8_t *)base + size));
  2936. if (addsz) {
  2937. pab->ab.EntryCnt++;
  2938. size += addsz;
  2939. }
  2940. /* check if another attribute fits */
  2941. if ((size + FDMI_MAX_ATTRLEN) >
  2942. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  2943. goto port_out;
  2944. }
  2945. mask = mask >> 1;
  2946. bit_pos++;
  2947. }
  2948. port_out:
  2949. pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
  2950. size += GID_REQUEST_SZ - 4;
  2951. break;
  2952. case SLI_MGMT_GHAT:
  2953. case SLI_MGMT_GRPL:
  2954. rsp_size = FC_MAX_NS_RSP;
  2955. fallthrough;
  2956. case SLI_MGMT_DHBA:
  2957. case SLI_MGMT_DHAT:
  2958. pe = (struct lpfc_fdmi_port_entry *)&CtReq->un;
  2959. memcpy((uint8_t *)&pe->PortName,
  2960. (uint8_t *)&vport->fc_sparam.portName,
  2961. sizeof(struct lpfc_name));
  2962. size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
  2963. break;
  2964. case SLI_MGMT_GPAT:
  2965. case SLI_MGMT_GPAS:
  2966. rsp_size = FC_MAX_NS_RSP;
  2967. fallthrough;
  2968. case SLI_MGMT_DPRT:
  2969. if (vport->port_type != LPFC_PHYSICAL_PORT) {
  2970. ndlp = lpfc_findnode_did(phba->pport, FDMI_DID);
  2971. if (!ndlp)
  2972. return 0;
  2973. }
  2974. fallthrough;
  2975. case SLI_MGMT_DPA:
  2976. pe = (struct lpfc_fdmi_port_entry *)&CtReq->un;
  2977. memcpy((uint8_t *)&pe->PortName,
  2978. (uint8_t *)&vport->fc_sparam.portName,
  2979. sizeof(struct lpfc_name));
  2980. size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
  2981. break;
  2982. case SLI_MGMT_GRHL:
  2983. size = GID_REQUEST_SZ - 4;
  2984. break;
  2985. default:
  2986. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  2987. "0298 FDMI cmdcode x%x not supported\n",
  2988. cmdcode);
  2989. goto fdmi_cmd_free_rspvirt;
  2990. }
  2991. CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
  2992. bde = (struct ulp_bde64_le *)rsp->virt;
  2993. bde->addr_high = cpu_to_le32(putPaddrHigh(rq->phys));
  2994. bde->addr_low = cpu_to_le32(putPaddrLow(rq->phys));
  2995. bde->type_size = cpu_to_le32(ULP_BDE64_TYPE_BDE_64 <<
  2996. ULP_BDE64_TYPE_SHIFT);
  2997. bde->type_size |= cpu_to_le32(size);
  2998. /*
  2999. * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  3000. * to hold ndlp reference for the corresponding callback function.
  3001. */
  3002. if (!lpfc_ct_cmd(vport, rq, rsp, ndlp, cmpl, rsp_size, 0))
  3003. return 0;
  3004. fdmi_cmd_free_rspvirt:
  3005. lpfc_mbuf_free(phba, rsp->virt, rsp->phys);
  3006. fdmi_cmd_free_rsp:
  3007. kfree(rsp);
  3008. fdmi_cmd_free_rqvirt:
  3009. lpfc_mbuf_free(phba, rq->virt, rq->phys);
  3010. fdmi_cmd_free_rq:
  3011. kfree(rq);
  3012. fdmi_cmd_exit:
  3013. /* Issue FDMI request failed */
  3014. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3015. "0244 Issue FDMI request failed Data: x%x\n",
  3016. cmdcode);
  3017. return 1;
  3018. }
  3019. /**
  3020. * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
  3021. * @t: Context object of the timer.
  3022. *
  3023. * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
  3024. * the worker thread.
  3025. **/
  3026. void
  3027. lpfc_delayed_disc_tmo(struct timer_list *t)
  3028. {
  3029. struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
  3030. struct lpfc_hba *phba = vport->phba;
  3031. uint32_t tmo_posted;
  3032. unsigned long iflag;
  3033. spin_lock_irqsave(&vport->work_port_lock, iflag);
  3034. tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
  3035. if (!tmo_posted)
  3036. vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
  3037. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  3038. if (!tmo_posted)
  3039. lpfc_worker_wake_up(phba);
  3040. return;
  3041. }
  3042. /**
  3043. * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
  3044. * handle delayed discovery.
  3045. * @vport: pointer to a host virtual N_Port data structure.
  3046. *
  3047. * This function start nport discovery of the vport.
  3048. **/
  3049. void
  3050. lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
  3051. {
  3052. if (!test_and_clear_bit(FC_DISC_DELAYED, &vport->fc_flag))
  3053. return;
  3054. lpfc_do_scr_ns_plogi(vport->phba, vport);
  3055. }
  3056. void
  3057. lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
  3058. {
  3059. struct lpfc_sli *psli = &phba->sli;
  3060. lpfc_vpd_t *vp = &phba->vpd;
  3061. uint32_t b1, b2, b3, b4, i, rev;
  3062. char c;
  3063. uint32_t *ptr, str[4];
  3064. uint8_t *fwname;
  3065. if (phba->sli_rev == LPFC_SLI_REV4)
  3066. snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
  3067. else if (vp->rev.rBit) {
  3068. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  3069. rev = vp->rev.sli2FwRev;
  3070. else
  3071. rev = vp->rev.sli1FwRev;
  3072. b1 = (rev & 0x0000f000) >> 12;
  3073. b2 = (rev & 0x00000f00) >> 8;
  3074. b3 = (rev & 0x000000c0) >> 6;
  3075. b4 = (rev & 0x00000030) >> 4;
  3076. switch (b4) {
  3077. case 0:
  3078. c = 'N';
  3079. break;
  3080. case 1:
  3081. c = 'A';
  3082. break;
  3083. case 2:
  3084. c = 'B';
  3085. break;
  3086. case 3:
  3087. c = 'X';
  3088. break;
  3089. default:
  3090. c = 0;
  3091. break;
  3092. }
  3093. b4 = (rev & 0x0000000f);
  3094. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  3095. fwname = vp->rev.sli2FwName;
  3096. else
  3097. fwname = vp->rev.sli1FwName;
  3098. for (i = 0; i < 16; i++)
  3099. if (fwname[i] == 0x20)
  3100. fwname[i] = 0;
  3101. ptr = (uint32_t*)fwname;
  3102. for (i = 0; i < 3; i++)
  3103. str[i] = be32_to_cpu(*ptr++);
  3104. if (c == 0) {
  3105. if (flag)
  3106. sprintf(fwrevision, "%d.%d%d (%s)",
  3107. b1, b2, b3, (char *)str);
  3108. else
  3109. sprintf(fwrevision, "%d.%d%d", b1,
  3110. b2, b3);
  3111. } else {
  3112. if (flag)
  3113. sprintf(fwrevision, "%d.%d%d%c%d (%s)",
  3114. b1, b2, b3, c,
  3115. b4, (char *)str);
  3116. else
  3117. sprintf(fwrevision, "%d.%d%d%c%d",
  3118. b1, b2, b3, c, b4);
  3119. }
  3120. } else {
  3121. rev = vp->rev.smFwRev;
  3122. b1 = (rev & 0xff000000) >> 24;
  3123. b2 = (rev & 0x00f00000) >> 20;
  3124. b3 = (rev & 0x000f0000) >> 16;
  3125. c = (rev & 0x0000ff00) >> 8;
  3126. b4 = (rev & 0x000000ff);
  3127. sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
  3128. }
  3129. return;
  3130. }
  3131. static void
  3132. lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3133. struct lpfc_iocbq *rspiocb)
  3134. {
  3135. struct lpfc_vport *vport = cmdiocb->vport;
  3136. struct lpfc_dmabuf *inp = cmdiocb->cmd_dmabuf;
  3137. struct lpfc_dmabuf *outp = cmdiocb->rsp_dmabuf;
  3138. struct lpfc_sli_ct_request *ctcmd = inp->virt;
  3139. struct lpfc_sli_ct_request *ctrsp = outp->virt;
  3140. __be16 rsp = ctrsp->CommandResponse.bits.CmdRsp;
  3141. struct app_id_object *app;
  3142. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  3143. u32 cmd, hash, bucket;
  3144. struct lpfc_vmid *vmp, *cur;
  3145. u8 *data = outp->virt;
  3146. int i;
  3147. cmd = be16_to_cpu(ctcmd->CommandResponse.bits.CmdRsp);
  3148. if (cmd == SLI_CTAS_DALLAPP_ID)
  3149. lpfc_ct_free_iocb(phba, cmdiocb);
  3150. if (lpfc_els_chk_latt(vport) || get_job_ulpstatus(phba, rspiocb)) {
  3151. if (cmd != SLI_CTAS_DALLAPP_ID)
  3152. goto free_res;
  3153. }
  3154. /* Check for a CT LS_RJT response */
  3155. if (be16_to_cpu(rsp) == SLI_CT_RESPONSE_FS_RJT) {
  3156. if (cmd != SLI_CTAS_DALLAPP_ID)
  3157. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,
  3158. "3306 VMID FS_RJT Data: x%x x%x x%x\n",
  3159. cmd, ctrsp->ReasonCode,
  3160. ctrsp->Explanation);
  3161. if ((cmd != SLI_CTAS_DALLAPP_ID) ||
  3162. (ctrsp->ReasonCode != SLI_CT_UNABLE_TO_PERFORM_REQ) ||
  3163. (ctrsp->Explanation != SLI_CT_APP_ID_NOT_AVAILABLE)) {
  3164. /* If DALLAPP_ID failed retry later */
  3165. if (cmd == SLI_CTAS_DALLAPP_ID)
  3166. set_bit(FC_DEREGISTER_ALL_APP_ID,
  3167. &vport->load_flag);
  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. set_bit(FC_ALLOW_VMID, &vport->load_flag);
  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%lx 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. struct_size(rap, obj, be32_to_cpu(rap->no_of_objects));
  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. struct_size(dap, obj, be32_to_cpu(dap->no_of_objects));
  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. }