lpfc_init.c 325 KB

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