lpfc_init.c 314 KB

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