lpfc_init.c 299 KB

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