lpfc_init.c 337 KB

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