lpfc_init.c 270 KB

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