lpfc_init.c 311 KB

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