lpfc_init.c 272 KB

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