lpfc_init.c 325 KB

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