lpfc_init.c 282 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2010 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/idr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/kthread.h>
  27. #include <linux/pci.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/ctype.h>
  30. #include <linux/aer.h>
  31. #include <linux/slab.h>
  32. #include <scsi/scsi.h>
  33. #include <scsi/scsi_device.h>
  34. #include <scsi/scsi_host.h>
  35. #include <scsi/scsi_transport_fc.h>
  36. #include "lpfc_hw4.h"
  37. #include "lpfc_hw.h"
  38. #include "lpfc_sli.h"
  39. #include "lpfc_sli4.h"
  40. #include "lpfc_nl.h"
  41. #include "lpfc_disc.h"
  42. #include "lpfc_scsi.h"
  43. #include "lpfc.h"
  44. #include "lpfc_logmsg.h"
  45. #include "lpfc_crtn.h"
  46. #include "lpfc_vport.h"
  47. #include "lpfc_version.h"
  48. char *_dump_buf_data;
  49. unsigned long _dump_buf_data_order;
  50. char *_dump_buf_dif;
  51. unsigned long _dump_buf_dif_order;
  52. spinlock_t _dump_buf_lock;
  53. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  54. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  55. static int lpfc_sli4_queue_create(struct lpfc_hba *);
  56. static void lpfc_sli4_queue_destroy(struct lpfc_hba *);
  57. static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
  58. static int lpfc_setup_endian_order(struct lpfc_hba *);
  59. static int lpfc_sli4_read_config(struct lpfc_hba *);
  60. static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
  61. static void lpfc_free_sgl_list(struct lpfc_hba *);
  62. static int lpfc_init_sgl_list(struct lpfc_hba *);
  63. static int lpfc_init_active_sgl_array(struct lpfc_hba *);
  64. static void lpfc_free_active_sgl(struct lpfc_hba *);
  65. static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
  66. static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
  67. static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
  68. static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
  69. static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
  70. static struct scsi_transport_template *lpfc_transport_template = NULL;
  71. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  72. static DEFINE_IDR(lpfc_hba_index);
  73. /**
  74. * lpfc_config_port_prep - Perform lpfc initialization prior to config port
  75. * @phba: pointer to lpfc hba data structure.
  76. *
  77. * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
  78. * mailbox command. It retrieves the revision information from the HBA and
  79. * collects the Vital Product Data (VPD) about the HBA for preparing the
  80. * configuration of the HBA.
  81. *
  82. * Return codes:
  83. * 0 - success.
  84. * -ERESTART - requests the SLI layer to reset the HBA and try again.
  85. * Any other value - indicates an error.
  86. **/
  87. int
  88. lpfc_config_port_prep(struct lpfc_hba *phba)
  89. {
  90. lpfc_vpd_t *vp = &phba->vpd;
  91. int i = 0, rc;
  92. LPFC_MBOXQ_t *pmb;
  93. MAILBOX_t *mb;
  94. char *lpfc_vpd_data = NULL;
  95. uint16_t offset = 0;
  96. static char licensed[56] =
  97. "key unlock for use with gnu public licensed code only\0";
  98. static int init_key = 1;
  99. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  100. if (!pmb) {
  101. phba->link_state = LPFC_HBA_ERROR;
  102. return -ENOMEM;
  103. }
  104. mb = &pmb->u.mb;
  105. phba->link_state = LPFC_INIT_MBX_CMDS;
  106. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  107. if (init_key) {
  108. uint32_t *ptext = (uint32_t *) licensed;
  109. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  110. *ptext = cpu_to_be32(*ptext);
  111. init_key = 0;
  112. }
  113. lpfc_read_nv(phba, pmb);
  114. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  115. sizeof (mb->un.varRDnvp.rsvd3));
  116. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  117. sizeof (licensed));
  118. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  119. if (rc != MBX_SUCCESS) {
  120. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  121. "0324 Config Port initialization "
  122. "error, mbxCmd x%x READ_NVPARM, "
  123. "mbxStatus x%x\n",
  124. mb->mbxCommand, mb->mbxStatus);
  125. mempool_free(pmb, phba->mbox_mem_pool);
  126. return -ERESTART;
  127. }
  128. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  129. sizeof(phba->wwnn));
  130. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  131. sizeof(phba->wwpn));
  132. }
  133. phba->sli3_options = 0x0;
  134. /* Setup and issue mailbox READ REV command */
  135. lpfc_read_rev(phba, pmb);
  136. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  137. if (rc != MBX_SUCCESS) {
  138. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  139. "0439 Adapter failed to init, mbxCmd x%x "
  140. "READ_REV, mbxStatus x%x\n",
  141. mb->mbxCommand, mb->mbxStatus);
  142. mempool_free( pmb, phba->mbox_mem_pool);
  143. return -ERESTART;
  144. }
  145. /*
  146. * The value of rr must be 1 since the driver set the cv field to 1.
  147. * This setting requires the FW to set all revision fields.
  148. */
  149. if (mb->un.varRdRev.rr == 0) {
  150. vp->rev.rBit = 0;
  151. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  152. "0440 Adapter failed to init, READ_REV has "
  153. "missing revision information.\n");
  154. mempool_free(pmb, phba->mbox_mem_pool);
  155. return -ERESTART;
  156. }
  157. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
  158. mempool_free(pmb, phba->mbox_mem_pool);
  159. return -EINVAL;
  160. }
  161. /* Save information as VPD data */
  162. vp->rev.rBit = 1;
  163. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  164. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  165. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  166. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  167. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  168. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  169. vp->rev.smRev = mb->un.varRdRev.smRev;
  170. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  171. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  172. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  173. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  174. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  175. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  176. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  177. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  178. /* If the sli feature level is less then 9, we must
  179. * tear down all RPIs and VPIs on link down if NPIV
  180. * is enabled.
  181. */
  182. if (vp->rev.feaLevelHigh < 9)
  183. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  184. if (lpfc_is_LC_HBA(phba->pcidev->device))
  185. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  186. sizeof (phba->RandomData));
  187. /* Get adapter VPD information */
  188. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  189. if (!lpfc_vpd_data)
  190. goto out_free_mbox;
  191. do {
  192. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
  193. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  194. if (rc != MBX_SUCCESS) {
  195. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  196. "0441 VPD not present on adapter, "
  197. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  198. mb->mbxCommand, mb->mbxStatus);
  199. mb->un.varDmp.word_cnt = 0;
  200. }
  201. /* dump mem may return a zero when finished or we got a
  202. * mailbox error, either way we are done.
  203. */
  204. if (mb->un.varDmp.word_cnt == 0)
  205. break;
  206. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  207. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  208. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  209. lpfc_vpd_data + offset,
  210. mb->un.varDmp.word_cnt);
  211. offset += mb->un.varDmp.word_cnt;
  212. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  213. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  214. kfree(lpfc_vpd_data);
  215. out_free_mbox:
  216. mempool_free(pmb, phba->mbox_mem_pool);
  217. return 0;
  218. }
  219. /**
  220. * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
  221. * @phba: pointer to lpfc hba data structure.
  222. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  223. *
  224. * This is the completion handler for driver's configuring asynchronous event
  225. * mailbox command to the device. If the mailbox command returns successfully,
  226. * it will set internal async event support flag to 1; otherwise, it will
  227. * set internal async event support flag to 0.
  228. **/
  229. static void
  230. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  231. {
  232. if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
  233. phba->temp_sensor_support = 1;
  234. else
  235. phba->temp_sensor_support = 0;
  236. mempool_free(pmboxq, phba->mbox_mem_pool);
  237. return;
  238. }
  239. /**
  240. * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
  241. * @phba: pointer to lpfc hba data structure.
  242. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  243. *
  244. * This is the completion handler for dump mailbox command for getting
  245. * wake up parameters. When this command complete, the response contain
  246. * Option rom version of the HBA. This function translate the version number
  247. * into a human readable string and store it in OptionROMVersion.
  248. **/
  249. static void
  250. lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  251. {
  252. struct prog_id *prg;
  253. uint32_t prog_id_word;
  254. char dist = ' ';
  255. /* character array used for decoding dist type. */
  256. char dist_char[] = "nabx";
  257. if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
  258. mempool_free(pmboxq, phba->mbox_mem_pool);
  259. return;
  260. }
  261. prg = (struct prog_id *) &prog_id_word;
  262. /* word 7 contain option rom version */
  263. prog_id_word = pmboxq->u.mb.un.varWords[7];
  264. /* Decode the Option rom version word to a readable string */
  265. if (prg->dist < 4)
  266. dist = dist_char[prg->dist];
  267. if ((prg->dist == 3) && (prg->num == 0))
  268. sprintf(phba->OptionROMVersion, "%d.%d%d",
  269. prg->ver, prg->rev, prg->lev);
  270. else
  271. sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
  272. prg->ver, prg->rev, prg->lev,
  273. dist, prg->num);
  274. mempool_free(pmboxq, phba->mbox_mem_pool);
  275. return;
  276. }
  277. /**
  278. * lpfc_config_port_post - Perform lpfc initialization after config port
  279. * @phba: pointer to lpfc hba data structure.
  280. *
  281. * This routine will do LPFC initialization after the CONFIG_PORT mailbox
  282. * command call. It performs all internal resource and state setups on the
  283. * port: post IOCB buffers, enable appropriate host interrupt attentions,
  284. * ELS ring timers, etc.
  285. *
  286. * Return codes
  287. * 0 - success.
  288. * Any other value - error.
  289. **/
  290. int
  291. lpfc_config_port_post(struct lpfc_hba *phba)
  292. {
  293. struct lpfc_vport *vport = phba->pport;
  294. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  295. LPFC_MBOXQ_t *pmb;
  296. MAILBOX_t *mb;
  297. struct lpfc_dmabuf *mp;
  298. struct lpfc_sli *psli = &phba->sli;
  299. uint32_t status, timeout;
  300. int i, j;
  301. int rc;
  302. spin_lock_irq(&phba->hbalock);
  303. /*
  304. * If the Config port completed correctly the HBA is not
  305. * over heated any more.
  306. */
  307. if (phba->over_temp_state == HBA_OVER_TEMP)
  308. phba->over_temp_state = HBA_NORMAL_TEMP;
  309. spin_unlock_irq(&phba->hbalock);
  310. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  311. if (!pmb) {
  312. phba->link_state = LPFC_HBA_ERROR;
  313. return -ENOMEM;
  314. }
  315. mb = &pmb->u.mb;
  316. /* Get login parameters for NID. */
  317. rc = lpfc_read_sparam(phba, pmb, 0);
  318. if (rc) {
  319. mempool_free(pmb, phba->mbox_mem_pool);
  320. return -ENOMEM;
  321. }
  322. pmb->vport = vport;
  323. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  324. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  325. "0448 Adapter failed init, mbxCmd x%x "
  326. "READ_SPARM mbxStatus x%x\n",
  327. mb->mbxCommand, mb->mbxStatus);
  328. phba->link_state = LPFC_HBA_ERROR;
  329. mp = (struct lpfc_dmabuf *) pmb->context1;
  330. mempool_free(pmb, phba->mbox_mem_pool);
  331. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  332. kfree(mp);
  333. return -EIO;
  334. }
  335. mp = (struct lpfc_dmabuf *) pmb->context1;
  336. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  337. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  338. kfree(mp);
  339. pmb->context1 = NULL;
  340. if (phba->cfg_soft_wwnn)
  341. u64_to_wwn(phba->cfg_soft_wwnn,
  342. vport->fc_sparam.nodeName.u.wwn);
  343. if (phba->cfg_soft_wwpn)
  344. u64_to_wwn(phba->cfg_soft_wwpn,
  345. vport->fc_sparam.portName.u.wwn);
  346. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  347. sizeof (struct lpfc_name));
  348. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  349. sizeof (struct lpfc_name));
  350. /* Update the fc_host data structures with new wwn. */
  351. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  352. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  353. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  354. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  355. /* This should be consolidated into parse_vpd ? - mr */
  356. if (phba->SerialNumber[0] == 0) {
  357. uint8_t *outptr;
  358. outptr = &vport->fc_nodename.u.s.IEEE[0];
  359. for (i = 0; i < 12; i++) {
  360. status = *outptr++;
  361. j = ((status & 0xf0) >> 4);
  362. if (j <= 9)
  363. phba->SerialNumber[i] =
  364. (char)((uint8_t) 0x30 + (uint8_t) j);
  365. else
  366. phba->SerialNumber[i] =
  367. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  368. i++;
  369. j = (status & 0xf);
  370. if (j <= 9)
  371. phba->SerialNumber[i] =
  372. (char)((uint8_t) 0x30 + (uint8_t) j);
  373. else
  374. phba->SerialNumber[i] =
  375. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  376. }
  377. }
  378. lpfc_read_config(phba, pmb);
  379. pmb->vport = vport;
  380. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  381. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  382. "0453 Adapter failed to init, mbxCmd x%x "
  383. "READ_CONFIG, mbxStatus x%x\n",
  384. mb->mbxCommand, mb->mbxStatus);
  385. phba->link_state = LPFC_HBA_ERROR;
  386. mempool_free( pmb, phba->mbox_mem_pool);
  387. return -EIO;
  388. }
  389. /* Check if the port is disabled */
  390. lpfc_sli_read_link_ste(phba);
  391. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  392. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  393. phba->cfg_hba_queue_depth =
  394. (mb->un.varRdConfig.max_xri + 1) -
  395. lpfc_sli4_get_els_iocb_cnt(phba);
  396. phba->lmt = mb->un.varRdConfig.lmt;
  397. /* Get the default values for Model Name and Description */
  398. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  399. if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_16G)
  400. || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G)
  401. && !(phba->lmt & LMT_1Gb))
  402. || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G)
  403. && !(phba->lmt & LMT_2Gb))
  404. || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G)
  405. && !(phba->lmt & LMT_4Gb))
  406. || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G)
  407. && !(phba->lmt & LMT_8Gb))
  408. || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G)
  409. && !(phba->lmt & LMT_10Gb))
  410. || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G)
  411. && !(phba->lmt & LMT_16Gb))) {
  412. /* Reset link speed to auto */
  413. lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
  414. "1302 Invalid speed for this board: "
  415. "Reset link speed to auto: x%x\n",
  416. phba->cfg_link_speed);
  417. phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
  418. }
  419. phba->link_state = LPFC_LINK_DOWN;
  420. /* Only process IOCBs on ELS ring till hba_state is READY */
  421. if (psli->ring[psli->extra_ring].cmdringaddr)
  422. psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
  423. if (psli->ring[psli->fcp_ring].cmdringaddr)
  424. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  425. if (psli->ring[psli->next_ring].cmdringaddr)
  426. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  427. /* Post receive buffers for desired rings */
  428. if (phba->sli_rev != 3)
  429. lpfc_post_rcv_buf(phba);
  430. /*
  431. * Configure HBA MSI-X attention conditions to messages if MSI-X mode
  432. */
  433. if (phba->intr_type == MSIX) {
  434. rc = lpfc_config_msi(phba, pmb);
  435. if (rc) {
  436. mempool_free(pmb, phba->mbox_mem_pool);
  437. return -EIO;
  438. }
  439. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  440. if (rc != MBX_SUCCESS) {
  441. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  442. "0352 Config MSI mailbox command "
  443. "failed, mbxCmd x%x, mbxStatus x%x\n",
  444. pmb->u.mb.mbxCommand,
  445. pmb->u.mb.mbxStatus);
  446. mempool_free(pmb, phba->mbox_mem_pool);
  447. return -EIO;
  448. }
  449. }
  450. spin_lock_irq(&phba->hbalock);
  451. /* Initialize ERATT handling flag */
  452. phba->hba_flag &= ~HBA_ERATT_HANDLED;
  453. /* Enable appropriate host interrupts */
  454. status = readl(phba->HCregaddr);
  455. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  456. if (psli->num_rings > 0)
  457. status |= HC_R0INT_ENA;
  458. if (psli->num_rings > 1)
  459. status |= HC_R1INT_ENA;
  460. if (psli->num_rings > 2)
  461. status |= HC_R2INT_ENA;
  462. if (psli->num_rings > 3)
  463. status |= HC_R3INT_ENA;
  464. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  465. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  466. status &= ~(HC_R0INT_ENA);
  467. writel(status, phba->HCregaddr);
  468. readl(phba->HCregaddr); /* flush */
  469. spin_unlock_irq(&phba->hbalock);
  470. /* Set up ring-0 (ELS) timer */
  471. timeout = phba->fc_ratov * 2;
  472. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  473. /* Set up heart beat (HB) timer */
  474. mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  475. phba->hb_outstanding = 0;
  476. phba->last_completion_time = jiffies;
  477. /* Set up error attention (ERATT) polling timer */
  478. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  479. if (phba->hba_flag & LINK_DISABLED) {
  480. lpfc_printf_log(phba,
  481. KERN_ERR, LOG_INIT,
  482. "2598 Adapter Link is disabled.\n");
  483. lpfc_down_link(phba, pmb);
  484. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  485. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  486. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  487. lpfc_printf_log(phba,
  488. KERN_ERR, LOG_INIT,
  489. "2599 Adapter failed to issue DOWN_LINK"
  490. " mbox command rc 0x%x\n", rc);
  491. mempool_free(pmb, phba->mbox_mem_pool);
  492. return -EIO;
  493. }
  494. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  495. lpfc_init_link(phba, pmb, phba->cfg_topology,
  496. phba->cfg_link_speed);
  497. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  498. lpfc_set_loopback_flag(phba);
  499. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  500. if (rc != MBX_SUCCESS) {
  501. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  502. "0454 Adapter failed to init, mbxCmd x%x "
  503. "INIT_LINK, mbxStatus x%x\n",
  504. mb->mbxCommand, mb->mbxStatus);
  505. /* Clear all interrupt enable conditions */
  506. writel(0, phba->HCregaddr);
  507. readl(phba->HCregaddr); /* flush */
  508. /* Clear all pending interrupts */
  509. writel(0xffffffff, phba->HAregaddr);
  510. readl(phba->HAregaddr); /* flush */
  511. phba->link_state = LPFC_HBA_ERROR;
  512. if (rc != MBX_BUSY)
  513. mempool_free(pmb, phba->mbox_mem_pool);
  514. return -EIO;
  515. }
  516. }
  517. /* MBOX buffer will be freed in mbox compl */
  518. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  519. if (!pmb) {
  520. phba->link_state = LPFC_HBA_ERROR;
  521. return -ENOMEM;
  522. }
  523. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  524. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  525. pmb->vport = phba->pport;
  526. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  527. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  528. lpfc_printf_log(phba,
  529. KERN_ERR,
  530. LOG_INIT,
  531. "0456 Adapter failed to issue "
  532. "ASYNCEVT_ENABLE mbox status x%x\n",
  533. rc);
  534. mempool_free(pmb, phba->mbox_mem_pool);
  535. }
  536. /* Get Option rom version */
  537. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  538. if (!pmb) {
  539. phba->link_state = LPFC_HBA_ERROR;
  540. return -ENOMEM;
  541. }
  542. lpfc_dump_wakeup_param(phba, pmb);
  543. pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
  544. pmb->vport = phba->pport;
  545. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  546. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  547. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
  548. "to get Option ROM version status x%x\n", rc);
  549. mempool_free(pmb, phba->mbox_mem_pool);
  550. }
  551. return 0;
  552. }
  553. /**
  554. * lpfc_hba_init_link - Initialize the FC link
  555. * @phba: pointer to lpfc hba data structure.
  556. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  557. *
  558. * This routine will issue the INIT_LINK mailbox command call.
  559. * It is available to other drivers through the lpfc_hba data
  560. * structure for use as a delayed link up mechanism with the
  561. * module parameter lpfc_suppress_link_up.
  562. *
  563. * Return code
  564. * 0 - success
  565. * Any other value - error
  566. **/
  567. int
  568. lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
  569. {
  570. struct lpfc_vport *vport = phba->pport;
  571. LPFC_MBOXQ_t *pmb;
  572. MAILBOX_t *mb;
  573. int rc;
  574. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  575. if (!pmb) {
  576. phba->link_state = LPFC_HBA_ERROR;
  577. return -ENOMEM;
  578. }
  579. mb = &pmb->u.mb;
  580. pmb->vport = vport;
  581. lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
  582. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  583. lpfc_set_loopback_flag(phba);
  584. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  585. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  586. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  587. "0498 Adapter failed to init, mbxCmd x%x "
  588. "INIT_LINK, mbxStatus x%x\n",
  589. mb->mbxCommand, mb->mbxStatus);
  590. if (phba->sli_rev <= LPFC_SLI_REV3) {
  591. /* Clear all interrupt enable conditions */
  592. writel(0, phba->HCregaddr);
  593. readl(phba->HCregaddr); /* flush */
  594. /* Clear all pending interrupts */
  595. writel(0xffffffff, phba->HAregaddr);
  596. readl(phba->HAregaddr); /* flush */
  597. }
  598. phba->link_state = LPFC_HBA_ERROR;
  599. if (rc != MBX_BUSY || flag == MBX_POLL)
  600. mempool_free(pmb, phba->mbox_mem_pool);
  601. return -EIO;
  602. }
  603. phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
  604. if (flag == MBX_POLL)
  605. mempool_free(pmb, phba->mbox_mem_pool);
  606. return 0;
  607. }
  608. /**
  609. * lpfc_hba_down_link - this routine downs the FC link
  610. * @phba: pointer to lpfc hba data structure.
  611. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  612. *
  613. * This routine will issue the DOWN_LINK mailbox command call.
  614. * It is available to other drivers through the lpfc_hba data
  615. * structure for use to stop the link.
  616. *
  617. * Return code
  618. * 0 - success
  619. * Any other value - error
  620. **/
  621. int
  622. lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
  623. {
  624. LPFC_MBOXQ_t *pmb;
  625. int rc;
  626. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  627. if (!pmb) {
  628. phba->link_state = LPFC_HBA_ERROR;
  629. return -ENOMEM;
  630. }
  631. lpfc_printf_log(phba,
  632. KERN_ERR, LOG_INIT,
  633. "0491 Adapter Link is disabled.\n");
  634. lpfc_down_link(phba, pmb);
  635. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  636. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  637. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  638. lpfc_printf_log(phba,
  639. KERN_ERR, LOG_INIT,
  640. "2522 Adapter failed to issue DOWN_LINK"
  641. " mbox command rc 0x%x\n", rc);
  642. mempool_free(pmb, phba->mbox_mem_pool);
  643. return -EIO;
  644. }
  645. if (flag == MBX_POLL)
  646. mempool_free(pmb, phba->mbox_mem_pool);
  647. return 0;
  648. }
  649. /**
  650. * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
  651. * @phba: pointer to lpfc HBA data structure.
  652. *
  653. * This routine will do LPFC uninitialization before the HBA is reset when
  654. * bringing down the SLI Layer.
  655. *
  656. * Return codes
  657. * 0 - success.
  658. * Any other value - error.
  659. **/
  660. int
  661. lpfc_hba_down_prep(struct lpfc_hba *phba)
  662. {
  663. struct lpfc_vport **vports;
  664. int i;
  665. if (phba->sli_rev <= LPFC_SLI_REV3) {
  666. /* Disable interrupts */
  667. writel(0, phba->HCregaddr);
  668. readl(phba->HCregaddr); /* flush */
  669. }
  670. if (phba->pport->load_flag & FC_UNLOADING)
  671. lpfc_cleanup_discovery_resources(phba->pport);
  672. else {
  673. vports = lpfc_create_vport_work_array(phba);
  674. if (vports != NULL)
  675. for (i = 0; i <= phba->max_vports &&
  676. vports[i] != NULL; i++)
  677. lpfc_cleanup_discovery_resources(vports[i]);
  678. lpfc_destroy_vport_work_array(phba, vports);
  679. }
  680. return 0;
  681. }
  682. /**
  683. * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
  684. * @phba: pointer to lpfc HBA data structure.
  685. *
  686. * This routine will do uninitialization after the HBA is reset when bring
  687. * down the SLI Layer.
  688. *
  689. * Return codes
  690. * 0 - success.
  691. * Any other value - error.
  692. **/
  693. static int
  694. lpfc_hba_down_post_s3(struct lpfc_hba *phba)
  695. {
  696. struct lpfc_sli *psli = &phba->sli;
  697. struct lpfc_sli_ring *pring;
  698. struct lpfc_dmabuf *mp, *next_mp;
  699. LIST_HEAD(completions);
  700. int i;
  701. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  702. lpfc_sli_hbqbuf_free_all(phba);
  703. else {
  704. /* Cleanup preposted buffers on the ELS ring */
  705. pring = &psli->ring[LPFC_ELS_RING];
  706. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  707. list_del(&mp->list);
  708. pring->postbufq_cnt--;
  709. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  710. kfree(mp);
  711. }
  712. }
  713. spin_lock_irq(&phba->hbalock);
  714. for (i = 0; i < psli->num_rings; i++) {
  715. pring = &psli->ring[i];
  716. /* At this point in time the HBA is either reset or DOA. Either
  717. * way, nothing should be on txcmplq as it will NEVER complete.
  718. */
  719. list_splice_init(&pring->txcmplq, &completions);
  720. pring->txcmplq_cnt = 0;
  721. spin_unlock_irq(&phba->hbalock);
  722. /* Cancel all the IOCBs from the completions list */
  723. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  724. IOERR_SLI_ABORTED);
  725. lpfc_sli_abort_iocb_ring(phba, pring);
  726. spin_lock_irq(&phba->hbalock);
  727. }
  728. spin_unlock_irq(&phba->hbalock);
  729. return 0;
  730. }
  731. /**
  732. * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
  733. * @phba: pointer to lpfc HBA data structure.
  734. *
  735. * This routine will do uninitialization after the HBA is reset when bring
  736. * down the SLI Layer.
  737. *
  738. * Return codes
  739. * 0 - success.
  740. * Any other value - error.
  741. **/
  742. static int
  743. lpfc_hba_down_post_s4(struct lpfc_hba *phba)
  744. {
  745. struct lpfc_scsi_buf *psb, *psb_next;
  746. LIST_HEAD(aborts);
  747. int ret;
  748. unsigned long iflag = 0;
  749. struct lpfc_sglq *sglq_entry = NULL;
  750. ret = lpfc_hba_down_post_s3(phba);
  751. if (ret)
  752. return ret;
  753. /* At this point in time the HBA is either reset or DOA. Either
  754. * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
  755. * on the lpfc_sgl_list so that it can either be freed if the
  756. * driver is unloading or reposted if the driver is restarting
  757. * the port.
  758. */
  759. spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
  760. /* scsl_buf_list */
  761. /* abts_sgl_list_lock required because worker thread uses this
  762. * list.
  763. */
  764. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  765. list_for_each_entry(sglq_entry,
  766. &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
  767. sglq_entry->state = SGL_FREED;
  768. list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
  769. &phba->sli4_hba.lpfc_sgl_list);
  770. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  771. /* abts_scsi_buf_list_lock required because worker thread uses this
  772. * list.
  773. */
  774. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  775. list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
  776. &aborts);
  777. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  778. spin_unlock_irq(&phba->hbalock);
  779. list_for_each_entry_safe(psb, psb_next, &aborts, list) {
  780. psb->pCmd = NULL;
  781. psb->status = IOSTAT_SUCCESS;
  782. }
  783. spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
  784. list_splice(&aborts, &phba->lpfc_scsi_buf_list);
  785. spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
  786. return 0;
  787. }
  788. /**
  789. * lpfc_hba_down_post - Wrapper func for hba down post routine
  790. * @phba: pointer to lpfc HBA data structure.
  791. *
  792. * This routine wraps the actual SLI3 or SLI4 routine for performing
  793. * uninitialization after the HBA is reset when bring down the SLI Layer.
  794. *
  795. * Return codes
  796. * 0 - success.
  797. * Any other value - error.
  798. **/
  799. int
  800. lpfc_hba_down_post(struct lpfc_hba *phba)
  801. {
  802. return (*phba->lpfc_hba_down_post)(phba);
  803. }
  804. /**
  805. * lpfc_hb_timeout - The HBA-timer timeout handler
  806. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  807. *
  808. * This is the HBA-timer timeout handler registered to the lpfc driver. When
  809. * this timer fires, a HBA timeout event shall be posted to the lpfc driver
  810. * work-port-events bitmap and the worker thread is notified. This timeout
  811. * event will be used by the worker thread to invoke the actual timeout
  812. * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
  813. * be performed in the timeout handler and the HBA timeout event bit shall
  814. * be cleared by the worker thread after it has taken the event bitmap out.
  815. **/
  816. static void
  817. lpfc_hb_timeout(unsigned long ptr)
  818. {
  819. struct lpfc_hba *phba;
  820. uint32_t tmo_posted;
  821. unsigned long iflag;
  822. phba = (struct lpfc_hba *)ptr;
  823. /* Check for heart beat timeout conditions */
  824. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  825. tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
  826. if (!tmo_posted)
  827. phba->pport->work_port_events |= WORKER_HB_TMO;
  828. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  829. /* Tell the worker thread there is work to do */
  830. if (!tmo_posted)
  831. lpfc_worker_wake_up(phba);
  832. return;
  833. }
  834. /**
  835. * lpfc_rrq_timeout - The RRQ-timer timeout handler
  836. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  837. *
  838. * This is the RRQ-timer timeout handler registered to the lpfc driver. When
  839. * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
  840. * work-port-events bitmap and the worker thread is notified. This timeout
  841. * event will be used by the worker thread to invoke the actual timeout
  842. * handler routine, lpfc_rrq_handler. Any periodical operations will
  843. * be performed in the timeout handler and the RRQ timeout event bit shall
  844. * be cleared by the worker thread after it has taken the event bitmap out.
  845. **/
  846. static void
  847. lpfc_rrq_timeout(unsigned long ptr)
  848. {
  849. struct lpfc_hba *phba;
  850. uint32_t tmo_posted;
  851. unsigned long iflag;
  852. phba = (struct lpfc_hba *)ptr;
  853. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  854. tmo_posted = phba->hba_flag & HBA_RRQ_ACTIVE;
  855. if (!tmo_posted)
  856. phba->hba_flag |= HBA_RRQ_ACTIVE;
  857. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  858. if (!tmo_posted)
  859. lpfc_worker_wake_up(phba);
  860. }
  861. /**
  862. * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
  863. * @phba: pointer to lpfc hba data structure.
  864. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  865. *
  866. * This is the callback function to the lpfc heart-beat mailbox command.
  867. * If configured, the lpfc driver issues the heart-beat mailbox command to
  868. * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
  869. * heart-beat mailbox command is issued, the driver shall set up heart-beat
  870. * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
  871. * heart-beat outstanding state. Once the mailbox command comes back and
  872. * no error conditions detected, the heart-beat mailbox command timer is
  873. * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
  874. * state is cleared for the next heart-beat. If the timer expired with the
  875. * heart-beat outstanding state set, the driver will put the HBA offline.
  876. **/
  877. static void
  878. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  879. {
  880. unsigned long drvr_flag;
  881. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  882. phba->hb_outstanding = 0;
  883. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  884. /* Check and reset heart-beat timer is necessary */
  885. mempool_free(pmboxq, phba->mbox_mem_pool);
  886. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  887. !(phba->link_state == LPFC_HBA_ERROR) &&
  888. !(phba->pport->load_flag & FC_UNLOADING))
  889. mod_timer(&phba->hb_tmofunc,
  890. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  891. return;
  892. }
  893. /**
  894. * lpfc_hb_timeout_handler - The HBA-timer timeout handler
  895. * @phba: pointer to lpfc hba data structure.
  896. *
  897. * This is the actual HBA-timer timeout handler to be invoked by the worker
  898. * thread whenever the HBA timer fired and HBA-timeout event posted. This
  899. * handler performs any periodic operations needed for the device. If such
  900. * periodic event has already been attended to either in the interrupt handler
  901. * or by processing slow-ring or fast-ring events within the HBA-timer
  902. * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
  903. * the timer for the next timeout period. If lpfc heart-beat mailbox command
  904. * is configured and there is no heart-beat mailbox command outstanding, a
  905. * heart-beat mailbox is issued and timer set properly. Otherwise, if there
  906. * has been a heart-beat mailbox command outstanding, the HBA shall be put
  907. * to offline.
  908. **/
  909. void
  910. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  911. {
  912. struct lpfc_vport **vports;
  913. LPFC_MBOXQ_t *pmboxq;
  914. struct lpfc_dmabuf *buf_ptr;
  915. int retval, i;
  916. struct lpfc_sli *psli = &phba->sli;
  917. LIST_HEAD(completions);
  918. vports = lpfc_create_vport_work_array(phba);
  919. if (vports != NULL)
  920. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  921. lpfc_rcv_seq_check_edtov(vports[i]);
  922. lpfc_destroy_vport_work_array(phba, vports);
  923. if ((phba->link_state == LPFC_HBA_ERROR) ||
  924. (phba->pport->load_flag & FC_UNLOADING) ||
  925. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  926. return;
  927. spin_lock_irq(&phba->pport->work_port_lock);
  928. if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
  929. jiffies)) {
  930. spin_unlock_irq(&phba->pport->work_port_lock);
  931. if (!phba->hb_outstanding)
  932. mod_timer(&phba->hb_tmofunc,
  933. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  934. else
  935. mod_timer(&phba->hb_tmofunc,
  936. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  937. return;
  938. }
  939. spin_unlock_irq(&phba->pport->work_port_lock);
  940. if (phba->elsbuf_cnt &&
  941. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  942. spin_lock_irq(&phba->hbalock);
  943. list_splice_init(&phba->elsbuf, &completions);
  944. phba->elsbuf_cnt = 0;
  945. phba->elsbuf_prev_cnt = 0;
  946. spin_unlock_irq(&phba->hbalock);
  947. while (!list_empty(&completions)) {
  948. list_remove_head(&completions, buf_ptr,
  949. struct lpfc_dmabuf, list);
  950. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  951. kfree(buf_ptr);
  952. }
  953. }
  954. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  955. /* If there is no heart beat outstanding, issue a heartbeat command */
  956. if (phba->cfg_enable_hba_heartbeat) {
  957. if (!phba->hb_outstanding) {
  958. if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
  959. (list_empty(&psli->mboxq))) {
  960. pmboxq = mempool_alloc(phba->mbox_mem_pool,
  961. GFP_KERNEL);
  962. if (!pmboxq) {
  963. mod_timer(&phba->hb_tmofunc,
  964. jiffies +
  965. HZ * LPFC_HB_MBOX_INTERVAL);
  966. return;
  967. }
  968. lpfc_heart_beat(phba, pmboxq);
  969. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  970. pmboxq->vport = phba->pport;
  971. retval = lpfc_sli_issue_mbox(phba, pmboxq,
  972. MBX_NOWAIT);
  973. if (retval != MBX_BUSY &&
  974. retval != MBX_SUCCESS) {
  975. mempool_free(pmboxq,
  976. phba->mbox_mem_pool);
  977. mod_timer(&phba->hb_tmofunc,
  978. jiffies +
  979. HZ * LPFC_HB_MBOX_INTERVAL);
  980. return;
  981. }
  982. phba->skipped_hb = 0;
  983. phba->hb_outstanding = 1;
  984. } else if (time_before_eq(phba->last_completion_time,
  985. phba->skipped_hb)) {
  986. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  987. "2857 Last completion time not "
  988. " updated in %d ms\n",
  989. jiffies_to_msecs(jiffies
  990. - phba->last_completion_time));
  991. } else
  992. phba->skipped_hb = jiffies;
  993. mod_timer(&phba->hb_tmofunc,
  994. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  995. return;
  996. } else {
  997. /*
  998. * If heart beat timeout called with hb_outstanding set
  999. * we need to give the hb mailbox cmd a chance to
  1000. * complete or TMO.
  1001. */
  1002. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1003. "0459 Adapter heartbeat still out"
  1004. "standing:last compl time was %d ms.\n",
  1005. jiffies_to_msecs(jiffies
  1006. - phba->last_completion_time));
  1007. mod_timer(&phba->hb_tmofunc,
  1008. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  1009. }
  1010. }
  1011. }
  1012. /**
  1013. * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
  1014. * @phba: pointer to lpfc hba data structure.
  1015. *
  1016. * This routine is called to bring the HBA offline when HBA hardware error
  1017. * other than Port Error 6 has been detected.
  1018. **/
  1019. static void
  1020. lpfc_offline_eratt(struct lpfc_hba *phba)
  1021. {
  1022. struct lpfc_sli *psli = &phba->sli;
  1023. spin_lock_irq(&phba->hbalock);
  1024. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1025. spin_unlock_irq(&phba->hbalock);
  1026. lpfc_offline_prep(phba);
  1027. lpfc_offline(phba);
  1028. lpfc_reset_barrier(phba);
  1029. spin_lock_irq(&phba->hbalock);
  1030. lpfc_sli_brdreset(phba);
  1031. spin_unlock_irq(&phba->hbalock);
  1032. lpfc_hba_down_post(phba);
  1033. lpfc_sli_brdready(phba, HS_MBRDY);
  1034. lpfc_unblock_mgmt_io(phba);
  1035. phba->link_state = LPFC_HBA_ERROR;
  1036. return;
  1037. }
  1038. /**
  1039. * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
  1040. * @phba: pointer to lpfc hba data structure.
  1041. *
  1042. * This routine is called to bring a SLI4 HBA offline when HBA hardware error
  1043. * other than Port Error 6 has been detected.
  1044. **/
  1045. static void
  1046. lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
  1047. {
  1048. lpfc_offline_prep(phba);
  1049. lpfc_offline(phba);
  1050. lpfc_sli4_brdreset(phba);
  1051. lpfc_hba_down_post(phba);
  1052. lpfc_sli4_post_status_check(phba);
  1053. lpfc_unblock_mgmt_io(phba);
  1054. phba->link_state = LPFC_HBA_ERROR;
  1055. }
  1056. /**
  1057. * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
  1058. * @phba: pointer to lpfc hba data structure.
  1059. *
  1060. * This routine is invoked to handle the deferred HBA hardware error
  1061. * conditions. This type of error is indicated by HBA by setting ER1
  1062. * and another ER bit in the host status register. The driver will
  1063. * wait until the ER1 bit clears before handling the error condition.
  1064. **/
  1065. static void
  1066. lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
  1067. {
  1068. uint32_t old_host_status = phba->work_hs;
  1069. struct lpfc_sli_ring *pring;
  1070. struct lpfc_sli *psli = &phba->sli;
  1071. /* If the pci channel is offline, ignore possible errors,
  1072. * since we cannot communicate with the pci card anyway.
  1073. */
  1074. if (pci_channel_offline(phba->pcidev)) {
  1075. spin_lock_irq(&phba->hbalock);
  1076. phba->hba_flag &= ~DEFER_ERATT;
  1077. spin_unlock_irq(&phba->hbalock);
  1078. return;
  1079. }
  1080. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1081. "0479 Deferred Adapter Hardware Error "
  1082. "Data: x%x x%x x%x\n",
  1083. phba->work_hs,
  1084. phba->work_status[0], phba->work_status[1]);
  1085. spin_lock_irq(&phba->hbalock);
  1086. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1087. spin_unlock_irq(&phba->hbalock);
  1088. /*
  1089. * Firmware stops when it triggred erratt. That could cause the I/Os
  1090. * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
  1091. * SCSI layer retry it after re-establishing link.
  1092. */
  1093. pring = &psli->ring[psli->fcp_ring];
  1094. lpfc_sli_abort_iocb_ring(phba, pring);
  1095. /*
  1096. * There was a firmware error. Take the hba offline and then
  1097. * attempt to restart it.
  1098. */
  1099. lpfc_offline_prep(phba);
  1100. lpfc_offline(phba);
  1101. /* Wait for the ER1 bit to clear.*/
  1102. while (phba->work_hs & HS_FFER1) {
  1103. msleep(100);
  1104. phba->work_hs = readl(phba->HSregaddr);
  1105. /* If driver is unloading let the worker thread continue */
  1106. if (phba->pport->load_flag & FC_UNLOADING) {
  1107. phba->work_hs = 0;
  1108. break;
  1109. }
  1110. }
  1111. /*
  1112. * This is to ptrotect against a race condition in which
  1113. * first write to the host attention register clear the
  1114. * host status register.
  1115. */
  1116. if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
  1117. phba->work_hs = old_host_status & ~HS_FFER1;
  1118. spin_lock_irq(&phba->hbalock);
  1119. phba->hba_flag &= ~DEFER_ERATT;
  1120. spin_unlock_irq(&phba->hbalock);
  1121. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  1122. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  1123. }
  1124. static void
  1125. lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
  1126. {
  1127. struct lpfc_board_event_header board_event;
  1128. struct Scsi_Host *shost;
  1129. board_event.event_type = FC_REG_BOARD_EVENT;
  1130. board_event.subcategory = LPFC_EVENT_PORTINTERR;
  1131. shost = lpfc_shost_from_vport(phba->pport);
  1132. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1133. sizeof(board_event),
  1134. (char *) &board_event,
  1135. LPFC_NL_VENDOR_ID);
  1136. }
  1137. /**
  1138. * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
  1139. * @phba: pointer to lpfc hba data structure.
  1140. *
  1141. * This routine is invoked to handle the following HBA hardware error
  1142. * conditions:
  1143. * 1 - HBA error attention interrupt
  1144. * 2 - DMA ring index out of range
  1145. * 3 - Mailbox command came back as unknown
  1146. **/
  1147. static void
  1148. lpfc_handle_eratt_s3(struct lpfc_hba *phba)
  1149. {
  1150. struct lpfc_vport *vport = phba->pport;
  1151. struct lpfc_sli *psli = &phba->sli;
  1152. struct lpfc_sli_ring *pring;
  1153. uint32_t event_data;
  1154. unsigned long temperature;
  1155. struct temp_event temp_event_data;
  1156. struct Scsi_Host *shost;
  1157. /* If the pci channel is offline, ignore possible errors,
  1158. * since we cannot communicate with the pci card anyway.
  1159. */
  1160. if (pci_channel_offline(phba->pcidev)) {
  1161. spin_lock_irq(&phba->hbalock);
  1162. phba->hba_flag &= ~DEFER_ERATT;
  1163. spin_unlock_irq(&phba->hbalock);
  1164. return;
  1165. }
  1166. /* If resets are disabled then leave the HBA alone and return */
  1167. if (!phba->cfg_enable_hba_reset)
  1168. return;
  1169. /* Send an internal error event to mgmt application */
  1170. lpfc_board_errevt_to_mgmt(phba);
  1171. if (phba->hba_flag & DEFER_ERATT)
  1172. lpfc_handle_deferred_eratt(phba);
  1173. if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
  1174. if (phba->work_hs & HS_FFER6)
  1175. /* Re-establishing Link */
  1176. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1177. "1301 Re-establishing Link "
  1178. "Data: x%x x%x x%x\n",
  1179. phba->work_hs, phba->work_status[0],
  1180. phba->work_status[1]);
  1181. if (phba->work_hs & HS_FFER8)
  1182. /* Device Zeroization */
  1183. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1184. "2861 Host Authentication device "
  1185. "zeroization Data:x%x x%x x%x\n",
  1186. phba->work_hs, phba->work_status[0],
  1187. phba->work_status[1]);
  1188. spin_lock_irq(&phba->hbalock);
  1189. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1190. spin_unlock_irq(&phba->hbalock);
  1191. /*
  1192. * Firmware stops when it triggled erratt with HS_FFER6.
  1193. * That could cause the I/Os dropped by the firmware.
  1194. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1195. * retry it after re-establishing link.
  1196. */
  1197. pring = &psli->ring[psli->fcp_ring];
  1198. lpfc_sli_abort_iocb_ring(phba, pring);
  1199. /*
  1200. * There was a firmware error. Take the hba offline and then
  1201. * attempt to restart it.
  1202. */
  1203. lpfc_offline_prep(phba);
  1204. lpfc_offline(phba);
  1205. lpfc_sli_brdrestart(phba);
  1206. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  1207. lpfc_unblock_mgmt_io(phba);
  1208. return;
  1209. }
  1210. lpfc_unblock_mgmt_io(phba);
  1211. } else if (phba->work_hs & HS_CRIT_TEMP) {
  1212. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  1213. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  1214. temp_event_data.event_code = LPFC_CRIT_TEMP;
  1215. temp_event_data.data = (uint32_t)temperature;
  1216. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1217. "0406 Adapter maximum temperature exceeded "
  1218. "(%ld), taking this port offline "
  1219. "Data: x%x x%x x%x\n",
  1220. temperature, phba->work_hs,
  1221. phba->work_status[0], phba->work_status[1]);
  1222. shost = lpfc_shost_from_vport(phba->pport);
  1223. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1224. sizeof(temp_event_data),
  1225. (char *) &temp_event_data,
  1226. SCSI_NL_VID_TYPE_PCI
  1227. | PCI_VENDOR_ID_EMULEX);
  1228. spin_lock_irq(&phba->hbalock);
  1229. phba->over_temp_state = HBA_OVER_TEMP;
  1230. spin_unlock_irq(&phba->hbalock);
  1231. lpfc_offline_eratt(phba);
  1232. } else {
  1233. /* The if clause above forces this code path when the status
  1234. * failure is a value other than FFER6. Do not call the offline
  1235. * twice. This is the adapter hardware error path.
  1236. */
  1237. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1238. "0457 Adapter Hardware Error "
  1239. "Data: x%x x%x x%x\n",
  1240. phba->work_hs,
  1241. phba->work_status[0], phba->work_status[1]);
  1242. event_data = FC_REG_DUMP_EVENT;
  1243. shost = lpfc_shost_from_vport(vport);
  1244. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1245. sizeof(event_data), (char *) &event_data,
  1246. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1247. lpfc_offline_eratt(phba);
  1248. }
  1249. return;
  1250. }
  1251. /**
  1252. * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
  1253. * @phba: pointer to lpfc hba data structure.
  1254. *
  1255. * This routine is invoked to handle the SLI4 HBA hardware error attention
  1256. * conditions.
  1257. **/
  1258. static void
  1259. lpfc_handle_eratt_s4(struct lpfc_hba *phba)
  1260. {
  1261. struct lpfc_vport *vport = phba->pport;
  1262. uint32_t event_data;
  1263. struct Scsi_Host *shost;
  1264. uint32_t if_type;
  1265. struct lpfc_register portstat_reg;
  1266. /* If the pci channel is offline, ignore possible errors, since
  1267. * we cannot communicate with the pci card anyway.
  1268. */
  1269. if (pci_channel_offline(phba->pcidev))
  1270. return;
  1271. /* If resets are disabled then leave the HBA alone and return */
  1272. if (!phba->cfg_enable_hba_reset)
  1273. return;
  1274. /* Send an internal error event to mgmt application */
  1275. lpfc_board_errevt_to_mgmt(phba);
  1276. /* For now, the actual action for SLI4 device handling is not
  1277. * specified yet, just treated it as adaptor hardware failure
  1278. */
  1279. event_data = FC_REG_DUMP_EVENT;
  1280. shost = lpfc_shost_from_vport(vport);
  1281. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1282. sizeof(event_data), (char *) &event_data,
  1283. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1284. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  1285. switch (if_type) {
  1286. case LPFC_SLI_INTF_IF_TYPE_0:
  1287. lpfc_sli4_offline_eratt(phba);
  1288. break;
  1289. case LPFC_SLI_INTF_IF_TYPE_2:
  1290. portstat_reg.word0 =
  1291. readl(phba->sli4_hba.u.if_type2.STATUSregaddr);
  1292. if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
  1293. /* TODO: Register for Overtemp async events. */
  1294. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1295. "2889 Port Overtemperature event, "
  1296. "taking port\n");
  1297. spin_lock_irq(&phba->hbalock);
  1298. phba->over_temp_state = HBA_OVER_TEMP;
  1299. spin_unlock_irq(&phba->hbalock);
  1300. lpfc_sli4_offline_eratt(phba);
  1301. return;
  1302. }
  1303. if (bf_get(lpfc_sliport_status_rn, &portstat_reg)) {
  1304. /*
  1305. * TODO: Attempt port recovery via a port reset.
  1306. * When fully implemented, the driver should
  1307. * attempt to recover the port here and return.
  1308. * For now, log an error and take the port offline.
  1309. */
  1310. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1311. "2887 Port Error: Attempting "
  1312. "Port Recovery\n");
  1313. }
  1314. lpfc_sli4_offline_eratt(phba);
  1315. break;
  1316. case LPFC_SLI_INTF_IF_TYPE_1:
  1317. default:
  1318. break;
  1319. }
  1320. }
  1321. /**
  1322. * lpfc_handle_eratt - Wrapper func for handling hba error attention
  1323. * @phba: pointer to lpfc HBA data structure.
  1324. *
  1325. * This routine wraps the actual SLI3 or SLI4 hba error attention handling
  1326. * routine from the API jump table function pointer from the lpfc_hba struct.
  1327. *
  1328. * Return codes
  1329. * 0 - success.
  1330. * Any other value - error.
  1331. **/
  1332. void
  1333. lpfc_handle_eratt(struct lpfc_hba *phba)
  1334. {
  1335. (*phba->lpfc_handle_eratt)(phba);
  1336. }
  1337. /**
  1338. * lpfc_handle_latt - The HBA link event handler
  1339. * @phba: pointer to lpfc hba data structure.
  1340. *
  1341. * This routine is invoked from the worker thread to handle a HBA host
  1342. * attention link event.
  1343. **/
  1344. void
  1345. lpfc_handle_latt(struct lpfc_hba *phba)
  1346. {
  1347. struct lpfc_vport *vport = phba->pport;
  1348. struct lpfc_sli *psli = &phba->sli;
  1349. LPFC_MBOXQ_t *pmb;
  1350. volatile uint32_t control;
  1351. struct lpfc_dmabuf *mp;
  1352. int rc = 0;
  1353. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1354. if (!pmb) {
  1355. rc = 1;
  1356. goto lpfc_handle_latt_err_exit;
  1357. }
  1358. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1359. if (!mp) {
  1360. rc = 2;
  1361. goto lpfc_handle_latt_free_pmb;
  1362. }
  1363. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  1364. if (!mp->virt) {
  1365. rc = 3;
  1366. goto lpfc_handle_latt_free_mp;
  1367. }
  1368. /* Cleanup any outstanding ELS commands */
  1369. lpfc_els_flush_all_cmd(phba);
  1370. psli->slistat.link_event++;
  1371. lpfc_read_topology(phba, pmb, mp);
  1372. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  1373. pmb->vport = vport;
  1374. /* Block ELS IOCBs until we have processed this mbox command */
  1375. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  1376. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  1377. if (rc == MBX_NOT_FINISHED) {
  1378. rc = 4;
  1379. goto lpfc_handle_latt_free_mbuf;
  1380. }
  1381. /* Clear Link Attention in HA REG */
  1382. spin_lock_irq(&phba->hbalock);
  1383. writel(HA_LATT, phba->HAregaddr);
  1384. readl(phba->HAregaddr); /* flush */
  1385. spin_unlock_irq(&phba->hbalock);
  1386. return;
  1387. lpfc_handle_latt_free_mbuf:
  1388. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  1389. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1390. lpfc_handle_latt_free_mp:
  1391. kfree(mp);
  1392. lpfc_handle_latt_free_pmb:
  1393. mempool_free(pmb, phba->mbox_mem_pool);
  1394. lpfc_handle_latt_err_exit:
  1395. /* Enable Link attention interrupts */
  1396. spin_lock_irq(&phba->hbalock);
  1397. psli->sli_flag |= LPFC_PROCESS_LA;
  1398. control = readl(phba->HCregaddr);
  1399. control |= HC_LAINT_ENA;
  1400. writel(control, phba->HCregaddr);
  1401. readl(phba->HCregaddr); /* flush */
  1402. /* Clear Link Attention in HA REG */
  1403. writel(HA_LATT, phba->HAregaddr);
  1404. readl(phba->HAregaddr); /* flush */
  1405. spin_unlock_irq(&phba->hbalock);
  1406. lpfc_linkdown(phba);
  1407. phba->link_state = LPFC_HBA_ERROR;
  1408. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1409. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  1410. return;
  1411. }
  1412. /**
  1413. * lpfc_parse_vpd - Parse VPD (Vital Product Data)
  1414. * @phba: pointer to lpfc hba data structure.
  1415. * @vpd: pointer to the vital product data.
  1416. * @len: length of the vital product data in bytes.
  1417. *
  1418. * This routine parses the Vital Product Data (VPD). The VPD is treated as
  1419. * an array of characters. In this routine, the ModelName, ProgramType, and
  1420. * ModelDesc, etc. fields of the phba data structure will be populated.
  1421. *
  1422. * Return codes
  1423. * 0 - pointer to the VPD passed in is NULL
  1424. * 1 - success
  1425. **/
  1426. int
  1427. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  1428. {
  1429. uint8_t lenlo, lenhi;
  1430. int Length;
  1431. int i, j;
  1432. int finished = 0;
  1433. int index = 0;
  1434. if (!vpd)
  1435. return 0;
  1436. /* Vital Product */
  1437. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1438. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  1439. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  1440. (uint32_t) vpd[3]);
  1441. while (!finished && (index < (len - 4))) {
  1442. switch (vpd[index]) {
  1443. case 0x82:
  1444. case 0x91:
  1445. index += 1;
  1446. lenlo = vpd[index];
  1447. index += 1;
  1448. lenhi = vpd[index];
  1449. index += 1;
  1450. i = ((((unsigned short)lenhi) << 8) + lenlo);
  1451. index += i;
  1452. break;
  1453. case 0x90:
  1454. index += 1;
  1455. lenlo = vpd[index];
  1456. index += 1;
  1457. lenhi = vpd[index];
  1458. index += 1;
  1459. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  1460. if (Length > len - index)
  1461. Length = len - index;
  1462. while (Length > 0) {
  1463. /* Look for Serial Number */
  1464. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  1465. index += 2;
  1466. i = vpd[index];
  1467. index += 1;
  1468. j = 0;
  1469. Length -= (3+i);
  1470. while(i--) {
  1471. phba->SerialNumber[j++] = vpd[index++];
  1472. if (j == 31)
  1473. break;
  1474. }
  1475. phba->SerialNumber[j] = 0;
  1476. continue;
  1477. }
  1478. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  1479. phba->vpd_flag |= VPD_MODEL_DESC;
  1480. index += 2;
  1481. i = vpd[index];
  1482. index += 1;
  1483. j = 0;
  1484. Length -= (3+i);
  1485. while(i--) {
  1486. phba->ModelDesc[j++] = vpd[index++];
  1487. if (j == 255)
  1488. break;
  1489. }
  1490. phba->ModelDesc[j] = 0;
  1491. continue;
  1492. }
  1493. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  1494. phba->vpd_flag |= VPD_MODEL_NAME;
  1495. index += 2;
  1496. i = vpd[index];
  1497. index += 1;
  1498. j = 0;
  1499. Length -= (3+i);
  1500. while(i--) {
  1501. phba->ModelName[j++] = vpd[index++];
  1502. if (j == 79)
  1503. break;
  1504. }
  1505. phba->ModelName[j] = 0;
  1506. continue;
  1507. }
  1508. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  1509. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  1510. index += 2;
  1511. i = vpd[index];
  1512. index += 1;
  1513. j = 0;
  1514. Length -= (3+i);
  1515. while(i--) {
  1516. phba->ProgramType[j++] = vpd[index++];
  1517. if (j == 255)
  1518. break;
  1519. }
  1520. phba->ProgramType[j] = 0;
  1521. continue;
  1522. }
  1523. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  1524. phba->vpd_flag |= VPD_PORT;
  1525. index += 2;
  1526. i = vpd[index];
  1527. index += 1;
  1528. j = 0;
  1529. Length -= (3+i);
  1530. while(i--) {
  1531. phba->Port[j++] = vpd[index++];
  1532. if (j == 19)
  1533. break;
  1534. }
  1535. phba->Port[j] = 0;
  1536. continue;
  1537. }
  1538. else {
  1539. index += 2;
  1540. i = vpd[index];
  1541. index += 1;
  1542. index += i;
  1543. Length -= (3 + i);
  1544. }
  1545. }
  1546. finished = 0;
  1547. break;
  1548. case 0x78:
  1549. finished = 1;
  1550. break;
  1551. default:
  1552. index ++;
  1553. break;
  1554. }
  1555. }
  1556. return(1);
  1557. }
  1558. /**
  1559. * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
  1560. * @phba: pointer to lpfc hba data structure.
  1561. * @mdp: pointer to the data structure to hold the derived model name.
  1562. * @descp: pointer to the data structure to hold the derived description.
  1563. *
  1564. * This routine retrieves HBA's description based on its registered PCI device
  1565. * ID. The @descp passed into this function points to an array of 256 chars. It
  1566. * shall be returned with the model name, maximum speed, and the host bus type.
  1567. * The @mdp passed into this function points to an array of 80 chars. When the
  1568. * function returns, the @mdp will be filled with the model name.
  1569. **/
  1570. static void
  1571. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  1572. {
  1573. lpfc_vpd_t *vp;
  1574. uint16_t dev_id = phba->pcidev->device;
  1575. int max_speed;
  1576. int GE = 0;
  1577. int oneConnect = 0; /* default is not a oneConnect */
  1578. struct {
  1579. char *name;
  1580. char *bus;
  1581. char *function;
  1582. } m = {"<Unknown>", "", ""};
  1583. if (mdp && mdp[0] != '\0'
  1584. && descp && descp[0] != '\0')
  1585. return;
  1586. if (phba->lmt & LMT_10Gb)
  1587. max_speed = 10;
  1588. else if (phba->lmt & LMT_8Gb)
  1589. max_speed = 8;
  1590. else if (phba->lmt & LMT_4Gb)
  1591. max_speed = 4;
  1592. else if (phba->lmt & LMT_2Gb)
  1593. max_speed = 2;
  1594. else
  1595. max_speed = 1;
  1596. vp = &phba->vpd;
  1597. switch (dev_id) {
  1598. case PCI_DEVICE_ID_FIREFLY:
  1599. m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"};
  1600. break;
  1601. case PCI_DEVICE_ID_SUPERFLY:
  1602. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  1603. m = (typeof(m)){"LP7000", "PCI",
  1604. "Fibre Channel Adapter"};
  1605. else
  1606. m = (typeof(m)){"LP7000E", "PCI",
  1607. "Fibre Channel Adapter"};
  1608. break;
  1609. case PCI_DEVICE_ID_DRAGONFLY:
  1610. m = (typeof(m)){"LP8000", "PCI",
  1611. "Fibre Channel Adapter"};
  1612. break;
  1613. case PCI_DEVICE_ID_CENTAUR:
  1614. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  1615. m = (typeof(m)){"LP9002", "PCI",
  1616. "Fibre Channel Adapter"};
  1617. else
  1618. m = (typeof(m)){"LP9000", "PCI",
  1619. "Fibre Channel Adapter"};
  1620. break;
  1621. case PCI_DEVICE_ID_RFLY:
  1622. m = (typeof(m)){"LP952", "PCI",
  1623. "Fibre Channel Adapter"};
  1624. break;
  1625. case PCI_DEVICE_ID_PEGASUS:
  1626. m = (typeof(m)){"LP9802", "PCI-X",
  1627. "Fibre Channel Adapter"};
  1628. break;
  1629. case PCI_DEVICE_ID_THOR:
  1630. m = (typeof(m)){"LP10000", "PCI-X",
  1631. "Fibre Channel Adapter"};
  1632. break;
  1633. case PCI_DEVICE_ID_VIPER:
  1634. m = (typeof(m)){"LPX1000", "PCI-X",
  1635. "Fibre Channel Adapter"};
  1636. break;
  1637. case PCI_DEVICE_ID_PFLY:
  1638. m = (typeof(m)){"LP982", "PCI-X",
  1639. "Fibre Channel Adapter"};
  1640. break;
  1641. case PCI_DEVICE_ID_TFLY:
  1642. m = (typeof(m)){"LP1050", "PCI-X",
  1643. "Fibre Channel Adapter"};
  1644. break;
  1645. case PCI_DEVICE_ID_HELIOS:
  1646. m = (typeof(m)){"LP11000", "PCI-X2",
  1647. "Fibre Channel Adapter"};
  1648. break;
  1649. case PCI_DEVICE_ID_HELIOS_SCSP:
  1650. m = (typeof(m)){"LP11000-SP", "PCI-X2",
  1651. "Fibre Channel Adapter"};
  1652. break;
  1653. case PCI_DEVICE_ID_HELIOS_DCSP:
  1654. m = (typeof(m)){"LP11002-SP", "PCI-X2",
  1655. "Fibre Channel Adapter"};
  1656. break;
  1657. case PCI_DEVICE_ID_NEPTUNE:
  1658. m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
  1659. break;
  1660. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  1661. m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
  1662. break;
  1663. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  1664. m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
  1665. break;
  1666. case PCI_DEVICE_ID_BMID:
  1667. m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
  1668. break;
  1669. case PCI_DEVICE_ID_BSMB:
  1670. m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
  1671. break;
  1672. case PCI_DEVICE_ID_ZEPHYR:
  1673. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  1674. break;
  1675. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  1676. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  1677. break;
  1678. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  1679. m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
  1680. GE = 1;
  1681. break;
  1682. case PCI_DEVICE_ID_ZMID:
  1683. m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
  1684. break;
  1685. case PCI_DEVICE_ID_ZSMB:
  1686. m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
  1687. break;
  1688. case PCI_DEVICE_ID_LP101:
  1689. m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"};
  1690. break;
  1691. case PCI_DEVICE_ID_LP10000S:
  1692. m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
  1693. break;
  1694. case PCI_DEVICE_ID_LP11000S:
  1695. m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
  1696. break;
  1697. case PCI_DEVICE_ID_LPE11000S:
  1698. m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
  1699. break;
  1700. case PCI_DEVICE_ID_SAT:
  1701. m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
  1702. break;
  1703. case PCI_DEVICE_ID_SAT_MID:
  1704. m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
  1705. break;
  1706. case PCI_DEVICE_ID_SAT_SMB:
  1707. m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
  1708. break;
  1709. case PCI_DEVICE_ID_SAT_DCSP:
  1710. m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
  1711. break;
  1712. case PCI_DEVICE_ID_SAT_SCSP:
  1713. m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
  1714. break;
  1715. case PCI_DEVICE_ID_SAT_S:
  1716. m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
  1717. break;
  1718. case PCI_DEVICE_ID_HORNET:
  1719. m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"};
  1720. GE = 1;
  1721. break;
  1722. case PCI_DEVICE_ID_PROTEUS_VF:
  1723. m = (typeof(m)){"LPev12000", "PCIe IOV",
  1724. "Fibre Channel Adapter"};
  1725. break;
  1726. case PCI_DEVICE_ID_PROTEUS_PF:
  1727. m = (typeof(m)){"LPev12000", "PCIe IOV",
  1728. "Fibre Channel Adapter"};
  1729. break;
  1730. case PCI_DEVICE_ID_PROTEUS_S:
  1731. m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
  1732. "Fibre Channel Adapter"};
  1733. break;
  1734. case PCI_DEVICE_ID_TIGERSHARK:
  1735. oneConnect = 1;
  1736. m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
  1737. break;
  1738. case PCI_DEVICE_ID_TOMCAT:
  1739. oneConnect = 1;
  1740. m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
  1741. break;
  1742. case PCI_DEVICE_ID_FALCON:
  1743. m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
  1744. "EmulexSecure Fibre"};
  1745. break;
  1746. case PCI_DEVICE_ID_BALIUS:
  1747. m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
  1748. "Fibre Channel Adapter"};
  1749. break;
  1750. case PCI_DEVICE_ID_LANCER_FC:
  1751. oneConnect = 1;
  1752. m = (typeof(m)){"Undefined", "PCIe", "Fibre Channel Adapter"};
  1753. break;
  1754. case PCI_DEVICE_ID_LANCER_FCOE:
  1755. oneConnect = 1;
  1756. m = (typeof(m)){"Undefined", "PCIe", "FCoE"};
  1757. break;
  1758. default:
  1759. m = (typeof(m)){"Unknown", "", ""};
  1760. break;
  1761. }
  1762. if (mdp && mdp[0] == '\0')
  1763. snprintf(mdp, 79,"%s", m.name);
  1764. /* oneConnect hba requires special processing, they are all initiators
  1765. * and we put the port number on the end
  1766. */
  1767. if (descp && descp[0] == '\0') {
  1768. if (oneConnect)
  1769. snprintf(descp, 255,
  1770. "Emulex OneConnect %s, %s Initiator, Port %s",
  1771. m.name, m.function,
  1772. phba->Port);
  1773. else
  1774. snprintf(descp, 255,
  1775. "Emulex %s %d%s %s %s",
  1776. m.name, max_speed, (GE) ? "GE" : "Gb",
  1777. m.bus, m.function);
  1778. }
  1779. }
  1780. /**
  1781. * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
  1782. * @phba: pointer to lpfc hba data structure.
  1783. * @pring: pointer to a IOCB ring.
  1784. * @cnt: the number of IOCBs to be posted to the IOCB ring.
  1785. *
  1786. * This routine posts a given number of IOCBs with the associated DMA buffer
  1787. * descriptors specified by the cnt argument to the given IOCB ring.
  1788. *
  1789. * Return codes
  1790. * The number of IOCBs NOT able to be posted to the IOCB ring.
  1791. **/
  1792. int
  1793. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
  1794. {
  1795. IOCB_t *icmd;
  1796. struct lpfc_iocbq *iocb;
  1797. struct lpfc_dmabuf *mp1, *mp2;
  1798. cnt += pring->missbufcnt;
  1799. /* While there are buffers to post */
  1800. while (cnt > 0) {
  1801. /* Allocate buffer for command iocb */
  1802. iocb = lpfc_sli_get_iocbq(phba);
  1803. if (iocb == NULL) {
  1804. pring->missbufcnt = cnt;
  1805. return cnt;
  1806. }
  1807. icmd = &iocb->iocb;
  1808. /* 2 buffers can be posted per command */
  1809. /* Allocate buffer to post */
  1810. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1811. if (mp1)
  1812. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  1813. if (!mp1 || !mp1->virt) {
  1814. kfree(mp1);
  1815. lpfc_sli_release_iocbq(phba, iocb);
  1816. pring->missbufcnt = cnt;
  1817. return cnt;
  1818. }
  1819. INIT_LIST_HEAD(&mp1->list);
  1820. /* Allocate buffer to post */
  1821. if (cnt > 1) {
  1822. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1823. if (mp2)
  1824. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  1825. &mp2->phys);
  1826. if (!mp2 || !mp2->virt) {
  1827. kfree(mp2);
  1828. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1829. kfree(mp1);
  1830. lpfc_sli_release_iocbq(phba, iocb);
  1831. pring->missbufcnt = cnt;
  1832. return cnt;
  1833. }
  1834. INIT_LIST_HEAD(&mp2->list);
  1835. } else {
  1836. mp2 = NULL;
  1837. }
  1838. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  1839. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  1840. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  1841. icmd->ulpBdeCount = 1;
  1842. cnt--;
  1843. if (mp2) {
  1844. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  1845. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  1846. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  1847. cnt--;
  1848. icmd->ulpBdeCount = 2;
  1849. }
  1850. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  1851. icmd->ulpLe = 1;
  1852. if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
  1853. IOCB_ERROR) {
  1854. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1855. kfree(mp1);
  1856. cnt++;
  1857. if (mp2) {
  1858. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  1859. kfree(mp2);
  1860. cnt++;
  1861. }
  1862. lpfc_sli_release_iocbq(phba, iocb);
  1863. pring->missbufcnt = cnt;
  1864. return cnt;
  1865. }
  1866. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  1867. if (mp2)
  1868. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  1869. }
  1870. pring->missbufcnt = 0;
  1871. return 0;
  1872. }
  1873. /**
  1874. * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
  1875. * @phba: pointer to lpfc hba data structure.
  1876. *
  1877. * This routine posts initial receive IOCB buffers to the ELS ring. The
  1878. * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
  1879. * set to 64 IOCBs.
  1880. *
  1881. * Return codes
  1882. * 0 - success (currently always success)
  1883. **/
  1884. static int
  1885. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  1886. {
  1887. struct lpfc_sli *psli = &phba->sli;
  1888. /* Ring 0, ELS / CT buffers */
  1889. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
  1890. /* Ring 2 - FCP no buffers needed */
  1891. return 0;
  1892. }
  1893. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  1894. /**
  1895. * lpfc_sha_init - Set up initial array of hash table entries
  1896. * @HashResultPointer: pointer to an array as hash table.
  1897. *
  1898. * This routine sets up the initial values to the array of hash table entries
  1899. * for the LC HBAs.
  1900. **/
  1901. static void
  1902. lpfc_sha_init(uint32_t * HashResultPointer)
  1903. {
  1904. HashResultPointer[0] = 0x67452301;
  1905. HashResultPointer[1] = 0xEFCDAB89;
  1906. HashResultPointer[2] = 0x98BADCFE;
  1907. HashResultPointer[3] = 0x10325476;
  1908. HashResultPointer[4] = 0xC3D2E1F0;
  1909. }
  1910. /**
  1911. * lpfc_sha_iterate - Iterate initial hash table with the working hash table
  1912. * @HashResultPointer: pointer to an initial/result hash table.
  1913. * @HashWorkingPointer: pointer to an working hash table.
  1914. *
  1915. * This routine iterates an initial hash table pointed by @HashResultPointer
  1916. * with the values from the working hash table pointeed by @HashWorkingPointer.
  1917. * The results are putting back to the initial hash table, returned through
  1918. * the @HashResultPointer as the result hash table.
  1919. **/
  1920. static void
  1921. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  1922. {
  1923. int t;
  1924. uint32_t TEMP;
  1925. uint32_t A, B, C, D, E;
  1926. t = 16;
  1927. do {
  1928. HashWorkingPointer[t] =
  1929. S(1,
  1930. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  1931. 8] ^
  1932. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  1933. } while (++t <= 79);
  1934. t = 0;
  1935. A = HashResultPointer[0];
  1936. B = HashResultPointer[1];
  1937. C = HashResultPointer[2];
  1938. D = HashResultPointer[3];
  1939. E = HashResultPointer[4];
  1940. do {
  1941. if (t < 20) {
  1942. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  1943. } else if (t < 40) {
  1944. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  1945. } else if (t < 60) {
  1946. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  1947. } else {
  1948. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  1949. }
  1950. TEMP += S(5, A) + E + HashWorkingPointer[t];
  1951. E = D;
  1952. D = C;
  1953. C = S(30, B);
  1954. B = A;
  1955. A = TEMP;
  1956. } while (++t <= 79);
  1957. HashResultPointer[0] += A;
  1958. HashResultPointer[1] += B;
  1959. HashResultPointer[2] += C;
  1960. HashResultPointer[3] += D;
  1961. HashResultPointer[4] += E;
  1962. }
  1963. /**
  1964. * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
  1965. * @RandomChallenge: pointer to the entry of host challenge random number array.
  1966. * @HashWorking: pointer to the entry of the working hash array.
  1967. *
  1968. * This routine calculates the working hash array referred by @HashWorking
  1969. * from the challenge random numbers associated with the host, referred by
  1970. * @RandomChallenge. The result is put into the entry of the working hash
  1971. * array and returned by reference through @HashWorking.
  1972. **/
  1973. static void
  1974. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1975. {
  1976. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1977. }
  1978. /**
  1979. * lpfc_hba_init - Perform special handling for LC HBA initialization
  1980. * @phba: pointer to lpfc hba data structure.
  1981. * @hbainit: pointer to an array of unsigned 32-bit integers.
  1982. *
  1983. * This routine performs the special handling for LC HBA initialization.
  1984. **/
  1985. void
  1986. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1987. {
  1988. int t;
  1989. uint32_t *HashWorking;
  1990. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  1991. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  1992. if (!HashWorking)
  1993. return;
  1994. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1995. HashWorking[1] = HashWorking[79] = *pwwnn;
  1996. for (t = 0; t < 7; t++)
  1997. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1998. lpfc_sha_init(hbainit);
  1999. lpfc_sha_iterate(hbainit, HashWorking);
  2000. kfree(HashWorking);
  2001. }
  2002. /**
  2003. * lpfc_cleanup - Performs vport cleanups before deleting a vport
  2004. * @vport: pointer to a virtual N_Port data structure.
  2005. *
  2006. * This routine performs the necessary cleanups before deleting the @vport.
  2007. * It invokes the discovery state machine to perform necessary state
  2008. * transitions and to release the ndlps associated with the @vport. Note,
  2009. * the physical port is treated as @vport 0.
  2010. **/
  2011. void
  2012. lpfc_cleanup(struct lpfc_vport *vport)
  2013. {
  2014. struct lpfc_hba *phba = vport->phba;
  2015. struct lpfc_nodelist *ndlp, *next_ndlp;
  2016. int i = 0;
  2017. if (phba->link_state > LPFC_LINK_DOWN)
  2018. lpfc_port_link_failure(vport);
  2019. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2020. if (!NLP_CHK_NODE_ACT(ndlp)) {
  2021. ndlp = lpfc_enable_node(vport, ndlp,
  2022. NLP_STE_UNUSED_NODE);
  2023. if (!ndlp)
  2024. continue;
  2025. spin_lock_irq(&phba->ndlp_lock);
  2026. NLP_SET_FREE_REQ(ndlp);
  2027. spin_unlock_irq(&phba->ndlp_lock);
  2028. /* Trigger the release of the ndlp memory */
  2029. lpfc_nlp_put(ndlp);
  2030. continue;
  2031. }
  2032. spin_lock_irq(&phba->ndlp_lock);
  2033. if (NLP_CHK_FREE_REQ(ndlp)) {
  2034. /* The ndlp should not be in memory free mode already */
  2035. spin_unlock_irq(&phba->ndlp_lock);
  2036. continue;
  2037. } else
  2038. /* Indicate request for freeing ndlp memory */
  2039. NLP_SET_FREE_REQ(ndlp);
  2040. spin_unlock_irq(&phba->ndlp_lock);
  2041. if (vport->port_type != LPFC_PHYSICAL_PORT &&
  2042. ndlp->nlp_DID == Fabric_DID) {
  2043. /* Just free up ndlp with Fabric_DID for vports */
  2044. lpfc_nlp_put(ndlp);
  2045. continue;
  2046. }
  2047. if (ndlp->nlp_type & NLP_FABRIC)
  2048. lpfc_disc_state_machine(vport, ndlp, NULL,
  2049. NLP_EVT_DEVICE_RECOVERY);
  2050. lpfc_disc_state_machine(vport, ndlp, NULL,
  2051. NLP_EVT_DEVICE_RM);
  2052. }
  2053. /* At this point, ALL ndlp's should be gone
  2054. * because of the previous NLP_EVT_DEVICE_RM.
  2055. * Lets wait for this to happen, if needed.
  2056. */
  2057. while (!list_empty(&vport->fc_nodes)) {
  2058. if (i++ > 3000) {
  2059. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2060. "0233 Nodelist not empty\n");
  2061. list_for_each_entry_safe(ndlp, next_ndlp,
  2062. &vport->fc_nodes, nlp_listp) {
  2063. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  2064. LOG_NODE,
  2065. "0282 did:x%x ndlp:x%p "
  2066. "usgmap:x%x refcnt:%d\n",
  2067. ndlp->nlp_DID, (void *)ndlp,
  2068. ndlp->nlp_usg_map,
  2069. atomic_read(
  2070. &ndlp->kref.refcount));
  2071. }
  2072. break;
  2073. }
  2074. /* Wait for any activity on ndlps to settle */
  2075. msleep(10);
  2076. }
  2077. }
  2078. /**
  2079. * lpfc_stop_vport_timers - Stop all the timers associated with a vport
  2080. * @vport: pointer to a virtual N_Port data structure.
  2081. *
  2082. * This routine stops all the timers associated with a @vport. This function
  2083. * is invoked before disabling or deleting a @vport. Note that the physical
  2084. * port is treated as @vport 0.
  2085. **/
  2086. void
  2087. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  2088. {
  2089. del_timer_sync(&vport->els_tmofunc);
  2090. del_timer_sync(&vport->fc_fdmitmo);
  2091. lpfc_can_disctmo(vport);
  2092. return;
  2093. }
  2094. /**
  2095. * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
  2096. * @phba: pointer to lpfc hba data structure.
  2097. *
  2098. * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
  2099. * caller of this routine should already hold the host lock.
  2100. **/
  2101. void
  2102. __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
  2103. {
  2104. /* Clear pending FCF rediscovery wait flag */
  2105. phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
  2106. /* Now, try to stop the timer */
  2107. del_timer(&phba->fcf.redisc_wait);
  2108. }
  2109. /**
  2110. * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
  2111. * @phba: pointer to lpfc hba data structure.
  2112. *
  2113. * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
  2114. * checks whether the FCF rediscovery wait timer is pending with the host
  2115. * lock held before proceeding with disabling the timer and clearing the
  2116. * wait timer pendig flag.
  2117. **/
  2118. void
  2119. lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
  2120. {
  2121. spin_lock_irq(&phba->hbalock);
  2122. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
  2123. /* FCF rediscovery timer already fired or stopped */
  2124. spin_unlock_irq(&phba->hbalock);
  2125. return;
  2126. }
  2127. __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
  2128. /* Clear failover in progress flags */
  2129. phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
  2130. spin_unlock_irq(&phba->hbalock);
  2131. }
  2132. /**
  2133. * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
  2134. * @phba: pointer to lpfc hba data structure.
  2135. *
  2136. * This routine stops all the timers associated with a HBA. This function is
  2137. * invoked before either putting a HBA offline or unloading the driver.
  2138. **/
  2139. void
  2140. lpfc_stop_hba_timers(struct lpfc_hba *phba)
  2141. {
  2142. lpfc_stop_vport_timers(phba->pport);
  2143. del_timer_sync(&phba->sli.mbox_tmo);
  2144. del_timer_sync(&phba->fabric_block_timer);
  2145. del_timer_sync(&phba->eratt_poll);
  2146. del_timer_sync(&phba->hb_tmofunc);
  2147. phba->hb_outstanding = 0;
  2148. switch (phba->pci_dev_grp) {
  2149. case LPFC_PCI_DEV_LP:
  2150. /* Stop any LightPulse device specific driver timers */
  2151. del_timer_sync(&phba->fcp_poll_timer);
  2152. break;
  2153. case LPFC_PCI_DEV_OC:
  2154. /* Stop any OneConnect device sepcific driver timers */
  2155. lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
  2156. break;
  2157. default:
  2158. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2159. "0297 Invalid device group (x%x)\n",
  2160. phba->pci_dev_grp);
  2161. break;
  2162. }
  2163. return;
  2164. }
  2165. /**
  2166. * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
  2167. * @phba: pointer to lpfc hba data structure.
  2168. *
  2169. * This routine marks a HBA's management interface as blocked. Once the HBA's
  2170. * management interface is marked as blocked, all the user space access to
  2171. * the HBA, whether they are from sysfs interface or libdfc interface will
  2172. * all be blocked. The HBA is set to block the management interface when the
  2173. * driver prepares the HBA interface for online or offline.
  2174. **/
  2175. static void
  2176. lpfc_block_mgmt_io(struct lpfc_hba * phba)
  2177. {
  2178. unsigned long iflag;
  2179. uint8_t actcmd = MBX_HEARTBEAT;
  2180. unsigned long timeout;
  2181. spin_lock_irqsave(&phba->hbalock, iflag);
  2182. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  2183. if (phba->sli.mbox_active)
  2184. actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
  2185. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2186. /* Determine how long we might wait for the active mailbox
  2187. * command to be gracefully completed by firmware.
  2188. */
  2189. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) +
  2190. jiffies;
  2191. /* Wait for the outstnading mailbox command to complete */
  2192. while (phba->sli.mbox_active) {
  2193. /* Check active mailbox complete status every 2ms */
  2194. msleep(2);
  2195. if (time_after(jiffies, timeout)) {
  2196. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2197. "2813 Mgmt IO is Blocked %x "
  2198. "- mbox cmd %x still active\n",
  2199. phba->sli.sli_flag, actcmd);
  2200. break;
  2201. }
  2202. }
  2203. }
  2204. /**
  2205. * lpfc_online - Initialize and bring a HBA online
  2206. * @phba: pointer to lpfc hba data structure.
  2207. *
  2208. * This routine initializes the HBA and brings a HBA online. During this
  2209. * process, the management interface is blocked to prevent user space access
  2210. * to the HBA interfering with the driver initialization.
  2211. *
  2212. * Return codes
  2213. * 0 - successful
  2214. * 1 - failed
  2215. **/
  2216. int
  2217. lpfc_online(struct lpfc_hba *phba)
  2218. {
  2219. struct lpfc_vport *vport;
  2220. struct lpfc_vport **vports;
  2221. int i;
  2222. if (!phba)
  2223. return 0;
  2224. vport = phba->pport;
  2225. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  2226. return 0;
  2227. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2228. "0458 Bring Adapter online\n");
  2229. lpfc_block_mgmt_io(phba);
  2230. if (!lpfc_sli_queue_setup(phba)) {
  2231. lpfc_unblock_mgmt_io(phba);
  2232. return 1;
  2233. }
  2234. if (phba->sli_rev == LPFC_SLI_REV4) {
  2235. if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
  2236. lpfc_unblock_mgmt_io(phba);
  2237. return 1;
  2238. }
  2239. } else {
  2240. if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
  2241. lpfc_unblock_mgmt_io(phba);
  2242. return 1;
  2243. }
  2244. }
  2245. vports = lpfc_create_vport_work_array(phba);
  2246. if (vports != NULL)
  2247. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2248. struct Scsi_Host *shost;
  2249. shost = lpfc_shost_from_vport(vports[i]);
  2250. spin_lock_irq(shost->host_lock);
  2251. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  2252. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  2253. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2254. if (phba->sli_rev == LPFC_SLI_REV4)
  2255. vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  2256. spin_unlock_irq(shost->host_lock);
  2257. }
  2258. lpfc_destroy_vport_work_array(phba, vports);
  2259. lpfc_unblock_mgmt_io(phba);
  2260. return 0;
  2261. }
  2262. /**
  2263. * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
  2264. * @phba: pointer to lpfc hba data structure.
  2265. *
  2266. * This routine marks a HBA's management interface as not blocked. Once the
  2267. * HBA's management interface is marked as not blocked, all the user space
  2268. * access to the HBA, whether they are from sysfs interface or libdfc
  2269. * interface will be allowed. The HBA is set to block the management interface
  2270. * when the driver prepares the HBA interface for online or offline and then
  2271. * set to unblock the management interface afterwards.
  2272. **/
  2273. void
  2274. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  2275. {
  2276. unsigned long iflag;
  2277. spin_lock_irqsave(&phba->hbalock, iflag);
  2278. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  2279. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2280. }
  2281. /**
  2282. * lpfc_offline_prep - Prepare a HBA to be brought offline
  2283. * @phba: pointer to lpfc hba data structure.
  2284. *
  2285. * This routine is invoked to prepare a HBA to be brought offline. It performs
  2286. * unregistration login to all the nodes on all vports and flushes the mailbox
  2287. * queue to make it ready to be brought offline.
  2288. **/
  2289. void
  2290. lpfc_offline_prep(struct lpfc_hba * phba)
  2291. {
  2292. struct lpfc_vport *vport = phba->pport;
  2293. struct lpfc_nodelist *ndlp, *next_ndlp;
  2294. struct lpfc_vport **vports;
  2295. struct Scsi_Host *shost;
  2296. int i;
  2297. if (vport->fc_flag & FC_OFFLINE_MODE)
  2298. return;
  2299. lpfc_block_mgmt_io(phba);
  2300. lpfc_linkdown(phba);
  2301. /* Issue an unreg_login to all nodes on all vports */
  2302. vports = lpfc_create_vport_work_array(phba);
  2303. if (vports != NULL) {
  2304. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2305. if (vports[i]->load_flag & FC_UNLOADING)
  2306. continue;
  2307. shost = lpfc_shost_from_vport(vports[i]);
  2308. spin_lock_irq(shost->host_lock);
  2309. vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
  2310. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2311. vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
  2312. spin_unlock_irq(shost->host_lock);
  2313. shost = lpfc_shost_from_vport(vports[i]);
  2314. list_for_each_entry_safe(ndlp, next_ndlp,
  2315. &vports[i]->fc_nodes,
  2316. nlp_listp) {
  2317. if (!NLP_CHK_NODE_ACT(ndlp))
  2318. continue;
  2319. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  2320. continue;
  2321. if (ndlp->nlp_type & NLP_FABRIC) {
  2322. lpfc_disc_state_machine(vports[i], ndlp,
  2323. NULL, NLP_EVT_DEVICE_RECOVERY);
  2324. lpfc_disc_state_machine(vports[i], ndlp,
  2325. NULL, NLP_EVT_DEVICE_RM);
  2326. }
  2327. spin_lock_irq(shost->host_lock);
  2328. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2329. spin_unlock_irq(shost->host_lock);
  2330. lpfc_unreg_rpi(vports[i], ndlp);
  2331. }
  2332. }
  2333. }
  2334. lpfc_destroy_vport_work_array(phba, vports);
  2335. lpfc_sli_mbox_sys_shutdown(phba);
  2336. }
  2337. /**
  2338. * lpfc_offline - Bring a HBA offline
  2339. * @phba: pointer to lpfc hba data structure.
  2340. *
  2341. * This routine actually brings a HBA offline. It stops all the timers
  2342. * associated with the HBA, brings down the SLI layer, and eventually
  2343. * marks the HBA as in offline state for the upper layer protocol.
  2344. **/
  2345. void
  2346. lpfc_offline(struct lpfc_hba *phba)
  2347. {
  2348. struct Scsi_Host *shost;
  2349. struct lpfc_vport **vports;
  2350. int i;
  2351. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  2352. return;
  2353. /* stop port and all timers associated with this hba */
  2354. lpfc_stop_port(phba);
  2355. vports = lpfc_create_vport_work_array(phba);
  2356. if (vports != NULL)
  2357. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  2358. lpfc_stop_vport_timers(vports[i]);
  2359. lpfc_destroy_vport_work_array(phba, vports);
  2360. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2361. "0460 Bring Adapter offline\n");
  2362. /* Bring down the SLI Layer and cleanup. The HBA is offline
  2363. now. */
  2364. lpfc_sli_hba_down(phba);
  2365. spin_lock_irq(&phba->hbalock);
  2366. phba->work_ha = 0;
  2367. spin_unlock_irq(&phba->hbalock);
  2368. vports = lpfc_create_vport_work_array(phba);
  2369. if (vports != NULL)
  2370. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2371. shost = lpfc_shost_from_vport(vports[i]);
  2372. spin_lock_irq(shost->host_lock);
  2373. vports[i]->work_port_events = 0;
  2374. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  2375. spin_unlock_irq(shost->host_lock);
  2376. }
  2377. lpfc_destroy_vport_work_array(phba, vports);
  2378. }
  2379. /**
  2380. * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
  2381. * @phba: pointer to lpfc hba data structure.
  2382. *
  2383. * This routine is to free all the SCSI buffers and IOCBs from the driver
  2384. * list back to kernel. It is called from lpfc_pci_remove_one to free
  2385. * the internal resources before the device is removed from the system.
  2386. *
  2387. * Return codes
  2388. * 0 - successful (for now, it always returns 0)
  2389. **/
  2390. static int
  2391. lpfc_scsi_free(struct lpfc_hba *phba)
  2392. {
  2393. struct lpfc_scsi_buf *sb, *sb_next;
  2394. struct lpfc_iocbq *io, *io_next;
  2395. spin_lock_irq(&phba->hbalock);
  2396. /* Release all the lpfc_scsi_bufs maintained by this host. */
  2397. spin_lock(&phba->scsi_buf_list_lock);
  2398. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  2399. list_del(&sb->list);
  2400. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  2401. sb->dma_handle);
  2402. kfree(sb);
  2403. phba->total_scsi_bufs--;
  2404. }
  2405. spin_unlock(&phba->scsi_buf_list_lock);
  2406. /* Release all the lpfc_iocbq entries maintained by this host. */
  2407. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  2408. list_del(&io->list);
  2409. kfree(io);
  2410. phba->total_iocbq_bufs--;
  2411. }
  2412. spin_unlock_irq(&phba->hbalock);
  2413. return 0;
  2414. }
  2415. /**
  2416. * lpfc_create_port - Create an FC port
  2417. * @phba: pointer to lpfc hba data structure.
  2418. * @instance: a unique integer ID to this FC port.
  2419. * @dev: pointer to the device data structure.
  2420. *
  2421. * This routine creates a FC port for the upper layer protocol. The FC port
  2422. * can be created on top of either a physical port or a virtual port provided
  2423. * by the HBA. This routine also allocates a SCSI host data structure (shost)
  2424. * and associates the FC port created before adding the shost into the SCSI
  2425. * layer.
  2426. *
  2427. * Return codes
  2428. * @vport - pointer to the virtual N_Port data structure.
  2429. * NULL - port create failed.
  2430. **/
  2431. struct lpfc_vport *
  2432. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  2433. {
  2434. struct lpfc_vport *vport;
  2435. struct Scsi_Host *shost;
  2436. int error = 0;
  2437. if (dev != &phba->pcidev->dev)
  2438. shost = scsi_host_alloc(&lpfc_vport_template,
  2439. sizeof(struct lpfc_vport));
  2440. else
  2441. shost = scsi_host_alloc(&lpfc_template,
  2442. sizeof(struct lpfc_vport));
  2443. if (!shost)
  2444. goto out;
  2445. vport = (struct lpfc_vport *) shost->hostdata;
  2446. vport->phba = phba;
  2447. vport->load_flag |= FC_LOADING;
  2448. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2449. vport->fc_rscn_flush = 0;
  2450. lpfc_get_vport_cfgparam(vport);
  2451. shost->unique_id = instance;
  2452. shost->max_id = LPFC_MAX_TARGET;
  2453. shost->max_lun = vport->cfg_max_luns;
  2454. shost->this_id = -1;
  2455. shost->max_cmd_len = 16;
  2456. if (phba->sli_rev == LPFC_SLI_REV4) {
  2457. shost->dma_boundary =
  2458. phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
  2459. shost->sg_tablesize = phba->cfg_sg_seg_cnt;
  2460. }
  2461. /*
  2462. * Set initial can_queue value since 0 is no longer supported and
  2463. * scsi_add_host will fail. This will be adjusted later based on the
  2464. * max xri value determined in hba setup.
  2465. */
  2466. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  2467. if (dev != &phba->pcidev->dev) {
  2468. shost->transportt = lpfc_vport_transport_template;
  2469. vport->port_type = LPFC_NPIV_PORT;
  2470. } else {
  2471. shost->transportt = lpfc_transport_template;
  2472. vport->port_type = LPFC_PHYSICAL_PORT;
  2473. }
  2474. /* Initialize all internally managed lists. */
  2475. INIT_LIST_HEAD(&vport->fc_nodes);
  2476. INIT_LIST_HEAD(&vport->rcv_buffer_list);
  2477. spin_lock_init(&vport->work_port_lock);
  2478. init_timer(&vport->fc_disctmo);
  2479. vport->fc_disctmo.function = lpfc_disc_timeout;
  2480. vport->fc_disctmo.data = (unsigned long)vport;
  2481. init_timer(&vport->fc_fdmitmo);
  2482. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  2483. vport->fc_fdmitmo.data = (unsigned long)vport;
  2484. init_timer(&vport->els_tmofunc);
  2485. vport->els_tmofunc.function = lpfc_els_timeout;
  2486. vport->els_tmofunc.data = (unsigned long)vport;
  2487. error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
  2488. if (error)
  2489. goto out_put_shost;
  2490. spin_lock_irq(&phba->hbalock);
  2491. list_add_tail(&vport->listentry, &phba->port_list);
  2492. spin_unlock_irq(&phba->hbalock);
  2493. return vport;
  2494. out_put_shost:
  2495. scsi_host_put(shost);
  2496. out:
  2497. return NULL;
  2498. }
  2499. /**
  2500. * destroy_port - destroy an FC port
  2501. * @vport: pointer to an lpfc virtual N_Port data structure.
  2502. *
  2503. * This routine destroys a FC port from the upper layer protocol. All the
  2504. * resources associated with the port are released.
  2505. **/
  2506. void
  2507. destroy_port(struct lpfc_vport *vport)
  2508. {
  2509. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2510. struct lpfc_hba *phba = vport->phba;
  2511. lpfc_debugfs_terminate(vport);
  2512. fc_remove_host(shost);
  2513. scsi_remove_host(shost);
  2514. spin_lock_irq(&phba->hbalock);
  2515. list_del_init(&vport->listentry);
  2516. spin_unlock_irq(&phba->hbalock);
  2517. lpfc_cleanup(vport);
  2518. return;
  2519. }
  2520. /**
  2521. * lpfc_get_instance - Get a unique integer ID
  2522. *
  2523. * This routine allocates a unique integer ID from lpfc_hba_index pool. It
  2524. * uses the kernel idr facility to perform the task.
  2525. *
  2526. * Return codes:
  2527. * instance - a unique integer ID allocated as the new instance.
  2528. * -1 - lpfc get instance failed.
  2529. **/
  2530. int
  2531. lpfc_get_instance(void)
  2532. {
  2533. int instance = 0;
  2534. /* Assign an unused number */
  2535. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  2536. return -1;
  2537. if (idr_get_new(&lpfc_hba_index, NULL, &instance))
  2538. return -1;
  2539. return instance;
  2540. }
  2541. /**
  2542. * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
  2543. * @shost: pointer to SCSI host data structure.
  2544. * @time: elapsed time of the scan in jiffies.
  2545. *
  2546. * This routine is called by the SCSI layer with a SCSI host to determine
  2547. * whether the scan host is finished.
  2548. *
  2549. * Note: there is no scan_start function as adapter initialization will have
  2550. * asynchronously kicked off the link initialization.
  2551. *
  2552. * Return codes
  2553. * 0 - SCSI host scan is not over yet.
  2554. * 1 - SCSI host scan is over.
  2555. **/
  2556. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2557. {
  2558. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2559. struct lpfc_hba *phba = vport->phba;
  2560. int stat = 0;
  2561. spin_lock_irq(shost->host_lock);
  2562. if (vport->load_flag & FC_UNLOADING) {
  2563. stat = 1;
  2564. goto finished;
  2565. }
  2566. if (time >= 30 * HZ) {
  2567. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2568. "0461 Scanning longer than 30 "
  2569. "seconds. Continuing initialization\n");
  2570. stat = 1;
  2571. goto finished;
  2572. }
  2573. if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
  2574. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2575. "0465 Link down longer than 15 "
  2576. "seconds. Continuing initialization\n");
  2577. stat = 1;
  2578. goto finished;
  2579. }
  2580. if (vport->port_state != LPFC_VPORT_READY)
  2581. goto finished;
  2582. if (vport->num_disc_nodes || vport->fc_prli_sent)
  2583. goto finished;
  2584. if (vport->fc_map_cnt == 0 && time < 2 * HZ)
  2585. goto finished;
  2586. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  2587. goto finished;
  2588. stat = 1;
  2589. finished:
  2590. spin_unlock_irq(shost->host_lock);
  2591. return stat;
  2592. }
  2593. /**
  2594. * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
  2595. * @shost: pointer to SCSI host data structure.
  2596. *
  2597. * This routine initializes a given SCSI host attributes on a FC port. The
  2598. * SCSI host can be either on top of a physical port or a virtual port.
  2599. **/
  2600. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  2601. {
  2602. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2603. struct lpfc_hba *phba = vport->phba;
  2604. /*
  2605. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  2606. */
  2607. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  2608. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  2609. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  2610. memset(fc_host_supported_fc4s(shost), 0,
  2611. sizeof(fc_host_supported_fc4s(shost)));
  2612. fc_host_supported_fc4s(shost)[2] = 1;
  2613. fc_host_supported_fc4s(shost)[7] = 1;
  2614. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  2615. sizeof fc_host_symbolic_name(shost));
  2616. fc_host_supported_speeds(shost) = 0;
  2617. if (phba->lmt & LMT_10Gb)
  2618. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  2619. if (phba->lmt & LMT_8Gb)
  2620. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  2621. if (phba->lmt & LMT_4Gb)
  2622. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  2623. if (phba->lmt & LMT_2Gb)
  2624. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  2625. if (phba->lmt & LMT_1Gb)
  2626. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  2627. fc_host_maxframe_size(shost) =
  2628. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  2629. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  2630. fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
  2631. /* This value is also unchanging */
  2632. memset(fc_host_active_fc4s(shost), 0,
  2633. sizeof(fc_host_active_fc4s(shost)));
  2634. fc_host_active_fc4s(shost)[2] = 1;
  2635. fc_host_active_fc4s(shost)[7] = 1;
  2636. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  2637. spin_lock_irq(shost->host_lock);
  2638. vport->load_flag &= ~FC_LOADING;
  2639. spin_unlock_irq(shost->host_lock);
  2640. }
  2641. /**
  2642. * lpfc_stop_port_s3 - Stop SLI3 device port
  2643. * @phba: pointer to lpfc hba data structure.
  2644. *
  2645. * This routine is invoked to stop an SLI3 device port, it stops the device
  2646. * from generating interrupts and stops the device driver's timers for the
  2647. * device.
  2648. **/
  2649. static void
  2650. lpfc_stop_port_s3(struct lpfc_hba *phba)
  2651. {
  2652. /* Clear all interrupt enable conditions */
  2653. writel(0, phba->HCregaddr);
  2654. readl(phba->HCregaddr); /* flush */
  2655. /* Clear all pending interrupts */
  2656. writel(0xffffffff, phba->HAregaddr);
  2657. readl(phba->HAregaddr); /* flush */
  2658. /* Reset some HBA SLI setup states */
  2659. lpfc_stop_hba_timers(phba);
  2660. phba->pport->work_port_events = 0;
  2661. }
  2662. /**
  2663. * lpfc_stop_port_s4 - Stop SLI4 device port
  2664. * @phba: pointer to lpfc hba data structure.
  2665. *
  2666. * This routine is invoked to stop an SLI4 device port, it stops the device
  2667. * from generating interrupts and stops the device driver's timers for the
  2668. * device.
  2669. **/
  2670. static void
  2671. lpfc_stop_port_s4(struct lpfc_hba *phba)
  2672. {
  2673. /* Reset some HBA SLI4 setup states */
  2674. lpfc_stop_hba_timers(phba);
  2675. phba->pport->work_port_events = 0;
  2676. phba->sli4_hba.intr_enable = 0;
  2677. }
  2678. /**
  2679. * lpfc_stop_port - Wrapper function for stopping hba port
  2680. * @phba: Pointer to HBA context object.
  2681. *
  2682. * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
  2683. * the API jump table function pointer from the lpfc_hba struct.
  2684. **/
  2685. void
  2686. lpfc_stop_port(struct lpfc_hba *phba)
  2687. {
  2688. phba->lpfc_stop_port(phba);
  2689. }
  2690. /**
  2691. * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
  2692. * @phba: Pointer to hba for which this call is being executed.
  2693. *
  2694. * This routine starts the timer waiting for the FCF rediscovery to complete.
  2695. **/
  2696. void
  2697. lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
  2698. {
  2699. unsigned long fcf_redisc_wait_tmo =
  2700. (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
  2701. /* Start fcf rediscovery wait period timer */
  2702. mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
  2703. spin_lock_irq(&phba->hbalock);
  2704. /* Allow action to new fcf asynchronous event */
  2705. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
  2706. /* Mark the FCF rediscovery pending state */
  2707. phba->fcf.fcf_flag |= FCF_REDISC_PEND;
  2708. spin_unlock_irq(&phba->hbalock);
  2709. }
  2710. /**
  2711. * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
  2712. * @ptr: Map to lpfc_hba data structure pointer.
  2713. *
  2714. * This routine is invoked when waiting for FCF table rediscover has been
  2715. * timed out. If new FCF record(s) has (have) been discovered during the
  2716. * wait period, a new FCF event shall be added to the FCOE async event
  2717. * list, and then worker thread shall be waked up for processing from the
  2718. * worker thread context.
  2719. **/
  2720. void
  2721. lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
  2722. {
  2723. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  2724. /* Don't send FCF rediscovery event if timer cancelled */
  2725. spin_lock_irq(&phba->hbalock);
  2726. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
  2727. spin_unlock_irq(&phba->hbalock);
  2728. return;
  2729. }
  2730. /* Clear FCF rediscovery timer pending flag */
  2731. phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
  2732. /* FCF rediscovery event to worker thread */
  2733. phba->fcf.fcf_flag |= FCF_REDISC_EVT;
  2734. spin_unlock_irq(&phba->hbalock);
  2735. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2736. "2776 FCF rediscover quiescent timer expired\n");
  2737. /* wake up worker thread */
  2738. lpfc_worker_wake_up(phba);
  2739. }
  2740. /**
  2741. * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
  2742. * @phba: pointer to lpfc hba data structure.
  2743. * @acqe_link: pointer to the async link completion queue entry.
  2744. *
  2745. * This routine is to parse the SLI4 link-attention link fault code and
  2746. * translate it into the base driver's read link attention mailbox command
  2747. * status.
  2748. *
  2749. * Return: Link-attention status in terms of base driver's coding.
  2750. **/
  2751. static uint16_t
  2752. lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
  2753. struct lpfc_acqe_link *acqe_link)
  2754. {
  2755. uint16_t latt_fault;
  2756. switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
  2757. case LPFC_ASYNC_LINK_FAULT_NONE:
  2758. case LPFC_ASYNC_LINK_FAULT_LOCAL:
  2759. case LPFC_ASYNC_LINK_FAULT_REMOTE:
  2760. latt_fault = 0;
  2761. break;
  2762. default:
  2763. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2764. "0398 Invalid link fault code: x%x\n",
  2765. bf_get(lpfc_acqe_link_fault, acqe_link));
  2766. latt_fault = MBXERR_ERROR;
  2767. break;
  2768. }
  2769. return latt_fault;
  2770. }
  2771. /**
  2772. * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
  2773. * @phba: pointer to lpfc hba data structure.
  2774. * @acqe_link: pointer to the async link completion queue entry.
  2775. *
  2776. * This routine is to parse the SLI4 link attention type and translate it
  2777. * into the base driver's link attention type coding.
  2778. *
  2779. * Return: Link attention type in terms of base driver's coding.
  2780. **/
  2781. static uint8_t
  2782. lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
  2783. struct lpfc_acqe_link *acqe_link)
  2784. {
  2785. uint8_t att_type;
  2786. switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
  2787. case LPFC_ASYNC_LINK_STATUS_DOWN:
  2788. case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
  2789. att_type = LPFC_ATT_LINK_DOWN;
  2790. break;
  2791. case LPFC_ASYNC_LINK_STATUS_UP:
  2792. /* Ignore physical link up events - wait for logical link up */
  2793. att_type = LPFC_ATT_RESERVED;
  2794. break;
  2795. case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
  2796. att_type = LPFC_ATT_LINK_UP;
  2797. break;
  2798. default:
  2799. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2800. "0399 Invalid link attention type: x%x\n",
  2801. bf_get(lpfc_acqe_link_status, acqe_link));
  2802. att_type = LPFC_ATT_RESERVED;
  2803. break;
  2804. }
  2805. return att_type;
  2806. }
  2807. /**
  2808. * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
  2809. * @phba: pointer to lpfc hba data structure.
  2810. * @acqe_link: pointer to the async link completion queue entry.
  2811. *
  2812. * This routine is to parse the SLI4 link-attention link speed and translate
  2813. * it into the base driver's link-attention link speed coding.
  2814. *
  2815. * Return: Link-attention link speed in terms of base driver's coding.
  2816. **/
  2817. static uint8_t
  2818. lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
  2819. struct lpfc_acqe_link *acqe_link)
  2820. {
  2821. uint8_t link_speed;
  2822. switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
  2823. case LPFC_ASYNC_LINK_SPEED_ZERO:
  2824. case LPFC_ASYNC_LINK_SPEED_10MBPS:
  2825. case LPFC_ASYNC_LINK_SPEED_100MBPS:
  2826. link_speed = LPFC_LINK_SPEED_UNKNOWN;
  2827. break;
  2828. case LPFC_ASYNC_LINK_SPEED_1GBPS:
  2829. link_speed = LPFC_LINK_SPEED_1GHZ;
  2830. break;
  2831. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  2832. link_speed = LPFC_LINK_SPEED_10GHZ;
  2833. break;
  2834. default:
  2835. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2836. "0483 Invalid link-attention link speed: x%x\n",
  2837. bf_get(lpfc_acqe_link_speed, acqe_link));
  2838. link_speed = LPFC_LINK_SPEED_UNKNOWN;
  2839. break;
  2840. }
  2841. return link_speed;
  2842. }
  2843. /**
  2844. * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
  2845. * @phba: pointer to lpfc hba data structure.
  2846. * @acqe_link: pointer to the async link completion queue entry.
  2847. *
  2848. * This routine is to handle the SLI4 asynchronous FCoE link event.
  2849. **/
  2850. static void
  2851. lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
  2852. struct lpfc_acqe_link *acqe_link)
  2853. {
  2854. struct lpfc_dmabuf *mp;
  2855. LPFC_MBOXQ_t *pmb;
  2856. MAILBOX_t *mb;
  2857. struct lpfc_mbx_read_top *la;
  2858. uint8_t att_type;
  2859. int rc;
  2860. att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
  2861. if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
  2862. return;
  2863. phba->fcoe_eventtag = acqe_link->event_tag;
  2864. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2865. if (!pmb) {
  2866. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2867. "0395 The mboxq allocation failed\n");
  2868. return;
  2869. }
  2870. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  2871. if (!mp) {
  2872. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2873. "0396 The lpfc_dmabuf allocation failed\n");
  2874. goto out_free_pmb;
  2875. }
  2876. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  2877. if (!mp->virt) {
  2878. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2879. "0397 The mbuf allocation failed\n");
  2880. goto out_free_dmabuf;
  2881. }
  2882. /* Cleanup any outstanding ELS commands */
  2883. lpfc_els_flush_all_cmd(phba);
  2884. /* Block ELS IOCBs until we have done process link event */
  2885. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  2886. /* Update link event statistics */
  2887. phba->sli.slistat.link_event++;
  2888. /* Create lpfc_handle_latt mailbox command from link ACQE */
  2889. lpfc_read_topology(phba, pmb, mp);
  2890. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  2891. pmb->vport = phba->pport;
  2892. /* Keep the link status for extra SLI4 state machine reference */
  2893. phba->sli4_hba.link_state.speed =
  2894. bf_get(lpfc_acqe_link_speed, acqe_link);
  2895. phba->sli4_hba.link_state.duplex =
  2896. bf_get(lpfc_acqe_link_duplex, acqe_link);
  2897. phba->sli4_hba.link_state.status =
  2898. bf_get(lpfc_acqe_link_status, acqe_link);
  2899. phba->sli4_hba.link_state.type =
  2900. bf_get(lpfc_acqe_link_type, acqe_link);
  2901. phba->sli4_hba.link_state.number =
  2902. bf_get(lpfc_acqe_link_number, acqe_link);
  2903. phba->sli4_hba.link_state.fault =
  2904. bf_get(lpfc_acqe_link_fault, acqe_link);
  2905. phba->sli4_hba.link_state.logical_speed =
  2906. bf_get(lpfc_acqe_logical_link_speed, acqe_link);
  2907. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2908. "2900 Async FCoE Link event - Speed:%dGBit duplex:x%x "
  2909. "LA Type:x%x Port Type:%d Port Number:%d Logical "
  2910. "speed:%dMbps Fault:%d\n",
  2911. phba->sli4_hba.link_state.speed,
  2912. phba->sli4_hba.link_state.topology,
  2913. phba->sli4_hba.link_state.status,
  2914. phba->sli4_hba.link_state.type,
  2915. phba->sli4_hba.link_state.number,
  2916. phba->sli4_hba.link_state.logical_speed * 10,
  2917. phba->sli4_hba.link_state.fault);
  2918. /*
  2919. * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
  2920. * topology info. Note: Optional for non FC-AL ports.
  2921. */
  2922. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  2923. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2924. if (rc == MBX_NOT_FINISHED)
  2925. goto out_free_dmabuf;
  2926. return;
  2927. }
  2928. /*
  2929. * For FCoE Mode: fill in all the topology information we need and call
  2930. * the READ_TOPOLOGY completion routine to continue without actually
  2931. * sending the READ_TOPOLOGY mailbox command to the port.
  2932. */
  2933. /* Parse and translate status field */
  2934. mb = &pmb->u.mb;
  2935. mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
  2936. /* Parse and translate link attention fields */
  2937. la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
  2938. la->eventTag = acqe_link->event_tag;
  2939. bf_set(lpfc_mbx_read_top_att_type, la, att_type);
  2940. bf_set(lpfc_mbx_read_top_link_spd, la,
  2941. lpfc_sli4_parse_latt_link_speed(phba, acqe_link));
  2942. /* Fake the the following irrelvant fields */
  2943. bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
  2944. bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
  2945. bf_set(lpfc_mbx_read_top_il, la, 0);
  2946. bf_set(lpfc_mbx_read_top_pb, la, 0);
  2947. bf_set(lpfc_mbx_read_top_fa, la, 0);
  2948. bf_set(lpfc_mbx_read_top_mm, la, 0);
  2949. /* Invoke the lpfc_handle_latt mailbox command callback function */
  2950. lpfc_mbx_cmpl_read_topology(phba, pmb);
  2951. return;
  2952. out_free_dmabuf:
  2953. kfree(mp);
  2954. out_free_pmb:
  2955. mempool_free(pmb, phba->mbox_mem_pool);
  2956. }
  2957. /**
  2958. * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
  2959. * @phba: pointer to lpfc hba data structure.
  2960. * @acqe_fc: pointer to the async fc completion queue entry.
  2961. *
  2962. * This routine is to handle the SLI4 asynchronous FC event. It will simply log
  2963. * that the event was received and then issue a read_topology mailbox command so
  2964. * that the rest of the driver will treat it the same as SLI3.
  2965. **/
  2966. static void
  2967. lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
  2968. {
  2969. struct lpfc_dmabuf *mp;
  2970. LPFC_MBOXQ_t *pmb;
  2971. int rc;
  2972. if (bf_get(lpfc_trailer_type, acqe_fc) !=
  2973. LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
  2974. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2975. "2895 Non FC link Event detected.(%d)\n",
  2976. bf_get(lpfc_trailer_type, acqe_fc));
  2977. return;
  2978. }
  2979. /* Keep the link status for extra SLI4 state machine reference */
  2980. phba->sli4_hba.link_state.speed =
  2981. bf_get(lpfc_acqe_fc_la_speed, acqe_fc);
  2982. phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
  2983. phba->sli4_hba.link_state.topology =
  2984. bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
  2985. phba->sli4_hba.link_state.status =
  2986. bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
  2987. phba->sli4_hba.link_state.type =
  2988. bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
  2989. phba->sli4_hba.link_state.number =
  2990. bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
  2991. phba->sli4_hba.link_state.fault =
  2992. bf_get(lpfc_acqe_link_fault, acqe_fc);
  2993. phba->sli4_hba.link_state.logical_speed =
  2994. bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc);
  2995. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2996. "2896 Async FC event - Speed:%dGBaud Topology:x%x "
  2997. "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
  2998. "%dMbps Fault:%d\n",
  2999. phba->sli4_hba.link_state.speed,
  3000. phba->sli4_hba.link_state.topology,
  3001. phba->sli4_hba.link_state.status,
  3002. phba->sli4_hba.link_state.type,
  3003. phba->sli4_hba.link_state.number,
  3004. phba->sli4_hba.link_state.logical_speed * 10,
  3005. phba->sli4_hba.link_state.fault);
  3006. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3007. if (!pmb) {
  3008. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3009. "2897 The mboxq allocation failed\n");
  3010. return;
  3011. }
  3012. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3013. if (!mp) {
  3014. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3015. "2898 The lpfc_dmabuf allocation failed\n");
  3016. goto out_free_pmb;
  3017. }
  3018. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  3019. if (!mp->virt) {
  3020. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3021. "2899 The mbuf allocation failed\n");
  3022. goto out_free_dmabuf;
  3023. }
  3024. /* Cleanup any outstanding ELS commands */
  3025. lpfc_els_flush_all_cmd(phba);
  3026. /* Block ELS IOCBs until we have done process link event */
  3027. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  3028. /* Update link event statistics */
  3029. phba->sli.slistat.link_event++;
  3030. /* Create lpfc_handle_latt mailbox command from link ACQE */
  3031. lpfc_read_topology(phba, pmb, mp);
  3032. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
  3033. pmb->vport = phba->pport;
  3034. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  3035. if (rc == MBX_NOT_FINISHED)
  3036. goto out_free_dmabuf;
  3037. return;
  3038. out_free_dmabuf:
  3039. kfree(mp);
  3040. out_free_pmb:
  3041. mempool_free(pmb, phba->mbox_mem_pool);
  3042. }
  3043. /**
  3044. * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
  3045. * @phba: pointer to lpfc hba data structure.
  3046. * @acqe_fc: pointer to the async SLI completion queue entry.
  3047. *
  3048. * This routine is to handle the SLI4 asynchronous SLI events.
  3049. **/
  3050. static void
  3051. lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
  3052. {
  3053. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3054. "2901 Async SLI event - Event Data1:x%08x Event Data2:"
  3055. "x%08x SLI Event Type:%d",
  3056. acqe_sli->event_data1, acqe_sli->event_data2,
  3057. bf_get(lpfc_trailer_type, acqe_sli));
  3058. return;
  3059. }
  3060. /**
  3061. * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
  3062. * @vport: pointer to vport data structure.
  3063. *
  3064. * This routine is to perform Clear Virtual Link (CVL) on a vport in
  3065. * response to a CVL event.
  3066. *
  3067. * Return the pointer to the ndlp with the vport if successful, otherwise
  3068. * return NULL.
  3069. **/
  3070. static struct lpfc_nodelist *
  3071. lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
  3072. {
  3073. struct lpfc_nodelist *ndlp;
  3074. struct Scsi_Host *shost;
  3075. struct lpfc_hba *phba;
  3076. if (!vport)
  3077. return NULL;
  3078. phba = vport->phba;
  3079. if (!phba)
  3080. return NULL;
  3081. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  3082. if (!ndlp) {
  3083. /* Cannot find existing Fabric ndlp, so allocate a new one */
  3084. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3085. if (!ndlp)
  3086. return 0;
  3087. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  3088. /* Set the node type */
  3089. ndlp->nlp_type |= NLP_FABRIC;
  3090. /* Put ndlp onto node list */
  3091. lpfc_enqueue_node(vport, ndlp);
  3092. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3093. /* re-setup ndlp without removing from node list */
  3094. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  3095. if (!ndlp)
  3096. return 0;
  3097. }
  3098. if ((phba->pport->port_state < LPFC_FLOGI) &&
  3099. (phba->pport->port_state != LPFC_VPORT_FAILED))
  3100. return NULL;
  3101. /* If virtual link is not yet instantiated ignore CVL */
  3102. if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
  3103. && (vport->port_state != LPFC_VPORT_FAILED))
  3104. return NULL;
  3105. shost = lpfc_shost_from_vport(vport);
  3106. if (!shost)
  3107. return NULL;
  3108. lpfc_linkdown_port(vport);
  3109. lpfc_cleanup_pending_mbox(vport);
  3110. spin_lock_irq(shost->host_lock);
  3111. vport->fc_flag |= FC_VPORT_CVL_RCVD;
  3112. spin_unlock_irq(shost->host_lock);
  3113. return ndlp;
  3114. }
  3115. /**
  3116. * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
  3117. * @vport: pointer to lpfc hba data structure.
  3118. *
  3119. * This routine is to perform Clear Virtual Link (CVL) on all vports in
  3120. * response to a FCF dead event.
  3121. **/
  3122. static void
  3123. lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
  3124. {
  3125. struct lpfc_vport **vports;
  3126. int i;
  3127. vports = lpfc_create_vport_work_array(phba);
  3128. if (vports)
  3129. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  3130. lpfc_sli4_perform_vport_cvl(vports[i]);
  3131. lpfc_destroy_vport_work_array(phba, vports);
  3132. }
  3133. /**
  3134. * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
  3135. * @phba: pointer to lpfc hba data structure.
  3136. * @acqe_link: pointer to the async fcoe completion queue entry.
  3137. *
  3138. * This routine is to handle the SLI4 asynchronous fcoe event.
  3139. **/
  3140. static void
  3141. lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
  3142. struct lpfc_acqe_fip *acqe_fip)
  3143. {
  3144. uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
  3145. int rc;
  3146. struct lpfc_vport *vport;
  3147. struct lpfc_nodelist *ndlp;
  3148. struct Scsi_Host *shost;
  3149. int active_vlink_present;
  3150. struct lpfc_vport **vports;
  3151. int i;
  3152. phba->fc_eventTag = acqe_fip->event_tag;
  3153. phba->fcoe_eventtag = acqe_fip->event_tag;
  3154. switch (event_type) {
  3155. case LPFC_FIP_EVENT_TYPE_NEW_FCF:
  3156. case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
  3157. if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
  3158. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3159. LOG_DISCOVERY,
  3160. "2546 New FCF event, evt_tag:x%x, "
  3161. "index:x%x\n",
  3162. acqe_fip->event_tag,
  3163. acqe_fip->index);
  3164. else
  3165. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
  3166. LOG_DISCOVERY,
  3167. "2788 FCF param modified event, "
  3168. "evt_tag:x%x, index:x%x\n",
  3169. acqe_fip->event_tag,
  3170. acqe_fip->index);
  3171. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3172. /*
  3173. * During period of FCF discovery, read the FCF
  3174. * table record indexed by the event to update
  3175. * FCF roundrobin failover eligible FCF bmask.
  3176. */
  3177. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  3178. LOG_DISCOVERY,
  3179. "2779 Read FCF (x%x) for updating "
  3180. "roundrobin FCF failover bmask\n",
  3181. acqe_fip->index);
  3182. rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
  3183. }
  3184. /* If the FCF discovery is in progress, do nothing. */
  3185. spin_lock_irq(&phba->hbalock);
  3186. if (phba->hba_flag & FCF_TS_INPROG) {
  3187. spin_unlock_irq(&phba->hbalock);
  3188. break;
  3189. }
  3190. /* If fast FCF failover rescan event is pending, do nothing */
  3191. if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
  3192. spin_unlock_irq(&phba->hbalock);
  3193. break;
  3194. }
  3195. /* If the FCF has been in discovered state, do nothing. */
  3196. if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
  3197. spin_unlock_irq(&phba->hbalock);
  3198. break;
  3199. }
  3200. spin_unlock_irq(&phba->hbalock);
  3201. /* Otherwise, scan the entire FCF table and re-discover SAN */
  3202. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3203. "2770 Start FCF table scan per async FCF "
  3204. "event, evt_tag:x%x, index:x%x\n",
  3205. acqe_fip->event_tag, acqe_fip->index);
  3206. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  3207. LPFC_FCOE_FCF_GET_FIRST);
  3208. if (rc)
  3209. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3210. "2547 Issue FCF scan read FCF mailbox "
  3211. "command failed (x%x)\n", rc);
  3212. break;
  3213. case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
  3214. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3215. "2548 FCF Table full count 0x%x tag 0x%x\n",
  3216. bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
  3217. acqe_fip->event_tag);
  3218. break;
  3219. case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
  3220. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3221. "2549 FCF (x%x) disconnected from network, "
  3222. "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
  3223. /*
  3224. * If we are in the middle of FCF failover process, clear
  3225. * the corresponding FCF bit in the roundrobin bitmap.
  3226. */
  3227. spin_lock_irq(&phba->hbalock);
  3228. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3229. spin_unlock_irq(&phba->hbalock);
  3230. /* Update FLOGI FCF failover eligible FCF bmask */
  3231. lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
  3232. break;
  3233. }
  3234. spin_unlock_irq(&phba->hbalock);
  3235. /* If the event is not for currently used fcf do nothing */
  3236. if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
  3237. break;
  3238. /*
  3239. * Otherwise, request the port to rediscover the entire FCF
  3240. * table for a fast recovery from case that the current FCF
  3241. * is no longer valid as we are not in the middle of FCF
  3242. * failover process already.
  3243. */
  3244. spin_lock_irq(&phba->hbalock);
  3245. /* Mark the fast failover process in progress */
  3246. phba->fcf.fcf_flag |= FCF_DEAD_DISC;
  3247. spin_unlock_irq(&phba->hbalock);
  3248. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3249. "2771 Start FCF fast failover process due to "
  3250. "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
  3251. "\n", acqe_fip->event_tag, acqe_fip->index);
  3252. rc = lpfc_sli4_redisc_fcf_table(phba);
  3253. if (rc) {
  3254. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3255. LOG_DISCOVERY,
  3256. "2772 Issue FCF rediscover mabilbox "
  3257. "command failed, fail through to FCF "
  3258. "dead event\n");
  3259. spin_lock_irq(&phba->hbalock);
  3260. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  3261. spin_unlock_irq(&phba->hbalock);
  3262. /*
  3263. * Last resort will fail over by treating this
  3264. * as a link down to FCF registration.
  3265. */
  3266. lpfc_sli4_fcf_dead_failthrough(phba);
  3267. } else {
  3268. /* Reset FCF roundrobin bmask for new discovery */
  3269. memset(phba->fcf.fcf_rr_bmask, 0,
  3270. sizeof(*phba->fcf.fcf_rr_bmask));
  3271. /*
  3272. * Handling fast FCF failover to a DEAD FCF event is
  3273. * considered equalivant to receiving CVL to all vports.
  3274. */
  3275. lpfc_sli4_perform_all_vport_cvl(phba);
  3276. }
  3277. break;
  3278. case LPFC_FIP_EVENT_TYPE_CVL:
  3279. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3280. "2718 Clear Virtual Link Received for VPI 0x%x"
  3281. " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
  3282. vport = lpfc_find_vport_by_vpid(phba,
  3283. acqe_fip->index - phba->vpi_base);
  3284. ndlp = lpfc_sli4_perform_vport_cvl(vport);
  3285. if (!ndlp)
  3286. break;
  3287. active_vlink_present = 0;
  3288. vports = lpfc_create_vport_work_array(phba);
  3289. if (vports) {
  3290. for (i = 0; i <= phba->max_vports && vports[i] != NULL;
  3291. i++) {
  3292. if ((!(vports[i]->fc_flag &
  3293. FC_VPORT_CVL_RCVD)) &&
  3294. (vports[i]->port_state > LPFC_FDISC)) {
  3295. active_vlink_present = 1;
  3296. break;
  3297. }
  3298. }
  3299. lpfc_destroy_vport_work_array(phba, vports);
  3300. }
  3301. if (active_vlink_present) {
  3302. /*
  3303. * If there are other active VLinks present,
  3304. * re-instantiate the Vlink using FDISC.
  3305. */
  3306. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  3307. shost = lpfc_shost_from_vport(vport);
  3308. spin_lock_irq(shost->host_lock);
  3309. ndlp->nlp_flag |= NLP_DELAY_TMO;
  3310. spin_unlock_irq(shost->host_lock);
  3311. ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
  3312. vport->port_state = LPFC_FDISC;
  3313. } else {
  3314. /*
  3315. * Otherwise, we request port to rediscover
  3316. * the entire FCF table for a fast recovery
  3317. * from possible case that the current FCF
  3318. * is no longer valid if we are not already
  3319. * in the FCF failover process.
  3320. */
  3321. spin_lock_irq(&phba->hbalock);
  3322. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  3323. spin_unlock_irq(&phba->hbalock);
  3324. break;
  3325. }
  3326. /* Mark the fast failover process in progress */
  3327. phba->fcf.fcf_flag |= FCF_ACVL_DISC;
  3328. spin_unlock_irq(&phba->hbalock);
  3329. lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
  3330. LOG_DISCOVERY,
  3331. "2773 Start FCF failover per CVL, "
  3332. "evt_tag:x%x\n", acqe_fip->event_tag);
  3333. rc = lpfc_sli4_redisc_fcf_table(phba);
  3334. if (rc) {
  3335. lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
  3336. LOG_DISCOVERY,
  3337. "2774 Issue FCF rediscover "
  3338. "mabilbox command failed, "
  3339. "through to CVL event\n");
  3340. spin_lock_irq(&phba->hbalock);
  3341. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  3342. spin_unlock_irq(&phba->hbalock);
  3343. /*
  3344. * Last resort will be re-try on the
  3345. * the current registered FCF entry.
  3346. */
  3347. lpfc_retry_pport_discovery(phba);
  3348. } else
  3349. /*
  3350. * Reset FCF roundrobin bmask for new
  3351. * discovery.
  3352. */
  3353. memset(phba->fcf.fcf_rr_bmask, 0,
  3354. sizeof(*phba->fcf.fcf_rr_bmask));
  3355. }
  3356. break;
  3357. default:
  3358. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3359. "0288 Unknown FCoE event type 0x%x event tag "
  3360. "0x%x\n", event_type, acqe_fip->event_tag);
  3361. break;
  3362. }
  3363. }
  3364. /**
  3365. * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
  3366. * @phba: pointer to lpfc hba data structure.
  3367. * @acqe_link: pointer to the async dcbx completion queue entry.
  3368. *
  3369. * This routine is to handle the SLI4 asynchronous dcbx event.
  3370. **/
  3371. static void
  3372. lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
  3373. struct lpfc_acqe_dcbx *acqe_dcbx)
  3374. {
  3375. phba->fc_eventTag = acqe_dcbx->event_tag;
  3376. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3377. "0290 The SLI4 DCBX asynchronous event is not "
  3378. "handled yet\n");
  3379. }
  3380. /**
  3381. * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
  3382. * @phba: pointer to lpfc hba data structure.
  3383. * @acqe_link: pointer to the async grp5 completion queue entry.
  3384. *
  3385. * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
  3386. * is an asynchronous notified of a logical link speed change. The Port
  3387. * reports the logical link speed in units of 10Mbps.
  3388. **/
  3389. static void
  3390. lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
  3391. struct lpfc_acqe_grp5 *acqe_grp5)
  3392. {
  3393. uint16_t prev_ll_spd;
  3394. phba->fc_eventTag = acqe_grp5->event_tag;
  3395. phba->fcoe_eventtag = acqe_grp5->event_tag;
  3396. prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
  3397. phba->sli4_hba.link_state.logical_speed =
  3398. (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5));
  3399. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3400. "2789 GRP5 Async Event: Updating logical link speed "
  3401. "from %dMbps to %dMbps\n", (prev_ll_spd * 10),
  3402. (phba->sli4_hba.link_state.logical_speed*10));
  3403. }
  3404. /**
  3405. * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
  3406. * @phba: pointer to lpfc hba data structure.
  3407. *
  3408. * This routine is invoked by the worker thread to process all the pending
  3409. * SLI4 asynchronous events.
  3410. **/
  3411. void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
  3412. {
  3413. struct lpfc_cq_event *cq_event;
  3414. /* First, declare the async event has been handled */
  3415. spin_lock_irq(&phba->hbalock);
  3416. phba->hba_flag &= ~ASYNC_EVENT;
  3417. spin_unlock_irq(&phba->hbalock);
  3418. /* Now, handle all the async events */
  3419. while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
  3420. /* Get the first event from the head of the event queue */
  3421. spin_lock_irq(&phba->hbalock);
  3422. list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
  3423. cq_event, struct lpfc_cq_event, list);
  3424. spin_unlock_irq(&phba->hbalock);
  3425. /* Process the asynchronous event */
  3426. switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
  3427. case LPFC_TRAILER_CODE_LINK:
  3428. lpfc_sli4_async_link_evt(phba,
  3429. &cq_event->cqe.acqe_link);
  3430. break;
  3431. case LPFC_TRAILER_CODE_FCOE:
  3432. lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
  3433. break;
  3434. case LPFC_TRAILER_CODE_DCBX:
  3435. lpfc_sli4_async_dcbx_evt(phba,
  3436. &cq_event->cqe.acqe_dcbx);
  3437. break;
  3438. case LPFC_TRAILER_CODE_GRP5:
  3439. lpfc_sli4_async_grp5_evt(phba,
  3440. &cq_event->cqe.acqe_grp5);
  3441. break;
  3442. case LPFC_TRAILER_CODE_FC:
  3443. lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
  3444. break;
  3445. case LPFC_TRAILER_CODE_SLI:
  3446. lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
  3447. break;
  3448. default:
  3449. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3450. "1804 Invalid asynchrous event code: "
  3451. "x%x\n", bf_get(lpfc_trailer_code,
  3452. &cq_event->cqe.mcqe_cmpl));
  3453. break;
  3454. }
  3455. /* Free the completion event processed to the free pool */
  3456. lpfc_sli4_cq_event_release(phba, cq_event);
  3457. }
  3458. }
  3459. /**
  3460. * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
  3461. * @phba: pointer to lpfc hba data structure.
  3462. *
  3463. * This routine is invoked by the worker thread to process FCF table
  3464. * rediscovery pending completion event.
  3465. **/
  3466. void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
  3467. {
  3468. int rc;
  3469. spin_lock_irq(&phba->hbalock);
  3470. /* Clear FCF rediscovery timeout event */
  3471. phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
  3472. /* Clear driver fast failover FCF record flag */
  3473. phba->fcf.failover_rec.flag = 0;
  3474. /* Set state for FCF fast failover */
  3475. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  3476. spin_unlock_irq(&phba->hbalock);
  3477. /* Scan FCF table from the first entry to re-discover SAN */
  3478. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  3479. "2777 Start post-quiescent FCF table scan\n");
  3480. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  3481. if (rc)
  3482. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
  3483. "2747 Issue FCF scan read FCF mailbox "
  3484. "command failed 0x%x\n", rc);
  3485. }
  3486. /**
  3487. * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
  3488. * @phba: pointer to lpfc hba data structure.
  3489. * @dev_grp: The HBA PCI-Device group number.
  3490. *
  3491. * This routine is invoked to set up the per HBA PCI-Device group function
  3492. * API jump table entries.
  3493. *
  3494. * Return: 0 if success, otherwise -ENODEV
  3495. **/
  3496. int
  3497. lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  3498. {
  3499. int rc;
  3500. /* Set up lpfc PCI-device group */
  3501. phba->pci_dev_grp = dev_grp;
  3502. /* The LPFC_PCI_DEV_OC uses SLI4 */
  3503. if (dev_grp == LPFC_PCI_DEV_OC)
  3504. phba->sli_rev = LPFC_SLI_REV4;
  3505. /* Set up device INIT API function jump table */
  3506. rc = lpfc_init_api_table_setup(phba, dev_grp);
  3507. if (rc)
  3508. return -ENODEV;
  3509. /* Set up SCSI API function jump table */
  3510. rc = lpfc_scsi_api_table_setup(phba, dev_grp);
  3511. if (rc)
  3512. return -ENODEV;
  3513. /* Set up SLI API function jump table */
  3514. rc = lpfc_sli_api_table_setup(phba, dev_grp);
  3515. if (rc)
  3516. return -ENODEV;
  3517. /* Set up MBOX API function jump table */
  3518. rc = lpfc_mbox_api_table_setup(phba, dev_grp);
  3519. if (rc)
  3520. return -ENODEV;
  3521. return 0;
  3522. }
  3523. /**
  3524. * lpfc_log_intr_mode - Log the active interrupt mode
  3525. * @phba: pointer to lpfc hba data structure.
  3526. * @intr_mode: active interrupt mode adopted.
  3527. *
  3528. * This routine it invoked to log the currently used active interrupt mode
  3529. * to the device.
  3530. **/
  3531. static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
  3532. {
  3533. switch (intr_mode) {
  3534. case 0:
  3535. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3536. "0470 Enable INTx interrupt mode.\n");
  3537. break;
  3538. case 1:
  3539. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3540. "0481 Enabled MSI interrupt mode.\n");
  3541. break;
  3542. case 2:
  3543. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3544. "0480 Enabled MSI-X interrupt mode.\n");
  3545. break;
  3546. default:
  3547. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3548. "0482 Illegal interrupt mode.\n");
  3549. break;
  3550. }
  3551. return;
  3552. }
  3553. /**
  3554. * lpfc_enable_pci_dev - Enable a generic PCI device.
  3555. * @phba: pointer to lpfc hba data structure.
  3556. *
  3557. * This routine is invoked to enable the PCI device that is common to all
  3558. * PCI devices.
  3559. *
  3560. * Return codes
  3561. * 0 - successful
  3562. * other values - error
  3563. **/
  3564. static int
  3565. lpfc_enable_pci_dev(struct lpfc_hba *phba)
  3566. {
  3567. struct pci_dev *pdev;
  3568. int bars;
  3569. /* Obtain PCI device reference */
  3570. if (!phba->pcidev)
  3571. goto out_error;
  3572. else
  3573. pdev = phba->pcidev;
  3574. /* Select PCI BARs */
  3575. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  3576. /* Enable PCI device */
  3577. if (pci_enable_device_mem(pdev))
  3578. goto out_error;
  3579. /* Request PCI resource for the device */
  3580. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  3581. goto out_disable_device;
  3582. /* Set up device as PCI master and save state for EEH */
  3583. pci_set_master(pdev);
  3584. pci_try_set_mwi(pdev);
  3585. pci_save_state(pdev);
  3586. return 0;
  3587. out_disable_device:
  3588. pci_disable_device(pdev);
  3589. out_error:
  3590. return -ENODEV;
  3591. }
  3592. /**
  3593. * lpfc_disable_pci_dev - Disable a generic PCI device.
  3594. * @phba: pointer to lpfc hba data structure.
  3595. *
  3596. * This routine is invoked to disable the PCI device that is common to all
  3597. * PCI devices.
  3598. **/
  3599. static void
  3600. lpfc_disable_pci_dev(struct lpfc_hba *phba)
  3601. {
  3602. struct pci_dev *pdev;
  3603. int bars;
  3604. /* Obtain PCI device reference */
  3605. if (!phba->pcidev)
  3606. return;
  3607. else
  3608. pdev = phba->pcidev;
  3609. /* Select PCI BARs */
  3610. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  3611. /* Release PCI resource and disable PCI device */
  3612. pci_release_selected_regions(pdev, bars);
  3613. pci_disable_device(pdev);
  3614. /* Null out PCI private reference to driver */
  3615. pci_set_drvdata(pdev, NULL);
  3616. return;
  3617. }
  3618. /**
  3619. * lpfc_reset_hba - Reset a hba
  3620. * @phba: pointer to lpfc hba data structure.
  3621. *
  3622. * This routine is invoked to reset a hba device. It brings the HBA
  3623. * offline, performs a board restart, and then brings the board back
  3624. * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
  3625. * on outstanding mailbox commands.
  3626. **/
  3627. void
  3628. lpfc_reset_hba(struct lpfc_hba *phba)
  3629. {
  3630. /* If resets are disabled then set error state and return. */
  3631. if (!phba->cfg_enable_hba_reset) {
  3632. phba->link_state = LPFC_HBA_ERROR;
  3633. return;
  3634. }
  3635. lpfc_offline_prep(phba);
  3636. lpfc_offline(phba);
  3637. lpfc_sli_brdrestart(phba);
  3638. lpfc_online(phba);
  3639. lpfc_unblock_mgmt_io(phba);
  3640. }
  3641. /**
  3642. * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
  3643. * @phba: pointer to lpfc hba data structure.
  3644. *
  3645. * This routine is invoked to set up the driver internal resources specific to
  3646. * support the SLI-3 HBA device it attached to.
  3647. *
  3648. * Return codes
  3649. * 0 - successful
  3650. * other values - error
  3651. **/
  3652. static int
  3653. lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
  3654. {
  3655. struct lpfc_sli *psli;
  3656. /*
  3657. * Initialize timers used by driver
  3658. */
  3659. /* Heartbeat timer */
  3660. init_timer(&phba->hb_tmofunc);
  3661. phba->hb_tmofunc.function = lpfc_hb_timeout;
  3662. phba->hb_tmofunc.data = (unsigned long)phba;
  3663. psli = &phba->sli;
  3664. /* MBOX heartbeat timer */
  3665. init_timer(&psli->mbox_tmo);
  3666. psli->mbox_tmo.function = lpfc_mbox_timeout;
  3667. psli->mbox_tmo.data = (unsigned long) phba;
  3668. /* FCP polling mode timer */
  3669. init_timer(&phba->fcp_poll_timer);
  3670. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  3671. phba->fcp_poll_timer.data = (unsigned long) phba;
  3672. /* Fabric block timer */
  3673. init_timer(&phba->fabric_block_timer);
  3674. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  3675. phba->fabric_block_timer.data = (unsigned long) phba;
  3676. /* EA polling mode timer */
  3677. init_timer(&phba->eratt_poll);
  3678. phba->eratt_poll.function = lpfc_poll_eratt;
  3679. phba->eratt_poll.data = (unsigned long) phba;
  3680. /* Host attention work mask setup */
  3681. phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
  3682. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  3683. /* Get all the module params for configuring this host */
  3684. lpfc_get_cfgparam(phba);
  3685. if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
  3686. phba->menlo_flag |= HBA_MENLO_SUPPORT;
  3687. /* check for menlo minimum sg count */
  3688. if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
  3689. phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
  3690. }
  3691. /*
  3692. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  3693. * used to create the sg_dma_buf_pool must be dynamically calculated.
  3694. * 2 segments are added since the IOCB needs a command and response bde.
  3695. */
  3696. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  3697. sizeof(struct fcp_rsp) +
  3698. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
  3699. if (phba->cfg_enable_bg) {
  3700. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
  3701. phba->cfg_sg_dma_buf_size +=
  3702. phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
  3703. }
  3704. /* Also reinitialize the host templates with new values. */
  3705. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  3706. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  3707. phba->max_vpi = LPFC_MAX_VPI;
  3708. /* This will be set to correct value after config_port mbox */
  3709. phba->max_vports = 0;
  3710. /*
  3711. * Initialize the SLI Layer to run with lpfc HBAs.
  3712. */
  3713. lpfc_sli_setup(phba);
  3714. lpfc_sli_queue_setup(phba);
  3715. /* Allocate device driver memory */
  3716. if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
  3717. return -ENOMEM;
  3718. return 0;
  3719. }
  3720. /**
  3721. * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
  3722. * @phba: pointer to lpfc hba data structure.
  3723. *
  3724. * This routine is invoked to unset the driver internal resources set up
  3725. * specific for supporting the SLI-3 HBA device it attached to.
  3726. **/
  3727. static void
  3728. lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
  3729. {
  3730. /* Free device driver memory allocated */
  3731. lpfc_mem_free_all(phba);
  3732. return;
  3733. }
  3734. /**
  3735. * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
  3736. * @phba: pointer to lpfc hba data structure.
  3737. *
  3738. * This routine is invoked to set up the driver internal resources specific to
  3739. * support the SLI-4 HBA device it attached to.
  3740. *
  3741. * Return codes
  3742. * 0 - successful
  3743. * other values - error
  3744. **/
  3745. static int
  3746. lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
  3747. {
  3748. struct lpfc_sli *psli;
  3749. LPFC_MBOXQ_t *mboxq;
  3750. int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size;
  3751. uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
  3752. struct lpfc_mqe *mqe;
  3753. int longs, sli_family;
  3754. /* Before proceed, wait for POST done and device ready */
  3755. rc = lpfc_sli4_post_status_check(phba);
  3756. if (rc)
  3757. return -ENODEV;
  3758. /*
  3759. * Initialize timers used by driver
  3760. */
  3761. /* Heartbeat timer */
  3762. init_timer(&phba->hb_tmofunc);
  3763. phba->hb_tmofunc.function = lpfc_hb_timeout;
  3764. phba->hb_tmofunc.data = (unsigned long)phba;
  3765. init_timer(&phba->rrq_tmr);
  3766. phba->rrq_tmr.function = lpfc_rrq_timeout;
  3767. phba->rrq_tmr.data = (unsigned long)phba;
  3768. psli = &phba->sli;
  3769. /* MBOX heartbeat timer */
  3770. init_timer(&psli->mbox_tmo);
  3771. psli->mbox_tmo.function = lpfc_mbox_timeout;
  3772. psli->mbox_tmo.data = (unsigned long) phba;
  3773. /* Fabric block timer */
  3774. init_timer(&phba->fabric_block_timer);
  3775. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  3776. phba->fabric_block_timer.data = (unsigned long) phba;
  3777. /* EA polling mode timer */
  3778. init_timer(&phba->eratt_poll);
  3779. phba->eratt_poll.function = lpfc_poll_eratt;
  3780. phba->eratt_poll.data = (unsigned long) phba;
  3781. /* FCF rediscover timer */
  3782. init_timer(&phba->fcf.redisc_wait);
  3783. phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
  3784. phba->fcf.redisc_wait.data = (unsigned long)phba;
  3785. /*
  3786. * We need to do a READ_CONFIG mailbox command here before
  3787. * calling lpfc_get_cfgparam. For VFs this will report the
  3788. * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
  3789. * All of the resources allocated
  3790. * for this Port are tied to these values.
  3791. */
  3792. /* Get all the module params for configuring this host */
  3793. lpfc_get_cfgparam(phba);
  3794. phba->max_vpi = LPFC_MAX_VPI;
  3795. /* This will be set to correct value after the read_config mbox */
  3796. phba->max_vports = 0;
  3797. /* Program the default value of vlan_id and fc_map */
  3798. phba->valid_vlan = 0;
  3799. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3800. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3801. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3802. /*
  3803. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  3804. * used to create the sg_dma_buf_pool must be dynamically calculated.
  3805. * 2 segments are added since the IOCB needs a command and response bde.
  3806. * To insure that the scsi sgl does not cross a 4k page boundary only
  3807. * sgl sizes of must be a power of 2.
  3808. */
  3809. buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) +
  3810. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)));
  3811. sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf);
  3812. max_buf_size = LPFC_SLI4_MAX_BUF_SIZE;
  3813. switch (sli_family) {
  3814. case LPFC_SLI_INTF_FAMILY_BE2:
  3815. case LPFC_SLI_INTF_FAMILY_BE3:
  3816. /* There is a single hint for BE - 2 pages per BPL. */
  3817. if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) ==
  3818. LPFC_SLI_INTF_SLI_HINT1_1)
  3819. max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE;
  3820. break;
  3821. case LPFC_SLI_INTF_FAMILY_LNCR_A0:
  3822. case LPFC_SLI_INTF_FAMILY_LNCR_B0:
  3823. default:
  3824. break;
  3825. }
  3826. for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE;
  3827. dma_buf_size < max_buf_size && buf_size > dma_buf_size;
  3828. dma_buf_size = dma_buf_size << 1)
  3829. ;
  3830. if (dma_buf_size == max_buf_size)
  3831. phba->cfg_sg_seg_cnt = (dma_buf_size -
  3832. sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) -
  3833. (2 * sizeof(struct sli4_sge))) /
  3834. sizeof(struct sli4_sge);
  3835. phba->cfg_sg_dma_buf_size = dma_buf_size;
  3836. /* Initialize buffer queue management fields */
  3837. hbq_count = lpfc_sli_hbq_count();
  3838. for (i = 0; i < hbq_count; ++i)
  3839. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  3840. INIT_LIST_HEAD(&phba->rb_pend_list);
  3841. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
  3842. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
  3843. /*
  3844. * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
  3845. */
  3846. /* Initialize the Abort scsi buffer list used by driver */
  3847. spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
  3848. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  3849. /* This abort list used by worker thread */
  3850. spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
  3851. /*
  3852. * Initialize dirver internal slow-path work queues
  3853. */
  3854. /* Driver internel slow-path CQ Event pool */
  3855. INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
  3856. /* Response IOCB work queue list */
  3857. INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
  3858. /* Asynchronous event CQ Event work queue list */
  3859. INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
  3860. /* Fast-path XRI aborted CQ Event work queue list */
  3861. INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  3862. /* Slow-path XRI aborted CQ Event work queue list */
  3863. INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
  3864. /* Receive queue CQ Event work queue list */
  3865. INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
  3866. /* Initialize the driver internal SLI layer lists. */
  3867. lpfc_sli_setup(phba);
  3868. lpfc_sli_queue_setup(phba);
  3869. /* Allocate device driver memory */
  3870. rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
  3871. if (rc)
  3872. return -ENOMEM;
  3873. /* IF Type 2 ports get initialized now. */
  3874. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  3875. LPFC_SLI_INTF_IF_TYPE_2) {
  3876. rc = lpfc_pci_function_reset(phba);
  3877. if (unlikely(rc))
  3878. return -ENODEV;
  3879. }
  3880. /* Create the bootstrap mailbox command */
  3881. rc = lpfc_create_bootstrap_mbox(phba);
  3882. if (unlikely(rc))
  3883. goto out_free_mem;
  3884. /* Set up the host's endian order with the device. */
  3885. rc = lpfc_setup_endian_order(phba);
  3886. if (unlikely(rc))
  3887. goto out_free_bsmbx;
  3888. /* Set up the hba's configuration parameters. */
  3889. rc = lpfc_sli4_read_config(phba);
  3890. if (unlikely(rc))
  3891. goto out_free_bsmbx;
  3892. /* IF Type 0 ports get initialized now. */
  3893. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  3894. LPFC_SLI_INTF_IF_TYPE_0) {
  3895. rc = lpfc_pci_function_reset(phba);
  3896. if (unlikely(rc))
  3897. goto out_free_bsmbx;
  3898. }
  3899. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  3900. GFP_KERNEL);
  3901. if (!mboxq) {
  3902. rc = -ENOMEM;
  3903. goto out_free_bsmbx;
  3904. }
  3905. /* Get the Supported Pages. It is always available. */
  3906. lpfc_supported_pages(mboxq);
  3907. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  3908. if (unlikely(rc)) {
  3909. rc = -EIO;
  3910. mempool_free(mboxq, phba->mbox_mem_pool);
  3911. goto out_free_bsmbx;
  3912. }
  3913. mqe = &mboxq->u.mqe;
  3914. memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
  3915. LPFC_MAX_SUPPORTED_PAGES);
  3916. for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
  3917. switch (pn_page[i]) {
  3918. case LPFC_SLI4_PARAMETERS:
  3919. phba->sli4_hba.pc_sli4_params.supported = 1;
  3920. break;
  3921. default:
  3922. break;
  3923. }
  3924. }
  3925. /* Read the port's SLI4 Parameters capabilities if supported. */
  3926. if (phba->sli4_hba.pc_sli4_params.supported)
  3927. rc = lpfc_pc_sli4_params_get(phba, mboxq);
  3928. mempool_free(mboxq, phba->mbox_mem_pool);
  3929. if (rc) {
  3930. rc = -EIO;
  3931. goto out_free_bsmbx;
  3932. }
  3933. /* Create all the SLI4 queues */
  3934. rc = lpfc_sli4_queue_create(phba);
  3935. if (rc)
  3936. goto out_free_bsmbx;
  3937. /* Create driver internal CQE event pool */
  3938. rc = lpfc_sli4_cq_event_pool_create(phba);
  3939. if (rc)
  3940. goto out_destroy_queue;
  3941. /* Initialize and populate the iocb list per host */
  3942. rc = lpfc_init_sgl_list(phba);
  3943. if (rc) {
  3944. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3945. "1400 Failed to initialize sgl list.\n");
  3946. goto out_destroy_cq_event_pool;
  3947. }
  3948. rc = lpfc_init_active_sgl_array(phba);
  3949. if (rc) {
  3950. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3951. "1430 Failed to initialize sgl list.\n");
  3952. goto out_free_sgl_list;
  3953. }
  3954. rc = lpfc_sli4_init_rpi_hdrs(phba);
  3955. if (rc) {
  3956. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3957. "1432 Failed to initialize rpi headers.\n");
  3958. goto out_free_active_sgl;
  3959. }
  3960. /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
  3961. longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
  3962. phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
  3963. GFP_KERNEL);
  3964. if (!phba->fcf.fcf_rr_bmask) {
  3965. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3966. "2759 Failed allocate memory for FCF round "
  3967. "robin failover bmask\n");
  3968. goto out_remove_rpi_hdrs;
  3969. }
  3970. phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
  3971. phba->cfg_fcp_eq_count), GFP_KERNEL);
  3972. if (!phba->sli4_hba.fcp_eq_hdl) {
  3973. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3974. "2572 Failed allocate memory for fast-path "
  3975. "per-EQ handle array\n");
  3976. goto out_free_fcf_rr_bmask;
  3977. }
  3978. phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
  3979. phba->sli4_hba.cfg_eqn), GFP_KERNEL);
  3980. if (!phba->sli4_hba.msix_entries) {
  3981. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3982. "2573 Failed allocate memory for msi-x "
  3983. "interrupt vector entries\n");
  3984. goto out_free_fcp_eq_hdl;
  3985. }
  3986. return rc;
  3987. out_free_fcp_eq_hdl:
  3988. kfree(phba->sli4_hba.fcp_eq_hdl);
  3989. out_free_fcf_rr_bmask:
  3990. kfree(phba->fcf.fcf_rr_bmask);
  3991. out_remove_rpi_hdrs:
  3992. lpfc_sli4_remove_rpi_hdrs(phba);
  3993. out_free_active_sgl:
  3994. lpfc_free_active_sgl(phba);
  3995. out_free_sgl_list:
  3996. lpfc_free_sgl_list(phba);
  3997. out_destroy_cq_event_pool:
  3998. lpfc_sli4_cq_event_pool_destroy(phba);
  3999. out_destroy_queue:
  4000. lpfc_sli4_queue_destroy(phba);
  4001. out_free_bsmbx:
  4002. lpfc_destroy_bootstrap_mbox(phba);
  4003. out_free_mem:
  4004. lpfc_mem_free(phba);
  4005. return rc;
  4006. }
  4007. /**
  4008. * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
  4009. * @phba: pointer to lpfc hba data structure.
  4010. *
  4011. * This routine is invoked to unset the driver internal resources set up
  4012. * specific for supporting the SLI-4 HBA device it attached to.
  4013. **/
  4014. static void
  4015. lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
  4016. {
  4017. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  4018. /* Free memory allocated for msi-x interrupt vector entries */
  4019. kfree(phba->sli4_hba.msix_entries);
  4020. /* Free memory allocated for fast-path work queue handles */
  4021. kfree(phba->sli4_hba.fcp_eq_hdl);
  4022. /* Free the allocated rpi headers. */
  4023. lpfc_sli4_remove_rpi_hdrs(phba);
  4024. lpfc_sli4_remove_rpis(phba);
  4025. /* Free eligible FCF index bmask */
  4026. kfree(phba->fcf.fcf_rr_bmask);
  4027. /* Free the ELS sgl list */
  4028. lpfc_free_active_sgl(phba);
  4029. lpfc_free_sgl_list(phba);
  4030. /* Free the SCSI sgl management array */
  4031. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  4032. /* Free the SLI4 queues */
  4033. lpfc_sli4_queue_destroy(phba);
  4034. /* Free the completion queue EQ event pool */
  4035. lpfc_sli4_cq_event_release_all(phba);
  4036. lpfc_sli4_cq_event_pool_destroy(phba);
  4037. /* Free the bsmbx region. */
  4038. lpfc_destroy_bootstrap_mbox(phba);
  4039. /* Free the SLI Layer memory with SLI4 HBAs */
  4040. lpfc_mem_free_all(phba);
  4041. /* Free the current connect table */
  4042. list_for_each_entry_safe(conn_entry, next_conn_entry,
  4043. &phba->fcf_conn_rec_list, list) {
  4044. list_del_init(&conn_entry->list);
  4045. kfree(conn_entry);
  4046. }
  4047. return;
  4048. }
  4049. /**
  4050. * lpfc_init_api_table_setup - Set up init api fucntion jump table
  4051. * @phba: The hba struct for which this call is being executed.
  4052. * @dev_grp: The HBA PCI-Device group number.
  4053. *
  4054. * This routine sets up the device INIT interface API function jump table
  4055. * in @phba struct.
  4056. *
  4057. * Returns: 0 - success, -ENODEV - failure.
  4058. **/
  4059. int
  4060. lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  4061. {
  4062. phba->lpfc_hba_init_link = lpfc_hba_init_link;
  4063. phba->lpfc_hba_down_link = lpfc_hba_down_link;
  4064. switch (dev_grp) {
  4065. case LPFC_PCI_DEV_LP:
  4066. phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
  4067. phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
  4068. phba->lpfc_stop_port = lpfc_stop_port_s3;
  4069. break;
  4070. case LPFC_PCI_DEV_OC:
  4071. phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
  4072. phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
  4073. phba->lpfc_stop_port = lpfc_stop_port_s4;
  4074. break;
  4075. default:
  4076. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4077. "1431 Invalid HBA PCI-device group: 0x%x\n",
  4078. dev_grp);
  4079. return -ENODEV;
  4080. break;
  4081. }
  4082. return 0;
  4083. }
  4084. /**
  4085. * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
  4086. * @phba: pointer to lpfc hba data structure.
  4087. *
  4088. * This routine is invoked to set up the driver internal resources before the
  4089. * device specific resource setup to support the HBA device it attached to.
  4090. *
  4091. * Return codes
  4092. * 0 - successful
  4093. * other values - error
  4094. **/
  4095. static int
  4096. lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
  4097. {
  4098. /*
  4099. * Driver resources common to all SLI revisions
  4100. */
  4101. atomic_set(&phba->fast_event_count, 0);
  4102. spin_lock_init(&phba->hbalock);
  4103. /* Initialize ndlp management spinlock */
  4104. spin_lock_init(&phba->ndlp_lock);
  4105. INIT_LIST_HEAD(&phba->port_list);
  4106. INIT_LIST_HEAD(&phba->work_list);
  4107. init_waitqueue_head(&phba->wait_4_mlo_m_q);
  4108. /* Initialize the wait queue head for the kernel thread */
  4109. init_waitqueue_head(&phba->work_waitq);
  4110. /* Initialize the scsi buffer list used by driver for scsi IO */
  4111. spin_lock_init(&phba->scsi_buf_list_lock);
  4112. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  4113. /* Initialize the fabric iocb list */
  4114. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  4115. /* Initialize list to save ELS buffers */
  4116. INIT_LIST_HEAD(&phba->elsbuf);
  4117. /* Initialize FCF connection rec list */
  4118. INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
  4119. return 0;
  4120. }
  4121. /**
  4122. * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
  4123. * @phba: pointer to lpfc hba data structure.
  4124. *
  4125. * This routine is invoked to set up the driver internal resources after the
  4126. * device specific resource setup to support the HBA device it attached to.
  4127. *
  4128. * Return codes
  4129. * 0 - successful
  4130. * other values - error
  4131. **/
  4132. static int
  4133. lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
  4134. {
  4135. int error;
  4136. /* Startup the kernel thread for this host adapter. */
  4137. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  4138. "lpfc_worker_%d", phba->brd_no);
  4139. if (IS_ERR(phba->worker_thread)) {
  4140. error = PTR_ERR(phba->worker_thread);
  4141. return error;
  4142. }
  4143. return 0;
  4144. }
  4145. /**
  4146. * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
  4147. * @phba: pointer to lpfc hba data structure.
  4148. *
  4149. * This routine is invoked to unset the driver internal resources set up after
  4150. * the device specific resource setup for supporting the HBA device it
  4151. * attached to.
  4152. **/
  4153. static void
  4154. lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
  4155. {
  4156. /* Stop kernel worker thread */
  4157. kthread_stop(phba->worker_thread);
  4158. }
  4159. /**
  4160. * lpfc_free_iocb_list - Free iocb list.
  4161. * @phba: pointer to lpfc hba data structure.
  4162. *
  4163. * This routine is invoked to free the driver's IOCB list and memory.
  4164. **/
  4165. static void
  4166. lpfc_free_iocb_list(struct lpfc_hba *phba)
  4167. {
  4168. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  4169. spin_lock_irq(&phba->hbalock);
  4170. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  4171. &phba->lpfc_iocb_list, list) {
  4172. list_del(&iocbq_entry->list);
  4173. kfree(iocbq_entry);
  4174. phba->total_iocbq_bufs--;
  4175. }
  4176. spin_unlock_irq(&phba->hbalock);
  4177. return;
  4178. }
  4179. /**
  4180. * lpfc_init_iocb_list - Allocate and initialize iocb list.
  4181. * @phba: pointer to lpfc hba data structure.
  4182. *
  4183. * This routine is invoked to allocate and initizlize the driver's IOCB
  4184. * list and set up the IOCB tag array accordingly.
  4185. *
  4186. * Return codes
  4187. * 0 - successful
  4188. * other values - error
  4189. **/
  4190. static int
  4191. lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
  4192. {
  4193. struct lpfc_iocbq *iocbq_entry = NULL;
  4194. uint16_t iotag;
  4195. int i;
  4196. /* Initialize and populate the iocb list per host. */
  4197. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  4198. for (i = 0; i < iocb_count; i++) {
  4199. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  4200. if (iocbq_entry == NULL) {
  4201. printk(KERN_ERR "%s: only allocated %d iocbs of "
  4202. "expected %d count. Unloading driver.\n",
  4203. __func__, i, LPFC_IOCB_LIST_CNT);
  4204. goto out_free_iocbq;
  4205. }
  4206. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  4207. if (iotag == 0) {
  4208. kfree(iocbq_entry);
  4209. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  4210. "Unloading driver.\n", __func__);
  4211. goto out_free_iocbq;
  4212. }
  4213. iocbq_entry->sli4_xritag = NO_XRI;
  4214. spin_lock_irq(&phba->hbalock);
  4215. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  4216. phba->total_iocbq_bufs++;
  4217. spin_unlock_irq(&phba->hbalock);
  4218. }
  4219. return 0;
  4220. out_free_iocbq:
  4221. lpfc_free_iocb_list(phba);
  4222. return -ENOMEM;
  4223. }
  4224. /**
  4225. * lpfc_free_sgl_list - Free sgl list.
  4226. * @phba: pointer to lpfc hba data structure.
  4227. *
  4228. * This routine is invoked to free the driver's sgl list and memory.
  4229. **/
  4230. static void
  4231. lpfc_free_sgl_list(struct lpfc_hba *phba)
  4232. {
  4233. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  4234. LIST_HEAD(sglq_list);
  4235. spin_lock_irq(&phba->hbalock);
  4236. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
  4237. spin_unlock_irq(&phba->hbalock);
  4238. list_for_each_entry_safe(sglq_entry, sglq_next,
  4239. &sglq_list, list) {
  4240. list_del(&sglq_entry->list);
  4241. lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
  4242. kfree(sglq_entry);
  4243. phba->sli4_hba.total_sglq_bufs--;
  4244. }
  4245. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  4246. }
  4247. /**
  4248. * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
  4249. * @phba: pointer to lpfc hba data structure.
  4250. *
  4251. * This routine is invoked to allocate the driver's active sgl memory.
  4252. * This array will hold the sglq_entry's for active IOs.
  4253. **/
  4254. static int
  4255. lpfc_init_active_sgl_array(struct lpfc_hba *phba)
  4256. {
  4257. int size;
  4258. size = sizeof(struct lpfc_sglq *);
  4259. size *= phba->sli4_hba.max_cfg_param.max_xri;
  4260. phba->sli4_hba.lpfc_sglq_active_list =
  4261. kzalloc(size, GFP_KERNEL);
  4262. if (!phba->sli4_hba.lpfc_sglq_active_list)
  4263. return -ENOMEM;
  4264. return 0;
  4265. }
  4266. /**
  4267. * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
  4268. * @phba: pointer to lpfc hba data structure.
  4269. *
  4270. * This routine is invoked to walk through the array of active sglq entries
  4271. * and free all of the resources.
  4272. * This is just a place holder for now.
  4273. **/
  4274. static void
  4275. lpfc_free_active_sgl(struct lpfc_hba *phba)
  4276. {
  4277. kfree(phba->sli4_hba.lpfc_sglq_active_list);
  4278. }
  4279. /**
  4280. * lpfc_init_sgl_list - Allocate and initialize sgl list.
  4281. * @phba: pointer to lpfc hba data structure.
  4282. *
  4283. * This routine is invoked to allocate and initizlize the driver's sgl
  4284. * list and set up the sgl xritag tag array accordingly.
  4285. *
  4286. * Return codes
  4287. * 0 - successful
  4288. * other values - error
  4289. **/
  4290. static int
  4291. lpfc_init_sgl_list(struct lpfc_hba *phba)
  4292. {
  4293. struct lpfc_sglq *sglq_entry = NULL;
  4294. int i;
  4295. int els_xri_cnt;
  4296. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  4297. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4298. "2400 lpfc_init_sgl_list els %d.\n",
  4299. els_xri_cnt);
  4300. /* Initialize and populate the sglq list per host/VF. */
  4301. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
  4302. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  4303. /* Sanity check on XRI management */
  4304. if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) {
  4305. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4306. "2562 No room left for SCSI XRI allocation: "
  4307. "max_xri=%d, els_xri=%d\n",
  4308. phba->sli4_hba.max_cfg_param.max_xri,
  4309. els_xri_cnt);
  4310. return -ENOMEM;
  4311. }
  4312. /* Allocate memory for the ELS XRI management array */
  4313. phba->sli4_hba.lpfc_els_sgl_array =
  4314. kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt),
  4315. GFP_KERNEL);
  4316. if (!phba->sli4_hba.lpfc_els_sgl_array) {
  4317. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4318. "2401 Failed to allocate memory for ELS "
  4319. "XRI management array of size %d.\n",
  4320. els_xri_cnt);
  4321. return -ENOMEM;
  4322. }
  4323. /* Keep the SCSI XRI into the XRI management array */
  4324. phba->sli4_hba.scsi_xri_max =
  4325. phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
  4326. phba->sli4_hba.scsi_xri_cnt = 0;
  4327. phba->sli4_hba.lpfc_scsi_psb_array =
  4328. kzalloc((sizeof(struct lpfc_scsi_buf *) *
  4329. phba->sli4_hba.scsi_xri_max), GFP_KERNEL);
  4330. if (!phba->sli4_hba.lpfc_scsi_psb_array) {
  4331. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4332. "2563 Failed to allocate memory for SCSI "
  4333. "XRI management array of size %d.\n",
  4334. phba->sli4_hba.scsi_xri_max);
  4335. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  4336. return -ENOMEM;
  4337. }
  4338. for (i = 0; i < els_xri_cnt; i++) {
  4339. sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL);
  4340. if (sglq_entry == NULL) {
  4341. printk(KERN_ERR "%s: only allocated %d sgls of "
  4342. "expected %d count. Unloading driver.\n",
  4343. __func__, i, els_xri_cnt);
  4344. goto out_free_mem;
  4345. }
  4346. sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba);
  4347. if (sglq_entry->sli4_xritag == NO_XRI) {
  4348. kfree(sglq_entry);
  4349. printk(KERN_ERR "%s: failed to allocate XRI.\n"
  4350. "Unloading driver.\n", __func__);
  4351. goto out_free_mem;
  4352. }
  4353. sglq_entry->buff_type = GEN_BUFF_TYPE;
  4354. sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys);
  4355. if (sglq_entry->virt == NULL) {
  4356. kfree(sglq_entry);
  4357. printk(KERN_ERR "%s: failed to allocate mbuf.\n"
  4358. "Unloading driver.\n", __func__);
  4359. goto out_free_mem;
  4360. }
  4361. sglq_entry->sgl = sglq_entry->virt;
  4362. memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
  4363. /* The list order is used by later block SGL registraton */
  4364. spin_lock_irq(&phba->hbalock);
  4365. sglq_entry->state = SGL_FREED;
  4366. list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list);
  4367. phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry;
  4368. phba->sli4_hba.total_sglq_bufs++;
  4369. spin_unlock_irq(&phba->hbalock);
  4370. }
  4371. return 0;
  4372. out_free_mem:
  4373. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  4374. lpfc_free_sgl_list(phba);
  4375. return -ENOMEM;
  4376. }
  4377. /**
  4378. * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
  4379. * @phba: pointer to lpfc hba data structure.
  4380. *
  4381. * This routine is invoked to post rpi header templates to the
  4382. * HBA consistent with the SLI-4 interface spec. This routine
  4383. * posts a PAGE_SIZE memory region to the port to hold up to
  4384. * PAGE_SIZE modulo 64 rpi context headers.
  4385. * No locks are held here because this is an initialization routine
  4386. * called only from probe or lpfc_online when interrupts are not
  4387. * enabled and the driver is reinitializing the device.
  4388. *
  4389. * Return codes
  4390. * 0 - successful
  4391. * -ENOMEM - No availble memory
  4392. * -EIO - The mailbox failed to complete successfully.
  4393. **/
  4394. int
  4395. lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
  4396. {
  4397. int rc = 0;
  4398. int longs;
  4399. uint16_t rpi_count;
  4400. struct lpfc_rpi_hdr *rpi_hdr;
  4401. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
  4402. /*
  4403. * Provision an rpi bitmask range for discovery. The total count
  4404. * is the difference between max and base + 1.
  4405. */
  4406. rpi_count = phba->sli4_hba.max_cfg_param.rpi_base +
  4407. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  4408. longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  4409. phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long),
  4410. GFP_KERNEL);
  4411. if (!phba->sli4_hba.rpi_bmask)
  4412. return -ENOMEM;
  4413. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  4414. if (!rpi_hdr) {
  4415. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  4416. "0391 Error during rpi post operation\n");
  4417. lpfc_sli4_remove_rpis(phba);
  4418. rc = -ENODEV;
  4419. }
  4420. return rc;
  4421. }
  4422. /**
  4423. * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
  4424. * @phba: pointer to lpfc hba data structure.
  4425. *
  4426. * This routine is invoked to allocate a single 4KB memory region to
  4427. * support rpis and stores them in the phba. This single region
  4428. * provides support for up to 64 rpis. The region is used globally
  4429. * by the device.
  4430. *
  4431. * Returns:
  4432. * A valid rpi hdr on success.
  4433. * A NULL pointer on any failure.
  4434. **/
  4435. struct lpfc_rpi_hdr *
  4436. lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
  4437. {
  4438. uint16_t rpi_limit, curr_rpi_range;
  4439. struct lpfc_dmabuf *dmabuf;
  4440. struct lpfc_rpi_hdr *rpi_hdr;
  4441. rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
  4442. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  4443. spin_lock_irq(&phba->hbalock);
  4444. curr_rpi_range = phba->sli4_hba.next_rpi;
  4445. spin_unlock_irq(&phba->hbalock);
  4446. /*
  4447. * The port has a limited number of rpis. The increment here
  4448. * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
  4449. * and to allow the full max_rpi range per port.
  4450. */
  4451. if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
  4452. return NULL;
  4453. /*
  4454. * First allocate the protocol header region for the port. The
  4455. * port expects a 4KB DMA-mapped memory region that is 4K aligned.
  4456. */
  4457. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4458. if (!dmabuf)
  4459. return NULL;
  4460. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4461. LPFC_HDR_TEMPLATE_SIZE,
  4462. &dmabuf->phys,
  4463. GFP_KERNEL);
  4464. if (!dmabuf->virt) {
  4465. rpi_hdr = NULL;
  4466. goto err_free_dmabuf;
  4467. }
  4468. memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
  4469. if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
  4470. rpi_hdr = NULL;
  4471. goto err_free_coherent;
  4472. }
  4473. /* Save the rpi header data for cleanup later. */
  4474. rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
  4475. if (!rpi_hdr)
  4476. goto err_free_coherent;
  4477. rpi_hdr->dmabuf = dmabuf;
  4478. rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
  4479. rpi_hdr->page_count = 1;
  4480. spin_lock_irq(&phba->hbalock);
  4481. rpi_hdr->start_rpi = phba->sli4_hba.next_rpi;
  4482. list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
  4483. /*
  4484. * The next_rpi stores the next module-64 rpi value to post
  4485. * in any subsequent rpi memory region postings.
  4486. */
  4487. phba->sli4_hba.next_rpi += LPFC_RPI_HDR_COUNT;
  4488. spin_unlock_irq(&phba->hbalock);
  4489. return rpi_hdr;
  4490. err_free_coherent:
  4491. dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
  4492. dmabuf->virt, dmabuf->phys);
  4493. err_free_dmabuf:
  4494. kfree(dmabuf);
  4495. return NULL;
  4496. }
  4497. /**
  4498. * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
  4499. * @phba: pointer to lpfc hba data structure.
  4500. *
  4501. * This routine is invoked to remove all memory resources allocated
  4502. * to support rpis. This routine presumes the caller has released all
  4503. * rpis consumed by fabric or port logins and is prepared to have
  4504. * the header pages removed.
  4505. **/
  4506. void
  4507. lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
  4508. {
  4509. struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
  4510. list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
  4511. &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  4512. list_del(&rpi_hdr->list);
  4513. dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
  4514. rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
  4515. kfree(rpi_hdr->dmabuf);
  4516. kfree(rpi_hdr);
  4517. }
  4518. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
  4519. memset(phba->sli4_hba.rpi_bmask, 0, sizeof(*phba->sli4_hba.rpi_bmask));
  4520. }
  4521. /**
  4522. * lpfc_hba_alloc - Allocate driver hba data structure for a device.
  4523. * @pdev: pointer to pci device data structure.
  4524. *
  4525. * This routine is invoked to allocate the driver hba data structure for an
  4526. * HBA device. If the allocation is successful, the phba reference to the
  4527. * PCI device data structure is set.
  4528. *
  4529. * Return codes
  4530. * pointer to @phba - successful
  4531. * NULL - error
  4532. **/
  4533. static struct lpfc_hba *
  4534. lpfc_hba_alloc(struct pci_dev *pdev)
  4535. {
  4536. struct lpfc_hba *phba;
  4537. /* Allocate memory for HBA structure */
  4538. phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
  4539. if (!phba) {
  4540. dev_err(&pdev->dev, "failed to allocate hba struct\n");
  4541. return NULL;
  4542. }
  4543. /* Set reference to PCI device in HBA structure */
  4544. phba->pcidev = pdev;
  4545. /* Assign an unused board number */
  4546. phba->brd_no = lpfc_get_instance();
  4547. if (phba->brd_no < 0) {
  4548. kfree(phba);
  4549. return NULL;
  4550. }
  4551. spin_lock_init(&phba->ct_ev_lock);
  4552. INIT_LIST_HEAD(&phba->ct_ev_waiters);
  4553. return phba;
  4554. }
  4555. /**
  4556. * lpfc_hba_free - Free driver hba data structure with a device.
  4557. * @phba: pointer to lpfc hba data structure.
  4558. *
  4559. * This routine is invoked to free the driver hba data structure with an
  4560. * HBA device.
  4561. **/
  4562. static void
  4563. lpfc_hba_free(struct lpfc_hba *phba)
  4564. {
  4565. /* Release the driver assigned board number */
  4566. idr_remove(&lpfc_hba_index, phba->brd_no);
  4567. kfree(phba);
  4568. return;
  4569. }
  4570. /**
  4571. * lpfc_create_shost - Create hba physical port with associated scsi host.
  4572. * @phba: pointer to lpfc hba data structure.
  4573. *
  4574. * This routine is invoked to create HBA physical port and associate a SCSI
  4575. * host with it.
  4576. *
  4577. * Return codes
  4578. * 0 - successful
  4579. * other values - error
  4580. **/
  4581. static int
  4582. lpfc_create_shost(struct lpfc_hba *phba)
  4583. {
  4584. struct lpfc_vport *vport;
  4585. struct Scsi_Host *shost;
  4586. /* Initialize HBA FC structure */
  4587. phba->fc_edtov = FF_DEF_EDTOV;
  4588. phba->fc_ratov = FF_DEF_RATOV;
  4589. phba->fc_altov = FF_DEF_ALTOV;
  4590. phba->fc_arbtov = FF_DEF_ARBTOV;
  4591. atomic_set(&phba->sdev_cnt, 0);
  4592. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  4593. if (!vport)
  4594. return -ENODEV;
  4595. shost = lpfc_shost_from_vport(vport);
  4596. phba->pport = vport;
  4597. lpfc_debugfs_initialize(vport);
  4598. /* Put reference to SCSI host to driver's device private data */
  4599. pci_set_drvdata(phba->pcidev, shost);
  4600. return 0;
  4601. }
  4602. /**
  4603. * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
  4604. * @phba: pointer to lpfc hba data structure.
  4605. *
  4606. * This routine is invoked to destroy HBA physical port and the associated
  4607. * SCSI host.
  4608. **/
  4609. static void
  4610. lpfc_destroy_shost(struct lpfc_hba *phba)
  4611. {
  4612. struct lpfc_vport *vport = phba->pport;
  4613. /* Destroy physical port that associated with the SCSI host */
  4614. destroy_port(vport);
  4615. return;
  4616. }
  4617. /**
  4618. * lpfc_setup_bg - Setup Block guard structures and debug areas.
  4619. * @phba: pointer to lpfc hba data structure.
  4620. * @shost: the shost to be used to detect Block guard settings.
  4621. *
  4622. * This routine sets up the local Block guard protocol settings for @shost.
  4623. * This routine also allocates memory for debugging bg buffers.
  4624. **/
  4625. static void
  4626. lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
  4627. {
  4628. int pagecnt = 10;
  4629. if (lpfc_prot_mask && lpfc_prot_guard) {
  4630. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4631. "1478 Registering BlockGuard with the "
  4632. "SCSI layer\n");
  4633. scsi_host_set_prot(shost, lpfc_prot_mask);
  4634. scsi_host_set_guard(shost, lpfc_prot_guard);
  4635. }
  4636. if (!_dump_buf_data) {
  4637. while (pagecnt) {
  4638. spin_lock_init(&_dump_buf_lock);
  4639. _dump_buf_data =
  4640. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  4641. if (_dump_buf_data) {
  4642. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4643. "9043 BLKGRD: allocated %d pages for "
  4644. "_dump_buf_data at 0x%p\n",
  4645. (1 << pagecnt), _dump_buf_data);
  4646. _dump_buf_data_order = pagecnt;
  4647. memset(_dump_buf_data, 0,
  4648. ((1 << PAGE_SHIFT) << pagecnt));
  4649. break;
  4650. } else
  4651. --pagecnt;
  4652. }
  4653. if (!_dump_buf_data_order)
  4654. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4655. "9044 BLKGRD: ERROR unable to allocate "
  4656. "memory for hexdump\n");
  4657. } else
  4658. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4659. "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
  4660. "\n", _dump_buf_data);
  4661. if (!_dump_buf_dif) {
  4662. while (pagecnt) {
  4663. _dump_buf_dif =
  4664. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  4665. if (_dump_buf_dif) {
  4666. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4667. "9046 BLKGRD: allocated %d pages for "
  4668. "_dump_buf_dif at 0x%p\n",
  4669. (1 << pagecnt), _dump_buf_dif);
  4670. _dump_buf_dif_order = pagecnt;
  4671. memset(_dump_buf_dif, 0,
  4672. ((1 << PAGE_SHIFT) << pagecnt));
  4673. break;
  4674. } else
  4675. --pagecnt;
  4676. }
  4677. if (!_dump_buf_dif_order)
  4678. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4679. "9047 BLKGRD: ERROR unable to allocate "
  4680. "memory for hexdump\n");
  4681. } else
  4682. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4683. "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
  4684. _dump_buf_dif);
  4685. }
  4686. /**
  4687. * lpfc_post_init_setup - Perform necessary device post initialization setup.
  4688. * @phba: pointer to lpfc hba data structure.
  4689. *
  4690. * This routine is invoked to perform all the necessary post initialization
  4691. * setup for the device.
  4692. **/
  4693. static void
  4694. lpfc_post_init_setup(struct lpfc_hba *phba)
  4695. {
  4696. struct Scsi_Host *shost;
  4697. struct lpfc_adapter_event_header adapter_event;
  4698. /* Get the default values for Model Name and Description */
  4699. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  4700. /*
  4701. * hba setup may have changed the hba_queue_depth so we need to
  4702. * adjust the value of can_queue.
  4703. */
  4704. shost = pci_get_drvdata(phba->pcidev);
  4705. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  4706. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  4707. lpfc_setup_bg(phba, shost);
  4708. lpfc_host_attrib_init(shost);
  4709. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  4710. spin_lock_irq(shost->host_lock);
  4711. lpfc_poll_start_timer(phba);
  4712. spin_unlock_irq(shost->host_lock);
  4713. }
  4714. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4715. "0428 Perform SCSI scan\n");
  4716. /* Send board arrival event to upper layer */
  4717. adapter_event.event_type = FC_REG_ADAPTER_EVENT;
  4718. adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
  4719. fc_host_post_vendor_event(shost, fc_get_event_number(),
  4720. sizeof(adapter_event),
  4721. (char *) &adapter_event,
  4722. LPFC_NL_VENDOR_ID);
  4723. return;
  4724. }
  4725. /**
  4726. * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
  4727. * @phba: pointer to lpfc hba data structure.
  4728. *
  4729. * This routine is invoked to set up the PCI device memory space for device
  4730. * with SLI-3 interface spec.
  4731. *
  4732. * Return codes
  4733. * 0 - successful
  4734. * other values - error
  4735. **/
  4736. static int
  4737. lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
  4738. {
  4739. struct pci_dev *pdev;
  4740. unsigned long bar0map_len, bar2map_len;
  4741. int i, hbq_count;
  4742. void *ptr;
  4743. int error = -ENODEV;
  4744. /* Obtain PCI device reference */
  4745. if (!phba->pcidev)
  4746. return error;
  4747. else
  4748. pdev = phba->pcidev;
  4749. /* Set the device DMA mask size */
  4750. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  4751. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  4752. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  4753. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  4754. return error;
  4755. }
  4756. }
  4757. /* Get the bus address of Bar0 and Bar2 and the number of bytes
  4758. * required by each mapping.
  4759. */
  4760. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  4761. bar0map_len = pci_resource_len(pdev, 0);
  4762. phba->pci_bar2_map = pci_resource_start(pdev, 2);
  4763. bar2map_len = pci_resource_len(pdev, 2);
  4764. /* Map HBA SLIM to a kernel virtual address. */
  4765. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  4766. if (!phba->slim_memmap_p) {
  4767. dev_printk(KERN_ERR, &pdev->dev,
  4768. "ioremap failed for SLIM memory.\n");
  4769. goto out;
  4770. }
  4771. /* Map HBA Control Registers to a kernel virtual address. */
  4772. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  4773. if (!phba->ctrl_regs_memmap_p) {
  4774. dev_printk(KERN_ERR, &pdev->dev,
  4775. "ioremap failed for HBA control registers.\n");
  4776. goto out_iounmap_slim;
  4777. }
  4778. /* Allocate memory for SLI-2 structures */
  4779. phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
  4780. SLI2_SLIM_SIZE,
  4781. &phba->slim2p.phys,
  4782. GFP_KERNEL);
  4783. if (!phba->slim2p.virt)
  4784. goto out_iounmap;
  4785. memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
  4786. phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
  4787. phba->mbox_ext = (phba->slim2p.virt +
  4788. offsetof(struct lpfc_sli2_slim, mbx_ext_words));
  4789. phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
  4790. phba->IOCBs = (phba->slim2p.virt +
  4791. offsetof(struct lpfc_sli2_slim, IOCBs));
  4792. phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
  4793. lpfc_sli_hbq_size(),
  4794. &phba->hbqslimp.phys,
  4795. GFP_KERNEL);
  4796. if (!phba->hbqslimp.virt)
  4797. goto out_free_slim;
  4798. hbq_count = lpfc_sli_hbq_count();
  4799. ptr = phba->hbqslimp.virt;
  4800. for (i = 0; i < hbq_count; ++i) {
  4801. phba->hbqs[i].hbq_virt = ptr;
  4802. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  4803. ptr += (lpfc_hbq_defs[i]->entry_count *
  4804. sizeof(struct lpfc_hbq_entry));
  4805. }
  4806. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  4807. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  4808. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  4809. INIT_LIST_HEAD(&phba->rb_pend_list);
  4810. phba->MBslimaddr = phba->slim_memmap_p;
  4811. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  4812. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  4813. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  4814. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  4815. return 0;
  4816. out_free_slim:
  4817. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  4818. phba->slim2p.virt, phba->slim2p.phys);
  4819. out_iounmap:
  4820. iounmap(phba->ctrl_regs_memmap_p);
  4821. out_iounmap_slim:
  4822. iounmap(phba->slim_memmap_p);
  4823. out:
  4824. return error;
  4825. }
  4826. /**
  4827. * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
  4828. * @phba: pointer to lpfc hba data structure.
  4829. *
  4830. * This routine is invoked to unset the PCI device memory space for device
  4831. * with SLI-3 interface spec.
  4832. **/
  4833. static void
  4834. lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
  4835. {
  4836. struct pci_dev *pdev;
  4837. /* Obtain PCI device reference */
  4838. if (!phba->pcidev)
  4839. return;
  4840. else
  4841. pdev = phba->pcidev;
  4842. /* Free coherent DMA memory allocated */
  4843. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  4844. phba->hbqslimp.virt, phba->hbqslimp.phys);
  4845. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  4846. phba->slim2p.virt, phba->slim2p.phys);
  4847. /* I/O memory unmap */
  4848. iounmap(phba->ctrl_regs_memmap_p);
  4849. iounmap(phba->slim_memmap_p);
  4850. return;
  4851. }
  4852. /**
  4853. * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
  4854. * @phba: pointer to lpfc hba data structure.
  4855. *
  4856. * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
  4857. * done and check status.
  4858. *
  4859. * Return 0 if successful, otherwise -ENODEV.
  4860. **/
  4861. int
  4862. lpfc_sli4_post_status_check(struct lpfc_hba *phba)
  4863. {
  4864. struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
  4865. struct lpfc_register reg_data;
  4866. int i, port_error = 0;
  4867. uint32_t if_type;
  4868. if (!phba->sli4_hba.PSMPHRregaddr)
  4869. return -ENODEV;
  4870. /* Wait up to 30 seconds for the SLI Port POST done and ready */
  4871. for (i = 0; i < 3000; i++) {
  4872. portsmphr_reg.word0 = readl(phba->sli4_hba.PSMPHRregaddr);
  4873. if (bf_get(lpfc_port_smphr_perr, &portsmphr_reg)) {
  4874. /* Port has a fatal POST error, break out */
  4875. port_error = -ENODEV;
  4876. break;
  4877. }
  4878. if (LPFC_POST_STAGE_PORT_READY ==
  4879. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
  4880. break;
  4881. msleep(10);
  4882. }
  4883. /*
  4884. * If there was a port error during POST, then don't proceed with
  4885. * other register reads as the data may not be valid. Just exit.
  4886. */
  4887. if (port_error) {
  4888. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4889. "1408 Port Failed POST - portsmphr=0x%x, "
  4890. "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
  4891. "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
  4892. portsmphr_reg.word0,
  4893. bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
  4894. bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
  4895. bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
  4896. bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
  4897. bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
  4898. bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
  4899. bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
  4900. bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
  4901. } else {
  4902. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4903. "2534 Device Info: SLIFamily=0x%x, "
  4904. "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
  4905. "SLIHint_2=0x%x, FT=0x%x\n",
  4906. bf_get(lpfc_sli_intf_sli_family,
  4907. &phba->sli4_hba.sli_intf),
  4908. bf_get(lpfc_sli_intf_slirev,
  4909. &phba->sli4_hba.sli_intf),
  4910. bf_get(lpfc_sli_intf_if_type,
  4911. &phba->sli4_hba.sli_intf),
  4912. bf_get(lpfc_sli_intf_sli_hint1,
  4913. &phba->sli4_hba.sli_intf),
  4914. bf_get(lpfc_sli_intf_sli_hint2,
  4915. &phba->sli4_hba.sli_intf),
  4916. bf_get(lpfc_sli_intf_func_type,
  4917. &phba->sli4_hba.sli_intf));
  4918. /*
  4919. * Check for other Port errors during the initialization
  4920. * process. Fail the load if the port did not come up
  4921. * correctly.
  4922. */
  4923. if_type = bf_get(lpfc_sli_intf_if_type,
  4924. &phba->sli4_hba.sli_intf);
  4925. switch (if_type) {
  4926. case LPFC_SLI_INTF_IF_TYPE_0:
  4927. phba->sli4_hba.ue_mask_lo =
  4928. readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
  4929. phba->sli4_hba.ue_mask_hi =
  4930. readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
  4931. uerrlo_reg.word0 =
  4932. readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
  4933. uerrhi_reg.word0 =
  4934. readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
  4935. if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
  4936. (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
  4937. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4938. "1422 Unrecoverable Error "
  4939. "Detected during POST "
  4940. "uerr_lo_reg=0x%x, "
  4941. "uerr_hi_reg=0x%x, "
  4942. "ue_mask_lo_reg=0x%x, "
  4943. "ue_mask_hi_reg=0x%x\n",
  4944. uerrlo_reg.word0,
  4945. uerrhi_reg.word0,
  4946. phba->sli4_hba.ue_mask_lo,
  4947. phba->sli4_hba.ue_mask_hi);
  4948. port_error = -ENODEV;
  4949. }
  4950. break;
  4951. case LPFC_SLI_INTF_IF_TYPE_2:
  4952. /* Final checks. The port status should be clean. */
  4953. reg_data.word0 =
  4954. readl(phba->sli4_hba.u.if_type2.STATUSregaddr);
  4955. if (bf_get(lpfc_sliport_status_err, &reg_data)) {
  4956. phba->work_status[0] =
  4957. readl(phba->sli4_hba.u.if_type2.
  4958. ERR1regaddr);
  4959. phba->work_status[1] =
  4960. readl(phba->sli4_hba.u.if_type2.
  4961. ERR2regaddr);
  4962. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4963. "2888 Port Error Detected "
  4964. "during POST: "
  4965. "port status reg 0x%x, "
  4966. "port_smphr reg 0x%x, "
  4967. "error 1=0x%x, error 2=0x%x\n",
  4968. reg_data.word0,
  4969. portsmphr_reg.word0,
  4970. phba->work_status[0],
  4971. phba->work_status[1]);
  4972. port_error = -ENODEV;
  4973. }
  4974. break;
  4975. case LPFC_SLI_INTF_IF_TYPE_1:
  4976. default:
  4977. break;
  4978. }
  4979. }
  4980. return port_error;
  4981. }
  4982. /**
  4983. * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
  4984. * @phba: pointer to lpfc hba data structure.
  4985. * @if_type: The SLI4 interface type getting configured.
  4986. *
  4987. * This routine is invoked to set up SLI4 BAR0 PCI config space register
  4988. * memory map.
  4989. **/
  4990. static void
  4991. lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
  4992. {
  4993. switch (if_type) {
  4994. case LPFC_SLI_INTF_IF_TYPE_0:
  4995. phba->sli4_hba.u.if_type0.UERRLOregaddr =
  4996. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
  4997. phba->sli4_hba.u.if_type0.UERRHIregaddr =
  4998. phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
  4999. phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
  5000. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
  5001. phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
  5002. phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
  5003. phba->sli4_hba.SLIINTFregaddr =
  5004. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  5005. break;
  5006. case LPFC_SLI_INTF_IF_TYPE_2:
  5007. phba->sli4_hba.u.if_type2.ERR1regaddr =
  5008. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLIPORT_ERR_1;
  5009. phba->sli4_hba.u.if_type2.ERR2regaddr =
  5010. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLIPORT_ERR_2;
  5011. phba->sli4_hba.u.if_type2.CTRLregaddr =
  5012. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLIPORT_CNTRL;
  5013. phba->sli4_hba.u.if_type2.STATUSregaddr =
  5014. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLIPORT_STATUS;
  5015. phba->sli4_hba.SLIINTFregaddr =
  5016. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
  5017. phba->sli4_hba.PSMPHRregaddr =
  5018. phba->sli4_hba.conf_regs_memmap_p + LPFC_SLIPORT_IF2_SMPHR;
  5019. phba->sli4_hba.RQDBregaddr =
  5020. phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL;
  5021. phba->sli4_hba.WQDBregaddr =
  5022. phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL;
  5023. phba->sli4_hba.EQCQDBregaddr =
  5024. phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
  5025. phba->sli4_hba.MQDBregaddr =
  5026. phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
  5027. phba->sli4_hba.BMBXregaddr =
  5028. phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
  5029. break;
  5030. case LPFC_SLI_INTF_IF_TYPE_1:
  5031. default:
  5032. dev_printk(KERN_ERR, &phba->pcidev->dev,
  5033. "FATAL - unsupported SLI4 interface type - %d\n",
  5034. if_type);
  5035. break;
  5036. }
  5037. }
  5038. /**
  5039. * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
  5040. * @phba: pointer to lpfc hba data structure.
  5041. *
  5042. * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
  5043. * memory map.
  5044. **/
  5045. static void
  5046. lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
  5047. {
  5048. phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5049. LPFC_SLIPORT_IF0_SMPHR;
  5050. phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5051. LPFC_HST_ISR0;
  5052. phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5053. LPFC_HST_IMR0;
  5054. phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  5055. LPFC_HST_ISCR0;
  5056. }
  5057. /**
  5058. * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
  5059. * @phba: pointer to lpfc hba data structure.
  5060. * @vf: virtual function number
  5061. *
  5062. * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
  5063. * based on the given viftual function number, @vf.
  5064. *
  5065. * Return 0 if successful, otherwise -ENODEV.
  5066. **/
  5067. static int
  5068. lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
  5069. {
  5070. if (vf > LPFC_VIR_FUNC_MAX)
  5071. return -ENODEV;
  5072. phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5073. vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
  5074. phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5075. vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
  5076. phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5077. vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
  5078. phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5079. vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
  5080. phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  5081. vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
  5082. return 0;
  5083. }
  5084. /**
  5085. * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
  5086. * @phba: pointer to lpfc hba data structure.
  5087. *
  5088. * This routine is invoked to create the bootstrap mailbox
  5089. * region consistent with the SLI-4 interface spec. This
  5090. * routine allocates all memory necessary to communicate
  5091. * mailbox commands to the port and sets up all alignment
  5092. * needs. No locks are expected to be held when calling
  5093. * this routine.
  5094. *
  5095. * Return codes
  5096. * 0 - successful
  5097. * -ENOMEM - could not allocated memory.
  5098. **/
  5099. static int
  5100. lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
  5101. {
  5102. uint32_t bmbx_size;
  5103. struct lpfc_dmabuf *dmabuf;
  5104. struct dma_address *dma_address;
  5105. uint32_t pa_addr;
  5106. uint64_t phys_addr;
  5107. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  5108. if (!dmabuf)
  5109. return -ENOMEM;
  5110. /*
  5111. * The bootstrap mailbox region is comprised of 2 parts
  5112. * plus an alignment restriction of 16 bytes.
  5113. */
  5114. bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
  5115. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  5116. bmbx_size,
  5117. &dmabuf->phys,
  5118. GFP_KERNEL);
  5119. if (!dmabuf->virt) {
  5120. kfree(dmabuf);
  5121. return -ENOMEM;
  5122. }
  5123. memset(dmabuf->virt, 0, bmbx_size);
  5124. /*
  5125. * Initialize the bootstrap mailbox pointers now so that the register
  5126. * operations are simple later. The mailbox dma address is required
  5127. * to be 16-byte aligned. Also align the virtual memory as each
  5128. * maibox is copied into the bmbx mailbox region before issuing the
  5129. * command to the port.
  5130. */
  5131. phba->sli4_hba.bmbx.dmabuf = dmabuf;
  5132. phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
  5133. phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
  5134. LPFC_ALIGN_16_BYTE);
  5135. phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
  5136. LPFC_ALIGN_16_BYTE);
  5137. /*
  5138. * Set the high and low physical addresses now. The SLI4 alignment
  5139. * requirement is 16 bytes and the mailbox is posted to the port
  5140. * as two 30-bit addresses. The other data is a bit marking whether
  5141. * the 30-bit address is the high or low address.
  5142. * Upcast bmbx aphys to 64bits so shift instruction compiles
  5143. * clean on 32 bit machines.
  5144. */
  5145. dma_address = &phba->sli4_hba.bmbx.dma_address;
  5146. phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
  5147. pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
  5148. dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
  5149. LPFC_BMBX_BIT1_ADDR_HI);
  5150. pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
  5151. dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
  5152. LPFC_BMBX_BIT1_ADDR_LO);
  5153. return 0;
  5154. }
  5155. /**
  5156. * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
  5157. * @phba: pointer to lpfc hba data structure.
  5158. *
  5159. * This routine is invoked to teardown the bootstrap mailbox
  5160. * region and release all host resources. This routine requires
  5161. * the caller to ensure all mailbox commands recovered, no
  5162. * additional mailbox comands are sent, and interrupts are disabled
  5163. * before calling this routine.
  5164. *
  5165. **/
  5166. static void
  5167. lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
  5168. {
  5169. dma_free_coherent(&phba->pcidev->dev,
  5170. phba->sli4_hba.bmbx.bmbx_size,
  5171. phba->sli4_hba.bmbx.dmabuf->virt,
  5172. phba->sli4_hba.bmbx.dmabuf->phys);
  5173. kfree(phba->sli4_hba.bmbx.dmabuf);
  5174. memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
  5175. }
  5176. /**
  5177. * lpfc_sli4_read_config - Get the config parameters.
  5178. * @phba: pointer to lpfc hba data structure.
  5179. *
  5180. * This routine is invoked to read the configuration parameters from the HBA.
  5181. * The configuration parameters are used to set the base and maximum values
  5182. * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
  5183. * allocation for the port.
  5184. *
  5185. * Return codes
  5186. * 0 - successful
  5187. * -ENOMEM - No availble memory
  5188. * -EIO - The mailbox failed to complete successfully.
  5189. **/
  5190. static int
  5191. lpfc_sli4_read_config(struct lpfc_hba *phba)
  5192. {
  5193. LPFC_MBOXQ_t *pmb;
  5194. struct lpfc_mbx_read_config *rd_config;
  5195. uint32_t rc = 0;
  5196. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5197. if (!pmb) {
  5198. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5199. "2011 Unable to allocate memory for issuing "
  5200. "SLI_CONFIG_SPECIAL mailbox command\n");
  5201. return -ENOMEM;
  5202. }
  5203. lpfc_read_config(phba, pmb);
  5204. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  5205. if (rc != MBX_SUCCESS) {
  5206. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5207. "2012 Mailbox failed , mbxCmd x%x "
  5208. "READ_CONFIG, mbxStatus x%x\n",
  5209. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  5210. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  5211. rc = -EIO;
  5212. } else {
  5213. rd_config = &pmb->u.mqe.un.rd_config;
  5214. phba->sli4_hba.max_cfg_param.max_xri =
  5215. bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  5216. phba->sli4_hba.max_cfg_param.xri_base =
  5217. bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
  5218. phba->sli4_hba.max_cfg_param.max_vpi =
  5219. bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
  5220. phba->sli4_hba.max_cfg_param.vpi_base =
  5221. bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
  5222. phba->sli4_hba.max_cfg_param.max_rpi =
  5223. bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  5224. phba->sli4_hba.max_cfg_param.rpi_base =
  5225. bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
  5226. phba->sli4_hba.max_cfg_param.max_vfi =
  5227. bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
  5228. phba->sli4_hba.max_cfg_param.vfi_base =
  5229. bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
  5230. phba->sli4_hba.max_cfg_param.max_fcfi =
  5231. bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
  5232. phba->sli4_hba.max_cfg_param.fcfi_base =
  5233. bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config);
  5234. phba->sli4_hba.max_cfg_param.max_eq =
  5235. bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
  5236. phba->sli4_hba.max_cfg_param.max_rq =
  5237. bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
  5238. phba->sli4_hba.max_cfg_param.max_wq =
  5239. bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
  5240. phba->sli4_hba.max_cfg_param.max_cq =
  5241. bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
  5242. phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
  5243. phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
  5244. phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
  5245. phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
  5246. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
  5247. phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
  5248. (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
  5249. phba->max_vports = phba->max_vpi;
  5250. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5251. "2003 cfg params XRI(B:%d M:%d), "
  5252. "VPI(B:%d M:%d) "
  5253. "VFI(B:%d M:%d) "
  5254. "RPI(B:%d M:%d) "
  5255. "FCFI(B:%d M:%d)\n",
  5256. phba->sli4_hba.max_cfg_param.xri_base,
  5257. phba->sli4_hba.max_cfg_param.max_xri,
  5258. phba->sli4_hba.max_cfg_param.vpi_base,
  5259. phba->sli4_hba.max_cfg_param.max_vpi,
  5260. phba->sli4_hba.max_cfg_param.vfi_base,
  5261. phba->sli4_hba.max_cfg_param.max_vfi,
  5262. phba->sli4_hba.max_cfg_param.rpi_base,
  5263. phba->sli4_hba.max_cfg_param.max_rpi,
  5264. phba->sli4_hba.max_cfg_param.fcfi_base,
  5265. phba->sli4_hba.max_cfg_param.max_fcfi);
  5266. }
  5267. mempool_free(pmb, phba->mbox_mem_pool);
  5268. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  5269. if (phba->cfg_hba_queue_depth >
  5270. (phba->sli4_hba.max_cfg_param.max_xri -
  5271. lpfc_sli4_get_els_iocb_cnt(phba)))
  5272. phba->cfg_hba_queue_depth =
  5273. phba->sli4_hba.max_cfg_param.max_xri -
  5274. lpfc_sli4_get_els_iocb_cnt(phba);
  5275. return rc;
  5276. }
  5277. /**
  5278. * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
  5279. * @phba: pointer to lpfc hba data structure.
  5280. *
  5281. * This routine is invoked to setup the port-side endian order when
  5282. * the port if_type is 0. This routine has no function for other
  5283. * if_types.
  5284. *
  5285. * Return codes
  5286. * 0 - successful
  5287. * -ENOMEM - No availble memory
  5288. * -EIO - The mailbox failed to complete successfully.
  5289. **/
  5290. static int
  5291. lpfc_setup_endian_order(struct lpfc_hba *phba)
  5292. {
  5293. LPFC_MBOXQ_t *mboxq;
  5294. uint32_t if_type, rc = 0;
  5295. uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
  5296. HOST_ENDIAN_HIGH_WORD1};
  5297. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  5298. switch (if_type) {
  5299. case LPFC_SLI_INTF_IF_TYPE_0:
  5300. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  5301. GFP_KERNEL);
  5302. if (!mboxq) {
  5303. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5304. "0492 Unable to allocate memory for "
  5305. "issuing SLI_CONFIG_SPECIAL mailbox "
  5306. "command\n");
  5307. return -ENOMEM;
  5308. }
  5309. /*
  5310. * The SLI4_CONFIG_SPECIAL mailbox command requires the first
  5311. * two words to contain special data values and no other data.
  5312. */
  5313. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  5314. memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
  5315. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5316. if (rc != MBX_SUCCESS) {
  5317. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5318. "0493 SLI_CONFIG_SPECIAL mailbox "
  5319. "failed with status x%x\n",
  5320. rc);
  5321. rc = -EIO;
  5322. }
  5323. mempool_free(mboxq, phba->mbox_mem_pool);
  5324. break;
  5325. case LPFC_SLI_INTF_IF_TYPE_2:
  5326. case LPFC_SLI_INTF_IF_TYPE_1:
  5327. default:
  5328. break;
  5329. }
  5330. return rc;
  5331. }
  5332. /**
  5333. * lpfc_sli4_queue_create - Create all the SLI4 queues
  5334. * @phba: pointer to lpfc hba data structure.
  5335. *
  5336. * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
  5337. * operation. For each SLI4 queue type, the parameters such as queue entry
  5338. * count (queue depth) shall be taken from the module parameter. For now,
  5339. * we just use some constant number as place holder.
  5340. *
  5341. * Return codes
  5342. * 0 - successful
  5343. * -ENOMEM - No availble memory
  5344. * -EIO - The mailbox failed to complete successfully.
  5345. **/
  5346. static int
  5347. lpfc_sli4_queue_create(struct lpfc_hba *phba)
  5348. {
  5349. struct lpfc_queue *qdesc;
  5350. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  5351. int cfg_fcp_wq_count;
  5352. int cfg_fcp_eq_count;
  5353. /*
  5354. * Sanity check for confiugred queue parameters against the run-time
  5355. * device parameters
  5356. */
  5357. /* Sanity check on FCP fast-path WQ parameters */
  5358. cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
  5359. if (cfg_fcp_wq_count >
  5360. (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
  5361. cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
  5362. LPFC_SP_WQN_DEF;
  5363. if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
  5364. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5365. "2581 Not enough WQs (%d) from "
  5366. "the pci function for supporting "
  5367. "FCP WQs (%d)\n",
  5368. phba->sli4_hba.max_cfg_param.max_wq,
  5369. phba->cfg_fcp_wq_count);
  5370. goto out_error;
  5371. }
  5372. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5373. "2582 Not enough WQs (%d) from the pci "
  5374. "function for supporting the requested "
  5375. "FCP WQs (%d), the actual FCP WQs can "
  5376. "be supported: %d\n",
  5377. phba->sli4_hba.max_cfg_param.max_wq,
  5378. phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
  5379. }
  5380. /* The actual number of FCP work queues adopted */
  5381. phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
  5382. /* Sanity check on FCP fast-path EQ parameters */
  5383. cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
  5384. if (cfg_fcp_eq_count >
  5385. (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
  5386. cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
  5387. LPFC_SP_EQN_DEF;
  5388. if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
  5389. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5390. "2574 Not enough EQs (%d) from the "
  5391. "pci function for supporting FCP "
  5392. "EQs (%d)\n",
  5393. phba->sli4_hba.max_cfg_param.max_eq,
  5394. phba->cfg_fcp_eq_count);
  5395. goto out_error;
  5396. }
  5397. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5398. "2575 Not enough EQs (%d) from the pci "
  5399. "function for supporting the requested "
  5400. "FCP EQs (%d), the actual FCP EQs can "
  5401. "be supported: %d\n",
  5402. phba->sli4_hba.max_cfg_param.max_eq,
  5403. phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
  5404. }
  5405. /* It does not make sense to have more EQs than WQs */
  5406. if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
  5407. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5408. "2593 The FCP EQ count(%d) cannot be greater "
  5409. "than the FCP WQ count(%d), limiting the "
  5410. "FCP EQ count to %d\n", cfg_fcp_eq_count,
  5411. phba->cfg_fcp_wq_count,
  5412. phba->cfg_fcp_wq_count);
  5413. cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
  5414. }
  5415. /* The actual number of FCP event queues adopted */
  5416. phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
  5417. /* The overall number of event queues used */
  5418. phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
  5419. /*
  5420. * Create Event Queues (EQs)
  5421. */
  5422. /* Get EQ depth from module parameter, fake the default for now */
  5423. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  5424. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  5425. /* Create slow path event queue */
  5426. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  5427. phba->sli4_hba.eq_ecount);
  5428. if (!qdesc) {
  5429. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5430. "0496 Failed allocate slow-path EQ\n");
  5431. goto out_error;
  5432. }
  5433. phba->sli4_hba.sp_eq = qdesc;
  5434. /* Create fast-path FCP Event Queue(s) */
  5435. phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
  5436. phba->cfg_fcp_eq_count), GFP_KERNEL);
  5437. if (!phba->sli4_hba.fp_eq) {
  5438. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5439. "2576 Failed allocate memory for fast-path "
  5440. "EQ record array\n");
  5441. goto out_free_sp_eq;
  5442. }
  5443. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  5444. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  5445. phba->sli4_hba.eq_ecount);
  5446. if (!qdesc) {
  5447. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5448. "0497 Failed allocate fast-path EQ\n");
  5449. goto out_free_fp_eq;
  5450. }
  5451. phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
  5452. }
  5453. /*
  5454. * Create Complete Queues (CQs)
  5455. */
  5456. /* Get CQ depth from module parameter, fake the default for now */
  5457. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  5458. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  5459. /* Create slow-path Mailbox Command Complete Queue */
  5460. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  5461. phba->sli4_hba.cq_ecount);
  5462. if (!qdesc) {
  5463. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5464. "0500 Failed allocate slow-path mailbox CQ\n");
  5465. goto out_free_fp_eq;
  5466. }
  5467. phba->sli4_hba.mbx_cq = qdesc;
  5468. /* Create slow-path ELS Complete Queue */
  5469. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  5470. phba->sli4_hba.cq_ecount);
  5471. if (!qdesc) {
  5472. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5473. "0501 Failed allocate slow-path ELS CQ\n");
  5474. goto out_free_mbx_cq;
  5475. }
  5476. phba->sli4_hba.els_cq = qdesc;
  5477. /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
  5478. phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
  5479. phba->cfg_fcp_eq_count), GFP_KERNEL);
  5480. if (!phba->sli4_hba.fcp_cq) {
  5481. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5482. "2577 Failed allocate memory for fast-path "
  5483. "CQ record array\n");
  5484. goto out_free_els_cq;
  5485. }
  5486. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
  5487. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  5488. phba->sli4_hba.cq_ecount);
  5489. if (!qdesc) {
  5490. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5491. "0499 Failed allocate fast-path FCP "
  5492. "CQ (%d)\n", fcp_cqidx);
  5493. goto out_free_fcp_cq;
  5494. }
  5495. phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
  5496. }
  5497. /* Create Mailbox Command Queue */
  5498. phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
  5499. phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
  5500. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
  5501. phba->sli4_hba.mq_ecount);
  5502. if (!qdesc) {
  5503. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5504. "0505 Failed allocate slow-path MQ\n");
  5505. goto out_free_fcp_cq;
  5506. }
  5507. phba->sli4_hba.mbx_wq = qdesc;
  5508. /*
  5509. * Create all the Work Queues (WQs)
  5510. */
  5511. phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
  5512. phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
  5513. /* Create slow-path ELS Work Queue */
  5514. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  5515. phba->sli4_hba.wq_ecount);
  5516. if (!qdesc) {
  5517. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5518. "0504 Failed allocate slow-path ELS WQ\n");
  5519. goto out_free_mbx_wq;
  5520. }
  5521. phba->sli4_hba.els_wq = qdesc;
  5522. /* Create fast-path FCP Work Queue(s) */
  5523. phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
  5524. phba->cfg_fcp_wq_count), GFP_KERNEL);
  5525. if (!phba->sli4_hba.fcp_wq) {
  5526. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5527. "2578 Failed allocate memory for fast-path "
  5528. "WQ record array\n");
  5529. goto out_free_els_wq;
  5530. }
  5531. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  5532. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  5533. phba->sli4_hba.wq_ecount);
  5534. if (!qdesc) {
  5535. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5536. "0503 Failed allocate fast-path FCP "
  5537. "WQ (%d)\n", fcp_wqidx);
  5538. goto out_free_fcp_wq;
  5539. }
  5540. phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
  5541. }
  5542. /*
  5543. * Create Receive Queue (RQ)
  5544. */
  5545. phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
  5546. phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
  5547. /* Create Receive Queue for header */
  5548. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  5549. phba->sli4_hba.rq_ecount);
  5550. if (!qdesc) {
  5551. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5552. "0506 Failed allocate receive HRQ\n");
  5553. goto out_free_fcp_wq;
  5554. }
  5555. phba->sli4_hba.hdr_rq = qdesc;
  5556. /* Create Receive Queue for data */
  5557. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  5558. phba->sli4_hba.rq_ecount);
  5559. if (!qdesc) {
  5560. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5561. "0507 Failed allocate receive DRQ\n");
  5562. goto out_free_hdr_rq;
  5563. }
  5564. phba->sli4_hba.dat_rq = qdesc;
  5565. return 0;
  5566. out_free_hdr_rq:
  5567. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  5568. phba->sli4_hba.hdr_rq = NULL;
  5569. out_free_fcp_wq:
  5570. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
  5571. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
  5572. phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
  5573. }
  5574. kfree(phba->sli4_hba.fcp_wq);
  5575. out_free_els_wq:
  5576. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  5577. phba->sli4_hba.els_wq = NULL;
  5578. out_free_mbx_wq:
  5579. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  5580. phba->sli4_hba.mbx_wq = NULL;
  5581. out_free_fcp_cq:
  5582. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
  5583. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
  5584. phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
  5585. }
  5586. kfree(phba->sli4_hba.fcp_cq);
  5587. out_free_els_cq:
  5588. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  5589. phba->sli4_hba.els_cq = NULL;
  5590. out_free_mbx_cq:
  5591. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  5592. phba->sli4_hba.mbx_cq = NULL;
  5593. out_free_fp_eq:
  5594. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
  5595. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
  5596. phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
  5597. }
  5598. kfree(phba->sli4_hba.fp_eq);
  5599. out_free_sp_eq:
  5600. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  5601. phba->sli4_hba.sp_eq = NULL;
  5602. out_error:
  5603. return -ENOMEM;
  5604. }
  5605. /**
  5606. * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
  5607. * @phba: pointer to lpfc hba data structure.
  5608. *
  5609. * This routine is invoked to release all the SLI4 queues with the FCoE HBA
  5610. * operation.
  5611. *
  5612. * Return codes
  5613. * 0 - successful
  5614. * -ENOMEM - No availble memory
  5615. * -EIO - The mailbox failed to complete successfully.
  5616. **/
  5617. static void
  5618. lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
  5619. {
  5620. int fcp_qidx;
  5621. /* Release mailbox command work queue */
  5622. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  5623. phba->sli4_hba.mbx_wq = NULL;
  5624. /* Release ELS work queue */
  5625. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  5626. phba->sli4_hba.els_wq = NULL;
  5627. /* Release FCP work queue */
  5628. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
  5629. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
  5630. kfree(phba->sli4_hba.fcp_wq);
  5631. phba->sli4_hba.fcp_wq = NULL;
  5632. /* Release unsolicited receive queue */
  5633. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  5634. phba->sli4_hba.hdr_rq = NULL;
  5635. lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
  5636. phba->sli4_hba.dat_rq = NULL;
  5637. /* Release ELS complete queue */
  5638. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  5639. phba->sli4_hba.els_cq = NULL;
  5640. /* Release mailbox command complete queue */
  5641. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  5642. phba->sli4_hba.mbx_cq = NULL;
  5643. /* Release FCP response complete queue */
  5644. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5645. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
  5646. kfree(phba->sli4_hba.fcp_cq);
  5647. phba->sli4_hba.fcp_cq = NULL;
  5648. /* Release fast-path event queue */
  5649. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5650. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
  5651. kfree(phba->sli4_hba.fp_eq);
  5652. phba->sli4_hba.fp_eq = NULL;
  5653. /* Release slow-path event queue */
  5654. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  5655. phba->sli4_hba.sp_eq = NULL;
  5656. return;
  5657. }
  5658. /**
  5659. * lpfc_sli4_queue_setup - Set up all the SLI4 queues
  5660. * @phba: pointer to lpfc hba data structure.
  5661. *
  5662. * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
  5663. * operation.
  5664. *
  5665. * Return codes
  5666. * 0 - successful
  5667. * -ENOMEM - No availble memory
  5668. * -EIO - The mailbox failed to complete successfully.
  5669. **/
  5670. int
  5671. lpfc_sli4_queue_setup(struct lpfc_hba *phba)
  5672. {
  5673. int rc = -ENOMEM;
  5674. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  5675. int fcp_cq_index = 0;
  5676. /*
  5677. * Set up Event Queues (EQs)
  5678. */
  5679. /* Set up slow-path event queue */
  5680. if (!phba->sli4_hba.sp_eq) {
  5681. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5682. "0520 Slow-path EQ not allocated\n");
  5683. goto out_error;
  5684. }
  5685. rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
  5686. LPFC_SP_DEF_IMAX);
  5687. if (rc) {
  5688. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5689. "0521 Failed setup of slow-path EQ: "
  5690. "rc = 0x%x\n", rc);
  5691. goto out_error;
  5692. }
  5693. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5694. "2583 Slow-path EQ setup: queue-id=%d\n",
  5695. phba->sli4_hba.sp_eq->queue_id);
  5696. /* Set up fast-path event queue */
  5697. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  5698. if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
  5699. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5700. "0522 Fast-path EQ (%d) not "
  5701. "allocated\n", fcp_eqidx);
  5702. goto out_destroy_fp_eq;
  5703. }
  5704. rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
  5705. phba->cfg_fcp_imax);
  5706. if (rc) {
  5707. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5708. "0523 Failed setup of fast-path EQ "
  5709. "(%d), rc = 0x%x\n", fcp_eqidx, rc);
  5710. goto out_destroy_fp_eq;
  5711. }
  5712. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5713. "2584 Fast-path EQ setup: "
  5714. "queue[%d]-id=%d\n", fcp_eqidx,
  5715. phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
  5716. }
  5717. /*
  5718. * Set up Complete Queues (CQs)
  5719. */
  5720. /* Set up slow-path MBOX Complete Queue as the first CQ */
  5721. if (!phba->sli4_hba.mbx_cq) {
  5722. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5723. "0528 Mailbox CQ not allocated\n");
  5724. goto out_destroy_fp_eq;
  5725. }
  5726. rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
  5727. LPFC_MCQ, LPFC_MBOX);
  5728. if (rc) {
  5729. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5730. "0529 Failed setup of slow-path mailbox CQ: "
  5731. "rc = 0x%x\n", rc);
  5732. goto out_destroy_fp_eq;
  5733. }
  5734. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5735. "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
  5736. phba->sli4_hba.mbx_cq->queue_id,
  5737. phba->sli4_hba.sp_eq->queue_id);
  5738. /* Set up slow-path ELS Complete Queue */
  5739. if (!phba->sli4_hba.els_cq) {
  5740. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5741. "0530 ELS CQ not allocated\n");
  5742. goto out_destroy_mbx_cq;
  5743. }
  5744. rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
  5745. LPFC_WCQ, LPFC_ELS);
  5746. if (rc) {
  5747. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5748. "0531 Failed setup of slow-path ELS CQ: "
  5749. "rc = 0x%x\n", rc);
  5750. goto out_destroy_mbx_cq;
  5751. }
  5752. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5753. "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
  5754. phba->sli4_hba.els_cq->queue_id,
  5755. phba->sli4_hba.sp_eq->queue_id);
  5756. /* Set up fast-path FCP Response Complete Queue */
  5757. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
  5758. if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
  5759. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5760. "0526 Fast-path FCP CQ (%d) not "
  5761. "allocated\n", fcp_cqidx);
  5762. goto out_destroy_fcp_cq;
  5763. }
  5764. rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
  5765. phba->sli4_hba.fp_eq[fcp_cqidx],
  5766. LPFC_WCQ, LPFC_FCP);
  5767. if (rc) {
  5768. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5769. "0527 Failed setup of fast-path FCP "
  5770. "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
  5771. goto out_destroy_fcp_cq;
  5772. }
  5773. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5774. "2588 FCP CQ setup: cq[%d]-id=%d, "
  5775. "parent eq[%d]-id=%d\n",
  5776. fcp_cqidx,
  5777. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
  5778. fcp_cqidx,
  5779. phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id);
  5780. }
  5781. /*
  5782. * Set up all the Work Queues (WQs)
  5783. */
  5784. /* Set up Mailbox Command Queue */
  5785. if (!phba->sli4_hba.mbx_wq) {
  5786. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5787. "0538 Slow-path MQ not allocated\n");
  5788. goto out_destroy_fcp_cq;
  5789. }
  5790. rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
  5791. phba->sli4_hba.mbx_cq, LPFC_MBOX);
  5792. if (rc) {
  5793. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5794. "0539 Failed setup of slow-path MQ: "
  5795. "rc = 0x%x\n", rc);
  5796. goto out_destroy_fcp_cq;
  5797. }
  5798. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5799. "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
  5800. phba->sli4_hba.mbx_wq->queue_id,
  5801. phba->sli4_hba.mbx_cq->queue_id);
  5802. /* Set up slow-path ELS Work Queue */
  5803. if (!phba->sli4_hba.els_wq) {
  5804. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5805. "0536 Slow-path ELS WQ not allocated\n");
  5806. goto out_destroy_mbx_wq;
  5807. }
  5808. rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
  5809. phba->sli4_hba.els_cq, LPFC_ELS);
  5810. if (rc) {
  5811. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5812. "0537 Failed setup of slow-path ELS WQ: "
  5813. "rc = 0x%x\n", rc);
  5814. goto out_destroy_mbx_wq;
  5815. }
  5816. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5817. "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
  5818. phba->sli4_hba.els_wq->queue_id,
  5819. phba->sli4_hba.els_cq->queue_id);
  5820. /* Set up fast-path FCP Work Queue */
  5821. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  5822. if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
  5823. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5824. "0534 Fast-path FCP WQ (%d) not "
  5825. "allocated\n", fcp_wqidx);
  5826. goto out_destroy_fcp_wq;
  5827. }
  5828. rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
  5829. phba->sli4_hba.fcp_cq[fcp_cq_index],
  5830. LPFC_FCP);
  5831. if (rc) {
  5832. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5833. "0535 Failed setup of fast-path FCP "
  5834. "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
  5835. goto out_destroy_fcp_wq;
  5836. }
  5837. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5838. "2591 FCP WQ setup: wq[%d]-id=%d, "
  5839. "parent cq[%d]-id=%d\n",
  5840. fcp_wqidx,
  5841. phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
  5842. fcp_cq_index,
  5843. phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
  5844. /* Round robin FCP Work Queue's Completion Queue assignment */
  5845. fcp_cq_index = ((fcp_cq_index + 1) % phba->cfg_fcp_eq_count);
  5846. }
  5847. /*
  5848. * Create Receive Queue (RQ)
  5849. */
  5850. if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
  5851. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5852. "0540 Receive Queue not allocated\n");
  5853. goto out_destroy_fcp_wq;
  5854. }
  5855. rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  5856. phba->sli4_hba.els_cq, LPFC_USOL);
  5857. if (rc) {
  5858. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5859. "0541 Failed setup of Receive Queue: "
  5860. "rc = 0x%x\n", rc);
  5861. goto out_destroy_fcp_wq;
  5862. }
  5863. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5864. "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
  5865. "parent cq-id=%d\n",
  5866. phba->sli4_hba.hdr_rq->queue_id,
  5867. phba->sli4_hba.dat_rq->queue_id,
  5868. phba->sli4_hba.els_cq->queue_id);
  5869. return 0;
  5870. out_destroy_fcp_wq:
  5871. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
  5872. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
  5873. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  5874. out_destroy_mbx_wq:
  5875. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  5876. out_destroy_fcp_cq:
  5877. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
  5878. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
  5879. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  5880. out_destroy_mbx_cq:
  5881. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  5882. out_destroy_fp_eq:
  5883. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
  5884. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
  5885. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  5886. out_error:
  5887. return rc;
  5888. }
  5889. /**
  5890. * lpfc_sli4_queue_unset - Unset all the SLI4 queues
  5891. * @phba: pointer to lpfc hba data structure.
  5892. *
  5893. * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
  5894. * operation.
  5895. *
  5896. * Return codes
  5897. * 0 - successful
  5898. * -ENOMEM - No availble memory
  5899. * -EIO - The mailbox failed to complete successfully.
  5900. **/
  5901. void
  5902. lpfc_sli4_queue_unset(struct lpfc_hba *phba)
  5903. {
  5904. int fcp_qidx;
  5905. /* Unset mailbox command work queue */
  5906. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  5907. /* Unset ELS work queue */
  5908. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  5909. /* Unset unsolicited receive queue */
  5910. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
  5911. /* Unset FCP work queue */
  5912. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
  5913. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
  5914. /* Unset mailbox command complete queue */
  5915. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  5916. /* Unset ELS complete queue */
  5917. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  5918. /* Unset FCP response complete queue */
  5919. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5920. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
  5921. /* Unset fast-path event queue */
  5922. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5923. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
  5924. /* Unset slow-path event queue */
  5925. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  5926. }
  5927. /**
  5928. * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
  5929. * @phba: pointer to lpfc hba data structure.
  5930. *
  5931. * This routine is invoked to allocate and set up a pool of completion queue
  5932. * events. The body of the completion queue event is a completion queue entry
  5933. * CQE. For now, this pool is used for the interrupt service routine to queue
  5934. * the following HBA completion queue events for the worker thread to process:
  5935. * - Mailbox asynchronous events
  5936. * - Receive queue completion unsolicited events
  5937. * Later, this can be used for all the slow-path events.
  5938. *
  5939. * Return codes
  5940. * 0 - successful
  5941. * -ENOMEM - No availble memory
  5942. **/
  5943. static int
  5944. lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
  5945. {
  5946. struct lpfc_cq_event *cq_event;
  5947. int i;
  5948. for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
  5949. cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
  5950. if (!cq_event)
  5951. goto out_pool_create_fail;
  5952. list_add_tail(&cq_event->list,
  5953. &phba->sli4_hba.sp_cqe_event_pool);
  5954. }
  5955. return 0;
  5956. out_pool_create_fail:
  5957. lpfc_sli4_cq_event_pool_destroy(phba);
  5958. return -ENOMEM;
  5959. }
  5960. /**
  5961. * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
  5962. * @phba: pointer to lpfc hba data structure.
  5963. *
  5964. * This routine is invoked to free the pool of completion queue events at
  5965. * driver unload time. Note that, it is the responsibility of the driver
  5966. * cleanup routine to free all the outstanding completion-queue events
  5967. * allocated from this pool back into the pool before invoking this routine
  5968. * to destroy the pool.
  5969. **/
  5970. static void
  5971. lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
  5972. {
  5973. struct lpfc_cq_event *cq_event, *next_cq_event;
  5974. list_for_each_entry_safe(cq_event, next_cq_event,
  5975. &phba->sli4_hba.sp_cqe_event_pool, list) {
  5976. list_del(&cq_event->list);
  5977. kfree(cq_event);
  5978. }
  5979. }
  5980. /**
  5981. * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  5982. * @phba: pointer to lpfc hba data structure.
  5983. *
  5984. * This routine is the lock free version of the API invoked to allocate a
  5985. * completion-queue event from the free pool.
  5986. *
  5987. * Return: Pointer to the newly allocated completion-queue event if successful
  5988. * NULL otherwise.
  5989. **/
  5990. struct lpfc_cq_event *
  5991. __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  5992. {
  5993. struct lpfc_cq_event *cq_event = NULL;
  5994. list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
  5995. struct lpfc_cq_event, list);
  5996. return cq_event;
  5997. }
  5998. /**
  5999. * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  6000. * @phba: pointer to lpfc hba data structure.
  6001. *
  6002. * This routine is the lock version of the API invoked to allocate a
  6003. * completion-queue event from the free pool.
  6004. *
  6005. * Return: Pointer to the newly allocated completion-queue event if successful
  6006. * NULL otherwise.
  6007. **/
  6008. struct lpfc_cq_event *
  6009. lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  6010. {
  6011. struct lpfc_cq_event *cq_event;
  6012. unsigned long iflags;
  6013. spin_lock_irqsave(&phba->hbalock, iflags);
  6014. cq_event = __lpfc_sli4_cq_event_alloc(phba);
  6015. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6016. return cq_event;
  6017. }
  6018. /**
  6019. * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  6020. * @phba: pointer to lpfc hba data structure.
  6021. * @cq_event: pointer to the completion queue event to be freed.
  6022. *
  6023. * This routine is the lock free version of the API invoked to release a
  6024. * completion-queue event back into the free pool.
  6025. **/
  6026. void
  6027. __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  6028. struct lpfc_cq_event *cq_event)
  6029. {
  6030. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
  6031. }
  6032. /**
  6033. * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  6034. * @phba: pointer to lpfc hba data structure.
  6035. * @cq_event: pointer to the completion queue event to be freed.
  6036. *
  6037. * This routine is the lock version of the API invoked to release a
  6038. * completion-queue event back into the free pool.
  6039. **/
  6040. void
  6041. lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  6042. struct lpfc_cq_event *cq_event)
  6043. {
  6044. unsigned long iflags;
  6045. spin_lock_irqsave(&phba->hbalock, iflags);
  6046. __lpfc_sli4_cq_event_release(phba, cq_event);
  6047. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6048. }
  6049. /**
  6050. * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
  6051. * @phba: pointer to lpfc hba data structure.
  6052. *
  6053. * This routine is to free all the pending completion-queue events to the
  6054. * back into the free pool for device reset.
  6055. **/
  6056. static void
  6057. lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
  6058. {
  6059. LIST_HEAD(cqelist);
  6060. struct lpfc_cq_event *cqe;
  6061. unsigned long iflags;
  6062. /* Retrieve all the pending WCQEs from pending WCQE lists */
  6063. spin_lock_irqsave(&phba->hbalock, iflags);
  6064. /* Pending FCP XRI abort events */
  6065. list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  6066. &cqelist);
  6067. /* Pending ELS XRI abort events */
  6068. list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  6069. &cqelist);
  6070. /* Pending asynnc events */
  6071. list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
  6072. &cqelist);
  6073. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6074. while (!list_empty(&cqelist)) {
  6075. list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
  6076. lpfc_sli4_cq_event_release(phba, cqe);
  6077. }
  6078. }
  6079. /**
  6080. * lpfc_pci_function_reset - Reset pci function.
  6081. * @phba: pointer to lpfc hba data structure.
  6082. *
  6083. * This routine is invoked to request a PCI function reset. It will destroys
  6084. * all resources assigned to the PCI function which originates this request.
  6085. *
  6086. * Return codes
  6087. * 0 - successful
  6088. * -ENOMEM - No availble memory
  6089. * -EIO - The mailbox failed to complete successfully.
  6090. **/
  6091. int
  6092. lpfc_pci_function_reset(struct lpfc_hba *phba)
  6093. {
  6094. LPFC_MBOXQ_t *mboxq;
  6095. uint32_t rc = 0, if_type;
  6096. uint32_t shdr_status, shdr_add_status;
  6097. uint32_t rdy_chk, num_resets = 0, reset_again = 0;
  6098. union lpfc_sli4_cfg_shdr *shdr;
  6099. struct lpfc_register reg_data;
  6100. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  6101. switch (if_type) {
  6102. case LPFC_SLI_INTF_IF_TYPE_0:
  6103. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  6104. GFP_KERNEL);
  6105. if (!mboxq) {
  6106. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6107. "0494 Unable to allocate memory for "
  6108. "issuing SLI_FUNCTION_RESET mailbox "
  6109. "command\n");
  6110. return -ENOMEM;
  6111. }
  6112. /* Setup PCI function reset mailbox-ioctl command */
  6113. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  6114. LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
  6115. LPFC_SLI4_MBX_EMBED);
  6116. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6117. shdr = (union lpfc_sli4_cfg_shdr *)
  6118. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  6119. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6120. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  6121. &shdr->response);
  6122. if (rc != MBX_TIMEOUT)
  6123. mempool_free(mboxq, phba->mbox_mem_pool);
  6124. if (shdr_status || shdr_add_status || rc) {
  6125. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6126. "0495 SLI_FUNCTION_RESET mailbox "
  6127. "failed with status x%x add_status x%x,"
  6128. " mbx status x%x\n",
  6129. shdr_status, shdr_add_status, rc);
  6130. rc = -ENXIO;
  6131. }
  6132. break;
  6133. case LPFC_SLI_INTF_IF_TYPE_2:
  6134. for (num_resets = 0;
  6135. num_resets < MAX_IF_TYPE_2_RESETS;
  6136. num_resets++) {
  6137. reg_data.word0 = 0;
  6138. bf_set(lpfc_sliport_ctrl_end, &reg_data,
  6139. LPFC_SLIPORT_LITTLE_ENDIAN);
  6140. bf_set(lpfc_sliport_ctrl_ip, &reg_data,
  6141. LPFC_SLIPORT_INIT_PORT);
  6142. writel(reg_data.word0, phba->sli4_hba.u.if_type2.
  6143. CTRLregaddr);
  6144. /*
  6145. * Poll the Port Status Register and wait for RDY for
  6146. * up to 10 seconds. If the port doesn't respond, treat
  6147. * it as an error. If the port responds with RN, start
  6148. * the loop again.
  6149. */
  6150. for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) {
  6151. reg_data.word0 =
  6152. readl(phba->sli4_hba.u.if_type2.
  6153. STATUSregaddr);
  6154. if (bf_get(lpfc_sliport_status_rdy, &reg_data))
  6155. break;
  6156. if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
  6157. reset_again++;
  6158. break;
  6159. }
  6160. msleep(10);
  6161. }
  6162. /*
  6163. * If the port responds to the init request with
  6164. * reset needed, delay for a bit and restart the loop.
  6165. */
  6166. if (reset_again) {
  6167. msleep(10);
  6168. reset_again = 0;
  6169. continue;
  6170. }
  6171. /* Detect any port errors. */
  6172. reg_data.word0 = readl(phba->sli4_hba.u.if_type2.
  6173. STATUSregaddr);
  6174. if ((bf_get(lpfc_sliport_status_err, &reg_data)) ||
  6175. (rdy_chk >= 1000)) {
  6176. phba->work_status[0] = readl(
  6177. phba->sli4_hba.u.if_type2.ERR1regaddr);
  6178. phba->work_status[1] = readl(
  6179. phba->sli4_hba.u.if_type2.ERR2regaddr);
  6180. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6181. "2890 Port Error Detected "
  6182. "during Port Reset: "
  6183. "port status reg 0x%x, "
  6184. "error 1=0x%x, error 2=0x%x\n",
  6185. reg_data.word0,
  6186. phba->work_status[0],
  6187. phba->work_status[1]);
  6188. rc = -ENODEV;
  6189. }
  6190. /*
  6191. * Terminate the outer loop provided the Port indicated
  6192. * ready within 10 seconds.
  6193. */
  6194. if (rdy_chk < 1000)
  6195. break;
  6196. }
  6197. break;
  6198. case LPFC_SLI_INTF_IF_TYPE_1:
  6199. default:
  6200. break;
  6201. }
  6202. /* Catch the not-ready port failure after a port reset. */
  6203. if (num_resets >= MAX_IF_TYPE_2_RESETS)
  6204. rc = -ENODEV;
  6205. return rc;
  6206. }
  6207. /**
  6208. * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
  6209. * @phba: pointer to lpfc hba data structure.
  6210. * @cnt: number of nop mailbox commands to send.
  6211. *
  6212. * This routine is invoked to send a number @cnt of NOP mailbox command and
  6213. * wait for each command to complete.
  6214. *
  6215. * Return: the number of NOP mailbox command completed.
  6216. **/
  6217. static int
  6218. lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
  6219. {
  6220. LPFC_MBOXQ_t *mboxq;
  6221. int length, cmdsent;
  6222. uint32_t mbox_tmo;
  6223. uint32_t rc = 0;
  6224. uint32_t shdr_status, shdr_add_status;
  6225. union lpfc_sli4_cfg_shdr *shdr;
  6226. if (cnt == 0) {
  6227. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6228. "2518 Requested to send 0 NOP mailbox cmd\n");
  6229. return cnt;
  6230. }
  6231. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6232. if (!mboxq) {
  6233. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6234. "2519 Unable to allocate memory for issuing "
  6235. "NOP mailbox command\n");
  6236. return 0;
  6237. }
  6238. /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
  6239. length = (sizeof(struct lpfc_mbx_nop) -
  6240. sizeof(struct lpfc_sli4_cfg_mhdr));
  6241. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  6242. LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
  6243. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  6244. for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
  6245. if (!phba->sli4_hba.intr_enable)
  6246. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  6247. else
  6248. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  6249. if (rc == MBX_TIMEOUT)
  6250. break;
  6251. /* Check return status */
  6252. shdr = (union lpfc_sli4_cfg_shdr *)
  6253. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  6254. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6255. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  6256. &shdr->response);
  6257. if (shdr_status || shdr_add_status || rc) {
  6258. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6259. "2520 NOP mailbox command failed "
  6260. "status x%x add_status x%x mbx "
  6261. "status x%x\n", shdr_status,
  6262. shdr_add_status, rc);
  6263. break;
  6264. }
  6265. }
  6266. if (rc != MBX_TIMEOUT)
  6267. mempool_free(mboxq, phba->mbox_mem_pool);
  6268. return cmdsent;
  6269. }
  6270. /**
  6271. * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
  6272. * @phba: pointer to lpfc hba data structure.
  6273. *
  6274. * This routine is invoked to set up the PCI device memory space for device
  6275. * with SLI-4 interface spec.
  6276. *
  6277. * Return codes
  6278. * 0 - successful
  6279. * other values - error
  6280. **/
  6281. static int
  6282. lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
  6283. {
  6284. struct pci_dev *pdev;
  6285. unsigned long bar0map_len, bar1map_len, bar2map_len;
  6286. int error = -ENODEV;
  6287. uint32_t if_type;
  6288. /* Obtain PCI device reference */
  6289. if (!phba->pcidev)
  6290. return error;
  6291. else
  6292. pdev = phba->pcidev;
  6293. /* Set the device DMA mask size */
  6294. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  6295. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  6296. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  6297. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  6298. return error;
  6299. }
  6300. }
  6301. /*
  6302. * The BARs and register set definitions and offset locations are
  6303. * dependent on the if_type.
  6304. */
  6305. if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
  6306. &phba->sli4_hba.sli_intf.word0)) {
  6307. return error;
  6308. }
  6309. /* There is no SLI3 failback for SLI4 devices. */
  6310. if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
  6311. LPFC_SLI_INTF_VALID) {
  6312. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6313. "2894 SLI_INTF reg contents invalid "
  6314. "sli_intf reg 0x%x\n",
  6315. phba->sli4_hba.sli_intf.word0);
  6316. return error;
  6317. }
  6318. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  6319. /*
  6320. * Get the bus address of SLI4 device Bar regions and the
  6321. * number of bytes required by each mapping. The mapping of the
  6322. * particular PCI BARs regions is dependent on the type of
  6323. * SLI4 device.
  6324. */
  6325. if (pci_resource_start(pdev, 0)) {
  6326. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  6327. bar0map_len = pci_resource_len(pdev, 0);
  6328. /*
  6329. * Map SLI4 PCI Config Space Register base to a kernel virtual
  6330. * addr
  6331. */
  6332. phba->sli4_hba.conf_regs_memmap_p =
  6333. ioremap(phba->pci_bar0_map, bar0map_len);
  6334. if (!phba->sli4_hba.conf_regs_memmap_p) {
  6335. dev_printk(KERN_ERR, &pdev->dev,
  6336. "ioremap failed for SLI4 PCI config "
  6337. "registers.\n");
  6338. goto out;
  6339. }
  6340. /* Set up BAR0 PCI config space register memory map */
  6341. lpfc_sli4_bar0_register_memmap(phba, if_type);
  6342. } else {
  6343. phba->pci_bar0_map = pci_resource_start(pdev, 1);
  6344. bar0map_len = pci_resource_len(pdev, 1);
  6345. if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  6346. dev_printk(KERN_ERR, &pdev->dev,
  6347. "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
  6348. goto out;
  6349. }
  6350. phba->sli4_hba.conf_regs_memmap_p =
  6351. ioremap(phba->pci_bar0_map, bar0map_len);
  6352. if (!phba->sli4_hba.conf_regs_memmap_p) {
  6353. dev_printk(KERN_ERR, &pdev->dev,
  6354. "ioremap failed for SLI4 PCI config "
  6355. "registers.\n");
  6356. goto out;
  6357. }
  6358. lpfc_sli4_bar0_register_memmap(phba, if_type);
  6359. }
  6360. if (pci_resource_start(pdev, 2)) {
  6361. /*
  6362. * Map SLI4 if type 0 HBA Control Register base to a kernel
  6363. * virtual address and setup the registers.
  6364. */
  6365. phba->pci_bar1_map = pci_resource_start(pdev, 2);
  6366. bar1map_len = pci_resource_len(pdev, 2);
  6367. phba->sli4_hba.ctrl_regs_memmap_p =
  6368. ioremap(phba->pci_bar1_map, bar1map_len);
  6369. if (!phba->sli4_hba.ctrl_regs_memmap_p) {
  6370. dev_printk(KERN_ERR, &pdev->dev,
  6371. "ioremap failed for SLI4 HBA control registers.\n");
  6372. goto out_iounmap_conf;
  6373. }
  6374. lpfc_sli4_bar1_register_memmap(phba);
  6375. }
  6376. if (pci_resource_start(pdev, 4)) {
  6377. /*
  6378. * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
  6379. * virtual address and setup the registers.
  6380. */
  6381. phba->pci_bar2_map = pci_resource_start(pdev, 4);
  6382. bar2map_len = pci_resource_len(pdev, 4);
  6383. phba->sli4_hba.drbl_regs_memmap_p =
  6384. ioremap(phba->pci_bar2_map, bar2map_len);
  6385. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  6386. dev_printk(KERN_ERR, &pdev->dev,
  6387. "ioremap failed for SLI4 HBA doorbell registers.\n");
  6388. goto out_iounmap_ctrl;
  6389. }
  6390. error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
  6391. if (error)
  6392. goto out_iounmap_all;
  6393. }
  6394. return 0;
  6395. out_iounmap_all:
  6396. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  6397. out_iounmap_ctrl:
  6398. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  6399. out_iounmap_conf:
  6400. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  6401. out:
  6402. return error;
  6403. }
  6404. /**
  6405. * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
  6406. * @phba: pointer to lpfc hba data structure.
  6407. *
  6408. * This routine is invoked to unset the PCI device memory space for device
  6409. * with SLI-4 interface spec.
  6410. **/
  6411. static void
  6412. lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
  6413. {
  6414. struct pci_dev *pdev;
  6415. /* Obtain PCI device reference */
  6416. if (!phba->pcidev)
  6417. return;
  6418. else
  6419. pdev = phba->pcidev;
  6420. /* Free coherent DMA memory allocated */
  6421. /* Unmap I/O memory space */
  6422. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  6423. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  6424. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  6425. return;
  6426. }
  6427. /**
  6428. * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
  6429. * @phba: pointer to lpfc hba data structure.
  6430. *
  6431. * This routine is invoked to enable the MSI-X interrupt vectors to device
  6432. * with SLI-3 interface specs. The kernel function pci_enable_msix() is
  6433. * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
  6434. * invoked, enables either all or nothing, depending on the current
  6435. * availability of PCI vector resources. The device driver is responsible
  6436. * for calling the individual request_irq() to register each MSI-X vector
  6437. * with a interrupt handler, which is done in this function. Note that
  6438. * later when device is unloading, the driver should always call free_irq()
  6439. * on all MSI-X vectors it has done request_irq() on before calling
  6440. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  6441. * will be left with MSI-X enabled and leaks its vectors.
  6442. *
  6443. * Return codes
  6444. * 0 - successful
  6445. * other values - error
  6446. **/
  6447. static int
  6448. lpfc_sli_enable_msix(struct lpfc_hba *phba)
  6449. {
  6450. int rc, i;
  6451. LPFC_MBOXQ_t *pmb;
  6452. /* Set up MSI-X multi-message vectors */
  6453. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  6454. phba->msix_entries[i].entry = i;
  6455. /* Configure MSI-X capability structure */
  6456. rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
  6457. ARRAY_SIZE(phba->msix_entries));
  6458. if (rc) {
  6459. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6460. "0420 PCI enable MSI-X failed (%d)\n", rc);
  6461. goto msi_fail_out;
  6462. }
  6463. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  6464. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6465. "0477 MSI-X entry[%d]: vector=x%x "
  6466. "message=%d\n", i,
  6467. phba->msix_entries[i].vector,
  6468. phba->msix_entries[i].entry);
  6469. /*
  6470. * Assign MSI-X vectors to interrupt handlers
  6471. */
  6472. /* vector-0 is associated to slow-path handler */
  6473. rc = request_irq(phba->msix_entries[0].vector,
  6474. &lpfc_sli_sp_intr_handler, IRQF_SHARED,
  6475. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  6476. if (rc) {
  6477. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6478. "0421 MSI-X slow-path request_irq failed "
  6479. "(%d)\n", rc);
  6480. goto msi_fail_out;
  6481. }
  6482. /* vector-1 is associated to fast-path handler */
  6483. rc = request_irq(phba->msix_entries[1].vector,
  6484. &lpfc_sli_fp_intr_handler, IRQF_SHARED,
  6485. LPFC_FP_DRIVER_HANDLER_NAME, phba);
  6486. if (rc) {
  6487. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6488. "0429 MSI-X fast-path request_irq failed "
  6489. "(%d)\n", rc);
  6490. goto irq_fail_out;
  6491. }
  6492. /*
  6493. * Configure HBA MSI-X attention conditions to messages
  6494. */
  6495. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6496. if (!pmb) {
  6497. rc = -ENOMEM;
  6498. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6499. "0474 Unable to allocate memory for issuing "
  6500. "MBOX_CONFIG_MSI command\n");
  6501. goto mem_fail_out;
  6502. }
  6503. rc = lpfc_config_msi(phba, pmb);
  6504. if (rc)
  6505. goto mbx_fail_out;
  6506. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  6507. if (rc != MBX_SUCCESS) {
  6508. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  6509. "0351 Config MSI mailbox command failed, "
  6510. "mbxCmd x%x, mbxStatus x%x\n",
  6511. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
  6512. goto mbx_fail_out;
  6513. }
  6514. /* Free memory allocated for mailbox command */
  6515. mempool_free(pmb, phba->mbox_mem_pool);
  6516. return rc;
  6517. mbx_fail_out:
  6518. /* Free memory allocated for mailbox command */
  6519. mempool_free(pmb, phba->mbox_mem_pool);
  6520. mem_fail_out:
  6521. /* free the irq already requested */
  6522. free_irq(phba->msix_entries[1].vector, phba);
  6523. irq_fail_out:
  6524. /* free the irq already requested */
  6525. free_irq(phba->msix_entries[0].vector, phba);
  6526. msi_fail_out:
  6527. /* Unconfigure MSI-X capability structure */
  6528. pci_disable_msix(phba->pcidev);
  6529. return rc;
  6530. }
  6531. /**
  6532. * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
  6533. * @phba: pointer to lpfc hba data structure.
  6534. *
  6535. * This routine is invoked to release the MSI-X vectors and then disable the
  6536. * MSI-X interrupt mode to device with SLI-3 interface spec.
  6537. **/
  6538. static void
  6539. lpfc_sli_disable_msix(struct lpfc_hba *phba)
  6540. {
  6541. int i;
  6542. /* Free up MSI-X multi-message vectors */
  6543. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  6544. free_irq(phba->msix_entries[i].vector, phba);
  6545. /* Disable MSI-X */
  6546. pci_disable_msix(phba->pcidev);
  6547. return;
  6548. }
  6549. /**
  6550. * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
  6551. * @phba: pointer to lpfc hba data structure.
  6552. *
  6553. * This routine is invoked to enable the MSI interrupt mode to device with
  6554. * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
  6555. * enable the MSI vector. The device driver is responsible for calling the
  6556. * request_irq() to register MSI vector with a interrupt the handler, which
  6557. * is done in this function.
  6558. *
  6559. * Return codes
  6560. * 0 - successful
  6561. * other values - error
  6562. */
  6563. static int
  6564. lpfc_sli_enable_msi(struct lpfc_hba *phba)
  6565. {
  6566. int rc;
  6567. rc = pci_enable_msi(phba->pcidev);
  6568. if (!rc)
  6569. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6570. "0462 PCI enable MSI mode success.\n");
  6571. else {
  6572. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6573. "0471 PCI enable MSI mode failed (%d)\n", rc);
  6574. return rc;
  6575. }
  6576. rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  6577. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  6578. if (rc) {
  6579. pci_disable_msi(phba->pcidev);
  6580. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6581. "0478 MSI request_irq failed (%d)\n", rc);
  6582. }
  6583. return rc;
  6584. }
  6585. /**
  6586. * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
  6587. * @phba: pointer to lpfc hba data structure.
  6588. *
  6589. * This routine is invoked to disable the MSI interrupt mode to device with
  6590. * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
  6591. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  6592. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  6593. * its vector.
  6594. */
  6595. static void
  6596. lpfc_sli_disable_msi(struct lpfc_hba *phba)
  6597. {
  6598. free_irq(phba->pcidev->irq, phba);
  6599. pci_disable_msi(phba->pcidev);
  6600. return;
  6601. }
  6602. /**
  6603. * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
  6604. * @phba: pointer to lpfc hba data structure.
  6605. *
  6606. * This routine is invoked to enable device interrupt and associate driver's
  6607. * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
  6608. * spec. Depends on the interrupt mode configured to the driver, the driver
  6609. * will try to fallback from the configured interrupt mode to an interrupt
  6610. * mode which is supported by the platform, kernel, and device in the order
  6611. * of:
  6612. * MSI-X -> MSI -> IRQ.
  6613. *
  6614. * Return codes
  6615. * 0 - successful
  6616. * other values - error
  6617. **/
  6618. static uint32_t
  6619. lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  6620. {
  6621. uint32_t intr_mode = LPFC_INTR_ERROR;
  6622. int retval;
  6623. if (cfg_mode == 2) {
  6624. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  6625. retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  6626. if (!retval) {
  6627. /* Now, try to enable MSI-X interrupt mode */
  6628. retval = lpfc_sli_enable_msix(phba);
  6629. if (!retval) {
  6630. /* Indicate initialization to MSI-X mode */
  6631. phba->intr_type = MSIX;
  6632. intr_mode = 2;
  6633. }
  6634. }
  6635. }
  6636. /* Fallback to MSI if MSI-X initialization failed */
  6637. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  6638. retval = lpfc_sli_enable_msi(phba);
  6639. if (!retval) {
  6640. /* Indicate initialization to MSI mode */
  6641. phba->intr_type = MSI;
  6642. intr_mode = 1;
  6643. }
  6644. }
  6645. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  6646. if (phba->intr_type == NONE) {
  6647. retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  6648. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  6649. if (!retval) {
  6650. /* Indicate initialization to INTx mode */
  6651. phba->intr_type = INTx;
  6652. intr_mode = 0;
  6653. }
  6654. }
  6655. return intr_mode;
  6656. }
  6657. /**
  6658. * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
  6659. * @phba: pointer to lpfc hba data structure.
  6660. *
  6661. * This routine is invoked to disable device interrupt and disassociate the
  6662. * driver's interrupt handler(s) from interrupt vector(s) to device with
  6663. * SLI-3 interface spec. Depending on the interrupt mode, the driver will
  6664. * release the interrupt vector(s) for the message signaled interrupt.
  6665. **/
  6666. static void
  6667. lpfc_sli_disable_intr(struct lpfc_hba *phba)
  6668. {
  6669. /* Disable the currently initialized interrupt mode */
  6670. if (phba->intr_type == MSIX)
  6671. lpfc_sli_disable_msix(phba);
  6672. else if (phba->intr_type == MSI)
  6673. lpfc_sli_disable_msi(phba);
  6674. else if (phba->intr_type == INTx)
  6675. free_irq(phba->pcidev->irq, phba);
  6676. /* Reset interrupt management states */
  6677. phba->intr_type = NONE;
  6678. phba->sli.slistat.sli_intr = 0;
  6679. return;
  6680. }
  6681. /**
  6682. * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
  6683. * @phba: pointer to lpfc hba data structure.
  6684. *
  6685. * This routine is invoked to enable the MSI-X interrupt vectors to device
  6686. * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
  6687. * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
  6688. * enables either all or nothing, depending on the current availability of
  6689. * PCI vector resources. The device driver is responsible for calling the
  6690. * individual request_irq() to register each MSI-X vector with a interrupt
  6691. * handler, which is done in this function. Note that later when device is
  6692. * unloading, the driver should always call free_irq() on all MSI-X vectors
  6693. * it has done request_irq() on before calling pci_disable_msix(). Failure
  6694. * to do so results in a BUG_ON() and a device will be left with MSI-X
  6695. * enabled and leaks its vectors.
  6696. *
  6697. * Return codes
  6698. * 0 - successful
  6699. * other values - error
  6700. **/
  6701. static int
  6702. lpfc_sli4_enable_msix(struct lpfc_hba *phba)
  6703. {
  6704. int vectors, rc, index;
  6705. /* Set up MSI-X multi-message vectors */
  6706. for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
  6707. phba->sli4_hba.msix_entries[index].entry = index;
  6708. /* Configure MSI-X capability structure */
  6709. vectors = phba->sli4_hba.cfg_eqn;
  6710. enable_msix_vectors:
  6711. rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
  6712. vectors);
  6713. if (rc > 1) {
  6714. vectors = rc;
  6715. goto enable_msix_vectors;
  6716. } else if (rc) {
  6717. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6718. "0484 PCI enable MSI-X failed (%d)\n", rc);
  6719. goto msi_fail_out;
  6720. }
  6721. /* Log MSI-X vector assignment */
  6722. for (index = 0; index < vectors; index++)
  6723. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6724. "0489 MSI-X entry[%d]: vector=x%x "
  6725. "message=%d\n", index,
  6726. phba->sli4_hba.msix_entries[index].vector,
  6727. phba->sli4_hba.msix_entries[index].entry);
  6728. /*
  6729. * Assign MSI-X vectors to interrupt handlers
  6730. */
  6731. /* The first vector must associated to slow-path handler for MQ */
  6732. rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
  6733. &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
  6734. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  6735. if (rc) {
  6736. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6737. "0485 MSI-X slow-path request_irq failed "
  6738. "(%d)\n", rc);
  6739. goto msi_fail_out;
  6740. }
  6741. /* The rest of the vector(s) are associated to fast-path handler(s) */
  6742. for (index = 1; index < vectors; index++) {
  6743. phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
  6744. phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
  6745. rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
  6746. &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
  6747. LPFC_FP_DRIVER_HANDLER_NAME,
  6748. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  6749. if (rc) {
  6750. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6751. "0486 MSI-X fast-path (%d) "
  6752. "request_irq failed (%d)\n", index, rc);
  6753. goto cfg_fail_out;
  6754. }
  6755. }
  6756. phba->sli4_hba.msix_vec_nr = vectors;
  6757. return rc;
  6758. cfg_fail_out:
  6759. /* free the irq already requested */
  6760. for (--index; index >= 1; index--)
  6761. free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
  6762. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  6763. /* free the irq already requested */
  6764. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  6765. msi_fail_out:
  6766. /* Unconfigure MSI-X capability structure */
  6767. pci_disable_msix(phba->pcidev);
  6768. return rc;
  6769. }
  6770. /**
  6771. * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
  6772. * @phba: pointer to lpfc hba data structure.
  6773. *
  6774. * This routine is invoked to release the MSI-X vectors and then disable the
  6775. * MSI-X interrupt mode to device with SLI-4 interface spec.
  6776. **/
  6777. static void
  6778. lpfc_sli4_disable_msix(struct lpfc_hba *phba)
  6779. {
  6780. int index;
  6781. /* Free up MSI-X multi-message vectors */
  6782. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  6783. for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++)
  6784. free_irq(phba->sli4_hba.msix_entries[index].vector,
  6785. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  6786. /* Disable MSI-X */
  6787. pci_disable_msix(phba->pcidev);
  6788. return;
  6789. }
  6790. /**
  6791. * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
  6792. * @phba: pointer to lpfc hba data structure.
  6793. *
  6794. * This routine is invoked to enable the MSI interrupt mode to device with
  6795. * SLI-4 interface spec. The kernel function pci_enable_msi() is called
  6796. * to enable the MSI vector. The device driver is responsible for calling
  6797. * the request_irq() to register MSI vector with a interrupt the handler,
  6798. * which is done in this function.
  6799. *
  6800. * Return codes
  6801. * 0 - successful
  6802. * other values - error
  6803. **/
  6804. static int
  6805. lpfc_sli4_enable_msi(struct lpfc_hba *phba)
  6806. {
  6807. int rc, index;
  6808. rc = pci_enable_msi(phba->pcidev);
  6809. if (!rc)
  6810. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6811. "0487 PCI enable MSI mode success.\n");
  6812. else {
  6813. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6814. "0488 PCI enable MSI mode failed (%d)\n", rc);
  6815. return rc;
  6816. }
  6817. rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  6818. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  6819. if (rc) {
  6820. pci_disable_msi(phba->pcidev);
  6821. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6822. "0490 MSI request_irq failed (%d)\n", rc);
  6823. return rc;
  6824. }
  6825. for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
  6826. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  6827. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  6828. }
  6829. return 0;
  6830. }
  6831. /**
  6832. * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
  6833. * @phba: pointer to lpfc hba data structure.
  6834. *
  6835. * This routine is invoked to disable the MSI interrupt mode to device with
  6836. * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
  6837. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  6838. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  6839. * its vector.
  6840. **/
  6841. static void
  6842. lpfc_sli4_disable_msi(struct lpfc_hba *phba)
  6843. {
  6844. free_irq(phba->pcidev->irq, phba);
  6845. pci_disable_msi(phba->pcidev);
  6846. return;
  6847. }
  6848. /**
  6849. * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
  6850. * @phba: pointer to lpfc hba data structure.
  6851. *
  6852. * This routine is invoked to enable device interrupt and associate driver's
  6853. * interrupt handler(s) to interrupt vector(s) to device with SLI-4
  6854. * interface spec. Depends on the interrupt mode configured to the driver,
  6855. * the driver will try to fallback from the configured interrupt mode to an
  6856. * interrupt mode which is supported by the platform, kernel, and device in
  6857. * the order of:
  6858. * MSI-X -> MSI -> IRQ.
  6859. *
  6860. * Return codes
  6861. * 0 - successful
  6862. * other values - error
  6863. **/
  6864. static uint32_t
  6865. lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  6866. {
  6867. uint32_t intr_mode = LPFC_INTR_ERROR;
  6868. int retval, index;
  6869. if (cfg_mode == 2) {
  6870. /* Preparation before conf_msi mbox cmd */
  6871. retval = 0;
  6872. if (!retval) {
  6873. /* Now, try to enable MSI-X interrupt mode */
  6874. retval = lpfc_sli4_enable_msix(phba);
  6875. if (!retval) {
  6876. /* Indicate initialization to MSI-X mode */
  6877. phba->intr_type = MSIX;
  6878. intr_mode = 2;
  6879. }
  6880. }
  6881. }
  6882. /* Fallback to MSI if MSI-X initialization failed */
  6883. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  6884. retval = lpfc_sli4_enable_msi(phba);
  6885. if (!retval) {
  6886. /* Indicate initialization to MSI mode */
  6887. phba->intr_type = MSI;
  6888. intr_mode = 1;
  6889. }
  6890. }
  6891. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  6892. if (phba->intr_type == NONE) {
  6893. retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  6894. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  6895. if (!retval) {
  6896. /* Indicate initialization to INTx mode */
  6897. phba->intr_type = INTx;
  6898. intr_mode = 0;
  6899. for (index = 0; index < phba->cfg_fcp_eq_count;
  6900. index++) {
  6901. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  6902. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  6903. }
  6904. }
  6905. }
  6906. return intr_mode;
  6907. }
  6908. /**
  6909. * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
  6910. * @phba: pointer to lpfc hba data structure.
  6911. *
  6912. * This routine is invoked to disable device interrupt and disassociate
  6913. * the driver's interrupt handler(s) from interrupt vector(s) to device
  6914. * with SLI-4 interface spec. Depending on the interrupt mode, the driver
  6915. * will release the interrupt vector(s) for the message signaled interrupt.
  6916. **/
  6917. static void
  6918. lpfc_sli4_disable_intr(struct lpfc_hba *phba)
  6919. {
  6920. /* Disable the currently initialized interrupt mode */
  6921. if (phba->intr_type == MSIX)
  6922. lpfc_sli4_disable_msix(phba);
  6923. else if (phba->intr_type == MSI)
  6924. lpfc_sli4_disable_msi(phba);
  6925. else if (phba->intr_type == INTx)
  6926. free_irq(phba->pcidev->irq, phba);
  6927. /* Reset interrupt management states */
  6928. phba->intr_type = NONE;
  6929. phba->sli.slistat.sli_intr = 0;
  6930. return;
  6931. }
  6932. /**
  6933. * lpfc_unset_hba - Unset SLI3 hba device initialization
  6934. * @phba: pointer to lpfc hba data structure.
  6935. *
  6936. * This routine is invoked to unset the HBA device initialization steps to
  6937. * a device with SLI-3 interface spec.
  6938. **/
  6939. static void
  6940. lpfc_unset_hba(struct lpfc_hba *phba)
  6941. {
  6942. struct lpfc_vport *vport = phba->pport;
  6943. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6944. spin_lock_irq(shost->host_lock);
  6945. vport->load_flag |= FC_UNLOADING;
  6946. spin_unlock_irq(shost->host_lock);
  6947. lpfc_stop_hba_timers(phba);
  6948. phba->pport->work_port_events = 0;
  6949. lpfc_sli_hba_down(phba);
  6950. lpfc_sli_brdrestart(phba);
  6951. lpfc_sli_disable_intr(phba);
  6952. return;
  6953. }
  6954. /**
  6955. * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
  6956. * @phba: pointer to lpfc hba data structure.
  6957. *
  6958. * This routine is invoked to unset the HBA device initialization steps to
  6959. * a device with SLI-4 interface spec.
  6960. **/
  6961. static void
  6962. lpfc_sli4_unset_hba(struct lpfc_hba *phba)
  6963. {
  6964. struct lpfc_vport *vport = phba->pport;
  6965. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6966. spin_lock_irq(shost->host_lock);
  6967. vport->load_flag |= FC_UNLOADING;
  6968. spin_unlock_irq(shost->host_lock);
  6969. phba->pport->work_port_events = 0;
  6970. /* Stop the SLI4 device port */
  6971. lpfc_stop_port(phba);
  6972. lpfc_sli4_disable_intr(phba);
  6973. /* Reset SLI4 HBA FCoE function */
  6974. lpfc_pci_function_reset(phba);
  6975. return;
  6976. }
  6977. /**
  6978. * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
  6979. * @phba: Pointer to HBA context object.
  6980. *
  6981. * This function is called in the SLI4 code path to wait for completion
  6982. * of device's XRIs exchange busy. It will check the XRI exchange busy
  6983. * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
  6984. * that, it will check the XRI exchange busy on outstanding FCP and ELS
  6985. * I/Os every 30 seconds, log error message, and wait forever. Only when
  6986. * all XRI exchange busy complete, the driver unload shall proceed with
  6987. * invoking the function reset ioctl mailbox command to the CNA and the
  6988. * the rest of the driver unload resource release.
  6989. **/
  6990. static void
  6991. lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
  6992. {
  6993. int wait_time = 0;
  6994. int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  6995. int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  6996. while (!fcp_xri_cmpl || !els_xri_cmpl) {
  6997. if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
  6998. if (!fcp_xri_cmpl)
  6999. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7000. "2877 FCP XRI exchange busy "
  7001. "wait time: %d seconds.\n",
  7002. wait_time/1000);
  7003. if (!els_xri_cmpl)
  7004. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7005. "2878 ELS XRI exchange busy "
  7006. "wait time: %d seconds.\n",
  7007. wait_time/1000);
  7008. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
  7009. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
  7010. } else {
  7011. msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
  7012. wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
  7013. }
  7014. fcp_xri_cmpl =
  7015. list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  7016. els_xri_cmpl =
  7017. list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  7018. }
  7019. }
  7020. /**
  7021. * lpfc_sli4_hba_unset - Unset the fcoe hba
  7022. * @phba: Pointer to HBA context object.
  7023. *
  7024. * This function is called in the SLI4 code path to reset the HBA's FCoE
  7025. * function. The caller is not required to hold any lock. This routine
  7026. * issues PCI function reset mailbox command to reset the FCoE function.
  7027. * At the end of the function, it calls lpfc_hba_down_post function to
  7028. * free any pending commands.
  7029. **/
  7030. static void
  7031. lpfc_sli4_hba_unset(struct lpfc_hba *phba)
  7032. {
  7033. int wait_cnt = 0;
  7034. LPFC_MBOXQ_t *mboxq;
  7035. lpfc_stop_hba_timers(phba);
  7036. phba->sli4_hba.intr_enable = 0;
  7037. /*
  7038. * Gracefully wait out the potential current outstanding asynchronous
  7039. * mailbox command.
  7040. */
  7041. /* First, block any pending async mailbox command from posted */
  7042. spin_lock_irq(&phba->hbalock);
  7043. phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  7044. spin_unlock_irq(&phba->hbalock);
  7045. /* Now, trying to wait it out if we can */
  7046. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  7047. msleep(10);
  7048. if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
  7049. break;
  7050. }
  7051. /* Forcefully release the outstanding mailbox command if timed out */
  7052. if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  7053. spin_lock_irq(&phba->hbalock);
  7054. mboxq = phba->sli.mbox_active;
  7055. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  7056. __lpfc_mbox_cmpl_put(phba, mboxq);
  7057. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  7058. phba->sli.mbox_active = NULL;
  7059. spin_unlock_irq(&phba->hbalock);
  7060. }
  7061. /* Abort all iocbs associated with the hba */
  7062. lpfc_sli_hba_iocb_abort(phba);
  7063. /* Wait for completion of device XRI exchange busy */
  7064. lpfc_sli4_xri_exchange_busy_wait(phba);
  7065. /* Disable PCI subsystem interrupt */
  7066. lpfc_sli4_disable_intr(phba);
  7067. /* Stop kthread signal shall trigger work_done one more time */
  7068. kthread_stop(phba->worker_thread);
  7069. /* Reset SLI4 HBA FCoE function */
  7070. lpfc_pci_function_reset(phba);
  7071. /* Stop the SLI4 device port */
  7072. phba->pport->work_port_events = 0;
  7073. }
  7074. /**
  7075. * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
  7076. * @phba: Pointer to HBA context object.
  7077. * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
  7078. *
  7079. * This function is called in the SLI4 code path to read the port's
  7080. * sli4 capabilities.
  7081. *
  7082. * This function may be be called from any context that can block-wait
  7083. * for the completion. The expectation is that this routine is called
  7084. * typically from probe_one or from the online routine.
  7085. **/
  7086. int
  7087. lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  7088. {
  7089. int rc;
  7090. struct lpfc_mqe *mqe;
  7091. struct lpfc_pc_sli4_params *sli4_params;
  7092. uint32_t mbox_tmo;
  7093. rc = 0;
  7094. mqe = &mboxq->u.mqe;
  7095. /* Read the port's SLI4 Parameters port capabilities */
  7096. lpfc_sli4_params(mboxq);
  7097. if (!phba->sli4_hba.intr_enable)
  7098. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7099. else {
  7100. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_PORT_CAPABILITIES);
  7101. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  7102. }
  7103. if (unlikely(rc))
  7104. return 1;
  7105. sli4_params = &phba->sli4_hba.pc_sli4_params;
  7106. sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
  7107. sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
  7108. sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
  7109. sli4_params->featurelevel_1 = bf_get(featurelevel_1,
  7110. &mqe->un.sli4_params);
  7111. sli4_params->featurelevel_2 = bf_get(featurelevel_2,
  7112. &mqe->un.sli4_params);
  7113. sli4_params->proto_types = mqe->un.sli4_params.word3;
  7114. sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
  7115. sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
  7116. sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
  7117. sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
  7118. sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
  7119. sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
  7120. sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
  7121. sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
  7122. sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
  7123. sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
  7124. sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
  7125. sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
  7126. sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
  7127. sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
  7128. sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
  7129. sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
  7130. sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
  7131. sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
  7132. sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
  7133. sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
  7134. return rc;
  7135. }
  7136. /**
  7137. * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
  7138. * @pdev: pointer to PCI device
  7139. * @pid: pointer to PCI device identifier
  7140. *
  7141. * This routine is to be called to attach a device with SLI-3 interface spec
  7142. * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  7143. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  7144. * information of the device and driver to see if the driver state that it can
  7145. * support this kind of device. If the match is successful, the driver core
  7146. * invokes this routine. If this routine determines it can claim the HBA, it
  7147. * does all the initialization that it needs to do to handle the HBA properly.
  7148. *
  7149. * Return code
  7150. * 0 - driver can claim the device
  7151. * negative value - driver can not claim the device
  7152. **/
  7153. static int __devinit
  7154. lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
  7155. {
  7156. struct lpfc_hba *phba;
  7157. struct lpfc_vport *vport = NULL;
  7158. struct Scsi_Host *shost = NULL;
  7159. int error;
  7160. uint32_t cfg_mode, intr_mode;
  7161. /* Allocate memory for HBA structure */
  7162. phba = lpfc_hba_alloc(pdev);
  7163. if (!phba)
  7164. return -ENOMEM;
  7165. /* Perform generic PCI device enabling operation */
  7166. error = lpfc_enable_pci_dev(phba);
  7167. if (error) {
  7168. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7169. "1401 Failed to enable pci device.\n");
  7170. goto out_free_phba;
  7171. }
  7172. /* Set up SLI API function jump table for PCI-device group-0 HBAs */
  7173. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
  7174. if (error)
  7175. goto out_disable_pci_dev;
  7176. /* Set up SLI-3 specific device PCI memory space */
  7177. error = lpfc_sli_pci_mem_setup(phba);
  7178. if (error) {
  7179. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7180. "1402 Failed to set up pci memory space.\n");
  7181. goto out_disable_pci_dev;
  7182. }
  7183. /* Set up phase-1 common device driver resources */
  7184. error = lpfc_setup_driver_resource_phase1(phba);
  7185. if (error) {
  7186. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7187. "1403 Failed to set up driver resource.\n");
  7188. goto out_unset_pci_mem_s3;
  7189. }
  7190. /* Set up SLI-3 specific device driver resources */
  7191. error = lpfc_sli_driver_resource_setup(phba);
  7192. if (error) {
  7193. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7194. "1404 Failed to set up driver resource.\n");
  7195. goto out_unset_pci_mem_s3;
  7196. }
  7197. /* Initialize and populate the iocb list per host */
  7198. error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
  7199. if (error) {
  7200. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7201. "1405 Failed to initialize iocb list.\n");
  7202. goto out_unset_driver_resource_s3;
  7203. }
  7204. /* Set up common device driver resources */
  7205. error = lpfc_setup_driver_resource_phase2(phba);
  7206. if (error) {
  7207. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7208. "1406 Failed to set up driver resource.\n");
  7209. goto out_free_iocb_list;
  7210. }
  7211. /* Create SCSI host to the physical port */
  7212. error = lpfc_create_shost(phba);
  7213. if (error) {
  7214. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7215. "1407 Failed to create scsi host.\n");
  7216. goto out_unset_driver_resource;
  7217. }
  7218. /* Configure sysfs attributes */
  7219. vport = phba->pport;
  7220. error = lpfc_alloc_sysfs_attr(vport);
  7221. if (error) {
  7222. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7223. "1476 Failed to allocate sysfs attr\n");
  7224. goto out_destroy_shost;
  7225. }
  7226. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  7227. /* Now, trying to enable interrupt and bring up the device */
  7228. cfg_mode = phba->cfg_use_msi;
  7229. while (true) {
  7230. /* Put device to a known state before enabling interrupt */
  7231. lpfc_stop_port(phba);
  7232. /* Configure and enable interrupt */
  7233. intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
  7234. if (intr_mode == LPFC_INTR_ERROR) {
  7235. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7236. "0431 Failed to enable interrupt.\n");
  7237. error = -ENODEV;
  7238. goto out_free_sysfs_attr;
  7239. }
  7240. /* SLI-3 HBA setup */
  7241. if (lpfc_sli_hba_setup(phba)) {
  7242. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7243. "1477 Failed to set up hba\n");
  7244. error = -ENODEV;
  7245. goto out_remove_device;
  7246. }
  7247. /* Wait 50ms for the interrupts of previous mailbox commands */
  7248. msleep(50);
  7249. /* Check active interrupts on message signaled interrupts */
  7250. if (intr_mode == 0 ||
  7251. phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
  7252. /* Log the current active interrupt mode */
  7253. phba->intr_mode = intr_mode;
  7254. lpfc_log_intr_mode(phba, intr_mode);
  7255. break;
  7256. } else {
  7257. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7258. "0447 Configure interrupt mode (%d) "
  7259. "failed active interrupt test.\n",
  7260. intr_mode);
  7261. /* Disable the current interrupt mode */
  7262. lpfc_sli_disable_intr(phba);
  7263. /* Try next level of interrupt mode */
  7264. cfg_mode = --intr_mode;
  7265. }
  7266. }
  7267. /* Perform post initialization setup */
  7268. lpfc_post_init_setup(phba);
  7269. /* Check if there are static vports to be created. */
  7270. lpfc_create_static_vport(phba);
  7271. return 0;
  7272. out_remove_device:
  7273. lpfc_unset_hba(phba);
  7274. out_free_sysfs_attr:
  7275. lpfc_free_sysfs_attr(vport);
  7276. out_destroy_shost:
  7277. lpfc_destroy_shost(phba);
  7278. out_unset_driver_resource:
  7279. lpfc_unset_driver_resource_phase2(phba);
  7280. out_free_iocb_list:
  7281. lpfc_free_iocb_list(phba);
  7282. out_unset_driver_resource_s3:
  7283. lpfc_sli_driver_resource_unset(phba);
  7284. out_unset_pci_mem_s3:
  7285. lpfc_sli_pci_mem_unset(phba);
  7286. out_disable_pci_dev:
  7287. lpfc_disable_pci_dev(phba);
  7288. if (shost)
  7289. scsi_host_put(shost);
  7290. out_free_phba:
  7291. lpfc_hba_free(phba);
  7292. return error;
  7293. }
  7294. /**
  7295. * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
  7296. * @pdev: pointer to PCI device
  7297. *
  7298. * This routine is to be called to disattach a device with SLI-3 interface
  7299. * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  7300. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  7301. * device to be removed from the PCI subsystem properly.
  7302. **/
  7303. static void __devexit
  7304. lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  7305. {
  7306. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7307. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  7308. struct lpfc_vport **vports;
  7309. struct lpfc_hba *phba = vport->phba;
  7310. int i;
  7311. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  7312. spin_lock_irq(&phba->hbalock);
  7313. vport->load_flag |= FC_UNLOADING;
  7314. spin_unlock_irq(&phba->hbalock);
  7315. lpfc_free_sysfs_attr(vport);
  7316. /* Release all the vports against this physical port */
  7317. vports = lpfc_create_vport_work_array(phba);
  7318. if (vports != NULL)
  7319. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  7320. fc_vport_terminate(vports[i]->fc_vport);
  7321. lpfc_destroy_vport_work_array(phba, vports);
  7322. /* Remove FC host and then SCSI host with the physical port */
  7323. fc_remove_host(shost);
  7324. scsi_remove_host(shost);
  7325. lpfc_cleanup(vport);
  7326. /*
  7327. * Bring down the SLI Layer. This step disable all interrupts,
  7328. * clears the rings, discards all mailbox commands, and resets
  7329. * the HBA.
  7330. */
  7331. /* HBA interrupt will be diabled after this call */
  7332. lpfc_sli_hba_down(phba);
  7333. /* Stop kthread signal shall trigger work_done one more time */
  7334. kthread_stop(phba->worker_thread);
  7335. /* Final cleanup of txcmplq and reset the HBA */
  7336. lpfc_sli_brdrestart(phba);
  7337. lpfc_stop_hba_timers(phba);
  7338. spin_lock_irq(&phba->hbalock);
  7339. list_del_init(&vport->listentry);
  7340. spin_unlock_irq(&phba->hbalock);
  7341. lpfc_debugfs_terminate(vport);
  7342. /* Disable interrupt */
  7343. lpfc_sli_disable_intr(phba);
  7344. pci_set_drvdata(pdev, NULL);
  7345. scsi_host_put(shost);
  7346. /*
  7347. * Call scsi_free before mem_free since scsi bufs are released to their
  7348. * corresponding pools here.
  7349. */
  7350. lpfc_scsi_free(phba);
  7351. lpfc_mem_free_all(phba);
  7352. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  7353. phba->hbqslimp.virt, phba->hbqslimp.phys);
  7354. /* Free resources associated with SLI2 interface */
  7355. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  7356. phba->slim2p.virt, phba->slim2p.phys);
  7357. /* unmap adapter SLIM and Control Registers */
  7358. iounmap(phba->ctrl_regs_memmap_p);
  7359. iounmap(phba->slim_memmap_p);
  7360. lpfc_hba_free(phba);
  7361. pci_release_selected_regions(pdev, bars);
  7362. pci_disable_device(pdev);
  7363. }
  7364. /**
  7365. * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
  7366. * @pdev: pointer to PCI device
  7367. * @msg: power management message
  7368. *
  7369. * This routine is to be called from the kernel's PCI subsystem to support
  7370. * system Power Management (PM) to device with SLI-3 interface spec. When
  7371. * PM invokes this method, it quiesces the device by stopping the driver's
  7372. * worker thread for the device, turning off device's interrupt and DMA,
  7373. * and bring the device offline. Note that as the driver implements the
  7374. * minimum PM requirements to a power-aware driver's PM support for the
  7375. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  7376. * to the suspend() method call will be treated as SUSPEND and the driver will
  7377. * fully reinitialize its device during resume() method call, the driver will
  7378. * set device to PCI_D3hot state in PCI config space instead of setting it
  7379. * according to the @msg provided by the PM.
  7380. *
  7381. * Return code
  7382. * 0 - driver suspended the device
  7383. * Error otherwise
  7384. **/
  7385. static int
  7386. lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
  7387. {
  7388. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7389. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7390. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7391. "0473 PCI device Power Management suspend.\n");
  7392. /* Bring down the device */
  7393. lpfc_offline_prep(phba);
  7394. lpfc_offline(phba);
  7395. kthread_stop(phba->worker_thread);
  7396. /* Disable interrupt from device */
  7397. lpfc_sli_disable_intr(phba);
  7398. /* Save device state to PCI config space */
  7399. pci_save_state(pdev);
  7400. pci_set_power_state(pdev, PCI_D3hot);
  7401. return 0;
  7402. }
  7403. /**
  7404. * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
  7405. * @pdev: pointer to PCI device
  7406. *
  7407. * This routine is to be called from the kernel's PCI subsystem to support
  7408. * system Power Management (PM) to device with SLI-3 interface spec. When PM
  7409. * invokes this method, it restores the device's PCI config space state and
  7410. * fully reinitializes the device and brings it online. Note that as the
  7411. * driver implements the minimum PM requirements to a power-aware driver's
  7412. * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
  7413. * FREEZE) to the suspend() method call will be treated as SUSPEND and the
  7414. * driver will fully reinitialize its device during resume() method call,
  7415. * the device will be set to PCI_D0 directly in PCI config space before
  7416. * restoring the state.
  7417. *
  7418. * Return code
  7419. * 0 - driver suspended the device
  7420. * Error otherwise
  7421. **/
  7422. static int
  7423. lpfc_pci_resume_one_s3(struct pci_dev *pdev)
  7424. {
  7425. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7426. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7427. uint32_t intr_mode;
  7428. int error;
  7429. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7430. "0452 PCI device Power Management resume.\n");
  7431. /* Restore device state from PCI config space */
  7432. pci_set_power_state(pdev, PCI_D0);
  7433. pci_restore_state(pdev);
  7434. /*
  7435. * As the new kernel behavior of pci_restore_state() API call clears
  7436. * device saved_state flag, need to save the restored state again.
  7437. */
  7438. pci_save_state(pdev);
  7439. if (pdev->is_busmaster)
  7440. pci_set_master(pdev);
  7441. /* Startup the kernel thread for this host adapter. */
  7442. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  7443. "lpfc_worker_%d", phba->brd_no);
  7444. if (IS_ERR(phba->worker_thread)) {
  7445. error = PTR_ERR(phba->worker_thread);
  7446. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7447. "0434 PM resume failed to start worker "
  7448. "thread: error=x%x.\n", error);
  7449. return error;
  7450. }
  7451. /* Configure and enable interrupt */
  7452. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  7453. if (intr_mode == LPFC_INTR_ERROR) {
  7454. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7455. "0430 PM resume Failed to enable interrupt\n");
  7456. return -EIO;
  7457. } else
  7458. phba->intr_mode = intr_mode;
  7459. /* Restart HBA and bring it online */
  7460. lpfc_sli_brdrestart(phba);
  7461. lpfc_online(phba);
  7462. /* Log the current active interrupt mode */
  7463. lpfc_log_intr_mode(phba, phba->intr_mode);
  7464. return 0;
  7465. }
  7466. /**
  7467. * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
  7468. * @phba: pointer to lpfc hba data structure.
  7469. *
  7470. * This routine is called to prepare the SLI3 device for PCI slot recover. It
  7471. * aborts all the outstanding SCSI I/Os to the pci device.
  7472. **/
  7473. static void
  7474. lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
  7475. {
  7476. struct lpfc_sli *psli = &phba->sli;
  7477. struct lpfc_sli_ring *pring;
  7478. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7479. "2723 PCI channel I/O abort preparing for recovery\n");
  7480. /*
  7481. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  7482. * and let the SCSI mid-layer to retry them to recover.
  7483. */
  7484. pring = &psli->ring[psli->fcp_ring];
  7485. lpfc_sli_abort_iocb_ring(phba, pring);
  7486. }
  7487. /**
  7488. * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
  7489. * @phba: pointer to lpfc hba data structure.
  7490. *
  7491. * This routine is called to prepare the SLI3 device for PCI slot reset. It
  7492. * disables the device interrupt and pci device, and aborts the internal FCP
  7493. * pending I/Os.
  7494. **/
  7495. static void
  7496. lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
  7497. {
  7498. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7499. "2710 PCI channel disable preparing for reset\n");
  7500. /* Block any management I/Os to the device */
  7501. lpfc_block_mgmt_io(phba);
  7502. /* Block all SCSI devices' I/Os on the host */
  7503. lpfc_scsi_dev_block(phba);
  7504. /* stop all timers */
  7505. lpfc_stop_hba_timers(phba);
  7506. /* Disable interrupt and pci device */
  7507. lpfc_sli_disable_intr(phba);
  7508. pci_disable_device(phba->pcidev);
  7509. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  7510. lpfc_sli_flush_fcp_rings(phba);
  7511. }
  7512. /**
  7513. * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
  7514. * @phba: pointer to lpfc hba data structure.
  7515. *
  7516. * This routine is called to prepare the SLI3 device for PCI slot permanently
  7517. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  7518. * pending I/Os.
  7519. **/
  7520. static void
  7521. lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  7522. {
  7523. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7524. "2711 PCI channel permanent disable for failure\n");
  7525. /* Block all SCSI devices' I/Os on the host */
  7526. lpfc_scsi_dev_block(phba);
  7527. /* stop all timers */
  7528. lpfc_stop_hba_timers(phba);
  7529. /* Clean up all driver's outstanding SCSI I/Os */
  7530. lpfc_sli_flush_fcp_rings(phba);
  7531. }
  7532. /**
  7533. * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
  7534. * @pdev: pointer to PCI device.
  7535. * @state: the current PCI connection state.
  7536. *
  7537. * This routine is called from the PCI subsystem for I/O error handling to
  7538. * device with SLI-3 interface spec. This function is called by the PCI
  7539. * subsystem after a PCI bus error affecting this device has been detected.
  7540. * When this function is invoked, it will need to stop all the I/Os and
  7541. * interrupt(s) to the device. Once that is done, it will return
  7542. * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
  7543. * as desired.
  7544. *
  7545. * Return codes
  7546. * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
  7547. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  7548. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7549. **/
  7550. static pci_ers_result_t
  7551. lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
  7552. {
  7553. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7554. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7555. switch (state) {
  7556. case pci_channel_io_normal:
  7557. /* Non-fatal error, prepare for recovery */
  7558. lpfc_sli_prep_dev_for_recover(phba);
  7559. return PCI_ERS_RESULT_CAN_RECOVER;
  7560. case pci_channel_io_frozen:
  7561. /* Fatal error, prepare for slot reset */
  7562. lpfc_sli_prep_dev_for_reset(phba);
  7563. return PCI_ERS_RESULT_NEED_RESET;
  7564. case pci_channel_io_perm_failure:
  7565. /* Permanent failure, prepare for device down */
  7566. lpfc_sli_prep_dev_for_perm_failure(phba);
  7567. return PCI_ERS_RESULT_DISCONNECT;
  7568. default:
  7569. /* Unknown state, prepare and request slot reset */
  7570. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7571. "0472 Unknown PCI error state: x%x\n", state);
  7572. lpfc_sli_prep_dev_for_reset(phba);
  7573. return PCI_ERS_RESULT_NEED_RESET;
  7574. }
  7575. }
  7576. /**
  7577. * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
  7578. * @pdev: pointer to PCI device.
  7579. *
  7580. * This routine is called from the PCI subsystem for error handling to
  7581. * device with SLI-3 interface spec. This is called after PCI bus has been
  7582. * reset to restart the PCI card from scratch, as if from a cold-boot.
  7583. * During the PCI subsystem error recovery, after driver returns
  7584. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  7585. * recovery and then call this routine before calling the .resume method
  7586. * to recover the device. This function will initialize the HBA device,
  7587. * enable the interrupt, but it will just put the HBA to offline state
  7588. * without passing any I/O traffic.
  7589. *
  7590. * Return codes
  7591. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  7592. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7593. */
  7594. static pci_ers_result_t
  7595. lpfc_io_slot_reset_s3(struct pci_dev *pdev)
  7596. {
  7597. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7598. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7599. struct lpfc_sli *psli = &phba->sli;
  7600. uint32_t intr_mode;
  7601. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  7602. if (pci_enable_device_mem(pdev)) {
  7603. printk(KERN_ERR "lpfc: Cannot re-enable "
  7604. "PCI device after reset.\n");
  7605. return PCI_ERS_RESULT_DISCONNECT;
  7606. }
  7607. pci_restore_state(pdev);
  7608. /*
  7609. * As the new kernel behavior of pci_restore_state() API call clears
  7610. * device saved_state flag, need to save the restored state again.
  7611. */
  7612. pci_save_state(pdev);
  7613. if (pdev->is_busmaster)
  7614. pci_set_master(pdev);
  7615. spin_lock_irq(&phba->hbalock);
  7616. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  7617. spin_unlock_irq(&phba->hbalock);
  7618. /* Configure and enable interrupt */
  7619. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  7620. if (intr_mode == LPFC_INTR_ERROR) {
  7621. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7622. "0427 Cannot re-enable interrupt after "
  7623. "slot reset.\n");
  7624. return PCI_ERS_RESULT_DISCONNECT;
  7625. } else
  7626. phba->intr_mode = intr_mode;
  7627. /* Take device offline, it will perform cleanup */
  7628. lpfc_offline_prep(phba);
  7629. lpfc_offline(phba);
  7630. lpfc_sli_brdrestart(phba);
  7631. /* Log the current active interrupt mode */
  7632. lpfc_log_intr_mode(phba, phba->intr_mode);
  7633. return PCI_ERS_RESULT_RECOVERED;
  7634. }
  7635. /**
  7636. * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
  7637. * @pdev: pointer to PCI device
  7638. *
  7639. * This routine is called from the PCI subsystem for error handling to device
  7640. * with SLI-3 interface spec. It is called when kernel error recovery tells
  7641. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  7642. * error recovery. After this call, traffic can start to flow from this device
  7643. * again.
  7644. */
  7645. static void
  7646. lpfc_io_resume_s3(struct pci_dev *pdev)
  7647. {
  7648. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7649. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7650. /* Bring device online, it will be no-op for non-fatal error resume */
  7651. lpfc_online(phba);
  7652. /* Clean up Advanced Error Reporting (AER) if needed */
  7653. if (phba->hba_flag & HBA_AER_ENABLED)
  7654. pci_cleanup_aer_uncorrect_error_status(pdev);
  7655. }
  7656. /**
  7657. * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
  7658. * @phba: pointer to lpfc hba data structure.
  7659. *
  7660. * returns the number of ELS/CT IOCBs to reserve
  7661. **/
  7662. int
  7663. lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
  7664. {
  7665. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  7666. if (phba->sli_rev == LPFC_SLI_REV4) {
  7667. if (max_xri <= 100)
  7668. return 10;
  7669. else if (max_xri <= 256)
  7670. return 25;
  7671. else if (max_xri <= 512)
  7672. return 50;
  7673. else if (max_xri <= 1024)
  7674. return 100;
  7675. else
  7676. return 150;
  7677. } else
  7678. return 0;
  7679. }
  7680. /**
  7681. * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
  7682. * @pdev: pointer to PCI device
  7683. * @pid: pointer to PCI device identifier
  7684. *
  7685. * This routine is called from the kernel's PCI subsystem to device with
  7686. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  7687. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  7688. * information of the device and driver to see if the driver state that it
  7689. * can support this kind of device. If the match is successful, the driver
  7690. * core invokes this routine. If this routine determines it can claim the HBA,
  7691. * it does all the initialization that it needs to do to handle the HBA
  7692. * properly.
  7693. *
  7694. * Return code
  7695. * 0 - driver can claim the device
  7696. * negative value - driver can not claim the device
  7697. **/
  7698. static int __devinit
  7699. lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
  7700. {
  7701. struct lpfc_hba *phba;
  7702. struct lpfc_vport *vport = NULL;
  7703. struct Scsi_Host *shost = NULL;
  7704. int error;
  7705. uint32_t cfg_mode, intr_mode;
  7706. int mcnt;
  7707. /* Allocate memory for HBA structure */
  7708. phba = lpfc_hba_alloc(pdev);
  7709. if (!phba)
  7710. return -ENOMEM;
  7711. /* Perform generic PCI device enabling operation */
  7712. error = lpfc_enable_pci_dev(phba);
  7713. if (error) {
  7714. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7715. "1409 Failed to enable pci device.\n");
  7716. goto out_free_phba;
  7717. }
  7718. /* Set up SLI API function jump table for PCI-device group-1 HBAs */
  7719. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
  7720. if (error)
  7721. goto out_disable_pci_dev;
  7722. /* Set up SLI-4 specific device PCI memory space */
  7723. error = lpfc_sli4_pci_mem_setup(phba);
  7724. if (error) {
  7725. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7726. "1410 Failed to set up pci memory space.\n");
  7727. goto out_disable_pci_dev;
  7728. }
  7729. /* Set up phase-1 common device driver resources */
  7730. error = lpfc_setup_driver_resource_phase1(phba);
  7731. if (error) {
  7732. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7733. "1411 Failed to set up driver resource.\n");
  7734. goto out_unset_pci_mem_s4;
  7735. }
  7736. /* Set up SLI-4 Specific device driver resources */
  7737. error = lpfc_sli4_driver_resource_setup(phba);
  7738. if (error) {
  7739. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7740. "1412 Failed to set up driver resource.\n");
  7741. goto out_unset_pci_mem_s4;
  7742. }
  7743. /* Initialize and populate the iocb list per host */
  7744. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7745. "2821 initialize iocb list %d.\n",
  7746. phba->cfg_iocb_cnt*1024);
  7747. error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
  7748. if (error) {
  7749. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7750. "1413 Failed to initialize iocb list.\n");
  7751. goto out_unset_driver_resource_s4;
  7752. }
  7753. INIT_LIST_HEAD(&phba->active_rrq_list);
  7754. /* Set up common device driver resources */
  7755. error = lpfc_setup_driver_resource_phase2(phba);
  7756. if (error) {
  7757. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7758. "1414 Failed to set up driver resource.\n");
  7759. goto out_free_iocb_list;
  7760. }
  7761. /* Create SCSI host to the physical port */
  7762. error = lpfc_create_shost(phba);
  7763. if (error) {
  7764. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7765. "1415 Failed to create scsi host.\n");
  7766. goto out_unset_driver_resource;
  7767. }
  7768. /* Configure sysfs attributes */
  7769. vport = phba->pport;
  7770. error = lpfc_alloc_sysfs_attr(vport);
  7771. if (error) {
  7772. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7773. "1416 Failed to allocate sysfs attr\n");
  7774. goto out_destroy_shost;
  7775. }
  7776. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  7777. /* Now, trying to enable interrupt and bring up the device */
  7778. cfg_mode = phba->cfg_use_msi;
  7779. while (true) {
  7780. /* Put device to a known state before enabling interrupt */
  7781. lpfc_stop_port(phba);
  7782. /* Configure and enable interrupt */
  7783. intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
  7784. if (intr_mode == LPFC_INTR_ERROR) {
  7785. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7786. "0426 Failed to enable interrupt.\n");
  7787. error = -ENODEV;
  7788. goto out_free_sysfs_attr;
  7789. }
  7790. /* Default to single FCP EQ for non-MSI-X */
  7791. if (phba->intr_type != MSIX)
  7792. phba->cfg_fcp_eq_count = 1;
  7793. else if (phba->sli4_hba.msix_vec_nr < phba->cfg_fcp_eq_count)
  7794. phba->cfg_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1;
  7795. /* Set up SLI-4 HBA */
  7796. if (lpfc_sli4_hba_setup(phba)) {
  7797. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7798. "1421 Failed to set up hba\n");
  7799. error = -ENODEV;
  7800. goto out_disable_intr;
  7801. }
  7802. /* Send NOP mbx cmds for non-INTx mode active interrupt test */
  7803. if (intr_mode != 0)
  7804. mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
  7805. LPFC_ACT_INTR_CNT);
  7806. /* Check active interrupts received only for MSI/MSI-X */
  7807. if (intr_mode == 0 ||
  7808. phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
  7809. /* Log the current active interrupt mode */
  7810. phba->intr_mode = intr_mode;
  7811. lpfc_log_intr_mode(phba, intr_mode);
  7812. break;
  7813. }
  7814. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7815. "0451 Configure interrupt mode (%d) "
  7816. "failed active interrupt test.\n",
  7817. intr_mode);
  7818. /* Unset the previous SLI-4 HBA setup. */
  7819. /*
  7820. * TODO: Is this operation compatible with IF TYPE 2
  7821. * devices? All port state is deleted and cleared.
  7822. */
  7823. lpfc_sli4_unset_hba(phba);
  7824. /* Try next level of interrupt mode */
  7825. cfg_mode = --intr_mode;
  7826. }
  7827. /* Perform post initialization setup */
  7828. lpfc_post_init_setup(phba);
  7829. /* Check if there are static vports to be created. */
  7830. lpfc_create_static_vport(phba);
  7831. return 0;
  7832. out_disable_intr:
  7833. lpfc_sli4_disable_intr(phba);
  7834. out_free_sysfs_attr:
  7835. lpfc_free_sysfs_attr(vport);
  7836. out_destroy_shost:
  7837. lpfc_destroy_shost(phba);
  7838. out_unset_driver_resource:
  7839. lpfc_unset_driver_resource_phase2(phba);
  7840. out_free_iocb_list:
  7841. lpfc_free_iocb_list(phba);
  7842. out_unset_driver_resource_s4:
  7843. lpfc_sli4_driver_resource_unset(phba);
  7844. out_unset_pci_mem_s4:
  7845. lpfc_sli4_pci_mem_unset(phba);
  7846. out_disable_pci_dev:
  7847. lpfc_disable_pci_dev(phba);
  7848. if (shost)
  7849. scsi_host_put(shost);
  7850. out_free_phba:
  7851. lpfc_hba_free(phba);
  7852. return error;
  7853. }
  7854. /**
  7855. * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
  7856. * @pdev: pointer to PCI device
  7857. *
  7858. * This routine is called from the kernel's PCI subsystem to device with
  7859. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  7860. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  7861. * device to be removed from the PCI subsystem properly.
  7862. **/
  7863. static void __devexit
  7864. lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  7865. {
  7866. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7867. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  7868. struct lpfc_vport **vports;
  7869. struct lpfc_hba *phba = vport->phba;
  7870. int i;
  7871. /* Mark the device unloading flag */
  7872. spin_lock_irq(&phba->hbalock);
  7873. vport->load_flag |= FC_UNLOADING;
  7874. spin_unlock_irq(&phba->hbalock);
  7875. /* Free the HBA sysfs attributes */
  7876. lpfc_free_sysfs_attr(vport);
  7877. /* Release all the vports against this physical port */
  7878. vports = lpfc_create_vport_work_array(phba);
  7879. if (vports != NULL)
  7880. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  7881. fc_vport_terminate(vports[i]->fc_vport);
  7882. lpfc_destroy_vport_work_array(phba, vports);
  7883. /* Remove FC host and then SCSI host with the physical port */
  7884. fc_remove_host(shost);
  7885. scsi_remove_host(shost);
  7886. /* Perform cleanup on the physical port */
  7887. lpfc_cleanup(vport);
  7888. /*
  7889. * Bring down the SLI Layer. This step disables all interrupts,
  7890. * clears the rings, discards all mailbox commands, and resets
  7891. * the HBA FCoE function.
  7892. */
  7893. lpfc_debugfs_terminate(vport);
  7894. lpfc_sli4_hba_unset(phba);
  7895. spin_lock_irq(&phba->hbalock);
  7896. list_del_init(&vport->listentry);
  7897. spin_unlock_irq(&phba->hbalock);
  7898. /* Perform scsi free before driver resource_unset since scsi
  7899. * buffers are released to their corresponding pools here.
  7900. */
  7901. lpfc_scsi_free(phba);
  7902. lpfc_sli4_driver_resource_unset(phba);
  7903. /* Unmap adapter Control and Doorbell registers */
  7904. lpfc_sli4_pci_mem_unset(phba);
  7905. /* Release PCI resources and disable device's PCI function */
  7906. scsi_host_put(shost);
  7907. lpfc_disable_pci_dev(phba);
  7908. /* Finally, free the driver's device data structure */
  7909. lpfc_hba_free(phba);
  7910. return;
  7911. }
  7912. /**
  7913. * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
  7914. * @pdev: pointer to PCI device
  7915. * @msg: power management message
  7916. *
  7917. * This routine is called from the kernel's PCI subsystem to support system
  7918. * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
  7919. * this method, it quiesces the device by stopping the driver's worker
  7920. * thread for the device, turning off device's interrupt and DMA, and bring
  7921. * the device offline. Note that as the driver implements the minimum PM
  7922. * requirements to a power-aware driver's PM support for suspend/resume -- all
  7923. * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
  7924. * method call will be treated as SUSPEND and the driver will fully
  7925. * reinitialize its device during resume() method call, the driver will set
  7926. * device to PCI_D3hot state in PCI config space instead of setting it
  7927. * according to the @msg provided by the PM.
  7928. *
  7929. * Return code
  7930. * 0 - driver suspended the device
  7931. * Error otherwise
  7932. **/
  7933. static int
  7934. lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
  7935. {
  7936. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7937. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7938. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7939. "2843 PCI device Power Management suspend.\n");
  7940. /* Bring down the device */
  7941. lpfc_offline_prep(phba);
  7942. lpfc_offline(phba);
  7943. kthread_stop(phba->worker_thread);
  7944. /* Disable interrupt from device */
  7945. lpfc_sli4_disable_intr(phba);
  7946. /* Save device state to PCI config space */
  7947. pci_save_state(pdev);
  7948. pci_set_power_state(pdev, PCI_D3hot);
  7949. return 0;
  7950. }
  7951. /**
  7952. * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
  7953. * @pdev: pointer to PCI device
  7954. *
  7955. * This routine is called from the kernel's PCI subsystem to support system
  7956. * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
  7957. * this method, it restores the device's PCI config space state and fully
  7958. * reinitializes the device and brings it online. Note that as the driver
  7959. * implements the minimum PM requirements to a power-aware driver's PM for
  7960. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  7961. * to the suspend() method call will be treated as SUSPEND and the driver
  7962. * will fully reinitialize its device during resume() method call, the device
  7963. * will be set to PCI_D0 directly in PCI config space before restoring the
  7964. * state.
  7965. *
  7966. * Return code
  7967. * 0 - driver suspended the device
  7968. * Error otherwise
  7969. **/
  7970. static int
  7971. lpfc_pci_resume_one_s4(struct pci_dev *pdev)
  7972. {
  7973. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7974. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7975. uint32_t intr_mode;
  7976. int error;
  7977. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7978. "0292 PCI device Power Management resume.\n");
  7979. /* Restore device state from PCI config space */
  7980. pci_set_power_state(pdev, PCI_D0);
  7981. pci_restore_state(pdev);
  7982. /*
  7983. * As the new kernel behavior of pci_restore_state() API call clears
  7984. * device saved_state flag, need to save the restored state again.
  7985. */
  7986. pci_save_state(pdev);
  7987. if (pdev->is_busmaster)
  7988. pci_set_master(pdev);
  7989. /* Startup the kernel thread for this host adapter. */
  7990. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  7991. "lpfc_worker_%d", phba->brd_no);
  7992. if (IS_ERR(phba->worker_thread)) {
  7993. error = PTR_ERR(phba->worker_thread);
  7994. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7995. "0293 PM resume failed to start worker "
  7996. "thread: error=x%x.\n", error);
  7997. return error;
  7998. }
  7999. /* Configure and enable interrupt */
  8000. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  8001. if (intr_mode == LPFC_INTR_ERROR) {
  8002. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8003. "0294 PM resume Failed to enable interrupt\n");
  8004. return -EIO;
  8005. } else
  8006. phba->intr_mode = intr_mode;
  8007. /* Restart HBA and bring it online */
  8008. lpfc_sli_brdrestart(phba);
  8009. lpfc_online(phba);
  8010. /* Log the current active interrupt mode */
  8011. lpfc_log_intr_mode(phba, phba->intr_mode);
  8012. return 0;
  8013. }
  8014. /**
  8015. * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
  8016. * @phba: pointer to lpfc hba data structure.
  8017. *
  8018. * This routine is called to prepare the SLI4 device for PCI slot recover. It
  8019. * aborts all the outstanding SCSI I/Os to the pci device.
  8020. **/
  8021. static void
  8022. lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
  8023. {
  8024. struct lpfc_sli *psli = &phba->sli;
  8025. struct lpfc_sli_ring *pring;
  8026. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8027. "2828 PCI channel I/O abort preparing for recovery\n");
  8028. /*
  8029. * There may be errored I/Os through HBA, abort all I/Os on txcmplq
  8030. * and let the SCSI mid-layer to retry them to recover.
  8031. */
  8032. pring = &psli->ring[psli->fcp_ring];
  8033. lpfc_sli_abort_iocb_ring(phba, pring);
  8034. }
  8035. /**
  8036. * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
  8037. * @phba: pointer to lpfc hba data structure.
  8038. *
  8039. * This routine is called to prepare the SLI4 device for PCI slot reset. It
  8040. * disables the device interrupt and pci device, and aborts the internal FCP
  8041. * pending I/Os.
  8042. **/
  8043. static void
  8044. lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
  8045. {
  8046. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8047. "2826 PCI channel disable preparing for reset\n");
  8048. /* Block any management I/Os to the device */
  8049. lpfc_block_mgmt_io(phba);
  8050. /* Block all SCSI devices' I/Os on the host */
  8051. lpfc_scsi_dev_block(phba);
  8052. /* stop all timers */
  8053. lpfc_stop_hba_timers(phba);
  8054. /* Disable interrupt and pci device */
  8055. lpfc_sli4_disable_intr(phba);
  8056. pci_disable_device(phba->pcidev);
  8057. /* Flush all driver's outstanding SCSI I/Os as we are to reset */
  8058. lpfc_sli_flush_fcp_rings(phba);
  8059. }
  8060. /**
  8061. * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
  8062. * @phba: pointer to lpfc hba data structure.
  8063. *
  8064. * This routine is called to prepare the SLI4 device for PCI slot permanently
  8065. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  8066. * pending I/Os.
  8067. **/
  8068. static void
  8069. lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  8070. {
  8071. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8072. "2827 PCI channel permanent disable for failure\n");
  8073. /* Block all SCSI devices' I/Os on the host */
  8074. lpfc_scsi_dev_block(phba);
  8075. /* stop all timers */
  8076. lpfc_stop_hba_timers(phba);
  8077. /* Clean up all driver's outstanding SCSI I/Os */
  8078. lpfc_sli_flush_fcp_rings(phba);
  8079. }
  8080. /**
  8081. * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
  8082. * @pdev: pointer to PCI device.
  8083. * @state: the current PCI connection state.
  8084. *
  8085. * This routine is called from the PCI subsystem for error handling to device
  8086. * with SLI-4 interface spec. This function is called by the PCI subsystem
  8087. * after a PCI bus error affecting this device has been detected. When this
  8088. * function is invoked, it will need to stop all the I/Os and interrupt(s)
  8089. * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
  8090. * for the PCI subsystem to perform proper recovery as desired.
  8091. *
  8092. * Return codes
  8093. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  8094. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8095. **/
  8096. static pci_ers_result_t
  8097. lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
  8098. {
  8099. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8100. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8101. switch (state) {
  8102. case pci_channel_io_normal:
  8103. /* Non-fatal error, prepare for recovery */
  8104. lpfc_sli4_prep_dev_for_recover(phba);
  8105. return PCI_ERS_RESULT_CAN_RECOVER;
  8106. case pci_channel_io_frozen:
  8107. /* Fatal error, prepare for slot reset */
  8108. lpfc_sli4_prep_dev_for_reset(phba);
  8109. return PCI_ERS_RESULT_NEED_RESET;
  8110. case pci_channel_io_perm_failure:
  8111. /* Permanent failure, prepare for device down */
  8112. lpfc_sli4_prep_dev_for_perm_failure(phba);
  8113. return PCI_ERS_RESULT_DISCONNECT;
  8114. default:
  8115. /* Unknown state, prepare and request slot reset */
  8116. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8117. "2825 Unknown PCI error state: x%x\n", state);
  8118. lpfc_sli4_prep_dev_for_reset(phba);
  8119. return PCI_ERS_RESULT_NEED_RESET;
  8120. }
  8121. }
  8122. /**
  8123. * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
  8124. * @pdev: pointer to PCI device.
  8125. *
  8126. * This routine is called from the PCI subsystem for error handling to device
  8127. * with SLI-4 interface spec. It is called after PCI bus has been reset to
  8128. * restart the PCI card from scratch, as if from a cold-boot. During the
  8129. * PCI subsystem error recovery, after the driver returns
  8130. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  8131. * recovery and then call this routine before calling the .resume method to
  8132. * recover the device. This function will initialize the HBA device, enable
  8133. * the interrupt, but it will just put the HBA to offline state without
  8134. * passing any I/O traffic.
  8135. *
  8136. * Return codes
  8137. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  8138. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8139. */
  8140. static pci_ers_result_t
  8141. lpfc_io_slot_reset_s4(struct pci_dev *pdev)
  8142. {
  8143. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8144. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8145. struct lpfc_sli *psli = &phba->sli;
  8146. uint32_t intr_mode;
  8147. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  8148. if (pci_enable_device_mem(pdev)) {
  8149. printk(KERN_ERR "lpfc: Cannot re-enable "
  8150. "PCI device after reset.\n");
  8151. return PCI_ERS_RESULT_DISCONNECT;
  8152. }
  8153. pci_restore_state(pdev);
  8154. if (pdev->is_busmaster)
  8155. pci_set_master(pdev);
  8156. spin_lock_irq(&phba->hbalock);
  8157. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  8158. spin_unlock_irq(&phba->hbalock);
  8159. /* Configure and enable interrupt */
  8160. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  8161. if (intr_mode == LPFC_INTR_ERROR) {
  8162. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8163. "2824 Cannot re-enable interrupt after "
  8164. "slot reset.\n");
  8165. return PCI_ERS_RESULT_DISCONNECT;
  8166. } else
  8167. phba->intr_mode = intr_mode;
  8168. /* Log the current active interrupt mode */
  8169. lpfc_log_intr_mode(phba, phba->intr_mode);
  8170. return PCI_ERS_RESULT_RECOVERED;
  8171. }
  8172. /**
  8173. * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
  8174. * @pdev: pointer to PCI device
  8175. *
  8176. * This routine is called from the PCI subsystem for error handling to device
  8177. * with SLI-4 interface spec. It is called when kernel error recovery tells
  8178. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  8179. * error recovery. After this call, traffic can start to flow from this device
  8180. * again.
  8181. **/
  8182. static void
  8183. lpfc_io_resume_s4(struct pci_dev *pdev)
  8184. {
  8185. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8186. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8187. /*
  8188. * In case of slot reset, as function reset is performed through
  8189. * mailbox command which needs DMA to be enabled, this operation
  8190. * has to be moved to the io resume phase. Taking device offline
  8191. * will perform the necessary cleanup.
  8192. */
  8193. if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
  8194. /* Perform device reset */
  8195. lpfc_offline_prep(phba);
  8196. lpfc_offline(phba);
  8197. lpfc_sli_brdrestart(phba);
  8198. /* Bring the device back online */
  8199. lpfc_online(phba);
  8200. }
  8201. /* Clean up Advanced Error Reporting (AER) if needed */
  8202. if (phba->hba_flag & HBA_AER_ENABLED)
  8203. pci_cleanup_aer_uncorrect_error_status(pdev);
  8204. }
  8205. /**
  8206. * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
  8207. * @pdev: pointer to PCI device
  8208. * @pid: pointer to PCI device identifier
  8209. *
  8210. * This routine is to be registered to the kernel's PCI subsystem. When an
  8211. * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
  8212. * at PCI device-specific information of the device and driver to see if the
  8213. * driver state that it can support this kind of device. If the match is
  8214. * successful, the driver core invokes this routine. This routine dispatches
  8215. * the action to the proper SLI-3 or SLI-4 device probing routine, which will
  8216. * do all the initialization that it needs to do to handle the HBA device
  8217. * properly.
  8218. *
  8219. * Return code
  8220. * 0 - driver can claim the device
  8221. * negative value - driver can not claim the device
  8222. **/
  8223. static int __devinit
  8224. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  8225. {
  8226. int rc;
  8227. struct lpfc_sli_intf intf;
  8228. if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
  8229. return -ENODEV;
  8230. if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
  8231. (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
  8232. rc = lpfc_pci_probe_one_s4(pdev, pid);
  8233. else
  8234. rc = lpfc_pci_probe_one_s3(pdev, pid);
  8235. return rc;
  8236. }
  8237. /**
  8238. * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
  8239. * @pdev: pointer to PCI device
  8240. *
  8241. * This routine is to be registered to the kernel's PCI subsystem. When an
  8242. * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
  8243. * This routine dispatches the action to the proper SLI-3 or SLI-4 device
  8244. * remove routine, which will perform all the necessary cleanup for the
  8245. * device to be removed from the PCI subsystem properly.
  8246. **/
  8247. static void __devexit
  8248. lpfc_pci_remove_one(struct pci_dev *pdev)
  8249. {
  8250. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8251. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8252. switch (phba->pci_dev_grp) {
  8253. case LPFC_PCI_DEV_LP:
  8254. lpfc_pci_remove_one_s3(pdev);
  8255. break;
  8256. case LPFC_PCI_DEV_OC:
  8257. lpfc_pci_remove_one_s4(pdev);
  8258. break;
  8259. default:
  8260. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8261. "1424 Invalid PCI device group: 0x%x\n",
  8262. phba->pci_dev_grp);
  8263. break;
  8264. }
  8265. return;
  8266. }
  8267. /**
  8268. * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
  8269. * @pdev: pointer to PCI device
  8270. * @msg: power management message
  8271. *
  8272. * This routine is to be registered to the kernel's PCI subsystem to support
  8273. * system Power Management (PM). When PM invokes this method, it dispatches
  8274. * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
  8275. * suspend the device.
  8276. *
  8277. * Return code
  8278. * 0 - driver suspended the device
  8279. * Error otherwise
  8280. **/
  8281. static int
  8282. lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
  8283. {
  8284. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8285. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8286. int rc = -ENODEV;
  8287. switch (phba->pci_dev_grp) {
  8288. case LPFC_PCI_DEV_LP:
  8289. rc = lpfc_pci_suspend_one_s3(pdev, msg);
  8290. break;
  8291. case LPFC_PCI_DEV_OC:
  8292. rc = lpfc_pci_suspend_one_s4(pdev, msg);
  8293. break;
  8294. default:
  8295. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8296. "1425 Invalid PCI device group: 0x%x\n",
  8297. phba->pci_dev_grp);
  8298. break;
  8299. }
  8300. return rc;
  8301. }
  8302. /**
  8303. * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
  8304. * @pdev: pointer to PCI device
  8305. *
  8306. * This routine is to be registered to the kernel's PCI subsystem to support
  8307. * system Power Management (PM). When PM invokes this method, it dispatches
  8308. * the action to the proper SLI-3 or SLI-4 device resume routine, which will
  8309. * resume the device.
  8310. *
  8311. * Return code
  8312. * 0 - driver suspended the device
  8313. * Error otherwise
  8314. **/
  8315. static int
  8316. lpfc_pci_resume_one(struct pci_dev *pdev)
  8317. {
  8318. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8319. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8320. int rc = -ENODEV;
  8321. switch (phba->pci_dev_grp) {
  8322. case LPFC_PCI_DEV_LP:
  8323. rc = lpfc_pci_resume_one_s3(pdev);
  8324. break;
  8325. case LPFC_PCI_DEV_OC:
  8326. rc = lpfc_pci_resume_one_s4(pdev);
  8327. break;
  8328. default:
  8329. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8330. "1426 Invalid PCI device group: 0x%x\n",
  8331. phba->pci_dev_grp);
  8332. break;
  8333. }
  8334. return rc;
  8335. }
  8336. /**
  8337. * lpfc_io_error_detected - lpfc method for handling PCI I/O error
  8338. * @pdev: pointer to PCI device.
  8339. * @state: the current PCI connection state.
  8340. *
  8341. * This routine is registered to the PCI subsystem for error handling. This
  8342. * function is called by the PCI subsystem after a PCI bus error affecting
  8343. * this device has been detected. When this routine is invoked, it dispatches
  8344. * the action to the proper SLI-3 or SLI-4 device error detected handling
  8345. * routine, which will perform the proper error detected operation.
  8346. *
  8347. * Return codes
  8348. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  8349. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8350. **/
  8351. static pci_ers_result_t
  8352. lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  8353. {
  8354. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8355. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8356. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  8357. switch (phba->pci_dev_grp) {
  8358. case LPFC_PCI_DEV_LP:
  8359. rc = lpfc_io_error_detected_s3(pdev, state);
  8360. break;
  8361. case LPFC_PCI_DEV_OC:
  8362. rc = lpfc_io_error_detected_s4(pdev, state);
  8363. break;
  8364. default:
  8365. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8366. "1427 Invalid PCI device group: 0x%x\n",
  8367. phba->pci_dev_grp);
  8368. break;
  8369. }
  8370. return rc;
  8371. }
  8372. /**
  8373. * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
  8374. * @pdev: pointer to PCI device.
  8375. *
  8376. * This routine is registered to the PCI subsystem for error handling. This
  8377. * function is called after PCI bus has been reset to restart the PCI card
  8378. * from scratch, as if from a cold-boot. When this routine is invoked, it
  8379. * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
  8380. * routine, which will perform the proper device reset.
  8381. *
  8382. * Return codes
  8383. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  8384. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  8385. **/
  8386. static pci_ers_result_t
  8387. lpfc_io_slot_reset(struct pci_dev *pdev)
  8388. {
  8389. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8390. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8391. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  8392. switch (phba->pci_dev_grp) {
  8393. case LPFC_PCI_DEV_LP:
  8394. rc = lpfc_io_slot_reset_s3(pdev);
  8395. break;
  8396. case LPFC_PCI_DEV_OC:
  8397. rc = lpfc_io_slot_reset_s4(pdev);
  8398. break;
  8399. default:
  8400. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8401. "1428 Invalid PCI device group: 0x%x\n",
  8402. phba->pci_dev_grp);
  8403. break;
  8404. }
  8405. return rc;
  8406. }
  8407. /**
  8408. * lpfc_io_resume - lpfc method for resuming PCI I/O operation
  8409. * @pdev: pointer to PCI device
  8410. *
  8411. * This routine is registered to the PCI subsystem for error handling. It
  8412. * is called when kernel error recovery tells the lpfc driver that it is
  8413. * OK to resume normal PCI operation after PCI bus error recovery. When
  8414. * this routine is invoked, it dispatches the action to the proper SLI-3
  8415. * or SLI-4 device io_resume routine, which will resume the device operation.
  8416. **/
  8417. static void
  8418. lpfc_io_resume(struct pci_dev *pdev)
  8419. {
  8420. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  8421. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  8422. switch (phba->pci_dev_grp) {
  8423. case LPFC_PCI_DEV_LP:
  8424. lpfc_io_resume_s3(pdev);
  8425. break;
  8426. case LPFC_PCI_DEV_OC:
  8427. lpfc_io_resume_s4(pdev);
  8428. break;
  8429. default:
  8430. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  8431. "1429 Invalid PCI device group: 0x%x\n",
  8432. phba->pci_dev_grp);
  8433. break;
  8434. }
  8435. return;
  8436. }
  8437. static struct pci_device_id lpfc_id_table[] = {
  8438. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  8439. PCI_ANY_ID, PCI_ANY_ID, },
  8440. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  8441. PCI_ANY_ID, PCI_ANY_ID, },
  8442. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  8443. PCI_ANY_ID, PCI_ANY_ID, },
  8444. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  8445. PCI_ANY_ID, PCI_ANY_ID, },
  8446. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  8447. PCI_ANY_ID, PCI_ANY_ID, },
  8448. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  8449. PCI_ANY_ID, PCI_ANY_ID, },
  8450. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  8451. PCI_ANY_ID, PCI_ANY_ID, },
  8452. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  8453. PCI_ANY_ID, PCI_ANY_ID, },
  8454. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  8455. PCI_ANY_ID, PCI_ANY_ID, },
  8456. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  8457. PCI_ANY_ID, PCI_ANY_ID, },
  8458. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  8459. PCI_ANY_ID, PCI_ANY_ID, },
  8460. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  8461. PCI_ANY_ID, PCI_ANY_ID, },
  8462. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  8463. PCI_ANY_ID, PCI_ANY_ID, },
  8464. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  8465. PCI_ANY_ID, PCI_ANY_ID, },
  8466. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  8467. PCI_ANY_ID, PCI_ANY_ID, },
  8468. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  8469. PCI_ANY_ID, PCI_ANY_ID, },
  8470. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  8471. PCI_ANY_ID, PCI_ANY_ID, },
  8472. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  8473. PCI_ANY_ID, PCI_ANY_ID, },
  8474. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
  8475. PCI_ANY_ID, PCI_ANY_ID, },
  8476. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  8477. PCI_ANY_ID, PCI_ANY_ID, },
  8478. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  8479. PCI_ANY_ID, PCI_ANY_ID, },
  8480. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  8481. PCI_ANY_ID, PCI_ANY_ID, },
  8482. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  8483. PCI_ANY_ID, PCI_ANY_ID, },
  8484. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  8485. PCI_ANY_ID, PCI_ANY_ID, },
  8486. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  8487. PCI_ANY_ID, PCI_ANY_ID, },
  8488. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  8489. PCI_ANY_ID, PCI_ANY_ID, },
  8490. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  8491. PCI_ANY_ID, PCI_ANY_ID, },
  8492. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  8493. PCI_ANY_ID, PCI_ANY_ID, },
  8494. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  8495. PCI_ANY_ID, PCI_ANY_ID, },
  8496. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  8497. PCI_ANY_ID, PCI_ANY_ID, },
  8498. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  8499. PCI_ANY_ID, PCI_ANY_ID, },
  8500. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  8501. PCI_ANY_ID, PCI_ANY_ID, },
  8502. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  8503. PCI_ANY_ID, PCI_ANY_ID, },
  8504. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  8505. PCI_ANY_ID, PCI_ANY_ID, },
  8506. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
  8507. PCI_ANY_ID, PCI_ANY_ID, },
  8508. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
  8509. PCI_ANY_ID, PCI_ANY_ID, },
  8510. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
  8511. PCI_ANY_ID, PCI_ANY_ID, },
  8512. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
  8513. PCI_ANY_ID, PCI_ANY_ID, },
  8514. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
  8515. PCI_ANY_ID, PCI_ANY_ID, },
  8516. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
  8517. PCI_ANY_ID, PCI_ANY_ID, },
  8518. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS,
  8519. PCI_ANY_ID, PCI_ANY_ID, },
  8520. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC,
  8521. PCI_ANY_ID, PCI_ANY_ID, },
  8522. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE,
  8523. PCI_ANY_ID, PCI_ANY_ID, },
  8524. { 0 }
  8525. };
  8526. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  8527. static struct pci_error_handlers lpfc_err_handler = {
  8528. .error_detected = lpfc_io_error_detected,
  8529. .slot_reset = lpfc_io_slot_reset,
  8530. .resume = lpfc_io_resume,
  8531. };
  8532. static struct pci_driver lpfc_driver = {
  8533. .name = LPFC_DRIVER_NAME,
  8534. .id_table = lpfc_id_table,
  8535. .probe = lpfc_pci_probe_one,
  8536. .remove = __devexit_p(lpfc_pci_remove_one),
  8537. .suspend = lpfc_pci_suspend_one,
  8538. .resume = lpfc_pci_resume_one,
  8539. .err_handler = &lpfc_err_handler,
  8540. };
  8541. /**
  8542. * lpfc_init - lpfc module initialization routine
  8543. *
  8544. * This routine is to be invoked when the lpfc module is loaded into the
  8545. * kernel. The special kernel macro module_init() is used to indicate the
  8546. * role of this routine to the kernel as lpfc module entry point.
  8547. *
  8548. * Return codes
  8549. * 0 - successful
  8550. * -ENOMEM - FC attach transport failed
  8551. * all others - failed
  8552. */
  8553. static int __init
  8554. lpfc_init(void)
  8555. {
  8556. int error = 0;
  8557. printk(LPFC_MODULE_DESC "\n");
  8558. printk(LPFC_COPYRIGHT "\n");
  8559. if (lpfc_enable_npiv) {
  8560. lpfc_transport_functions.vport_create = lpfc_vport_create;
  8561. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  8562. }
  8563. lpfc_transport_template =
  8564. fc_attach_transport(&lpfc_transport_functions);
  8565. if (lpfc_transport_template == NULL)
  8566. return -ENOMEM;
  8567. if (lpfc_enable_npiv) {
  8568. lpfc_vport_transport_template =
  8569. fc_attach_transport(&lpfc_vport_transport_functions);
  8570. if (lpfc_vport_transport_template == NULL) {
  8571. fc_release_transport(lpfc_transport_template);
  8572. return -ENOMEM;
  8573. }
  8574. }
  8575. error = pci_register_driver(&lpfc_driver);
  8576. if (error) {
  8577. fc_release_transport(lpfc_transport_template);
  8578. if (lpfc_enable_npiv)
  8579. fc_release_transport(lpfc_vport_transport_template);
  8580. }
  8581. return error;
  8582. }
  8583. /**
  8584. * lpfc_exit - lpfc module removal routine
  8585. *
  8586. * This routine is invoked when the lpfc module is removed from the kernel.
  8587. * The special kernel macro module_exit() is used to indicate the role of
  8588. * this routine to the kernel as lpfc module exit point.
  8589. */
  8590. static void __exit
  8591. lpfc_exit(void)
  8592. {
  8593. pci_unregister_driver(&lpfc_driver);
  8594. fc_release_transport(lpfc_transport_template);
  8595. if (lpfc_enable_npiv)
  8596. fc_release_transport(lpfc_vport_transport_template);
  8597. if (_dump_buf_data) {
  8598. printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
  8599. "_dump_buf_data at 0x%p\n",
  8600. (1L << _dump_buf_data_order), _dump_buf_data);
  8601. free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
  8602. }
  8603. if (_dump_buf_dif) {
  8604. printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
  8605. "_dump_buf_dif at 0x%p\n",
  8606. (1L << _dump_buf_dif_order), _dump_buf_dif);
  8607. free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
  8608. }
  8609. }
  8610. module_init(lpfc_init);
  8611. module_exit(lpfc_exit);
  8612. MODULE_LICENSE("GPL");
  8613. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  8614. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  8615. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);