lpfc_init.c 270 KB

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