1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921 |
- /*******************************************************************
- * This file is part of the Emulex Linux Device Driver for *
- * Fibre Channel Host Bus Adapters. *
- * Copyright (C) 2009-2011 Emulex. All rights reserved. *
- * EMULEX and SLI are trademarks of Emulex. *
- * www.emulex.com *
- * *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of version 2 of the GNU General *
- * Public License as published by the Free Software Foundation. *
- * This program is distributed in the hope that it will be useful. *
- * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
- * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
- * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
- * TO BE LEGALLY INVALID. See the GNU General Public License for *
- * more details, a copy of which can be found in the file COPYING *
- * included with this package. *
- *******************************************************************/
- #include <linux/interrupt.h>
- #include <linux/mempool.h>
- #include <linux/pci.h>
- #include <linux/slab.h>
- #include <linux/delay.h>
- #include <linux/list.h>
- #include <scsi/scsi.h>
- #include <scsi/scsi_host.h>
- #include <scsi/scsi_transport_fc.h>
- #include <scsi/scsi_bsg_fc.h>
- #include <scsi/fc/fc_fs.h>
- #include "lpfc_hw4.h"
- #include "lpfc_hw.h"
- #include "lpfc_sli.h"
- #include "lpfc_sli4.h"
- #include "lpfc_nl.h"
- #include "lpfc_bsg.h"
- #include "lpfc_disc.h"
- #include "lpfc_scsi.h"
- #include "lpfc.h"
- #include "lpfc_logmsg.h"
- #include "lpfc_crtn.h"
- #include "lpfc_vport.h"
- #include "lpfc_version.h"
- struct lpfc_bsg_event {
- struct list_head node;
- struct kref kref;
- wait_queue_head_t wq;
- /* Event type and waiter identifiers */
- uint32_t type_mask;
- uint32_t req_id;
- uint32_t reg_id;
- /* next two flags are here for the auto-delete logic */
- unsigned long wait_time_stamp;
- int waiting;
- /* seen and not seen events */
- struct list_head events_to_get;
- struct list_head events_to_see;
- /* job waiting for this event to finish */
- struct fc_bsg_job *set_job;
- };
- struct lpfc_bsg_iocb {
- struct lpfc_iocbq *cmdiocbq;
- struct lpfc_iocbq *rspiocbq;
- struct lpfc_dmabuf *bmp;
- struct lpfc_nodelist *ndlp;
- /* job waiting for this iocb to finish */
- struct fc_bsg_job *set_job;
- };
- struct lpfc_bsg_mbox {
- LPFC_MBOXQ_t *pmboxq;
- MAILBOX_t *mb;
- struct lpfc_dmabuf *dmabuffers; /* for BIU diags */
- uint8_t *ext; /* extended mailbox data */
- uint32_t mbOffset; /* from app */
- uint32_t inExtWLen; /* from app */
- uint32_t outExtWLen; /* from app */
- /* job waiting for this mbox command to finish */
- struct fc_bsg_job *set_job;
- };
- #define MENLO_DID 0x0000FC0E
- struct lpfc_bsg_menlo {
- struct lpfc_iocbq *cmdiocbq;
- struct lpfc_iocbq *rspiocbq;
- struct lpfc_dmabuf *bmp;
- /* job waiting for this iocb to finish */
- struct fc_bsg_job *set_job;
- };
- #define TYPE_EVT 1
- #define TYPE_IOCB 2
- #define TYPE_MBOX 3
- #define TYPE_MENLO 4
- struct bsg_job_data {
- uint32_t type;
- union {
- struct lpfc_bsg_event *evt;
- struct lpfc_bsg_iocb iocb;
- struct lpfc_bsg_mbox mbox;
- struct lpfc_bsg_menlo menlo;
- } context_un;
- };
- struct event_data {
- struct list_head node;
- uint32_t type;
- uint32_t immed_dat;
- void *data;
- uint32_t len;
- };
- #define BUF_SZ_4K 4096
- #define SLI_CT_ELX_LOOPBACK 0x10
- enum ELX_LOOPBACK_CMD {
- ELX_LOOPBACK_XRI_SETUP,
- ELX_LOOPBACK_DATA,
- };
- #define ELX_LOOPBACK_HEADER_SZ \
- (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un)
- struct lpfc_dmabufext {
- struct lpfc_dmabuf dma;
- uint32_t size;
- uint32_t flag;
- };
- /**
- * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler
- * @phba: Pointer to HBA context object.
- * @cmdiocbq: Pointer to command iocb.
- * @rspiocbq: Pointer to response iocb.
- *
- * This function is the completion handler for iocbs issued using
- * lpfc_bsg_send_mgmt_cmd function. This function is called by the
- * ring event handler function without any lock held. This function
- * can be called from both worker thread context and interrupt
- * context. This function also can be called from another thread which
- * cleans up the SLI layer objects.
- * This function copies the contents of the response iocb to the
- * response iocb memory object provided by the caller of
- * lpfc_sli_issue_iocb_wait and then wakes up the thread which
- * sleeps for the iocb completion.
- **/
- static void
- lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
- struct lpfc_iocbq *cmdiocbq,
- struct lpfc_iocbq *rspiocbq)
- {
- struct bsg_job_data *dd_data;
- struct fc_bsg_job *job;
- IOCB_t *rsp;
- struct lpfc_dmabuf *bmp;
- struct lpfc_nodelist *ndlp;
- struct lpfc_bsg_iocb *iocb;
- unsigned long flags;
- int rc = 0;
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- dd_data = cmdiocbq->context2;
- if (!dd_data) {
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- lpfc_sli_release_iocbq(phba, cmdiocbq);
- return;
- }
- iocb = &dd_data->context_un.iocb;
- job = iocb->set_job;
- job->dd_data = NULL; /* so timeout handler does not reply */
- bmp = iocb->bmp;
- rsp = &rspiocbq->iocb;
- ndlp = cmdiocbq->context1;
- pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list,
- job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
- if (rsp->ulpStatus) {
- if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
- switch (rsp->un.ulpWord[4] & 0xff) {
- case IOERR_SEQUENCE_TIMEOUT:
- rc = -ETIMEDOUT;
- break;
- case IOERR_INVALID_RPI:
- rc = -EFAULT;
- break;
- default:
- rc = -EACCES;
- break;
- }
- } else
- rc = -EACCES;
- } else
- job->reply->reply_payload_rcv_len =
- rsp->un.genreq64.bdl.bdeSize;
- lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
- lpfc_sli_release_iocbq(phba, cmdiocbq);
- lpfc_nlp_put(ndlp);
- kfree(bmp);
- kfree(dd_data);
- /* make error code available to userspace */
- job->reply->result = rc;
- /* complete the job back to userspace */
- job->job_done(job);
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- return;
- }
- /**
- * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request
- * @job: fc_bsg_job to handle
- **/
- static int
- lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
- {
- struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_rport_data *rdata = job->rport->dd_data;
- struct lpfc_nodelist *ndlp = rdata->pnode;
- struct ulp_bde64 *bpl = NULL;
- uint32_t timeout;
- struct lpfc_iocbq *cmdiocbq = NULL;
- IOCB_t *cmd;
- struct lpfc_dmabuf *bmp = NULL;
- int request_nseg;
- int reply_nseg;
- struct scatterlist *sgel = NULL;
- int numbde;
- dma_addr_t busaddr;
- struct bsg_job_data *dd_data;
- uint32_t creg_val;
- int rc = 0;
- int iocb_stat;
- /* in case no data is transferred */
- job->reply->reply_payload_rcv_len = 0;
- /* allocate our bsg tracking structure */
- dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
- if (!dd_data) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2733 Failed allocation of dd_data\n");
- rc = -ENOMEM;
- goto no_dd_data;
- }
- if (!lpfc_nlp_get(ndlp)) {
- rc = -ENODEV;
- goto no_ndlp;
- }
- bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
- if (!bmp) {
- rc = -ENOMEM;
- goto free_ndlp;
- }
- if (ndlp->nlp_flag & NLP_ELS_SND_MASK) {
- rc = -ENODEV;
- goto free_bmp;
- }
- cmdiocbq = lpfc_sli_get_iocbq(phba);
- if (!cmdiocbq) {
- rc = -ENOMEM;
- goto free_bmp;
- }
- cmd = &cmdiocbq->iocb;
- bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
- if (!bmp->virt) {
- rc = -ENOMEM;
- goto free_cmdiocbq;
- }
- INIT_LIST_HEAD(&bmp->list);
- bpl = (struct ulp_bde64 *) bmp->virt;
- request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) {
- busaddr = sg_dma_address(sgel);
- bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
- bpl->tus.f.bdeSize = sg_dma_len(sgel);
- bpl->tus.w = cpu_to_le32(bpl->tus.w);
- bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr));
- bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr));
- bpl++;
- }
- reply_nseg = pci_map_sg(phba->pcidev, job->reply_payload.sg_list,
- job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
- for_each_sg(job->reply_payload.sg_list, sgel, reply_nseg, numbde) {
- busaddr = sg_dma_address(sgel);
- bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
- bpl->tus.f.bdeSize = sg_dma_len(sgel);
- bpl->tus.w = cpu_to_le32(bpl->tus.w);
- bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr));
- bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr));
- bpl++;
- }
- cmd->un.genreq64.bdl.ulpIoTag32 = 0;
- cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
- cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
- cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
- cmd->un.genreq64.bdl.bdeSize =
- (request_nseg + reply_nseg) * sizeof(struct ulp_bde64);
- cmd->ulpCommand = CMD_GEN_REQUEST64_CR;
- cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
- cmd->un.genreq64.w5.hcsw.Dfctl = 0;
- cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
- cmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
- cmd->ulpBdeCount = 1;
- cmd->ulpLe = 1;
- cmd->ulpClass = CLASS3;
- cmd->ulpContext = ndlp->nlp_rpi;
- if (phba->sli_rev == LPFC_SLI_REV4)
- cmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
- cmd->ulpOwner = OWN_CHIP;
- cmdiocbq->vport = phba->pport;
- cmdiocbq->context3 = bmp;
- cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
- timeout = phba->fc_ratov * 2;
- cmd->ulpTimeout = timeout;
- cmdiocbq->iocb_cmpl = lpfc_bsg_send_mgmt_cmd_cmp;
- cmdiocbq->context1 = ndlp;
- cmdiocbq->context2 = dd_data;
- dd_data->type = TYPE_IOCB;
- dd_data->context_un.iocb.cmdiocbq = cmdiocbq;
- dd_data->context_un.iocb.set_job = job;
- dd_data->context_un.iocb.bmp = bmp;
- if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
- if (lpfc_readl(phba->HCregaddr, &creg_val)) {
- rc = -EIO ;
- goto free_cmdiocbq;
- }
- creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
- writel(creg_val, phba->HCregaddr);
- readl(phba->HCregaddr); /* flush */
- }
- iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
- if (iocb_stat == IOCB_SUCCESS)
- return 0; /* done for now */
- else if (iocb_stat == IOCB_BUSY)
- rc = -EAGAIN;
- else
- rc = -EIO;
- /* iocb failed so cleanup */
- pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list,
- job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
- lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
- free_cmdiocbq:
- lpfc_sli_release_iocbq(phba, cmdiocbq);
- free_bmp:
- kfree(bmp);
- free_ndlp:
- lpfc_nlp_put(ndlp);
- no_ndlp:
- kfree(dd_data);
- no_dd_data:
- /* make error code available to userspace */
- job->reply->result = rc;
- job->dd_data = NULL;
- return rc;
- }
- /**
- * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler
- * @phba: Pointer to HBA context object.
- * @cmdiocbq: Pointer to command iocb.
- * @rspiocbq: Pointer to response iocb.
- *
- * This function is the completion handler for iocbs issued using
- * lpfc_bsg_rport_els_cmp function. This function is called by the
- * ring event handler function without any lock held. This function
- * can be called from both worker thread context and interrupt
- * context. This function also can be called from other thread which
- * cleans up the SLI layer objects.
- * This function copies the contents of the response iocb to the
- * response iocb memory object provided by the caller of
- * lpfc_sli_issue_iocb_wait and then wakes up the thread which
- * sleeps for the iocb completion.
- **/
- static void
- lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba,
- struct lpfc_iocbq *cmdiocbq,
- struct lpfc_iocbq *rspiocbq)
- {
- struct bsg_job_data *dd_data;
- struct fc_bsg_job *job;
- IOCB_t *rsp;
- struct lpfc_nodelist *ndlp;
- struct lpfc_dmabuf *pbuflist = NULL;
- struct fc_bsg_ctels_reply *els_reply;
- uint8_t *rjt_data;
- unsigned long flags;
- int rc = 0;
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- dd_data = cmdiocbq->context1;
- /* normal completion and timeout crossed paths, already done */
- if (!dd_data) {
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- return;
- }
- cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
- if (cmdiocbq->context2 && rspiocbq)
- memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
- &rspiocbq->iocb, sizeof(IOCB_t));
- job = dd_data->context_un.iocb.set_job;
- cmdiocbq = dd_data->context_un.iocb.cmdiocbq;
- rspiocbq = dd_data->context_un.iocb.rspiocbq;
- rsp = &rspiocbq->iocb;
- ndlp = dd_data->context_un.iocb.ndlp;
- pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list,
- job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
- if (job->reply->result == -EAGAIN)
- rc = -EAGAIN;
- else if (rsp->ulpStatus == IOSTAT_SUCCESS)
- job->reply->reply_payload_rcv_len =
- rsp->un.elsreq64.bdl.bdeSize;
- else if (rsp->ulpStatus == IOSTAT_LS_RJT) {
- job->reply->reply_payload_rcv_len =
- sizeof(struct fc_bsg_ctels_reply);
- /* LS_RJT data returned in word 4 */
- rjt_data = (uint8_t *)&rsp->un.ulpWord[4];
- els_reply = &job->reply->reply_data.ctels_reply;
- els_reply->status = FC_CTELS_STATUS_REJECT;
- els_reply->rjt_data.action = rjt_data[3];
- els_reply->rjt_data.reason_code = rjt_data[2];
- els_reply->rjt_data.reason_explanation = rjt_data[1];
- els_reply->rjt_data.vendor_unique = rjt_data[0];
- } else
- rc = -EIO;
- pbuflist = (struct lpfc_dmabuf *) cmdiocbq->context3;
- lpfc_mbuf_free(phba, pbuflist->virt, pbuflist->phys);
- lpfc_sli_release_iocbq(phba, rspiocbq);
- lpfc_sli_release_iocbq(phba, cmdiocbq);
- lpfc_nlp_put(ndlp);
- kfree(dd_data);
- /* make error code available to userspace */
- job->reply->result = rc;
- job->dd_data = NULL;
- /* complete the job back to userspace */
- job->job_done(job);
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- return;
- }
- /**
- * lpfc_bsg_rport_els - send an ELS command from a bsg request
- * @job: fc_bsg_job to handle
- **/
- static int
- lpfc_bsg_rport_els(struct fc_bsg_job *job)
- {
- struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_rport_data *rdata = job->rport->dd_data;
- struct lpfc_nodelist *ndlp = rdata->pnode;
- uint32_t elscmd;
- uint32_t cmdsize;
- uint32_t rspsize;
- struct lpfc_iocbq *rspiocbq;
- struct lpfc_iocbq *cmdiocbq;
- IOCB_t *rsp;
- uint16_t rpi = 0;
- struct lpfc_dmabuf *pcmd;
- struct lpfc_dmabuf *prsp;
- struct lpfc_dmabuf *pbuflist = NULL;
- struct ulp_bde64 *bpl;
- int request_nseg;
- int reply_nseg;
- struct scatterlist *sgel = NULL;
- int numbde;
- dma_addr_t busaddr;
- struct bsg_job_data *dd_data;
- uint32_t creg_val;
- int rc = 0;
- /* in case no data is transferred */
- job->reply->reply_payload_rcv_len = 0;
- /* allocate our bsg tracking structure */
- dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
- if (!dd_data) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2735 Failed allocation of dd_data\n");
- rc = -ENOMEM;
- goto no_dd_data;
- }
- if (!lpfc_nlp_get(ndlp)) {
- rc = -ENODEV;
- goto free_dd_data;
- }
- elscmd = job->request->rqst_data.r_els.els_code;
- cmdsize = job->request_payload.payload_len;
- rspsize = job->reply_payload.payload_len;
- rspiocbq = lpfc_sli_get_iocbq(phba);
- if (!rspiocbq) {
- lpfc_nlp_put(ndlp);
- rc = -ENOMEM;
- goto free_dd_data;
- }
- rsp = &rspiocbq->iocb;
- rpi = ndlp->nlp_rpi;
- cmdiocbq = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp,
- ndlp->nlp_DID, elscmd);
- if (!cmdiocbq) {
- rc = -EIO;
- goto free_rspiocbq;
- }
- /* prep els iocb set context1 to the ndlp, context2 to the command
- * dmabuf, context3 holds the data dmabuf
- */
- pcmd = (struct lpfc_dmabuf *) cmdiocbq->context2;
- prsp = (struct lpfc_dmabuf *) pcmd->list.next;
- lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
- kfree(pcmd);
- lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
- kfree(prsp);
- cmdiocbq->context2 = NULL;
- pbuflist = (struct lpfc_dmabuf *) cmdiocbq->context3;
- bpl = (struct ulp_bde64 *) pbuflist->virt;
- request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) {
- busaddr = sg_dma_address(sgel);
- bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
- bpl->tus.f.bdeSize = sg_dma_len(sgel);
- bpl->tus.w = cpu_to_le32(bpl->tus.w);
- bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr));
- bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr));
- bpl++;
- }
- reply_nseg = pci_map_sg(phba->pcidev, job->reply_payload.sg_list,
- job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
- for_each_sg(job->reply_payload.sg_list, sgel, reply_nseg, numbde) {
- busaddr = sg_dma_address(sgel);
- bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
- bpl->tus.f.bdeSize = sg_dma_len(sgel);
- bpl->tus.w = cpu_to_le32(bpl->tus.w);
- bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr));
- bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr));
- bpl++;
- }
- cmdiocbq->iocb.un.elsreq64.bdl.bdeSize =
- (request_nseg + reply_nseg) * sizeof(struct ulp_bde64);
- cmdiocbq->iocb.ulpContext = rpi;
- cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
- cmdiocbq->context1 = NULL;
- cmdiocbq->context2 = NULL;
- cmdiocbq->iocb_cmpl = lpfc_bsg_rport_els_cmp;
- cmdiocbq->context1 = dd_data;
- cmdiocbq->context2 = rspiocbq;
- dd_data->type = TYPE_IOCB;
- dd_data->context_un.iocb.cmdiocbq = cmdiocbq;
- dd_data->context_un.iocb.rspiocbq = rspiocbq;
- dd_data->context_un.iocb.set_job = job;
- dd_data->context_un.iocb.bmp = NULL;
- dd_data->context_un.iocb.ndlp = ndlp;
- if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
- if (lpfc_readl(phba->HCregaddr, &creg_val)) {
- rc = -EIO;
- goto linkdown_err;
- }
- creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
- writel(creg_val, phba->HCregaddr);
- readl(phba->HCregaddr); /* flush */
- }
- rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
- lpfc_nlp_put(ndlp);
- if (rc == IOCB_SUCCESS)
- return 0; /* done for now */
- else if (rc == IOCB_BUSY)
- rc = -EAGAIN;
- else
- rc = -EIO;
- linkdown_err:
- pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list,
- job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
- lpfc_mbuf_free(phba, pbuflist->virt, pbuflist->phys);
- lpfc_sli_release_iocbq(phba, cmdiocbq);
- free_rspiocbq:
- lpfc_sli_release_iocbq(phba, rspiocbq);
- free_dd_data:
- kfree(dd_data);
- no_dd_data:
- /* make error code available to userspace */
- job->reply->result = rc;
- job->dd_data = NULL;
- return rc;
- }
- /**
- * lpfc_bsg_event_free - frees an allocated event structure
- * @kref: Pointer to a kref.
- *
- * Called from kref_put. Back cast the kref into an event structure address.
- * Free any events to get, delete associated nodes, free any events to see,
- * free any data then free the event itself.
- **/
- static void
- lpfc_bsg_event_free(struct kref *kref)
- {
- struct lpfc_bsg_event *evt = container_of(kref, struct lpfc_bsg_event,
- kref);
- struct event_data *ed;
- list_del(&evt->node);
- while (!list_empty(&evt->events_to_get)) {
- ed = list_entry(evt->events_to_get.next, typeof(*ed), node);
- list_del(&ed->node);
- kfree(ed->data);
- kfree(ed);
- }
- while (!list_empty(&evt->events_to_see)) {
- ed = list_entry(evt->events_to_see.next, typeof(*ed), node);
- list_del(&ed->node);
- kfree(ed->data);
- kfree(ed);
- }
- kfree(evt);
- }
- /**
- * lpfc_bsg_event_ref - increments the kref for an event
- * @evt: Pointer to an event structure.
- **/
- static inline void
- lpfc_bsg_event_ref(struct lpfc_bsg_event *evt)
- {
- kref_get(&evt->kref);
- }
- /**
- * lpfc_bsg_event_unref - Uses kref_put to free an event structure
- * @evt: Pointer to an event structure.
- **/
- static inline void
- lpfc_bsg_event_unref(struct lpfc_bsg_event *evt)
- {
- kref_put(&evt->kref, lpfc_bsg_event_free);
- }
- /**
- * lpfc_bsg_event_new - allocate and initialize a event structure
- * @ev_mask: Mask of events.
- * @ev_reg_id: Event reg id.
- * @ev_req_id: Event request id.
- **/
- static struct lpfc_bsg_event *
- lpfc_bsg_event_new(uint32_t ev_mask, int ev_reg_id, uint32_t ev_req_id)
- {
- struct lpfc_bsg_event *evt = kzalloc(sizeof(*evt), GFP_KERNEL);
- if (!evt)
- return NULL;
- INIT_LIST_HEAD(&evt->events_to_get);
- INIT_LIST_HEAD(&evt->events_to_see);
- evt->type_mask = ev_mask;
- evt->req_id = ev_req_id;
- evt->reg_id = ev_reg_id;
- evt->wait_time_stamp = jiffies;
- init_waitqueue_head(&evt->wq);
- kref_init(&evt->kref);
- return evt;
- }
- /**
- * diag_cmd_data_free - Frees an lpfc dma buffer extension
- * @phba: Pointer to HBA context object.
- * @mlist: Pointer to an lpfc dma buffer extension.
- **/
- static int
- diag_cmd_data_free(struct lpfc_hba *phba, struct lpfc_dmabufext *mlist)
- {
- struct lpfc_dmabufext *mlast;
- struct pci_dev *pcidev;
- struct list_head head, *curr, *next;
- if ((!mlist) || (!lpfc_is_link_up(phba) &&
- (phba->link_flag & LS_LOOPBACK_MODE))) {
- return 0;
- }
- pcidev = phba->pcidev;
- list_add_tail(&head, &mlist->dma.list);
- list_for_each_safe(curr, next, &head) {
- mlast = list_entry(curr, struct lpfc_dmabufext , dma.list);
- if (mlast->dma.virt)
- dma_free_coherent(&pcidev->dev,
- mlast->size,
- mlast->dma.virt,
- mlast->dma.phys);
- kfree(mlast);
- }
- return 0;
- }
- /**
- * lpfc_bsg_ct_unsol_event - process an unsolicited CT command
- * @phba:
- * @pring:
- * @piocbq:
- *
- * This function is called when an unsolicited CT command is received. It
- * forwards the event to any processes registered to receive CT events.
- **/
- int
- lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
- struct lpfc_iocbq *piocbq)
- {
- uint32_t evt_req_id = 0;
- uint32_t cmd;
- uint32_t len;
- struct lpfc_dmabuf *dmabuf = NULL;
- struct lpfc_bsg_event *evt;
- struct event_data *evt_dat = NULL;
- struct lpfc_iocbq *iocbq;
- size_t offset = 0;
- struct list_head head;
- struct ulp_bde64 *bde;
- dma_addr_t dma_addr;
- int i;
- struct lpfc_dmabuf *bdeBuf1 = piocbq->context2;
- struct lpfc_dmabuf *bdeBuf2 = piocbq->context3;
- struct lpfc_hbq_entry *hbqe;
- struct lpfc_sli_ct_request *ct_req;
- struct fc_bsg_job *job = NULL;
- unsigned long flags;
- int size = 0;
- INIT_LIST_HEAD(&head);
- list_add_tail(&head, &piocbq->list);
- if (piocbq->iocb.ulpBdeCount == 0 ||
- piocbq->iocb.un.cont64[0].tus.f.bdeSize == 0)
- goto error_ct_unsol_exit;
- if (phba->link_state == LPFC_HBA_ERROR ||
- (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)))
- goto error_ct_unsol_exit;
- if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
- dmabuf = bdeBuf1;
- else {
- dma_addr = getPaddr(piocbq->iocb.un.cont64[0].addrHigh,
- piocbq->iocb.un.cont64[0].addrLow);
- dmabuf = lpfc_sli_ringpostbuf_get(phba, pring, dma_addr);
- }
- if (dmabuf == NULL)
- goto error_ct_unsol_exit;
- ct_req = (struct lpfc_sli_ct_request *)dmabuf->virt;
- evt_req_id = ct_req->FsType;
- cmd = ct_req->CommandResponse.bits.CmdRsp;
- len = ct_req->CommandResponse.bits.Size;
- if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
- lpfc_sli_ringpostbuf_put(phba, pring, dmabuf);
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
- if (!(evt->type_mask & FC_REG_CT_EVENT) ||
- evt->req_id != evt_req_id)
- continue;
- lpfc_bsg_event_ref(evt);
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- evt_dat = kzalloc(sizeof(*evt_dat), GFP_KERNEL);
- if (evt_dat == NULL) {
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- lpfc_bsg_event_unref(evt);
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2614 Memory allocation failed for "
- "CT event\n");
- break;
- }
- if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
- /* take accumulated byte count from the last iocbq */
- iocbq = list_entry(head.prev, typeof(*iocbq), list);
- evt_dat->len = iocbq->iocb.unsli3.rcvsli3.acc_len;
- } else {
- list_for_each_entry(iocbq, &head, list) {
- for (i = 0; i < iocbq->iocb.ulpBdeCount; i++)
- evt_dat->len +=
- iocbq->iocb.un.cont64[i].tus.f.bdeSize;
- }
- }
- evt_dat->data = kzalloc(evt_dat->len, GFP_KERNEL);
- if (evt_dat->data == NULL) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2615 Memory allocation failed for "
- "CT event data, size %d\n",
- evt_dat->len);
- kfree(evt_dat);
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- lpfc_bsg_event_unref(evt);
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- goto error_ct_unsol_exit;
- }
- list_for_each_entry(iocbq, &head, list) {
- size = 0;
- if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
- bdeBuf1 = iocbq->context2;
- bdeBuf2 = iocbq->context3;
- }
- for (i = 0; i < iocbq->iocb.ulpBdeCount; i++) {
- if (phba->sli3_options &
- LPFC_SLI3_HBQ_ENABLED) {
- if (i == 0) {
- hbqe = (struct lpfc_hbq_entry *)
- &iocbq->iocb.un.ulpWord[0];
- size = hbqe->bde.tus.f.bdeSize;
- dmabuf = bdeBuf1;
- } else if (i == 1) {
- hbqe = (struct lpfc_hbq_entry *)
- &iocbq->iocb.unsli3.
- sli3Words[4];
- size = hbqe->bde.tus.f.bdeSize;
- dmabuf = bdeBuf2;
- }
- if ((offset + size) > evt_dat->len)
- size = evt_dat->len - offset;
- } else {
- size = iocbq->iocb.un.cont64[i].
- tus.f.bdeSize;
- bde = &iocbq->iocb.un.cont64[i];
- dma_addr = getPaddr(bde->addrHigh,
- bde->addrLow);
- dmabuf = lpfc_sli_ringpostbuf_get(phba,
- pring, dma_addr);
- }
- if (!dmabuf) {
- lpfc_printf_log(phba, KERN_ERR,
- LOG_LIBDFC, "2616 No dmabuf "
- "found for iocbq 0x%p\n",
- iocbq);
- kfree(evt_dat->data);
- kfree(evt_dat);
- spin_lock_irqsave(&phba->ct_ev_lock,
- flags);
- lpfc_bsg_event_unref(evt);
- spin_unlock_irqrestore(
- &phba->ct_ev_lock, flags);
- goto error_ct_unsol_exit;
- }
- memcpy((char *)(evt_dat->data) + offset,
- dmabuf->virt, size);
- offset += size;
- if (evt_req_id != SLI_CT_ELX_LOOPBACK &&
- !(phba->sli3_options &
- LPFC_SLI3_HBQ_ENABLED)) {
- lpfc_sli_ringpostbuf_put(phba, pring,
- dmabuf);
- } else {
- switch (cmd) {
- case ELX_LOOPBACK_DATA:
- diag_cmd_data_free(phba,
- (struct lpfc_dmabufext *)
- dmabuf);
- break;
- case ELX_LOOPBACK_XRI_SETUP:
- if ((phba->sli_rev ==
- LPFC_SLI_REV2) ||
- (phba->sli3_options &
- LPFC_SLI3_HBQ_ENABLED
- )) {
- lpfc_in_buf_free(phba,
- dmabuf);
- } else {
- lpfc_post_buffer(phba,
- pring,
- 1);
- }
- break;
- default:
- if (!(phba->sli3_options &
- LPFC_SLI3_HBQ_ENABLED))
- lpfc_post_buffer(phba,
- pring,
- 1);
- break;
- }
- }
- }
- }
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- if (phba->sli_rev == LPFC_SLI_REV4) {
- evt_dat->immed_dat = phba->ctx_idx;
- phba->ctx_idx = (phba->ctx_idx + 1) % 64;
- /* Provide warning for over-run of the ct_ctx array */
- if (phba->ct_ctx[evt_dat->immed_dat].flags &
- UNSOL_VALID)
- lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
- "2717 CT context array entry "
- "[%d] over-run: oxid:x%x, "
- "sid:x%x\n", phba->ctx_idx,
- phba->ct_ctx[
- evt_dat->immed_dat].oxid,
- phba->ct_ctx[
- evt_dat->immed_dat].SID);
- phba->ct_ctx[evt_dat->immed_dat].rxid =
- piocbq->iocb.ulpContext;
- phba->ct_ctx[evt_dat->immed_dat].oxid =
- piocbq->iocb.unsli3.rcvsli3.ox_id;
- phba->ct_ctx[evt_dat->immed_dat].SID =
- piocbq->iocb.un.rcvels.remoteID;
- phba->ct_ctx[evt_dat->immed_dat].flags = UNSOL_VALID;
- } else
- evt_dat->immed_dat = piocbq->iocb.ulpContext;
- evt_dat->type = FC_REG_CT_EVENT;
- list_add(&evt_dat->node, &evt->events_to_see);
- if (evt_req_id == SLI_CT_ELX_LOOPBACK) {
- wake_up_interruptible(&evt->wq);
- lpfc_bsg_event_unref(evt);
- break;
- }
- list_move(evt->events_to_see.prev, &evt->events_to_get);
- lpfc_bsg_event_unref(evt);
- job = evt->set_job;
- evt->set_job = NULL;
- if (job) {
- job->reply->reply_payload_rcv_len = size;
- /* make error code available to userspace */
- job->reply->result = 0;
- job->dd_data = NULL;
- /* complete the job back to userspace */
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- job->job_done(job);
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- }
- }
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- error_ct_unsol_exit:
- if (!list_empty(&head))
- list_del(&head);
- if (evt_req_id == SLI_CT_ELX_LOOPBACK)
- return 0;
- return 1;
- }
- /**
- * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command
- * @job: SET_EVENT fc_bsg_job
- **/
- static int
- lpfc_bsg_hba_set_event(struct fc_bsg_job *job)
- {
- struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
- struct lpfc_hba *phba = vport->phba;
- struct set_ct_event *event_req;
- struct lpfc_bsg_event *evt;
- int rc = 0;
- struct bsg_job_data *dd_data = NULL;
- uint32_t ev_mask;
- unsigned long flags;
- if (job->request_len <
- sizeof(struct fc_bsg_request) + sizeof(struct set_ct_event)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2612 Received SET_CT_EVENT below minimum "
- "size\n");
- rc = -EINVAL;
- goto job_error;
- }
- dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
- if (dd_data == NULL) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2734 Failed allocation of dd_data\n");
- rc = -ENOMEM;
- goto job_error;
- }
- event_req = (struct set_ct_event *)
- job->request->rqst_data.h_vendor.vendor_cmd;
- ev_mask = ((uint32_t)(unsigned long)event_req->type_mask &
- FC_REG_EVENT_MASK);
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
- if (evt->reg_id == event_req->ev_reg_id) {
- lpfc_bsg_event_ref(evt);
- evt->wait_time_stamp = jiffies;
- break;
- }
- }
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- if (&evt->node == &phba->ct_ev_waiters) {
- /* no event waiting struct yet - first call */
- evt = lpfc_bsg_event_new(ev_mask, event_req->ev_reg_id,
- event_req->ev_req_id);
- if (!evt) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2617 Failed allocation of event "
- "waiter\n");
- rc = -ENOMEM;
- goto job_error;
- }
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- list_add(&evt->node, &phba->ct_ev_waiters);
- lpfc_bsg_event_ref(evt);
- evt->wait_time_stamp = jiffies;
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- }
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- evt->waiting = 1;
- dd_data->type = TYPE_EVT;
- dd_data->context_un.evt = evt;
- evt->set_job = job; /* for unsolicited command */
- job->dd_data = dd_data; /* for fc transport timeout callback*/
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- return 0; /* call job done later */
- job_error:
- if (dd_data != NULL)
- kfree(dd_data);
- job->dd_data = NULL;
- return rc;
- }
- /**
- * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command
- * @job: GET_EVENT fc_bsg_job
- **/
- static int
- lpfc_bsg_hba_get_event(struct fc_bsg_job *job)
- {
- struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
- struct lpfc_hba *phba = vport->phba;
- struct get_ct_event *event_req;
- struct get_ct_event_reply *event_reply;
- struct lpfc_bsg_event *evt;
- struct event_data *evt_dat = NULL;
- unsigned long flags;
- uint32_t rc = 0;
- if (job->request_len <
- sizeof(struct fc_bsg_request) + sizeof(struct get_ct_event)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2613 Received GET_CT_EVENT request below "
- "minimum size\n");
- rc = -EINVAL;
- goto job_error;
- }
- event_req = (struct get_ct_event *)
- job->request->rqst_data.h_vendor.vendor_cmd;
- event_reply = (struct get_ct_event_reply *)
- job->reply->reply_data.vendor_reply.vendor_rsp;
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
- if (evt->reg_id == event_req->ev_reg_id) {
- if (list_empty(&evt->events_to_get))
- break;
- lpfc_bsg_event_ref(evt);
- evt->wait_time_stamp = jiffies;
- evt_dat = list_entry(evt->events_to_get.prev,
- struct event_data, node);
- list_del(&evt_dat->node);
- break;
- }
- }
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- /* The app may continue to ask for event data until it gets
- * an error indicating that there isn't anymore
- */
- if (evt_dat == NULL) {
- job->reply->reply_payload_rcv_len = 0;
- rc = -ENOENT;
- goto job_error;
- }
- if (evt_dat->len > job->request_payload.payload_len) {
- evt_dat->len = job->request_payload.payload_len;
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2618 Truncated event data at %d "
- "bytes\n",
- job->request_payload.payload_len);
- }
- event_reply->type = evt_dat->type;
- event_reply->immed_data = evt_dat->immed_dat;
- if (evt_dat->len > 0)
- job->reply->reply_payload_rcv_len =
- sg_copy_from_buffer(job->request_payload.sg_list,
- job->request_payload.sg_cnt,
- evt_dat->data, evt_dat->len);
- else
- job->reply->reply_payload_rcv_len = 0;
- if (evt_dat) {
- kfree(evt_dat->data);
- kfree(evt_dat);
- }
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- lpfc_bsg_event_unref(evt);
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- job->dd_data = NULL;
- job->reply->result = 0;
- job->job_done(job);
- return 0;
- job_error:
- job->dd_data = NULL;
- job->reply->result = rc;
- return rc;
- }
- /**
- * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler
- * @phba: Pointer to HBA context object.
- * @cmdiocbq: Pointer to command iocb.
- * @rspiocbq: Pointer to response iocb.
- *
- * This function is the completion handler for iocbs issued using
- * lpfc_issue_ct_rsp_cmp function. This function is called by the
- * ring event handler function without any lock held. This function
- * can be called from both worker thread context and interrupt
- * context. This function also can be called from other thread which
- * cleans up the SLI layer objects.
- * This function copy the contents of the response iocb to the
- * response iocb memory object provided by the caller of
- * lpfc_sli_issue_iocb_wait and then wakes up the thread which
- * sleeps for the iocb completion.
- **/
- static void
- lpfc_issue_ct_rsp_cmp(struct lpfc_hba *phba,
- struct lpfc_iocbq *cmdiocbq,
- struct lpfc_iocbq *rspiocbq)
- {
- struct bsg_job_data *dd_data;
- struct fc_bsg_job *job;
- IOCB_t *rsp;
- struct lpfc_dmabuf *bmp;
- struct lpfc_nodelist *ndlp;
- unsigned long flags;
- int rc = 0;
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- dd_data = cmdiocbq->context2;
- /* normal completion and timeout crossed paths, already done */
- if (!dd_data) {
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- return;
- }
- job = dd_data->context_un.iocb.set_job;
- bmp = dd_data->context_un.iocb.bmp;
- rsp = &rspiocbq->iocb;
- ndlp = dd_data->context_un.iocb.ndlp;
- pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- if (rsp->ulpStatus) {
- if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
- switch (rsp->un.ulpWord[4] & 0xff) {
- case IOERR_SEQUENCE_TIMEOUT:
- rc = -ETIMEDOUT;
- break;
- case IOERR_INVALID_RPI:
- rc = -EFAULT;
- break;
- default:
- rc = -EACCES;
- break;
- }
- } else
- rc = -EACCES;
- } else
- job->reply->reply_payload_rcv_len =
- rsp->un.genreq64.bdl.bdeSize;
- lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
- lpfc_sli_release_iocbq(phba, cmdiocbq);
- lpfc_nlp_put(ndlp);
- kfree(bmp);
- kfree(dd_data);
- /* make error code available to userspace */
- job->reply->result = rc;
- job->dd_data = NULL;
- /* complete the job back to userspace */
- job->job_done(job);
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- return;
- }
- /**
- * lpfc_issue_ct_rsp - issue a ct response
- * @phba: Pointer to HBA context object.
- * @job: Pointer to the job object.
- * @tag: tag index value into the ports context exchange array.
- * @bmp: Pointer to a dma buffer descriptor.
- * @num_entry: Number of enties in the bde.
- **/
- static int
- lpfc_issue_ct_rsp(struct lpfc_hba *phba, struct fc_bsg_job *job, uint32_t tag,
- struct lpfc_dmabuf *bmp, int num_entry)
- {
- IOCB_t *icmd;
- struct lpfc_iocbq *ctiocb = NULL;
- int rc = 0;
- struct lpfc_nodelist *ndlp = NULL;
- struct bsg_job_data *dd_data;
- uint32_t creg_val;
- /* allocate our bsg tracking structure */
- dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
- if (!dd_data) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2736 Failed allocation of dd_data\n");
- rc = -ENOMEM;
- goto no_dd_data;
- }
- /* Allocate buffer for command iocb */
- ctiocb = lpfc_sli_get_iocbq(phba);
- if (!ctiocb) {
- rc = -ENOMEM;
- goto no_ctiocb;
- }
- icmd = &ctiocb->iocb;
- icmd->un.xseq64.bdl.ulpIoTag32 = 0;
- icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
- icmd->un.xseq64.bdl.addrLow = putPaddrLow(bmp->phys);
- icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
- icmd->un.xseq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
- icmd->un.xseq64.w5.hcsw.Fctl = (LS | LA);
- icmd->un.xseq64.w5.hcsw.Dfctl = 0;
- icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_SOL_CTL;
- icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT;
- /* Fill in rest of iocb */
- icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX;
- icmd->ulpBdeCount = 1;
- icmd->ulpLe = 1;
- icmd->ulpClass = CLASS3;
- if (phba->sli_rev == LPFC_SLI_REV4) {
- /* Do not issue unsol response if oxid not marked as valid */
- if (!(phba->ct_ctx[tag].flags & UNSOL_VALID)) {
- rc = IOCB_ERROR;
- goto issue_ct_rsp_exit;
- }
- icmd->ulpContext = phba->ct_ctx[tag].rxid;
- icmd->unsli3.rcvsli3.ox_id = phba->ct_ctx[tag].oxid;
- ndlp = lpfc_findnode_did(phba->pport, phba->ct_ctx[tag].SID);
- if (!ndlp) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
- "2721 ndlp null for oxid %x SID %x\n",
- icmd->ulpContext,
- phba->ct_ctx[tag].SID);
- rc = IOCB_ERROR;
- goto issue_ct_rsp_exit;
- }
- /* Check if the ndlp is active */
- if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
- rc = -IOCB_ERROR;
- goto issue_ct_rsp_exit;
- }
- /* get a refernece count so the ndlp doesn't go away while
- * we respond
- */
- if (!lpfc_nlp_get(ndlp)) {
- rc = -IOCB_ERROR;
- goto issue_ct_rsp_exit;
- }
- icmd->un.ulpWord[3] =
- phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
- /* The exchange is done, mark the entry as invalid */
- phba->ct_ctx[tag].flags &= ~UNSOL_VALID;
- } else
- icmd->ulpContext = (ushort) tag;
- icmd->ulpTimeout = phba->fc_ratov * 2;
- /* Xmit CT response on exchange <xid> */
- lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
- "2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n",
- icmd->ulpContext, icmd->ulpIoTag, tag, phba->link_state);
- ctiocb->iocb_cmpl = NULL;
- ctiocb->iocb_flag |= LPFC_IO_LIBDFC;
- ctiocb->vport = phba->pport;
- ctiocb->context3 = bmp;
- ctiocb->iocb_cmpl = lpfc_issue_ct_rsp_cmp;
- ctiocb->context2 = dd_data;
- ctiocb->context1 = ndlp;
- dd_data->type = TYPE_IOCB;
- dd_data->context_un.iocb.cmdiocbq = ctiocb;
- dd_data->context_un.iocb.rspiocbq = NULL;
- dd_data->context_un.iocb.set_job = job;
- dd_data->context_un.iocb.bmp = bmp;
- dd_data->context_un.iocb.ndlp = ndlp;
- if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
- if (lpfc_readl(phba->HCregaddr, &creg_val)) {
- rc = -IOCB_ERROR;
- goto issue_ct_rsp_exit;
- }
- creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
- writel(creg_val, phba->HCregaddr);
- readl(phba->HCregaddr); /* flush */
- }
- rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
- if (rc == IOCB_SUCCESS)
- return 0; /* done for now */
- issue_ct_rsp_exit:
- lpfc_sli_release_iocbq(phba, ctiocb);
- no_ctiocb:
- kfree(dd_data);
- no_dd_data:
- return rc;
- }
- /**
- * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command
- * @job: SEND_MGMT_RESP fc_bsg_job
- **/
- static int
- lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job *job)
- {
- struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
- struct lpfc_hba *phba = vport->phba;
- struct send_mgmt_resp *mgmt_resp = (struct send_mgmt_resp *)
- job->request->rqst_data.h_vendor.vendor_cmd;
- struct ulp_bde64 *bpl;
- struct lpfc_dmabuf *bmp = NULL;
- struct scatterlist *sgel = NULL;
- int request_nseg;
- int numbde;
- dma_addr_t busaddr;
- uint32_t tag = mgmt_resp->tag;
- unsigned long reqbfrcnt =
- (unsigned long)job->request_payload.payload_len;
- int rc = 0;
- /* in case no data is transferred */
- job->reply->reply_payload_rcv_len = 0;
- if (!reqbfrcnt || (reqbfrcnt > (80 * BUF_SZ_4K))) {
- rc = -ERANGE;
- goto send_mgmt_rsp_exit;
- }
- bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
- if (!bmp) {
- rc = -ENOMEM;
- goto send_mgmt_rsp_exit;
- }
- bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
- if (!bmp->virt) {
- rc = -ENOMEM;
- goto send_mgmt_rsp_free_bmp;
- }
- INIT_LIST_HEAD(&bmp->list);
- bpl = (struct ulp_bde64 *) bmp->virt;
- request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) {
- busaddr = sg_dma_address(sgel);
- bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
- bpl->tus.f.bdeSize = sg_dma_len(sgel);
- bpl->tus.w = cpu_to_le32(bpl->tus.w);
- bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr));
- bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr));
- bpl++;
- }
- rc = lpfc_issue_ct_rsp(phba, job, tag, bmp, request_nseg);
- if (rc == IOCB_SUCCESS)
- return 0; /* done for now */
- /* TBD need to handle a timeout */
- pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- rc = -EACCES;
- lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
- send_mgmt_rsp_free_bmp:
- kfree(bmp);
- send_mgmt_rsp_exit:
- /* make error code available to userspace */
- job->reply->result = rc;
- job->dd_data = NULL;
- return rc;
- }
- /**
- * lpfc_bsg_diag_mode_enter - process preparing into device diag loopback mode
- * @phba: Pointer to HBA context object.
- *
- * This function is responsible for preparing driver for diag loopback
- * on device.
- */
- static int
- lpfc_bsg_diag_mode_enter(struct lpfc_hba *phba)
- {
- struct lpfc_vport **vports;
- struct Scsi_Host *shost;
- struct lpfc_sli *psli;
- struct lpfc_sli_ring *pring;
- int i = 0;
- psli = &phba->sli;
- if (!psli)
- return -ENODEV;
- pring = &psli->ring[LPFC_FCP_RING];
- if (!pring)
- return -ENODEV;
- if ((phba->link_state == LPFC_HBA_ERROR) ||
- (psli->sli_flag & LPFC_BLOCK_MGMT_IO) ||
- (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
- return -EACCES;
- vports = lpfc_create_vport_work_array(phba);
- if (vports) {
- for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
- shost = lpfc_shost_from_vport(vports[i]);
- scsi_block_requests(shost);
- }
- lpfc_destroy_vport_work_array(phba, vports);
- } else {
- shost = lpfc_shost_from_vport(phba->pport);
- scsi_block_requests(shost);
- }
- while (pring->txcmplq_cnt) {
- if (i++ > 500) /* wait up to 5 seconds */
- break;
- msleep(10);
- }
- return 0;
- }
- /**
- * lpfc_bsg_diag_mode_exit - exit process from device diag loopback mode
- * @phba: Pointer to HBA context object.
- *
- * This function is responsible for driver exit processing of setting up
- * diag loopback mode on device.
- */
- static void
- lpfc_bsg_diag_mode_exit(struct lpfc_hba *phba)
- {
- struct Scsi_Host *shost;
- struct lpfc_vport **vports;
- int i;
- vports = lpfc_create_vport_work_array(phba);
- if (vports) {
- for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
- shost = lpfc_shost_from_vport(vports[i]);
- scsi_unblock_requests(shost);
- }
- lpfc_destroy_vport_work_array(phba, vports);
- } else {
- shost = lpfc_shost_from_vport(phba->pport);
- scsi_unblock_requests(shost);
- }
- return;
- }
- /**
- * lpfc_sli3_bsg_diag_loopback_mode - process an sli3 bsg vendor command
- * @phba: Pointer to HBA context object.
- * @job: LPFC_BSG_VENDOR_DIAG_MODE
- *
- * This function is responsible for placing an sli3 port into diagnostic
- * loopback mode in order to perform a diagnostic loopback test.
- * All new scsi requests are blocked, a small delay is used to allow the
- * scsi requests to complete then the link is brought down. If the link is
- * is placed in loopback mode then scsi requests are again allowed
- * so the scsi mid-layer doesn't give up on the port.
- * All of this is done in-line.
- */
- static int
- lpfc_sli3_bsg_diag_loopback_mode(struct lpfc_hba *phba, struct fc_bsg_job *job)
- {
- struct diag_mode_set *loopback_mode;
- uint32_t link_flags;
- uint32_t timeout;
- LPFC_MBOXQ_t *pmboxq;
- int mbxstatus;
- int i = 0;
- int rc = 0;
- /* no data to return just the return code */
- job->reply->reply_payload_rcv_len = 0;
- if (job->request_len < sizeof(struct fc_bsg_request) +
- sizeof(struct diag_mode_set)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2738 Received DIAG MODE request size:%d "
- "below the minimum size:%d\n",
- job->request_len,
- (int)(sizeof(struct fc_bsg_request) +
- sizeof(struct diag_mode_set)));
- rc = -EINVAL;
- goto job_error;
- }
- rc = lpfc_bsg_diag_mode_enter(phba);
- if (rc)
- goto job_error;
- /* bring the link to diagnostic mode */
- loopback_mode = (struct diag_mode_set *)
- job->request->rqst_data.h_vendor.vendor_cmd;
- link_flags = loopback_mode->type;
- timeout = loopback_mode->timeout * 100;
- pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!pmboxq) {
- rc = -ENOMEM;
- goto loopback_mode_exit;
- }
- memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t));
- pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
- pmboxq->u.mb.mbxOwner = OWN_HOST;
- mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO);
- if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0)) {
- /* wait for link down before proceeding */
- i = 0;
- while (phba->link_state != LPFC_LINK_DOWN) {
- if (i++ > timeout) {
- rc = -ETIMEDOUT;
- goto loopback_mode_exit;
- }
- msleep(10);
- }
- memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t));
- if (link_flags == INTERNAL_LOOP_BACK)
- pmboxq->u.mb.un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
- else
- pmboxq->u.mb.un.varInitLnk.link_flags =
- FLAGS_TOPOLOGY_MODE_LOOP;
- pmboxq->u.mb.mbxCommand = MBX_INIT_LINK;
- pmboxq->u.mb.mbxOwner = OWN_HOST;
- mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
- LPFC_MBOX_TMO);
- if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus))
- rc = -ENODEV;
- else {
- phba->link_flag |= LS_LOOPBACK_MODE;
- /* wait for the link attention interrupt */
- msleep(100);
- i = 0;
- while (phba->link_state != LPFC_HBA_READY) {
- if (i++ > timeout) {
- rc = -ETIMEDOUT;
- break;
- }
- msleep(10);
- }
- }
- } else
- rc = -ENODEV;
- loopback_mode_exit:
- lpfc_bsg_diag_mode_exit(phba);
- /*
- * Let SLI layer release mboxq if mbox command completed after timeout.
- */
- if (mbxstatus != MBX_TIMEOUT)
- mempool_free(pmboxq, phba->mbox_mem_pool);
- job_error:
- /* make error code available to userspace */
- job->reply->result = rc;
- /* complete the job back to userspace if no error */
- if (rc == 0)
- job->job_done(job);
- return rc;
- }
- /**
- * lpfc_sli4_bsg_set_link_diag_state - set sli4 link diag state
- * @phba: Pointer to HBA context object.
- * @diag: Flag for set link to diag or nomral operation state.
- *
- * This function is responsible for issuing a sli4 mailbox command for setting
- * link to either diag state or normal operation state.
- */
- static int
- lpfc_sli4_bsg_set_link_diag_state(struct lpfc_hba *phba, uint32_t diag)
- {
- LPFC_MBOXQ_t *pmboxq;
- struct lpfc_mbx_set_link_diag_state *link_diag_state;
- uint32_t req_len, alloc_len;
- int mbxstatus = MBX_SUCCESS, rc;
- pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!pmboxq)
- return -ENOMEM;
- req_len = (sizeof(struct lpfc_mbx_set_link_diag_state) -
- sizeof(struct lpfc_sli4_cfg_mhdr));
- alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
- LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE,
- req_len, LPFC_SLI4_MBX_EMBED);
- if (alloc_len != req_len) {
- rc = -ENOMEM;
- goto link_diag_state_set_out;
- }
- link_diag_state = &pmboxq->u.mqe.un.link_diag_state;
- bf_set(lpfc_mbx_set_diag_state_link_num, &link_diag_state->u.req,
- phba->sli4_hba.link_state.number);
- bf_set(lpfc_mbx_set_diag_state_link_type, &link_diag_state->u.req,
- phba->sli4_hba.link_state.type);
- if (diag)
- bf_set(lpfc_mbx_set_diag_state_diag,
- &link_diag_state->u.req, 1);
- else
- bf_set(lpfc_mbx_set_diag_state_diag,
- &link_diag_state->u.req, 0);
- mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO);
- if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0))
- rc = 0;
- else
- rc = -ENODEV;
- link_diag_state_set_out:
- if (pmboxq && (mbxstatus != MBX_TIMEOUT))
- mempool_free(pmboxq, phba->mbox_mem_pool);
- return rc;
- }
- /**
- * lpfc_sli4_bsg_diag_loopback_mode - process an sli4 bsg vendor command
- * @phba: Pointer to HBA context object.
- * @job: LPFC_BSG_VENDOR_DIAG_MODE
- *
- * This function is responsible for placing an sli4 port into diagnostic
- * loopback mode in order to perform a diagnostic loopback test.
- */
- static int
- lpfc_sli4_bsg_diag_loopback_mode(struct lpfc_hba *phba, struct fc_bsg_job *job)
- {
- struct diag_mode_set *loopback_mode;
- uint32_t link_flags, timeout, req_len, alloc_len;
- struct lpfc_mbx_set_link_diag_loopback *link_diag_loopback;
- LPFC_MBOXQ_t *pmboxq = NULL;
- int mbxstatus, i, rc = 0;
- /* no data to return just the return code */
- job->reply->reply_payload_rcv_len = 0;
- if (job->request_len < sizeof(struct fc_bsg_request) +
- sizeof(struct diag_mode_set)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "3011 Received DIAG MODE request size:%d "
- "below the minimum size:%d\n",
- job->request_len,
- (int)(sizeof(struct fc_bsg_request) +
- sizeof(struct diag_mode_set)));
- rc = -EINVAL;
- goto job_error;
- }
- rc = lpfc_bsg_diag_mode_enter(phba);
- if (rc)
- goto job_error;
- /* bring the link to diagnostic mode */
- loopback_mode = (struct diag_mode_set *)
- job->request->rqst_data.h_vendor.vendor_cmd;
- link_flags = loopback_mode->type;
- timeout = loopback_mode->timeout * 100;
- rc = lpfc_sli4_bsg_set_link_diag_state(phba, 1);
- if (rc)
- goto loopback_mode_exit;
- /* wait for link down before proceeding */
- i = 0;
- while (phba->link_state != LPFC_LINK_DOWN) {
- if (i++ > timeout) {
- rc = -ETIMEDOUT;
- goto loopback_mode_exit;
- }
- msleep(10);
- }
- /* set up loopback mode */
- pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!pmboxq) {
- rc = -ENOMEM;
- goto loopback_mode_exit;
- }
- req_len = (sizeof(struct lpfc_mbx_set_link_diag_loopback) -
- sizeof(struct lpfc_sli4_cfg_mhdr));
- alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
- LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_LOOPBACK,
- req_len, LPFC_SLI4_MBX_EMBED);
- if (alloc_len != req_len) {
- rc = -ENOMEM;
- goto loopback_mode_exit;
- }
- link_diag_loopback = &pmboxq->u.mqe.un.link_diag_loopback;
- bf_set(lpfc_mbx_set_diag_state_link_num,
- &link_diag_loopback->u.req, phba->sli4_hba.link_state.number);
- bf_set(lpfc_mbx_set_diag_state_link_type,
- &link_diag_loopback->u.req, phba->sli4_hba.link_state.type);
- if (link_flags == INTERNAL_LOOP_BACK)
- bf_set(lpfc_mbx_set_diag_lpbk_type,
- &link_diag_loopback->u.req,
- LPFC_DIAG_LOOPBACK_TYPE_INTERNAL);
- else
- bf_set(lpfc_mbx_set_diag_lpbk_type,
- &link_diag_loopback->u.req,
- LPFC_DIAG_LOOPBACK_TYPE_EXTERNAL);
- mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO);
- if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus))
- rc = -ENODEV;
- else {
- phba->link_flag |= LS_LOOPBACK_MODE;
- /* wait for the link attention interrupt */
- msleep(100);
- i = 0;
- while (phba->link_state != LPFC_HBA_READY) {
- if (i++ > timeout) {
- rc = -ETIMEDOUT;
- break;
- }
- msleep(10);
- }
- }
- loopback_mode_exit:
- lpfc_bsg_diag_mode_exit(phba);
- /*
- * Let SLI layer release mboxq if mbox command completed after timeout.
- */
- if (pmboxq && (mbxstatus != MBX_TIMEOUT))
- mempool_free(pmboxq, phba->mbox_mem_pool);
- job_error:
- /* make error code available to userspace */
- job->reply->result = rc;
- /* complete the job back to userspace if no error */
- if (rc == 0)
- job->job_done(job);
- return rc;
- }
- /**
- * lpfc_bsg_diag_loopback_mode - bsg vendor command for diag loopback mode
- * @job: LPFC_BSG_VENDOR_DIAG_MODE
- *
- * This function is responsible for responding to check and dispatch bsg diag
- * command from the user to proper driver action routines.
- */
- static int
- lpfc_bsg_diag_loopback_mode(struct fc_bsg_job *job)
- {
- struct Scsi_Host *shost;
- struct lpfc_vport *vport;
- struct lpfc_hba *phba;
- int rc;
- shost = job->shost;
- if (!shost)
- return -ENODEV;
- vport = (struct lpfc_vport *)job->shost->hostdata;
- if (!vport)
- return -ENODEV;
- phba = vport->phba;
- if (!phba)
- return -ENODEV;
- if (phba->sli_rev < LPFC_SLI_REV4)
- rc = lpfc_sli3_bsg_diag_loopback_mode(phba, job);
- else if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
- LPFC_SLI_INTF_IF_TYPE_2)
- rc = lpfc_sli4_bsg_diag_loopback_mode(phba, job);
- else
- rc = -ENODEV;
- return rc;
- }
- /**
- * lpfc_sli4_bsg_diag_mode_end - sli4 bsg vendor command for ending diag mode
- * @job: LPFC_BSG_VENDOR_DIAG_MODE_END
- *
- * This function is responsible for responding to check and dispatch bsg diag
- * command from the user to proper driver action routines.
- */
- static int
- lpfc_sli4_bsg_diag_mode_end(struct fc_bsg_job *job)
- {
- struct Scsi_Host *shost;
- struct lpfc_vport *vport;
- struct lpfc_hba *phba;
- int rc;
- shost = job->shost;
- if (!shost)
- return -ENODEV;
- vport = (struct lpfc_vport *)job->shost->hostdata;
- if (!vport)
- return -ENODEV;
- phba = vport->phba;
- if (!phba)
- return -ENODEV;
- if (phba->sli_rev < LPFC_SLI_REV4)
- return -ENODEV;
- if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
- LPFC_SLI_INTF_IF_TYPE_2)
- return -ENODEV;
- rc = lpfc_sli4_bsg_set_link_diag_state(phba, 0);
- if (!rc)
- rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
- return rc;
- }
- /**
- * lpfc_sli4_bsg_link_diag_test - sli4 bsg vendor command for diag link test
- * @job: LPFC_BSG_VENDOR_DIAG_LINK_TEST
- *
- * This function is to perform SLI4 diag link test request from the user
- * applicaiton.
- */
- static int
- lpfc_sli4_bsg_link_diag_test(struct fc_bsg_job *job)
- {
- struct Scsi_Host *shost;
- struct lpfc_vport *vport;
- struct lpfc_hba *phba;
- LPFC_MBOXQ_t *pmboxq;
- struct sli4_link_diag *link_diag_test_cmd;
- uint32_t req_len, alloc_len;
- uint32_t timeout;
- struct lpfc_mbx_run_link_diag_test *run_link_diag_test;
- union lpfc_sli4_cfg_shdr *shdr;
- uint32_t shdr_status, shdr_add_status;
- struct diag_status *diag_status_reply;
- int mbxstatus, rc = 0;
- shost = job->shost;
- if (!shost) {
- rc = -ENODEV;
- goto job_error;
- }
- vport = (struct lpfc_vport *)job->shost->hostdata;
- if (!vport) {
- rc = -ENODEV;
- goto job_error;
- }
- phba = vport->phba;
- if (!phba) {
- rc = -ENODEV;
- goto job_error;
- }
- if (phba->sli_rev < LPFC_SLI_REV4) {
- rc = -ENODEV;
- goto job_error;
- }
- if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
- LPFC_SLI_INTF_IF_TYPE_2) {
- rc = -ENODEV;
- goto job_error;
- }
- if (job->request_len < sizeof(struct fc_bsg_request) +
- sizeof(struct sli4_link_diag)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "3013 Received LINK DIAG TEST request "
- " size:%d below the minimum size:%d\n",
- job->request_len,
- (int)(sizeof(struct fc_bsg_request) +
- sizeof(struct sli4_link_diag)));
- rc = -EINVAL;
- goto job_error;
- }
- rc = lpfc_bsg_diag_mode_enter(phba);
- if (rc)
- goto job_error;
- link_diag_test_cmd = (struct sli4_link_diag *)
- job->request->rqst_data.h_vendor.vendor_cmd;
- timeout = link_diag_test_cmd->timeout * 100;
- rc = lpfc_sli4_bsg_set_link_diag_state(phba, 1);
- if (rc)
- goto job_error;
- pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!pmboxq) {
- rc = -ENOMEM;
- goto link_diag_test_exit;
- }
- req_len = (sizeof(struct lpfc_mbx_set_link_diag_state) -
- sizeof(struct lpfc_sli4_cfg_mhdr));
- alloc_len = lpfc_sli4_config(phba, pmboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
- LPFC_MBOX_OPCODE_FCOE_LINK_DIAG_STATE,
- req_len, LPFC_SLI4_MBX_EMBED);
- if (alloc_len != req_len) {
- rc = -ENOMEM;
- goto link_diag_test_exit;
- }
- run_link_diag_test = &pmboxq->u.mqe.un.link_diag_test;
- bf_set(lpfc_mbx_run_diag_test_link_num, &run_link_diag_test->u.req,
- phba->sli4_hba.link_state.number);
- bf_set(lpfc_mbx_run_diag_test_link_type, &run_link_diag_test->u.req,
- phba->sli4_hba.link_state.type);
- bf_set(lpfc_mbx_run_diag_test_test_id, &run_link_diag_test->u.req,
- link_diag_test_cmd->test_id);
- bf_set(lpfc_mbx_run_diag_test_loops, &run_link_diag_test->u.req,
- link_diag_test_cmd->loops);
- bf_set(lpfc_mbx_run_diag_test_test_ver, &run_link_diag_test->u.req,
- link_diag_test_cmd->test_version);
- bf_set(lpfc_mbx_run_diag_test_err_act, &run_link_diag_test->u.req,
- link_diag_test_cmd->error_action);
- mbxstatus = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
- shdr = (union lpfc_sli4_cfg_shdr *)
- &pmboxq->u.mqe.un.sli4_config.header.cfg_shdr;
- shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
- shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
- if (shdr_status || shdr_add_status || mbxstatus) {
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "3010 Run link diag test mailbox failed with "
- "mbx_status x%x status x%x, add_status x%x\n",
- mbxstatus, shdr_status, shdr_add_status);
- }
- diag_status_reply = (struct diag_status *)
- job->reply->reply_data.vendor_reply.vendor_rsp;
- if (job->reply_len <
- sizeof(struct fc_bsg_request) + sizeof(struct diag_status)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "3012 Received Run link diag test reply "
- "below minimum size (%d): reply_len:%d\n",
- (int)(sizeof(struct fc_bsg_request) +
- sizeof(struct diag_status)),
- job->reply_len);
- rc = -EINVAL;
- goto job_error;
- }
- diag_status_reply->mbox_status = mbxstatus;
- diag_status_reply->shdr_status = shdr_status;
- diag_status_reply->shdr_add_status = shdr_add_status;
- link_diag_test_exit:
- rc = lpfc_sli4_bsg_set_link_diag_state(phba, 0);
- if (pmboxq)
- mempool_free(pmboxq, phba->mbox_mem_pool);
- lpfc_bsg_diag_mode_exit(phba);
- job_error:
- /* make error code available to userspace */
- job->reply->result = rc;
- /* complete the job back to userspace if no error */
- if (rc == 0)
- job->job_done(job);
- return rc;
- }
- /**
- * lpfcdiag_loop_self_reg - obtains a remote port login id
- * @phba: Pointer to HBA context object
- * @rpi: Pointer to a remote port login id
- *
- * This function obtains a remote port login id so the diag loopback test
- * can send and receive its own unsolicited CT command.
- **/
- static int lpfcdiag_loop_self_reg(struct lpfc_hba *phba, uint16_t *rpi)
- {
- LPFC_MBOXQ_t *mbox;
- struct lpfc_dmabuf *dmabuff;
- int status;
- mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!mbox)
- return -ENOMEM;
- if (phba->sli_rev == LPFC_SLI_REV4)
- *rpi = lpfc_sli4_alloc_rpi(phba);
- status = lpfc_reg_rpi(phba, 0, phba->pport->fc_myDID,
- (uint8_t *)&phba->pport->fc_sparam, mbox, *rpi);
- if (status) {
- mempool_free(mbox, phba->mbox_mem_pool);
- if (phba->sli_rev == LPFC_SLI_REV4)
- lpfc_sli4_free_rpi(phba, *rpi);
- return -ENOMEM;
- }
- dmabuff = (struct lpfc_dmabuf *) mbox->context1;
- mbox->context1 = NULL;
- mbox->context2 = NULL;
- status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
- if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) {
- lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys);
- kfree(dmabuff);
- if (status != MBX_TIMEOUT)
- mempool_free(mbox, phba->mbox_mem_pool);
- if (phba->sli_rev == LPFC_SLI_REV4)
- lpfc_sli4_free_rpi(phba, *rpi);
- return -ENODEV;
- }
- *rpi = mbox->u.mb.un.varWords[0];
- lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys);
- kfree(dmabuff);
- mempool_free(mbox, phba->mbox_mem_pool);
- return 0;
- }
- /**
- * lpfcdiag_loop_self_unreg - unregs from the rpi
- * @phba: Pointer to HBA context object
- * @rpi: Remote port login id
- *
- * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg
- **/
- static int lpfcdiag_loop_self_unreg(struct lpfc_hba *phba, uint16_t rpi)
- {
- LPFC_MBOXQ_t *mbox;
- int status;
- /* Allocate mboxq structure */
- mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (mbox == NULL)
- return -ENOMEM;
- lpfc_unreg_login(phba, 0, rpi, mbox);
- status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
- if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) {
- if (status != MBX_TIMEOUT)
- mempool_free(mbox, phba->mbox_mem_pool);
- return -EIO;
- }
- mempool_free(mbox, phba->mbox_mem_pool);
- if (phba->sli_rev == LPFC_SLI_REV4)
- lpfc_sli4_free_rpi(phba, rpi);
- return 0;
- }
- /**
- * lpfcdiag_loop_get_xri - obtains the transmit and receive ids
- * @phba: Pointer to HBA context object
- * @rpi: Remote port login id
- * @txxri: Pointer to transmit exchange id
- * @rxxri: Pointer to response exchabge id
- *
- * This function obtains the transmit and receive ids required to send
- * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp
- * flags are used to the unsolicted response handler is able to process
- * the ct command sent on the same port.
- **/
- static int lpfcdiag_loop_get_xri(struct lpfc_hba *phba, uint16_t rpi,
- uint16_t *txxri, uint16_t * rxxri)
- {
- struct lpfc_bsg_event *evt;
- struct lpfc_iocbq *cmdiocbq, *rspiocbq;
- IOCB_t *cmd, *rsp;
- struct lpfc_dmabuf *dmabuf;
- struct ulp_bde64 *bpl = NULL;
- struct lpfc_sli_ct_request *ctreq = NULL;
- int ret_val = 0;
- int time_left;
- int iocb_stat = 0;
- unsigned long flags;
- *txxri = 0;
- *rxxri = 0;
- evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid,
- SLI_CT_ELX_LOOPBACK);
- if (!evt)
- return -ENOMEM;
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- list_add(&evt->node, &phba->ct_ev_waiters);
- lpfc_bsg_event_ref(evt);
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- cmdiocbq = lpfc_sli_get_iocbq(phba);
- rspiocbq = lpfc_sli_get_iocbq(phba);
- dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
- if (dmabuf) {
- dmabuf->virt = lpfc_mbuf_alloc(phba, 0, &dmabuf->phys);
- if (dmabuf->virt) {
- INIT_LIST_HEAD(&dmabuf->list);
- bpl = (struct ulp_bde64 *) dmabuf->virt;
- memset(bpl, 0, sizeof(*bpl));
- ctreq = (struct lpfc_sli_ct_request *)(bpl + 1);
- bpl->addrHigh =
- le32_to_cpu(putPaddrHigh(dmabuf->phys +
- sizeof(*bpl)));
- bpl->addrLow =
- le32_to_cpu(putPaddrLow(dmabuf->phys +
- sizeof(*bpl)));
- bpl->tus.f.bdeFlags = 0;
- bpl->tus.f.bdeSize = ELX_LOOPBACK_HEADER_SZ;
- bpl->tus.w = le32_to_cpu(bpl->tus.w);
- }
- }
- if (cmdiocbq == NULL || rspiocbq == NULL ||
- dmabuf == NULL || bpl == NULL || ctreq == NULL ||
- dmabuf->virt == NULL) {
- ret_val = -ENOMEM;
- goto err_get_xri_exit;
- }
- cmd = &cmdiocbq->iocb;
- rsp = &rspiocbq->iocb;
- memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ);
- ctreq->RevisionId.bits.Revision = SLI_CT_REVISION;
- ctreq->RevisionId.bits.InId = 0;
- ctreq->FsType = SLI_CT_ELX_LOOPBACK;
- ctreq->FsSubType = 0;
- ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_XRI_SETUP;
- ctreq->CommandResponse.bits.Size = 0;
- cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(dmabuf->phys);
- cmd->un.xseq64.bdl.addrLow = putPaddrLow(dmabuf->phys);
- cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
- cmd->un.xseq64.bdl.bdeSize = sizeof(*bpl);
- cmd->un.xseq64.w5.hcsw.Fctl = LA;
- cmd->un.xseq64.w5.hcsw.Dfctl = 0;
- cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
- cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT;
- cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CR;
- cmd->ulpBdeCount = 1;
- cmd->ulpLe = 1;
- cmd->ulpClass = CLASS3;
- cmd->ulpContext = rpi;
- cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
- cmdiocbq->vport = phba->pport;
- iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq,
- rspiocbq,
- (phba->fc_ratov * 2)
- + LPFC_DRVR_TIMEOUT);
- if (iocb_stat) {
- ret_val = -EIO;
- goto err_get_xri_exit;
- }
- *txxri = rsp->ulpContext;
- evt->waiting = 1;
- evt->wait_time_stamp = jiffies;
- time_left = wait_event_interruptible_timeout(
- evt->wq, !list_empty(&evt->events_to_see),
- ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ);
- if (list_empty(&evt->events_to_see))
- ret_val = (time_left) ? -EINTR : -ETIMEDOUT;
- else {
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- list_move(evt->events_to_see.prev, &evt->events_to_get);
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- *rxxri = (list_entry(evt->events_to_get.prev,
- typeof(struct event_data),
- node))->immed_dat;
- }
- evt->waiting = 0;
- err_get_xri_exit:
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- lpfc_bsg_event_unref(evt); /* release ref */
- lpfc_bsg_event_unref(evt); /* delete */
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- if (dmabuf) {
- if (dmabuf->virt)
- lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
- kfree(dmabuf);
- }
- if (cmdiocbq && (iocb_stat != IOCB_TIMEDOUT))
- lpfc_sli_release_iocbq(phba, cmdiocbq);
- if (rspiocbq)
- lpfc_sli_release_iocbq(phba, rspiocbq);
- return ret_val;
- }
- /**
- * lpfc_bsg_dma_page_alloc - allocate a bsg mbox page sized dma buffers
- * @phba: Pointer to HBA context object
- *
- * This function allocates BSG_MBOX_SIZE (4KB) page size dma buffer and.
- * retruns the pointer to the buffer.
- **/
- static struct lpfc_dmabuf *
- lpfc_bsg_dma_page_alloc(struct lpfc_hba *phba)
- {
- struct lpfc_dmabuf *dmabuf;
- struct pci_dev *pcidev = phba->pcidev;
- /* allocate dma buffer struct */
- dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
- if (!dmabuf)
- return NULL;
- INIT_LIST_HEAD(&dmabuf->list);
- /* now, allocate dma buffer */
- dmabuf->virt = dma_alloc_coherent(&pcidev->dev, BSG_MBOX_SIZE,
- &(dmabuf->phys), GFP_KERNEL);
- if (!dmabuf->virt) {
- kfree(dmabuf);
- return NULL;
- }
- memset((uint8_t *)dmabuf->virt, 0, BSG_MBOX_SIZE);
- return dmabuf;
- }
- /**
- * lpfc_bsg_dma_page_free - free a bsg mbox page sized dma buffer
- * @phba: Pointer to HBA context object.
- * @dmabuf: Pointer to the bsg mbox page sized dma buffer descriptor.
- *
- * This routine just simply frees a dma buffer and its associated buffer
- * descriptor referred by @dmabuf.
- **/
- static void
- lpfc_bsg_dma_page_free(struct lpfc_hba *phba, struct lpfc_dmabuf *dmabuf)
- {
- struct pci_dev *pcidev = phba->pcidev;
- if (!dmabuf)
- return;
- if (dmabuf->virt)
- dma_free_coherent(&pcidev->dev, BSG_MBOX_SIZE,
- dmabuf->virt, dmabuf->phys);
- kfree(dmabuf);
- return;
- }
- /**
- * lpfc_bsg_dma_page_list_free - free a list of bsg mbox page sized dma buffers
- * @phba: Pointer to HBA context object.
- * @dmabuf_list: Pointer to a list of bsg mbox page sized dma buffer descs.
- *
- * This routine just simply frees all dma buffers and their associated buffer
- * descriptors referred by @dmabuf_list.
- **/
- static void
- lpfc_bsg_dma_page_list_free(struct lpfc_hba *phba,
- struct list_head *dmabuf_list)
- {
- struct lpfc_dmabuf *dmabuf, *next_dmabuf;
- if (list_empty(dmabuf_list))
- return;
- list_for_each_entry_safe(dmabuf, next_dmabuf, dmabuf_list, list) {
- list_del_init(&dmabuf->list);
- lpfc_bsg_dma_page_free(phba, dmabuf);
- }
- return;
- }
- /**
- * diag_cmd_data_alloc - fills in a bde struct with dma buffers
- * @phba: Pointer to HBA context object
- * @bpl: Pointer to 64 bit bde structure
- * @size: Number of bytes to process
- * @nocopydata: Flag to copy user data into the allocated buffer
- *
- * This function allocates page size buffers and populates an lpfc_dmabufext.
- * If allowed the user data pointed to with indataptr is copied into the kernel
- * memory. The chained list of page size buffers is returned.
- **/
- static struct lpfc_dmabufext *
- diag_cmd_data_alloc(struct lpfc_hba *phba,
- struct ulp_bde64 *bpl, uint32_t size,
- int nocopydata)
- {
- struct lpfc_dmabufext *mlist = NULL;
- struct lpfc_dmabufext *dmp;
- int cnt, offset = 0, i = 0;
- struct pci_dev *pcidev;
- pcidev = phba->pcidev;
- while (size) {
- /* We get chunks of 4K */
- if (size > BUF_SZ_4K)
- cnt = BUF_SZ_4K;
- else
- cnt = size;
- /* allocate struct lpfc_dmabufext buffer header */
- dmp = kmalloc(sizeof(struct lpfc_dmabufext), GFP_KERNEL);
- if (!dmp)
- goto out;
- INIT_LIST_HEAD(&dmp->dma.list);
- /* Queue it to a linked list */
- if (mlist)
- list_add_tail(&dmp->dma.list, &mlist->dma.list);
- else
- mlist = dmp;
- /* allocate buffer */
- dmp->dma.virt = dma_alloc_coherent(&pcidev->dev,
- cnt,
- &(dmp->dma.phys),
- GFP_KERNEL);
- if (!dmp->dma.virt)
- goto out;
- dmp->size = cnt;
- if (nocopydata) {
- bpl->tus.f.bdeFlags = 0;
- pci_dma_sync_single_for_device(phba->pcidev,
- dmp->dma.phys, LPFC_BPL_SIZE, PCI_DMA_TODEVICE);
- } else {
- memset((uint8_t *)dmp->dma.virt, 0, cnt);
- bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
- }
- /* build buffer ptr list for IOCB */
- bpl->addrLow = le32_to_cpu(putPaddrLow(dmp->dma.phys));
- bpl->addrHigh = le32_to_cpu(putPaddrHigh(dmp->dma.phys));
- bpl->tus.f.bdeSize = (ushort) cnt;
- bpl->tus.w = le32_to_cpu(bpl->tus.w);
- bpl++;
- i++;
- offset += cnt;
- size -= cnt;
- }
- mlist->flag = i;
- return mlist;
- out:
- diag_cmd_data_free(phba, mlist);
- return NULL;
- }
- /**
- * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd
- * @phba: Pointer to HBA context object
- * @rxxri: Receive exchange id
- * @len: Number of data bytes
- *
- * This function allocates and posts a data buffer of sufficient size to receive
- * an unsolicted CT command.
- **/
- static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba *phba, uint16_t rxxri,
- size_t len)
- {
- struct lpfc_sli *psli = &phba->sli;
- struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
- struct lpfc_iocbq *cmdiocbq;
- IOCB_t *cmd = NULL;
- struct list_head head, *curr, *next;
- struct lpfc_dmabuf *rxbmp;
- struct lpfc_dmabuf *dmp;
- struct lpfc_dmabuf *mp[2] = {NULL, NULL};
- struct ulp_bde64 *rxbpl = NULL;
- uint32_t num_bde;
- struct lpfc_dmabufext *rxbuffer = NULL;
- int ret_val = 0;
- int iocb_stat;
- int i = 0;
- cmdiocbq = lpfc_sli_get_iocbq(phba);
- rxbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
- if (rxbmp != NULL) {
- rxbmp->virt = lpfc_mbuf_alloc(phba, 0, &rxbmp->phys);
- if (rxbmp->virt) {
- INIT_LIST_HEAD(&rxbmp->list);
- rxbpl = (struct ulp_bde64 *) rxbmp->virt;
- rxbuffer = diag_cmd_data_alloc(phba, rxbpl, len, 0);
- }
- }
- if (!cmdiocbq || !rxbmp || !rxbpl || !rxbuffer) {
- ret_val = -ENOMEM;
- goto err_post_rxbufs_exit;
- }
- /* Queue buffers for the receive exchange */
- num_bde = (uint32_t)rxbuffer->flag;
- dmp = &rxbuffer->dma;
- cmd = &cmdiocbq->iocb;
- i = 0;
- INIT_LIST_HEAD(&head);
- list_add_tail(&head, &dmp->list);
- list_for_each_safe(curr, next, &head) {
- mp[i] = list_entry(curr, struct lpfc_dmabuf, list);
- list_del(curr);
- if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
- mp[i]->buffer_tag = lpfc_sli_get_buffer_tag(phba);
- cmd->un.quexri64cx.buff.bde.addrHigh =
- putPaddrHigh(mp[i]->phys);
- cmd->un.quexri64cx.buff.bde.addrLow =
- putPaddrLow(mp[i]->phys);
- cmd->un.quexri64cx.buff.bde.tus.f.bdeSize =
- ((struct lpfc_dmabufext *)mp[i])->size;
- cmd->un.quexri64cx.buff.buffer_tag = mp[i]->buffer_tag;
- cmd->ulpCommand = CMD_QUE_XRI64_CX;
- cmd->ulpPU = 0;
- cmd->ulpLe = 1;
- cmd->ulpBdeCount = 1;
- cmd->unsli3.que_xri64cx_ext_words.ebde_count = 0;
- } else {
- cmd->un.cont64[i].addrHigh = putPaddrHigh(mp[i]->phys);
- cmd->un.cont64[i].addrLow = putPaddrLow(mp[i]->phys);
- cmd->un.cont64[i].tus.f.bdeSize =
- ((struct lpfc_dmabufext *)mp[i])->size;
- cmd->ulpBdeCount = ++i;
- if ((--num_bde > 0) && (i < 2))
- continue;
- cmd->ulpCommand = CMD_QUE_XRI_BUF64_CX;
- cmd->ulpLe = 1;
- }
- cmd->ulpClass = CLASS3;
- cmd->ulpContext = rxxri;
- iocb_stat = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq,
- 0);
- if (iocb_stat == IOCB_ERROR) {
- diag_cmd_data_free(phba,
- (struct lpfc_dmabufext *)mp[0]);
- if (mp[1])
- diag_cmd_data_free(phba,
- (struct lpfc_dmabufext *)mp[1]);
- dmp = list_entry(next, struct lpfc_dmabuf, list);
- ret_val = -EIO;
- goto err_post_rxbufs_exit;
- }
- lpfc_sli_ringpostbuf_put(phba, pring, mp[0]);
- if (mp[1]) {
- lpfc_sli_ringpostbuf_put(phba, pring, mp[1]);
- mp[1] = NULL;
- }
- /* The iocb was freed by lpfc_sli_issue_iocb */
- cmdiocbq = lpfc_sli_get_iocbq(phba);
- if (!cmdiocbq) {
- dmp = list_entry(next, struct lpfc_dmabuf, list);
- ret_val = -EIO;
- goto err_post_rxbufs_exit;
- }
- cmd = &cmdiocbq->iocb;
- i = 0;
- }
- list_del(&head);
- err_post_rxbufs_exit:
- if (rxbmp) {
- if (rxbmp->virt)
- lpfc_mbuf_free(phba, rxbmp->virt, rxbmp->phys);
- kfree(rxbmp);
- }
- if (cmdiocbq)
- lpfc_sli_release_iocbq(phba, cmdiocbq);
- return ret_val;
- }
- /**
- * lpfc_bsg_diag_loopback_run - run loopback on a port by issue ct cmd to itself
- * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job
- *
- * This function receives a user data buffer to be transmitted and received on
- * the same port, the link must be up and in loopback mode prior
- * to being called.
- * 1. A kernel buffer is allocated to copy the user data into.
- * 2. The port registers with "itself".
- * 3. The transmit and receive exchange ids are obtained.
- * 4. The receive exchange id is posted.
- * 5. A new els loopback event is created.
- * 6. The command and response iocbs are allocated.
- * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback.
- *
- * This function is meant to be called n times while the port is in loopback
- * so it is the apps responsibility to issue a reset to take the port out
- * of loopback mode.
- **/
- static int
- lpfc_bsg_diag_loopback_run(struct fc_bsg_job *job)
- {
- struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
- struct lpfc_hba *phba = vport->phba;
- struct diag_mode_test *diag_mode;
- struct lpfc_bsg_event *evt;
- struct event_data *evdat;
- struct lpfc_sli *psli = &phba->sli;
- uint32_t size;
- uint32_t full_size;
- size_t segment_len = 0, segment_offset = 0, current_offset = 0;
- uint16_t rpi = 0;
- struct lpfc_iocbq *cmdiocbq, *rspiocbq;
- IOCB_t *cmd, *rsp;
- struct lpfc_sli_ct_request *ctreq;
- struct lpfc_dmabuf *txbmp;
- struct ulp_bde64 *txbpl = NULL;
- struct lpfc_dmabufext *txbuffer = NULL;
- struct list_head head;
- struct lpfc_dmabuf *curr;
- uint16_t txxri, rxxri;
- uint32_t num_bde;
- uint8_t *ptr = NULL, *rx_databuf = NULL;
- int rc = 0;
- int time_left;
- int iocb_stat;
- unsigned long flags;
- void *dataout = NULL;
- uint32_t total_mem;
- /* in case no data is returned return just the return code */
- job->reply->reply_payload_rcv_len = 0;
- if (job->request_len <
- sizeof(struct fc_bsg_request) + sizeof(struct diag_mode_test)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2739 Received DIAG TEST request below minimum "
- "size\n");
- rc = -EINVAL;
- goto loopback_test_exit;
- }
- if (job->request_payload.payload_len !=
- job->reply_payload.payload_len) {
- rc = -EINVAL;
- goto loopback_test_exit;
- }
- diag_mode = (struct diag_mode_test *)
- job->request->rqst_data.h_vendor.vendor_cmd;
- if ((phba->link_state == LPFC_HBA_ERROR) ||
- (psli->sli_flag & LPFC_BLOCK_MGMT_IO) ||
- (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
- rc = -EACCES;
- goto loopback_test_exit;
- }
- if (!lpfc_is_link_up(phba) || !(phba->link_flag & LS_LOOPBACK_MODE)) {
- rc = -EACCES;
- goto loopback_test_exit;
- }
- size = job->request_payload.payload_len;
- full_size = size + ELX_LOOPBACK_HEADER_SZ; /* plus the header */
- if ((size == 0) || (size > 80 * BUF_SZ_4K)) {
- rc = -ERANGE;
- goto loopback_test_exit;
- }
- if (full_size >= BUF_SZ_4K) {
- /*
- * Allocate memory for ioctl data. If buffer is bigger than 64k,
- * then we allocate 64k and re-use that buffer over and over to
- * xfer the whole block. This is because Linux kernel has a
- * problem allocating more than 120k of kernel space memory. Saw
- * problem with GET_FCPTARGETMAPPING...
- */
- if (size <= (64 * 1024))
- total_mem = full_size;
- else
- total_mem = 64 * 1024;
- } else
- /* Allocate memory for ioctl data */
- total_mem = BUF_SZ_4K;
- dataout = kmalloc(total_mem, GFP_KERNEL);
- if (dataout == NULL) {
- rc = -ENOMEM;
- goto loopback_test_exit;
- }
- ptr = dataout;
- ptr += ELX_LOOPBACK_HEADER_SZ;
- sg_copy_to_buffer(job->request_payload.sg_list,
- job->request_payload.sg_cnt,
- ptr, size);
- rc = lpfcdiag_loop_self_reg(phba, &rpi);
- if (rc)
- goto loopback_test_exit;
- rc = lpfcdiag_loop_get_xri(phba, rpi, &txxri, &rxxri);
- if (rc) {
- lpfcdiag_loop_self_unreg(phba, rpi);
- goto loopback_test_exit;
- }
- rc = lpfcdiag_loop_post_rxbufs(phba, rxxri, full_size);
- if (rc) {
- lpfcdiag_loop_self_unreg(phba, rpi);
- goto loopback_test_exit;
- }
- evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid,
- SLI_CT_ELX_LOOPBACK);
- if (!evt) {
- lpfcdiag_loop_self_unreg(phba, rpi);
- rc = -ENOMEM;
- goto loopback_test_exit;
- }
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- list_add(&evt->node, &phba->ct_ev_waiters);
- lpfc_bsg_event_ref(evt);
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- cmdiocbq = lpfc_sli_get_iocbq(phba);
- rspiocbq = lpfc_sli_get_iocbq(phba);
- txbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
- if (txbmp) {
- txbmp->virt = lpfc_mbuf_alloc(phba, 0, &txbmp->phys);
- if (txbmp->virt) {
- INIT_LIST_HEAD(&txbmp->list);
- txbpl = (struct ulp_bde64 *) txbmp->virt;
- txbuffer = diag_cmd_data_alloc(phba,
- txbpl, full_size, 0);
- }
- }
- if (!cmdiocbq || !rspiocbq || !txbmp || !txbpl || !txbuffer ||
- !txbmp->virt) {
- rc = -ENOMEM;
- goto err_loopback_test_exit;
- }
- cmd = &cmdiocbq->iocb;
- rsp = &rspiocbq->iocb;
- INIT_LIST_HEAD(&head);
- list_add_tail(&head, &txbuffer->dma.list);
- list_for_each_entry(curr, &head, list) {
- segment_len = ((struct lpfc_dmabufext *)curr)->size;
- if (current_offset == 0) {
- ctreq = curr->virt;
- memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ);
- ctreq->RevisionId.bits.Revision = SLI_CT_REVISION;
- ctreq->RevisionId.bits.InId = 0;
- ctreq->FsType = SLI_CT_ELX_LOOPBACK;
- ctreq->FsSubType = 0;
- ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_DATA;
- ctreq->CommandResponse.bits.Size = size;
- segment_offset = ELX_LOOPBACK_HEADER_SZ;
- } else
- segment_offset = 0;
- BUG_ON(segment_offset >= segment_len);
- memcpy(curr->virt + segment_offset,
- ptr + current_offset,
- segment_len - segment_offset);
- current_offset += segment_len - segment_offset;
- BUG_ON(current_offset > size);
- }
- list_del(&head);
- /* Build the XMIT_SEQUENCE iocb */
- num_bde = (uint32_t)txbuffer->flag;
- cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(txbmp->phys);
- cmd->un.xseq64.bdl.addrLow = putPaddrLow(txbmp->phys);
- cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
- cmd->un.xseq64.bdl.bdeSize = (num_bde * sizeof(struct ulp_bde64));
- cmd->un.xseq64.w5.hcsw.Fctl = (LS | LA);
- cmd->un.xseq64.w5.hcsw.Dfctl = 0;
- cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
- cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT;
- cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX;
- cmd->ulpBdeCount = 1;
- cmd->ulpLe = 1;
- cmd->ulpClass = CLASS3;
- cmd->ulpContext = txxri;
- cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
- cmdiocbq->vport = phba->pport;
- iocb_stat = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq,
- rspiocbq, (phba->fc_ratov * 2) +
- LPFC_DRVR_TIMEOUT);
- if ((iocb_stat != IOCB_SUCCESS) || (rsp->ulpStatus != IOCB_SUCCESS)) {
- rc = -EIO;
- goto err_loopback_test_exit;
- }
- evt->waiting = 1;
- time_left = wait_event_interruptible_timeout(
- evt->wq, !list_empty(&evt->events_to_see),
- ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ);
- evt->waiting = 0;
- if (list_empty(&evt->events_to_see))
- rc = (time_left) ? -EINTR : -ETIMEDOUT;
- else {
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- list_move(evt->events_to_see.prev, &evt->events_to_get);
- evdat = list_entry(evt->events_to_get.prev,
- typeof(*evdat), node);
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- rx_databuf = evdat->data;
- if (evdat->len != full_size) {
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "1603 Loopback test did not receive expected "
- "data length. actual length 0x%x expected "
- "length 0x%x\n",
- evdat->len, full_size);
- rc = -EIO;
- } else if (rx_databuf == NULL)
- rc = -EIO;
- else {
- rc = IOCB_SUCCESS;
- /* skip over elx loopback header */
- rx_databuf += ELX_LOOPBACK_HEADER_SZ;
- job->reply->reply_payload_rcv_len =
- sg_copy_from_buffer(job->reply_payload.sg_list,
- job->reply_payload.sg_cnt,
- rx_databuf, size);
- job->reply->reply_payload_rcv_len = size;
- }
- }
- err_loopback_test_exit:
- lpfcdiag_loop_self_unreg(phba, rpi);
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- lpfc_bsg_event_unref(evt); /* release ref */
- lpfc_bsg_event_unref(evt); /* delete */
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- if (cmdiocbq != NULL)
- lpfc_sli_release_iocbq(phba, cmdiocbq);
- if (rspiocbq != NULL)
- lpfc_sli_release_iocbq(phba, rspiocbq);
- if (txbmp != NULL) {
- if (txbpl != NULL) {
- if (txbuffer != NULL)
- diag_cmd_data_free(phba, txbuffer);
- lpfc_mbuf_free(phba, txbmp->virt, txbmp->phys);
- }
- kfree(txbmp);
- }
- loopback_test_exit:
- kfree(dataout);
- /* make error code available to userspace */
- job->reply->result = rc;
- job->dd_data = NULL;
- /* complete the job back to userspace if no error */
- if (rc == 0)
- job->job_done(job);
- return rc;
- }
- /**
- * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command
- * @job: GET_DFC_REV fc_bsg_job
- **/
- static int
- lpfc_bsg_get_dfc_rev(struct fc_bsg_job *job)
- {
- struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
- struct lpfc_hba *phba = vport->phba;
- struct get_mgmt_rev *event_req;
- struct get_mgmt_rev_reply *event_reply;
- int rc = 0;
- if (job->request_len <
- sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2740 Received GET_DFC_REV request below "
- "minimum size\n");
- rc = -EINVAL;
- goto job_error;
- }
- event_req = (struct get_mgmt_rev *)
- job->request->rqst_data.h_vendor.vendor_cmd;
- event_reply = (struct get_mgmt_rev_reply *)
- job->reply->reply_data.vendor_reply.vendor_rsp;
- if (job->reply_len <
- sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev_reply)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2741 Received GET_DFC_REV reply below "
- "minimum size\n");
- rc = -EINVAL;
- goto job_error;
- }
- event_reply->info.a_Major = MANAGEMENT_MAJOR_REV;
- event_reply->info.a_Minor = MANAGEMENT_MINOR_REV;
- job_error:
- job->reply->result = rc;
- if (rc == 0)
- job->job_done(job);
- return rc;
- }
- /**
- * lpfc_bsg_issue_mbox_cmpl - lpfc_bsg_issue_mbox mbox completion handler
- * @phba: Pointer to HBA context object.
- * @pmboxq: Pointer to mailbox command.
- *
- * This is completion handler function for mailbox commands issued from
- * lpfc_bsg_issue_mbox function. This function is called by the
- * mailbox event handler function with no lock held. This function
- * will wake up thread waiting on the wait queue pointed by context1
- * of the mailbox.
- **/
- void
- lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
- {
- struct bsg_job_data *dd_data;
- struct fc_bsg_job *job;
- uint32_t size;
- unsigned long flags;
- uint8_t *pmb, *pmb_buf;
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- dd_data = pmboxq->context1;
- /* job already timed out? */
- if (!dd_data) {
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- return;
- }
- /*
- * The outgoing buffer is readily referred from the dma buffer,
- * just need to get header part from mailboxq structure.
- */
- pmb = (uint8_t *)&pmboxq->u.mb;
- pmb_buf = (uint8_t *)dd_data->context_un.mbox.mb;
- memcpy(pmb_buf, pmb, sizeof(MAILBOX_t));
- job = dd_data->context_un.mbox.set_job;
- if (job) {
- size = job->reply_payload.payload_len;
- job->reply->reply_payload_rcv_len =
- sg_copy_from_buffer(job->reply_payload.sg_list,
- job->reply_payload.sg_cnt,
- pmb_buf, size);
- /* need to hold the lock until we set job->dd_data to NULL
- * to hold off the timeout handler returning to the mid-layer
- * while we are still processing the job.
- */
- job->dd_data = NULL;
- dd_data->context_un.mbox.set_job = NULL;
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- } else {
- dd_data->context_un.mbox.set_job = NULL;
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- }
- mempool_free(dd_data->context_un.mbox.pmboxq, phba->mbox_mem_pool);
- lpfc_bsg_dma_page_free(phba, dd_data->context_un.mbox.dmabuffers);
- kfree(dd_data);
- if (job) {
- job->reply->result = 0;
- job->job_done(job);
- }
- return;
- }
- /**
- * lpfc_bsg_check_cmd_access - test for a supported mailbox command
- * @phba: Pointer to HBA context object.
- * @mb: Pointer to a mailbox object.
- * @vport: Pointer to a vport object.
- *
- * Some commands require the port to be offline, some may not be called from
- * the application.
- **/
- static int lpfc_bsg_check_cmd_access(struct lpfc_hba *phba,
- MAILBOX_t *mb, struct lpfc_vport *vport)
- {
- /* return negative error values for bsg job */
- switch (mb->mbxCommand) {
- /* Offline only */
- case MBX_INIT_LINK:
- case MBX_DOWN_LINK:
- case MBX_CONFIG_LINK:
- case MBX_CONFIG_RING:
- case MBX_RESET_RING:
- case MBX_UNREG_LOGIN:
- case MBX_CLEAR_LA:
- case MBX_DUMP_CONTEXT:
- case MBX_RUN_DIAGS:
- case MBX_RESTART:
- case MBX_SET_MASK:
- if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2743 Command 0x%x is illegal in on-line "
- "state\n",
- mb->mbxCommand);
- return -EPERM;
- }
- case MBX_WRITE_NV:
- case MBX_WRITE_VPARMS:
- case MBX_LOAD_SM:
- case MBX_READ_NV:
- case MBX_READ_CONFIG:
- case MBX_READ_RCONFIG:
- case MBX_READ_STATUS:
- case MBX_READ_XRI:
- case MBX_READ_REV:
- case MBX_READ_LNK_STAT:
- case MBX_DUMP_MEMORY:
- case MBX_DOWN_LOAD:
- case MBX_UPDATE_CFG:
- case MBX_KILL_BOARD:
- case MBX_LOAD_AREA:
- case MBX_LOAD_EXP_ROM:
- case MBX_BEACON:
- case MBX_DEL_LD_ENTRY:
- case MBX_SET_DEBUG:
- case MBX_WRITE_WWN:
- case MBX_SLI4_CONFIG:
- case MBX_READ_EVENT_LOG:
- case MBX_READ_EVENT_LOG_STATUS:
- case MBX_WRITE_EVENT_LOG:
- case MBX_PORT_CAPABILITIES:
- case MBX_PORT_IOV_CONTROL:
- case MBX_RUN_BIU_DIAG64:
- break;
- case MBX_SET_VARIABLE:
- lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
- "1226 mbox: set_variable 0x%x, 0x%x\n",
- mb->un.varWords[0],
- mb->un.varWords[1]);
- if ((mb->un.varWords[0] == SETVAR_MLOMNT)
- && (mb->un.varWords[1] == 1)) {
- phba->wait_4_mlo_maint_flg = 1;
- } else if (mb->un.varWords[0] == SETVAR_MLORST) {
- phba->link_flag &= ~LS_LOOPBACK_MODE;
- phba->fc_topology = LPFC_TOPOLOGY_PT_PT;
- }
- break;
- case MBX_READ_SPARM64:
- case MBX_READ_TOPOLOGY:
- case MBX_REG_LOGIN:
- case MBX_REG_LOGIN64:
- case MBX_CONFIG_PORT:
- case MBX_RUN_BIU_DIAG:
- default:
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2742 Unknown Command 0x%x\n",
- mb->mbxCommand);
- return -EPERM;
- }
- return 0; /* ok */
- }
- /**
- * lpfc_bsg_mbox_ext_cleanup - clean up context of multi-buffer mbox session
- * @phba: Pointer to HBA context object.
- *
- * This is routine clean up and reset BSG handling of multi-buffer mbox
- * command session.
- **/
- static void
- lpfc_bsg_mbox_ext_session_reset(struct lpfc_hba *phba)
- {
- if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_IDLE)
- return;
- /* free all memory, including dma buffers */
- lpfc_bsg_dma_page_list_free(phba,
- &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
- lpfc_bsg_dma_page_free(phba, phba->mbox_ext_buf_ctx.mbx_dmabuf);
- /* multi-buffer write mailbox command pass-through complete */
- memset((char *)&phba->mbox_ext_buf_ctx, 0,
- sizeof(struct lpfc_mbox_ext_buf_ctx));
- INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
- return;
- }
- /**
- * lpfc_bsg_issue_mbox_ext_handle_job - job handler for multi-buffer mbox cmpl
- * @phba: Pointer to HBA context object.
- * @pmboxq: Pointer to mailbox command.
- *
- * This is routine handles BSG job for mailbox commands completions with
- * multiple external buffers.
- **/
- static struct fc_bsg_job *
- lpfc_bsg_issue_mbox_ext_handle_job(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
- {
- struct bsg_job_data *dd_data;
- struct fc_bsg_job *job;
- uint8_t *pmb, *pmb_buf;
- unsigned long flags;
- uint32_t size;
- int rc = 0;
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- dd_data = pmboxq->context1;
- /* has the job already timed out? */
- if (!dd_data) {
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- job = NULL;
- goto job_done_out;
- }
- /*
- * The outgoing buffer is readily referred from the dma buffer,
- * just need to get header part from mailboxq structure.
- */
- pmb = (uint8_t *)&pmboxq->u.mb;
- pmb_buf = (uint8_t *)dd_data->context_un.mbox.mb;
- memcpy(pmb_buf, pmb, sizeof(MAILBOX_t));
- job = dd_data->context_un.mbox.set_job;
- if (job) {
- size = job->reply_payload.payload_len;
- job->reply->reply_payload_rcv_len =
- sg_copy_from_buffer(job->reply_payload.sg_list,
- job->reply_payload.sg_cnt,
- pmb_buf, size);
- /* result for successful */
- job->reply->result = 0;
- job->dd_data = NULL;
- /* need to hold the lock util we set job->dd_data to NULL
- * to hold off the timeout handler from midlayer to take
- * any action.
- */
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2937 SLI_CONFIG ext-buffer maibox command "
- "(x%x/x%x) complete bsg job done, bsize:%d\n",
- phba->mbox_ext_buf_ctx.nembType,
- phba->mbox_ext_buf_ctx.mboxType, size);
- } else
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- job_done_out:
- if (!job)
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "2938 SLI_CONFIG ext-buffer maibox "
- "command (x%x/x%x) failure, rc:x%x\n",
- phba->mbox_ext_buf_ctx.nembType,
- phba->mbox_ext_buf_ctx.mboxType, rc);
- /* state change */
- phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_DONE;
- kfree(dd_data);
- return job;
- }
- /**
- * lpfc_bsg_issue_read_mbox_ext_cmpl - compl handler for multi-buffer read mbox
- * @phba: Pointer to HBA context object.
- * @pmboxq: Pointer to mailbox command.
- *
- * This is completion handler function for mailbox read commands with multiple
- * external buffers.
- **/
- static void
- lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
- {
- struct fc_bsg_job *job;
- /* handle the BSG job with mailbox command */
- if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_ABTS)
- pmboxq->u.mb.mbxStatus = MBXERR_ERROR;
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2939 SLI_CONFIG ext-buffer rd maibox command "
- "complete, ctxState:x%x, mbxStatus:x%x\n",
- phba->mbox_ext_buf_ctx.state, pmboxq->u.mb.mbxStatus);
- job = lpfc_bsg_issue_mbox_ext_handle_job(phba, pmboxq);
- if (pmboxq->u.mb.mbxStatus || phba->mbox_ext_buf_ctx.numBuf == 1)
- lpfc_bsg_mbox_ext_session_reset(phba);
- /* free base driver mailbox structure memory */
- mempool_free(pmboxq, phba->mbox_mem_pool);
- /* complete the bsg job if we have it */
- if (job)
- job->job_done(job);
- return;
- }
- /**
- * lpfc_bsg_issue_write_mbox_ext_cmpl - cmpl handler for multi-buffer write mbox
- * @phba: Pointer to HBA context object.
- * @pmboxq: Pointer to mailbox command.
- *
- * This is completion handler function for mailbox write commands with multiple
- * external buffers.
- **/
- static void
- lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
- {
- struct fc_bsg_job *job;
- /* handle the BSG job with the mailbox command */
- if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_ABTS)
- pmboxq->u.mb.mbxStatus = MBXERR_ERROR;
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2940 SLI_CONFIG ext-buffer wr maibox command "
- "complete, ctxState:x%x, mbxStatus:x%x\n",
- phba->mbox_ext_buf_ctx.state, pmboxq->u.mb.mbxStatus);
- job = lpfc_bsg_issue_mbox_ext_handle_job(phba, pmboxq);
- /* free all memory, including dma buffers */
- mempool_free(pmboxq, phba->mbox_mem_pool);
- lpfc_bsg_mbox_ext_session_reset(phba);
- /* complete the bsg job if we have it */
- if (job)
- job->job_done(job);
- return;
- }
- static void
- lpfc_bsg_sli_cfg_dma_desc_setup(struct lpfc_hba *phba, enum nemb_type nemb_tp,
- uint32_t index, struct lpfc_dmabuf *mbx_dmabuf,
- struct lpfc_dmabuf *ext_dmabuf)
- {
- struct lpfc_sli_config_mbox *sli_cfg_mbx;
- /* pointer to the start of mailbox command */
- sli_cfg_mbx = (struct lpfc_sli_config_mbox *)mbx_dmabuf->virt;
- if (nemb_tp == nemb_mse) {
- if (index == 0) {
- sli_cfg_mbx->un.sli_config_emb0_subsys.
- mse[index].pa_hi =
- putPaddrHigh(mbx_dmabuf->phys +
- sizeof(MAILBOX_t));
- sli_cfg_mbx->un.sli_config_emb0_subsys.
- mse[index].pa_lo =
- putPaddrLow(mbx_dmabuf->phys +
- sizeof(MAILBOX_t));
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2943 SLI_CONFIG(mse)[%d], "
- "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
- index,
- sli_cfg_mbx->un.sli_config_emb0_subsys.
- mse[index].buf_len,
- sli_cfg_mbx->un.sli_config_emb0_subsys.
- mse[index].pa_hi,
- sli_cfg_mbx->un.sli_config_emb0_subsys.
- mse[index].pa_lo);
- } else {
- sli_cfg_mbx->un.sli_config_emb0_subsys.
- mse[index].pa_hi =
- putPaddrHigh(ext_dmabuf->phys);
- sli_cfg_mbx->un.sli_config_emb0_subsys.
- mse[index].pa_lo =
- putPaddrLow(ext_dmabuf->phys);
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2944 SLI_CONFIG(mse)[%d], "
- "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
- index,
- sli_cfg_mbx->un.sli_config_emb0_subsys.
- mse[index].buf_len,
- sli_cfg_mbx->un.sli_config_emb0_subsys.
- mse[index].pa_hi,
- sli_cfg_mbx->un.sli_config_emb0_subsys.
- mse[index].pa_lo);
- }
- } else {
- if (index == 0) {
- sli_cfg_mbx->un.sli_config_emb1_subsys.
- hbd[index].pa_hi =
- putPaddrHigh(mbx_dmabuf->phys +
- sizeof(MAILBOX_t));
- sli_cfg_mbx->un.sli_config_emb1_subsys.
- hbd[index].pa_lo =
- putPaddrLow(mbx_dmabuf->phys +
- sizeof(MAILBOX_t));
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "3007 SLI_CONFIG(hbd)[%d], "
- "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
- index,
- bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
- &sli_cfg_mbx->un.
- sli_config_emb1_subsys.hbd[index]),
- sli_cfg_mbx->un.sli_config_emb1_subsys.
- hbd[index].pa_hi,
- sli_cfg_mbx->un.sli_config_emb1_subsys.
- hbd[index].pa_lo);
- } else {
- sli_cfg_mbx->un.sli_config_emb1_subsys.
- hbd[index].pa_hi =
- putPaddrHigh(ext_dmabuf->phys);
- sli_cfg_mbx->un.sli_config_emb1_subsys.
- hbd[index].pa_lo =
- putPaddrLow(ext_dmabuf->phys);
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "3008 SLI_CONFIG(hbd)[%d], "
- "bufLen:%d, addrHi:x%x, addrLo:x%x\n",
- index,
- bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
- &sli_cfg_mbx->un.
- sli_config_emb1_subsys.hbd[index]),
- sli_cfg_mbx->un.sli_config_emb1_subsys.
- hbd[index].pa_hi,
- sli_cfg_mbx->un.sli_config_emb1_subsys.
- hbd[index].pa_lo);
- }
- }
- return;
- }
- /**
- * lpfc_bsg_sli_cfg_mse_read_cmd_ext - sli_config non-embedded mailbox cmd read
- * @phba: Pointer to HBA context object.
- * @mb: Pointer to a BSG mailbox object.
- * @nemb_tp: Enumerate of non-embedded mailbox command type.
- * @dmabuff: Pointer to a DMA buffer descriptor.
- *
- * This routine performs SLI_CONFIG (0x9B) read mailbox command operation with
- * non-embedded external bufffers.
- **/
- static int
- lpfc_bsg_sli_cfg_read_cmd_ext(struct lpfc_hba *phba, struct fc_bsg_job *job,
- enum nemb_type nemb_tp,
- struct lpfc_dmabuf *dmabuf)
- {
- struct lpfc_sli_config_mbox *sli_cfg_mbx;
- struct dfc_mbox_req *mbox_req;
- struct lpfc_dmabuf *curr_dmabuf, *next_dmabuf;
- uint32_t ext_buf_cnt, ext_buf_index;
- struct lpfc_dmabuf *ext_dmabuf = NULL;
- struct bsg_job_data *dd_data = NULL;
- LPFC_MBOXQ_t *pmboxq = NULL;
- MAILBOX_t *pmb;
- uint8_t *pmbx;
- int rc, i;
- mbox_req =
- (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd;
- /* pointer to the start of mailbox command */
- sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt;
- if (nemb_tp == nemb_mse) {
- ext_buf_cnt = bsg_bf_get(lpfc_mbox_hdr_mse_cnt,
- &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr);
- if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_MSE) {
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "2945 Handled SLI_CONFIG(mse) rd, "
- "ext_buf_cnt(%d) out of range(%d)\n",
- ext_buf_cnt,
- LPFC_MBX_SLI_CONFIG_MAX_MSE);
- rc = -ERANGE;
- goto job_error;
- }
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2941 Handled SLI_CONFIG(mse) rd, "
- "ext_buf_cnt:%d\n", ext_buf_cnt);
- } else {
- /* sanity check on interface type for support */
- if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
- LPFC_SLI_INTF_IF_TYPE_2) {
- rc = -ENODEV;
- goto job_error;
- }
- /* nemb_tp == nemb_hbd */
- ext_buf_cnt = sli_cfg_mbx->un.sli_config_emb1_subsys.hbd_count;
- if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_HBD) {
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "2946 Handled SLI_CONFIG(hbd) rd, "
- "ext_buf_cnt(%d) out of range(%d)\n",
- ext_buf_cnt,
- LPFC_MBX_SLI_CONFIG_MAX_HBD);
- rc = -ERANGE;
- goto job_error;
- }
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2942 Handled SLI_CONFIG(hbd) rd, "
- "ext_buf_cnt:%d\n", ext_buf_cnt);
- }
- /* reject non-embedded mailbox command with none external buffer */
- if (ext_buf_cnt == 0) {
- rc = -EPERM;
- goto job_error;
- } else if (ext_buf_cnt > 1) {
- /* additional external read buffers */
- for (i = 1; i < ext_buf_cnt; i++) {
- ext_dmabuf = lpfc_bsg_dma_page_alloc(phba);
- if (!ext_dmabuf) {
- rc = -ENOMEM;
- goto job_error;
- }
- list_add_tail(&ext_dmabuf->list,
- &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
- }
- }
- /* bsg tracking structure */
- dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
- if (!dd_data) {
- rc = -ENOMEM;
- goto job_error;
- }
- /* mailbox command structure for base driver */
- pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!pmboxq) {
- rc = -ENOMEM;
- goto job_error;
- }
- memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
- /* for the first external buffer */
- lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, 0, dmabuf, dmabuf);
- /* for the rest of external buffer descriptors if any */
- if (ext_buf_cnt > 1) {
- ext_buf_index = 1;
- list_for_each_entry_safe(curr_dmabuf, next_dmabuf,
- &phba->mbox_ext_buf_ctx.ext_dmabuf_list, list) {
- lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp,
- ext_buf_index, dmabuf,
- curr_dmabuf);
- ext_buf_index++;
- }
- }
- /* construct base driver mbox command */
- pmb = &pmboxq->u.mb;
- pmbx = (uint8_t *)dmabuf->virt;
- memcpy(pmb, pmbx, sizeof(*pmb));
- pmb->mbxOwner = OWN_HOST;
- pmboxq->vport = phba->pport;
- /* multi-buffer handling context */
- phba->mbox_ext_buf_ctx.nembType = nemb_tp;
- phba->mbox_ext_buf_ctx.mboxType = mbox_rd;
- phba->mbox_ext_buf_ctx.numBuf = ext_buf_cnt;
- phba->mbox_ext_buf_ctx.mbxTag = mbox_req->extMboxTag;
- phba->mbox_ext_buf_ctx.seqNum = mbox_req->extSeqNum;
- phba->mbox_ext_buf_ctx.mbx_dmabuf = dmabuf;
- /* callback for multi-buffer read mailbox command */
- pmboxq->mbox_cmpl = lpfc_bsg_issue_read_mbox_ext_cmpl;
- /* context fields to callback function */
- pmboxq->context1 = dd_data;
- dd_data->type = TYPE_MBOX;
- dd_data->context_un.mbox.pmboxq = pmboxq;
- dd_data->context_un.mbox.mb = (MAILBOX_t *)pmbx;
- dd_data->context_un.mbox.set_job = job;
- job->dd_data = dd_data;
- /* state change */
- phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT;
- rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
- if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) {
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2947 Issued SLI_CONFIG ext-buffer "
- "maibox command, rc:x%x\n", rc);
- return SLI_CONFIG_HANDLED;
- }
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "2948 Failed to issue SLI_CONFIG ext-buffer "
- "maibox command, rc:x%x\n", rc);
- rc = -EPIPE;
- job_error:
- if (pmboxq)
- mempool_free(pmboxq, phba->mbox_mem_pool);
- lpfc_bsg_dma_page_list_free(phba,
- &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
- kfree(dd_data);
- phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_IDLE;
- return rc;
- }
- /**
- * lpfc_bsg_sli_cfg_write_cmd_ext - sli_config non-embedded mailbox cmd write
- * @phba: Pointer to HBA context object.
- * @mb: Pointer to a BSG mailbox object.
- * @dmabuff: Pointer to a DMA buffer descriptor.
- *
- * This routine performs SLI_CONFIG (0x9B) write mailbox command operation with
- * non-embedded external bufffers.
- **/
- static int
- lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba *phba, struct fc_bsg_job *job,
- enum nemb_type nemb_tp,
- struct lpfc_dmabuf *dmabuf)
- {
- struct dfc_mbox_req *mbox_req;
- struct lpfc_sli_config_mbox *sli_cfg_mbx;
- uint32_t ext_buf_cnt;
- struct bsg_job_data *dd_data = NULL;
- LPFC_MBOXQ_t *pmboxq = NULL;
- MAILBOX_t *pmb;
- uint8_t *mbx;
- int rc = SLI_CONFIG_NOT_HANDLED, i;
- mbox_req =
- (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd;
- /* pointer to the start of mailbox command */
- sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt;
- if (nemb_tp == nemb_mse) {
- ext_buf_cnt = bsg_bf_get(lpfc_mbox_hdr_mse_cnt,
- &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr);
- if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_MSE) {
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "2953 Handled SLI_CONFIG(mse) wr, "
- "ext_buf_cnt(%d) out of range(%d)\n",
- ext_buf_cnt,
- LPFC_MBX_SLI_CONFIG_MAX_MSE);
- return -ERANGE;
- }
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2949 Handled SLI_CONFIG(mse) wr, "
- "ext_buf_cnt:%d\n", ext_buf_cnt);
- } else {
- /* sanity check on interface type for support */
- if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
- LPFC_SLI_INTF_IF_TYPE_2)
- return -ENODEV;
- /* nemb_tp == nemb_hbd */
- ext_buf_cnt = sli_cfg_mbx->un.sli_config_emb1_subsys.hbd_count;
- if (ext_buf_cnt > LPFC_MBX_SLI_CONFIG_MAX_HBD) {
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "2954 Handled SLI_CONFIG(hbd) wr, "
- "ext_buf_cnt(%d) out of range(%d)\n",
- ext_buf_cnt,
- LPFC_MBX_SLI_CONFIG_MAX_HBD);
- return -ERANGE;
- }
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2950 Handled SLI_CONFIG(hbd) wr, "
- "ext_buf_cnt:%d\n", ext_buf_cnt);
- }
- if (ext_buf_cnt == 0)
- return -EPERM;
- /* for the first external buffer */
- lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, 0, dmabuf, dmabuf);
- /* log for looking forward */
- for (i = 1; i < ext_buf_cnt; i++) {
- if (nemb_tp == nemb_mse)
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2951 SLI_CONFIG(mse), buf[%d]-length:%d\n",
- i, sli_cfg_mbx->un.sli_config_emb0_subsys.
- mse[i].buf_len);
- else
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2952 SLI_CONFIG(hbd), buf[%d]-length:%d\n",
- i, bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
- &sli_cfg_mbx->un.sli_config_emb1_subsys.
- hbd[i]));
- }
- /* multi-buffer handling context */
- phba->mbox_ext_buf_ctx.nembType = nemb_tp;
- phba->mbox_ext_buf_ctx.mboxType = mbox_wr;
- phba->mbox_ext_buf_ctx.numBuf = ext_buf_cnt;
- phba->mbox_ext_buf_ctx.mbxTag = mbox_req->extMboxTag;
- phba->mbox_ext_buf_ctx.seqNum = mbox_req->extSeqNum;
- phba->mbox_ext_buf_ctx.mbx_dmabuf = dmabuf;
- if (ext_buf_cnt == 1) {
- /* bsg tracking structure */
- dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
- if (!dd_data) {
- rc = -ENOMEM;
- goto job_error;
- }
- /* mailbox command structure for base driver */
- pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!pmboxq) {
- rc = -ENOMEM;
- goto job_error;
- }
- memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
- pmb = &pmboxq->u.mb;
- mbx = (uint8_t *)dmabuf->virt;
- memcpy(pmb, mbx, sizeof(*pmb));
- pmb->mbxOwner = OWN_HOST;
- pmboxq->vport = phba->pport;
- /* callback for multi-buffer read mailbox command */
- pmboxq->mbox_cmpl = lpfc_bsg_issue_write_mbox_ext_cmpl;
- /* context fields to callback function */
- pmboxq->context1 = dd_data;
- dd_data->type = TYPE_MBOX;
- dd_data->context_un.mbox.pmboxq = pmboxq;
- dd_data->context_un.mbox.mb = (MAILBOX_t *)mbx;
- dd_data->context_un.mbox.set_job = job;
- job->dd_data = dd_data;
- /* state change */
- phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT;
- rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
- if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) {
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2955 Issued SLI_CONFIG ext-buffer "
- "maibox command, rc:x%x\n", rc);
- return SLI_CONFIG_HANDLED;
- }
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "2956 Failed to issue SLI_CONFIG ext-buffer "
- "maibox command, rc:x%x\n", rc);
- rc = -EPIPE;
- }
- /* wait for additoinal external buffers */
- job->reply->result = 0;
- job->job_done(job);
- return SLI_CONFIG_HANDLED;
- job_error:
- if (pmboxq)
- mempool_free(pmboxq, phba->mbox_mem_pool);
- kfree(dd_data);
- return rc;
- }
- /**
- * lpfc_bsg_handle_sli_cfg_mbox - handle sli-cfg mailbox cmd with ext buffer
- * @phba: Pointer to HBA context object.
- * @mb: Pointer to a BSG mailbox object.
- * @dmabuff: Pointer to a DMA buffer descriptor.
- *
- * This routine handles SLI_CONFIG (0x9B) mailbox command with non-embedded
- * external bufffers, including both 0x9B with non-embedded MSEs and 0x9B
- * with embedded sussystem 0x1 and opcodes with external HBDs.
- **/
- static int
- lpfc_bsg_handle_sli_cfg_mbox(struct lpfc_hba *phba, struct fc_bsg_job *job,
- struct lpfc_dmabuf *dmabuf)
- {
- struct lpfc_sli_config_mbox *sli_cfg_mbx;
- uint32_t subsys;
- uint32_t opcode;
- int rc = SLI_CONFIG_NOT_HANDLED;
- /* state change */
- phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_HOST;
- sli_cfg_mbx = (struct lpfc_sli_config_mbox *)dmabuf->virt;
- if (!bsg_bf_get(lpfc_mbox_hdr_emb,
- &sli_cfg_mbx->un.sli_config_emb0_subsys.sli_config_hdr)) {
- subsys = bsg_bf_get(lpfc_emb0_subcmnd_subsys,
- &sli_cfg_mbx->un.sli_config_emb0_subsys);
- opcode = bsg_bf_get(lpfc_emb0_subcmnd_opcode,
- &sli_cfg_mbx->un.sli_config_emb0_subsys);
- if (subsys == SLI_CONFIG_SUBSYS_FCOE) {
- switch (opcode) {
- case FCOE_OPCODE_READ_FCF:
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2957 Handled SLI_CONFIG "
- "subsys_fcoe, opcode:x%x\n",
- opcode);
- rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job,
- nemb_mse, dmabuf);
- break;
- case FCOE_OPCODE_ADD_FCF:
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2958 Handled SLI_CONFIG "
- "subsys_fcoe, opcode:x%x\n",
- opcode);
- rc = lpfc_bsg_sli_cfg_write_cmd_ext(phba, job,
- nemb_mse, dmabuf);
- break;
- default:
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2959 Not handled SLI_CONFIG "
- "subsys_fcoe, opcode:x%x\n",
- opcode);
- rc = SLI_CONFIG_NOT_HANDLED;
- break;
- }
- } else {
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2977 Handled SLI_CONFIG "
- "subsys:x%d, opcode:x%x\n",
- subsys, opcode);
- rc = SLI_CONFIG_NOT_HANDLED;
- }
- } else {
- subsys = bsg_bf_get(lpfc_emb1_subcmnd_subsys,
- &sli_cfg_mbx->un.sli_config_emb1_subsys);
- opcode = bsg_bf_get(lpfc_emb1_subcmnd_opcode,
- &sli_cfg_mbx->un.sli_config_emb1_subsys);
- if (subsys == SLI_CONFIG_SUBSYS_COMN) {
- switch (opcode) {
- case COMN_OPCODE_READ_OBJECT:
- case COMN_OPCODE_READ_OBJECT_LIST:
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2960 Handled SLI_CONFIG "
- "subsys_comn, opcode:x%x\n",
- opcode);
- rc = lpfc_bsg_sli_cfg_read_cmd_ext(phba, job,
- nemb_hbd, dmabuf);
- break;
- case COMN_OPCODE_WRITE_OBJECT:
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2961 Handled SLI_CONFIG "
- "subsys_comn, opcode:x%x\n",
- opcode);
- rc = lpfc_bsg_sli_cfg_write_cmd_ext(phba, job,
- nemb_hbd, dmabuf);
- break;
- default:
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2962 Not handled SLI_CONFIG "
- "subsys_comn, opcode:x%x\n",
- opcode);
- rc = SLI_CONFIG_NOT_HANDLED;
- break;
- }
- } else {
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2978 Handled SLI_CONFIG "
- "subsys:x%d, opcode:x%x\n",
- subsys, opcode);
- rc = SLI_CONFIG_NOT_HANDLED;
- }
- }
- return rc;
- }
- /**
- * lpfc_bsg_mbox_ext_abort_req - request to abort mbox command with ext buffers
- * @phba: Pointer to HBA context object.
- *
- * This routine is for requesting to abort a pass-through mailbox command with
- * multiple external buffers due to error condition.
- **/
- static void
- lpfc_bsg_mbox_ext_abort(struct lpfc_hba *phba)
- {
- if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_PORT)
- phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_ABTS;
- else
- lpfc_bsg_mbox_ext_session_reset(phba);
- return;
- }
- /**
- * lpfc_bsg_read_ebuf_get - get the next mailbox read external buffer
- * @phba: Pointer to HBA context object.
- * @dmabuf: Pointer to a DMA buffer descriptor.
- *
- * This routine extracts the next mailbox read external buffer back to
- * user space through BSG.
- **/
- static int
- lpfc_bsg_read_ebuf_get(struct lpfc_hba *phba, struct fc_bsg_job *job)
- {
- struct lpfc_sli_config_mbox *sli_cfg_mbx;
- struct lpfc_dmabuf *dmabuf;
- uint8_t *pbuf;
- uint32_t size;
- uint32_t index;
- index = phba->mbox_ext_buf_ctx.seqNum;
- phba->mbox_ext_buf_ctx.seqNum++;
- sli_cfg_mbx = (struct lpfc_sli_config_mbox *)
- phba->mbox_ext_buf_ctx.mbx_dmabuf->virt;
- if (phba->mbox_ext_buf_ctx.nembType == nemb_mse) {
- size = bsg_bf_get(lpfc_mbox_sli_config_mse_len,
- &sli_cfg_mbx->un.sli_config_emb0_subsys.mse[index]);
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2963 SLI_CONFIG (mse) ext-buffer rd get "
- "buffer[%d], size:%d\n", index, size);
- } else {
- size = bsg_bf_get(lpfc_mbox_sli_config_ecmn_hbd_len,
- &sli_cfg_mbx->un.sli_config_emb1_subsys.hbd[index]);
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2964 SLI_CONFIG (hbd) ext-buffer rd get "
- "buffer[%d], size:%d\n", index, size);
- }
- if (list_empty(&phba->mbox_ext_buf_ctx.ext_dmabuf_list))
- return -EPIPE;
- dmabuf = list_first_entry(&phba->mbox_ext_buf_ctx.ext_dmabuf_list,
- struct lpfc_dmabuf, list);
- list_del_init(&dmabuf->list);
- pbuf = (uint8_t *)dmabuf->virt;
- job->reply->reply_payload_rcv_len =
- sg_copy_from_buffer(job->reply_payload.sg_list,
- job->reply_payload.sg_cnt,
- pbuf, size);
- lpfc_bsg_dma_page_free(phba, dmabuf);
- if (phba->mbox_ext_buf_ctx.seqNum == phba->mbox_ext_buf_ctx.numBuf) {
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2965 SLI_CONFIG (hbd) ext-buffer rd mbox "
- "command session done\n");
- lpfc_bsg_mbox_ext_session_reset(phba);
- }
- job->reply->result = 0;
- job->job_done(job);
- return SLI_CONFIG_HANDLED;
- }
- /**
- * lpfc_bsg_write_ebuf_set - set the next mailbox write external buffer
- * @phba: Pointer to HBA context object.
- * @dmabuf: Pointer to a DMA buffer descriptor.
- *
- * This routine sets up the next mailbox read external buffer obtained
- * from user space through BSG.
- **/
- static int
- lpfc_bsg_write_ebuf_set(struct lpfc_hba *phba, struct fc_bsg_job *job,
- struct lpfc_dmabuf *dmabuf)
- {
- struct lpfc_sli_config_mbox *sli_cfg_mbx;
- struct bsg_job_data *dd_data = NULL;
- LPFC_MBOXQ_t *pmboxq = NULL;
- MAILBOX_t *pmb;
- enum nemb_type nemb_tp;
- uint8_t *pbuf;
- uint32_t size;
- uint32_t index;
- int rc;
- index = phba->mbox_ext_buf_ctx.seqNum;
- phba->mbox_ext_buf_ctx.seqNum++;
- nemb_tp = phba->mbox_ext_buf_ctx.nembType;
- sli_cfg_mbx = (struct lpfc_sli_config_mbox *)
- phba->mbox_ext_buf_ctx.mbx_dmabuf->virt;
- dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
- if (!dd_data) {
- rc = -ENOMEM;
- goto job_error;
- }
- pbuf = (uint8_t *)dmabuf->virt;
- size = job->request_payload.payload_len;
- sg_copy_to_buffer(job->request_payload.sg_list,
- job->request_payload.sg_cnt,
- pbuf, size);
- if (phba->mbox_ext_buf_ctx.nembType == nemb_mse) {
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2966 SLI_CONFIG (mse) ext-buffer wr set "
- "buffer[%d], size:%d\n",
- phba->mbox_ext_buf_ctx.seqNum, size);
- } else {
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2967 SLI_CONFIG (hbd) ext-buffer wr set "
- "buffer[%d], size:%d\n",
- phba->mbox_ext_buf_ctx.seqNum, size);
- }
- /* set up external buffer descriptor and add to external buffer list */
- lpfc_bsg_sli_cfg_dma_desc_setup(phba, nemb_tp, index,
- phba->mbox_ext_buf_ctx.mbx_dmabuf,
- dmabuf);
- list_add_tail(&dmabuf->list, &phba->mbox_ext_buf_ctx.ext_dmabuf_list);
- if (phba->mbox_ext_buf_ctx.seqNum == phba->mbox_ext_buf_ctx.numBuf) {
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2968 SLI_CONFIG ext-buffer wr all %d "
- "ebuffers received\n",
- phba->mbox_ext_buf_ctx.numBuf);
- /* mailbox command structure for base driver */
- pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!pmboxq) {
- rc = -ENOMEM;
- goto job_error;
- }
- memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
- pbuf = (uint8_t *)phba->mbox_ext_buf_ctx.mbx_dmabuf->virt;
- pmb = &pmboxq->u.mb;
- memcpy(pmb, pbuf, sizeof(*pmb));
- pmb->mbxOwner = OWN_HOST;
- pmboxq->vport = phba->pport;
- /* callback for multi-buffer write mailbox command */
- pmboxq->mbox_cmpl = lpfc_bsg_issue_write_mbox_ext_cmpl;
- /* context fields to callback function */
- pmboxq->context1 = dd_data;
- dd_data->type = TYPE_MBOX;
- dd_data->context_un.mbox.pmboxq = pmboxq;
- dd_data->context_un.mbox.mb = (MAILBOX_t *)pbuf;
- dd_data->context_un.mbox.set_job = job;
- job->dd_data = dd_data;
- /* state change */
- phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_PORT;
- rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
- if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY)) {
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2969 Issued SLI_CONFIG ext-buffer "
- "maibox command, rc:x%x\n", rc);
- return SLI_CONFIG_HANDLED;
- }
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "2970 Failed to issue SLI_CONFIG ext-buffer "
- "maibox command, rc:x%x\n", rc);
- rc = -EPIPE;
- goto job_error;
- }
- /* wait for additoinal external buffers */
- job->reply->result = 0;
- job->job_done(job);
- return SLI_CONFIG_HANDLED;
- job_error:
- lpfc_bsg_dma_page_free(phba, dmabuf);
- kfree(dd_data);
- return rc;
- }
- /**
- * lpfc_bsg_handle_sli_cfg_ebuf - handle ext buffer with sli-cfg mailbox cmd
- * @phba: Pointer to HBA context object.
- * @mb: Pointer to a BSG mailbox object.
- * @dmabuff: Pointer to a DMA buffer descriptor.
- *
- * This routine handles the external buffer with SLI_CONFIG (0x9B) mailbox
- * command with multiple non-embedded external buffers.
- **/
- static int
- lpfc_bsg_handle_sli_cfg_ebuf(struct lpfc_hba *phba, struct fc_bsg_job *job,
- struct lpfc_dmabuf *dmabuf)
- {
- int rc;
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2971 SLI_CONFIG buffer (type:x%x)\n",
- phba->mbox_ext_buf_ctx.mboxType);
- if (phba->mbox_ext_buf_ctx.mboxType == mbox_rd) {
- if (phba->mbox_ext_buf_ctx.state != LPFC_BSG_MBOX_DONE) {
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "2972 SLI_CONFIG rd buffer state "
- "mismatch:x%x\n",
- phba->mbox_ext_buf_ctx.state);
- lpfc_bsg_mbox_ext_abort(phba);
- return -EPIPE;
- }
- rc = lpfc_bsg_read_ebuf_get(phba, job);
- if (rc == SLI_CONFIG_HANDLED)
- lpfc_bsg_dma_page_free(phba, dmabuf);
- } else { /* phba->mbox_ext_buf_ctx.mboxType == mbox_wr */
- if (phba->mbox_ext_buf_ctx.state != LPFC_BSG_MBOX_HOST) {
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "2973 SLI_CONFIG wr buffer state "
- "mismatch:x%x\n",
- phba->mbox_ext_buf_ctx.state);
- lpfc_bsg_mbox_ext_abort(phba);
- return -EPIPE;
- }
- rc = lpfc_bsg_write_ebuf_set(phba, job, dmabuf);
- }
- return rc;
- }
- /**
- * lpfc_bsg_handle_sli_cfg_ext - handle sli-cfg mailbox with external buffer
- * @phba: Pointer to HBA context object.
- * @mb: Pointer to a BSG mailbox object.
- * @dmabuff: Pointer to a DMA buffer descriptor.
- *
- * This routine checkes and handles non-embedded multi-buffer SLI_CONFIG
- * (0x9B) mailbox commands and external buffers.
- **/
- static int
- lpfc_bsg_handle_sli_cfg_ext(struct lpfc_hba *phba, struct fc_bsg_job *job,
- struct lpfc_dmabuf *dmabuf)
- {
- struct dfc_mbox_req *mbox_req;
- int rc = SLI_CONFIG_NOT_HANDLED;
- mbox_req =
- (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd;
- /* mbox command with/without single external buffer */
- if (mbox_req->extMboxTag == 0 && mbox_req->extSeqNum == 0)
- return rc;
- /* mbox command and first external buffer */
- if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_IDLE) {
- if (mbox_req->extSeqNum == 1) {
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2974 SLI_CONFIG mailbox: tag:%d, "
- "seq:%d\n", mbox_req->extMboxTag,
- mbox_req->extSeqNum);
- rc = lpfc_bsg_handle_sli_cfg_mbox(phba, job, dmabuf);
- return rc;
- } else
- goto sli_cfg_ext_error;
- }
- /*
- * handle additional external buffers
- */
- /* check broken pipe conditions */
- if (mbox_req->extMboxTag != phba->mbox_ext_buf_ctx.mbxTag)
- goto sli_cfg_ext_error;
- if (mbox_req->extSeqNum > phba->mbox_ext_buf_ctx.numBuf)
- goto sli_cfg_ext_error;
- if (mbox_req->extSeqNum != phba->mbox_ext_buf_ctx.seqNum + 1)
- goto sli_cfg_ext_error;
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2975 SLI_CONFIG mailbox external buffer: "
- "extSta:x%x, tag:%d, seq:%d\n",
- phba->mbox_ext_buf_ctx.state, mbox_req->extMboxTag,
- mbox_req->extSeqNum);
- rc = lpfc_bsg_handle_sli_cfg_ebuf(phba, job, dmabuf);
- return rc;
- sli_cfg_ext_error:
- /* all other cases, broken pipe */
- lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
- "2976 SLI_CONFIG mailbox broken pipe: "
- "ctxSta:x%x, ctxNumBuf:%d "
- "ctxTag:%d, ctxSeq:%d, tag:%d, seq:%d\n",
- phba->mbox_ext_buf_ctx.state,
- phba->mbox_ext_buf_ctx.numBuf,
- phba->mbox_ext_buf_ctx.mbxTag,
- phba->mbox_ext_buf_ctx.seqNum,
- mbox_req->extMboxTag, mbox_req->extSeqNum);
- lpfc_bsg_mbox_ext_session_reset(phba);
- return -EPIPE;
- }
- /**
- * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app
- * @phba: Pointer to HBA context object.
- * @mb: Pointer to a mailbox object.
- * @vport: Pointer to a vport object.
- *
- * Allocate a tracking object, mailbox command memory, get a mailbox
- * from the mailbox pool, copy the caller mailbox command.
- *
- * If offline and the sli is active we need to poll for the command (port is
- * being reset) and com-plete the job, otherwise issue the mailbox command and
- * let our completion handler finish the command.
- **/
- static uint32_t
- lpfc_bsg_issue_mbox(struct lpfc_hba *phba, struct fc_bsg_job *job,
- struct lpfc_vport *vport)
- {
- LPFC_MBOXQ_t *pmboxq = NULL; /* internal mailbox queue */
- MAILBOX_t *pmb; /* shortcut to the pmboxq mailbox */
- /* a 4k buffer to hold the mb and extended data from/to the bsg */
- uint8_t *pmbx = NULL;
- struct bsg_job_data *dd_data = NULL; /* bsg data tracking structure */
- struct lpfc_dmabuf *dmabuf = NULL;
- struct dfc_mbox_req *mbox_req;
- struct READ_EVENT_LOG_VAR *rdEventLog;
- uint32_t transmit_length, receive_length, mode;
- struct lpfc_mbx_sli4_config *sli4_config;
- struct lpfc_mbx_nembed_cmd *nembed_sge;
- struct mbox_header *header;
- struct ulp_bde64 *bde;
- uint8_t *ext = NULL;
- int rc = 0;
- uint8_t *from;
- uint32_t size;
- /* in case no data is transferred */
- job->reply->reply_payload_rcv_len = 0;
- /* sanity check to protect driver */
- if (job->reply_payload.payload_len > BSG_MBOX_SIZE ||
- job->request_payload.payload_len > BSG_MBOX_SIZE) {
- rc = -ERANGE;
- goto job_done;
- }
- /*
- * Don't allow mailbox commands to be sent when blocked or when in
- * the middle of discovery
- */
- if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
- rc = -EAGAIN;
- goto job_done;
- }
- mbox_req =
- (struct dfc_mbox_req *)job->request->rqst_data.h_vendor.vendor_cmd;
- /* check if requested extended data lengths are valid */
- if ((mbox_req->inExtWLen > BSG_MBOX_SIZE/sizeof(uint32_t)) ||
- (mbox_req->outExtWLen > BSG_MBOX_SIZE/sizeof(uint32_t))) {
- rc = -ERANGE;
- goto job_done;
- }
- dmabuf = lpfc_bsg_dma_page_alloc(phba);
- if (!dmabuf || !dmabuf->virt) {
- rc = -ENOMEM;
- goto job_done;
- }
- /* Get the mailbox command or external buffer from BSG */
- pmbx = (uint8_t *)dmabuf->virt;
- size = job->request_payload.payload_len;
- sg_copy_to_buffer(job->request_payload.sg_list,
- job->request_payload.sg_cnt, pmbx, size);
- /* Handle possible SLI_CONFIG with non-embedded payloads */
- if (phba->sli_rev == LPFC_SLI_REV4) {
- rc = lpfc_bsg_handle_sli_cfg_ext(phba, job, dmabuf);
- if (rc == SLI_CONFIG_HANDLED)
- goto job_cont;
- if (rc)
- goto job_done;
- /* SLI_CONFIG_NOT_HANDLED for other mailbox commands */
- }
- rc = lpfc_bsg_check_cmd_access(phba, (MAILBOX_t *)pmbx, vport);
- if (rc != 0)
- goto job_done; /* must be negative */
- /* allocate our bsg tracking structure */
- dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
- if (!dd_data) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2727 Failed allocation of dd_data\n");
- rc = -ENOMEM;
- goto job_done;
- }
- pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
- if (!pmboxq) {
- rc = -ENOMEM;
- goto job_done;
- }
- memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
- pmb = &pmboxq->u.mb;
- memcpy(pmb, pmbx, sizeof(*pmb));
- pmb->mbxOwner = OWN_HOST;
- pmboxq->vport = vport;
- /* If HBA encountered an error attention, allow only DUMP
- * or RESTART mailbox commands until the HBA is restarted.
- */
- if (phba->pport->stopped &&
- pmb->mbxCommand != MBX_DUMP_MEMORY &&
- pmb->mbxCommand != MBX_RESTART &&
- pmb->mbxCommand != MBX_WRITE_VPARMS &&
- pmb->mbxCommand != MBX_WRITE_WWN)
- lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
- "2797 mbox: Issued mailbox cmd "
- "0x%x while in stopped state.\n",
- pmb->mbxCommand);
- /* extended mailbox commands will need an extended buffer */
- if (mbox_req->inExtWLen || mbox_req->outExtWLen) {
- /* any data for the device? */
- if (mbox_req->inExtWLen) {
- from = pmbx;
- ext = from + sizeof(MAILBOX_t);
- }
- pmboxq->context2 = ext;
- pmboxq->in_ext_byte_len =
- mbox_req->inExtWLen * sizeof(uint32_t);
- pmboxq->out_ext_byte_len =
- mbox_req->outExtWLen * sizeof(uint32_t);
- pmboxq->mbox_offset_word = mbox_req->mbOffset;
- }
- /* biu diag will need a kernel buffer to transfer the data
- * allocate our own buffer and setup the mailbox command to
- * use ours
- */
- if (pmb->mbxCommand == MBX_RUN_BIU_DIAG64) {
- transmit_length = pmb->un.varWords[1];
- receive_length = pmb->un.varWords[4];
- /* transmit length cannot be greater than receive length or
- * mailbox extension size
- */
- if ((transmit_length > receive_length) ||
- (transmit_length > BSG_MBOX_SIZE - sizeof(MAILBOX_t))) {
- rc = -ERANGE;
- goto job_done;
- }
- pmb->un.varBIUdiag.un.s2.xmit_bde64.addrHigh =
- putPaddrHigh(dmabuf->phys + sizeof(MAILBOX_t));
- pmb->un.varBIUdiag.un.s2.xmit_bde64.addrLow =
- putPaddrLow(dmabuf->phys + sizeof(MAILBOX_t));
- pmb->un.varBIUdiag.un.s2.rcv_bde64.addrHigh =
- putPaddrHigh(dmabuf->phys + sizeof(MAILBOX_t)
- + pmb->un.varBIUdiag.un.s2.xmit_bde64.tus.f.bdeSize);
- pmb->un.varBIUdiag.un.s2.rcv_bde64.addrLow =
- putPaddrLow(dmabuf->phys + sizeof(MAILBOX_t)
- + pmb->un.varBIUdiag.un.s2.xmit_bde64.tus.f.bdeSize);
- } else if (pmb->mbxCommand == MBX_READ_EVENT_LOG) {
- rdEventLog = &pmb->un.varRdEventLog;
- receive_length = rdEventLog->rcv_bde64.tus.f.bdeSize;
- mode = bf_get(lpfc_event_log, rdEventLog);
- /* receive length cannot be greater than mailbox
- * extension size
- */
- if (receive_length > BSG_MBOX_SIZE - sizeof(MAILBOX_t)) {
- rc = -ERANGE;
- goto job_done;
- }
- /* mode zero uses a bde like biu diags command */
- if (mode == 0) {
- pmb->un.varWords[3] = putPaddrLow(dmabuf->phys
- + sizeof(MAILBOX_t));
- pmb->un.varWords[4] = putPaddrHigh(dmabuf->phys
- + sizeof(MAILBOX_t));
- }
- } else if (phba->sli_rev == LPFC_SLI_REV4) {
- if (pmb->mbxCommand == MBX_DUMP_MEMORY) {
- /* rebuild the command for sli4 using our own buffers
- * like we do for biu diags
- */
- receive_length = pmb->un.varWords[2];
- /* receive length cannot be greater than mailbox
- * extension size
- */
- if (receive_length == 0) {
- rc = -ERANGE;
- goto job_done;
- }
- pmb->un.varWords[3] = putPaddrLow(dmabuf->phys
- + sizeof(MAILBOX_t));
- pmb->un.varWords[4] = putPaddrHigh(dmabuf->phys
- + sizeof(MAILBOX_t));
- } else if ((pmb->mbxCommand == MBX_UPDATE_CFG) &&
- pmb->un.varUpdateCfg.co) {
- bde = (struct ulp_bde64 *)&pmb->un.varWords[4];
- /* bde size cannot be greater than mailbox ext size */
- if (bde->tus.f.bdeSize >
- BSG_MBOX_SIZE - sizeof(MAILBOX_t)) {
- rc = -ERANGE;
- goto job_done;
- }
- bde->addrHigh = putPaddrHigh(dmabuf->phys
- + sizeof(MAILBOX_t));
- bde->addrLow = putPaddrLow(dmabuf->phys
- + sizeof(MAILBOX_t));
- } else if (pmb->mbxCommand == MBX_SLI4_CONFIG) {
- /* Handling non-embedded SLI_CONFIG mailbox command */
- sli4_config = &pmboxq->u.mqe.un.sli4_config;
- if (!bf_get(lpfc_mbox_hdr_emb,
- &sli4_config->header.cfg_mhdr)) {
- /* rebuild the command for sli4 using our
- * own buffers like we do for biu diags
- */
- header = (struct mbox_header *)
- &pmb->un.varWords[0];
- nembed_sge = (struct lpfc_mbx_nembed_cmd *)
- &pmb->un.varWords[0];
- receive_length = nembed_sge->sge[0].length;
- /* receive length cannot be greater than
- * mailbox extension size
- */
- if ((receive_length == 0) ||
- (receive_length >
- BSG_MBOX_SIZE - sizeof(MAILBOX_t))) {
- rc = -ERANGE;
- goto job_done;
- }
- nembed_sge->sge[0].pa_hi =
- putPaddrHigh(dmabuf->phys
- + sizeof(MAILBOX_t));
- nembed_sge->sge[0].pa_lo =
- putPaddrLow(dmabuf->phys
- + sizeof(MAILBOX_t));
- }
- }
- }
- dd_data->context_un.mbox.dmabuffers = dmabuf;
- /* setup wake call as IOCB callback */
- pmboxq->mbox_cmpl = lpfc_bsg_issue_mbox_cmpl;
- /* setup context field to pass wait_queue pointer to wake function */
- pmboxq->context1 = dd_data;
- dd_data->type = TYPE_MBOX;
- dd_data->context_un.mbox.pmboxq = pmboxq;
- dd_data->context_un.mbox.mb = (MAILBOX_t *)pmbx;
- dd_data->context_un.mbox.set_job = job;
- dd_data->context_un.mbox.ext = ext;
- dd_data->context_un.mbox.mbOffset = mbox_req->mbOffset;
- dd_data->context_un.mbox.inExtWLen = mbox_req->inExtWLen;
- dd_data->context_un.mbox.outExtWLen = mbox_req->outExtWLen;
- job->dd_data = dd_data;
- if ((vport->fc_flag & FC_OFFLINE_MODE) ||
- (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
- rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
- if (rc != MBX_SUCCESS) {
- rc = (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
- goto job_done;
- }
- /* job finished, copy the data */
- memcpy(pmbx, pmb, sizeof(*pmb));
- job->reply->reply_payload_rcv_len =
- sg_copy_from_buffer(job->reply_payload.sg_list,
- job->reply_payload.sg_cnt,
- pmbx, size);
- /* not waiting mbox already done */
- rc = 0;
- goto job_done;
- }
- rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
- if ((rc == MBX_SUCCESS) || (rc == MBX_BUSY))
- return 1; /* job started */
- job_done:
- /* common exit for error or job completed inline */
- if (pmboxq)
- mempool_free(pmboxq, phba->mbox_mem_pool);
- lpfc_bsg_dma_page_free(phba, dmabuf);
- kfree(dd_data);
- job_cont:
- return rc;
- }
- /**
- * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command
- * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX.
- **/
- static int
- lpfc_bsg_mbox_cmd(struct fc_bsg_job *job)
- {
- struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
- struct lpfc_hba *phba = vport->phba;
- struct dfc_mbox_req *mbox_req;
- int rc = 0;
- /* mix-and-match backward compatibility */
- job->reply->reply_payload_rcv_len = 0;
- if (job->request_len <
- sizeof(struct fc_bsg_request) + sizeof(struct dfc_mbox_req)) {
- lpfc_printf_log(phba, KERN_INFO, LOG_LIBDFC,
- "2737 Mix-and-match backward compability "
- "between MBOX_REQ old size:%d and "
- "new request size:%d\n",
- (int)(job->request_len -
- sizeof(struct fc_bsg_request)),
- (int)sizeof(struct dfc_mbox_req));
- mbox_req = (struct dfc_mbox_req *)
- job->request->rqst_data.h_vendor.vendor_cmd;
- mbox_req->extMboxTag = 0;
- mbox_req->extSeqNum = 0;
- }
- rc = lpfc_bsg_issue_mbox(phba, job, vport);
- if (rc == 0) {
- /* job done */
- job->reply->result = 0;
- job->dd_data = NULL;
- job->job_done(job);
- } else if (rc == 1)
- /* job submitted, will complete later*/
- rc = 0; /* return zero, no error */
- else {
- /* some error occurred */
- job->reply->result = rc;
- job->dd_data = NULL;
- }
- return rc;
- }
- /**
- * lpfc_bsg_menlo_cmd_cmp - lpfc_menlo_cmd completion handler
- * @phba: Pointer to HBA context object.
- * @cmdiocbq: Pointer to command iocb.
- * @rspiocbq: Pointer to response iocb.
- *
- * This function is the completion handler for iocbs issued using
- * lpfc_menlo_cmd function. This function is called by the
- * ring event handler function without any lock held. This function
- * can be called from both worker thread context and interrupt
- * context. This function also can be called from another thread which
- * cleans up the SLI layer objects.
- * This function copies the contents of the response iocb to the
- * response iocb memory object provided by the caller of
- * lpfc_sli_issue_iocb_wait and then wakes up the thread which
- * sleeps for the iocb completion.
- **/
- static void
- lpfc_bsg_menlo_cmd_cmp(struct lpfc_hba *phba,
- struct lpfc_iocbq *cmdiocbq,
- struct lpfc_iocbq *rspiocbq)
- {
- struct bsg_job_data *dd_data;
- struct fc_bsg_job *job;
- IOCB_t *rsp;
- struct lpfc_dmabuf *bmp;
- struct lpfc_bsg_menlo *menlo;
- unsigned long flags;
- struct menlo_response *menlo_resp;
- int rc = 0;
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- dd_data = cmdiocbq->context1;
- if (!dd_data) {
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- return;
- }
- menlo = &dd_data->context_un.menlo;
- job = menlo->set_job;
- job->dd_data = NULL; /* so timeout handler does not reply */
- spin_lock(&phba->hbalock);
- cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
- if (cmdiocbq->context2 && rspiocbq)
- memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
- &rspiocbq->iocb, sizeof(IOCB_t));
- spin_unlock(&phba->hbalock);
- bmp = menlo->bmp;
- rspiocbq = menlo->rspiocbq;
- rsp = &rspiocbq->iocb;
- pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list,
- job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
- /* always return the xri, this would be used in the case
- * of a menlo download to allow the data to be sent as a continuation
- * of the exchange.
- */
- menlo_resp = (struct menlo_response *)
- job->reply->reply_data.vendor_reply.vendor_rsp;
- menlo_resp->xri = rsp->ulpContext;
- if (rsp->ulpStatus) {
- if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
- switch (rsp->un.ulpWord[4] & 0xff) {
- case IOERR_SEQUENCE_TIMEOUT:
- rc = -ETIMEDOUT;
- break;
- case IOERR_INVALID_RPI:
- rc = -EFAULT;
- break;
- default:
- rc = -EACCES;
- break;
- }
- } else
- rc = -EACCES;
- } else
- job->reply->reply_payload_rcv_len =
- rsp->un.genreq64.bdl.bdeSize;
- lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
- lpfc_sli_release_iocbq(phba, rspiocbq);
- lpfc_sli_release_iocbq(phba, cmdiocbq);
- kfree(bmp);
- kfree(dd_data);
- /* make error code available to userspace */
- job->reply->result = rc;
- /* complete the job back to userspace */
- job->job_done(job);
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- return;
- }
- /**
- * lpfc_menlo_cmd - send an ioctl for menlo hardware
- * @job: fc_bsg_job to handle
- *
- * This function issues a gen request 64 CR ioctl for all menlo cmd requests,
- * all the command completions will return the xri for the command.
- * For menlo data requests a gen request 64 CX is used to continue the exchange
- * supplied in the menlo request header xri field.
- **/
- static int
- lpfc_menlo_cmd(struct fc_bsg_job *job)
- {
- struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocbq, *rspiocbq;
- IOCB_t *cmd, *rsp;
- int rc = 0;
- struct menlo_command *menlo_cmd;
- struct menlo_response *menlo_resp;
- struct lpfc_dmabuf *bmp = NULL;
- int request_nseg;
- int reply_nseg;
- struct scatterlist *sgel = NULL;
- int numbde;
- dma_addr_t busaddr;
- struct bsg_job_data *dd_data;
- struct ulp_bde64 *bpl = NULL;
- /* in case no data is returned return just the return code */
- job->reply->reply_payload_rcv_len = 0;
- if (job->request_len <
- sizeof(struct fc_bsg_request) +
- sizeof(struct menlo_command)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2784 Received MENLO_CMD request below "
- "minimum size\n");
- rc = -ERANGE;
- goto no_dd_data;
- }
- if (job->reply_len <
- sizeof(struct fc_bsg_request) + sizeof(struct menlo_response)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2785 Received MENLO_CMD reply below "
- "minimum size\n");
- rc = -ERANGE;
- goto no_dd_data;
- }
- if (!(phba->menlo_flag & HBA_MENLO_SUPPORT)) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2786 Adapter does not support menlo "
- "commands\n");
- rc = -EPERM;
- goto no_dd_data;
- }
- menlo_cmd = (struct menlo_command *)
- job->request->rqst_data.h_vendor.vendor_cmd;
- menlo_resp = (struct menlo_response *)
- job->reply->reply_data.vendor_reply.vendor_rsp;
- /* allocate our bsg tracking structure */
- dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
- if (!dd_data) {
- lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
- "2787 Failed allocation of dd_data\n");
- rc = -ENOMEM;
- goto no_dd_data;
- }
- bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
- if (!bmp) {
- rc = -ENOMEM;
- goto free_dd;
- }
- cmdiocbq = lpfc_sli_get_iocbq(phba);
- if (!cmdiocbq) {
- rc = -ENOMEM;
- goto free_bmp;
- }
- rspiocbq = lpfc_sli_get_iocbq(phba);
- if (!rspiocbq) {
- rc = -ENOMEM;
- goto free_cmdiocbq;
- }
- rsp = &rspiocbq->iocb;
- bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
- if (!bmp->virt) {
- rc = -ENOMEM;
- goto free_rspiocbq;
- }
- INIT_LIST_HEAD(&bmp->list);
- bpl = (struct ulp_bde64 *) bmp->virt;
- request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) {
- busaddr = sg_dma_address(sgel);
- bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
- bpl->tus.f.bdeSize = sg_dma_len(sgel);
- bpl->tus.w = cpu_to_le32(bpl->tus.w);
- bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr));
- bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr));
- bpl++;
- }
- reply_nseg = pci_map_sg(phba->pcidev, job->reply_payload.sg_list,
- job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
- for_each_sg(job->reply_payload.sg_list, sgel, reply_nseg, numbde) {
- busaddr = sg_dma_address(sgel);
- bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
- bpl->tus.f.bdeSize = sg_dma_len(sgel);
- bpl->tus.w = cpu_to_le32(bpl->tus.w);
- bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr));
- bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr));
- bpl++;
- }
- cmd = &cmdiocbq->iocb;
- cmd->un.genreq64.bdl.ulpIoTag32 = 0;
- cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
- cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
- cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
- cmd->un.genreq64.bdl.bdeSize =
- (request_nseg + reply_nseg) * sizeof(struct ulp_bde64);
- cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
- cmd->un.genreq64.w5.hcsw.Dfctl = 0;
- cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CMD;
- cmd->un.genreq64.w5.hcsw.Type = MENLO_TRANSPORT_TYPE; /* 0xfe */
- cmd->ulpBdeCount = 1;
- cmd->ulpClass = CLASS3;
- cmd->ulpOwner = OWN_CHIP;
- cmd->ulpLe = 1; /* Limited Edition */
- cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
- cmdiocbq->vport = phba->pport;
- /* We want the firmware to timeout before we do */
- cmd->ulpTimeout = MENLO_TIMEOUT - 5;
- cmdiocbq->context3 = bmp;
- cmdiocbq->context2 = rspiocbq;
- cmdiocbq->iocb_cmpl = lpfc_bsg_menlo_cmd_cmp;
- cmdiocbq->context1 = dd_data;
- cmdiocbq->context2 = rspiocbq;
- if (menlo_cmd->cmd == LPFC_BSG_VENDOR_MENLO_CMD) {
- cmd->ulpCommand = CMD_GEN_REQUEST64_CR;
- cmd->ulpPU = MENLO_PU; /* 3 */
- cmd->un.ulpWord[4] = MENLO_DID; /* 0x0000FC0E */
- cmd->ulpContext = MENLO_CONTEXT; /* 0 */
- } else {
- cmd->ulpCommand = CMD_GEN_REQUEST64_CX;
- cmd->ulpPU = 1;
- cmd->un.ulpWord[4] = 0;
- cmd->ulpContext = menlo_cmd->xri;
- }
- dd_data->type = TYPE_MENLO;
- dd_data->context_un.menlo.cmdiocbq = cmdiocbq;
- dd_data->context_un.menlo.rspiocbq = rspiocbq;
- dd_data->context_un.menlo.set_job = job;
- dd_data->context_un.menlo.bmp = bmp;
- rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq,
- MENLO_TIMEOUT - 5);
- if (rc == IOCB_SUCCESS)
- return 0; /* done for now */
- /* iocb failed so cleanup */
- pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
- job->request_payload.sg_cnt, DMA_TO_DEVICE);
- pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list,
- job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
- lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
- free_rspiocbq:
- lpfc_sli_release_iocbq(phba, rspiocbq);
- free_cmdiocbq:
- lpfc_sli_release_iocbq(phba, cmdiocbq);
- free_bmp:
- kfree(bmp);
- free_dd:
- kfree(dd_data);
- no_dd_data:
- /* make error code available to userspace */
- job->reply->result = rc;
- job->dd_data = NULL;
- return rc;
- }
- /**
- * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
- * @job: fc_bsg_job to handle
- **/
- static int
- lpfc_bsg_hst_vendor(struct fc_bsg_job *job)
- {
- int command = job->request->rqst_data.h_vendor.vendor_cmd[0];
- int rc;
- switch (command) {
- case LPFC_BSG_VENDOR_SET_CT_EVENT:
- rc = lpfc_bsg_hba_set_event(job);
- break;
- case LPFC_BSG_VENDOR_GET_CT_EVENT:
- rc = lpfc_bsg_hba_get_event(job);
- break;
- case LPFC_BSG_VENDOR_SEND_MGMT_RESP:
- rc = lpfc_bsg_send_mgmt_rsp(job);
- break;
- case LPFC_BSG_VENDOR_DIAG_MODE:
- rc = lpfc_bsg_diag_loopback_mode(job);
- break;
- case LPFC_BSG_VENDOR_DIAG_MODE_END:
- rc = lpfc_sli4_bsg_diag_mode_end(job);
- break;
- case LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK:
- rc = lpfc_bsg_diag_loopback_run(job);
- break;
- case LPFC_BSG_VENDOR_LINK_DIAG_TEST:
- rc = lpfc_sli4_bsg_link_diag_test(job);
- break;
- case LPFC_BSG_VENDOR_GET_MGMT_REV:
- rc = lpfc_bsg_get_dfc_rev(job);
- break;
- case LPFC_BSG_VENDOR_MBOX:
- rc = lpfc_bsg_mbox_cmd(job);
- break;
- case LPFC_BSG_VENDOR_MENLO_CMD:
- case LPFC_BSG_VENDOR_MENLO_DATA:
- rc = lpfc_menlo_cmd(job);
- break;
- default:
- rc = -EINVAL;
- job->reply->reply_payload_rcv_len = 0;
- /* make error code available to userspace */
- job->reply->result = rc;
- break;
- }
- return rc;
- }
- /**
- * lpfc_bsg_request - handle a bsg request from the FC transport
- * @job: fc_bsg_job to handle
- **/
- int
- lpfc_bsg_request(struct fc_bsg_job *job)
- {
- uint32_t msgcode;
- int rc;
- msgcode = job->request->msgcode;
- switch (msgcode) {
- case FC_BSG_HST_VENDOR:
- rc = lpfc_bsg_hst_vendor(job);
- break;
- case FC_BSG_RPT_ELS:
- rc = lpfc_bsg_rport_els(job);
- break;
- case FC_BSG_RPT_CT:
- rc = lpfc_bsg_send_mgmt_cmd(job);
- break;
- default:
- rc = -EINVAL;
- job->reply->reply_payload_rcv_len = 0;
- /* make error code available to userspace */
- job->reply->result = rc;
- break;
- }
- return rc;
- }
- /**
- * lpfc_bsg_timeout - handle timeout of a bsg request from the FC transport
- * @job: fc_bsg_job that has timed out
- *
- * This function just aborts the job's IOCB. The aborted IOCB will return to
- * the waiting function which will handle passing the error back to userspace
- **/
- int
- lpfc_bsg_timeout(struct fc_bsg_job *job)
- {
- struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
- struct lpfc_hba *phba = vport->phba;
- struct lpfc_iocbq *cmdiocb;
- struct lpfc_bsg_event *evt;
- struct lpfc_bsg_iocb *iocb;
- struct lpfc_bsg_mbox *mbox;
- struct lpfc_bsg_menlo *menlo;
- struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
- struct bsg_job_data *dd_data;
- unsigned long flags;
- spin_lock_irqsave(&phba->ct_ev_lock, flags);
- dd_data = (struct bsg_job_data *)job->dd_data;
- /* timeout and completion crossed paths if no dd_data */
- if (!dd_data) {
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- return 0;
- }
- switch (dd_data->type) {
- case TYPE_IOCB:
- iocb = &dd_data->context_un.iocb;
- cmdiocb = iocb->cmdiocbq;
- /* hint to completion handler that the job timed out */
- job->reply->result = -EAGAIN;
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- /* this will call our completion handler */
- spin_lock_irq(&phba->hbalock);
- lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb);
- spin_unlock_irq(&phba->hbalock);
- break;
- case TYPE_EVT:
- evt = dd_data->context_un.evt;
- /* this event has no job anymore */
- evt->set_job = NULL;
- job->dd_data = NULL;
- job->reply->reply_payload_rcv_len = 0;
- /* Return -EAGAIN which is our way of signallying the
- * app to retry.
- */
- job->reply->result = -EAGAIN;
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- job->job_done(job);
- break;
- case TYPE_MBOX:
- mbox = &dd_data->context_un.mbox;
- /* this mbox has no job anymore */
- mbox->set_job = NULL;
- job->dd_data = NULL;
- job->reply->reply_payload_rcv_len = 0;
- job->reply->result = -EAGAIN;
- /* the mbox completion handler can now be run */
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- job->job_done(job);
- if (phba->mbox_ext_buf_ctx.state == LPFC_BSG_MBOX_PORT)
- phba->mbox_ext_buf_ctx.state = LPFC_BSG_MBOX_ABTS;
- break;
- case TYPE_MENLO:
- menlo = &dd_data->context_un.menlo;
- cmdiocb = menlo->cmdiocbq;
- /* hint to completion handler that the job timed out */
- job->reply->result = -EAGAIN;
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- /* this will call our completion handler */
- spin_lock_irq(&phba->hbalock);
- lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb);
- spin_unlock_irq(&phba->hbalock);
- break;
- default:
- spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
- break;
- }
- /* scsi transport fc fc_bsg_job_timeout expects a zero return code,
- * otherwise an error message will be displayed on the console
- * so always return success (zero)
- */
- return 0;
- }
|