lpfc_init.c 267 KB

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