lpfc_init.c 299 KB

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