lpfc_init.c 298 KB

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