lpfc_init.c 298 KB

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