lpfc_init.c 292 KB

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