ql4_os.c 178 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2012 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include <linux/moduleparam.h>
  8. #include <linux/slab.h>
  9. #include <linux/blkdev.h>
  10. #include <linux/iscsi_boot_sysfs.h>
  11. #include <linux/inet.h>
  12. #include <scsi/scsi_tcq.h>
  13. #include <scsi/scsicam.h>
  14. #include "ql4_def.h"
  15. #include "ql4_version.h"
  16. #include "ql4_glbl.h"
  17. #include "ql4_dbg.h"
  18. #include "ql4_inline.h"
  19. #include "ql4_83xx.h"
  20. /*
  21. * Driver version
  22. */
  23. static char qla4xxx_version_str[40];
  24. /*
  25. * SRB allocation cache
  26. */
  27. static struct kmem_cache *srb_cachep;
  28. /*
  29. * Module parameter information and variables
  30. */
  31. static int ql4xdisablesysfsboot = 1;
  32. module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
  33. MODULE_PARM_DESC(ql4xdisablesysfsboot,
  34. " Set to disable exporting boot targets to sysfs.\n"
  35. "\t\t 0 - Export boot targets\n"
  36. "\t\t 1 - Do not export boot targets (Default)");
  37. int ql4xdontresethba;
  38. module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
  39. MODULE_PARM_DESC(ql4xdontresethba,
  40. " Don't reset the HBA for driver recovery.\n"
  41. "\t\t 0 - It will reset HBA (Default)\n"
  42. "\t\t 1 - It will NOT reset HBA");
  43. int ql4xextended_error_logging;
  44. module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
  45. MODULE_PARM_DESC(ql4xextended_error_logging,
  46. " Option to enable extended error logging.\n"
  47. "\t\t 0 - no logging (Default)\n"
  48. "\t\t 2 - debug logging");
  49. int ql4xenablemsix = 1;
  50. module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
  51. MODULE_PARM_DESC(ql4xenablemsix,
  52. " Set to enable MSI or MSI-X interrupt mechanism.\n"
  53. "\t\t 0 = enable INTx interrupt mechanism.\n"
  54. "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
  55. "\t\t 2 = enable MSI interrupt mechanism.");
  56. #define QL4_DEF_QDEPTH 32
  57. static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
  58. module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
  59. MODULE_PARM_DESC(ql4xmaxqdepth,
  60. " Maximum queue depth to report for target devices.\n"
  61. "\t\t Default: 32.");
  62. static int ql4xqfulltracking = 1;
  63. module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
  64. MODULE_PARM_DESC(ql4xqfulltracking,
  65. " Enable or disable dynamic tracking and adjustment of\n"
  66. "\t\t scsi device queue depth.\n"
  67. "\t\t 0 - Disable.\n"
  68. "\t\t 1 - Enable. (Default)");
  69. static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
  70. module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
  71. MODULE_PARM_DESC(ql4xsess_recovery_tmo,
  72. " Target Session Recovery Timeout.\n"
  73. "\t\t Default: 120 sec.");
  74. int ql4xmdcapmask = 0x1F;
  75. module_param(ql4xmdcapmask, int, S_IRUGO);
  76. MODULE_PARM_DESC(ql4xmdcapmask,
  77. " Set the Minidump driver capture mask level.\n"
  78. "\t\t Default is 0x1F.\n"
  79. "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F");
  80. int ql4xenablemd = 1;
  81. module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
  82. MODULE_PARM_DESC(ql4xenablemd,
  83. " Set to enable minidump.\n"
  84. "\t\t 0 - disable minidump\n"
  85. "\t\t 1 - enable minidump (Default)");
  86. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
  87. /*
  88. * SCSI host template entry points
  89. */
  90. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
  91. /*
  92. * iSCSI template entry points
  93. */
  94. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  95. enum iscsi_param param, char *buf);
  96. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  97. enum iscsi_param param, char *buf);
  98. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  99. enum iscsi_host_param param, char *buf);
  100. static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
  101. uint32_t len);
  102. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  103. enum iscsi_param_type param_type,
  104. int param, char *buf);
  105. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
  106. static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
  107. struct sockaddr *dst_addr,
  108. int non_blocking);
  109. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
  110. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
  111. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  112. enum iscsi_param param, char *buf);
  113. static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
  114. static struct iscsi_cls_conn *
  115. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
  116. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  117. struct iscsi_cls_conn *cls_conn,
  118. uint64_t transport_fd, int is_leading);
  119. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
  120. static struct iscsi_cls_session *
  121. qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
  122. uint16_t qdepth, uint32_t initial_cmdsn);
  123. static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
  124. static void qla4xxx_task_work(struct work_struct *wdata);
  125. static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
  126. static int qla4xxx_task_xmit(struct iscsi_task *);
  127. static void qla4xxx_task_cleanup(struct iscsi_task *);
  128. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
  129. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  130. struct iscsi_stats *stats);
  131. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  132. uint32_t iface_type, uint32_t payload_size,
  133. uint32_t pid, struct sockaddr *dst_addr);
  134. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  135. uint32_t *num_entries, char *buf);
  136. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
  137. /*
  138. * SCSI host template entry points
  139. */
  140. static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  141. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
  142. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
  143. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
  144. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
  145. static int qla4xxx_slave_alloc(struct scsi_device *device);
  146. static int qla4xxx_slave_configure(struct scsi_device *device);
  147. static void qla4xxx_slave_destroy(struct scsi_device *sdev);
  148. static umode_t qla4_attr_is_visible(int param_type, int param);
  149. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
  150. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  151. int reason);
  152. static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
  153. QLA82XX_LEGACY_INTR_CONFIG;
  154. static struct scsi_host_template qla4xxx_driver_template = {
  155. .module = THIS_MODULE,
  156. .name = DRIVER_NAME,
  157. .proc_name = DRIVER_NAME,
  158. .queuecommand = qla4xxx_queuecommand,
  159. .eh_abort_handler = qla4xxx_eh_abort,
  160. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  161. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  162. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  163. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  164. .slave_configure = qla4xxx_slave_configure,
  165. .slave_alloc = qla4xxx_slave_alloc,
  166. .slave_destroy = qla4xxx_slave_destroy,
  167. .change_queue_depth = qla4xxx_change_queue_depth,
  168. .this_id = -1,
  169. .cmd_per_lun = 3,
  170. .use_clustering = ENABLE_CLUSTERING,
  171. .sg_tablesize = SG_ALL,
  172. .max_sectors = 0xFFFF,
  173. .shost_attrs = qla4xxx_host_attrs,
  174. .host_reset = qla4xxx_host_reset,
  175. .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
  176. };
  177. static struct iscsi_transport qla4xxx_iscsi_transport = {
  178. .owner = THIS_MODULE,
  179. .name = DRIVER_NAME,
  180. .caps = CAP_TEXT_NEGO |
  181. CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
  182. CAP_DATADGST | CAP_LOGIN_OFFLOAD |
  183. CAP_MULTI_R2T,
  184. .attr_is_visible = qla4_attr_is_visible,
  185. .create_session = qla4xxx_session_create,
  186. .destroy_session = qla4xxx_session_destroy,
  187. .start_conn = qla4xxx_conn_start,
  188. .create_conn = qla4xxx_conn_create,
  189. .bind_conn = qla4xxx_conn_bind,
  190. .stop_conn = iscsi_conn_stop,
  191. .destroy_conn = qla4xxx_conn_destroy,
  192. .set_param = iscsi_set_param,
  193. .get_conn_param = qla4xxx_conn_get_param,
  194. .get_session_param = qla4xxx_session_get_param,
  195. .get_ep_param = qla4xxx_get_ep_param,
  196. .ep_connect = qla4xxx_ep_connect,
  197. .ep_poll = qla4xxx_ep_poll,
  198. .ep_disconnect = qla4xxx_ep_disconnect,
  199. .get_stats = qla4xxx_conn_get_stats,
  200. .send_pdu = iscsi_conn_send_pdu,
  201. .xmit_task = qla4xxx_task_xmit,
  202. .cleanup_task = qla4xxx_task_cleanup,
  203. .alloc_pdu = qla4xxx_alloc_pdu,
  204. .get_host_param = qla4xxx_host_get_param,
  205. .set_iface_param = qla4xxx_iface_set_param,
  206. .get_iface_param = qla4xxx_get_iface_param,
  207. .bsg_request = qla4xxx_bsg_request,
  208. .send_ping = qla4xxx_send_ping,
  209. .get_chap = qla4xxx_get_chap_list,
  210. .delete_chap = qla4xxx_delete_chap,
  211. };
  212. static struct scsi_transport_template *qla4xxx_scsi_transport;
  213. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  214. uint32_t iface_type, uint32_t payload_size,
  215. uint32_t pid, struct sockaddr *dst_addr)
  216. {
  217. struct scsi_qla_host *ha = to_qla_host(shost);
  218. struct sockaddr_in *addr;
  219. struct sockaddr_in6 *addr6;
  220. uint32_t options = 0;
  221. uint8_t ipaddr[IPv6_ADDR_LEN];
  222. int rval;
  223. memset(ipaddr, 0, IPv6_ADDR_LEN);
  224. /* IPv4 to IPv4 */
  225. if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
  226. (dst_addr->sa_family == AF_INET)) {
  227. addr = (struct sockaddr_in *)dst_addr;
  228. memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
  229. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
  230. "dest: %pI4\n", __func__,
  231. &ha->ip_config.ip_address, ipaddr));
  232. rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
  233. ipaddr);
  234. if (rval)
  235. rval = -EINVAL;
  236. } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
  237. (dst_addr->sa_family == AF_INET6)) {
  238. /* IPv6 to IPv6 */
  239. addr6 = (struct sockaddr_in6 *)dst_addr;
  240. memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
  241. options |= PING_IPV6_PROTOCOL_ENABLE;
  242. /* Ping using LinkLocal address */
  243. if ((iface_num == 0) || (iface_num == 1)) {
  244. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
  245. "src: %pI6 dest: %pI6\n", __func__,
  246. &ha->ip_config.ipv6_link_local_addr,
  247. ipaddr));
  248. options |= PING_IPV6_LINKLOCAL_ADDR;
  249. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  250. pid, ipaddr);
  251. } else {
  252. ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
  253. "not supported\n", __func__, iface_num);
  254. rval = -ENOSYS;
  255. goto exit_send_ping;
  256. }
  257. /*
  258. * If ping using LinkLocal address fails, try ping using
  259. * IPv6 address
  260. */
  261. if (rval != QLA_SUCCESS) {
  262. options &= ~PING_IPV6_LINKLOCAL_ADDR;
  263. if (iface_num == 0) {
  264. options |= PING_IPV6_ADDR0;
  265. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  266. "Ping src: %pI6 "
  267. "dest: %pI6\n", __func__,
  268. &ha->ip_config.ipv6_addr0,
  269. ipaddr));
  270. } else if (iface_num == 1) {
  271. options |= PING_IPV6_ADDR1;
  272. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  273. "Ping src: %pI6 "
  274. "dest: %pI6\n", __func__,
  275. &ha->ip_config.ipv6_addr1,
  276. ipaddr));
  277. }
  278. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  279. pid, ipaddr);
  280. if (rval)
  281. rval = -EINVAL;
  282. }
  283. } else
  284. rval = -ENOSYS;
  285. exit_send_ping:
  286. return rval;
  287. }
  288. static umode_t qla4_attr_is_visible(int param_type, int param)
  289. {
  290. switch (param_type) {
  291. case ISCSI_HOST_PARAM:
  292. switch (param) {
  293. case ISCSI_HOST_PARAM_HWADDRESS:
  294. case ISCSI_HOST_PARAM_IPADDRESS:
  295. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  296. case ISCSI_HOST_PARAM_PORT_STATE:
  297. case ISCSI_HOST_PARAM_PORT_SPEED:
  298. return S_IRUGO;
  299. default:
  300. return 0;
  301. }
  302. case ISCSI_PARAM:
  303. switch (param) {
  304. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  305. case ISCSI_PARAM_PERSISTENT_PORT:
  306. case ISCSI_PARAM_CONN_ADDRESS:
  307. case ISCSI_PARAM_CONN_PORT:
  308. case ISCSI_PARAM_TARGET_NAME:
  309. case ISCSI_PARAM_TPGT:
  310. case ISCSI_PARAM_TARGET_ALIAS:
  311. case ISCSI_PARAM_MAX_BURST:
  312. case ISCSI_PARAM_MAX_R2T:
  313. case ISCSI_PARAM_FIRST_BURST:
  314. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  315. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  316. case ISCSI_PARAM_IFACE_NAME:
  317. case ISCSI_PARAM_CHAP_OUT_IDX:
  318. case ISCSI_PARAM_CHAP_IN_IDX:
  319. case ISCSI_PARAM_USERNAME:
  320. case ISCSI_PARAM_PASSWORD:
  321. case ISCSI_PARAM_USERNAME_IN:
  322. case ISCSI_PARAM_PASSWORD_IN:
  323. return S_IRUGO;
  324. default:
  325. return 0;
  326. }
  327. case ISCSI_NET_PARAM:
  328. switch (param) {
  329. case ISCSI_NET_PARAM_IPV4_ADDR:
  330. case ISCSI_NET_PARAM_IPV4_SUBNET:
  331. case ISCSI_NET_PARAM_IPV4_GW:
  332. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  333. case ISCSI_NET_PARAM_IFACE_ENABLE:
  334. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  335. case ISCSI_NET_PARAM_IPV6_ADDR:
  336. case ISCSI_NET_PARAM_IPV6_ROUTER:
  337. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  338. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  339. case ISCSI_NET_PARAM_VLAN_ID:
  340. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  341. case ISCSI_NET_PARAM_VLAN_ENABLED:
  342. case ISCSI_NET_PARAM_MTU:
  343. case ISCSI_NET_PARAM_PORT:
  344. return S_IRUGO;
  345. default:
  346. return 0;
  347. }
  348. }
  349. return 0;
  350. }
  351. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  352. uint32_t *num_entries, char *buf)
  353. {
  354. struct scsi_qla_host *ha = to_qla_host(shost);
  355. struct ql4_chap_table *chap_table;
  356. struct iscsi_chap_rec *chap_rec;
  357. int max_chap_entries = 0;
  358. int valid_chap_entries = 0;
  359. int ret = 0, i;
  360. if (is_qla80XX(ha))
  361. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  362. sizeof(struct ql4_chap_table);
  363. else
  364. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  365. ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
  366. __func__, *num_entries, chap_tbl_idx);
  367. if (!buf) {
  368. ret = -ENOMEM;
  369. goto exit_get_chap_list;
  370. }
  371. chap_rec = (struct iscsi_chap_rec *) buf;
  372. mutex_lock(&ha->chap_sem);
  373. for (i = chap_tbl_idx; i < max_chap_entries; i++) {
  374. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  375. if (chap_table->cookie !=
  376. __constant_cpu_to_le16(CHAP_VALID_COOKIE))
  377. continue;
  378. chap_rec->chap_tbl_idx = i;
  379. strncpy(chap_rec->username, chap_table->name,
  380. ISCSI_CHAP_AUTH_NAME_MAX_LEN);
  381. strncpy(chap_rec->password, chap_table->secret,
  382. QL4_CHAP_MAX_SECRET_LEN);
  383. chap_rec->password_length = chap_table->secret_len;
  384. if (chap_table->flags & BIT_7) /* local */
  385. chap_rec->chap_type = CHAP_TYPE_OUT;
  386. if (chap_table->flags & BIT_6) /* peer */
  387. chap_rec->chap_type = CHAP_TYPE_IN;
  388. chap_rec++;
  389. valid_chap_entries++;
  390. if (valid_chap_entries == *num_entries)
  391. break;
  392. else
  393. continue;
  394. }
  395. mutex_unlock(&ha->chap_sem);
  396. exit_get_chap_list:
  397. ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
  398. __func__, valid_chap_entries);
  399. *num_entries = valid_chap_entries;
  400. return ret;
  401. }
  402. static int __qla4xxx_is_chap_active(struct device *dev, void *data)
  403. {
  404. int ret = 0;
  405. uint16_t *chap_tbl_idx = (uint16_t *) data;
  406. struct iscsi_cls_session *cls_session;
  407. struct iscsi_session *sess;
  408. struct ddb_entry *ddb_entry;
  409. if (!iscsi_is_session_dev(dev))
  410. goto exit_is_chap_active;
  411. cls_session = iscsi_dev_to_session(dev);
  412. sess = cls_session->dd_data;
  413. ddb_entry = sess->dd_data;
  414. if (iscsi_session_chkready(cls_session))
  415. goto exit_is_chap_active;
  416. if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
  417. ret = 1;
  418. exit_is_chap_active:
  419. return ret;
  420. }
  421. static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
  422. uint16_t chap_tbl_idx)
  423. {
  424. int ret = 0;
  425. ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
  426. __qla4xxx_is_chap_active);
  427. return ret;
  428. }
  429. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
  430. {
  431. struct scsi_qla_host *ha = to_qla_host(shost);
  432. struct ql4_chap_table *chap_table;
  433. dma_addr_t chap_dma;
  434. int max_chap_entries = 0;
  435. uint32_t offset = 0;
  436. uint32_t chap_size;
  437. int ret = 0;
  438. chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
  439. if (chap_table == NULL)
  440. return -ENOMEM;
  441. memset(chap_table, 0, sizeof(struct ql4_chap_table));
  442. if (is_qla80XX(ha))
  443. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  444. sizeof(struct ql4_chap_table);
  445. else
  446. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  447. if (chap_tbl_idx > max_chap_entries) {
  448. ret = -EINVAL;
  449. goto exit_delete_chap;
  450. }
  451. /* Check if chap index is in use.
  452. * If chap is in use don't delet chap entry */
  453. ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
  454. if (ret) {
  455. ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
  456. "delete from flash\n", chap_tbl_idx);
  457. ret = -EBUSY;
  458. goto exit_delete_chap;
  459. }
  460. chap_size = sizeof(struct ql4_chap_table);
  461. if (is_qla40XX(ha))
  462. offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
  463. else {
  464. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  465. /* flt_chap_size is CHAP table size for both ports
  466. * so divide it by 2 to calculate the offset for second port
  467. */
  468. if (ha->port_num == 1)
  469. offset += (ha->hw.flt_chap_size / 2);
  470. offset += (chap_tbl_idx * chap_size);
  471. }
  472. ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  473. if (ret != QLA_SUCCESS) {
  474. ret = -EINVAL;
  475. goto exit_delete_chap;
  476. }
  477. DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
  478. __le16_to_cpu(chap_table->cookie)));
  479. if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
  480. ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
  481. goto exit_delete_chap;
  482. }
  483. chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
  484. offset = FLASH_CHAP_OFFSET |
  485. (chap_tbl_idx * sizeof(struct ql4_chap_table));
  486. ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
  487. FLASH_OPT_RMW_COMMIT);
  488. if (ret == QLA_SUCCESS && ha->chap_list) {
  489. mutex_lock(&ha->chap_sem);
  490. /* Update ha chap_list cache */
  491. memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
  492. chap_table, sizeof(struct ql4_chap_table));
  493. mutex_unlock(&ha->chap_sem);
  494. }
  495. if (ret != QLA_SUCCESS)
  496. ret = -EINVAL;
  497. exit_delete_chap:
  498. dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
  499. return ret;
  500. }
  501. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  502. enum iscsi_param_type param_type,
  503. int param, char *buf)
  504. {
  505. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  506. struct scsi_qla_host *ha = to_qla_host(shost);
  507. int len = -ENOSYS;
  508. if (param_type != ISCSI_NET_PARAM)
  509. return -ENOSYS;
  510. switch (param) {
  511. case ISCSI_NET_PARAM_IPV4_ADDR:
  512. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  513. break;
  514. case ISCSI_NET_PARAM_IPV4_SUBNET:
  515. len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
  516. break;
  517. case ISCSI_NET_PARAM_IPV4_GW:
  518. len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
  519. break;
  520. case ISCSI_NET_PARAM_IFACE_ENABLE:
  521. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  522. len = sprintf(buf, "%s\n",
  523. (ha->ip_config.ipv4_options &
  524. IPOPT_IPV4_PROTOCOL_ENABLE) ?
  525. "enabled" : "disabled");
  526. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  527. len = sprintf(buf, "%s\n",
  528. (ha->ip_config.ipv6_options &
  529. IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
  530. "enabled" : "disabled");
  531. break;
  532. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  533. len = sprintf(buf, "%s\n",
  534. (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
  535. "dhcp" : "static");
  536. break;
  537. case ISCSI_NET_PARAM_IPV6_ADDR:
  538. if (iface->iface_num == 0)
  539. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
  540. if (iface->iface_num == 1)
  541. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
  542. break;
  543. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  544. len = sprintf(buf, "%pI6\n",
  545. &ha->ip_config.ipv6_link_local_addr);
  546. break;
  547. case ISCSI_NET_PARAM_IPV6_ROUTER:
  548. len = sprintf(buf, "%pI6\n",
  549. &ha->ip_config.ipv6_default_router_addr);
  550. break;
  551. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  552. len = sprintf(buf, "%s\n",
  553. (ha->ip_config.ipv6_addl_options &
  554. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
  555. "nd" : "static");
  556. break;
  557. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  558. len = sprintf(buf, "%s\n",
  559. (ha->ip_config.ipv6_addl_options &
  560. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
  561. "auto" : "static");
  562. break;
  563. case ISCSI_NET_PARAM_VLAN_ID:
  564. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  565. len = sprintf(buf, "%d\n",
  566. (ha->ip_config.ipv4_vlan_tag &
  567. ISCSI_MAX_VLAN_ID));
  568. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  569. len = sprintf(buf, "%d\n",
  570. (ha->ip_config.ipv6_vlan_tag &
  571. ISCSI_MAX_VLAN_ID));
  572. break;
  573. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  574. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  575. len = sprintf(buf, "%d\n",
  576. ((ha->ip_config.ipv4_vlan_tag >> 13) &
  577. ISCSI_MAX_VLAN_PRIORITY));
  578. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  579. len = sprintf(buf, "%d\n",
  580. ((ha->ip_config.ipv6_vlan_tag >> 13) &
  581. ISCSI_MAX_VLAN_PRIORITY));
  582. break;
  583. case ISCSI_NET_PARAM_VLAN_ENABLED:
  584. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  585. len = sprintf(buf, "%s\n",
  586. (ha->ip_config.ipv4_options &
  587. IPOPT_VLAN_TAGGING_ENABLE) ?
  588. "enabled" : "disabled");
  589. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  590. len = sprintf(buf, "%s\n",
  591. (ha->ip_config.ipv6_options &
  592. IPV6_OPT_VLAN_TAGGING_ENABLE) ?
  593. "enabled" : "disabled");
  594. break;
  595. case ISCSI_NET_PARAM_MTU:
  596. len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
  597. break;
  598. case ISCSI_NET_PARAM_PORT:
  599. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  600. len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
  601. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  602. len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
  603. break;
  604. default:
  605. len = -ENOSYS;
  606. }
  607. return len;
  608. }
  609. static struct iscsi_endpoint *
  610. qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  611. int non_blocking)
  612. {
  613. int ret;
  614. struct iscsi_endpoint *ep;
  615. struct qla_endpoint *qla_ep;
  616. struct scsi_qla_host *ha;
  617. struct sockaddr_in *addr;
  618. struct sockaddr_in6 *addr6;
  619. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  620. if (!shost) {
  621. ret = -ENXIO;
  622. printk(KERN_ERR "%s: shost is NULL\n",
  623. __func__);
  624. return ERR_PTR(ret);
  625. }
  626. ha = iscsi_host_priv(shost);
  627. ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
  628. if (!ep) {
  629. ret = -ENOMEM;
  630. return ERR_PTR(ret);
  631. }
  632. qla_ep = ep->dd_data;
  633. memset(qla_ep, 0, sizeof(struct qla_endpoint));
  634. if (dst_addr->sa_family == AF_INET) {
  635. memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
  636. addr = (struct sockaddr_in *)&qla_ep->dst_addr;
  637. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
  638. (char *)&addr->sin_addr));
  639. } else if (dst_addr->sa_family == AF_INET6) {
  640. memcpy(&qla_ep->dst_addr, dst_addr,
  641. sizeof(struct sockaddr_in6));
  642. addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
  643. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
  644. (char *)&addr6->sin6_addr));
  645. }
  646. qla_ep->host = shost;
  647. return ep;
  648. }
  649. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  650. {
  651. struct qla_endpoint *qla_ep;
  652. struct scsi_qla_host *ha;
  653. int ret = 0;
  654. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  655. qla_ep = ep->dd_data;
  656. ha = to_qla_host(qla_ep->host);
  657. if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
  658. ret = 1;
  659. return ret;
  660. }
  661. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
  662. {
  663. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  664. iscsi_destroy_endpoint(ep);
  665. }
  666. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  667. enum iscsi_param param,
  668. char *buf)
  669. {
  670. struct qla_endpoint *qla_ep = ep->dd_data;
  671. struct sockaddr *dst_addr;
  672. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  673. switch (param) {
  674. case ISCSI_PARAM_CONN_PORT:
  675. case ISCSI_PARAM_CONN_ADDRESS:
  676. if (!qla_ep)
  677. return -ENOTCONN;
  678. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  679. if (!dst_addr)
  680. return -ENOTCONN;
  681. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  682. &qla_ep->dst_addr, param, buf);
  683. default:
  684. return -ENOSYS;
  685. }
  686. }
  687. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  688. struct iscsi_stats *stats)
  689. {
  690. struct iscsi_session *sess;
  691. struct iscsi_cls_session *cls_sess;
  692. struct ddb_entry *ddb_entry;
  693. struct scsi_qla_host *ha;
  694. struct ql_iscsi_stats *ql_iscsi_stats;
  695. int stats_size;
  696. int ret;
  697. dma_addr_t iscsi_stats_dma;
  698. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  699. cls_sess = iscsi_conn_to_session(cls_conn);
  700. sess = cls_sess->dd_data;
  701. ddb_entry = sess->dd_data;
  702. ha = ddb_entry->ha;
  703. stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
  704. /* Allocate memory */
  705. ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
  706. &iscsi_stats_dma, GFP_KERNEL);
  707. if (!ql_iscsi_stats) {
  708. ql4_printk(KERN_ERR, ha,
  709. "Unable to allocate memory for iscsi stats\n");
  710. goto exit_get_stats;
  711. }
  712. ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
  713. iscsi_stats_dma);
  714. if (ret != QLA_SUCCESS) {
  715. ql4_printk(KERN_ERR, ha,
  716. "Unable to retrieve iscsi stats\n");
  717. goto free_stats;
  718. }
  719. /* octets */
  720. stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
  721. stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
  722. /* xmit pdus */
  723. stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
  724. stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
  725. stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
  726. stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
  727. stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
  728. stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
  729. stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
  730. stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
  731. /* recv pdus */
  732. stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
  733. stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
  734. stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
  735. stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
  736. stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
  737. stats->logoutrsp_pdus =
  738. le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
  739. stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
  740. stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
  741. stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
  742. free_stats:
  743. dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
  744. iscsi_stats_dma);
  745. exit_get_stats:
  746. return;
  747. }
  748. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  749. {
  750. struct iscsi_cls_session *session;
  751. struct iscsi_session *sess;
  752. unsigned long flags;
  753. enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
  754. session = starget_to_session(scsi_target(sc->device));
  755. sess = session->dd_data;
  756. spin_lock_irqsave(&session->lock, flags);
  757. if (session->state == ISCSI_SESSION_FAILED)
  758. ret = BLK_EH_RESET_TIMER;
  759. spin_unlock_irqrestore(&session->lock, flags);
  760. return ret;
  761. }
  762. static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
  763. {
  764. struct scsi_qla_host *ha = to_qla_host(shost);
  765. struct iscsi_cls_host *ihost = shost->shost_data;
  766. uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
  767. qla4xxx_get_firmware_state(ha);
  768. switch (ha->addl_fw_state & 0x0F00) {
  769. case FW_ADDSTATE_LINK_SPEED_10MBPS:
  770. speed = ISCSI_PORT_SPEED_10MBPS;
  771. break;
  772. case FW_ADDSTATE_LINK_SPEED_100MBPS:
  773. speed = ISCSI_PORT_SPEED_100MBPS;
  774. break;
  775. case FW_ADDSTATE_LINK_SPEED_1GBPS:
  776. speed = ISCSI_PORT_SPEED_1GBPS;
  777. break;
  778. case FW_ADDSTATE_LINK_SPEED_10GBPS:
  779. speed = ISCSI_PORT_SPEED_10GBPS;
  780. break;
  781. }
  782. ihost->port_speed = speed;
  783. }
  784. static void qla4xxx_set_port_state(struct Scsi_Host *shost)
  785. {
  786. struct scsi_qla_host *ha = to_qla_host(shost);
  787. struct iscsi_cls_host *ihost = shost->shost_data;
  788. uint32_t state = ISCSI_PORT_STATE_DOWN;
  789. if (test_bit(AF_LINK_UP, &ha->flags))
  790. state = ISCSI_PORT_STATE_UP;
  791. ihost->port_state = state;
  792. }
  793. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  794. enum iscsi_host_param param, char *buf)
  795. {
  796. struct scsi_qla_host *ha = to_qla_host(shost);
  797. int len;
  798. switch (param) {
  799. case ISCSI_HOST_PARAM_HWADDRESS:
  800. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  801. break;
  802. case ISCSI_HOST_PARAM_IPADDRESS:
  803. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  804. break;
  805. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  806. len = sprintf(buf, "%s\n", ha->name_string);
  807. break;
  808. case ISCSI_HOST_PARAM_PORT_STATE:
  809. qla4xxx_set_port_state(shost);
  810. len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
  811. break;
  812. case ISCSI_HOST_PARAM_PORT_SPEED:
  813. qla4xxx_set_port_speed(shost);
  814. len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
  815. break;
  816. default:
  817. return -ENOSYS;
  818. }
  819. return len;
  820. }
  821. static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
  822. {
  823. if (ha->iface_ipv4)
  824. return;
  825. /* IPv4 */
  826. ha->iface_ipv4 = iscsi_create_iface(ha->host,
  827. &qla4xxx_iscsi_transport,
  828. ISCSI_IFACE_TYPE_IPV4, 0, 0);
  829. if (!ha->iface_ipv4)
  830. ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
  831. "iface0.\n");
  832. }
  833. static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
  834. {
  835. if (!ha->iface_ipv6_0)
  836. /* IPv6 iface-0 */
  837. ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
  838. &qla4xxx_iscsi_transport,
  839. ISCSI_IFACE_TYPE_IPV6, 0,
  840. 0);
  841. if (!ha->iface_ipv6_0)
  842. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  843. "iface0.\n");
  844. if (!ha->iface_ipv6_1)
  845. /* IPv6 iface-1 */
  846. ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
  847. &qla4xxx_iscsi_transport,
  848. ISCSI_IFACE_TYPE_IPV6, 1,
  849. 0);
  850. if (!ha->iface_ipv6_1)
  851. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  852. "iface1.\n");
  853. }
  854. static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
  855. {
  856. if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
  857. qla4xxx_create_ipv4_iface(ha);
  858. if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
  859. qla4xxx_create_ipv6_iface(ha);
  860. }
  861. static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
  862. {
  863. if (ha->iface_ipv4) {
  864. iscsi_destroy_iface(ha->iface_ipv4);
  865. ha->iface_ipv4 = NULL;
  866. }
  867. }
  868. static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
  869. {
  870. if (ha->iface_ipv6_0) {
  871. iscsi_destroy_iface(ha->iface_ipv6_0);
  872. ha->iface_ipv6_0 = NULL;
  873. }
  874. if (ha->iface_ipv6_1) {
  875. iscsi_destroy_iface(ha->iface_ipv6_1);
  876. ha->iface_ipv6_1 = NULL;
  877. }
  878. }
  879. static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
  880. {
  881. qla4xxx_destroy_ipv4_iface(ha);
  882. qla4xxx_destroy_ipv6_iface(ha);
  883. }
  884. static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
  885. struct iscsi_iface_param_info *iface_param,
  886. struct addr_ctrl_blk *init_fw_cb)
  887. {
  888. /*
  889. * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
  890. * iface_num 1 is valid only for IPv6 Addr.
  891. */
  892. switch (iface_param->param) {
  893. case ISCSI_NET_PARAM_IPV6_ADDR:
  894. if (iface_param->iface_num & 0x1)
  895. /* IPv6 Addr 1 */
  896. memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
  897. sizeof(init_fw_cb->ipv6_addr1));
  898. else
  899. /* IPv6 Addr 0 */
  900. memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
  901. sizeof(init_fw_cb->ipv6_addr0));
  902. break;
  903. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  904. if (iface_param->iface_num & 0x1)
  905. break;
  906. memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
  907. sizeof(init_fw_cb->ipv6_if_id));
  908. break;
  909. case ISCSI_NET_PARAM_IPV6_ROUTER:
  910. if (iface_param->iface_num & 0x1)
  911. break;
  912. memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
  913. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  914. break;
  915. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  916. /* Autocfg applies to even interface */
  917. if (iface_param->iface_num & 0x1)
  918. break;
  919. if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
  920. init_fw_cb->ipv6_addtl_opts &=
  921. cpu_to_le16(
  922. ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  923. else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
  924. init_fw_cb->ipv6_addtl_opts |=
  925. cpu_to_le16(
  926. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  927. else
  928. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  929. "IPv6 addr\n");
  930. break;
  931. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  932. /* Autocfg applies to even interface */
  933. if (iface_param->iface_num & 0x1)
  934. break;
  935. if (iface_param->value[0] ==
  936. ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
  937. init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
  938. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  939. else if (iface_param->value[0] ==
  940. ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
  941. init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
  942. ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  943. else
  944. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  945. "IPv6 linklocal addr\n");
  946. break;
  947. case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
  948. /* Autocfg applies to even interface */
  949. if (iface_param->iface_num & 0x1)
  950. break;
  951. if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
  952. memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
  953. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  954. break;
  955. case ISCSI_NET_PARAM_IFACE_ENABLE:
  956. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  957. init_fw_cb->ipv6_opts |=
  958. cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
  959. qla4xxx_create_ipv6_iface(ha);
  960. } else {
  961. init_fw_cb->ipv6_opts &=
  962. cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
  963. 0xFFFF);
  964. qla4xxx_destroy_ipv6_iface(ha);
  965. }
  966. break;
  967. case ISCSI_NET_PARAM_VLAN_TAG:
  968. if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
  969. break;
  970. init_fw_cb->ipv6_vlan_tag =
  971. cpu_to_be16(*(uint16_t *)iface_param->value);
  972. break;
  973. case ISCSI_NET_PARAM_VLAN_ENABLED:
  974. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  975. init_fw_cb->ipv6_opts |=
  976. cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
  977. else
  978. init_fw_cb->ipv6_opts &=
  979. cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
  980. break;
  981. case ISCSI_NET_PARAM_MTU:
  982. init_fw_cb->eth_mtu_size =
  983. cpu_to_le16(*(uint16_t *)iface_param->value);
  984. break;
  985. case ISCSI_NET_PARAM_PORT:
  986. /* Autocfg applies to even interface */
  987. if (iface_param->iface_num & 0x1)
  988. break;
  989. init_fw_cb->ipv6_port =
  990. cpu_to_le16(*(uint16_t *)iface_param->value);
  991. break;
  992. default:
  993. ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
  994. iface_param->param);
  995. break;
  996. }
  997. }
  998. static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
  999. struct iscsi_iface_param_info *iface_param,
  1000. struct addr_ctrl_blk *init_fw_cb)
  1001. {
  1002. switch (iface_param->param) {
  1003. case ISCSI_NET_PARAM_IPV4_ADDR:
  1004. memcpy(init_fw_cb->ipv4_addr, iface_param->value,
  1005. sizeof(init_fw_cb->ipv4_addr));
  1006. break;
  1007. case ISCSI_NET_PARAM_IPV4_SUBNET:
  1008. memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
  1009. sizeof(init_fw_cb->ipv4_subnet));
  1010. break;
  1011. case ISCSI_NET_PARAM_IPV4_GW:
  1012. memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
  1013. sizeof(init_fw_cb->ipv4_gw_addr));
  1014. break;
  1015. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  1016. if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
  1017. init_fw_cb->ipv4_tcp_opts |=
  1018. cpu_to_le16(TCPOPT_DHCP_ENABLE);
  1019. else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
  1020. init_fw_cb->ipv4_tcp_opts &=
  1021. cpu_to_le16(~TCPOPT_DHCP_ENABLE);
  1022. else
  1023. ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
  1024. break;
  1025. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1026. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  1027. init_fw_cb->ipv4_ip_opts |=
  1028. cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
  1029. qla4xxx_create_ipv4_iface(ha);
  1030. } else {
  1031. init_fw_cb->ipv4_ip_opts &=
  1032. cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
  1033. 0xFFFF);
  1034. qla4xxx_destroy_ipv4_iface(ha);
  1035. }
  1036. break;
  1037. case ISCSI_NET_PARAM_VLAN_TAG:
  1038. if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
  1039. break;
  1040. init_fw_cb->ipv4_vlan_tag =
  1041. cpu_to_be16(*(uint16_t *)iface_param->value);
  1042. break;
  1043. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1044. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  1045. init_fw_cb->ipv4_ip_opts |=
  1046. cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
  1047. else
  1048. init_fw_cb->ipv4_ip_opts &=
  1049. cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
  1050. break;
  1051. case ISCSI_NET_PARAM_MTU:
  1052. init_fw_cb->eth_mtu_size =
  1053. cpu_to_le16(*(uint16_t *)iface_param->value);
  1054. break;
  1055. case ISCSI_NET_PARAM_PORT:
  1056. init_fw_cb->ipv4_port =
  1057. cpu_to_le16(*(uint16_t *)iface_param->value);
  1058. break;
  1059. default:
  1060. ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
  1061. iface_param->param);
  1062. break;
  1063. }
  1064. }
  1065. static void
  1066. qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
  1067. {
  1068. struct addr_ctrl_blk_def *acb;
  1069. acb = (struct addr_ctrl_blk_def *)init_fw_cb;
  1070. memset(acb->reserved1, 0, sizeof(acb->reserved1));
  1071. memset(acb->reserved2, 0, sizeof(acb->reserved2));
  1072. memset(acb->reserved3, 0, sizeof(acb->reserved3));
  1073. memset(acb->reserved4, 0, sizeof(acb->reserved4));
  1074. memset(acb->reserved5, 0, sizeof(acb->reserved5));
  1075. memset(acb->reserved6, 0, sizeof(acb->reserved6));
  1076. memset(acb->reserved7, 0, sizeof(acb->reserved7));
  1077. memset(acb->reserved8, 0, sizeof(acb->reserved8));
  1078. memset(acb->reserved9, 0, sizeof(acb->reserved9));
  1079. memset(acb->reserved10, 0, sizeof(acb->reserved10));
  1080. memset(acb->reserved11, 0, sizeof(acb->reserved11));
  1081. memset(acb->reserved12, 0, sizeof(acb->reserved12));
  1082. memset(acb->reserved13, 0, sizeof(acb->reserved13));
  1083. memset(acb->reserved14, 0, sizeof(acb->reserved14));
  1084. memset(acb->reserved15, 0, sizeof(acb->reserved15));
  1085. }
  1086. static int
  1087. qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
  1088. {
  1089. struct scsi_qla_host *ha = to_qla_host(shost);
  1090. int rval = 0;
  1091. struct iscsi_iface_param_info *iface_param = NULL;
  1092. struct addr_ctrl_blk *init_fw_cb = NULL;
  1093. dma_addr_t init_fw_cb_dma;
  1094. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1095. uint32_t mbox_sts[MBOX_REG_COUNT];
  1096. uint32_t rem = len;
  1097. struct nlattr *attr;
  1098. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  1099. sizeof(struct addr_ctrl_blk),
  1100. &init_fw_cb_dma, GFP_KERNEL);
  1101. if (!init_fw_cb) {
  1102. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
  1103. __func__);
  1104. return -ENOMEM;
  1105. }
  1106. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  1107. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1108. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1109. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
  1110. ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
  1111. rval = -EIO;
  1112. goto exit_init_fw_cb;
  1113. }
  1114. nla_for_each_attr(attr, data, len, rem) {
  1115. iface_param = nla_data(attr);
  1116. if (iface_param->param_type != ISCSI_NET_PARAM)
  1117. continue;
  1118. switch (iface_param->iface_type) {
  1119. case ISCSI_IFACE_TYPE_IPV4:
  1120. switch (iface_param->iface_num) {
  1121. case 0:
  1122. qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
  1123. break;
  1124. default:
  1125. /* Cannot have more than one IPv4 interface */
  1126. ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
  1127. "number = %d\n",
  1128. iface_param->iface_num);
  1129. break;
  1130. }
  1131. break;
  1132. case ISCSI_IFACE_TYPE_IPV6:
  1133. switch (iface_param->iface_num) {
  1134. case 0:
  1135. case 1:
  1136. qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
  1137. break;
  1138. default:
  1139. /* Cannot have more than two IPv6 interface */
  1140. ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
  1141. "number = %d\n",
  1142. iface_param->iface_num);
  1143. break;
  1144. }
  1145. break;
  1146. default:
  1147. ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
  1148. break;
  1149. }
  1150. }
  1151. init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
  1152. rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
  1153. sizeof(struct addr_ctrl_blk),
  1154. FLASH_OPT_RMW_COMMIT);
  1155. if (rval != QLA_SUCCESS) {
  1156. ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
  1157. __func__);
  1158. rval = -EIO;
  1159. goto exit_init_fw_cb;
  1160. }
  1161. rval = qla4xxx_disable_acb(ha);
  1162. if (rval != QLA_SUCCESS) {
  1163. ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
  1164. __func__);
  1165. rval = -EIO;
  1166. goto exit_init_fw_cb;
  1167. }
  1168. wait_for_completion_timeout(&ha->disable_acb_comp,
  1169. DISABLE_ACB_TOV * HZ);
  1170. qla4xxx_initcb_to_acb(init_fw_cb);
  1171. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
  1172. if (rval != QLA_SUCCESS) {
  1173. ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
  1174. __func__);
  1175. rval = -EIO;
  1176. goto exit_init_fw_cb;
  1177. }
  1178. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  1179. qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
  1180. init_fw_cb_dma);
  1181. exit_init_fw_cb:
  1182. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  1183. init_fw_cb, init_fw_cb_dma);
  1184. return rval;
  1185. }
  1186. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  1187. enum iscsi_param param, char *buf)
  1188. {
  1189. struct iscsi_session *sess = cls_sess->dd_data;
  1190. struct ddb_entry *ddb_entry = sess->dd_data;
  1191. struct scsi_qla_host *ha = ddb_entry->ha;
  1192. int rval, len;
  1193. uint16_t idx;
  1194. switch (param) {
  1195. case ISCSI_PARAM_CHAP_IN_IDX:
  1196. rval = qla4xxx_get_chap_index(ha, sess->username_in,
  1197. sess->password_in, BIDI_CHAP,
  1198. &idx);
  1199. if (rval)
  1200. len = sprintf(buf, "\n");
  1201. else
  1202. len = sprintf(buf, "%hu\n", idx);
  1203. break;
  1204. case ISCSI_PARAM_CHAP_OUT_IDX:
  1205. rval = qla4xxx_get_chap_index(ha, sess->username,
  1206. sess->password, LOCAL_CHAP,
  1207. &idx);
  1208. if (rval)
  1209. len = sprintf(buf, "\n");
  1210. else
  1211. len = sprintf(buf, "%hu\n", idx);
  1212. break;
  1213. default:
  1214. return iscsi_session_get_param(cls_sess, param, buf);
  1215. }
  1216. return len;
  1217. }
  1218. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
  1219. enum iscsi_param param, char *buf)
  1220. {
  1221. struct iscsi_conn *conn;
  1222. struct qla_conn *qla_conn;
  1223. struct sockaddr *dst_addr;
  1224. int len = 0;
  1225. conn = cls_conn->dd_data;
  1226. qla_conn = conn->dd_data;
  1227. dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
  1228. switch (param) {
  1229. case ISCSI_PARAM_CONN_PORT:
  1230. case ISCSI_PARAM_CONN_ADDRESS:
  1231. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  1232. dst_addr, param, buf);
  1233. default:
  1234. return iscsi_conn_get_param(cls_conn, param, buf);
  1235. }
  1236. return len;
  1237. }
  1238. int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
  1239. {
  1240. uint32_t mbx_sts = 0;
  1241. uint16_t tmp_ddb_index;
  1242. int ret;
  1243. get_ddb_index:
  1244. tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
  1245. if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
  1246. DEBUG2(ql4_printk(KERN_INFO, ha,
  1247. "Free DDB index not available\n"));
  1248. ret = QLA_ERROR;
  1249. goto exit_get_ddb_index;
  1250. }
  1251. if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
  1252. goto get_ddb_index;
  1253. DEBUG2(ql4_printk(KERN_INFO, ha,
  1254. "Found a free DDB index at %d\n", tmp_ddb_index));
  1255. ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
  1256. if (ret == QLA_ERROR) {
  1257. if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
  1258. ql4_printk(KERN_INFO, ha,
  1259. "DDB index = %d not available trying next\n",
  1260. tmp_ddb_index);
  1261. goto get_ddb_index;
  1262. }
  1263. DEBUG2(ql4_printk(KERN_INFO, ha,
  1264. "Free FW DDB not available\n"));
  1265. }
  1266. *ddb_index = tmp_ddb_index;
  1267. exit_get_ddb_index:
  1268. return ret;
  1269. }
  1270. static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
  1271. struct ddb_entry *ddb_entry,
  1272. char *existing_ipaddr,
  1273. char *user_ipaddr)
  1274. {
  1275. uint8_t dst_ipaddr[IPv6_ADDR_LEN];
  1276. char formatted_ipaddr[DDB_IPADDR_LEN];
  1277. int status = QLA_SUCCESS, ret = 0;
  1278. if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
  1279. ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  1280. '\0', NULL);
  1281. if (ret == 0) {
  1282. status = QLA_ERROR;
  1283. goto out_match;
  1284. }
  1285. ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
  1286. } else {
  1287. ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  1288. '\0', NULL);
  1289. if (ret == 0) {
  1290. status = QLA_ERROR;
  1291. goto out_match;
  1292. }
  1293. ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
  1294. }
  1295. if (strcmp(existing_ipaddr, formatted_ipaddr))
  1296. status = QLA_ERROR;
  1297. out_match:
  1298. return status;
  1299. }
  1300. static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
  1301. struct iscsi_cls_conn *cls_conn)
  1302. {
  1303. int idx = 0, max_ddbs, rval;
  1304. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1305. struct iscsi_session *sess, *existing_sess;
  1306. struct iscsi_conn *conn, *existing_conn;
  1307. struct ddb_entry *ddb_entry;
  1308. sess = cls_sess->dd_data;
  1309. conn = cls_conn->dd_data;
  1310. if (sess->targetname == NULL ||
  1311. conn->persistent_address == NULL ||
  1312. conn->persistent_port == 0)
  1313. return QLA_ERROR;
  1314. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  1315. MAX_DEV_DB_ENTRIES;
  1316. for (idx = 0; idx < max_ddbs; idx++) {
  1317. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  1318. if (ddb_entry == NULL)
  1319. continue;
  1320. if (ddb_entry->ddb_type != FLASH_DDB)
  1321. continue;
  1322. existing_sess = ddb_entry->sess->dd_data;
  1323. existing_conn = ddb_entry->conn->dd_data;
  1324. if (existing_sess->targetname == NULL ||
  1325. existing_conn->persistent_address == NULL ||
  1326. existing_conn->persistent_port == 0)
  1327. continue;
  1328. DEBUG2(ql4_printk(KERN_INFO, ha,
  1329. "IQN = %s User IQN = %s\n",
  1330. existing_sess->targetname,
  1331. sess->targetname));
  1332. DEBUG2(ql4_printk(KERN_INFO, ha,
  1333. "IP = %s User IP = %s\n",
  1334. existing_conn->persistent_address,
  1335. conn->persistent_address));
  1336. DEBUG2(ql4_printk(KERN_INFO, ha,
  1337. "Port = %d User Port = %d\n",
  1338. existing_conn->persistent_port,
  1339. conn->persistent_port));
  1340. if (strcmp(existing_sess->targetname, sess->targetname))
  1341. continue;
  1342. rval = qla4xxx_match_ipaddress(ha, ddb_entry,
  1343. existing_conn->persistent_address,
  1344. conn->persistent_address);
  1345. if (rval == QLA_ERROR)
  1346. continue;
  1347. if (existing_conn->persistent_port != conn->persistent_port)
  1348. continue;
  1349. break;
  1350. }
  1351. if (idx == max_ddbs)
  1352. return QLA_ERROR;
  1353. DEBUG2(ql4_printk(KERN_INFO, ha,
  1354. "Match found in fwdb sessions\n"));
  1355. return QLA_SUCCESS;
  1356. }
  1357. static struct iscsi_cls_session *
  1358. qla4xxx_session_create(struct iscsi_endpoint *ep,
  1359. uint16_t cmds_max, uint16_t qdepth,
  1360. uint32_t initial_cmdsn)
  1361. {
  1362. struct iscsi_cls_session *cls_sess;
  1363. struct scsi_qla_host *ha;
  1364. struct qla_endpoint *qla_ep;
  1365. struct ddb_entry *ddb_entry;
  1366. uint16_t ddb_index;
  1367. struct iscsi_session *sess;
  1368. struct sockaddr *dst_addr;
  1369. int ret;
  1370. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1371. if (!ep) {
  1372. printk(KERN_ERR "qla4xxx: missing ep.\n");
  1373. return NULL;
  1374. }
  1375. qla_ep = ep->dd_data;
  1376. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  1377. ha = to_qla_host(qla_ep->host);
  1378. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  1379. if (ret == QLA_ERROR)
  1380. return NULL;
  1381. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
  1382. cmds_max, sizeof(struct ddb_entry),
  1383. sizeof(struct ql4_task_data),
  1384. initial_cmdsn, ddb_index);
  1385. if (!cls_sess)
  1386. return NULL;
  1387. sess = cls_sess->dd_data;
  1388. ddb_entry = sess->dd_data;
  1389. ddb_entry->fw_ddb_index = ddb_index;
  1390. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  1391. ddb_entry->ha = ha;
  1392. ddb_entry->sess = cls_sess;
  1393. ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
  1394. ddb_entry->ddb_change = qla4xxx_ddb_change;
  1395. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  1396. ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
  1397. ha->tot_ddbs++;
  1398. return cls_sess;
  1399. }
  1400. static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
  1401. {
  1402. struct iscsi_session *sess;
  1403. struct ddb_entry *ddb_entry;
  1404. struct scsi_qla_host *ha;
  1405. unsigned long flags, wtime;
  1406. struct dev_db_entry *fw_ddb_entry = NULL;
  1407. dma_addr_t fw_ddb_entry_dma;
  1408. uint32_t ddb_state;
  1409. int ret;
  1410. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1411. sess = cls_sess->dd_data;
  1412. ddb_entry = sess->dd_data;
  1413. ha = ddb_entry->ha;
  1414. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1415. &fw_ddb_entry_dma, GFP_KERNEL);
  1416. if (!fw_ddb_entry) {
  1417. ql4_printk(KERN_ERR, ha,
  1418. "%s: Unable to allocate dma buffer\n", __func__);
  1419. goto destroy_session;
  1420. }
  1421. wtime = jiffies + (HZ * LOGOUT_TOV);
  1422. do {
  1423. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  1424. fw_ddb_entry, fw_ddb_entry_dma,
  1425. NULL, NULL, &ddb_state, NULL,
  1426. NULL, NULL);
  1427. if (ret == QLA_ERROR)
  1428. goto destroy_session;
  1429. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  1430. (ddb_state == DDB_DS_SESSION_FAILED))
  1431. goto destroy_session;
  1432. schedule_timeout_uninterruptible(HZ);
  1433. } while ((time_after(wtime, jiffies)));
  1434. destroy_session:
  1435. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  1436. spin_lock_irqsave(&ha->hardware_lock, flags);
  1437. qla4xxx_free_ddb(ha, ddb_entry);
  1438. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1439. iscsi_session_teardown(cls_sess);
  1440. if (fw_ddb_entry)
  1441. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1442. fw_ddb_entry, fw_ddb_entry_dma);
  1443. }
  1444. static struct iscsi_cls_conn *
  1445. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
  1446. {
  1447. struct iscsi_cls_conn *cls_conn;
  1448. struct iscsi_session *sess;
  1449. struct ddb_entry *ddb_entry;
  1450. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1451. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
  1452. conn_idx);
  1453. if (!cls_conn)
  1454. return NULL;
  1455. sess = cls_sess->dd_data;
  1456. ddb_entry = sess->dd_data;
  1457. ddb_entry->conn = cls_conn;
  1458. return cls_conn;
  1459. }
  1460. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  1461. struct iscsi_cls_conn *cls_conn,
  1462. uint64_t transport_fd, int is_leading)
  1463. {
  1464. struct iscsi_conn *conn;
  1465. struct qla_conn *qla_conn;
  1466. struct iscsi_endpoint *ep;
  1467. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1468. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  1469. return -EINVAL;
  1470. ep = iscsi_lookup_endpoint(transport_fd);
  1471. conn = cls_conn->dd_data;
  1472. qla_conn = conn->dd_data;
  1473. qla_conn->qla_ep = ep->dd_data;
  1474. return 0;
  1475. }
  1476. static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
  1477. {
  1478. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1479. struct iscsi_session *sess;
  1480. struct ddb_entry *ddb_entry;
  1481. struct scsi_qla_host *ha;
  1482. struct dev_db_entry *fw_ddb_entry = NULL;
  1483. dma_addr_t fw_ddb_entry_dma;
  1484. uint32_t mbx_sts = 0;
  1485. int ret = 0;
  1486. int status = QLA_SUCCESS;
  1487. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1488. sess = cls_sess->dd_data;
  1489. ddb_entry = sess->dd_data;
  1490. ha = ddb_entry->ha;
  1491. /* Check if we have matching FW DDB, if yes then do not
  1492. * login to this target. This could cause target to logout previous
  1493. * connection
  1494. */
  1495. ret = qla4xxx_match_fwdb_session(ha, cls_conn);
  1496. if (ret == QLA_SUCCESS) {
  1497. ql4_printk(KERN_INFO, ha,
  1498. "Session already exist in FW.\n");
  1499. ret = -EEXIST;
  1500. goto exit_conn_start;
  1501. }
  1502. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1503. &fw_ddb_entry_dma, GFP_KERNEL);
  1504. if (!fw_ddb_entry) {
  1505. ql4_printk(KERN_ERR, ha,
  1506. "%s: Unable to allocate dma buffer\n", __func__);
  1507. ret = -ENOMEM;
  1508. goto exit_conn_start;
  1509. }
  1510. ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
  1511. if (ret) {
  1512. /* If iscsid is stopped and started then no need to do
  1513. * set param again since ddb state will be already
  1514. * active and FW does not allow set ddb to an
  1515. * active session.
  1516. */
  1517. if (mbx_sts)
  1518. if (ddb_entry->fw_ddb_device_state ==
  1519. DDB_DS_SESSION_ACTIVE) {
  1520. ddb_entry->unblock_sess(ddb_entry->sess);
  1521. goto exit_set_param;
  1522. }
  1523. ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
  1524. __func__, ddb_entry->fw_ddb_index);
  1525. goto exit_conn_start;
  1526. }
  1527. status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
  1528. if (status == QLA_ERROR) {
  1529. ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
  1530. sess->targetname);
  1531. ret = -EINVAL;
  1532. goto exit_conn_start;
  1533. }
  1534. if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
  1535. ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
  1536. DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
  1537. ddb_entry->fw_ddb_device_state));
  1538. exit_set_param:
  1539. ret = 0;
  1540. exit_conn_start:
  1541. if (fw_ddb_entry)
  1542. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1543. fw_ddb_entry, fw_ddb_entry_dma);
  1544. return ret;
  1545. }
  1546. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
  1547. {
  1548. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1549. struct iscsi_session *sess;
  1550. struct scsi_qla_host *ha;
  1551. struct ddb_entry *ddb_entry;
  1552. int options;
  1553. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1554. sess = cls_sess->dd_data;
  1555. ddb_entry = sess->dd_data;
  1556. ha = ddb_entry->ha;
  1557. options = LOGOUT_OPTION_CLOSE_SESSION;
  1558. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
  1559. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  1560. }
  1561. static void qla4xxx_task_work(struct work_struct *wdata)
  1562. {
  1563. struct ql4_task_data *task_data;
  1564. struct scsi_qla_host *ha;
  1565. struct passthru_status *sts;
  1566. struct iscsi_task *task;
  1567. struct iscsi_hdr *hdr;
  1568. uint8_t *data;
  1569. uint32_t data_len;
  1570. struct iscsi_conn *conn;
  1571. int hdr_len;
  1572. itt_t itt;
  1573. task_data = container_of(wdata, struct ql4_task_data, task_work);
  1574. ha = task_data->ha;
  1575. task = task_data->task;
  1576. sts = &task_data->sts;
  1577. hdr_len = sizeof(struct iscsi_hdr);
  1578. DEBUG3(printk(KERN_INFO "Status returned\n"));
  1579. DEBUG3(qla4xxx_dump_buffer(sts, 64));
  1580. DEBUG3(printk(KERN_INFO "Response buffer"));
  1581. DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
  1582. conn = task->conn;
  1583. switch (sts->completionStatus) {
  1584. case PASSTHRU_STATUS_COMPLETE:
  1585. hdr = (struct iscsi_hdr *)task_data->resp_buffer;
  1586. /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
  1587. itt = sts->handle;
  1588. hdr->itt = itt;
  1589. data = task_data->resp_buffer + hdr_len;
  1590. data_len = task_data->resp_len - hdr_len;
  1591. iscsi_complete_pdu(conn, hdr, data, data_len);
  1592. break;
  1593. default:
  1594. ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
  1595. sts->completionStatus);
  1596. break;
  1597. }
  1598. return;
  1599. }
  1600. static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  1601. {
  1602. struct ql4_task_data *task_data;
  1603. struct iscsi_session *sess;
  1604. struct ddb_entry *ddb_entry;
  1605. struct scsi_qla_host *ha;
  1606. int hdr_len;
  1607. sess = task->conn->session;
  1608. ddb_entry = sess->dd_data;
  1609. ha = ddb_entry->ha;
  1610. task_data = task->dd_data;
  1611. memset(task_data, 0, sizeof(struct ql4_task_data));
  1612. if (task->sc) {
  1613. ql4_printk(KERN_INFO, ha,
  1614. "%s: SCSI Commands not implemented\n", __func__);
  1615. return -EINVAL;
  1616. }
  1617. hdr_len = sizeof(struct iscsi_hdr);
  1618. task_data->ha = ha;
  1619. task_data->task = task;
  1620. if (task->data_count) {
  1621. task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
  1622. task->data_count,
  1623. PCI_DMA_TODEVICE);
  1624. }
  1625. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1626. __func__, task->conn->max_recv_dlength, hdr_len));
  1627. task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
  1628. task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1629. task_data->resp_len,
  1630. &task_data->resp_dma,
  1631. GFP_ATOMIC);
  1632. if (!task_data->resp_buffer)
  1633. goto exit_alloc_pdu;
  1634. task_data->req_len = task->data_count + hdr_len;
  1635. task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1636. task_data->req_len,
  1637. &task_data->req_dma,
  1638. GFP_ATOMIC);
  1639. if (!task_data->req_buffer)
  1640. goto exit_alloc_pdu;
  1641. task->hdr = task_data->req_buffer;
  1642. INIT_WORK(&task_data->task_work, qla4xxx_task_work);
  1643. return 0;
  1644. exit_alloc_pdu:
  1645. if (task_data->resp_buffer)
  1646. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1647. task_data->resp_buffer, task_data->resp_dma);
  1648. if (task_data->req_buffer)
  1649. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1650. task_data->req_buffer, task_data->req_dma);
  1651. return -ENOMEM;
  1652. }
  1653. static void qla4xxx_task_cleanup(struct iscsi_task *task)
  1654. {
  1655. struct ql4_task_data *task_data;
  1656. struct iscsi_session *sess;
  1657. struct ddb_entry *ddb_entry;
  1658. struct scsi_qla_host *ha;
  1659. int hdr_len;
  1660. hdr_len = sizeof(struct iscsi_hdr);
  1661. sess = task->conn->session;
  1662. ddb_entry = sess->dd_data;
  1663. ha = ddb_entry->ha;
  1664. task_data = task->dd_data;
  1665. if (task->data_count) {
  1666. dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
  1667. task->data_count, PCI_DMA_TODEVICE);
  1668. }
  1669. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1670. __func__, task->conn->max_recv_dlength, hdr_len));
  1671. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1672. task_data->resp_buffer, task_data->resp_dma);
  1673. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1674. task_data->req_buffer, task_data->req_dma);
  1675. return;
  1676. }
  1677. static int qla4xxx_task_xmit(struct iscsi_task *task)
  1678. {
  1679. struct scsi_cmnd *sc = task->sc;
  1680. struct iscsi_session *sess = task->conn->session;
  1681. struct ddb_entry *ddb_entry = sess->dd_data;
  1682. struct scsi_qla_host *ha = ddb_entry->ha;
  1683. if (!sc)
  1684. return qla4xxx_send_passthru0(task);
  1685. ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
  1686. __func__);
  1687. return -ENOSYS;
  1688. }
  1689. static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
  1690. struct dev_db_entry *fw_ddb_entry,
  1691. struct iscsi_cls_session *cls_sess,
  1692. struct iscsi_cls_conn *cls_conn)
  1693. {
  1694. int buflen = 0;
  1695. struct iscsi_session *sess;
  1696. struct ddb_entry *ddb_entry;
  1697. struct iscsi_conn *conn;
  1698. char ip_addr[DDB_IPADDR_LEN];
  1699. uint16_t options = 0;
  1700. sess = cls_sess->dd_data;
  1701. ddb_entry = sess->dd_data;
  1702. conn = cls_conn->dd_data;
  1703. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  1704. conn->max_recv_dlength = BYTE_UNITS *
  1705. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  1706. conn->max_xmit_dlength = BYTE_UNITS *
  1707. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  1708. sess->initial_r2t_en =
  1709. (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1710. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  1711. sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1712. sess->first_burst = BYTE_UNITS *
  1713. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  1714. sess->max_burst = BYTE_UNITS *
  1715. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  1716. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1717. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  1718. conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
  1719. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  1720. options = le16_to_cpu(fw_ddb_entry->options);
  1721. if (options & DDB_OPT_IPV6_DEVICE)
  1722. sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  1723. else
  1724. sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  1725. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
  1726. (char *)fw_ddb_entry->iscsi_name, buflen);
  1727. iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
  1728. (char *)ha->name_string, buflen);
  1729. iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
  1730. (char *)ip_addr, buflen);
  1731. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  1732. (char *)fw_ddb_entry->iscsi_alias, buflen);
  1733. }
  1734. void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
  1735. struct ddb_entry *ddb_entry)
  1736. {
  1737. struct iscsi_cls_session *cls_sess;
  1738. struct iscsi_cls_conn *cls_conn;
  1739. uint32_t ddb_state;
  1740. dma_addr_t fw_ddb_entry_dma;
  1741. struct dev_db_entry *fw_ddb_entry;
  1742. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1743. &fw_ddb_entry_dma, GFP_KERNEL);
  1744. if (!fw_ddb_entry) {
  1745. ql4_printk(KERN_ERR, ha,
  1746. "%s: Unable to allocate dma buffer\n", __func__);
  1747. goto exit_session_conn_fwddb_param;
  1748. }
  1749. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  1750. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  1751. NULL, NULL, NULL) == QLA_ERROR) {
  1752. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1753. "get_ddb_entry for fw_ddb_index %d\n",
  1754. ha->host_no, __func__,
  1755. ddb_entry->fw_ddb_index));
  1756. goto exit_session_conn_fwddb_param;
  1757. }
  1758. cls_sess = ddb_entry->sess;
  1759. cls_conn = ddb_entry->conn;
  1760. /* Update params */
  1761. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  1762. exit_session_conn_fwddb_param:
  1763. if (fw_ddb_entry)
  1764. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1765. fw_ddb_entry, fw_ddb_entry_dma);
  1766. }
  1767. void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
  1768. struct ddb_entry *ddb_entry)
  1769. {
  1770. struct iscsi_cls_session *cls_sess;
  1771. struct iscsi_cls_conn *cls_conn;
  1772. struct iscsi_session *sess;
  1773. struct iscsi_conn *conn;
  1774. uint32_t ddb_state;
  1775. dma_addr_t fw_ddb_entry_dma;
  1776. struct dev_db_entry *fw_ddb_entry;
  1777. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1778. &fw_ddb_entry_dma, GFP_KERNEL);
  1779. if (!fw_ddb_entry) {
  1780. ql4_printk(KERN_ERR, ha,
  1781. "%s: Unable to allocate dma buffer\n", __func__);
  1782. goto exit_session_conn_param;
  1783. }
  1784. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  1785. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  1786. NULL, NULL, NULL) == QLA_ERROR) {
  1787. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1788. "get_ddb_entry for fw_ddb_index %d\n",
  1789. ha->host_no, __func__,
  1790. ddb_entry->fw_ddb_index));
  1791. goto exit_session_conn_param;
  1792. }
  1793. cls_sess = ddb_entry->sess;
  1794. sess = cls_sess->dd_data;
  1795. cls_conn = ddb_entry->conn;
  1796. conn = cls_conn->dd_data;
  1797. /* Update timers after login */
  1798. ddb_entry->default_relogin_timeout =
  1799. (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
  1800. (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
  1801. le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
  1802. ddb_entry->default_time2wait =
  1803. le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1804. /* Update params */
  1805. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  1806. conn->max_recv_dlength = BYTE_UNITS *
  1807. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  1808. conn->max_xmit_dlength = BYTE_UNITS *
  1809. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  1810. sess->initial_r2t_en =
  1811. (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1812. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  1813. sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1814. sess->first_burst = BYTE_UNITS *
  1815. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  1816. sess->max_burst = BYTE_UNITS *
  1817. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  1818. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1819. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  1820. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  1821. memcpy(sess->initiatorname, ha->name_string,
  1822. min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
  1823. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  1824. (char *)fw_ddb_entry->iscsi_alias, 0);
  1825. exit_session_conn_param:
  1826. if (fw_ddb_entry)
  1827. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1828. fw_ddb_entry, fw_ddb_entry_dma);
  1829. }
  1830. /*
  1831. * Timer routines
  1832. */
  1833. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  1834. unsigned long interval)
  1835. {
  1836. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  1837. __func__, ha->host->host_no));
  1838. init_timer(&ha->timer);
  1839. ha->timer.expires = jiffies + interval * HZ;
  1840. ha->timer.data = (unsigned long)ha;
  1841. ha->timer.function = (void (*)(unsigned long))func;
  1842. add_timer(&ha->timer);
  1843. ha->timer_active = 1;
  1844. }
  1845. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  1846. {
  1847. del_timer_sync(&ha->timer);
  1848. ha->timer_active = 0;
  1849. }
  1850. /***
  1851. * qla4xxx_mark_device_missing - blocks the session
  1852. * @cls_session: Pointer to the session to be blocked
  1853. * @ddb_entry: Pointer to device database entry
  1854. *
  1855. * This routine marks a device missing and close connection.
  1856. **/
  1857. void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
  1858. {
  1859. iscsi_block_session(cls_session);
  1860. }
  1861. /**
  1862. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  1863. * @ha: Pointer to host adapter structure.
  1864. *
  1865. * This routine marks a device missing and resets the relogin retry count.
  1866. **/
  1867. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  1868. {
  1869. iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
  1870. }
  1871. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  1872. struct ddb_entry *ddb_entry,
  1873. struct scsi_cmnd *cmd)
  1874. {
  1875. struct srb *srb;
  1876. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  1877. if (!srb)
  1878. return srb;
  1879. kref_init(&srb->srb_ref);
  1880. srb->ha = ha;
  1881. srb->ddb = ddb_entry;
  1882. srb->cmd = cmd;
  1883. srb->flags = 0;
  1884. CMD_SP(cmd) = (void *)srb;
  1885. return srb;
  1886. }
  1887. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  1888. {
  1889. struct scsi_cmnd *cmd = srb->cmd;
  1890. if (srb->flags & SRB_DMA_VALID) {
  1891. scsi_dma_unmap(cmd);
  1892. srb->flags &= ~SRB_DMA_VALID;
  1893. }
  1894. CMD_SP(cmd) = NULL;
  1895. }
  1896. void qla4xxx_srb_compl(struct kref *ref)
  1897. {
  1898. struct srb *srb = container_of(ref, struct srb, srb_ref);
  1899. struct scsi_cmnd *cmd = srb->cmd;
  1900. struct scsi_qla_host *ha = srb->ha;
  1901. qla4xxx_srb_free_dma(ha, srb);
  1902. mempool_free(srb, ha->srb_mempool);
  1903. cmd->scsi_done(cmd);
  1904. }
  1905. /**
  1906. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  1907. * @host: scsi host
  1908. * @cmd: Pointer to Linux's SCSI command structure
  1909. *
  1910. * Remarks:
  1911. * This routine is invoked by Linux to send a SCSI command to the driver.
  1912. * The mid-level driver tries to ensure that queuecommand never gets
  1913. * invoked concurrently with itself or the interrupt handler (although
  1914. * the interrupt handler may call this routine as part of request-
  1915. * completion handling). Unfortunely, it sometimes calls the scheduler
  1916. * in interrupt context which is a big NO! NO!.
  1917. **/
  1918. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  1919. {
  1920. struct scsi_qla_host *ha = to_qla_host(host);
  1921. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  1922. struct iscsi_cls_session *sess = ddb_entry->sess;
  1923. struct srb *srb;
  1924. int rval;
  1925. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  1926. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  1927. cmd->result = DID_NO_CONNECT << 16;
  1928. else
  1929. cmd->result = DID_REQUEUE << 16;
  1930. goto qc_fail_command;
  1931. }
  1932. if (!sess) {
  1933. cmd->result = DID_IMM_RETRY << 16;
  1934. goto qc_fail_command;
  1935. }
  1936. rval = iscsi_session_chkready(sess);
  1937. if (rval) {
  1938. cmd->result = rval;
  1939. goto qc_fail_command;
  1940. }
  1941. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  1942. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  1943. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1944. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  1945. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  1946. !test_bit(AF_ONLINE, &ha->flags) ||
  1947. !test_bit(AF_LINK_UP, &ha->flags) ||
  1948. test_bit(AF_LOOPBACK, &ha->flags) ||
  1949. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  1950. goto qc_host_busy;
  1951. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  1952. if (!srb)
  1953. goto qc_host_busy;
  1954. rval = qla4xxx_send_command_to_isp(ha, srb);
  1955. if (rval != QLA_SUCCESS)
  1956. goto qc_host_busy_free_sp;
  1957. return 0;
  1958. qc_host_busy_free_sp:
  1959. qla4xxx_srb_free_dma(ha, srb);
  1960. mempool_free(srb, ha->srb_mempool);
  1961. qc_host_busy:
  1962. return SCSI_MLQUEUE_HOST_BUSY;
  1963. qc_fail_command:
  1964. cmd->scsi_done(cmd);
  1965. return 0;
  1966. }
  1967. /**
  1968. * qla4xxx_mem_free - frees memory allocated to adapter
  1969. * @ha: Pointer to host adapter structure.
  1970. *
  1971. * Frees memory previously allocated by qla4xxx_mem_alloc
  1972. **/
  1973. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  1974. {
  1975. if (ha->queues)
  1976. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  1977. ha->queues_dma);
  1978. if (ha->fw_dump)
  1979. vfree(ha->fw_dump);
  1980. ha->queues_len = 0;
  1981. ha->queues = NULL;
  1982. ha->queues_dma = 0;
  1983. ha->request_ring = NULL;
  1984. ha->request_dma = 0;
  1985. ha->response_ring = NULL;
  1986. ha->response_dma = 0;
  1987. ha->shadow_regs = NULL;
  1988. ha->shadow_regs_dma = 0;
  1989. ha->fw_dump = NULL;
  1990. ha->fw_dump_size = 0;
  1991. /* Free srb pool. */
  1992. if (ha->srb_mempool)
  1993. mempool_destroy(ha->srb_mempool);
  1994. ha->srb_mempool = NULL;
  1995. if (ha->chap_dma_pool)
  1996. dma_pool_destroy(ha->chap_dma_pool);
  1997. if (ha->chap_list)
  1998. vfree(ha->chap_list);
  1999. ha->chap_list = NULL;
  2000. if (ha->fw_ddb_dma_pool)
  2001. dma_pool_destroy(ha->fw_ddb_dma_pool);
  2002. /* release io space registers */
  2003. if (is_qla8022(ha)) {
  2004. if (ha->nx_pcibase)
  2005. iounmap(
  2006. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  2007. } else if (is_qla8032(ha)) {
  2008. if (ha->nx_pcibase)
  2009. iounmap(
  2010. (struct device_reg_83xx __iomem *)ha->nx_pcibase);
  2011. } else if (ha->reg) {
  2012. iounmap(ha->reg);
  2013. }
  2014. if (ha->reset_tmplt.buff)
  2015. vfree(ha->reset_tmplt.buff);
  2016. pci_release_regions(ha->pdev);
  2017. }
  2018. /**
  2019. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  2020. * @ha: Pointer to host adapter structure
  2021. *
  2022. * Allocates DMA memory for request and response queues. Also allocates memory
  2023. * for srbs.
  2024. **/
  2025. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  2026. {
  2027. unsigned long align;
  2028. /* Allocate contiguous block of DMA memory for queues. */
  2029. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2030. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  2031. sizeof(struct shadow_regs) +
  2032. MEM_ALIGN_VALUE +
  2033. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  2034. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  2035. &ha->queues_dma, GFP_KERNEL);
  2036. if (ha->queues == NULL) {
  2037. ql4_printk(KERN_WARNING, ha,
  2038. "Memory Allocation failed - queues.\n");
  2039. goto mem_alloc_error_exit;
  2040. }
  2041. memset(ha->queues, 0, ha->queues_len);
  2042. /*
  2043. * As per RISC alignment requirements -- the bus-address must be a
  2044. * multiple of the request-ring size (in bytes).
  2045. */
  2046. align = 0;
  2047. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  2048. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  2049. (MEM_ALIGN_VALUE - 1));
  2050. /* Update request and response queue pointers. */
  2051. ha->request_dma = ha->queues_dma + align;
  2052. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  2053. ha->response_dma = ha->queues_dma + align +
  2054. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  2055. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  2056. (REQUEST_QUEUE_DEPTH *
  2057. QUEUE_SIZE));
  2058. ha->shadow_regs_dma = ha->queues_dma + align +
  2059. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2060. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  2061. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  2062. (REQUEST_QUEUE_DEPTH *
  2063. QUEUE_SIZE) +
  2064. (RESPONSE_QUEUE_DEPTH *
  2065. QUEUE_SIZE));
  2066. /* Allocate memory for srb pool. */
  2067. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  2068. mempool_free_slab, srb_cachep);
  2069. if (ha->srb_mempool == NULL) {
  2070. ql4_printk(KERN_WARNING, ha,
  2071. "Memory Allocation failed - SRB Pool.\n");
  2072. goto mem_alloc_error_exit;
  2073. }
  2074. ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
  2075. CHAP_DMA_BLOCK_SIZE, 8, 0);
  2076. if (ha->chap_dma_pool == NULL) {
  2077. ql4_printk(KERN_WARNING, ha,
  2078. "%s: chap_dma_pool allocation failed..\n", __func__);
  2079. goto mem_alloc_error_exit;
  2080. }
  2081. ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
  2082. DDB_DMA_BLOCK_SIZE, 8, 0);
  2083. if (ha->fw_ddb_dma_pool == NULL) {
  2084. ql4_printk(KERN_WARNING, ha,
  2085. "%s: fw_ddb_dma_pool allocation failed..\n",
  2086. __func__);
  2087. goto mem_alloc_error_exit;
  2088. }
  2089. return QLA_SUCCESS;
  2090. mem_alloc_error_exit:
  2091. qla4xxx_mem_free(ha);
  2092. return QLA_ERROR;
  2093. }
  2094. /**
  2095. * qla4_8xxx_check_temp - Check the ISP82XX temperature.
  2096. * @ha: adapter block pointer.
  2097. *
  2098. * Note: The caller should not hold the idc lock.
  2099. **/
  2100. static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
  2101. {
  2102. uint32_t temp, temp_state, temp_val;
  2103. int status = QLA_SUCCESS;
  2104. temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
  2105. temp_state = qla82xx_get_temp_state(temp);
  2106. temp_val = qla82xx_get_temp_val(temp);
  2107. if (temp_state == QLA82XX_TEMP_PANIC) {
  2108. ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
  2109. " exceeds maximum allowed. Hardware has been shut"
  2110. " down.\n", temp_val);
  2111. status = QLA_ERROR;
  2112. } else if (temp_state == QLA82XX_TEMP_WARN) {
  2113. if (ha->temperature == QLA82XX_TEMP_NORMAL)
  2114. ql4_printk(KERN_WARNING, ha, "Device temperature %d"
  2115. " degrees C exceeds operating range."
  2116. " Immediate action needed.\n", temp_val);
  2117. } else {
  2118. if (ha->temperature == QLA82XX_TEMP_WARN)
  2119. ql4_printk(KERN_INFO, ha, "Device temperature is"
  2120. " now %d degrees C in normal range.\n",
  2121. temp_val);
  2122. }
  2123. ha->temperature = temp_state;
  2124. return status;
  2125. }
  2126. /**
  2127. * qla4_8xxx_check_fw_alive - Check firmware health
  2128. * @ha: Pointer to host adapter structure.
  2129. *
  2130. * Context: Interrupt
  2131. **/
  2132. static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  2133. {
  2134. uint32_t fw_heartbeat_counter;
  2135. int status = QLA_SUCCESS;
  2136. fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
  2137. QLA8XXX_PEG_ALIVE_COUNTER);
  2138. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  2139. if (fw_heartbeat_counter == 0xffffffff) {
  2140. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  2141. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  2142. ha->host_no, __func__));
  2143. return status;
  2144. }
  2145. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  2146. ha->seconds_since_last_heartbeat++;
  2147. /* FW not alive after 2 seconds */
  2148. if (ha->seconds_since_last_heartbeat == 2) {
  2149. ha->seconds_since_last_heartbeat = 0;
  2150. qla4_8xxx_dump_peg_reg(ha);
  2151. status = QLA_ERROR;
  2152. }
  2153. } else
  2154. ha->seconds_since_last_heartbeat = 0;
  2155. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  2156. return status;
  2157. }
  2158. static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
  2159. {
  2160. uint32_t halt_status;
  2161. int halt_status_unrecoverable = 0;
  2162. halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
  2163. if (is_qla8022(ha)) {
  2164. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2165. __func__);
  2166. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2167. CRB_NIU_XG_PAUSE_CTL_P0 |
  2168. CRB_NIU_XG_PAUSE_CTL_P1);
  2169. if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
  2170. ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
  2171. __func__);
  2172. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  2173. halt_status_unrecoverable = 1;
  2174. } else if (is_qla8032(ha)) {
  2175. if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
  2176. ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
  2177. __func__);
  2178. else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
  2179. halt_status_unrecoverable = 1;
  2180. }
  2181. /*
  2182. * Since we cannot change dev_state in interrupt context,
  2183. * set appropriate DPC flag then wakeup DPC
  2184. */
  2185. if (halt_status_unrecoverable) {
  2186. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2187. } else {
  2188. ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
  2189. __func__);
  2190. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2191. }
  2192. qla4xxx_mailbox_premature_completion(ha);
  2193. qla4xxx_wake_dpc(ha);
  2194. }
  2195. /**
  2196. * qla4_8xxx_watchdog - Poll dev state
  2197. * @ha: Pointer to host adapter structure.
  2198. *
  2199. * Context: Interrupt
  2200. **/
  2201. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  2202. {
  2203. uint32_t dev_state;
  2204. uint32_t idc_ctrl;
  2205. /* don't poll if reset is going on */
  2206. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  2207. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2208. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  2209. dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
  2210. if (qla4_8xxx_check_temp(ha)) {
  2211. if (is_qla8022(ha)) {
  2212. ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
  2213. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2214. CRB_NIU_XG_PAUSE_CTL_P0 |
  2215. CRB_NIU_XG_PAUSE_CTL_P1);
  2216. }
  2217. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2218. qla4xxx_wake_dpc(ha);
  2219. } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
  2220. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  2221. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
  2222. __func__);
  2223. if (is_qla8032(ha)) {
  2224. idc_ctrl = qla4_83xx_rd_reg(ha,
  2225. QLA83XX_IDC_DRV_CTRL);
  2226. if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
  2227. ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
  2228. __func__);
  2229. qla4xxx_mailbox_premature_completion(
  2230. ha);
  2231. }
  2232. }
  2233. if (is_qla8032(ha) ||
  2234. (is_qla8022(ha) && !ql4xdontresethba)) {
  2235. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2236. qla4xxx_wake_dpc(ha);
  2237. }
  2238. } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
  2239. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2240. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  2241. __func__);
  2242. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  2243. qla4xxx_wake_dpc(ha);
  2244. } else {
  2245. /* Check firmware health */
  2246. if (qla4_8xxx_check_fw_alive(ha))
  2247. qla4_8xxx_process_fw_error(ha);
  2248. }
  2249. }
  2250. }
  2251. static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  2252. {
  2253. struct iscsi_session *sess;
  2254. struct ddb_entry *ddb_entry;
  2255. struct scsi_qla_host *ha;
  2256. sess = cls_sess->dd_data;
  2257. ddb_entry = sess->dd_data;
  2258. ha = ddb_entry->ha;
  2259. if (!(ddb_entry->ddb_type == FLASH_DDB))
  2260. return;
  2261. if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  2262. !iscsi_is_session_online(cls_sess)) {
  2263. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  2264. INVALID_ENTRY) {
  2265. if (atomic_read(&ddb_entry->retry_relogin_timer) ==
  2266. 0) {
  2267. atomic_set(&ddb_entry->retry_relogin_timer,
  2268. INVALID_ENTRY);
  2269. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2270. set_bit(DF_RELOGIN, &ddb_entry->flags);
  2271. DEBUG2(ql4_printk(KERN_INFO, ha,
  2272. "%s: index [%d] login device\n",
  2273. __func__, ddb_entry->fw_ddb_index));
  2274. } else
  2275. atomic_dec(&ddb_entry->retry_relogin_timer);
  2276. }
  2277. }
  2278. /* Wait for relogin to timeout */
  2279. if (atomic_read(&ddb_entry->relogin_timer) &&
  2280. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  2281. /*
  2282. * If the relogin times out and the device is
  2283. * still NOT ONLINE then try and relogin again.
  2284. */
  2285. if (!iscsi_is_session_online(cls_sess)) {
  2286. /* Reset retry relogin timer */
  2287. atomic_inc(&ddb_entry->relogin_retry_count);
  2288. DEBUG2(ql4_printk(KERN_INFO, ha,
  2289. "%s: index[%d] relogin timed out-retrying"
  2290. " relogin (%d), retry (%d)\n", __func__,
  2291. ddb_entry->fw_ddb_index,
  2292. atomic_read(&ddb_entry->relogin_retry_count),
  2293. ddb_entry->default_time2wait + 4));
  2294. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2295. atomic_set(&ddb_entry->retry_relogin_timer,
  2296. ddb_entry->default_time2wait + 4);
  2297. }
  2298. }
  2299. }
  2300. /**
  2301. * qla4xxx_timer - checks every second for work to do.
  2302. * @ha: Pointer to host adapter structure.
  2303. **/
  2304. static void qla4xxx_timer(struct scsi_qla_host *ha)
  2305. {
  2306. int start_dpc = 0;
  2307. uint16_t w;
  2308. iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
  2309. /* If we are in the middle of AER/EEH processing
  2310. * skip any processing and reschedule the timer
  2311. */
  2312. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2313. mod_timer(&ha->timer, jiffies + HZ);
  2314. return;
  2315. }
  2316. /* Hardware read to trigger an EEH error during mailbox waits. */
  2317. if (!pci_channel_offline(ha->pdev))
  2318. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  2319. if (is_qla80XX(ha))
  2320. qla4_8xxx_watchdog(ha);
  2321. if (is_qla40XX(ha)) {
  2322. /* Check for heartbeat interval. */
  2323. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  2324. ha->heartbeat_interval != 0) {
  2325. ha->seconds_since_last_heartbeat++;
  2326. if (ha->seconds_since_last_heartbeat >
  2327. ha->heartbeat_interval + 2)
  2328. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2329. }
  2330. }
  2331. /* Process any deferred work. */
  2332. if (!list_empty(&ha->work_list))
  2333. start_dpc++;
  2334. /* Wakeup the dpc routine for this adapter, if needed. */
  2335. if (start_dpc ||
  2336. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2337. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  2338. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  2339. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2340. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2341. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  2342. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  2343. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  2344. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  2345. test_bit(DPC_AEN, &ha->dpc_flags)) {
  2346. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  2347. " - dpc flags = 0x%lx\n",
  2348. ha->host_no, __func__, ha->dpc_flags));
  2349. qla4xxx_wake_dpc(ha);
  2350. }
  2351. /* Reschedule timer thread to call us back in one second */
  2352. mod_timer(&ha->timer, jiffies + HZ);
  2353. DEBUG2(ha->seconds_since_last_intr++);
  2354. }
  2355. /**
  2356. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  2357. * @ha: Pointer to host adapter structure.
  2358. *
  2359. * This routine stalls the driver until all outstanding commands are returned.
  2360. * Caller must release the Hardware Lock prior to calling this routine.
  2361. **/
  2362. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  2363. {
  2364. uint32_t index = 0;
  2365. unsigned long flags;
  2366. struct scsi_cmnd *cmd;
  2367. unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
  2368. DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
  2369. "complete\n", WAIT_CMD_TOV));
  2370. while (!time_after_eq(jiffies, wtime)) {
  2371. spin_lock_irqsave(&ha->hardware_lock, flags);
  2372. /* Find a command that hasn't completed. */
  2373. for (index = 0; index < ha->host->can_queue; index++) {
  2374. cmd = scsi_host_find_tag(ha->host, index);
  2375. /*
  2376. * We cannot just check if the index is valid,
  2377. * becase if we are run from the scsi eh, then
  2378. * the scsi/block layer is going to prevent
  2379. * the tag from being released.
  2380. */
  2381. if (cmd != NULL && CMD_SP(cmd))
  2382. break;
  2383. }
  2384. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2385. /* If No Commands are pending, wait is complete */
  2386. if (index == ha->host->can_queue)
  2387. return QLA_SUCCESS;
  2388. msleep(1000);
  2389. }
  2390. /* If we timed out on waiting for commands to come back
  2391. * return ERROR. */
  2392. return QLA_ERROR;
  2393. }
  2394. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  2395. {
  2396. uint32_t ctrl_status;
  2397. unsigned long flags = 0;
  2398. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  2399. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  2400. return QLA_ERROR;
  2401. spin_lock_irqsave(&ha->hardware_lock, flags);
  2402. /*
  2403. * If the SCSI Reset Interrupt bit is set, clear it.
  2404. * Otherwise, the Soft Reset won't work.
  2405. */
  2406. ctrl_status = readw(&ha->reg->ctrl_status);
  2407. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  2408. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2409. /* Issue Soft Reset */
  2410. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  2411. readl(&ha->reg->ctrl_status);
  2412. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2413. return QLA_SUCCESS;
  2414. }
  2415. /**
  2416. * qla4xxx_soft_reset - performs soft reset.
  2417. * @ha: Pointer to host adapter structure.
  2418. **/
  2419. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  2420. {
  2421. uint32_t max_wait_time;
  2422. unsigned long flags = 0;
  2423. int status;
  2424. uint32_t ctrl_status;
  2425. status = qla4xxx_hw_reset(ha);
  2426. if (status != QLA_SUCCESS)
  2427. return status;
  2428. status = QLA_ERROR;
  2429. /* Wait until the Network Reset Intr bit is cleared */
  2430. max_wait_time = RESET_INTR_TOV;
  2431. do {
  2432. spin_lock_irqsave(&ha->hardware_lock, flags);
  2433. ctrl_status = readw(&ha->reg->ctrl_status);
  2434. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2435. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  2436. break;
  2437. msleep(1000);
  2438. } while ((--max_wait_time));
  2439. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  2440. DEBUG2(printk(KERN_WARNING
  2441. "scsi%ld: Network Reset Intr not cleared by "
  2442. "Network function, clearing it now!\n",
  2443. ha->host_no));
  2444. spin_lock_irqsave(&ha->hardware_lock, flags);
  2445. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  2446. readl(&ha->reg->ctrl_status);
  2447. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2448. }
  2449. /* Wait until the firmware tells us the Soft Reset is done */
  2450. max_wait_time = SOFT_RESET_TOV;
  2451. do {
  2452. spin_lock_irqsave(&ha->hardware_lock, flags);
  2453. ctrl_status = readw(&ha->reg->ctrl_status);
  2454. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2455. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  2456. status = QLA_SUCCESS;
  2457. break;
  2458. }
  2459. msleep(1000);
  2460. } while ((--max_wait_time));
  2461. /*
  2462. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  2463. * after the soft reset has taken place.
  2464. */
  2465. spin_lock_irqsave(&ha->hardware_lock, flags);
  2466. ctrl_status = readw(&ha->reg->ctrl_status);
  2467. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  2468. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2469. readl(&ha->reg->ctrl_status);
  2470. }
  2471. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2472. /* If soft reset fails then most probably the bios on other
  2473. * function is also enabled.
  2474. * Since the initialization is sequential the other fn
  2475. * wont be able to acknowledge the soft reset.
  2476. * Issue a force soft reset to workaround this scenario.
  2477. */
  2478. if (max_wait_time == 0) {
  2479. /* Issue Force Soft Reset */
  2480. spin_lock_irqsave(&ha->hardware_lock, flags);
  2481. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  2482. readl(&ha->reg->ctrl_status);
  2483. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2484. /* Wait until the firmware tells us the Soft Reset is done */
  2485. max_wait_time = SOFT_RESET_TOV;
  2486. do {
  2487. spin_lock_irqsave(&ha->hardware_lock, flags);
  2488. ctrl_status = readw(&ha->reg->ctrl_status);
  2489. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2490. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  2491. status = QLA_SUCCESS;
  2492. break;
  2493. }
  2494. msleep(1000);
  2495. } while ((--max_wait_time));
  2496. }
  2497. return status;
  2498. }
  2499. /**
  2500. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  2501. * @ha: Pointer to host adapter structure.
  2502. * @res: returned scsi status
  2503. *
  2504. * This routine is called just prior to a HARD RESET to return all
  2505. * outstanding commands back to the Operating System.
  2506. * Caller should make sure that the following locks are released
  2507. * before this calling routine: Hardware lock, and io_request_lock.
  2508. **/
  2509. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  2510. {
  2511. struct srb *srb;
  2512. int i;
  2513. unsigned long flags;
  2514. spin_lock_irqsave(&ha->hardware_lock, flags);
  2515. for (i = 0; i < ha->host->can_queue; i++) {
  2516. srb = qla4xxx_del_from_active_array(ha, i);
  2517. if (srb != NULL) {
  2518. srb->cmd->result = res;
  2519. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  2520. }
  2521. }
  2522. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2523. }
  2524. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  2525. {
  2526. clear_bit(AF_ONLINE, &ha->flags);
  2527. /* Disable the board */
  2528. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  2529. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  2530. qla4xxx_mark_all_devices_missing(ha);
  2531. clear_bit(AF_INIT_DONE, &ha->flags);
  2532. }
  2533. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
  2534. {
  2535. struct iscsi_session *sess;
  2536. struct ddb_entry *ddb_entry;
  2537. sess = cls_session->dd_data;
  2538. ddb_entry = sess->dd_data;
  2539. ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
  2540. if (ddb_entry->ddb_type == FLASH_DDB)
  2541. iscsi_block_session(ddb_entry->sess);
  2542. else
  2543. iscsi_session_failure(cls_session->dd_data,
  2544. ISCSI_ERR_CONN_FAILED);
  2545. }
  2546. /**
  2547. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  2548. * @ha: Pointer to host adapter structure.
  2549. **/
  2550. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  2551. {
  2552. int status = QLA_ERROR;
  2553. uint8_t reset_chip = 0;
  2554. uint32_t dev_state;
  2555. unsigned long wait;
  2556. /* Stall incoming I/O until we are done */
  2557. scsi_block_requests(ha->host);
  2558. clear_bit(AF_ONLINE, &ha->flags);
  2559. clear_bit(AF_LINK_UP, &ha->flags);
  2560. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  2561. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2562. if (is_qla8032(ha) &&
  2563. !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2564. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2565. __func__);
  2566. /* disable pause frame for ISP83xx */
  2567. qla4_83xx_disable_pause(ha);
  2568. }
  2569. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  2570. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2571. reset_chip = 1;
  2572. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  2573. * do not reset adapter, jump to initialize_adapter */
  2574. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2575. status = QLA_SUCCESS;
  2576. goto recover_ha_init_adapter;
  2577. }
  2578. /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
  2579. * from eh_host_reset or ioctl module */
  2580. if (is_qla80XX(ha) && !reset_chip &&
  2581. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2582. DEBUG2(ql4_printk(KERN_INFO, ha,
  2583. "scsi%ld: %s - Performing stop_firmware...\n",
  2584. ha->host_no, __func__));
  2585. status = ha->isp_ops->reset_firmware(ha);
  2586. if (status == QLA_SUCCESS) {
  2587. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  2588. qla4xxx_cmd_wait(ha);
  2589. ha->isp_ops->disable_intrs(ha);
  2590. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2591. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2592. } else {
  2593. /* If the stop_firmware fails then
  2594. * reset the entire chip */
  2595. reset_chip = 1;
  2596. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2597. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2598. }
  2599. }
  2600. /* Issue full chip reset if recovering from a catastrophic error,
  2601. * or if stop_firmware fails for ISP-8xxx.
  2602. * This is the default case for ISP-4xxx */
  2603. if (is_qla40XX(ha) || reset_chip) {
  2604. if (is_qla40XX(ha))
  2605. goto chip_reset;
  2606. /* Check if 8XXX firmware is alive or not
  2607. * We may have arrived here from NEED_RESET
  2608. * detection only */
  2609. if (test_bit(AF_FW_RECOVERY, &ha->flags))
  2610. goto chip_reset;
  2611. wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
  2612. while (time_before(jiffies, wait)) {
  2613. if (qla4_8xxx_check_fw_alive(ha)) {
  2614. qla4xxx_mailbox_premature_completion(ha);
  2615. break;
  2616. }
  2617. set_current_state(TASK_UNINTERRUPTIBLE);
  2618. schedule_timeout(HZ);
  2619. }
  2620. chip_reset:
  2621. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  2622. qla4xxx_cmd_wait(ha);
  2623. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2624. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2625. DEBUG2(ql4_printk(KERN_INFO, ha,
  2626. "scsi%ld: %s - Performing chip reset..\n",
  2627. ha->host_no, __func__));
  2628. status = ha->isp_ops->reset_chip(ha);
  2629. }
  2630. /* Flush any pending ddb changed AENs */
  2631. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2632. recover_ha_init_adapter:
  2633. /* Upon successful firmware/chip reset, re-initialize the adapter */
  2634. if (status == QLA_SUCCESS) {
  2635. /* For ISP-4xxx, force function 1 to always initialize
  2636. * before function 3 to prevent both funcions from
  2637. * stepping on top of the other */
  2638. if (is_qla40XX(ha) && (ha->mac_index == 3))
  2639. ssleep(6);
  2640. /* NOTE: AF_ONLINE flag set upon successful completion of
  2641. * qla4xxx_initialize_adapter */
  2642. status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  2643. }
  2644. /* Retry failed adapter initialization, if necessary
  2645. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  2646. * case to prevent ping-pong resets between functions */
  2647. if (!test_bit(AF_ONLINE, &ha->flags) &&
  2648. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2649. /* Adapter initialization failed, see if we can retry
  2650. * resetting the ha.
  2651. * Since we don't want to block the DPC for too long
  2652. * with multiple resets in the same thread,
  2653. * utilize DPC to retry */
  2654. if (is_qla80XX(ha)) {
  2655. ha->isp_ops->idc_lock(ha);
  2656. dev_state = qla4_8xxx_rd_direct(ha,
  2657. QLA8XXX_CRB_DEV_STATE);
  2658. ha->isp_ops->idc_unlock(ha);
  2659. if (dev_state == QLA8XXX_DEV_FAILED) {
  2660. ql4_printk(KERN_INFO, ha, "%s: don't retry "
  2661. "recover adapter. H/W is in Failed "
  2662. "state\n", __func__);
  2663. qla4xxx_dead_adapter_cleanup(ha);
  2664. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2665. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2666. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  2667. &ha->dpc_flags);
  2668. status = QLA_ERROR;
  2669. goto exit_recover;
  2670. }
  2671. }
  2672. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  2673. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  2674. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  2675. "(%d) more times\n", ha->host_no,
  2676. ha->retry_reset_ha_cnt));
  2677. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2678. status = QLA_ERROR;
  2679. } else {
  2680. if (ha->retry_reset_ha_cnt > 0) {
  2681. /* Schedule another Reset HA--DPC will retry */
  2682. ha->retry_reset_ha_cnt--;
  2683. DEBUG2(printk("scsi%ld: recover adapter - "
  2684. "retry remaining %d\n",
  2685. ha->host_no,
  2686. ha->retry_reset_ha_cnt));
  2687. status = QLA_ERROR;
  2688. }
  2689. if (ha->retry_reset_ha_cnt == 0) {
  2690. /* Recover adapter retries have been exhausted.
  2691. * Adapter DEAD */
  2692. DEBUG2(printk("scsi%ld: recover adapter "
  2693. "failed - board disabled\n",
  2694. ha->host_no));
  2695. qla4xxx_dead_adapter_cleanup(ha);
  2696. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2697. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2698. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  2699. &ha->dpc_flags);
  2700. status = QLA_ERROR;
  2701. }
  2702. }
  2703. } else {
  2704. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2705. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2706. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  2707. }
  2708. exit_recover:
  2709. ha->adapter_error_count++;
  2710. if (test_bit(AF_ONLINE, &ha->flags))
  2711. ha->isp_ops->enable_intrs(ha);
  2712. scsi_unblock_requests(ha->host);
  2713. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2714. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  2715. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  2716. return status;
  2717. }
  2718. static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
  2719. {
  2720. struct iscsi_session *sess;
  2721. struct ddb_entry *ddb_entry;
  2722. struct scsi_qla_host *ha;
  2723. sess = cls_session->dd_data;
  2724. ddb_entry = sess->dd_data;
  2725. ha = ddb_entry->ha;
  2726. if (!iscsi_is_session_online(cls_session)) {
  2727. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
  2728. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2729. " unblock session\n", ha->host_no, __func__,
  2730. ddb_entry->fw_ddb_index);
  2731. iscsi_unblock_session(ddb_entry->sess);
  2732. } else {
  2733. /* Trigger relogin */
  2734. if (ddb_entry->ddb_type == FLASH_DDB) {
  2735. if (!test_bit(DF_RELOGIN, &ddb_entry->flags))
  2736. qla4xxx_arm_relogin_timer(ddb_entry);
  2737. } else
  2738. iscsi_session_failure(cls_session->dd_data,
  2739. ISCSI_ERR_CONN_FAILED);
  2740. }
  2741. }
  2742. }
  2743. int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
  2744. {
  2745. struct iscsi_session *sess;
  2746. struct ddb_entry *ddb_entry;
  2747. struct scsi_qla_host *ha;
  2748. sess = cls_session->dd_data;
  2749. ddb_entry = sess->dd_data;
  2750. ha = ddb_entry->ha;
  2751. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2752. " unblock session\n", ha->host_no, __func__,
  2753. ddb_entry->fw_ddb_index);
  2754. iscsi_unblock_session(ddb_entry->sess);
  2755. /* Start scan target */
  2756. if (test_bit(AF_ONLINE, &ha->flags)) {
  2757. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2758. " start scan\n", ha->host_no, __func__,
  2759. ddb_entry->fw_ddb_index);
  2760. scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
  2761. }
  2762. return QLA_SUCCESS;
  2763. }
  2764. int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
  2765. {
  2766. struct iscsi_session *sess;
  2767. struct ddb_entry *ddb_entry;
  2768. struct scsi_qla_host *ha;
  2769. int status = QLA_SUCCESS;
  2770. sess = cls_session->dd_data;
  2771. ddb_entry = sess->dd_data;
  2772. ha = ddb_entry->ha;
  2773. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  2774. " unblock user space session\n", ha->host_no, __func__,
  2775. ddb_entry->fw_ddb_index);
  2776. if (!iscsi_is_session_online(cls_session)) {
  2777. iscsi_conn_start(ddb_entry->conn);
  2778. iscsi_conn_login_event(ddb_entry->conn,
  2779. ISCSI_CONN_STATE_LOGGED_IN);
  2780. } else {
  2781. ql4_printk(KERN_INFO, ha,
  2782. "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
  2783. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  2784. cls_session->sid);
  2785. status = QLA_ERROR;
  2786. }
  2787. return status;
  2788. }
  2789. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  2790. {
  2791. iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
  2792. }
  2793. static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  2794. {
  2795. uint16_t relogin_timer;
  2796. struct iscsi_session *sess;
  2797. struct ddb_entry *ddb_entry;
  2798. struct scsi_qla_host *ha;
  2799. sess = cls_sess->dd_data;
  2800. ddb_entry = sess->dd_data;
  2801. ha = ddb_entry->ha;
  2802. relogin_timer = max(ddb_entry->default_relogin_timeout,
  2803. (uint16_t)RELOGIN_TOV);
  2804. atomic_set(&ddb_entry->relogin_timer, relogin_timer);
  2805. DEBUG2(ql4_printk(KERN_INFO, ha,
  2806. "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
  2807. ddb_entry->fw_ddb_index, relogin_timer));
  2808. qla4xxx_login_flash_ddb(cls_sess);
  2809. }
  2810. static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
  2811. {
  2812. struct iscsi_session *sess;
  2813. struct ddb_entry *ddb_entry;
  2814. struct scsi_qla_host *ha;
  2815. sess = cls_sess->dd_data;
  2816. ddb_entry = sess->dd_data;
  2817. ha = ddb_entry->ha;
  2818. if (!(ddb_entry->ddb_type == FLASH_DDB))
  2819. return;
  2820. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  2821. !iscsi_is_session_online(cls_sess)) {
  2822. DEBUG2(ql4_printk(KERN_INFO, ha,
  2823. "relogin issued\n"));
  2824. qla4xxx_relogin_flash_ddb(cls_sess);
  2825. }
  2826. }
  2827. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  2828. {
  2829. if (ha->dpc_thread)
  2830. queue_work(ha->dpc_thread, &ha->dpc_work);
  2831. }
  2832. static struct qla4_work_evt *
  2833. qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
  2834. enum qla4_work_type type)
  2835. {
  2836. struct qla4_work_evt *e;
  2837. uint32_t size = sizeof(struct qla4_work_evt) + data_size;
  2838. e = kzalloc(size, GFP_ATOMIC);
  2839. if (!e)
  2840. return NULL;
  2841. INIT_LIST_HEAD(&e->list);
  2842. e->type = type;
  2843. return e;
  2844. }
  2845. static void qla4xxx_post_work(struct scsi_qla_host *ha,
  2846. struct qla4_work_evt *e)
  2847. {
  2848. unsigned long flags;
  2849. spin_lock_irqsave(&ha->work_lock, flags);
  2850. list_add_tail(&e->list, &ha->work_list);
  2851. spin_unlock_irqrestore(&ha->work_lock, flags);
  2852. qla4xxx_wake_dpc(ha);
  2853. }
  2854. int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
  2855. enum iscsi_host_event_code aen_code,
  2856. uint32_t data_size, uint8_t *data)
  2857. {
  2858. struct qla4_work_evt *e;
  2859. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
  2860. if (!e)
  2861. return QLA_ERROR;
  2862. e->u.aen.code = aen_code;
  2863. e->u.aen.data_size = data_size;
  2864. memcpy(e->u.aen.data, data, data_size);
  2865. qla4xxx_post_work(ha, e);
  2866. return QLA_SUCCESS;
  2867. }
  2868. int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
  2869. uint32_t status, uint32_t pid,
  2870. uint32_t data_size, uint8_t *data)
  2871. {
  2872. struct qla4_work_evt *e;
  2873. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
  2874. if (!e)
  2875. return QLA_ERROR;
  2876. e->u.ping.status = status;
  2877. e->u.ping.pid = pid;
  2878. e->u.ping.data_size = data_size;
  2879. memcpy(e->u.ping.data, data, data_size);
  2880. qla4xxx_post_work(ha, e);
  2881. return QLA_SUCCESS;
  2882. }
  2883. static void qla4xxx_do_work(struct scsi_qla_host *ha)
  2884. {
  2885. struct qla4_work_evt *e, *tmp;
  2886. unsigned long flags;
  2887. LIST_HEAD(work);
  2888. spin_lock_irqsave(&ha->work_lock, flags);
  2889. list_splice_init(&ha->work_list, &work);
  2890. spin_unlock_irqrestore(&ha->work_lock, flags);
  2891. list_for_each_entry_safe(e, tmp, &work, list) {
  2892. list_del_init(&e->list);
  2893. switch (e->type) {
  2894. case QLA4_EVENT_AEN:
  2895. iscsi_post_host_event(ha->host_no,
  2896. &qla4xxx_iscsi_transport,
  2897. e->u.aen.code,
  2898. e->u.aen.data_size,
  2899. e->u.aen.data);
  2900. break;
  2901. case QLA4_EVENT_PING_STATUS:
  2902. iscsi_ping_comp_event(ha->host_no,
  2903. &qla4xxx_iscsi_transport,
  2904. e->u.ping.status,
  2905. e->u.ping.pid,
  2906. e->u.ping.data_size,
  2907. e->u.ping.data);
  2908. break;
  2909. default:
  2910. ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
  2911. "supported", e->type);
  2912. }
  2913. kfree(e);
  2914. }
  2915. }
  2916. /**
  2917. * qla4xxx_do_dpc - dpc routine
  2918. * @data: in our case pointer to adapter structure
  2919. *
  2920. * This routine is a task that is schedule by the interrupt handler
  2921. * to perform the background processing for interrupts. We put it
  2922. * on a task queue that is consumed whenever the scheduler runs; that's
  2923. * so you can do anything (i.e. put the process to sleep etc). In fact,
  2924. * the mid-level tries to sleep when it reaches the driver threshold
  2925. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  2926. **/
  2927. static void qla4xxx_do_dpc(struct work_struct *work)
  2928. {
  2929. struct scsi_qla_host *ha =
  2930. container_of(work, struct scsi_qla_host, dpc_work);
  2931. int status = QLA_ERROR;
  2932. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  2933. "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  2934. ha->host_no, __func__, ha->flags, ha->dpc_flags))
  2935. /* Initialization not yet finished. Don't do anything yet. */
  2936. if (!test_bit(AF_INIT_DONE, &ha->flags))
  2937. return;
  2938. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2939. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  2940. ha->host_no, __func__, ha->flags));
  2941. return;
  2942. }
  2943. /* post events to application */
  2944. qla4xxx_do_work(ha);
  2945. if (is_qla80XX(ha)) {
  2946. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  2947. if (is_qla8032(ha)) {
  2948. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2949. __func__);
  2950. /* disable pause frame for ISP83xx */
  2951. qla4_83xx_disable_pause(ha);
  2952. }
  2953. ha->isp_ops->idc_lock(ha);
  2954. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  2955. QLA8XXX_DEV_FAILED);
  2956. ha->isp_ops->idc_unlock(ha);
  2957. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  2958. qla4_8xxx_device_state_handler(ha);
  2959. }
  2960. if (test_and_clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags))
  2961. qla4_83xx_post_idc_ack(ha);
  2962. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2963. qla4_8xxx_need_qsnt_handler(ha);
  2964. }
  2965. }
  2966. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  2967. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2968. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2969. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  2970. if ((is_qla8022(ha) && ql4xdontresethba) ||
  2971. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  2972. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  2973. ha->host_no, __func__));
  2974. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2975. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  2976. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2977. goto dpc_post_reset_ha;
  2978. }
  2979. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2980. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2981. qla4xxx_recover_adapter(ha);
  2982. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2983. uint8_t wait_time = RESET_INTR_TOV;
  2984. while ((readw(&ha->reg->ctrl_status) &
  2985. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  2986. if (--wait_time == 0)
  2987. break;
  2988. msleep(1000);
  2989. }
  2990. if (wait_time == 0)
  2991. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  2992. "bit not cleared-- resetting\n",
  2993. ha->host_no, __func__));
  2994. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2995. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  2996. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2997. status = qla4xxx_recover_adapter(ha);
  2998. }
  2999. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  3000. if (status == QLA_SUCCESS)
  3001. ha->isp_ops->enable_intrs(ha);
  3002. }
  3003. }
  3004. dpc_post_reset_ha:
  3005. /* ---- process AEN? --- */
  3006. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  3007. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  3008. /* ---- Get DHCP IP Address? --- */
  3009. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  3010. qla4xxx_get_dhcp_ip_address(ha);
  3011. /* ---- relogin device? --- */
  3012. if (adapter_up(ha) &&
  3013. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  3014. iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
  3015. }
  3016. /* ---- link change? --- */
  3017. if (!test_bit(AF_LOOPBACK, &ha->flags) &&
  3018. test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  3019. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  3020. /* ---- link down? --- */
  3021. qla4xxx_mark_all_devices_missing(ha);
  3022. } else {
  3023. /* ---- link up? --- *
  3024. * F/W will auto login to all devices ONLY ONCE after
  3025. * link up during driver initialization and runtime
  3026. * fatal error recovery. Therefore, the driver must
  3027. * manually relogin to devices when recovering from
  3028. * connection failures, logouts, expired KATO, etc. */
  3029. if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
  3030. qla4xxx_build_ddb_list(ha, ha->is_reset);
  3031. iscsi_host_for_each_session(ha->host,
  3032. qla4xxx_login_flash_ddb);
  3033. } else
  3034. qla4xxx_relogin_all_devices(ha);
  3035. }
  3036. }
  3037. }
  3038. /**
  3039. * qla4xxx_free_adapter - release the adapter
  3040. * @ha: pointer to adapter structure
  3041. **/
  3042. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  3043. {
  3044. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  3045. /* Turn-off interrupts on the card. */
  3046. ha->isp_ops->disable_intrs(ha);
  3047. if (is_qla40XX(ha)) {
  3048. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  3049. &ha->reg->ctrl_status);
  3050. readl(&ha->reg->ctrl_status);
  3051. } else if (is_qla8022(ha)) {
  3052. writel(0, &ha->qla4_82xx_reg->host_int);
  3053. readl(&ha->qla4_82xx_reg->host_int);
  3054. } else if (is_qla8032(ha)) {
  3055. writel(0, &ha->qla4_83xx_reg->risc_intr);
  3056. readl(&ha->qla4_83xx_reg->risc_intr);
  3057. }
  3058. /* Remove timer thread, if present */
  3059. if (ha->timer_active)
  3060. qla4xxx_stop_timer(ha);
  3061. /* Kill the kernel thread for this host */
  3062. if (ha->dpc_thread)
  3063. destroy_workqueue(ha->dpc_thread);
  3064. /* Kill the kernel thread for this host */
  3065. if (ha->task_wq)
  3066. destroy_workqueue(ha->task_wq);
  3067. /* Put firmware in known state */
  3068. ha->isp_ops->reset_firmware(ha);
  3069. if (is_qla80XX(ha)) {
  3070. ha->isp_ops->idc_lock(ha);
  3071. qla4_8xxx_clear_drv_active(ha);
  3072. ha->isp_ops->idc_unlock(ha);
  3073. }
  3074. /* Detach interrupts */
  3075. qla4xxx_free_irqs(ha);
  3076. /* free extra memory */
  3077. qla4xxx_mem_free(ha);
  3078. }
  3079. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  3080. {
  3081. int status = 0;
  3082. unsigned long mem_base, mem_len, db_base, db_len;
  3083. struct pci_dev *pdev = ha->pdev;
  3084. status = pci_request_regions(pdev, DRIVER_NAME);
  3085. if (status) {
  3086. printk(KERN_WARNING
  3087. "scsi(%ld) Failed to reserve PIO regions (%s) "
  3088. "status=%d\n", ha->host_no, pci_name(pdev), status);
  3089. goto iospace_error_exit;
  3090. }
  3091. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  3092. __func__, pdev->revision));
  3093. ha->revision_id = pdev->revision;
  3094. /* remap phys address */
  3095. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  3096. mem_len = pci_resource_len(pdev, 0);
  3097. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  3098. __func__, mem_base, mem_len));
  3099. /* mapping of pcibase pointer */
  3100. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  3101. if (!ha->nx_pcibase) {
  3102. printk(KERN_ERR
  3103. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  3104. pci_release_regions(ha->pdev);
  3105. goto iospace_error_exit;
  3106. }
  3107. /* Mapping of IO base pointer, door bell read and write pointer */
  3108. /* mapping of IO base pointer */
  3109. if (is_qla8022(ha)) {
  3110. ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
  3111. ((uint8_t *)ha->nx_pcibase + 0xbc000 +
  3112. (ha->pdev->devfn << 11));
  3113. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  3114. QLA82XX_CAM_RAM_DB2);
  3115. } else if (is_qla8032(ha)) {
  3116. ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
  3117. ((uint8_t *)ha->nx_pcibase);
  3118. }
  3119. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  3120. db_len = pci_resource_len(pdev, 4);
  3121. return 0;
  3122. iospace_error_exit:
  3123. return -ENOMEM;
  3124. }
  3125. /***
  3126. * qla4xxx_iospace_config - maps registers
  3127. * @ha: pointer to adapter structure
  3128. *
  3129. * This routines maps HBA's registers from the pci address space
  3130. * into the kernel virtual address space for memory mapped i/o.
  3131. **/
  3132. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  3133. {
  3134. unsigned long pio, pio_len, pio_flags;
  3135. unsigned long mmio, mmio_len, mmio_flags;
  3136. pio = pci_resource_start(ha->pdev, 0);
  3137. pio_len = pci_resource_len(ha->pdev, 0);
  3138. pio_flags = pci_resource_flags(ha->pdev, 0);
  3139. if (pio_flags & IORESOURCE_IO) {
  3140. if (pio_len < MIN_IOBASE_LEN) {
  3141. ql4_printk(KERN_WARNING, ha,
  3142. "Invalid PCI I/O region size\n");
  3143. pio = 0;
  3144. }
  3145. } else {
  3146. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  3147. pio = 0;
  3148. }
  3149. /* Use MMIO operations for all accesses. */
  3150. mmio = pci_resource_start(ha->pdev, 1);
  3151. mmio_len = pci_resource_len(ha->pdev, 1);
  3152. mmio_flags = pci_resource_flags(ha->pdev, 1);
  3153. if (!(mmio_flags & IORESOURCE_MEM)) {
  3154. ql4_printk(KERN_ERR, ha,
  3155. "region #0 not an MMIO resource, aborting\n");
  3156. goto iospace_error_exit;
  3157. }
  3158. if (mmio_len < MIN_IOBASE_LEN) {
  3159. ql4_printk(KERN_ERR, ha,
  3160. "Invalid PCI mem region size, aborting\n");
  3161. goto iospace_error_exit;
  3162. }
  3163. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  3164. ql4_printk(KERN_WARNING, ha,
  3165. "Failed to reserve PIO/MMIO regions\n");
  3166. goto iospace_error_exit;
  3167. }
  3168. ha->pio_address = pio;
  3169. ha->pio_length = pio_len;
  3170. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  3171. if (!ha->reg) {
  3172. ql4_printk(KERN_ERR, ha,
  3173. "cannot remap MMIO, aborting\n");
  3174. goto iospace_error_exit;
  3175. }
  3176. return 0;
  3177. iospace_error_exit:
  3178. return -ENOMEM;
  3179. }
  3180. static struct isp_operations qla4xxx_isp_ops = {
  3181. .iospace_config = qla4xxx_iospace_config,
  3182. .pci_config = qla4xxx_pci_config,
  3183. .disable_intrs = qla4xxx_disable_intrs,
  3184. .enable_intrs = qla4xxx_enable_intrs,
  3185. .start_firmware = qla4xxx_start_firmware,
  3186. .intr_handler = qla4xxx_intr_handler,
  3187. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  3188. .reset_chip = qla4xxx_soft_reset,
  3189. .reset_firmware = qla4xxx_hw_reset,
  3190. .queue_iocb = qla4xxx_queue_iocb,
  3191. .complete_iocb = qla4xxx_complete_iocb,
  3192. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3193. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3194. .get_sys_info = qla4xxx_get_sys_info,
  3195. .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
  3196. .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
  3197. };
  3198. static struct isp_operations qla4_82xx_isp_ops = {
  3199. .iospace_config = qla4_8xxx_iospace_config,
  3200. .pci_config = qla4_8xxx_pci_config,
  3201. .disable_intrs = qla4_82xx_disable_intrs,
  3202. .enable_intrs = qla4_82xx_enable_intrs,
  3203. .start_firmware = qla4_8xxx_load_risc,
  3204. .restart_firmware = qla4_82xx_try_start_fw,
  3205. .intr_handler = qla4_82xx_intr_handler,
  3206. .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
  3207. .need_reset = qla4_8xxx_need_reset,
  3208. .reset_chip = qla4_82xx_isp_reset,
  3209. .reset_firmware = qla4_8xxx_stop_firmware,
  3210. .queue_iocb = qla4_82xx_queue_iocb,
  3211. .complete_iocb = qla4_82xx_complete_iocb,
  3212. .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
  3213. .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
  3214. .get_sys_info = qla4_8xxx_get_sys_info,
  3215. .rd_reg_direct = qla4_82xx_rd_32,
  3216. .wr_reg_direct = qla4_82xx_wr_32,
  3217. .rd_reg_indirect = qla4_82xx_md_rd_32,
  3218. .wr_reg_indirect = qla4_82xx_md_wr_32,
  3219. .idc_lock = qla4_82xx_idc_lock,
  3220. .idc_unlock = qla4_82xx_idc_unlock,
  3221. .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
  3222. .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
  3223. .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
  3224. };
  3225. static struct isp_operations qla4_83xx_isp_ops = {
  3226. .iospace_config = qla4_8xxx_iospace_config,
  3227. .pci_config = qla4_8xxx_pci_config,
  3228. .disable_intrs = qla4_83xx_disable_intrs,
  3229. .enable_intrs = qla4_83xx_enable_intrs,
  3230. .start_firmware = qla4_8xxx_load_risc,
  3231. .restart_firmware = qla4_83xx_start_firmware,
  3232. .intr_handler = qla4_83xx_intr_handler,
  3233. .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
  3234. .need_reset = qla4_8xxx_need_reset,
  3235. .reset_chip = qla4_83xx_isp_reset,
  3236. .reset_firmware = qla4_8xxx_stop_firmware,
  3237. .queue_iocb = qla4_83xx_queue_iocb,
  3238. .complete_iocb = qla4_83xx_complete_iocb,
  3239. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3240. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3241. .get_sys_info = qla4_8xxx_get_sys_info,
  3242. .rd_reg_direct = qla4_83xx_rd_reg,
  3243. .wr_reg_direct = qla4_83xx_wr_reg,
  3244. .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
  3245. .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
  3246. .idc_lock = qla4_83xx_drv_lock,
  3247. .idc_unlock = qla4_83xx_drv_unlock,
  3248. .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
  3249. .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
  3250. .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
  3251. };
  3252. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3253. {
  3254. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  3255. }
  3256. uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3257. {
  3258. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
  3259. }
  3260. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3261. {
  3262. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  3263. }
  3264. uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3265. {
  3266. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
  3267. }
  3268. static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
  3269. {
  3270. struct scsi_qla_host *ha = data;
  3271. char *str = buf;
  3272. int rc;
  3273. switch (type) {
  3274. case ISCSI_BOOT_ETH_FLAGS:
  3275. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3276. break;
  3277. case ISCSI_BOOT_ETH_INDEX:
  3278. rc = sprintf(str, "0\n");
  3279. break;
  3280. case ISCSI_BOOT_ETH_MAC:
  3281. rc = sysfs_format_mac(str, ha->my_mac,
  3282. MAC_ADDR_LEN);
  3283. break;
  3284. default:
  3285. rc = -ENOSYS;
  3286. break;
  3287. }
  3288. return rc;
  3289. }
  3290. static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
  3291. {
  3292. int rc;
  3293. switch (type) {
  3294. case ISCSI_BOOT_ETH_FLAGS:
  3295. case ISCSI_BOOT_ETH_MAC:
  3296. case ISCSI_BOOT_ETH_INDEX:
  3297. rc = S_IRUGO;
  3298. break;
  3299. default:
  3300. rc = 0;
  3301. break;
  3302. }
  3303. return rc;
  3304. }
  3305. static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
  3306. {
  3307. struct scsi_qla_host *ha = data;
  3308. char *str = buf;
  3309. int rc;
  3310. switch (type) {
  3311. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3312. rc = sprintf(str, "%s\n", ha->name_string);
  3313. break;
  3314. default:
  3315. rc = -ENOSYS;
  3316. break;
  3317. }
  3318. return rc;
  3319. }
  3320. static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
  3321. {
  3322. int rc;
  3323. switch (type) {
  3324. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3325. rc = S_IRUGO;
  3326. break;
  3327. default:
  3328. rc = 0;
  3329. break;
  3330. }
  3331. return rc;
  3332. }
  3333. static ssize_t
  3334. qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
  3335. char *buf)
  3336. {
  3337. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3338. char *str = buf;
  3339. int rc;
  3340. switch (type) {
  3341. case ISCSI_BOOT_TGT_NAME:
  3342. rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
  3343. break;
  3344. case ISCSI_BOOT_TGT_IP_ADDR:
  3345. if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
  3346. rc = sprintf(buf, "%pI4\n",
  3347. &boot_conn->dest_ipaddr.ip_address);
  3348. else
  3349. rc = sprintf(str, "%pI6\n",
  3350. &boot_conn->dest_ipaddr.ip_address);
  3351. break;
  3352. case ISCSI_BOOT_TGT_PORT:
  3353. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  3354. break;
  3355. case ISCSI_BOOT_TGT_CHAP_NAME:
  3356. rc = sprintf(str, "%.*s\n",
  3357. boot_conn->chap.target_chap_name_length,
  3358. (char *)&boot_conn->chap.target_chap_name);
  3359. break;
  3360. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3361. rc = sprintf(str, "%.*s\n",
  3362. boot_conn->chap.target_secret_length,
  3363. (char *)&boot_conn->chap.target_secret);
  3364. break;
  3365. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3366. rc = sprintf(str, "%.*s\n",
  3367. boot_conn->chap.intr_chap_name_length,
  3368. (char *)&boot_conn->chap.intr_chap_name);
  3369. break;
  3370. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3371. rc = sprintf(str, "%.*s\n",
  3372. boot_conn->chap.intr_secret_length,
  3373. (char *)&boot_conn->chap.intr_secret);
  3374. break;
  3375. case ISCSI_BOOT_TGT_FLAGS:
  3376. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3377. break;
  3378. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3379. rc = sprintf(str, "0\n");
  3380. break;
  3381. default:
  3382. rc = -ENOSYS;
  3383. break;
  3384. }
  3385. return rc;
  3386. }
  3387. static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
  3388. {
  3389. struct scsi_qla_host *ha = data;
  3390. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
  3391. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3392. }
  3393. static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
  3394. {
  3395. struct scsi_qla_host *ha = data;
  3396. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
  3397. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3398. }
  3399. static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
  3400. {
  3401. int rc;
  3402. switch (type) {
  3403. case ISCSI_BOOT_TGT_NAME:
  3404. case ISCSI_BOOT_TGT_IP_ADDR:
  3405. case ISCSI_BOOT_TGT_PORT:
  3406. case ISCSI_BOOT_TGT_CHAP_NAME:
  3407. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3408. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3409. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3410. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3411. case ISCSI_BOOT_TGT_FLAGS:
  3412. rc = S_IRUGO;
  3413. break;
  3414. default:
  3415. rc = 0;
  3416. break;
  3417. }
  3418. return rc;
  3419. }
  3420. static void qla4xxx_boot_release(void *data)
  3421. {
  3422. struct scsi_qla_host *ha = data;
  3423. scsi_host_put(ha->host);
  3424. }
  3425. static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
  3426. {
  3427. dma_addr_t buf_dma;
  3428. uint32_t addr, pri_addr, sec_addr;
  3429. uint32_t offset;
  3430. uint16_t func_num;
  3431. uint8_t val;
  3432. uint8_t *buf = NULL;
  3433. size_t size = 13 * sizeof(uint8_t);
  3434. int ret = QLA_SUCCESS;
  3435. func_num = PCI_FUNC(ha->pdev->devfn);
  3436. ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
  3437. __func__, ha->pdev->device, func_num);
  3438. if (is_qla40XX(ha)) {
  3439. if (func_num == 1) {
  3440. addr = NVRAM_PORT0_BOOT_MODE;
  3441. pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
  3442. sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
  3443. } else if (func_num == 3) {
  3444. addr = NVRAM_PORT1_BOOT_MODE;
  3445. pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
  3446. sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
  3447. } else {
  3448. ret = QLA_ERROR;
  3449. goto exit_boot_info;
  3450. }
  3451. /* Check Boot Mode */
  3452. val = rd_nvram_byte(ha, addr);
  3453. if (!(val & 0x07)) {
  3454. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
  3455. "options : 0x%x\n", __func__, val));
  3456. ret = QLA_ERROR;
  3457. goto exit_boot_info;
  3458. }
  3459. /* get primary valid target index */
  3460. val = rd_nvram_byte(ha, pri_addr);
  3461. if (val & BIT_7)
  3462. ddb_index[0] = (val & 0x7f);
  3463. /* get secondary valid target index */
  3464. val = rd_nvram_byte(ha, sec_addr);
  3465. if (val & BIT_7)
  3466. ddb_index[1] = (val & 0x7f);
  3467. } else if (is_qla80XX(ha)) {
  3468. buf = dma_alloc_coherent(&ha->pdev->dev, size,
  3469. &buf_dma, GFP_KERNEL);
  3470. if (!buf) {
  3471. DEBUG2(ql4_printk(KERN_ERR, ha,
  3472. "%s: Unable to allocate dma buffer\n",
  3473. __func__));
  3474. ret = QLA_ERROR;
  3475. goto exit_boot_info;
  3476. }
  3477. if (ha->port_num == 0)
  3478. offset = BOOT_PARAM_OFFSET_PORT0;
  3479. else if (ha->port_num == 1)
  3480. offset = BOOT_PARAM_OFFSET_PORT1;
  3481. else {
  3482. ret = QLA_ERROR;
  3483. goto exit_boot_info_free;
  3484. }
  3485. addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
  3486. offset;
  3487. if (qla4xxx_get_flash(ha, buf_dma, addr,
  3488. 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
  3489. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  3490. " failed\n", ha->host_no, __func__));
  3491. ret = QLA_ERROR;
  3492. goto exit_boot_info_free;
  3493. }
  3494. /* Check Boot Mode */
  3495. if (!(buf[1] & 0x07)) {
  3496. DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
  3497. " : 0x%x\n", buf[1]));
  3498. ret = QLA_ERROR;
  3499. goto exit_boot_info_free;
  3500. }
  3501. /* get primary valid target index */
  3502. if (buf[2] & BIT_7)
  3503. ddb_index[0] = buf[2] & 0x7f;
  3504. /* get secondary valid target index */
  3505. if (buf[11] & BIT_7)
  3506. ddb_index[1] = buf[11] & 0x7f;
  3507. } else {
  3508. ret = QLA_ERROR;
  3509. goto exit_boot_info;
  3510. }
  3511. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
  3512. " target ID %d\n", __func__, ddb_index[0],
  3513. ddb_index[1]));
  3514. exit_boot_info_free:
  3515. dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
  3516. exit_boot_info:
  3517. ha->pri_ddb_idx = ddb_index[0];
  3518. ha->sec_ddb_idx = ddb_index[1];
  3519. return ret;
  3520. }
  3521. /**
  3522. * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  3523. * @ha: pointer to adapter structure
  3524. * @username: CHAP username to be returned
  3525. * @password: CHAP password to be returned
  3526. *
  3527. * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
  3528. * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
  3529. * So from the CHAP cache find the first BIDI CHAP entry and set it
  3530. * to the boot record in sysfs.
  3531. **/
  3532. static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
  3533. char *password)
  3534. {
  3535. int i, ret = -EINVAL;
  3536. int max_chap_entries = 0;
  3537. struct ql4_chap_table *chap_table;
  3538. if (is_qla80XX(ha))
  3539. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  3540. sizeof(struct ql4_chap_table);
  3541. else
  3542. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  3543. if (!ha->chap_list) {
  3544. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  3545. return ret;
  3546. }
  3547. mutex_lock(&ha->chap_sem);
  3548. for (i = 0; i < max_chap_entries; i++) {
  3549. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  3550. if (chap_table->cookie !=
  3551. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  3552. continue;
  3553. }
  3554. if (chap_table->flags & BIT_7) /* local */
  3555. continue;
  3556. if (!(chap_table->flags & BIT_6)) /* Not BIDI */
  3557. continue;
  3558. strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  3559. strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  3560. ret = 0;
  3561. break;
  3562. }
  3563. mutex_unlock(&ha->chap_sem);
  3564. return ret;
  3565. }
  3566. static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
  3567. struct ql4_boot_session_info *boot_sess,
  3568. uint16_t ddb_index)
  3569. {
  3570. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3571. struct dev_db_entry *fw_ddb_entry;
  3572. dma_addr_t fw_ddb_entry_dma;
  3573. uint16_t idx;
  3574. uint16_t options;
  3575. int ret = QLA_SUCCESS;
  3576. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3577. &fw_ddb_entry_dma, GFP_KERNEL);
  3578. if (!fw_ddb_entry) {
  3579. DEBUG2(ql4_printk(KERN_ERR, ha,
  3580. "%s: Unable to allocate dma buffer.\n",
  3581. __func__));
  3582. ret = QLA_ERROR;
  3583. return ret;
  3584. }
  3585. if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
  3586. fw_ddb_entry_dma, ddb_index)) {
  3587. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
  3588. "index [%d]\n", __func__, ddb_index));
  3589. ret = QLA_ERROR;
  3590. goto exit_boot_target;
  3591. }
  3592. /* Update target name and IP from DDB */
  3593. memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
  3594. min(sizeof(boot_sess->target_name),
  3595. sizeof(fw_ddb_entry->iscsi_name)));
  3596. options = le16_to_cpu(fw_ddb_entry->options);
  3597. if (options & DDB_OPT_IPV6_DEVICE) {
  3598. memcpy(&boot_conn->dest_ipaddr.ip_address,
  3599. &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
  3600. } else {
  3601. boot_conn->dest_ipaddr.ip_type = 0x1;
  3602. memcpy(&boot_conn->dest_ipaddr.ip_address,
  3603. &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
  3604. }
  3605. boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
  3606. /* update chap information */
  3607. idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  3608. if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  3609. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
  3610. ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
  3611. target_chap_name,
  3612. (char *)&boot_conn->chap.target_secret,
  3613. idx);
  3614. if (ret) {
  3615. ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
  3616. ret = QLA_ERROR;
  3617. goto exit_boot_target;
  3618. }
  3619. boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  3620. boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  3621. }
  3622. if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  3623. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
  3624. ret = qla4xxx_get_bidi_chap(ha,
  3625. (char *)&boot_conn->chap.intr_chap_name,
  3626. (char *)&boot_conn->chap.intr_secret);
  3627. if (ret) {
  3628. ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
  3629. ret = QLA_ERROR;
  3630. goto exit_boot_target;
  3631. }
  3632. boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  3633. boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  3634. }
  3635. exit_boot_target:
  3636. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3637. fw_ddb_entry, fw_ddb_entry_dma);
  3638. return ret;
  3639. }
  3640. static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
  3641. {
  3642. uint16_t ddb_index[2];
  3643. int ret = QLA_ERROR;
  3644. int rval;
  3645. memset(ddb_index, 0, sizeof(ddb_index));
  3646. ddb_index[0] = 0xffff;
  3647. ddb_index[1] = 0xffff;
  3648. ret = get_fw_boot_info(ha, ddb_index);
  3649. if (ret != QLA_SUCCESS) {
  3650. DEBUG2(ql4_printk(KERN_INFO, ha,
  3651. "%s: No boot target configured.\n", __func__));
  3652. return ret;
  3653. }
  3654. if (ql4xdisablesysfsboot)
  3655. return QLA_SUCCESS;
  3656. if (ddb_index[0] == 0xffff)
  3657. goto sec_target;
  3658. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
  3659. ddb_index[0]);
  3660. if (rval != QLA_SUCCESS) {
  3661. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
  3662. "configured\n", __func__));
  3663. } else
  3664. ret = QLA_SUCCESS;
  3665. sec_target:
  3666. if (ddb_index[1] == 0xffff)
  3667. goto exit_get_boot_info;
  3668. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
  3669. ddb_index[1]);
  3670. if (rval != QLA_SUCCESS) {
  3671. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
  3672. " configured\n", __func__));
  3673. } else
  3674. ret = QLA_SUCCESS;
  3675. exit_get_boot_info:
  3676. return ret;
  3677. }
  3678. static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
  3679. {
  3680. struct iscsi_boot_kobj *boot_kobj;
  3681. if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
  3682. return QLA_ERROR;
  3683. if (ql4xdisablesysfsboot) {
  3684. ql4_printk(KERN_INFO, ha,
  3685. "%s: syfsboot disabled - driver will trigger login "
  3686. "and publish session for discovery .\n", __func__);
  3687. return QLA_SUCCESS;
  3688. }
  3689. ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
  3690. if (!ha->boot_kset)
  3691. goto kset_free;
  3692. if (!scsi_host_get(ha->host))
  3693. goto kset_free;
  3694. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
  3695. qla4xxx_show_boot_tgt_pri_info,
  3696. qla4xxx_tgt_get_attr_visibility,
  3697. qla4xxx_boot_release);
  3698. if (!boot_kobj)
  3699. goto put_host;
  3700. if (!scsi_host_get(ha->host))
  3701. goto kset_free;
  3702. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
  3703. qla4xxx_show_boot_tgt_sec_info,
  3704. qla4xxx_tgt_get_attr_visibility,
  3705. qla4xxx_boot_release);
  3706. if (!boot_kobj)
  3707. goto put_host;
  3708. if (!scsi_host_get(ha->host))
  3709. goto kset_free;
  3710. boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
  3711. qla4xxx_show_boot_ini_info,
  3712. qla4xxx_ini_get_attr_visibility,
  3713. qla4xxx_boot_release);
  3714. if (!boot_kobj)
  3715. goto put_host;
  3716. if (!scsi_host_get(ha->host))
  3717. goto kset_free;
  3718. boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
  3719. qla4xxx_show_boot_eth_info,
  3720. qla4xxx_eth_get_attr_visibility,
  3721. qla4xxx_boot_release);
  3722. if (!boot_kobj)
  3723. goto put_host;
  3724. return QLA_SUCCESS;
  3725. put_host:
  3726. scsi_host_put(ha->host);
  3727. kset_free:
  3728. iscsi_boot_destroy_kset(ha->boot_kset);
  3729. return -ENOMEM;
  3730. }
  3731. /**
  3732. * qla4xxx_create chap_list - Create CHAP list from FLASH
  3733. * @ha: pointer to adapter structure
  3734. *
  3735. * Read flash and make a list of CHAP entries, during login when a CHAP entry
  3736. * is received, it will be checked in this list. If entry exist then the CHAP
  3737. * entry index is set in the DDB. If CHAP entry does not exist in this list
  3738. * then a new entry is added in FLASH in CHAP table and the index obtained is
  3739. * used in the DDB.
  3740. **/
  3741. static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
  3742. {
  3743. int rval = 0;
  3744. uint8_t *chap_flash_data = NULL;
  3745. uint32_t offset;
  3746. dma_addr_t chap_dma;
  3747. uint32_t chap_size = 0;
  3748. if (is_qla40XX(ha))
  3749. chap_size = MAX_CHAP_ENTRIES_40XX *
  3750. sizeof(struct ql4_chap_table);
  3751. else /* Single region contains CHAP info for both
  3752. * ports which is divided into half for each port.
  3753. */
  3754. chap_size = ha->hw.flt_chap_size / 2;
  3755. chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
  3756. &chap_dma, GFP_KERNEL);
  3757. if (!chap_flash_data) {
  3758. ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
  3759. return;
  3760. }
  3761. if (is_qla40XX(ha))
  3762. offset = FLASH_CHAP_OFFSET;
  3763. else {
  3764. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  3765. if (ha->port_num == 1)
  3766. offset += chap_size;
  3767. }
  3768. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  3769. if (rval != QLA_SUCCESS)
  3770. goto exit_chap_list;
  3771. if (ha->chap_list == NULL)
  3772. ha->chap_list = vmalloc(chap_size);
  3773. if (ha->chap_list == NULL) {
  3774. ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
  3775. goto exit_chap_list;
  3776. }
  3777. memcpy(ha->chap_list, chap_flash_data, chap_size);
  3778. exit_chap_list:
  3779. dma_free_coherent(&ha->pdev->dev, chap_size,
  3780. chap_flash_data, chap_dma);
  3781. }
  3782. static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
  3783. struct ql4_tuple_ddb *tddb)
  3784. {
  3785. struct scsi_qla_host *ha;
  3786. struct iscsi_cls_session *cls_sess;
  3787. struct iscsi_cls_conn *cls_conn;
  3788. struct iscsi_session *sess;
  3789. struct iscsi_conn *conn;
  3790. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  3791. ha = ddb_entry->ha;
  3792. cls_sess = ddb_entry->sess;
  3793. sess = cls_sess->dd_data;
  3794. cls_conn = ddb_entry->conn;
  3795. conn = cls_conn->dd_data;
  3796. tddb->tpgt = sess->tpgt;
  3797. tddb->port = conn->persistent_port;
  3798. strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
  3799. strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
  3800. }
  3801. static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
  3802. struct ql4_tuple_ddb *tddb,
  3803. uint8_t *flash_isid)
  3804. {
  3805. uint16_t options = 0;
  3806. tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  3807. memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
  3808. min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
  3809. options = le16_to_cpu(fw_ddb_entry->options);
  3810. if (options & DDB_OPT_IPV6_DEVICE)
  3811. sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  3812. else
  3813. sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  3814. tddb->port = le16_to_cpu(fw_ddb_entry->port);
  3815. if (flash_isid == NULL)
  3816. memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
  3817. sizeof(tddb->isid));
  3818. else
  3819. memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
  3820. }
  3821. static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
  3822. struct ql4_tuple_ddb *old_tddb,
  3823. struct ql4_tuple_ddb *new_tddb,
  3824. uint8_t is_isid_compare)
  3825. {
  3826. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  3827. return QLA_ERROR;
  3828. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
  3829. return QLA_ERROR;
  3830. if (old_tddb->port != new_tddb->port)
  3831. return QLA_ERROR;
  3832. /* For multi sessions, driver generates the ISID, so do not compare
  3833. * ISID in reset path since it would be a comparison between the
  3834. * driver generated ISID and firmware generated ISID. This could
  3835. * lead to adding duplicated DDBs in the list as driver generated
  3836. * ISID would not match firmware generated ISID.
  3837. */
  3838. if (is_isid_compare) {
  3839. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
  3840. "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
  3841. __func__, old_tddb->isid[5], old_tddb->isid[4],
  3842. old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
  3843. old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
  3844. new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
  3845. new_tddb->isid[0]));
  3846. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  3847. sizeof(old_tddb->isid)))
  3848. return QLA_ERROR;
  3849. }
  3850. DEBUG2(ql4_printk(KERN_INFO, ha,
  3851. "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
  3852. old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
  3853. old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
  3854. new_tddb->ip_addr, new_tddb->iscsi_name));
  3855. return QLA_SUCCESS;
  3856. }
  3857. static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
  3858. struct dev_db_entry *fw_ddb_entry)
  3859. {
  3860. struct ddb_entry *ddb_entry;
  3861. struct ql4_tuple_ddb *fw_tddb = NULL;
  3862. struct ql4_tuple_ddb *tmp_tddb = NULL;
  3863. int idx;
  3864. int ret = QLA_ERROR;
  3865. fw_tddb = vzalloc(sizeof(*fw_tddb));
  3866. if (!fw_tddb) {
  3867. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3868. "Memory Allocation failed.\n"));
  3869. ret = QLA_SUCCESS;
  3870. goto exit_check;
  3871. }
  3872. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  3873. if (!tmp_tddb) {
  3874. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3875. "Memory Allocation failed.\n"));
  3876. ret = QLA_SUCCESS;
  3877. goto exit_check;
  3878. }
  3879. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  3880. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  3881. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  3882. if (ddb_entry == NULL)
  3883. continue;
  3884. qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
  3885. if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
  3886. ret = QLA_SUCCESS; /* found */
  3887. goto exit_check;
  3888. }
  3889. }
  3890. exit_check:
  3891. if (fw_tddb)
  3892. vfree(fw_tddb);
  3893. if (tmp_tddb)
  3894. vfree(tmp_tddb);
  3895. return ret;
  3896. }
  3897. /**
  3898. * qla4xxx_check_existing_isid - check if target with same isid exist
  3899. * in target list
  3900. * @list_nt: list of target
  3901. * @isid: isid to check
  3902. *
  3903. * This routine return QLA_SUCCESS if target with same isid exist
  3904. **/
  3905. static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
  3906. {
  3907. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  3908. struct dev_db_entry *fw_ddb_entry;
  3909. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  3910. fw_ddb_entry = &nt_ddb_idx->fw_ddb;
  3911. if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
  3912. sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
  3913. return QLA_SUCCESS;
  3914. }
  3915. }
  3916. return QLA_ERROR;
  3917. }
  3918. /**
  3919. * qla4xxx_update_isid - compare ddbs and updated isid
  3920. * @ha: Pointer to host adapter structure.
  3921. * @list_nt: list of nt target
  3922. * @fw_ddb_entry: firmware ddb entry
  3923. *
  3924. * This routine update isid if ddbs have same iqn, same isid and
  3925. * different IP addr.
  3926. * Return QLA_SUCCESS if isid is updated.
  3927. **/
  3928. static int qla4xxx_update_isid(struct scsi_qla_host *ha,
  3929. struct list_head *list_nt,
  3930. struct dev_db_entry *fw_ddb_entry)
  3931. {
  3932. uint8_t base_value, i;
  3933. base_value = fw_ddb_entry->isid[1] & 0x1f;
  3934. for (i = 0; i < 8; i++) {
  3935. fw_ddb_entry->isid[1] = (base_value | (i << 5));
  3936. if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  3937. break;
  3938. }
  3939. if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  3940. return QLA_ERROR;
  3941. return QLA_SUCCESS;
  3942. }
  3943. /**
  3944. * qla4xxx_should_update_isid - check if isid need to update
  3945. * @ha: Pointer to host adapter structure.
  3946. * @old_tddb: ddb tuple
  3947. * @new_tddb: ddb tuple
  3948. *
  3949. * Return QLA_SUCCESS if different IP, different PORT, same iqn,
  3950. * same isid
  3951. **/
  3952. static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
  3953. struct ql4_tuple_ddb *old_tddb,
  3954. struct ql4_tuple_ddb *new_tddb)
  3955. {
  3956. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
  3957. /* Same ip */
  3958. if (old_tddb->port == new_tddb->port)
  3959. return QLA_ERROR;
  3960. }
  3961. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  3962. /* different iqn */
  3963. return QLA_ERROR;
  3964. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  3965. sizeof(old_tddb->isid)))
  3966. /* different isid */
  3967. return QLA_ERROR;
  3968. return QLA_SUCCESS;
  3969. }
  3970. /**
  3971. * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
  3972. * @ha: Pointer to host adapter structure.
  3973. * @list_nt: list of nt target.
  3974. * @fw_ddb_entry: firmware ddb entry.
  3975. *
  3976. * This routine check if fw_ddb_entry already exists in list_nt to avoid
  3977. * duplicate ddb in list_nt.
  3978. * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
  3979. * Note: This function also update isid of DDB if required.
  3980. **/
  3981. static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
  3982. struct list_head *list_nt,
  3983. struct dev_db_entry *fw_ddb_entry)
  3984. {
  3985. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  3986. struct ql4_tuple_ddb *fw_tddb = NULL;
  3987. struct ql4_tuple_ddb *tmp_tddb = NULL;
  3988. int rval, ret = QLA_ERROR;
  3989. fw_tddb = vzalloc(sizeof(*fw_tddb));
  3990. if (!fw_tddb) {
  3991. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3992. "Memory Allocation failed.\n"));
  3993. ret = QLA_SUCCESS;
  3994. goto exit_check;
  3995. }
  3996. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  3997. if (!tmp_tddb) {
  3998. DEBUG2(ql4_printk(KERN_WARNING, ha,
  3999. "Memory Allocation failed.\n"));
  4000. ret = QLA_SUCCESS;
  4001. goto exit_check;
  4002. }
  4003. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  4004. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4005. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
  4006. nt_ddb_idx->flash_isid);
  4007. ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
  4008. /* found duplicate ddb */
  4009. if (ret == QLA_SUCCESS)
  4010. goto exit_check;
  4011. }
  4012. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4013. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
  4014. ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
  4015. if (ret == QLA_SUCCESS) {
  4016. rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
  4017. if (rval == QLA_SUCCESS)
  4018. ret = QLA_ERROR;
  4019. else
  4020. ret = QLA_SUCCESS;
  4021. goto exit_check;
  4022. }
  4023. }
  4024. exit_check:
  4025. if (fw_tddb)
  4026. vfree(fw_tddb);
  4027. if (tmp_tddb)
  4028. vfree(tmp_tddb);
  4029. return ret;
  4030. }
  4031. static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
  4032. {
  4033. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4034. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4035. list_del_init(&ddb_idx->list);
  4036. vfree(ddb_idx);
  4037. }
  4038. }
  4039. static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
  4040. struct dev_db_entry *fw_ddb_entry)
  4041. {
  4042. struct iscsi_endpoint *ep;
  4043. struct sockaddr_in *addr;
  4044. struct sockaddr_in6 *addr6;
  4045. struct sockaddr *t_addr;
  4046. struct sockaddr_storage *dst_addr;
  4047. char *ip;
  4048. /* TODO: need to destroy on unload iscsi_endpoint*/
  4049. dst_addr = vmalloc(sizeof(*dst_addr));
  4050. if (!dst_addr)
  4051. return NULL;
  4052. if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
  4053. t_addr = (struct sockaddr *)dst_addr;
  4054. t_addr->sa_family = AF_INET6;
  4055. addr6 = (struct sockaddr_in6 *)dst_addr;
  4056. ip = (char *)&addr6->sin6_addr;
  4057. memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  4058. addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4059. } else {
  4060. t_addr = (struct sockaddr *)dst_addr;
  4061. t_addr->sa_family = AF_INET;
  4062. addr = (struct sockaddr_in *)dst_addr;
  4063. ip = (char *)&addr->sin_addr;
  4064. memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
  4065. addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4066. }
  4067. ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
  4068. vfree(dst_addr);
  4069. return ep;
  4070. }
  4071. static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
  4072. {
  4073. if (ql4xdisablesysfsboot)
  4074. return QLA_SUCCESS;
  4075. if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
  4076. return QLA_ERROR;
  4077. return QLA_SUCCESS;
  4078. }
  4079. static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
  4080. struct ddb_entry *ddb_entry,
  4081. uint16_t idx)
  4082. {
  4083. uint16_t def_timeout;
  4084. ddb_entry->ddb_type = FLASH_DDB;
  4085. ddb_entry->fw_ddb_index = INVALID_ENTRY;
  4086. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  4087. ddb_entry->ha = ha;
  4088. ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
  4089. ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
  4090. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  4091. atomic_set(&ddb_entry->relogin_timer, 0);
  4092. atomic_set(&ddb_entry->relogin_retry_count, 0);
  4093. def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
  4094. ddb_entry->default_relogin_timeout =
  4095. (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
  4096. def_timeout : LOGIN_TOV;
  4097. ddb_entry->default_time2wait =
  4098. le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
  4099. if (ql4xdisablesysfsboot &&
  4100. (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
  4101. set_bit(DF_BOOT_TGT, &ddb_entry->flags);
  4102. }
  4103. static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
  4104. {
  4105. uint32_t idx = 0;
  4106. uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
  4107. uint32_t sts[MBOX_REG_COUNT];
  4108. uint32_t ip_state;
  4109. unsigned long wtime;
  4110. int ret;
  4111. wtime = jiffies + (HZ * IP_CONFIG_TOV);
  4112. do {
  4113. for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
  4114. if (ip_idx[idx] == -1)
  4115. continue;
  4116. ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
  4117. if (ret == QLA_ERROR) {
  4118. ip_idx[idx] = -1;
  4119. continue;
  4120. }
  4121. ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
  4122. DEBUG2(ql4_printk(KERN_INFO, ha,
  4123. "Waiting for IP state for idx = %d, state = 0x%x\n",
  4124. ip_idx[idx], ip_state));
  4125. if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
  4126. ip_state == IP_ADDRSTATE_INVALID ||
  4127. ip_state == IP_ADDRSTATE_PREFERRED ||
  4128. ip_state == IP_ADDRSTATE_DEPRICATED ||
  4129. ip_state == IP_ADDRSTATE_DISABLING)
  4130. ip_idx[idx] = -1;
  4131. }
  4132. /* Break if all IP states checked */
  4133. if ((ip_idx[0] == -1) &&
  4134. (ip_idx[1] == -1) &&
  4135. (ip_idx[2] == -1) &&
  4136. (ip_idx[3] == -1))
  4137. break;
  4138. schedule_timeout_uninterruptible(HZ);
  4139. } while (time_after(wtime, jiffies));
  4140. }
  4141. static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
  4142. struct list_head *list_st)
  4143. {
  4144. struct qla_ddb_index *st_ddb_idx;
  4145. int max_ddbs;
  4146. int fw_idx_size;
  4147. struct dev_db_entry *fw_ddb_entry;
  4148. dma_addr_t fw_ddb_dma;
  4149. int ret;
  4150. uint32_t idx = 0, next_idx = 0;
  4151. uint32_t state = 0, conn_err = 0;
  4152. uint16_t conn_id = 0;
  4153. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4154. &fw_ddb_dma);
  4155. if (fw_ddb_entry == NULL) {
  4156. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4157. goto exit_st_list;
  4158. }
  4159. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4160. MAX_DEV_DB_ENTRIES;
  4161. fw_idx_size = sizeof(struct qla_ddb_index);
  4162. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4163. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4164. NULL, &next_idx, &state,
  4165. &conn_err, NULL, &conn_id);
  4166. if (ret == QLA_ERROR)
  4167. break;
  4168. /* Ignore DDB if invalid state (unassigned) */
  4169. if (state == DDB_DS_UNASSIGNED)
  4170. goto continue_next_st;
  4171. /* Check if ST, add to the list_st */
  4172. if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
  4173. goto continue_next_st;
  4174. st_ddb_idx = vzalloc(fw_idx_size);
  4175. if (!st_ddb_idx)
  4176. break;
  4177. st_ddb_idx->fw_ddb_idx = idx;
  4178. list_add_tail(&st_ddb_idx->list, list_st);
  4179. continue_next_st:
  4180. if (next_idx == 0)
  4181. break;
  4182. }
  4183. exit_st_list:
  4184. if (fw_ddb_entry)
  4185. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4186. }
  4187. /**
  4188. * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
  4189. * @ha: pointer to adapter structure
  4190. * @list_ddb: List from which failed ddb to be removed
  4191. *
  4192. * Iterate over the list of DDBs and find and remove DDBs that are either in
  4193. * no connection active state or failed state
  4194. **/
  4195. static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
  4196. struct list_head *list_ddb)
  4197. {
  4198. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4199. uint32_t next_idx = 0;
  4200. uint32_t state = 0, conn_err = 0;
  4201. int ret;
  4202. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4203. ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
  4204. NULL, 0, NULL, &next_idx, &state,
  4205. &conn_err, NULL, NULL);
  4206. if (ret == QLA_ERROR)
  4207. continue;
  4208. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4209. state == DDB_DS_SESSION_FAILED) {
  4210. list_del_init(&ddb_idx->list);
  4211. vfree(ddb_idx);
  4212. }
  4213. }
  4214. }
  4215. static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
  4216. struct dev_db_entry *fw_ddb_entry,
  4217. int is_reset, uint16_t idx)
  4218. {
  4219. struct iscsi_cls_session *cls_sess;
  4220. struct iscsi_session *sess;
  4221. struct iscsi_cls_conn *cls_conn;
  4222. struct iscsi_endpoint *ep;
  4223. uint16_t cmds_max = 32;
  4224. uint16_t conn_id = 0;
  4225. uint32_t initial_cmdsn = 0;
  4226. int ret = QLA_SUCCESS;
  4227. struct ddb_entry *ddb_entry = NULL;
  4228. /* Create session object, with INVALID_ENTRY,
  4229. * the targer_id would get set when we issue the login
  4230. */
  4231. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
  4232. cmds_max, sizeof(struct ddb_entry),
  4233. sizeof(struct ql4_task_data),
  4234. initial_cmdsn, INVALID_ENTRY);
  4235. if (!cls_sess) {
  4236. ret = QLA_ERROR;
  4237. goto exit_setup;
  4238. }
  4239. /*
  4240. * so calling module_put function to decrement the
  4241. * reference count.
  4242. **/
  4243. module_put(qla4xxx_iscsi_transport.owner);
  4244. sess = cls_sess->dd_data;
  4245. ddb_entry = sess->dd_data;
  4246. ddb_entry->sess = cls_sess;
  4247. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  4248. memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
  4249. sizeof(struct dev_db_entry));
  4250. qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
  4251. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
  4252. if (!cls_conn) {
  4253. ret = QLA_ERROR;
  4254. goto exit_setup;
  4255. }
  4256. ddb_entry->conn = cls_conn;
  4257. /* Setup ep, for displaying attributes in sysfs */
  4258. ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
  4259. if (ep) {
  4260. ep->conn = cls_conn;
  4261. cls_conn->ep = ep;
  4262. } else {
  4263. DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
  4264. ret = QLA_ERROR;
  4265. goto exit_setup;
  4266. }
  4267. /* Update sess/conn params */
  4268. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  4269. if (is_reset == RESET_ADAPTER) {
  4270. iscsi_block_session(cls_sess);
  4271. /* Use the relogin path to discover new devices
  4272. * by short-circuting the logic of setting
  4273. * timer to relogin - instead set the flags
  4274. * to initiate login right away.
  4275. */
  4276. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  4277. set_bit(DF_RELOGIN, &ddb_entry->flags);
  4278. }
  4279. exit_setup:
  4280. return ret;
  4281. }
  4282. static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
  4283. struct list_head *list_nt, int is_reset)
  4284. {
  4285. struct dev_db_entry *fw_ddb_entry;
  4286. dma_addr_t fw_ddb_dma;
  4287. int max_ddbs;
  4288. int fw_idx_size;
  4289. int ret;
  4290. uint32_t idx = 0, next_idx = 0;
  4291. uint32_t state = 0, conn_err = 0;
  4292. uint16_t conn_id = 0;
  4293. struct qla_ddb_index *nt_ddb_idx;
  4294. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4295. &fw_ddb_dma);
  4296. if (fw_ddb_entry == NULL) {
  4297. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4298. goto exit_nt_list;
  4299. }
  4300. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4301. MAX_DEV_DB_ENTRIES;
  4302. fw_idx_size = sizeof(struct qla_ddb_index);
  4303. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4304. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4305. NULL, &next_idx, &state,
  4306. &conn_err, NULL, &conn_id);
  4307. if (ret == QLA_ERROR)
  4308. break;
  4309. if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
  4310. goto continue_next_nt;
  4311. /* Check if NT, then add to list it */
  4312. if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
  4313. goto continue_next_nt;
  4314. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4315. state == DDB_DS_SESSION_FAILED))
  4316. goto continue_next_nt;
  4317. DEBUG2(ql4_printk(KERN_INFO, ha,
  4318. "Adding DDB to session = 0x%x\n", idx));
  4319. if (is_reset == INIT_ADAPTER) {
  4320. nt_ddb_idx = vmalloc(fw_idx_size);
  4321. if (!nt_ddb_idx)
  4322. break;
  4323. nt_ddb_idx->fw_ddb_idx = idx;
  4324. /* Copy original isid as it may get updated in function
  4325. * qla4xxx_update_isid(). We need original isid in
  4326. * function qla4xxx_compare_tuple_ddb to find duplicate
  4327. * target */
  4328. memcpy(&nt_ddb_idx->flash_isid[0],
  4329. &fw_ddb_entry->isid[0],
  4330. sizeof(nt_ddb_idx->flash_isid));
  4331. ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
  4332. fw_ddb_entry);
  4333. if (ret == QLA_SUCCESS) {
  4334. /* free nt_ddb_idx and do not add to list_nt */
  4335. vfree(nt_ddb_idx);
  4336. goto continue_next_nt;
  4337. }
  4338. /* Copy updated isid */
  4339. memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
  4340. sizeof(struct dev_db_entry));
  4341. list_add_tail(&nt_ddb_idx->list, list_nt);
  4342. } else if (is_reset == RESET_ADAPTER) {
  4343. if (qla4xxx_is_session_exists(ha, fw_ddb_entry) ==
  4344. QLA_SUCCESS)
  4345. goto continue_next_nt;
  4346. }
  4347. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
  4348. if (ret == QLA_ERROR)
  4349. goto exit_nt_list;
  4350. continue_next_nt:
  4351. if (next_idx == 0)
  4352. break;
  4353. }
  4354. exit_nt_list:
  4355. if (fw_ddb_entry)
  4356. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4357. }
  4358. /**
  4359. * qla4xxx_build_ddb_list - Build ddb list and setup sessions
  4360. * @ha: pointer to adapter structure
  4361. * @is_reset: Is this init path or reset path
  4362. *
  4363. * Create a list of sendtargets (st) from firmware DDBs, issue send targets
  4364. * using connection open, then create the list of normal targets (nt)
  4365. * from firmware DDBs. Based on the list of nt setup session and connection
  4366. * objects.
  4367. **/
  4368. void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
  4369. {
  4370. uint16_t tmo = 0;
  4371. struct list_head list_st, list_nt;
  4372. struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
  4373. unsigned long wtime;
  4374. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  4375. set_bit(AF_BUILD_DDB_LIST, &ha->flags);
  4376. ha->is_reset = is_reset;
  4377. return;
  4378. }
  4379. INIT_LIST_HEAD(&list_st);
  4380. INIT_LIST_HEAD(&list_nt);
  4381. qla4xxx_build_st_list(ha, &list_st);
  4382. /* Before issuing conn open mbox, ensure all IPs states are configured
  4383. * Note, conn open fails if IPs are not configured
  4384. */
  4385. qla4xxx_wait_for_ip_configuration(ha);
  4386. /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
  4387. list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
  4388. qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
  4389. }
  4390. /* Wait to ensure all sendtargets are done for min 12 sec wait */
  4391. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  4392. (ha->def_timeout < LOGIN_TOV * 10) ?
  4393. ha->def_timeout : LOGIN_TOV);
  4394. DEBUG2(ql4_printk(KERN_INFO, ha,
  4395. "Default time to wait for build ddb %d\n", tmo));
  4396. wtime = jiffies + (HZ * tmo);
  4397. do {
  4398. if (list_empty(&list_st))
  4399. break;
  4400. qla4xxx_remove_failed_ddb(ha, &list_st);
  4401. schedule_timeout_uninterruptible(HZ / 10);
  4402. } while (time_after(wtime, jiffies));
  4403. /* Free up the sendtargets list */
  4404. qla4xxx_free_ddb_list(&list_st);
  4405. qla4xxx_build_nt_list(ha, &list_nt, is_reset);
  4406. qla4xxx_free_ddb_list(&list_nt);
  4407. qla4xxx_free_ddb_index(ha);
  4408. }
  4409. /**
  4410. * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
  4411. * response.
  4412. * @ha: pointer to adapter structure
  4413. *
  4414. * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
  4415. * set in DDB and we will wait for login response of boot targets during
  4416. * probe.
  4417. **/
  4418. static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
  4419. {
  4420. struct ddb_entry *ddb_entry;
  4421. struct dev_db_entry *fw_ddb_entry = NULL;
  4422. dma_addr_t fw_ddb_entry_dma;
  4423. unsigned long wtime;
  4424. uint32_t ddb_state;
  4425. int max_ddbs, idx, ret;
  4426. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4427. MAX_DEV_DB_ENTRIES;
  4428. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4429. &fw_ddb_entry_dma, GFP_KERNEL);
  4430. if (!fw_ddb_entry) {
  4431. ql4_printk(KERN_ERR, ha,
  4432. "%s: Unable to allocate dma buffer\n", __func__);
  4433. goto exit_login_resp;
  4434. }
  4435. wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
  4436. for (idx = 0; idx < max_ddbs; idx++) {
  4437. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  4438. if (ddb_entry == NULL)
  4439. continue;
  4440. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  4441. DEBUG2(ql4_printk(KERN_INFO, ha,
  4442. "%s: DDB index [%d]\n", __func__,
  4443. ddb_entry->fw_ddb_index));
  4444. do {
  4445. ret = qla4xxx_get_fwddb_entry(ha,
  4446. ddb_entry->fw_ddb_index,
  4447. fw_ddb_entry, fw_ddb_entry_dma,
  4448. NULL, NULL, &ddb_state, NULL,
  4449. NULL, NULL);
  4450. if (ret == QLA_ERROR)
  4451. goto exit_login_resp;
  4452. if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
  4453. (ddb_state == DDB_DS_SESSION_FAILED))
  4454. break;
  4455. schedule_timeout_uninterruptible(HZ);
  4456. } while ((time_after(wtime, jiffies)));
  4457. if (!time_after(wtime, jiffies)) {
  4458. DEBUG2(ql4_printk(KERN_INFO, ha,
  4459. "%s: Login response wait timer expired\n",
  4460. __func__));
  4461. goto exit_login_resp;
  4462. }
  4463. }
  4464. }
  4465. exit_login_resp:
  4466. if (fw_ddb_entry)
  4467. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4468. fw_ddb_entry, fw_ddb_entry_dma);
  4469. }
  4470. /**
  4471. * qla4xxx_probe_adapter - callback function to probe HBA
  4472. * @pdev: pointer to pci_dev structure
  4473. * @pci_device_id: pointer to pci_device entry
  4474. *
  4475. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  4476. * It returns zero if successful. It also initializes all data necessary for
  4477. * the driver.
  4478. **/
  4479. static int qla4xxx_probe_adapter(struct pci_dev *pdev,
  4480. const struct pci_device_id *ent)
  4481. {
  4482. int ret = -ENODEV, status;
  4483. struct Scsi_Host *host;
  4484. struct scsi_qla_host *ha;
  4485. uint8_t init_retry_count = 0;
  4486. char buf[34];
  4487. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  4488. uint32_t dev_state;
  4489. if (pci_enable_device(pdev))
  4490. return -1;
  4491. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  4492. if (host == NULL) {
  4493. printk(KERN_WARNING
  4494. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  4495. goto probe_disable_device;
  4496. }
  4497. /* Clear our data area */
  4498. ha = to_qla_host(host);
  4499. memset(ha, 0, sizeof(*ha));
  4500. /* Save the information from PCI BIOS. */
  4501. ha->pdev = pdev;
  4502. ha->host = host;
  4503. ha->host_no = host->host_no;
  4504. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  4505. pci_enable_pcie_error_reporting(pdev);
  4506. /* Setup Runtime configurable options */
  4507. if (is_qla8022(ha)) {
  4508. ha->isp_ops = &qla4_82xx_isp_ops;
  4509. ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
  4510. ha->qdr_sn_window = -1;
  4511. ha->ddr_mn_window = -1;
  4512. ha->curr_window = 255;
  4513. nx_legacy_intr = &legacy_intr[ha->func_num];
  4514. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  4515. ha->nx_legacy_intr.tgt_status_reg =
  4516. nx_legacy_intr->tgt_status_reg;
  4517. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  4518. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  4519. } else if (is_qla8032(ha)) {
  4520. ha->isp_ops = &qla4_83xx_isp_ops;
  4521. ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
  4522. } else {
  4523. ha->isp_ops = &qla4xxx_isp_ops;
  4524. }
  4525. if (is_qla80XX(ha)) {
  4526. rwlock_init(&ha->hw_lock);
  4527. ha->pf_bit = ha->func_num << 16;
  4528. /* Set EEH reset type to fundamental if required by hba */
  4529. pdev->needs_freset = 1;
  4530. }
  4531. /* Configure PCI I/O space. */
  4532. ret = ha->isp_ops->iospace_config(ha);
  4533. if (ret)
  4534. goto probe_failed_ioconfig;
  4535. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  4536. pdev->device, pdev->irq, ha->reg);
  4537. qla4xxx_config_dma_addressing(ha);
  4538. /* Initialize lists and spinlocks. */
  4539. INIT_LIST_HEAD(&ha->free_srb_q);
  4540. mutex_init(&ha->mbox_sem);
  4541. mutex_init(&ha->chap_sem);
  4542. init_completion(&ha->mbx_intr_comp);
  4543. init_completion(&ha->disable_acb_comp);
  4544. spin_lock_init(&ha->hardware_lock);
  4545. spin_lock_init(&ha->work_lock);
  4546. /* Initialize work list */
  4547. INIT_LIST_HEAD(&ha->work_list);
  4548. /* Allocate dma buffers */
  4549. if (qla4xxx_mem_alloc(ha)) {
  4550. ql4_printk(KERN_WARNING, ha,
  4551. "[ERROR] Failed to allocate memory for adapter\n");
  4552. ret = -ENOMEM;
  4553. goto probe_failed;
  4554. }
  4555. host->cmd_per_lun = 3;
  4556. host->max_channel = 0;
  4557. host->max_lun = MAX_LUNS - 1;
  4558. host->max_id = MAX_TARGETS;
  4559. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  4560. host->can_queue = MAX_SRBS ;
  4561. host->transportt = qla4xxx_scsi_transport;
  4562. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  4563. if (ret) {
  4564. ql4_printk(KERN_WARNING, ha,
  4565. "%s: scsi_init_shared_tag_map failed\n", __func__);
  4566. goto probe_failed;
  4567. }
  4568. pci_set_drvdata(pdev, ha);
  4569. ret = scsi_add_host(host, &pdev->dev);
  4570. if (ret)
  4571. goto probe_failed;
  4572. if (is_qla80XX(ha))
  4573. qla4_8xxx_get_flash_info(ha);
  4574. if (is_qla8032(ha)) {
  4575. qla4_83xx_read_reset_template(ha);
  4576. /*
  4577. * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  4578. * If DONRESET_BIT0 is set, drivers should not set dev_state
  4579. * to NEED_RESET. But if NEED_RESET is set, drivers should
  4580. * should honor the reset.
  4581. */
  4582. if (ql4xdontresethba == 1)
  4583. qla4_83xx_set_idc_dontreset(ha);
  4584. }
  4585. /*
  4586. * Initialize the Host adapter request/response queues and
  4587. * firmware
  4588. * NOTE: interrupts enabled upon successful completion
  4589. */
  4590. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  4591. /* Dont retry adapter initialization if IRQ allocation failed */
  4592. if (!test_bit(AF_IRQ_ATTACHED, &ha->flags))
  4593. goto skip_retry_init;
  4594. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  4595. init_retry_count++ < MAX_INIT_RETRIES) {
  4596. if (is_qla80XX(ha)) {
  4597. ha->isp_ops->idc_lock(ha);
  4598. dev_state = qla4_8xxx_rd_direct(ha,
  4599. QLA8XXX_CRB_DEV_STATE);
  4600. ha->isp_ops->idc_unlock(ha);
  4601. if (dev_state == QLA8XXX_DEV_FAILED) {
  4602. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  4603. "initialize adapter. H/W is in failed state\n",
  4604. __func__);
  4605. break;
  4606. }
  4607. }
  4608. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  4609. "(%d)\n", __func__, init_retry_count));
  4610. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  4611. continue;
  4612. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  4613. }
  4614. skip_retry_init:
  4615. if (!test_bit(AF_ONLINE, &ha->flags)) {
  4616. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  4617. if ((is_qla8022(ha) && ql4xdontresethba) ||
  4618. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  4619. /* Put the device in failed state. */
  4620. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  4621. ha->isp_ops->idc_lock(ha);
  4622. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  4623. QLA8XXX_DEV_FAILED);
  4624. ha->isp_ops->idc_unlock(ha);
  4625. }
  4626. ret = -ENODEV;
  4627. goto remove_host;
  4628. }
  4629. /* Startup the kernel thread for this host adapter. */
  4630. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  4631. "qla4xxx_dpc\n", __func__));
  4632. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  4633. ha->dpc_thread = create_singlethread_workqueue(buf);
  4634. if (!ha->dpc_thread) {
  4635. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  4636. ret = -ENODEV;
  4637. goto remove_host;
  4638. }
  4639. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  4640. sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
  4641. ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
  4642. if (!ha->task_wq) {
  4643. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  4644. ret = -ENODEV;
  4645. goto remove_host;
  4646. }
  4647. /*
  4648. * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
  4649. * (which is called indirectly by qla4xxx_initialize_adapter),
  4650. * so that irqs will be registered after crbinit but before
  4651. * mbx_intr_enable.
  4652. */
  4653. if (is_qla40XX(ha)) {
  4654. ret = qla4xxx_request_irqs(ha);
  4655. if (ret) {
  4656. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  4657. "interrupt %d already in use.\n", pdev->irq);
  4658. goto remove_host;
  4659. }
  4660. }
  4661. pci_save_state(ha->pdev);
  4662. ha->isp_ops->enable_intrs(ha);
  4663. /* Start timer thread. */
  4664. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  4665. set_bit(AF_INIT_DONE, &ha->flags);
  4666. qla4_8xxx_alloc_sysfs_attr(ha);
  4667. printk(KERN_INFO
  4668. " QLogic iSCSI HBA Driver version: %s\n"
  4669. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  4670. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  4671. ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
  4672. ha->patch_number, ha->build_number);
  4673. /* Set the driver version */
  4674. if (is_qla80XX(ha))
  4675. qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
  4676. if (qla4xxx_setup_boot_info(ha))
  4677. ql4_printk(KERN_ERR, ha,
  4678. "%s: No iSCSI boot target configured\n", __func__);
  4679. /* Perform the build ddb list and login to each */
  4680. qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
  4681. iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
  4682. qla4xxx_wait_login_resp_boot_tgt(ha);
  4683. qla4xxx_create_chap_list(ha);
  4684. qla4xxx_create_ifaces(ha);
  4685. return 0;
  4686. remove_host:
  4687. scsi_remove_host(ha->host);
  4688. probe_failed:
  4689. qla4xxx_free_adapter(ha);
  4690. probe_failed_ioconfig:
  4691. pci_disable_pcie_error_reporting(pdev);
  4692. scsi_host_put(ha->host);
  4693. probe_disable_device:
  4694. pci_disable_device(pdev);
  4695. return ret;
  4696. }
  4697. /**
  4698. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  4699. * @ha: pointer to adapter structure
  4700. *
  4701. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  4702. * so that the other port will not re-initialize while in the process of
  4703. * removing the ha due to driver unload or hba hotplug.
  4704. **/
  4705. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  4706. {
  4707. struct scsi_qla_host *other_ha = NULL;
  4708. struct pci_dev *other_pdev = NULL;
  4709. int fn = ISP4XXX_PCI_FN_2;
  4710. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  4711. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  4712. fn = ISP4XXX_PCI_FN_1;
  4713. other_pdev =
  4714. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  4715. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  4716. fn));
  4717. /* Get other_ha if other_pdev is valid and state is enable*/
  4718. if (other_pdev) {
  4719. if (atomic_read(&other_pdev->enable_cnt)) {
  4720. other_ha = pci_get_drvdata(other_pdev);
  4721. if (other_ha) {
  4722. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  4723. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  4724. "Prevent %s reinit\n", __func__,
  4725. dev_name(&other_ha->pdev->dev)));
  4726. }
  4727. }
  4728. pci_dev_put(other_pdev);
  4729. }
  4730. }
  4731. static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
  4732. {
  4733. struct ddb_entry *ddb_entry;
  4734. int options;
  4735. int idx;
  4736. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  4737. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  4738. if ((ddb_entry != NULL) &&
  4739. (ddb_entry->ddb_type == FLASH_DDB)) {
  4740. options = LOGOUT_OPTION_CLOSE_SESSION;
  4741. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
  4742. == QLA_ERROR)
  4743. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
  4744. __func__);
  4745. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  4746. /*
  4747. * we have decremented the reference count of the driver
  4748. * when we setup the session to have the driver unload
  4749. * to be seamless without actually destroying the
  4750. * session
  4751. **/
  4752. try_module_get(qla4xxx_iscsi_transport.owner);
  4753. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  4754. qla4xxx_free_ddb(ha, ddb_entry);
  4755. iscsi_session_teardown(ddb_entry->sess);
  4756. }
  4757. }
  4758. }
  4759. /**
  4760. * qla4xxx_remove_adapter - callback function to remove adapter.
  4761. * @pci_dev: PCI device pointer
  4762. **/
  4763. static void qla4xxx_remove_adapter(struct pci_dev *pdev)
  4764. {
  4765. struct scsi_qla_host *ha;
  4766. /*
  4767. * If the PCI device is disabled then it means probe_adapter had
  4768. * failed and resources already cleaned up on probe_adapter exit.
  4769. */
  4770. if (!pci_is_enabled(pdev))
  4771. return;
  4772. ha = pci_get_drvdata(pdev);
  4773. if (is_qla40XX(ha))
  4774. qla4xxx_prevent_other_port_reinit(ha);
  4775. /* destroy iface from sysfs */
  4776. qla4xxx_destroy_ifaces(ha);
  4777. if ((!ql4xdisablesysfsboot) && ha->boot_kset)
  4778. iscsi_boot_destroy_kset(ha->boot_kset);
  4779. qla4xxx_destroy_fw_ddb_session(ha);
  4780. qla4_8xxx_free_sysfs_attr(ha);
  4781. scsi_remove_host(ha->host);
  4782. qla4xxx_free_adapter(ha);
  4783. scsi_host_put(ha->host);
  4784. pci_disable_pcie_error_reporting(pdev);
  4785. pci_disable_device(pdev);
  4786. pci_set_drvdata(pdev, NULL);
  4787. }
  4788. /**
  4789. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  4790. * @ha: HA context
  4791. *
  4792. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  4793. * supported addressing method.
  4794. */
  4795. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  4796. {
  4797. int retval;
  4798. /* Update our PCI device dma_mask for full 64 bit mask */
  4799. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  4800. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  4801. dev_dbg(&ha->pdev->dev,
  4802. "Failed to set 64 bit PCI consistent mask; "
  4803. "using 32 bit.\n");
  4804. retval = pci_set_consistent_dma_mask(ha->pdev,
  4805. DMA_BIT_MASK(32));
  4806. }
  4807. } else
  4808. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  4809. }
  4810. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  4811. {
  4812. struct iscsi_cls_session *cls_sess;
  4813. struct iscsi_session *sess;
  4814. struct ddb_entry *ddb;
  4815. int queue_depth = QL4_DEF_QDEPTH;
  4816. cls_sess = starget_to_session(sdev->sdev_target);
  4817. sess = cls_sess->dd_data;
  4818. ddb = sess->dd_data;
  4819. sdev->hostdata = ddb;
  4820. sdev->tagged_supported = 1;
  4821. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  4822. queue_depth = ql4xmaxqdepth;
  4823. scsi_activate_tcq(sdev, queue_depth);
  4824. return 0;
  4825. }
  4826. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  4827. {
  4828. sdev->tagged_supported = 1;
  4829. return 0;
  4830. }
  4831. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  4832. {
  4833. scsi_deactivate_tcq(sdev, 1);
  4834. }
  4835. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  4836. int reason)
  4837. {
  4838. if (!ql4xqfulltracking)
  4839. return -EOPNOTSUPP;
  4840. return iscsi_change_queue_depth(sdev, qdepth, reason);
  4841. }
  4842. /**
  4843. * qla4xxx_del_from_active_array - returns an active srb
  4844. * @ha: Pointer to host adapter structure.
  4845. * @index: index into the active_array
  4846. *
  4847. * This routine removes and returns the srb at the specified index
  4848. **/
  4849. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  4850. uint32_t index)
  4851. {
  4852. struct srb *srb = NULL;
  4853. struct scsi_cmnd *cmd = NULL;
  4854. cmd = scsi_host_find_tag(ha->host, index);
  4855. if (!cmd)
  4856. return srb;
  4857. srb = (struct srb *)CMD_SP(cmd);
  4858. if (!srb)
  4859. return srb;
  4860. /* update counters */
  4861. if (srb->flags & SRB_DMA_VALID) {
  4862. ha->iocb_cnt -= srb->iocb_cnt;
  4863. if (srb->cmd)
  4864. srb->cmd->host_scribble =
  4865. (unsigned char *)(unsigned long) MAX_SRBS;
  4866. }
  4867. return srb;
  4868. }
  4869. /**
  4870. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  4871. * @ha: Pointer to host adapter structure.
  4872. * @cmd: Scsi Command to wait on.
  4873. *
  4874. * This routine waits for the command to be returned by the Firmware
  4875. * for some max time.
  4876. **/
  4877. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  4878. struct scsi_cmnd *cmd)
  4879. {
  4880. int done = 0;
  4881. struct srb *rp;
  4882. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  4883. int ret = SUCCESS;
  4884. /* Dont wait on command if PCI error is being handled
  4885. * by PCI AER driver
  4886. */
  4887. if (unlikely(pci_channel_offline(ha->pdev)) ||
  4888. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  4889. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  4890. ha->host_no, __func__);
  4891. return ret;
  4892. }
  4893. do {
  4894. /* Checking to see if its returned to OS */
  4895. rp = (struct srb *) CMD_SP(cmd);
  4896. if (rp == NULL) {
  4897. done++;
  4898. break;
  4899. }
  4900. msleep(2000);
  4901. } while (max_wait_time--);
  4902. return done;
  4903. }
  4904. /**
  4905. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  4906. * @ha: Pointer to host adapter structure
  4907. **/
  4908. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  4909. {
  4910. unsigned long wait_online;
  4911. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  4912. while (time_before(jiffies, wait_online)) {
  4913. if (adapter_up(ha))
  4914. return QLA_SUCCESS;
  4915. msleep(2000);
  4916. }
  4917. return QLA_ERROR;
  4918. }
  4919. /**
  4920. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  4921. * @ha: pointer to HBA
  4922. * @t: target id
  4923. * @l: lun id
  4924. *
  4925. * This function waits for all outstanding commands to a lun to complete. It
  4926. * returns 0 if all pending commands are returned and 1 otherwise.
  4927. **/
  4928. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  4929. struct scsi_target *stgt,
  4930. struct scsi_device *sdev)
  4931. {
  4932. int cnt;
  4933. int status = 0;
  4934. struct scsi_cmnd *cmd;
  4935. /*
  4936. * Waiting for all commands for the designated target or dev
  4937. * in the active array
  4938. */
  4939. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  4940. cmd = scsi_host_find_tag(ha->host, cnt);
  4941. if (cmd && stgt == scsi_target(cmd->device) &&
  4942. (!sdev || sdev == cmd->device)) {
  4943. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  4944. status++;
  4945. break;
  4946. }
  4947. }
  4948. }
  4949. return status;
  4950. }
  4951. /**
  4952. * qla4xxx_eh_abort - callback for abort task.
  4953. * @cmd: Pointer to Linux's SCSI command structure
  4954. *
  4955. * This routine is called by the Linux OS to abort the specified
  4956. * command.
  4957. **/
  4958. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  4959. {
  4960. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  4961. unsigned int id = cmd->device->id;
  4962. unsigned int lun = cmd->device->lun;
  4963. unsigned long flags;
  4964. struct srb *srb = NULL;
  4965. int ret = SUCCESS;
  4966. int wait = 0;
  4967. ql4_printk(KERN_INFO, ha,
  4968. "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
  4969. ha->host_no, id, lun, cmd);
  4970. spin_lock_irqsave(&ha->hardware_lock, flags);
  4971. srb = (struct srb *) CMD_SP(cmd);
  4972. if (!srb) {
  4973. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4974. return SUCCESS;
  4975. }
  4976. kref_get(&srb->srb_ref);
  4977. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4978. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  4979. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
  4980. ha->host_no, id, lun));
  4981. ret = FAILED;
  4982. } else {
  4983. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
  4984. ha->host_no, id, lun));
  4985. wait = 1;
  4986. }
  4987. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  4988. /* Wait for command to complete */
  4989. if (wait) {
  4990. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  4991. DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
  4992. ha->host_no, id, lun));
  4993. ret = FAILED;
  4994. }
  4995. }
  4996. ql4_printk(KERN_INFO, ha,
  4997. "scsi%ld:%d:%d: Abort command - %s\n",
  4998. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  4999. return ret;
  5000. }
  5001. /**
  5002. * qla4xxx_eh_device_reset - callback for target reset.
  5003. * @cmd: Pointer to Linux's SCSI command structure
  5004. *
  5005. * This routine is called by the Linux OS to reset all luns on the
  5006. * specified target.
  5007. **/
  5008. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  5009. {
  5010. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  5011. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  5012. int ret = FAILED, stat;
  5013. if (!ddb_entry)
  5014. return ret;
  5015. ret = iscsi_block_scsi_eh(cmd);
  5016. if (ret)
  5017. return ret;
  5018. ret = FAILED;
  5019. ql4_printk(KERN_INFO, ha,
  5020. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  5021. cmd->device->channel, cmd->device->id, cmd->device->lun);
  5022. DEBUG2(printk(KERN_INFO
  5023. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  5024. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  5025. cmd, jiffies, cmd->request->timeout / HZ,
  5026. ha->dpc_flags, cmd->result, cmd->allowed));
  5027. /* FIXME: wait for hba to go online */
  5028. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  5029. if (stat != QLA_SUCCESS) {
  5030. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  5031. goto eh_dev_reset_done;
  5032. }
  5033. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  5034. cmd->device)) {
  5035. ql4_printk(KERN_INFO, ha,
  5036. "DEVICE RESET FAILED - waiting for "
  5037. "commands.\n");
  5038. goto eh_dev_reset_done;
  5039. }
  5040. /* Send marker. */
  5041. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  5042. MM_LUN_RESET) != QLA_SUCCESS)
  5043. goto eh_dev_reset_done;
  5044. ql4_printk(KERN_INFO, ha,
  5045. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  5046. ha->host_no, cmd->device->channel, cmd->device->id,
  5047. cmd->device->lun);
  5048. ret = SUCCESS;
  5049. eh_dev_reset_done:
  5050. return ret;
  5051. }
  5052. /**
  5053. * qla4xxx_eh_target_reset - callback for target reset.
  5054. * @cmd: Pointer to Linux's SCSI command structure
  5055. *
  5056. * This routine is called by the Linux OS to reset the target.
  5057. **/
  5058. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  5059. {
  5060. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  5061. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  5062. int stat, ret;
  5063. if (!ddb_entry)
  5064. return FAILED;
  5065. ret = iscsi_block_scsi_eh(cmd);
  5066. if (ret)
  5067. return ret;
  5068. starget_printk(KERN_INFO, scsi_target(cmd->device),
  5069. "WARM TARGET RESET ISSUED.\n");
  5070. DEBUG2(printk(KERN_INFO
  5071. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  5072. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  5073. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  5074. ha->dpc_flags, cmd->result, cmd->allowed));
  5075. stat = qla4xxx_reset_target(ha, ddb_entry);
  5076. if (stat != QLA_SUCCESS) {
  5077. starget_printk(KERN_INFO, scsi_target(cmd->device),
  5078. "WARM TARGET RESET FAILED.\n");
  5079. return FAILED;
  5080. }
  5081. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  5082. NULL)) {
  5083. starget_printk(KERN_INFO, scsi_target(cmd->device),
  5084. "WARM TARGET DEVICE RESET FAILED - "
  5085. "waiting for commands.\n");
  5086. return FAILED;
  5087. }
  5088. /* Send marker. */
  5089. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  5090. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  5091. starget_printk(KERN_INFO, scsi_target(cmd->device),
  5092. "WARM TARGET DEVICE RESET FAILED - "
  5093. "marker iocb failed.\n");
  5094. return FAILED;
  5095. }
  5096. starget_printk(KERN_INFO, scsi_target(cmd->device),
  5097. "WARM TARGET RESET SUCCEEDED.\n");
  5098. return SUCCESS;
  5099. }
  5100. /**
  5101. * qla4xxx_is_eh_active - check if error handler is running
  5102. * @shost: Pointer to SCSI Host struct
  5103. *
  5104. * This routine finds that if reset host is called in EH
  5105. * scenario or from some application like sg_reset
  5106. **/
  5107. static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
  5108. {
  5109. if (shost->shost_state == SHOST_RECOVERY)
  5110. return 1;
  5111. return 0;
  5112. }
  5113. /**
  5114. * qla4xxx_eh_host_reset - kernel callback
  5115. * @cmd: Pointer to Linux's SCSI command structure
  5116. *
  5117. * This routine is invoked by the Linux kernel to perform fatal error
  5118. * recovery on the specified adapter.
  5119. **/
  5120. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  5121. {
  5122. int return_status = FAILED;
  5123. struct scsi_qla_host *ha;
  5124. ha = to_qla_host(cmd->device->host);
  5125. if (is_qla8032(ha) && ql4xdontresethba)
  5126. qla4_83xx_set_idc_dontreset(ha);
  5127. /*
  5128. * For ISP8324, if IDC_CTRL DONTRESET_BIT0 is set by other
  5129. * protocol drivers, we should not set device_state to
  5130. * NEED_RESET
  5131. */
  5132. if (ql4xdontresethba ||
  5133. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  5134. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  5135. ha->host_no, __func__));
  5136. /* Clear outstanding srb in queues */
  5137. if (qla4xxx_is_eh_active(cmd->device->host))
  5138. qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
  5139. return FAILED;
  5140. }
  5141. ql4_printk(KERN_INFO, ha,
  5142. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  5143. cmd->device->channel, cmd->device->id, cmd->device->lun);
  5144. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  5145. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  5146. "DEAD.\n", ha->host_no, cmd->device->channel,
  5147. __func__));
  5148. return FAILED;
  5149. }
  5150. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  5151. if (is_qla80XX(ha))
  5152. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  5153. else
  5154. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  5155. }
  5156. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  5157. return_status = SUCCESS;
  5158. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  5159. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  5160. return return_status;
  5161. }
  5162. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  5163. {
  5164. uint32_t mbox_cmd[MBOX_REG_COUNT];
  5165. uint32_t mbox_sts[MBOX_REG_COUNT];
  5166. struct addr_ctrl_blk_def *acb = NULL;
  5167. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  5168. int rval = QLA_SUCCESS;
  5169. dma_addr_t acb_dma;
  5170. acb = dma_alloc_coherent(&ha->pdev->dev,
  5171. sizeof(struct addr_ctrl_blk_def),
  5172. &acb_dma, GFP_KERNEL);
  5173. if (!acb) {
  5174. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  5175. __func__);
  5176. rval = -ENOMEM;
  5177. goto exit_port_reset;
  5178. }
  5179. memset(acb, 0, acb_len);
  5180. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  5181. if (rval != QLA_SUCCESS) {
  5182. rval = -EIO;
  5183. goto exit_free_acb;
  5184. }
  5185. rval = qla4xxx_disable_acb(ha);
  5186. if (rval != QLA_SUCCESS) {
  5187. rval = -EIO;
  5188. goto exit_free_acb;
  5189. }
  5190. wait_for_completion_timeout(&ha->disable_acb_comp,
  5191. DISABLE_ACB_TOV * HZ);
  5192. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  5193. if (rval != QLA_SUCCESS) {
  5194. rval = -EIO;
  5195. goto exit_free_acb;
  5196. }
  5197. exit_free_acb:
  5198. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  5199. acb, acb_dma);
  5200. exit_port_reset:
  5201. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  5202. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  5203. return rval;
  5204. }
  5205. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  5206. {
  5207. struct scsi_qla_host *ha = to_qla_host(shost);
  5208. int rval = QLA_SUCCESS;
  5209. uint32_t idc_ctrl;
  5210. if (ql4xdontresethba) {
  5211. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  5212. __func__));
  5213. rval = -EPERM;
  5214. goto exit_host_reset;
  5215. }
  5216. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  5217. goto recover_adapter;
  5218. switch (reset_type) {
  5219. case SCSI_ADAPTER_RESET:
  5220. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  5221. break;
  5222. case SCSI_FIRMWARE_RESET:
  5223. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  5224. if (is_qla80XX(ha))
  5225. /* set firmware context reset */
  5226. set_bit(DPC_RESET_HA_FW_CONTEXT,
  5227. &ha->dpc_flags);
  5228. else {
  5229. rval = qla4xxx_context_reset(ha);
  5230. goto exit_host_reset;
  5231. }
  5232. }
  5233. break;
  5234. }
  5235. recover_adapter:
  5236. /* For ISP83XX set graceful reset bit in IDC_DRV_CTRL if
  5237. * reset is issued by application */
  5238. if (is_qla8032(ha) && test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  5239. idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
  5240. qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
  5241. (idc_ctrl | GRACEFUL_RESET_BIT1));
  5242. }
  5243. rval = qla4xxx_recover_adapter(ha);
  5244. if (rval != QLA_SUCCESS) {
  5245. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  5246. __func__));
  5247. rval = -EIO;
  5248. }
  5249. exit_host_reset:
  5250. return rval;
  5251. }
  5252. /* PCI AER driver recovers from all correctable errors w/o
  5253. * driver intervention. For uncorrectable errors PCI AER
  5254. * driver calls the following device driver's callbacks
  5255. *
  5256. * - Fatal Errors - link_reset
  5257. * - Non-Fatal Errors - driver's pci_error_detected() which
  5258. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  5259. *
  5260. * PCI AER driver calls
  5261. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  5262. * returns RECOVERED or NEED_RESET if fw_hung
  5263. * NEED_RESET - driver's slot_reset()
  5264. * DISCONNECT - device is dead & cannot recover
  5265. * RECOVERED - driver's pci_resume()
  5266. */
  5267. static pci_ers_result_t
  5268. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  5269. {
  5270. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5271. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  5272. ha->host_no, __func__, state);
  5273. if (!is_aer_supported(ha))
  5274. return PCI_ERS_RESULT_NONE;
  5275. switch (state) {
  5276. case pci_channel_io_normal:
  5277. clear_bit(AF_EEH_BUSY, &ha->flags);
  5278. return PCI_ERS_RESULT_CAN_RECOVER;
  5279. case pci_channel_io_frozen:
  5280. set_bit(AF_EEH_BUSY, &ha->flags);
  5281. qla4xxx_mailbox_premature_completion(ha);
  5282. qla4xxx_free_irqs(ha);
  5283. pci_disable_device(pdev);
  5284. /* Return back all IOs */
  5285. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  5286. return PCI_ERS_RESULT_NEED_RESET;
  5287. case pci_channel_io_perm_failure:
  5288. set_bit(AF_EEH_BUSY, &ha->flags);
  5289. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  5290. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  5291. return PCI_ERS_RESULT_DISCONNECT;
  5292. }
  5293. return PCI_ERS_RESULT_NEED_RESET;
  5294. }
  5295. /**
  5296. * qla4xxx_pci_mmio_enabled() gets called if
  5297. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  5298. * and read/write to the device still works.
  5299. **/
  5300. static pci_ers_result_t
  5301. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  5302. {
  5303. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5304. if (!is_aer_supported(ha))
  5305. return PCI_ERS_RESULT_NONE;
  5306. return PCI_ERS_RESULT_RECOVERED;
  5307. }
  5308. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  5309. {
  5310. uint32_t rval = QLA_ERROR;
  5311. int fn;
  5312. struct pci_dev *other_pdev = NULL;
  5313. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  5314. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  5315. if (test_bit(AF_ONLINE, &ha->flags)) {
  5316. clear_bit(AF_ONLINE, &ha->flags);
  5317. clear_bit(AF_LINK_UP, &ha->flags);
  5318. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  5319. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  5320. }
  5321. fn = PCI_FUNC(ha->pdev->devfn);
  5322. while (fn > 0) {
  5323. fn--;
  5324. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
  5325. "func %x\n", ha->host_no, __func__, fn);
  5326. /* Get the pci device given the domain, bus,
  5327. * slot/function number */
  5328. other_pdev =
  5329. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  5330. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  5331. fn));
  5332. if (!other_pdev)
  5333. continue;
  5334. if (atomic_read(&other_pdev->enable_cnt)) {
  5335. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
  5336. "func in enabled state%x\n", ha->host_no,
  5337. __func__, fn);
  5338. pci_dev_put(other_pdev);
  5339. break;
  5340. }
  5341. pci_dev_put(other_pdev);
  5342. }
  5343. /* The first function on the card, the reset owner will
  5344. * start & initialize the firmware. The other functions
  5345. * on the card will reset the firmware context
  5346. */
  5347. if (!fn) {
  5348. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  5349. "0x%x is the owner\n", ha->host_no, __func__,
  5350. ha->pdev->devfn);
  5351. ha->isp_ops->idc_lock(ha);
  5352. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  5353. QLA8XXX_DEV_COLD);
  5354. ha->isp_ops->idc_unlock(ha);
  5355. rval = qla4_8xxx_update_idc_reg(ha);
  5356. if (rval == QLA_ERROR) {
  5357. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
  5358. ha->host_no, __func__);
  5359. ha->isp_ops->idc_lock(ha);
  5360. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  5361. QLA8XXX_DEV_FAILED);
  5362. ha->isp_ops->idc_unlock(ha);
  5363. goto exit_error_recovery;
  5364. }
  5365. clear_bit(AF_FW_RECOVERY, &ha->flags);
  5366. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  5367. if (rval != QLA_SUCCESS) {
  5368. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  5369. "FAILED\n", ha->host_no, __func__);
  5370. ha->isp_ops->idc_lock(ha);
  5371. qla4_8xxx_clear_drv_active(ha);
  5372. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  5373. QLA8XXX_DEV_FAILED);
  5374. ha->isp_ops->idc_unlock(ha);
  5375. } else {
  5376. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  5377. "READY\n", ha->host_no, __func__);
  5378. ha->isp_ops->idc_lock(ha);
  5379. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  5380. QLA8XXX_DEV_READY);
  5381. /* Clear driver state register */
  5382. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
  5383. qla4_8xxx_set_drv_active(ha);
  5384. ha->isp_ops->idc_unlock(ha);
  5385. ha->isp_ops->enable_intrs(ha);
  5386. }
  5387. } else {
  5388. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  5389. "the reset owner\n", ha->host_no, __func__,
  5390. ha->pdev->devfn);
  5391. if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
  5392. QLA8XXX_DEV_READY)) {
  5393. clear_bit(AF_FW_RECOVERY, &ha->flags);
  5394. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  5395. if (rval == QLA_SUCCESS)
  5396. ha->isp_ops->enable_intrs(ha);
  5397. ha->isp_ops->idc_lock(ha);
  5398. qla4_8xxx_set_drv_active(ha);
  5399. ha->isp_ops->idc_unlock(ha);
  5400. }
  5401. }
  5402. exit_error_recovery:
  5403. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  5404. return rval;
  5405. }
  5406. static pci_ers_result_t
  5407. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  5408. {
  5409. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  5410. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5411. int rc;
  5412. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  5413. ha->host_no, __func__);
  5414. if (!is_aer_supported(ha))
  5415. return PCI_ERS_RESULT_NONE;
  5416. /* Restore the saved state of PCIe device -
  5417. * BAR registers, PCI Config space, PCIX, MSI,
  5418. * IOV states
  5419. */
  5420. pci_restore_state(pdev);
  5421. /* pci_restore_state() clears the saved_state flag of the device
  5422. * save restored state which resets saved_state flag
  5423. */
  5424. pci_save_state(pdev);
  5425. /* Initialize device or resume if in suspended state */
  5426. rc = pci_enable_device(pdev);
  5427. if (rc) {
  5428. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  5429. "device after reset\n", ha->host_no, __func__);
  5430. goto exit_slot_reset;
  5431. }
  5432. ha->isp_ops->disable_intrs(ha);
  5433. if (is_qla80XX(ha)) {
  5434. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  5435. ret = PCI_ERS_RESULT_RECOVERED;
  5436. goto exit_slot_reset;
  5437. } else
  5438. goto exit_slot_reset;
  5439. }
  5440. exit_slot_reset:
  5441. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  5442. "device after reset\n", ha->host_no, __func__, ret);
  5443. return ret;
  5444. }
  5445. static void
  5446. qla4xxx_pci_resume(struct pci_dev *pdev)
  5447. {
  5448. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  5449. int ret;
  5450. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  5451. ha->host_no, __func__);
  5452. ret = qla4xxx_wait_for_hba_online(ha);
  5453. if (ret != QLA_SUCCESS) {
  5454. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  5455. "resume I/O from slot/link_reset\n", ha->host_no,
  5456. __func__);
  5457. }
  5458. pci_cleanup_aer_uncorrect_error_status(pdev);
  5459. clear_bit(AF_EEH_BUSY, &ha->flags);
  5460. }
  5461. static const struct pci_error_handlers qla4xxx_err_handler = {
  5462. .error_detected = qla4xxx_pci_error_detected,
  5463. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  5464. .slot_reset = qla4xxx_pci_slot_reset,
  5465. .resume = qla4xxx_pci_resume,
  5466. };
  5467. static struct pci_device_id qla4xxx_pci_tbl[] = {
  5468. {
  5469. .vendor = PCI_VENDOR_ID_QLOGIC,
  5470. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  5471. .subvendor = PCI_ANY_ID,
  5472. .subdevice = PCI_ANY_ID,
  5473. },
  5474. {
  5475. .vendor = PCI_VENDOR_ID_QLOGIC,
  5476. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  5477. .subvendor = PCI_ANY_ID,
  5478. .subdevice = PCI_ANY_ID,
  5479. },
  5480. {
  5481. .vendor = PCI_VENDOR_ID_QLOGIC,
  5482. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  5483. .subvendor = PCI_ANY_ID,
  5484. .subdevice = PCI_ANY_ID,
  5485. },
  5486. {
  5487. .vendor = PCI_VENDOR_ID_QLOGIC,
  5488. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  5489. .subvendor = PCI_ANY_ID,
  5490. .subdevice = PCI_ANY_ID,
  5491. },
  5492. {
  5493. .vendor = PCI_VENDOR_ID_QLOGIC,
  5494. .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
  5495. .subvendor = PCI_ANY_ID,
  5496. .subdevice = PCI_ANY_ID,
  5497. },
  5498. {0, 0},
  5499. };
  5500. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  5501. static struct pci_driver qla4xxx_pci_driver = {
  5502. .name = DRIVER_NAME,
  5503. .id_table = qla4xxx_pci_tbl,
  5504. .probe = qla4xxx_probe_adapter,
  5505. .remove = qla4xxx_remove_adapter,
  5506. .err_handler = &qla4xxx_err_handler,
  5507. };
  5508. static int __init qla4xxx_module_init(void)
  5509. {
  5510. int ret;
  5511. /* Allocate cache for SRBs. */
  5512. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  5513. SLAB_HWCACHE_ALIGN, NULL);
  5514. if (srb_cachep == NULL) {
  5515. printk(KERN_ERR
  5516. "%s: Unable to allocate SRB cache..."
  5517. "Failing load!\n", DRIVER_NAME);
  5518. ret = -ENOMEM;
  5519. goto no_srp_cache;
  5520. }
  5521. /* Derive version string. */
  5522. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  5523. if (ql4xextended_error_logging)
  5524. strcat(qla4xxx_version_str, "-debug");
  5525. qla4xxx_scsi_transport =
  5526. iscsi_register_transport(&qla4xxx_iscsi_transport);
  5527. if (!qla4xxx_scsi_transport){
  5528. ret = -ENODEV;
  5529. goto release_srb_cache;
  5530. }
  5531. ret = pci_register_driver(&qla4xxx_pci_driver);
  5532. if (ret)
  5533. goto unregister_transport;
  5534. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  5535. return 0;
  5536. unregister_transport:
  5537. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  5538. release_srb_cache:
  5539. kmem_cache_destroy(srb_cachep);
  5540. no_srp_cache:
  5541. return ret;
  5542. }
  5543. static void __exit qla4xxx_module_exit(void)
  5544. {
  5545. pci_unregister_driver(&qla4xxx_pci_driver);
  5546. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  5547. kmem_cache_destroy(srb_cachep);
  5548. }
  5549. module_init(qla4xxx_module_init);
  5550. module_exit(qla4xxx_module_exit);
  5551. MODULE_AUTHOR("QLogic Corporation");
  5552. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  5553. MODULE_LICENSE("GPL");
  5554. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);