ql4_os.c 239 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2013 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. /*
  153. * iSCSI Flash DDB sysfs entry points
  154. */
  155. static int
  156. qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
  157. struct iscsi_bus_flash_conn *fnode_conn,
  158. void *data, int len);
  159. static int
  160. qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
  161. int param, char *buf);
  162. static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
  163. int len);
  164. static int
  165. qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
  166. static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
  167. struct iscsi_bus_flash_conn *fnode_conn);
  168. static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
  169. struct iscsi_bus_flash_conn *fnode_conn);
  170. static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
  171. static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
  172. QLA82XX_LEGACY_INTR_CONFIG;
  173. static struct scsi_host_template qla4xxx_driver_template = {
  174. .module = THIS_MODULE,
  175. .name = DRIVER_NAME,
  176. .proc_name = DRIVER_NAME,
  177. .queuecommand = qla4xxx_queuecommand,
  178. .eh_abort_handler = qla4xxx_eh_abort,
  179. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  180. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  181. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  182. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  183. .slave_configure = qla4xxx_slave_configure,
  184. .slave_alloc = qla4xxx_slave_alloc,
  185. .slave_destroy = qla4xxx_slave_destroy,
  186. .change_queue_depth = qla4xxx_change_queue_depth,
  187. .this_id = -1,
  188. .cmd_per_lun = 3,
  189. .use_clustering = ENABLE_CLUSTERING,
  190. .sg_tablesize = SG_ALL,
  191. .max_sectors = 0xFFFF,
  192. .shost_attrs = qla4xxx_host_attrs,
  193. .host_reset = qla4xxx_host_reset,
  194. .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
  195. };
  196. static struct iscsi_transport qla4xxx_iscsi_transport = {
  197. .owner = THIS_MODULE,
  198. .name = DRIVER_NAME,
  199. .caps = CAP_TEXT_NEGO |
  200. CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
  201. CAP_DATADGST | CAP_LOGIN_OFFLOAD |
  202. CAP_MULTI_R2T,
  203. .attr_is_visible = qla4_attr_is_visible,
  204. .create_session = qla4xxx_session_create,
  205. .destroy_session = qla4xxx_session_destroy,
  206. .start_conn = qla4xxx_conn_start,
  207. .create_conn = qla4xxx_conn_create,
  208. .bind_conn = qla4xxx_conn_bind,
  209. .stop_conn = iscsi_conn_stop,
  210. .destroy_conn = qla4xxx_conn_destroy,
  211. .set_param = iscsi_set_param,
  212. .get_conn_param = qla4xxx_conn_get_param,
  213. .get_session_param = qla4xxx_session_get_param,
  214. .get_ep_param = qla4xxx_get_ep_param,
  215. .ep_connect = qla4xxx_ep_connect,
  216. .ep_poll = qla4xxx_ep_poll,
  217. .ep_disconnect = qla4xxx_ep_disconnect,
  218. .get_stats = qla4xxx_conn_get_stats,
  219. .send_pdu = iscsi_conn_send_pdu,
  220. .xmit_task = qla4xxx_task_xmit,
  221. .cleanup_task = qla4xxx_task_cleanup,
  222. .alloc_pdu = qla4xxx_alloc_pdu,
  223. .get_host_param = qla4xxx_host_get_param,
  224. .set_iface_param = qla4xxx_iface_set_param,
  225. .get_iface_param = qla4xxx_get_iface_param,
  226. .bsg_request = qla4xxx_bsg_request,
  227. .send_ping = qla4xxx_send_ping,
  228. .get_chap = qla4xxx_get_chap_list,
  229. .delete_chap = qla4xxx_delete_chap,
  230. .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
  231. .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
  232. .new_flashnode = qla4xxx_sysfs_ddb_add,
  233. .del_flashnode = qla4xxx_sysfs_ddb_delete,
  234. .login_flashnode = qla4xxx_sysfs_ddb_login,
  235. .logout_flashnode = qla4xxx_sysfs_ddb_logout,
  236. .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
  237. };
  238. static struct scsi_transport_template *qla4xxx_scsi_transport;
  239. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  240. uint32_t iface_type, uint32_t payload_size,
  241. uint32_t pid, struct sockaddr *dst_addr)
  242. {
  243. struct scsi_qla_host *ha = to_qla_host(shost);
  244. struct sockaddr_in *addr;
  245. struct sockaddr_in6 *addr6;
  246. uint32_t options = 0;
  247. uint8_t ipaddr[IPv6_ADDR_LEN];
  248. int rval;
  249. memset(ipaddr, 0, IPv6_ADDR_LEN);
  250. /* IPv4 to IPv4 */
  251. if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
  252. (dst_addr->sa_family == AF_INET)) {
  253. addr = (struct sockaddr_in *)dst_addr;
  254. memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
  255. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
  256. "dest: %pI4\n", __func__,
  257. &ha->ip_config.ip_address, ipaddr));
  258. rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
  259. ipaddr);
  260. if (rval)
  261. rval = -EINVAL;
  262. } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
  263. (dst_addr->sa_family == AF_INET6)) {
  264. /* IPv6 to IPv6 */
  265. addr6 = (struct sockaddr_in6 *)dst_addr;
  266. memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
  267. options |= PING_IPV6_PROTOCOL_ENABLE;
  268. /* Ping using LinkLocal address */
  269. if ((iface_num == 0) || (iface_num == 1)) {
  270. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
  271. "src: %pI6 dest: %pI6\n", __func__,
  272. &ha->ip_config.ipv6_link_local_addr,
  273. ipaddr));
  274. options |= PING_IPV6_LINKLOCAL_ADDR;
  275. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  276. pid, ipaddr);
  277. } else {
  278. ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
  279. "not supported\n", __func__, iface_num);
  280. rval = -ENOSYS;
  281. goto exit_send_ping;
  282. }
  283. /*
  284. * If ping using LinkLocal address fails, try ping using
  285. * IPv6 address
  286. */
  287. if (rval != QLA_SUCCESS) {
  288. options &= ~PING_IPV6_LINKLOCAL_ADDR;
  289. if (iface_num == 0) {
  290. options |= PING_IPV6_ADDR0;
  291. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  292. "Ping src: %pI6 "
  293. "dest: %pI6\n", __func__,
  294. &ha->ip_config.ipv6_addr0,
  295. ipaddr));
  296. } else if (iface_num == 1) {
  297. options |= PING_IPV6_ADDR1;
  298. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  299. "Ping src: %pI6 "
  300. "dest: %pI6\n", __func__,
  301. &ha->ip_config.ipv6_addr1,
  302. ipaddr));
  303. }
  304. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  305. pid, ipaddr);
  306. if (rval)
  307. rval = -EINVAL;
  308. }
  309. } else
  310. rval = -ENOSYS;
  311. exit_send_ping:
  312. return rval;
  313. }
  314. static umode_t qla4_attr_is_visible(int param_type, int param)
  315. {
  316. switch (param_type) {
  317. case ISCSI_HOST_PARAM:
  318. switch (param) {
  319. case ISCSI_HOST_PARAM_HWADDRESS:
  320. case ISCSI_HOST_PARAM_IPADDRESS:
  321. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  322. case ISCSI_HOST_PARAM_PORT_STATE:
  323. case ISCSI_HOST_PARAM_PORT_SPEED:
  324. return S_IRUGO;
  325. default:
  326. return 0;
  327. }
  328. case ISCSI_PARAM:
  329. switch (param) {
  330. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  331. case ISCSI_PARAM_PERSISTENT_PORT:
  332. case ISCSI_PARAM_CONN_ADDRESS:
  333. case ISCSI_PARAM_CONN_PORT:
  334. case ISCSI_PARAM_TARGET_NAME:
  335. case ISCSI_PARAM_TPGT:
  336. case ISCSI_PARAM_TARGET_ALIAS:
  337. case ISCSI_PARAM_MAX_BURST:
  338. case ISCSI_PARAM_MAX_R2T:
  339. case ISCSI_PARAM_FIRST_BURST:
  340. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  341. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  342. case ISCSI_PARAM_IFACE_NAME:
  343. case ISCSI_PARAM_CHAP_OUT_IDX:
  344. case ISCSI_PARAM_CHAP_IN_IDX:
  345. case ISCSI_PARAM_USERNAME:
  346. case ISCSI_PARAM_PASSWORD:
  347. case ISCSI_PARAM_USERNAME_IN:
  348. case ISCSI_PARAM_PASSWORD_IN:
  349. case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
  350. case ISCSI_PARAM_DISCOVERY_SESS:
  351. case ISCSI_PARAM_PORTAL_TYPE:
  352. case ISCSI_PARAM_CHAP_AUTH_EN:
  353. case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
  354. case ISCSI_PARAM_BIDI_CHAP_EN:
  355. case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
  356. case ISCSI_PARAM_DEF_TIME2WAIT:
  357. case ISCSI_PARAM_DEF_TIME2RETAIN:
  358. case ISCSI_PARAM_HDRDGST_EN:
  359. case ISCSI_PARAM_DATADGST_EN:
  360. case ISCSI_PARAM_INITIAL_R2T_EN:
  361. case ISCSI_PARAM_IMM_DATA_EN:
  362. case ISCSI_PARAM_PDU_INORDER_EN:
  363. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  364. case ISCSI_PARAM_MAX_SEGMENT_SIZE:
  365. case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
  366. case ISCSI_PARAM_TCP_WSF_DISABLE:
  367. case ISCSI_PARAM_TCP_NAGLE_DISABLE:
  368. case ISCSI_PARAM_TCP_TIMER_SCALE:
  369. case ISCSI_PARAM_TCP_TIMESTAMP_EN:
  370. case ISCSI_PARAM_TCP_XMIT_WSF:
  371. case ISCSI_PARAM_TCP_RECV_WSF:
  372. case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
  373. case ISCSI_PARAM_IPV4_TOS:
  374. case ISCSI_PARAM_IPV6_TC:
  375. case ISCSI_PARAM_IPV6_FLOW_LABEL:
  376. case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
  377. case ISCSI_PARAM_KEEPALIVE_TMO:
  378. case ISCSI_PARAM_LOCAL_PORT:
  379. case ISCSI_PARAM_ISID:
  380. case ISCSI_PARAM_TSID:
  381. case ISCSI_PARAM_DEF_TASKMGMT_TMO:
  382. case ISCSI_PARAM_ERL:
  383. case ISCSI_PARAM_STATSN:
  384. case ISCSI_PARAM_EXP_STATSN:
  385. case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
  386. case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
  387. return S_IRUGO;
  388. default:
  389. return 0;
  390. }
  391. case ISCSI_NET_PARAM:
  392. switch (param) {
  393. case ISCSI_NET_PARAM_IPV4_ADDR:
  394. case ISCSI_NET_PARAM_IPV4_SUBNET:
  395. case ISCSI_NET_PARAM_IPV4_GW:
  396. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  397. case ISCSI_NET_PARAM_IFACE_ENABLE:
  398. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  399. case ISCSI_NET_PARAM_IPV6_ADDR:
  400. case ISCSI_NET_PARAM_IPV6_ROUTER:
  401. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  402. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  403. case ISCSI_NET_PARAM_VLAN_ID:
  404. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  405. case ISCSI_NET_PARAM_VLAN_ENABLED:
  406. case ISCSI_NET_PARAM_MTU:
  407. case ISCSI_NET_PARAM_PORT:
  408. return S_IRUGO;
  409. default:
  410. return 0;
  411. }
  412. case ISCSI_FLASHNODE_PARAM:
  413. switch (param) {
  414. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  415. case ISCSI_FLASHNODE_PORTAL_TYPE:
  416. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  417. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  418. case ISCSI_FLASHNODE_ENTRY_EN:
  419. case ISCSI_FLASHNODE_HDR_DGST_EN:
  420. case ISCSI_FLASHNODE_DATA_DGST_EN:
  421. case ISCSI_FLASHNODE_IMM_DATA_EN:
  422. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  423. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  424. case ISCSI_FLASHNODE_PDU_INORDER:
  425. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  426. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  427. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  428. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  429. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  430. case ISCSI_FLASHNODE_ERL:
  431. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  432. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  433. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  434. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  435. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  436. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  437. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  438. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  439. case ISCSI_FLASHNODE_FIRST_BURST:
  440. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  441. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  442. case ISCSI_FLASHNODE_MAX_R2T:
  443. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  444. case ISCSI_FLASHNODE_ISID:
  445. case ISCSI_FLASHNODE_TSID:
  446. case ISCSI_FLASHNODE_PORT:
  447. case ISCSI_FLASHNODE_MAX_BURST:
  448. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  449. case ISCSI_FLASHNODE_IPADDR:
  450. case ISCSI_FLASHNODE_ALIAS:
  451. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  452. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  453. case ISCSI_FLASHNODE_LOCAL_PORT:
  454. case ISCSI_FLASHNODE_IPV4_TOS:
  455. case ISCSI_FLASHNODE_IPV6_TC:
  456. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  457. case ISCSI_FLASHNODE_NAME:
  458. case ISCSI_FLASHNODE_TPGT:
  459. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  460. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  461. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  462. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  463. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  464. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  465. case ISCSI_FLASHNODE_USERNAME:
  466. case ISCSI_FLASHNODE_PASSWORD:
  467. case ISCSI_FLASHNODE_STATSN:
  468. case ISCSI_FLASHNODE_EXP_STATSN:
  469. case ISCSI_FLASHNODE_IS_BOOT_TGT:
  470. return S_IRUGO;
  471. default:
  472. return 0;
  473. }
  474. }
  475. return 0;
  476. }
  477. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  478. uint32_t *num_entries, char *buf)
  479. {
  480. struct scsi_qla_host *ha = to_qla_host(shost);
  481. struct ql4_chap_table *chap_table;
  482. struct iscsi_chap_rec *chap_rec;
  483. int max_chap_entries = 0;
  484. int valid_chap_entries = 0;
  485. int ret = 0, i;
  486. if (is_qla80XX(ha))
  487. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  488. sizeof(struct ql4_chap_table);
  489. else
  490. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  491. ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
  492. __func__, *num_entries, chap_tbl_idx);
  493. if (!buf) {
  494. ret = -ENOMEM;
  495. goto exit_get_chap_list;
  496. }
  497. chap_rec = (struct iscsi_chap_rec *) buf;
  498. mutex_lock(&ha->chap_sem);
  499. for (i = chap_tbl_idx; i < max_chap_entries; i++) {
  500. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  501. if (chap_table->cookie !=
  502. __constant_cpu_to_le16(CHAP_VALID_COOKIE))
  503. continue;
  504. chap_rec->chap_tbl_idx = i;
  505. strncpy(chap_rec->username, chap_table->name,
  506. ISCSI_CHAP_AUTH_NAME_MAX_LEN);
  507. strncpy(chap_rec->password, chap_table->secret,
  508. QL4_CHAP_MAX_SECRET_LEN);
  509. chap_rec->password_length = chap_table->secret_len;
  510. if (chap_table->flags & BIT_7) /* local */
  511. chap_rec->chap_type = CHAP_TYPE_OUT;
  512. if (chap_table->flags & BIT_6) /* peer */
  513. chap_rec->chap_type = CHAP_TYPE_IN;
  514. chap_rec++;
  515. valid_chap_entries++;
  516. if (valid_chap_entries == *num_entries)
  517. break;
  518. else
  519. continue;
  520. }
  521. mutex_unlock(&ha->chap_sem);
  522. exit_get_chap_list:
  523. ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
  524. __func__, valid_chap_entries);
  525. *num_entries = valid_chap_entries;
  526. return ret;
  527. }
  528. static int __qla4xxx_is_chap_active(struct device *dev, void *data)
  529. {
  530. int ret = 0;
  531. uint16_t *chap_tbl_idx = (uint16_t *) data;
  532. struct iscsi_cls_session *cls_session;
  533. struct iscsi_session *sess;
  534. struct ddb_entry *ddb_entry;
  535. if (!iscsi_is_session_dev(dev))
  536. goto exit_is_chap_active;
  537. cls_session = iscsi_dev_to_session(dev);
  538. sess = cls_session->dd_data;
  539. ddb_entry = sess->dd_data;
  540. if (iscsi_session_chkready(cls_session))
  541. goto exit_is_chap_active;
  542. if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
  543. ret = 1;
  544. exit_is_chap_active:
  545. return ret;
  546. }
  547. static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
  548. uint16_t chap_tbl_idx)
  549. {
  550. int ret = 0;
  551. ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
  552. __qla4xxx_is_chap_active);
  553. return ret;
  554. }
  555. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
  556. {
  557. struct scsi_qla_host *ha = to_qla_host(shost);
  558. struct ql4_chap_table *chap_table;
  559. dma_addr_t chap_dma;
  560. int max_chap_entries = 0;
  561. uint32_t offset = 0;
  562. uint32_t chap_size;
  563. int ret = 0;
  564. chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
  565. if (chap_table == NULL)
  566. return -ENOMEM;
  567. memset(chap_table, 0, sizeof(struct ql4_chap_table));
  568. if (is_qla80XX(ha))
  569. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  570. sizeof(struct ql4_chap_table);
  571. else
  572. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  573. if (chap_tbl_idx > max_chap_entries) {
  574. ret = -EINVAL;
  575. goto exit_delete_chap;
  576. }
  577. /* Check if chap index is in use.
  578. * If chap is in use don't delet chap entry */
  579. ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
  580. if (ret) {
  581. ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
  582. "delete from flash\n", chap_tbl_idx);
  583. ret = -EBUSY;
  584. goto exit_delete_chap;
  585. }
  586. chap_size = sizeof(struct ql4_chap_table);
  587. if (is_qla40XX(ha))
  588. offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
  589. else {
  590. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  591. /* flt_chap_size is CHAP table size for both ports
  592. * so divide it by 2 to calculate the offset for second port
  593. */
  594. if (ha->port_num == 1)
  595. offset += (ha->hw.flt_chap_size / 2);
  596. offset += (chap_tbl_idx * chap_size);
  597. }
  598. ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  599. if (ret != QLA_SUCCESS) {
  600. ret = -EINVAL;
  601. goto exit_delete_chap;
  602. }
  603. DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
  604. __le16_to_cpu(chap_table->cookie)));
  605. if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
  606. ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
  607. goto exit_delete_chap;
  608. }
  609. chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
  610. offset = FLASH_CHAP_OFFSET |
  611. (chap_tbl_idx * sizeof(struct ql4_chap_table));
  612. ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
  613. FLASH_OPT_RMW_COMMIT);
  614. if (ret == QLA_SUCCESS && ha->chap_list) {
  615. mutex_lock(&ha->chap_sem);
  616. /* Update ha chap_list cache */
  617. memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
  618. chap_table, sizeof(struct ql4_chap_table));
  619. mutex_unlock(&ha->chap_sem);
  620. }
  621. if (ret != QLA_SUCCESS)
  622. ret = -EINVAL;
  623. exit_delete_chap:
  624. dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
  625. return ret;
  626. }
  627. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  628. enum iscsi_param_type param_type,
  629. int param, char *buf)
  630. {
  631. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  632. struct scsi_qla_host *ha = to_qla_host(shost);
  633. int len = -ENOSYS;
  634. if (param_type != ISCSI_NET_PARAM)
  635. return -ENOSYS;
  636. switch (param) {
  637. case ISCSI_NET_PARAM_IPV4_ADDR:
  638. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  639. break;
  640. case ISCSI_NET_PARAM_IPV4_SUBNET:
  641. len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
  642. break;
  643. case ISCSI_NET_PARAM_IPV4_GW:
  644. len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
  645. break;
  646. case ISCSI_NET_PARAM_IFACE_ENABLE:
  647. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  648. len = sprintf(buf, "%s\n",
  649. (ha->ip_config.ipv4_options &
  650. IPOPT_IPV4_PROTOCOL_ENABLE) ?
  651. "enabled" : "disabled");
  652. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  653. len = sprintf(buf, "%s\n",
  654. (ha->ip_config.ipv6_options &
  655. IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
  656. "enabled" : "disabled");
  657. break;
  658. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  659. len = sprintf(buf, "%s\n",
  660. (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
  661. "dhcp" : "static");
  662. break;
  663. case ISCSI_NET_PARAM_IPV6_ADDR:
  664. if (iface->iface_num == 0)
  665. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
  666. if (iface->iface_num == 1)
  667. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
  668. break;
  669. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  670. len = sprintf(buf, "%pI6\n",
  671. &ha->ip_config.ipv6_link_local_addr);
  672. break;
  673. case ISCSI_NET_PARAM_IPV6_ROUTER:
  674. len = sprintf(buf, "%pI6\n",
  675. &ha->ip_config.ipv6_default_router_addr);
  676. break;
  677. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  678. len = sprintf(buf, "%s\n",
  679. (ha->ip_config.ipv6_addl_options &
  680. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
  681. "nd" : "static");
  682. break;
  683. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  684. len = sprintf(buf, "%s\n",
  685. (ha->ip_config.ipv6_addl_options &
  686. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
  687. "auto" : "static");
  688. break;
  689. case ISCSI_NET_PARAM_VLAN_ID:
  690. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  691. len = sprintf(buf, "%d\n",
  692. (ha->ip_config.ipv4_vlan_tag &
  693. ISCSI_MAX_VLAN_ID));
  694. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  695. len = sprintf(buf, "%d\n",
  696. (ha->ip_config.ipv6_vlan_tag &
  697. ISCSI_MAX_VLAN_ID));
  698. break;
  699. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  700. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  701. len = sprintf(buf, "%d\n",
  702. ((ha->ip_config.ipv4_vlan_tag >> 13) &
  703. ISCSI_MAX_VLAN_PRIORITY));
  704. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  705. len = sprintf(buf, "%d\n",
  706. ((ha->ip_config.ipv6_vlan_tag >> 13) &
  707. ISCSI_MAX_VLAN_PRIORITY));
  708. break;
  709. case ISCSI_NET_PARAM_VLAN_ENABLED:
  710. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  711. len = sprintf(buf, "%s\n",
  712. (ha->ip_config.ipv4_options &
  713. IPOPT_VLAN_TAGGING_ENABLE) ?
  714. "enabled" : "disabled");
  715. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  716. len = sprintf(buf, "%s\n",
  717. (ha->ip_config.ipv6_options &
  718. IPV6_OPT_VLAN_TAGGING_ENABLE) ?
  719. "enabled" : "disabled");
  720. break;
  721. case ISCSI_NET_PARAM_MTU:
  722. len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
  723. break;
  724. case ISCSI_NET_PARAM_PORT:
  725. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  726. len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
  727. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  728. len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
  729. break;
  730. default:
  731. len = -ENOSYS;
  732. }
  733. return len;
  734. }
  735. static struct iscsi_endpoint *
  736. qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  737. int non_blocking)
  738. {
  739. int ret;
  740. struct iscsi_endpoint *ep;
  741. struct qla_endpoint *qla_ep;
  742. struct scsi_qla_host *ha;
  743. struct sockaddr_in *addr;
  744. struct sockaddr_in6 *addr6;
  745. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  746. if (!shost) {
  747. ret = -ENXIO;
  748. printk(KERN_ERR "%s: shost is NULL\n",
  749. __func__);
  750. return ERR_PTR(ret);
  751. }
  752. ha = iscsi_host_priv(shost);
  753. ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
  754. if (!ep) {
  755. ret = -ENOMEM;
  756. return ERR_PTR(ret);
  757. }
  758. qla_ep = ep->dd_data;
  759. memset(qla_ep, 0, sizeof(struct qla_endpoint));
  760. if (dst_addr->sa_family == AF_INET) {
  761. memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
  762. addr = (struct sockaddr_in *)&qla_ep->dst_addr;
  763. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
  764. (char *)&addr->sin_addr));
  765. } else if (dst_addr->sa_family == AF_INET6) {
  766. memcpy(&qla_ep->dst_addr, dst_addr,
  767. sizeof(struct sockaddr_in6));
  768. addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
  769. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
  770. (char *)&addr6->sin6_addr));
  771. }
  772. qla_ep->host = shost;
  773. return ep;
  774. }
  775. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  776. {
  777. struct qla_endpoint *qla_ep;
  778. struct scsi_qla_host *ha;
  779. int ret = 0;
  780. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  781. qla_ep = ep->dd_data;
  782. ha = to_qla_host(qla_ep->host);
  783. if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
  784. ret = 1;
  785. return ret;
  786. }
  787. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
  788. {
  789. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  790. iscsi_destroy_endpoint(ep);
  791. }
  792. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  793. enum iscsi_param param,
  794. char *buf)
  795. {
  796. struct qla_endpoint *qla_ep = ep->dd_data;
  797. struct sockaddr *dst_addr;
  798. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  799. switch (param) {
  800. case ISCSI_PARAM_CONN_PORT:
  801. case ISCSI_PARAM_CONN_ADDRESS:
  802. if (!qla_ep)
  803. return -ENOTCONN;
  804. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  805. if (!dst_addr)
  806. return -ENOTCONN;
  807. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  808. &qla_ep->dst_addr, param, buf);
  809. default:
  810. return -ENOSYS;
  811. }
  812. }
  813. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  814. struct iscsi_stats *stats)
  815. {
  816. struct iscsi_session *sess;
  817. struct iscsi_cls_session *cls_sess;
  818. struct ddb_entry *ddb_entry;
  819. struct scsi_qla_host *ha;
  820. struct ql_iscsi_stats *ql_iscsi_stats;
  821. int stats_size;
  822. int ret;
  823. dma_addr_t iscsi_stats_dma;
  824. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  825. cls_sess = iscsi_conn_to_session(cls_conn);
  826. sess = cls_sess->dd_data;
  827. ddb_entry = sess->dd_data;
  828. ha = ddb_entry->ha;
  829. stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
  830. /* Allocate memory */
  831. ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
  832. &iscsi_stats_dma, GFP_KERNEL);
  833. if (!ql_iscsi_stats) {
  834. ql4_printk(KERN_ERR, ha,
  835. "Unable to allocate memory for iscsi stats\n");
  836. goto exit_get_stats;
  837. }
  838. ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
  839. iscsi_stats_dma);
  840. if (ret != QLA_SUCCESS) {
  841. ql4_printk(KERN_ERR, ha,
  842. "Unable to retrieve iscsi stats\n");
  843. goto free_stats;
  844. }
  845. /* octets */
  846. stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
  847. stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
  848. /* xmit pdus */
  849. stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
  850. stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
  851. stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
  852. stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
  853. stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
  854. stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
  855. stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
  856. stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
  857. /* recv pdus */
  858. stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
  859. stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
  860. stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
  861. stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
  862. stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
  863. stats->logoutrsp_pdus =
  864. le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
  865. stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
  866. stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
  867. stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
  868. free_stats:
  869. dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
  870. iscsi_stats_dma);
  871. exit_get_stats:
  872. return;
  873. }
  874. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  875. {
  876. struct iscsi_cls_session *session;
  877. struct iscsi_session *sess;
  878. unsigned long flags;
  879. enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
  880. session = starget_to_session(scsi_target(sc->device));
  881. sess = session->dd_data;
  882. spin_lock_irqsave(&session->lock, flags);
  883. if (session->state == ISCSI_SESSION_FAILED)
  884. ret = BLK_EH_RESET_TIMER;
  885. spin_unlock_irqrestore(&session->lock, flags);
  886. return ret;
  887. }
  888. static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
  889. {
  890. struct scsi_qla_host *ha = to_qla_host(shost);
  891. struct iscsi_cls_host *ihost = shost->shost_data;
  892. uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
  893. qla4xxx_get_firmware_state(ha);
  894. switch (ha->addl_fw_state & 0x0F00) {
  895. case FW_ADDSTATE_LINK_SPEED_10MBPS:
  896. speed = ISCSI_PORT_SPEED_10MBPS;
  897. break;
  898. case FW_ADDSTATE_LINK_SPEED_100MBPS:
  899. speed = ISCSI_PORT_SPEED_100MBPS;
  900. break;
  901. case FW_ADDSTATE_LINK_SPEED_1GBPS:
  902. speed = ISCSI_PORT_SPEED_1GBPS;
  903. break;
  904. case FW_ADDSTATE_LINK_SPEED_10GBPS:
  905. speed = ISCSI_PORT_SPEED_10GBPS;
  906. break;
  907. }
  908. ihost->port_speed = speed;
  909. }
  910. static void qla4xxx_set_port_state(struct Scsi_Host *shost)
  911. {
  912. struct scsi_qla_host *ha = to_qla_host(shost);
  913. struct iscsi_cls_host *ihost = shost->shost_data;
  914. uint32_t state = ISCSI_PORT_STATE_DOWN;
  915. if (test_bit(AF_LINK_UP, &ha->flags))
  916. state = ISCSI_PORT_STATE_UP;
  917. ihost->port_state = state;
  918. }
  919. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  920. enum iscsi_host_param param, char *buf)
  921. {
  922. struct scsi_qla_host *ha = to_qla_host(shost);
  923. int len;
  924. switch (param) {
  925. case ISCSI_HOST_PARAM_HWADDRESS:
  926. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  927. break;
  928. case ISCSI_HOST_PARAM_IPADDRESS:
  929. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  930. break;
  931. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  932. len = sprintf(buf, "%s\n", ha->name_string);
  933. break;
  934. case ISCSI_HOST_PARAM_PORT_STATE:
  935. qla4xxx_set_port_state(shost);
  936. len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
  937. break;
  938. case ISCSI_HOST_PARAM_PORT_SPEED:
  939. qla4xxx_set_port_speed(shost);
  940. len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
  941. break;
  942. default:
  943. return -ENOSYS;
  944. }
  945. return len;
  946. }
  947. static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
  948. {
  949. if (ha->iface_ipv4)
  950. return;
  951. /* IPv4 */
  952. ha->iface_ipv4 = iscsi_create_iface(ha->host,
  953. &qla4xxx_iscsi_transport,
  954. ISCSI_IFACE_TYPE_IPV4, 0, 0);
  955. if (!ha->iface_ipv4)
  956. ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
  957. "iface0.\n");
  958. }
  959. static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
  960. {
  961. if (!ha->iface_ipv6_0)
  962. /* IPv6 iface-0 */
  963. ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
  964. &qla4xxx_iscsi_transport,
  965. ISCSI_IFACE_TYPE_IPV6, 0,
  966. 0);
  967. if (!ha->iface_ipv6_0)
  968. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  969. "iface0.\n");
  970. if (!ha->iface_ipv6_1)
  971. /* IPv6 iface-1 */
  972. ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
  973. &qla4xxx_iscsi_transport,
  974. ISCSI_IFACE_TYPE_IPV6, 1,
  975. 0);
  976. if (!ha->iface_ipv6_1)
  977. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  978. "iface1.\n");
  979. }
  980. static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
  981. {
  982. if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
  983. qla4xxx_create_ipv4_iface(ha);
  984. if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
  985. qla4xxx_create_ipv6_iface(ha);
  986. }
  987. static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
  988. {
  989. if (ha->iface_ipv4) {
  990. iscsi_destroy_iface(ha->iface_ipv4);
  991. ha->iface_ipv4 = NULL;
  992. }
  993. }
  994. static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
  995. {
  996. if (ha->iface_ipv6_0) {
  997. iscsi_destroy_iface(ha->iface_ipv6_0);
  998. ha->iface_ipv6_0 = NULL;
  999. }
  1000. if (ha->iface_ipv6_1) {
  1001. iscsi_destroy_iface(ha->iface_ipv6_1);
  1002. ha->iface_ipv6_1 = NULL;
  1003. }
  1004. }
  1005. static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
  1006. {
  1007. qla4xxx_destroy_ipv4_iface(ha);
  1008. qla4xxx_destroy_ipv6_iface(ha);
  1009. }
  1010. static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
  1011. struct iscsi_iface_param_info *iface_param,
  1012. struct addr_ctrl_blk *init_fw_cb)
  1013. {
  1014. /*
  1015. * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
  1016. * iface_num 1 is valid only for IPv6 Addr.
  1017. */
  1018. switch (iface_param->param) {
  1019. case ISCSI_NET_PARAM_IPV6_ADDR:
  1020. if (iface_param->iface_num & 0x1)
  1021. /* IPv6 Addr 1 */
  1022. memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
  1023. sizeof(init_fw_cb->ipv6_addr1));
  1024. else
  1025. /* IPv6 Addr 0 */
  1026. memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
  1027. sizeof(init_fw_cb->ipv6_addr0));
  1028. break;
  1029. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  1030. if (iface_param->iface_num & 0x1)
  1031. break;
  1032. memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
  1033. sizeof(init_fw_cb->ipv6_if_id));
  1034. break;
  1035. case ISCSI_NET_PARAM_IPV6_ROUTER:
  1036. if (iface_param->iface_num & 0x1)
  1037. break;
  1038. memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
  1039. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  1040. break;
  1041. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  1042. /* Autocfg applies to even interface */
  1043. if (iface_param->iface_num & 0x1)
  1044. break;
  1045. if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
  1046. init_fw_cb->ipv6_addtl_opts &=
  1047. cpu_to_le16(
  1048. ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  1049. else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
  1050. init_fw_cb->ipv6_addtl_opts |=
  1051. cpu_to_le16(
  1052. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  1053. else
  1054. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  1055. "IPv6 addr\n");
  1056. break;
  1057. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  1058. /* Autocfg applies to even interface */
  1059. if (iface_param->iface_num & 0x1)
  1060. break;
  1061. if (iface_param->value[0] ==
  1062. ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
  1063. init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
  1064. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  1065. else if (iface_param->value[0] ==
  1066. ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
  1067. init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
  1068. ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  1069. else
  1070. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  1071. "IPv6 linklocal addr\n");
  1072. break;
  1073. case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
  1074. /* Autocfg applies to even interface */
  1075. if (iface_param->iface_num & 0x1)
  1076. break;
  1077. if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
  1078. memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
  1079. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  1080. break;
  1081. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1082. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  1083. init_fw_cb->ipv6_opts |=
  1084. cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
  1085. qla4xxx_create_ipv6_iface(ha);
  1086. } else {
  1087. init_fw_cb->ipv6_opts &=
  1088. cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
  1089. 0xFFFF);
  1090. qla4xxx_destroy_ipv6_iface(ha);
  1091. }
  1092. break;
  1093. case ISCSI_NET_PARAM_VLAN_TAG:
  1094. if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
  1095. break;
  1096. init_fw_cb->ipv6_vlan_tag =
  1097. cpu_to_be16(*(uint16_t *)iface_param->value);
  1098. break;
  1099. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1100. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  1101. init_fw_cb->ipv6_opts |=
  1102. cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
  1103. else
  1104. init_fw_cb->ipv6_opts &=
  1105. cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
  1106. break;
  1107. case ISCSI_NET_PARAM_MTU:
  1108. init_fw_cb->eth_mtu_size =
  1109. cpu_to_le16(*(uint16_t *)iface_param->value);
  1110. break;
  1111. case ISCSI_NET_PARAM_PORT:
  1112. /* Autocfg applies to even interface */
  1113. if (iface_param->iface_num & 0x1)
  1114. break;
  1115. init_fw_cb->ipv6_port =
  1116. cpu_to_le16(*(uint16_t *)iface_param->value);
  1117. break;
  1118. default:
  1119. ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
  1120. iface_param->param);
  1121. break;
  1122. }
  1123. }
  1124. static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
  1125. struct iscsi_iface_param_info *iface_param,
  1126. struct addr_ctrl_blk *init_fw_cb)
  1127. {
  1128. switch (iface_param->param) {
  1129. case ISCSI_NET_PARAM_IPV4_ADDR:
  1130. memcpy(init_fw_cb->ipv4_addr, iface_param->value,
  1131. sizeof(init_fw_cb->ipv4_addr));
  1132. break;
  1133. case ISCSI_NET_PARAM_IPV4_SUBNET:
  1134. memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
  1135. sizeof(init_fw_cb->ipv4_subnet));
  1136. break;
  1137. case ISCSI_NET_PARAM_IPV4_GW:
  1138. memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
  1139. sizeof(init_fw_cb->ipv4_gw_addr));
  1140. break;
  1141. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  1142. if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
  1143. init_fw_cb->ipv4_tcp_opts |=
  1144. cpu_to_le16(TCPOPT_DHCP_ENABLE);
  1145. else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
  1146. init_fw_cb->ipv4_tcp_opts &=
  1147. cpu_to_le16(~TCPOPT_DHCP_ENABLE);
  1148. else
  1149. ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
  1150. break;
  1151. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1152. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  1153. init_fw_cb->ipv4_ip_opts |=
  1154. cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
  1155. qla4xxx_create_ipv4_iface(ha);
  1156. } else {
  1157. init_fw_cb->ipv4_ip_opts &=
  1158. cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
  1159. 0xFFFF);
  1160. qla4xxx_destroy_ipv4_iface(ha);
  1161. }
  1162. break;
  1163. case ISCSI_NET_PARAM_VLAN_TAG:
  1164. if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
  1165. break;
  1166. init_fw_cb->ipv4_vlan_tag =
  1167. cpu_to_be16(*(uint16_t *)iface_param->value);
  1168. break;
  1169. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1170. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  1171. init_fw_cb->ipv4_ip_opts |=
  1172. cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
  1173. else
  1174. init_fw_cb->ipv4_ip_opts &=
  1175. cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
  1176. break;
  1177. case ISCSI_NET_PARAM_MTU:
  1178. init_fw_cb->eth_mtu_size =
  1179. cpu_to_le16(*(uint16_t *)iface_param->value);
  1180. break;
  1181. case ISCSI_NET_PARAM_PORT:
  1182. init_fw_cb->ipv4_port =
  1183. cpu_to_le16(*(uint16_t *)iface_param->value);
  1184. break;
  1185. default:
  1186. ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
  1187. iface_param->param);
  1188. break;
  1189. }
  1190. }
  1191. static void
  1192. qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
  1193. {
  1194. struct addr_ctrl_blk_def *acb;
  1195. acb = (struct addr_ctrl_blk_def *)init_fw_cb;
  1196. memset(acb->reserved1, 0, sizeof(acb->reserved1));
  1197. memset(acb->reserved2, 0, sizeof(acb->reserved2));
  1198. memset(acb->reserved3, 0, sizeof(acb->reserved3));
  1199. memset(acb->reserved4, 0, sizeof(acb->reserved4));
  1200. memset(acb->reserved5, 0, sizeof(acb->reserved5));
  1201. memset(acb->reserved6, 0, sizeof(acb->reserved6));
  1202. memset(acb->reserved7, 0, sizeof(acb->reserved7));
  1203. memset(acb->reserved8, 0, sizeof(acb->reserved8));
  1204. memset(acb->reserved9, 0, sizeof(acb->reserved9));
  1205. memset(acb->reserved10, 0, sizeof(acb->reserved10));
  1206. memset(acb->reserved11, 0, sizeof(acb->reserved11));
  1207. memset(acb->reserved12, 0, sizeof(acb->reserved12));
  1208. memset(acb->reserved13, 0, sizeof(acb->reserved13));
  1209. memset(acb->reserved14, 0, sizeof(acb->reserved14));
  1210. memset(acb->reserved15, 0, sizeof(acb->reserved15));
  1211. }
  1212. static int
  1213. qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
  1214. {
  1215. struct scsi_qla_host *ha = to_qla_host(shost);
  1216. int rval = 0;
  1217. struct iscsi_iface_param_info *iface_param = NULL;
  1218. struct addr_ctrl_blk *init_fw_cb = NULL;
  1219. dma_addr_t init_fw_cb_dma;
  1220. uint32_t mbox_cmd[MBOX_REG_COUNT];
  1221. uint32_t mbox_sts[MBOX_REG_COUNT];
  1222. uint32_t rem = len;
  1223. struct nlattr *attr;
  1224. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  1225. sizeof(struct addr_ctrl_blk),
  1226. &init_fw_cb_dma, GFP_KERNEL);
  1227. if (!init_fw_cb) {
  1228. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
  1229. __func__);
  1230. return -ENOMEM;
  1231. }
  1232. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  1233. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  1234. memset(&mbox_sts, 0, sizeof(mbox_sts));
  1235. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
  1236. ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
  1237. rval = -EIO;
  1238. goto exit_init_fw_cb;
  1239. }
  1240. nla_for_each_attr(attr, data, len, rem) {
  1241. iface_param = nla_data(attr);
  1242. if (iface_param->param_type != ISCSI_NET_PARAM)
  1243. continue;
  1244. switch (iface_param->iface_type) {
  1245. case ISCSI_IFACE_TYPE_IPV4:
  1246. switch (iface_param->iface_num) {
  1247. case 0:
  1248. qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
  1249. break;
  1250. default:
  1251. /* Cannot have more than one IPv4 interface */
  1252. ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
  1253. "number = %d\n",
  1254. iface_param->iface_num);
  1255. break;
  1256. }
  1257. break;
  1258. case ISCSI_IFACE_TYPE_IPV6:
  1259. switch (iface_param->iface_num) {
  1260. case 0:
  1261. case 1:
  1262. qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
  1263. break;
  1264. default:
  1265. /* Cannot have more than two IPv6 interface */
  1266. ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
  1267. "number = %d\n",
  1268. iface_param->iface_num);
  1269. break;
  1270. }
  1271. break;
  1272. default:
  1273. ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
  1274. break;
  1275. }
  1276. }
  1277. init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
  1278. rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
  1279. sizeof(struct addr_ctrl_blk),
  1280. FLASH_OPT_RMW_COMMIT);
  1281. if (rval != QLA_SUCCESS) {
  1282. ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
  1283. __func__);
  1284. rval = -EIO;
  1285. goto exit_init_fw_cb;
  1286. }
  1287. rval = qla4xxx_disable_acb(ha);
  1288. if (rval != QLA_SUCCESS) {
  1289. ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
  1290. __func__);
  1291. rval = -EIO;
  1292. goto exit_init_fw_cb;
  1293. }
  1294. wait_for_completion_timeout(&ha->disable_acb_comp,
  1295. DISABLE_ACB_TOV * HZ);
  1296. qla4xxx_initcb_to_acb(init_fw_cb);
  1297. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
  1298. if (rval != QLA_SUCCESS) {
  1299. ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
  1300. __func__);
  1301. rval = -EIO;
  1302. goto exit_init_fw_cb;
  1303. }
  1304. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  1305. qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
  1306. init_fw_cb_dma);
  1307. exit_init_fw_cb:
  1308. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  1309. init_fw_cb, init_fw_cb_dma);
  1310. return rval;
  1311. }
  1312. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  1313. enum iscsi_param param, char *buf)
  1314. {
  1315. struct iscsi_session *sess = cls_sess->dd_data;
  1316. struct ddb_entry *ddb_entry = sess->dd_data;
  1317. struct scsi_qla_host *ha = ddb_entry->ha;
  1318. int rval, len;
  1319. uint16_t idx;
  1320. switch (param) {
  1321. case ISCSI_PARAM_CHAP_IN_IDX:
  1322. rval = qla4xxx_get_chap_index(ha, sess->username_in,
  1323. sess->password_in, BIDI_CHAP,
  1324. &idx);
  1325. if (rval)
  1326. len = sprintf(buf, "\n");
  1327. else
  1328. len = sprintf(buf, "%hu\n", idx);
  1329. break;
  1330. case ISCSI_PARAM_CHAP_OUT_IDX:
  1331. rval = qla4xxx_get_chap_index(ha, sess->username,
  1332. sess->password, LOCAL_CHAP,
  1333. &idx);
  1334. if (rval)
  1335. len = sprintf(buf, "\n");
  1336. else
  1337. len = sprintf(buf, "%hu\n", idx);
  1338. break;
  1339. default:
  1340. return iscsi_session_get_param(cls_sess, param, buf);
  1341. }
  1342. return len;
  1343. }
  1344. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
  1345. enum iscsi_param param, char *buf)
  1346. {
  1347. struct iscsi_conn *conn;
  1348. struct qla_conn *qla_conn;
  1349. struct sockaddr *dst_addr;
  1350. int len = 0;
  1351. conn = cls_conn->dd_data;
  1352. qla_conn = conn->dd_data;
  1353. dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
  1354. switch (param) {
  1355. case ISCSI_PARAM_CONN_PORT:
  1356. case ISCSI_PARAM_CONN_ADDRESS:
  1357. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  1358. dst_addr, param, buf);
  1359. default:
  1360. return iscsi_conn_get_param(cls_conn, param, buf);
  1361. }
  1362. return len;
  1363. }
  1364. int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
  1365. {
  1366. uint32_t mbx_sts = 0;
  1367. uint16_t tmp_ddb_index;
  1368. int ret;
  1369. get_ddb_index:
  1370. tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
  1371. if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
  1372. DEBUG2(ql4_printk(KERN_INFO, ha,
  1373. "Free DDB index not available\n"));
  1374. ret = QLA_ERROR;
  1375. goto exit_get_ddb_index;
  1376. }
  1377. if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
  1378. goto get_ddb_index;
  1379. DEBUG2(ql4_printk(KERN_INFO, ha,
  1380. "Found a free DDB index at %d\n", tmp_ddb_index));
  1381. ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
  1382. if (ret == QLA_ERROR) {
  1383. if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
  1384. ql4_printk(KERN_INFO, ha,
  1385. "DDB index = %d not available trying next\n",
  1386. tmp_ddb_index);
  1387. goto get_ddb_index;
  1388. }
  1389. DEBUG2(ql4_printk(KERN_INFO, ha,
  1390. "Free FW DDB not available\n"));
  1391. }
  1392. *ddb_index = tmp_ddb_index;
  1393. exit_get_ddb_index:
  1394. return ret;
  1395. }
  1396. static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
  1397. struct ddb_entry *ddb_entry,
  1398. char *existing_ipaddr,
  1399. char *user_ipaddr)
  1400. {
  1401. uint8_t dst_ipaddr[IPv6_ADDR_LEN];
  1402. char formatted_ipaddr[DDB_IPADDR_LEN];
  1403. int status = QLA_SUCCESS, ret = 0;
  1404. if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
  1405. ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  1406. '\0', NULL);
  1407. if (ret == 0) {
  1408. status = QLA_ERROR;
  1409. goto out_match;
  1410. }
  1411. ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
  1412. } else {
  1413. ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  1414. '\0', NULL);
  1415. if (ret == 0) {
  1416. status = QLA_ERROR;
  1417. goto out_match;
  1418. }
  1419. ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
  1420. }
  1421. if (strcmp(existing_ipaddr, formatted_ipaddr))
  1422. status = QLA_ERROR;
  1423. out_match:
  1424. return status;
  1425. }
  1426. static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
  1427. struct iscsi_cls_conn *cls_conn)
  1428. {
  1429. int idx = 0, max_ddbs, rval;
  1430. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1431. struct iscsi_session *sess, *existing_sess;
  1432. struct iscsi_conn *conn, *existing_conn;
  1433. struct ddb_entry *ddb_entry;
  1434. sess = cls_sess->dd_data;
  1435. conn = cls_conn->dd_data;
  1436. if (sess->targetname == NULL ||
  1437. conn->persistent_address == NULL ||
  1438. conn->persistent_port == 0)
  1439. return QLA_ERROR;
  1440. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  1441. MAX_DEV_DB_ENTRIES;
  1442. for (idx = 0; idx < max_ddbs; idx++) {
  1443. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  1444. if (ddb_entry == NULL)
  1445. continue;
  1446. if (ddb_entry->ddb_type != FLASH_DDB)
  1447. continue;
  1448. existing_sess = ddb_entry->sess->dd_data;
  1449. existing_conn = ddb_entry->conn->dd_data;
  1450. if (existing_sess->targetname == NULL ||
  1451. existing_conn->persistent_address == NULL ||
  1452. existing_conn->persistent_port == 0)
  1453. continue;
  1454. DEBUG2(ql4_printk(KERN_INFO, ha,
  1455. "IQN = %s User IQN = %s\n",
  1456. existing_sess->targetname,
  1457. sess->targetname));
  1458. DEBUG2(ql4_printk(KERN_INFO, ha,
  1459. "IP = %s User IP = %s\n",
  1460. existing_conn->persistent_address,
  1461. conn->persistent_address));
  1462. DEBUG2(ql4_printk(KERN_INFO, ha,
  1463. "Port = %d User Port = %d\n",
  1464. existing_conn->persistent_port,
  1465. conn->persistent_port));
  1466. if (strcmp(existing_sess->targetname, sess->targetname))
  1467. continue;
  1468. rval = qla4xxx_match_ipaddress(ha, ddb_entry,
  1469. existing_conn->persistent_address,
  1470. conn->persistent_address);
  1471. if (rval == QLA_ERROR)
  1472. continue;
  1473. if (existing_conn->persistent_port != conn->persistent_port)
  1474. continue;
  1475. break;
  1476. }
  1477. if (idx == max_ddbs)
  1478. return QLA_ERROR;
  1479. DEBUG2(ql4_printk(KERN_INFO, ha,
  1480. "Match found in fwdb sessions\n"));
  1481. return QLA_SUCCESS;
  1482. }
  1483. static struct iscsi_cls_session *
  1484. qla4xxx_session_create(struct iscsi_endpoint *ep,
  1485. uint16_t cmds_max, uint16_t qdepth,
  1486. uint32_t initial_cmdsn)
  1487. {
  1488. struct iscsi_cls_session *cls_sess;
  1489. struct scsi_qla_host *ha;
  1490. struct qla_endpoint *qla_ep;
  1491. struct ddb_entry *ddb_entry;
  1492. uint16_t ddb_index;
  1493. struct iscsi_session *sess;
  1494. struct sockaddr *dst_addr;
  1495. int ret;
  1496. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1497. if (!ep) {
  1498. printk(KERN_ERR "qla4xxx: missing ep.\n");
  1499. return NULL;
  1500. }
  1501. qla_ep = ep->dd_data;
  1502. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  1503. ha = to_qla_host(qla_ep->host);
  1504. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  1505. if (ret == QLA_ERROR)
  1506. return NULL;
  1507. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
  1508. cmds_max, sizeof(struct ddb_entry),
  1509. sizeof(struct ql4_task_data),
  1510. initial_cmdsn, ddb_index);
  1511. if (!cls_sess)
  1512. return NULL;
  1513. sess = cls_sess->dd_data;
  1514. ddb_entry = sess->dd_data;
  1515. ddb_entry->fw_ddb_index = ddb_index;
  1516. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  1517. ddb_entry->ha = ha;
  1518. ddb_entry->sess = cls_sess;
  1519. ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
  1520. ddb_entry->ddb_change = qla4xxx_ddb_change;
  1521. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  1522. ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
  1523. ha->tot_ddbs++;
  1524. return cls_sess;
  1525. }
  1526. static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
  1527. {
  1528. struct iscsi_session *sess;
  1529. struct ddb_entry *ddb_entry;
  1530. struct scsi_qla_host *ha;
  1531. unsigned long flags, wtime;
  1532. struct dev_db_entry *fw_ddb_entry = NULL;
  1533. dma_addr_t fw_ddb_entry_dma;
  1534. uint32_t ddb_state;
  1535. int ret;
  1536. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1537. sess = cls_sess->dd_data;
  1538. ddb_entry = sess->dd_data;
  1539. ha = ddb_entry->ha;
  1540. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1541. &fw_ddb_entry_dma, GFP_KERNEL);
  1542. if (!fw_ddb_entry) {
  1543. ql4_printk(KERN_ERR, ha,
  1544. "%s: Unable to allocate dma buffer\n", __func__);
  1545. goto destroy_session;
  1546. }
  1547. wtime = jiffies + (HZ * LOGOUT_TOV);
  1548. do {
  1549. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  1550. fw_ddb_entry, fw_ddb_entry_dma,
  1551. NULL, NULL, &ddb_state, NULL,
  1552. NULL, NULL);
  1553. if (ret == QLA_ERROR)
  1554. goto destroy_session;
  1555. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  1556. (ddb_state == DDB_DS_SESSION_FAILED))
  1557. goto destroy_session;
  1558. schedule_timeout_uninterruptible(HZ);
  1559. } while ((time_after(wtime, jiffies)));
  1560. destroy_session:
  1561. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  1562. spin_lock_irqsave(&ha->hardware_lock, flags);
  1563. qla4xxx_free_ddb(ha, ddb_entry);
  1564. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1565. iscsi_session_teardown(cls_sess);
  1566. if (fw_ddb_entry)
  1567. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1568. fw_ddb_entry, fw_ddb_entry_dma);
  1569. }
  1570. static struct iscsi_cls_conn *
  1571. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
  1572. {
  1573. struct iscsi_cls_conn *cls_conn;
  1574. struct iscsi_session *sess;
  1575. struct ddb_entry *ddb_entry;
  1576. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1577. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
  1578. conn_idx);
  1579. if (!cls_conn)
  1580. return NULL;
  1581. sess = cls_sess->dd_data;
  1582. ddb_entry = sess->dd_data;
  1583. ddb_entry->conn = cls_conn;
  1584. return cls_conn;
  1585. }
  1586. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  1587. struct iscsi_cls_conn *cls_conn,
  1588. uint64_t transport_fd, int is_leading)
  1589. {
  1590. struct iscsi_conn *conn;
  1591. struct qla_conn *qla_conn;
  1592. struct iscsi_endpoint *ep;
  1593. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1594. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  1595. return -EINVAL;
  1596. ep = iscsi_lookup_endpoint(transport_fd);
  1597. conn = cls_conn->dd_data;
  1598. qla_conn = conn->dd_data;
  1599. qla_conn->qla_ep = ep->dd_data;
  1600. return 0;
  1601. }
  1602. static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
  1603. {
  1604. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1605. struct iscsi_session *sess;
  1606. struct ddb_entry *ddb_entry;
  1607. struct scsi_qla_host *ha;
  1608. struct dev_db_entry *fw_ddb_entry = NULL;
  1609. dma_addr_t fw_ddb_entry_dma;
  1610. uint32_t mbx_sts = 0;
  1611. int ret = 0;
  1612. int status = QLA_SUCCESS;
  1613. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1614. sess = cls_sess->dd_data;
  1615. ddb_entry = sess->dd_data;
  1616. ha = ddb_entry->ha;
  1617. /* Check if we have matching FW DDB, if yes then do not
  1618. * login to this target. This could cause target to logout previous
  1619. * connection
  1620. */
  1621. ret = qla4xxx_match_fwdb_session(ha, cls_conn);
  1622. if (ret == QLA_SUCCESS) {
  1623. ql4_printk(KERN_INFO, ha,
  1624. "Session already exist in FW.\n");
  1625. ret = -EEXIST;
  1626. goto exit_conn_start;
  1627. }
  1628. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1629. &fw_ddb_entry_dma, GFP_KERNEL);
  1630. if (!fw_ddb_entry) {
  1631. ql4_printk(KERN_ERR, ha,
  1632. "%s: Unable to allocate dma buffer\n", __func__);
  1633. ret = -ENOMEM;
  1634. goto exit_conn_start;
  1635. }
  1636. ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
  1637. if (ret) {
  1638. /* If iscsid is stopped and started then no need to do
  1639. * set param again since ddb state will be already
  1640. * active and FW does not allow set ddb to an
  1641. * active session.
  1642. */
  1643. if (mbx_sts)
  1644. if (ddb_entry->fw_ddb_device_state ==
  1645. DDB_DS_SESSION_ACTIVE) {
  1646. ddb_entry->unblock_sess(ddb_entry->sess);
  1647. goto exit_set_param;
  1648. }
  1649. ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
  1650. __func__, ddb_entry->fw_ddb_index);
  1651. goto exit_conn_start;
  1652. }
  1653. status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
  1654. if (status == QLA_ERROR) {
  1655. ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
  1656. sess->targetname);
  1657. ret = -EINVAL;
  1658. goto exit_conn_start;
  1659. }
  1660. if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
  1661. ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
  1662. DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
  1663. ddb_entry->fw_ddb_device_state));
  1664. exit_set_param:
  1665. ret = 0;
  1666. exit_conn_start:
  1667. if (fw_ddb_entry)
  1668. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1669. fw_ddb_entry, fw_ddb_entry_dma);
  1670. return ret;
  1671. }
  1672. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
  1673. {
  1674. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1675. struct iscsi_session *sess;
  1676. struct scsi_qla_host *ha;
  1677. struct ddb_entry *ddb_entry;
  1678. int options;
  1679. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1680. sess = cls_sess->dd_data;
  1681. ddb_entry = sess->dd_data;
  1682. ha = ddb_entry->ha;
  1683. options = LOGOUT_OPTION_CLOSE_SESSION;
  1684. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
  1685. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  1686. }
  1687. static void qla4xxx_task_work(struct work_struct *wdata)
  1688. {
  1689. struct ql4_task_data *task_data;
  1690. struct scsi_qla_host *ha;
  1691. struct passthru_status *sts;
  1692. struct iscsi_task *task;
  1693. struct iscsi_hdr *hdr;
  1694. uint8_t *data;
  1695. uint32_t data_len;
  1696. struct iscsi_conn *conn;
  1697. int hdr_len;
  1698. itt_t itt;
  1699. task_data = container_of(wdata, struct ql4_task_data, task_work);
  1700. ha = task_data->ha;
  1701. task = task_data->task;
  1702. sts = &task_data->sts;
  1703. hdr_len = sizeof(struct iscsi_hdr);
  1704. DEBUG3(printk(KERN_INFO "Status returned\n"));
  1705. DEBUG3(qla4xxx_dump_buffer(sts, 64));
  1706. DEBUG3(printk(KERN_INFO "Response buffer"));
  1707. DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
  1708. conn = task->conn;
  1709. switch (sts->completionStatus) {
  1710. case PASSTHRU_STATUS_COMPLETE:
  1711. hdr = (struct iscsi_hdr *)task_data->resp_buffer;
  1712. /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
  1713. itt = sts->handle;
  1714. hdr->itt = itt;
  1715. data = task_data->resp_buffer + hdr_len;
  1716. data_len = task_data->resp_len - hdr_len;
  1717. iscsi_complete_pdu(conn, hdr, data, data_len);
  1718. break;
  1719. default:
  1720. ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
  1721. sts->completionStatus);
  1722. break;
  1723. }
  1724. return;
  1725. }
  1726. static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  1727. {
  1728. struct ql4_task_data *task_data;
  1729. struct iscsi_session *sess;
  1730. struct ddb_entry *ddb_entry;
  1731. struct scsi_qla_host *ha;
  1732. int hdr_len;
  1733. sess = task->conn->session;
  1734. ddb_entry = sess->dd_data;
  1735. ha = ddb_entry->ha;
  1736. task_data = task->dd_data;
  1737. memset(task_data, 0, sizeof(struct ql4_task_data));
  1738. if (task->sc) {
  1739. ql4_printk(KERN_INFO, ha,
  1740. "%s: SCSI Commands not implemented\n", __func__);
  1741. return -EINVAL;
  1742. }
  1743. hdr_len = sizeof(struct iscsi_hdr);
  1744. task_data->ha = ha;
  1745. task_data->task = task;
  1746. if (task->data_count) {
  1747. task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
  1748. task->data_count,
  1749. PCI_DMA_TODEVICE);
  1750. }
  1751. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1752. __func__, task->conn->max_recv_dlength, hdr_len));
  1753. task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
  1754. task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1755. task_data->resp_len,
  1756. &task_data->resp_dma,
  1757. GFP_ATOMIC);
  1758. if (!task_data->resp_buffer)
  1759. goto exit_alloc_pdu;
  1760. task_data->req_len = task->data_count + hdr_len;
  1761. task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1762. task_data->req_len,
  1763. &task_data->req_dma,
  1764. GFP_ATOMIC);
  1765. if (!task_data->req_buffer)
  1766. goto exit_alloc_pdu;
  1767. task->hdr = task_data->req_buffer;
  1768. INIT_WORK(&task_data->task_work, qla4xxx_task_work);
  1769. return 0;
  1770. exit_alloc_pdu:
  1771. if (task_data->resp_buffer)
  1772. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1773. task_data->resp_buffer, task_data->resp_dma);
  1774. if (task_data->req_buffer)
  1775. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1776. task_data->req_buffer, task_data->req_dma);
  1777. return -ENOMEM;
  1778. }
  1779. static void qla4xxx_task_cleanup(struct iscsi_task *task)
  1780. {
  1781. struct ql4_task_data *task_data;
  1782. struct iscsi_session *sess;
  1783. struct ddb_entry *ddb_entry;
  1784. struct scsi_qla_host *ha;
  1785. int hdr_len;
  1786. hdr_len = sizeof(struct iscsi_hdr);
  1787. sess = task->conn->session;
  1788. ddb_entry = sess->dd_data;
  1789. ha = ddb_entry->ha;
  1790. task_data = task->dd_data;
  1791. if (task->data_count) {
  1792. dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
  1793. task->data_count, PCI_DMA_TODEVICE);
  1794. }
  1795. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1796. __func__, task->conn->max_recv_dlength, hdr_len));
  1797. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1798. task_data->resp_buffer, task_data->resp_dma);
  1799. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1800. task_data->req_buffer, task_data->req_dma);
  1801. return;
  1802. }
  1803. static int qla4xxx_task_xmit(struct iscsi_task *task)
  1804. {
  1805. struct scsi_cmnd *sc = task->sc;
  1806. struct iscsi_session *sess = task->conn->session;
  1807. struct ddb_entry *ddb_entry = sess->dd_data;
  1808. struct scsi_qla_host *ha = ddb_entry->ha;
  1809. if (!sc)
  1810. return qla4xxx_send_passthru0(task);
  1811. ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
  1812. __func__);
  1813. return -ENOSYS;
  1814. }
  1815. static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
  1816. struct iscsi_bus_flash_conn *conn,
  1817. struct dev_db_entry *fw_ddb_entry)
  1818. {
  1819. unsigned long options = 0;
  1820. int rc = 0;
  1821. options = le16_to_cpu(fw_ddb_entry->options);
  1822. conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
  1823. if (test_bit(OPT_IPV6_DEVICE, &options)) {
  1824. rc = iscsi_switch_str_param(&sess->portal_type,
  1825. PORTAL_TYPE_IPV6);
  1826. if (rc)
  1827. goto exit_copy;
  1828. } else {
  1829. rc = iscsi_switch_str_param(&sess->portal_type,
  1830. PORTAL_TYPE_IPV4);
  1831. if (rc)
  1832. goto exit_copy;
  1833. }
  1834. sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
  1835. &options);
  1836. sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
  1837. sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
  1838. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  1839. conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
  1840. conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
  1841. sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
  1842. sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
  1843. sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
  1844. &options);
  1845. sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
  1846. sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
  1847. conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
  1848. sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
  1849. &options);
  1850. sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
  1851. sess->discovery_auth_optional =
  1852. test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
  1853. if (test_bit(ISCSIOPT_ERL1, &options))
  1854. sess->erl |= BIT_1;
  1855. if (test_bit(ISCSIOPT_ERL0, &options))
  1856. sess->erl |= BIT_0;
  1857. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  1858. conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
  1859. conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
  1860. conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
  1861. if (test_bit(TCPOPT_TIMER_SCALE3, &options))
  1862. conn->tcp_timer_scale |= BIT_3;
  1863. if (test_bit(TCPOPT_TIMER_SCALE2, &options))
  1864. conn->tcp_timer_scale |= BIT_2;
  1865. if (test_bit(TCPOPT_TIMER_SCALE1, &options))
  1866. conn->tcp_timer_scale |= BIT_1;
  1867. conn->tcp_timer_scale >>= 1;
  1868. conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
  1869. options = le16_to_cpu(fw_ddb_entry->ip_options);
  1870. conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
  1871. conn->max_recv_dlength = BYTE_UNITS *
  1872. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  1873. conn->max_xmit_dlength = BYTE_UNITS *
  1874. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  1875. sess->first_burst = BYTE_UNITS *
  1876. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  1877. sess->max_burst = BYTE_UNITS *
  1878. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  1879. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  1880. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1881. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  1882. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  1883. conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
  1884. conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
  1885. conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
  1886. conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
  1887. conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
  1888. conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
  1889. conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
  1890. conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
  1891. sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
  1892. sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
  1893. sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  1894. sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
  1895. sess->default_taskmgmt_timeout =
  1896. le16_to_cpu(fw_ddb_entry->def_timeout);
  1897. conn->port = le16_to_cpu(fw_ddb_entry->port);
  1898. options = le16_to_cpu(fw_ddb_entry->options);
  1899. conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
  1900. if (!conn->ipaddress) {
  1901. rc = -ENOMEM;
  1902. goto exit_copy;
  1903. }
  1904. conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
  1905. if (!conn->redirect_ipaddr) {
  1906. rc = -ENOMEM;
  1907. goto exit_copy;
  1908. }
  1909. memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  1910. memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
  1911. if (test_bit(OPT_IPV6_DEVICE, &options)) {
  1912. conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
  1913. conn->link_local_ipv6_addr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
  1914. if (!conn->link_local_ipv6_addr) {
  1915. rc = -ENOMEM;
  1916. goto exit_copy;
  1917. }
  1918. memcpy(conn->link_local_ipv6_addr,
  1919. fw_ddb_entry->link_local_ipv6_addr, IPv6_ADDR_LEN);
  1920. } else {
  1921. conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
  1922. }
  1923. if (fw_ddb_entry->iscsi_name[0]) {
  1924. rc = iscsi_switch_str_param(&sess->targetname,
  1925. (char *)fw_ddb_entry->iscsi_name);
  1926. if (rc)
  1927. goto exit_copy;
  1928. }
  1929. if (fw_ddb_entry->iscsi_alias[0]) {
  1930. rc = iscsi_switch_str_param(&sess->targetalias,
  1931. (char *)fw_ddb_entry->iscsi_alias);
  1932. if (rc)
  1933. goto exit_copy;
  1934. }
  1935. COPY_ISID(sess->isid, fw_ddb_entry->isid);
  1936. exit_copy:
  1937. return rc;
  1938. }
  1939. static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
  1940. struct iscsi_bus_flash_conn *conn,
  1941. struct dev_db_entry *fw_ddb_entry)
  1942. {
  1943. uint16_t options;
  1944. int rc = 0;
  1945. options = le16_to_cpu(fw_ddb_entry->options);
  1946. SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
  1947. if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
  1948. options |= BIT_8;
  1949. else
  1950. options &= ~BIT_8;
  1951. SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
  1952. SET_BITVAL(sess->discovery_sess, options, BIT_4);
  1953. SET_BITVAL(sess->entry_state, options, BIT_3);
  1954. fw_ddb_entry->options = cpu_to_le16(options);
  1955. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  1956. SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
  1957. SET_BITVAL(conn->datadgst_en, options, BIT_12);
  1958. SET_BITVAL(sess->imm_data_en, options, BIT_11);
  1959. SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
  1960. SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
  1961. SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
  1962. SET_BITVAL(sess->chap_auth_en, options, BIT_7);
  1963. SET_BITVAL(conn->snack_req_en, options, BIT_6);
  1964. SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
  1965. SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
  1966. SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
  1967. SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
  1968. SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
  1969. fw_ddb_entry->iscsi_options = cpu_to_le16(options);
  1970. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  1971. SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
  1972. SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
  1973. SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
  1974. SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
  1975. SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
  1976. SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
  1977. SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
  1978. fw_ddb_entry->tcp_options = cpu_to_le16(options);
  1979. options = le16_to_cpu(fw_ddb_entry->ip_options);
  1980. SET_BITVAL(conn->fragment_disable, options, BIT_4);
  1981. fw_ddb_entry->ip_options = cpu_to_le16(options);
  1982. fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
  1983. fw_ddb_entry->iscsi_max_rcv_data_seg_len =
  1984. cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
  1985. fw_ddb_entry->iscsi_max_snd_data_seg_len =
  1986. cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
  1987. fw_ddb_entry->iscsi_first_burst_len =
  1988. cpu_to_le16(sess->first_burst / BYTE_UNITS);
  1989. fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
  1990. BYTE_UNITS);
  1991. fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
  1992. fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
  1993. fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
  1994. fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
  1995. fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
  1996. fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
  1997. fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
  1998. fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
  1999. fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
  2000. fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
  2001. fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
  2002. fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
  2003. fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
  2004. fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
  2005. fw_ddb_entry->port = cpu_to_le16(conn->port);
  2006. fw_ddb_entry->def_timeout =
  2007. cpu_to_le16(sess->default_taskmgmt_timeout);
  2008. if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
  2009. fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
  2010. else
  2011. fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
  2012. if (conn->ipaddress)
  2013. memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
  2014. sizeof(fw_ddb_entry->ip_addr));
  2015. if (conn->redirect_ipaddr)
  2016. memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
  2017. sizeof(fw_ddb_entry->tgt_addr));
  2018. if (conn->link_local_ipv6_addr)
  2019. memcpy(fw_ddb_entry->link_local_ipv6_addr,
  2020. conn->link_local_ipv6_addr,
  2021. sizeof(fw_ddb_entry->link_local_ipv6_addr));
  2022. if (sess->targetname)
  2023. memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
  2024. sizeof(fw_ddb_entry->iscsi_name));
  2025. if (sess->targetalias)
  2026. memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
  2027. sizeof(fw_ddb_entry->iscsi_alias));
  2028. COPY_ISID(fw_ddb_entry->isid, sess->isid);
  2029. return rc;
  2030. }
  2031. static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
  2032. struct iscsi_session *sess,
  2033. struct dev_db_entry *fw_ddb_entry)
  2034. {
  2035. unsigned long options = 0;
  2036. uint16_t ddb_link;
  2037. uint16_t disc_parent;
  2038. options = le16_to_cpu(fw_ddb_entry->options);
  2039. conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
  2040. sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
  2041. &options);
  2042. sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
  2043. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  2044. conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
  2045. conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
  2046. sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
  2047. sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
  2048. sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
  2049. &options);
  2050. sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
  2051. sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
  2052. sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
  2053. &options);
  2054. sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
  2055. sess->discovery_auth_optional =
  2056. test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
  2057. if (test_bit(ISCSIOPT_ERL1, &options))
  2058. sess->erl |= BIT_1;
  2059. if (test_bit(ISCSIOPT_ERL0, &options))
  2060. sess->erl |= BIT_0;
  2061. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  2062. conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
  2063. conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
  2064. conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
  2065. if (test_bit(TCPOPT_TIMER_SCALE3, &options))
  2066. conn->tcp_timer_scale |= BIT_3;
  2067. if (test_bit(TCPOPT_TIMER_SCALE2, &options))
  2068. conn->tcp_timer_scale |= BIT_2;
  2069. if (test_bit(TCPOPT_TIMER_SCALE1, &options))
  2070. conn->tcp_timer_scale |= BIT_1;
  2071. conn->tcp_timer_scale >>= 1;
  2072. conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
  2073. options = le16_to_cpu(fw_ddb_entry->ip_options);
  2074. conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
  2075. conn->max_recv_dlength = BYTE_UNITS *
  2076. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  2077. conn->max_xmit_dlength = BYTE_UNITS *
  2078. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  2079. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  2080. sess->first_burst = BYTE_UNITS *
  2081. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  2082. sess->max_burst = BYTE_UNITS *
  2083. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  2084. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  2085. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  2086. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  2087. conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
  2088. conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
  2089. conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
  2090. conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
  2091. conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
  2092. conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
  2093. conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
  2094. conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
  2095. sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
  2096. COPY_ISID(sess->isid, fw_ddb_entry->isid);
  2097. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  2098. if (ddb_link == DDB_ISNS)
  2099. disc_parent = ISCSI_DISC_PARENT_ISNS;
  2100. else if (ddb_link == DDB_NO_LINK)
  2101. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  2102. else if (ddb_link < MAX_DDB_ENTRIES)
  2103. disc_parent = ISCSI_DISC_PARENT_SENDTGT;
  2104. else
  2105. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  2106. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
  2107. iscsi_get_discovery_parent_name(disc_parent), 0);
  2108. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  2109. (char *)fw_ddb_entry->iscsi_alias, 0);
  2110. }
  2111. static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
  2112. struct dev_db_entry *fw_ddb_entry,
  2113. struct iscsi_cls_session *cls_sess,
  2114. struct iscsi_cls_conn *cls_conn)
  2115. {
  2116. int buflen = 0;
  2117. struct iscsi_session *sess;
  2118. struct ddb_entry *ddb_entry;
  2119. struct iscsi_conn *conn;
  2120. char ip_addr[DDB_IPADDR_LEN];
  2121. uint16_t options = 0;
  2122. sess = cls_sess->dd_data;
  2123. ddb_entry = sess->dd_data;
  2124. conn = cls_conn->dd_data;
  2125. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  2126. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  2127. sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
  2128. conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
  2129. memset(ip_addr, 0, sizeof(ip_addr));
  2130. options = le16_to_cpu(fw_ddb_entry->options);
  2131. if (options & DDB_OPT_IPV6_DEVICE) {
  2132. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
  2133. memset(ip_addr, 0, sizeof(ip_addr));
  2134. sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  2135. } else {
  2136. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
  2137. sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  2138. }
  2139. iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
  2140. (char *)ip_addr, buflen);
  2141. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
  2142. (char *)fw_ddb_entry->iscsi_name, buflen);
  2143. iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
  2144. (char *)ha->name_string, buflen);
  2145. }
  2146. void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
  2147. struct ddb_entry *ddb_entry)
  2148. {
  2149. struct iscsi_cls_session *cls_sess;
  2150. struct iscsi_cls_conn *cls_conn;
  2151. uint32_t ddb_state;
  2152. dma_addr_t fw_ddb_entry_dma;
  2153. struct dev_db_entry *fw_ddb_entry;
  2154. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2155. &fw_ddb_entry_dma, GFP_KERNEL);
  2156. if (!fw_ddb_entry) {
  2157. ql4_printk(KERN_ERR, ha,
  2158. "%s: Unable to allocate dma buffer\n", __func__);
  2159. goto exit_session_conn_fwddb_param;
  2160. }
  2161. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  2162. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  2163. NULL, NULL, NULL) == QLA_ERROR) {
  2164. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  2165. "get_ddb_entry for fw_ddb_index %d\n",
  2166. ha->host_no, __func__,
  2167. ddb_entry->fw_ddb_index));
  2168. goto exit_session_conn_fwddb_param;
  2169. }
  2170. cls_sess = ddb_entry->sess;
  2171. cls_conn = ddb_entry->conn;
  2172. /* Update params */
  2173. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  2174. exit_session_conn_fwddb_param:
  2175. if (fw_ddb_entry)
  2176. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2177. fw_ddb_entry, fw_ddb_entry_dma);
  2178. }
  2179. void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
  2180. struct ddb_entry *ddb_entry)
  2181. {
  2182. struct iscsi_cls_session *cls_sess;
  2183. struct iscsi_cls_conn *cls_conn;
  2184. struct iscsi_session *sess;
  2185. struct iscsi_conn *conn;
  2186. uint32_t ddb_state;
  2187. dma_addr_t fw_ddb_entry_dma;
  2188. struct dev_db_entry *fw_ddb_entry;
  2189. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2190. &fw_ddb_entry_dma, GFP_KERNEL);
  2191. if (!fw_ddb_entry) {
  2192. ql4_printk(KERN_ERR, ha,
  2193. "%s: Unable to allocate dma buffer\n", __func__);
  2194. goto exit_session_conn_param;
  2195. }
  2196. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  2197. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  2198. NULL, NULL, NULL) == QLA_ERROR) {
  2199. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  2200. "get_ddb_entry for fw_ddb_index %d\n",
  2201. ha->host_no, __func__,
  2202. ddb_entry->fw_ddb_index));
  2203. goto exit_session_conn_param;
  2204. }
  2205. cls_sess = ddb_entry->sess;
  2206. sess = cls_sess->dd_data;
  2207. cls_conn = ddb_entry->conn;
  2208. conn = cls_conn->dd_data;
  2209. /* Update timers after login */
  2210. ddb_entry->default_relogin_timeout =
  2211. (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
  2212. (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
  2213. le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
  2214. ddb_entry->default_time2wait =
  2215. le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  2216. /* Update params */
  2217. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  2218. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  2219. memcpy(sess->initiatorname, ha->name_string,
  2220. min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
  2221. exit_session_conn_param:
  2222. if (fw_ddb_entry)
  2223. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2224. fw_ddb_entry, fw_ddb_entry_dma);
  2225. }
  2226. /*
  2227. * Timer routines
  2228. */
  2229. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  2230. unsigned long interval)
  2231. {
  2232. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  2233. __func__, ha->host->host_no));
  2234. init_timer(&ha->timer);
  2235. ha->timer.expires = jiffies + interval * HZ;
  2236. ha->timer.data = (unsigned long)ha;
  2237. ha->timer.function = (void (*)(unsigned long))func;
  2238. add_timer(&ha->timer);
  2239. ha->timer_active = 1;
  2240. }
  2241. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  2242. {
  2243. del_timer_sync(&ha->timer);
  2244. ha->timer_active = 0;
  2245. }
  2246. /***
  2247. * qla4xxx_mark_device_missing - blocks the session
  2248. * @cls_session: Pointer to the session to be blocked
  2249. * @ddb_entry: Pointer to device database entry
  2250. *
  2251. * This routine marks a device missing and close connection.
  2252. **/
  2253. void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
  2254. {
  2255. iscsi_block_session(cls_session);
  2256. }
  2257. /**
  2258. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  2259. * @ha: Pointer to host adapter structure.
  2260. *
  2261. * This routine marks a device missing and resets the relogin retry count.
  2262. **/
  2263. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  2264. {
  2265. iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
  2266. }
  2267. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  2268. struct ddb_entry *ddb_entry,
  2269. struct scsi_cmnd *cmd)
  2270. {
  2271. struct srb *srb;
  2272. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  2273. if (!srb)
  2274. return srb;
  2275. kref_init(&srb->srb_ref);
  2276. srb->ha = ha;
  2277. srb->ddb = ddb_entry;
  2278. srb->cmd = cmd;
  2279. srb->flags = 0;
  2280. CMD_SP(cmd) = (void *)srb;
  2281. return srb;
  2282. }
  2283. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  2284. {
  2285. struct scsi_cmnd *cmd = srb->cmd;
  2286. if (srb->flags & SRB_DMA_VALID) {
  2287. scsi_dma_unmap(cmd);
  2288. srb->flags &= ~SRB_DMA_VALID;
  2289. }
  2290. CMD_SP(cmd) = NULL;
  2291. }
  2292. void qla4xxx_srb_compl(struct kref *ref)
  2293. {
  2294. struct srb *srb = container_of(ref, struct srb, srb_ref);
  2295. struct scsi_cmnd *cmd = srb->cmd;
  2296. struct scsi_qla_host *ha = srb->ha;
  2297. qla4xxx_srb_free_dma(ha, srb);
  2298. mempool_free(srb, ha->srb_mempool);
  2299. cmd->scsi_done(cmd);
  2300. }
  2301. /**
  2302. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  2303. * @host: scsi host
  2304. * @cmd: Pointer to Linux's SCSI command structure
  2305. *
  2306. * Remarks:
  2307. * This routine is invoked by Linux to send a SCSI command to the driver.
  2308. * The mid-level driver tries to ensure that queuecommand never gets
  2309. * invoked concurrently with itself or the interrupt handler (although
  2310. * the interrupt handler may call this routine as part of request-
  2311. * completion handling). Unfortunely, it sometimes calls the scheduler
  2312. * in interrupt context which is a big NO! NO!.
  2313. **/
  2314. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  2315. {
  2316. struct scsi_qla_host *ha = to_qla_host(host);
  2317. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  2318. struct iscsi_cls_session *sess = ddb_entry->sess;
  2319. struct srb *srb;
  2320. int rval;
  2321. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2322. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  2323. cmd->result = DID_NO_CONNECT << 16;
  2324. else
  2325. cmd->result = DID_REQUEUE << 16;
  2326. goto qc_fail_command;
  2327. }
  2328. if (!sess) {
  2329. cmd->result = DID_IMM_RETRY << 16;
  2330. goto qc_fail_command;
  2331. }
  2332. rval = iscsi_session_chkready(sess);
  2333. if (rval) {
  2334. cmd->result = rval;
  2335. goto qc_fail_command;
  2336. }
  2337. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2338. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  2339. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2340. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  2341. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  2342. !test_bit(AF_ONLINE, &ha->flags) ||
  2343. !test_bit(AF_LINK_UP, &ha->flags) ||
  2344. test_bit(AF_LOOPBACK, &ha->flags) ||
  2345. test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
  2346. test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
  2347. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  2348. goto qc_host_busy;
  2349. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  2350. if (!srb)
  2351. goto qc_host_busy;
  2352. rval = qla4xxx_send_command_to_isp(ha, srb);
  2353. if (rval != QLA_SUCCESS)
  2354. goto qc_host_busy_free_sp;
  2355. return 0;
  2356. qc_host_busy_free_sp:
  2357. qla4xxx_srb_free_dma(ha, srb);
  2358. mempool_free(srb, ha->srb_mempool);
  2359. qc_host_busy:
  2360. return SCSI_MLQUEUE_HOST_BUSY;
  2361. qc_fail_command:
  2362. cmd->scsi_done(cmd);
  2363. return 0;
  2364. }
  2365. /**
  2366. * qla4xxx_mem_free - frees memory allocated to adapter
  2367. * @ha: Pointer to host adapter structure.
  2368. *
  2369. * Frees memory previously allocated by qla4xxx_mem_alloc
  2370. **/
  2371. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  2372. {
  2373. if (ha->queues)
  2374. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  2375. ha->queues_dma);
  2376. if (ha->fw_dump)
  2377. vfree(ha->fw_dump);
  2378. ha->queues_len = 0;
  2379. ha->queues = NULL;
  2380. ha->queues_dma = 0;
  2381. ha->request_ring = NULL;
  2382. ha->request_dma = 0;
  2383. ha->response_ring = NULL;
  2384. ha->response_dma = 0;
  2385. ha->shadow_regs = NULL;
  2386. ha->shadow_regs_dma = 0;
  2387. ha->fw_dump = NULL;
  2388. ha->fw_dump_size = 0;
  2389. /* Free srb pool. */
  2390. if (ha->srb_mempool)
  2391. mempool_destroy(ha->srb_mempool);
  2392. ha->srb_mempool = NULL;
  2393. if (ha->chap_dma_pool)
  2394. dma_pool_destroy(ha->chap_dma_pool);
  2395. if (ha->chap_list)
  2396. vfree(ha->chap_list);
  2397. ha->chap_list = NULL;
  2398. if (ha->fw_ddb_dma_pool)
  2399. dma_pool_destroy(ha->fw_ddb_dma_pool);
  2400. /* release io space registers */
  2401. if (is_qla8022(ha)) {
  2402. if (ha->nx_pcibase)
  2403. iounmap(
  2404. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  2405. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  2406. if (ha->nx_pcibase)
  2407. iounmap(
  2408. (struct device_reg_83xx __iomem *)ha->nx_pcibase);
  2409. } else if (ha->reg) {
  2410. iounmap(ha->reg);
  2411. }
  2412. if (ha->reset_tmplt.buff)
  2413. vfree(ha->reset_tmplt.buff);
  2414. pci_release_regions(ha->pdev);
  2415. }
  2416. /**
  2417. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  2418. * @ha: Pointer to host adapter structure
  2419. *
  2420. * Allocates DMA memory for request and response queues. Also allocates memory
  2421. * for srbs.
  2422. **/
  2423. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  2424. {
  2425. unsigned long align;
  2426. /* Allocate contiguous block of DMA memory for queues. */
  2427. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2428. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  2429. sizeof(struct shadow_regs) +
  2430. MEM_ALIGN_VALUE +
  2431. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  2432. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  2433. &ha->queues_dma, GFP_KERNEL);
  2434. if (ha->queues == NULL) {
  2435. ql4_printk(KERN_WARNING, ha,
  2436. "Memory Allocation failed - queues.\n");
  2437. goto mem_alloc_error_exit;
  2438. }
  2439. memset(ha->queues, 0, ha->queues_len);
  2440. /*
  2441. * As per RISC alignment requirements -- the bus-address must be a
  2442. * multiple of the request-ring size (in bytes).
  2443. */
  2444. align = 0;
  2445. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  2446. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  2447. (MEM_ALIGN_VALUE - 1));
  2448. /* Update request and response queue pointers. */
  2449. ha->request_dma = ha->queues_dma + align;
  2450. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  2451. ha->response_dma = ha->queues_dma + align +
  2452. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  2453. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  2454. (REQUEST_QUEUE_DEPTH *
  2455. QUEUE_SIZE));
  2456. ha->shadow_regs_dma = ha->queues_dma + align +
  2457. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  2458. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  2459. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  2460. (REQUEST_QUEUE_DEPTH *
  2461. QUEUE_SIZE) +
  2462. (RESPONSE_QUEUE_DEPTH *
  2463. QUEUE_SIZE));
  2464. /* Allocate memory for srb pool. */
  2465. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  2466. mempool_free_slab, srb_cachep);
  2467. if (ha->srb_mempool == NULL) {
  2468. ql4_printk(KERN_WARNING, ha,
  2469. "Memory Allocation failed - SRB Pool.\n");
  2470. goto mem_alloc_error_exit;
  2471. }
  2472. ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
  2473. CHAP_DMA_BLOCK_SIZE, 8, 0);
  2474. if (ha->chap_dma_pool == NULL) {
  2475. ql4_printk(KERN_WARNING, ha,
  2476. "%s: chap_dma_pool allocation failed..\n", __func__);
  2477. goto mem_alloc_error_exit;
  2478. }
  2479. ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
  2480. DDB_DMA_BLOCK_SIZE, 8, 0);
  2481. if (ha->fw_ddb_dma_pool == NULL) {
  2482. ql4_printk(KERN_WARNING, ha,
  2483. "%s: fw_ddb_dma_pool allocation failed..\n",
  2484. __func__);
  2485. goto mem_alloc_error_exit;
  2486. }
  2487. return QLA_SUCCESS;
  2488. mem_alloc_error_exit:
  2489. qla4xxx_mem_free(ha);
  2490. return QLA_ERROR;
  2491. }
  2492. /**
  2493. * qla4_8xxx_check_temp - Check the ISP82XX temperature.
  2494. * @ha: adapter block pointer.
  2495. *
  2496. * Note: The caller should not hold the idc lock.
  2497. **/
  2498. static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
  2499. {
  2500. uint32_t temp, temp_state, temp_val;
  2501. int status = QLA_SUCCESS;
  2502. temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
  2503. temp_state = qla82xx_get_temp_state(temp);
  2504. temp_val = qla82xx_get_temp_val(temp);
  2505. if (temp_state == QLA82XX_TEMP_PANIC) {
  2506. ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
  2507. " exceeds maximum allowed. Hardware has been shut"
  2508. " down.\n", temp_val);
  2509. status = QLA_ERROR;
  2510. } else if (temp_state == QLA82XX_TEMP_WARN) {
  2511. if (ha->temperature == QLA82XX_TEMP_NORMAL)
  2512. ql4_printk(KERN_WARNING, ha, "Device temperature %d"
  2513. " degrees C exceeds operating range."
  2514. " Immediate action needed.\n", temp_val);
  2515. } else {
  2516. if (ha->temperature == QLA82XX_TEMP_WARN)
  2517. ql4_printk(KERN_INFO, ha, "Device temperature is"
  2518. " now %d degrees C in normal range.\n",
  2519. temp_val);
  2520. }
  2521. ha->temperature = temp_state;
  2522. return status;
  2523. }
  2524. /**
  2525. * qla4_8xxx_check_fw_alive - Check firmware health
  2526. * @ha: Pointer to host adapter structure.
  2527. *
  2528. * Context: Interrupt
  2529. **/
  2530. static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  2531. {
  2532. uint32_t fw_heartbeat_counter;
  2533. int status = QLA_SUCCESS;
  2534. fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
  2535. QLA8XXX_PEG_ALIVE_COUNTER);
  2536. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  2537. if (fw_heartbeat_counter == 0xffffffff) {
  2538. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  2539. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  2540. ha->host_no, __func__));
  2541. return status;
  2542. }
  2543. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  2544. ha->seconds_since_last_heartbeat++;
  2545. /* FW not alive after 2 seconds */
  2546. if (ha->seconds_since_last_heartbeat == 2) {
  2547. ha->seconds_since_last_heartbeat = 0;
  2548. qla4_8xxx_dump_peg_reg(ha);
  2549. status = QLA_ERROR;
  2550. }
  2551. } else
  2552. ha->seconds_since_last_heartbeat = 0;
  2553. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  2554. return status;
  2555. }
  2556. static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
  2557. {
  2558. uint32_t halt_status;
  2559. int halt_status_unrecoverable = 0;
  2560. halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
  2561. if (is_qla8022(ha)) {
  2562. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2563. __func__);
  2564. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2565. CRB_NIU_XG_PAUSE_CTL_P0 |
  2566. CRB_NIU_XG_PAUSE_CTL_P1);
  2567. if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
  2568. ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
  2569. __func__);
  2570. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  2571. halt_status_unrecoverable = 1;
  2572. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  2573. if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
  2574. ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
  2575. __func__);
  2576. else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
  2577. halt_status_unrecoverable = 1;
  2578. }
  2579. /*
  2580. * Since we cannot change dev_state in interrupt context,
  2581. * set appropriate DPC flag then wakeup DPC
  2582. */
  2583. if (halt_status_unrecoverable) {
  2584. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2585. } else {
  2586. ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
  2587. __func__);
  2588. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2589. }
  2590. qla4xxx_mailbox_premature_completion(ha);
  2591. qla4xxx_wake_dpc(ha);
  2592. }
  2593. /**
  2594. * qla4_8xxx_watchdog - Poll dev state
  2595. * @ha: Pointer to host adapter structure.
  2596. *
  2597. * Context: Interrupt
  2598. **/
  2599. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  2600. {
  2601. uint32_t dev_state;
  2602. uint32_t idc_ctrl;
  2603. /* don't poll if reset is going on */
  2604. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  2605. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2606. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  2607. dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
  2608. if (qla4_8xxx_check_temp(ha)) {
  2609. if (is_qla8022(ha)) {
  2610. ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
  2611. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  2612. CRB_NIU_XG_PAUSE_CTL_P0 |
  2613. CRB_NIU_XG_PAUSE_CTL_P1);
  2614. }
  2615. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  2616. qla4xxx_wake_dpc(ha);
  2617. } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
  2618. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  2619. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
  2620. __func__);
  2621. if (is_qla8032(ha) || is_qla8042(ha)) {
  2622. idc_ctrl = qla4_83xx_rd_reg(ha,
  2623. QLA83XX_IDC_DRV_CTRL);
  2624. if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
  2625. ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
  2626. __func__);
  2627. qla4xxx_mailbox_premature_completion(
  2628. ha);
  2629. }
  2630. }
  2631. if ((is_qla8032(ha) || is_qla8042(ha)) ||
  2632. (is_qla8022(ha) && !ql4xdontresethba)) {
  2633. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2634. qla4xxx_wake_dpc(ha);
  2635. }
  2636. } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
  2637. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2638. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  2639. __func__);
  2640. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  2641. qla4xxx_wake_dpc(ha);
  2642. } else {
  2643. /* Check firmware health */
  2644. if (qla4_8xxx_check_fw_alive(ha))
  2645. qla4_8xxx_process_fw_error(ha);
  2646. }
  2647. }
  2648. }
  2649. static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  2650. {
  2651. struct iscsi_session *sess;
  2652. struct ddb_entry *ddb_entry;
  2653. struct scsi_qla_host *ha;
  2654. sess = cls_sess->dd_data;
  2655. ddb_entry = sess->dd_data;
  2656. ha = ddb_entry->ha;
  2657. if (!(ddb_entry->ddb_type == FLASH_DDB))
  2658. return;
  2659. if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  2660. !iscsi_is_session_online(cls_sess)) {
  2661. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  2662. INVALID_ENTRY) {
  2663. if (atomic_read(&ddb_entry->retry_relogin_timer) ==
  2664. 0) {
  2665. atomic_set(&ddb_entry->retry_relogin_timer,
  2666. INVALID_ENTRY);
  2667. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2668. set_bit(DF_RELOGIN, &ddb_entry->flags);
  2669. DEBUG2(ql4_printk(KERN_INFO, ha,
  2670. "%s: index [%d] login device\n",
  2671. __func__, ddb_entry->fw_ddb_index));
  2672. } else
  2673. atomic_dec(&ddb_entry->retry_relogin_timer);
  2674. }
  2675. }
  2676. /* Wait for relogin to timeout */
  2677. if (atomic_read(&ddb_entry->relogin_timer) &&
  2678. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  2679. /*
  2680. * If the relogin times out and the device is
  2681. * still NOT ONLINE then try and relogin again.
  2682. */
  2683. if (!iscsi_is_session_online(cls_sess)) {
  2684. /* Reset retry relogin timer */
  2685. atomic_inc(&ddb_entry->relogin_retry_count);
  2686. DEBUG2(ql4_printk(KERN_INFO, ha,
  2687. "%s: index[%d] relogin timed out-retrying"
  2688. " relogin (%d), retry (%d)\n", __func__,
  2689. ddb_entry->fw_ddb_index,
  2690. atomic_read(&ddb_entry->relogin_retry_count),
  2691. ddb_entry->default_time2wait + 4));
  2692. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  2693. atomic_set(&ddb_entry->retry_relogin_timer,
  2694. ddb_entry->default_time2wait + 4);
  2695. }
  2696. }
  2697. }
  2698. /**
  2699. * qla4xxx_timer - checks every second for work to do.
  2700. * @ha: Pointer to host adapter structure.
  2701. **/
  2702. static void qla4xxx_timer(struct scsi_qla_host *ha)
  2703. {
  2704. int start_dpc = 0;
  2705. uint16_t w;
  2706. iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
  2707. /* If we are in the middle of AER/EEH processing
  2708. * skip any processing and reschedule the timer
  2709. */
  2710. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  2711. mod_timer(&ha->timer, jiffies + HZ);
  2712. return;
  2713. }
  2714. /* Hardware read to trigger an EEH error during mailbox waits. */
  2715. if (!pci_channel_offline(ha->pdev))
  2716. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  2717. if (is_qla80XX(ha))
  2718. qla4_8xxx_watchdog(ha);
  2719. if (is_qla40XX(ha)) {
  2720. /* Check for heartbeat interval. */
  2721. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  2722. ha->heartbeat_interval != 0) {
  2723. ha->seconds_since_last_heartbeat++;
  2724. if (ha->seconds_since_last_heartbeat >
  2725. ha->heartbeat_interval + 2)
  2726. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2727. }
  2728. }
  2729. /* Process any deferred work. */
  2730. if (!list_empty(&ha->work_list))
  2731. start_dpc++;
  2732. /* Wakeup the dpc routine for this adapter, if needed. */
  2733. if (start_dpc ||
  2734. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2735. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  2736. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  2737. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2738. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2739. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  2740. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  2741. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  2742. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  2743. test_bit(DPC_AEN, &ha->dpc_flags)) {
  2744. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  2745. " - dpc flags = 0x%lx\n",
  2746. ha->host_no, __func__, ha->dpc_flags));
  2747. qla4xxx_wake_dpc(ha);
  2748. }
  2749. /* Reschedule timer thread to call us back in one second */
  2750. mod_timer(&ha->timer, jiffies + HZ);
  2751. DEBUG2(ha->seconds_since_last_intr++);
  2752. }
  2753. /**
  2754. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  2755. * @ha: Pointer to host adapter structure.
  2756. *
  2757. * This routine stalls the driver until all outstanding commands are returned.
  2758. * Caller must release the Hardware Lock prior to calling this routine.
  2759. **/
  2760. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  2761. {
  2762. uint32_t index = 0;
  2763. unsigned long flags;
  2764. struct scsi_cmnd *cmd;
  2765. unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
  2766. DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
  2767. "complete\n", WAIT_CMD_TOV));
  2768. while (!time_after_eq(jiffies, wtime)) {
  2769. spin_lock_irqsave(&ha->hardware_lock, flags);
  2770. /* Find a command that hasn't completed. */
  2771. for (index = 0; index < ha->host->can_queue; index++) {
  2772. cmd = scsi_host_find_tag(ha->host, index);
  2773. /*
  2774. * We cannot just check if the index is valid,
  2775. * becase if we are run from the scsi eh, then
  2776. * the scsi/block layer is going to prevent
  2777. * the tag from being released.
  2778. */
  2779. if (cmd != NULL && CMD_SP(cmd))
  2780. break;
  2781. }
  2782. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2783. /* If No Commands are pending, wait is complete */
  2784. if (index == ha->host->can_queue)
  2785. return QLA_SUCCESS;
  2786. msleep(1000);
  2787. }
  2788. /* If we timed out on waiting for commands to come back
  2789. * return ERROR. */
  2790. return QLA_ERROR;
  2791. }
  2792. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  2793. {
  2794. uint32_t ctrl_status;
  2795. unsigned long flags = 0;
  2796. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  2797. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  2798. return QLA_ERROR;
  2799. spin_lock_irqsave(&ha->hardware_lock, flags);
  2800. /*
  2801. * If the SCSI Reset Interrupt bit is set, clear it.
  2802. * Otherwise, the Soft Reset won't work.
  2803. */
  2804. ctrl_status = readw(&ha->reg->ctrl_status);
  2805. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  2806. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2807. /* Issue Soft Reset */
  2808. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  2809. readl(&ha->reg->ctrl_status);
  2810. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2811. return QLA_SUCCESS;
  2812. }
  2813. /**
  2814. * qla4xxx_soft_reset - performs soft reset.
  2815. * @ha: Pointer to host adapter structure.
  2816. **/
  2817. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  2818. {
  2819. uint32_t max_wait_time;
  2820. unsigned long flags = 0;
  2821. int status;
  2822. uint32_t ctrl_status;
  2823. status = qla4xxx_hw_reset(ha);
  2824. if (status != QLA_SUCCESS)
  2825. return status;
  2826. status = QLA_ERROR;
  2827. /* Wait until the Network Reset Intr bit is cleared */
  2828. max_wait_time = RESET_INTR_TOV;
  2829. do {
  2830. spin_lock_irqsave(&ha->hardware_lock, flags);
  2831. ctrl_status = readw(&ha->reg->ctrl_status);
  2832. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2833. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  2834. break;
  2835. msleep(1000);
  2836. } while ((--max_wait_time));
  2837. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  2838. DEBUG2(printk(KERN_WARNING
  2839. "scsi%ld: Network Reset Intr not cleared by "
  2840. "Network function, clearing it now!\n",
  2841. ha->host_no));
  2842. spin_lock_irqsave(&ha->hardware_lock, flags);
  2843. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  2844. readl(&ha->reg->ctrl_status);
  2845. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2846. }
  2847. /* Wait until the firmware tells us the Soft Reset is done */
  2848. max_wait_time = SOFT_RESET_TOV;
  2849. do {
  2850. spin_lock_irqsave(&ha->hardware_lock, flags);
  2851. ctrl_status = readw(&ha->reg->ctrl_status);
  2852. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2853. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  2854. status = QLA_SUCCESS;
  2855. break;
  2856. }
  2857. msleep(1000);
  2858. } while ((--max_wait_time));
  2859. /*
  2860. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  2861. * after the soft reset has taken place.
  2862. */
  2863. spin_lock_irqsave(&ha->hardware_lock, flags);
  2864. ctrl_status = readw(&ha->reg->ctrl_status);
  2865. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  2866. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  2867. readl(&ha->reg->ctrl_status);
  2868. }
  2869. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2870. /* If soft reset fails then most probably the bios on other
  2871. * function is also enabled.
  2872. * Since the initialization is sequential the other fn
  2873. * wont be able to acknowledge the soft reset.
  2874. * Issue a force soft reset to workaround this scenario.
  2875. */
  2876. if (max_wait_time == 0) {
  2877. /* Issue Force Soft Reset */
  2878. spin_lock_irqsave(&ha->hardware_lock, flags);
  2879. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  2880. readl(&ha->reg->ctrl_status);
  2881. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2882. /* Wait until the firmware tells us the Soft Reset is done */
  2883. max_wait_time = SOFT_RESET_TOV;
  2884. do {
  2885. spin_lock_irqsave(&ha->hardware_lock, flags);
  2886. ctrl_status = readw(&ha->reg->ctrl_status);
  2887. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2888. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  2889. status = QLA_SUCCESS;
  2890. break;
  2891. }
  2892. msleep(1000);
  2893. } while ((--max_wait_time));
  2894. }
  2895. return status;
  2896. }
  2897. /**
  2898. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  2899. * @ha: Pointer to host adapter structure.
  2900. * @res: returned scsi status
  2901. *
  2902. * This routine is called just prior to a HARD RESET to return all
  2903. * outstanding commands back to the Operating System.
  2904. * Caller should make sure that the following locks are released
  2905. * before this calling routine: Hardware lock, and io_request_lock.
  2906. **/
  2907. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  2908. {
  2909. struct srb *srb;
  2910. int i;
  2911. unsigned long flags;
  2912. spin_lock_irqsave(&ha->hardware_lock, flags);
  2913. for (i = 0; i < ha->host->can_queue; i++) {
  2914. srb = qla4xxx_del_from_active_array(ha, i);
  2915. if (srb != NULL) {
  2916. srb->cmd->result = res;
  2917. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  2918. }
  2919. }
  2920. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2921. }
  2922. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  2923. {
  2924. clear_bit(AF_ONLINE, &ha->flags);
  2925. /* Disable the board */
  2926. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  2927. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  2928. qla4xxx_mark_all_devices_missing(ha);
  2929. clear_bit(AF_INIT_DONE, &ha->flags);
  2930. }
  2931. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
  2932. {
  2933. struct iscsi_session *sess;
  2934. struct ddb_entry *ddb_entry;
  2935. sess = cls_session->dd_data;
  2936. ddb_entry = sess->dd_data;
  2937. ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
  2938. if (ddb_entry->ddb_type == FLASH_DDB)
  2939. iscsi_block_session(ddb_entry->sess);
  2940. else
  2941. iscsi_session_failure(cls_session->dd_data,
  2942. ISCSI_ERR_CONN_FAILED);
  2943. }
  2944. /**
  2945. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  2946. * @ha: Pointer to host adapter structure.
  2947. **/
  2948. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  2949. {
  2950. int status = QLA_ERROR;
  2951. uint8_t reset_chip = 0;
  2952. uint32_t dev_state;
  2953. unsigned long wait;
  2954. /* Stall incoming I/O until we are done */
  2955. scsi_block_requests(ha->host);
  2956. clear_bit(AF_ONLINE, &ha->flags);
  2957. clear_bit(AF_LINK_UP, &ha->flags);
  2958. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  2959. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2960. if ((is_qla8032(ha) || is_qla8042(ha)) &&
  2961. !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2962. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  2963. __func__);
  2964. /* disable pause frame for ISP83xx */
  2965. qla4_83xx_disable_pause(ha);
  2966. }
  2967. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  2968. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2969. reset_chip = 1;
  2970. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  2971. * do not reset adapter, jump to initialize_adapter */
  2972. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2973. status = QLA_SUCCESS;
  2974. goto recover_ha_init_adapter;
  2975. }
  2976. /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
  2977. * from eh_host_reset or ioctl module */
  2978. if (is_qla80XX(ha) && !reset_chip &&
  2979. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  2980. DEBUG2(ql4_printk(KERN_INFO, ha,
  2981. "scsi%ld: %s - Performing stop_firmware...\n",
  2982. ha->host_no, __func__));
  2983. status = ha->isp_ops->reset_firmware(ha);
  2984. if (status == QLA_SUCCESS) {
  2985. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  2986. qla4xxx_cmd_wait(ha);
  2987. ha->isp_ops->disable_intrs(ha);
  2988. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2989. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2990. } else {
  2991. /* If the stop_firmware fails then
  2992. * reset the entire chip */
  2993. reset_chip = 1;
  2994. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2995. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2996. }
  2997. }
  2998. /* Issue full chip reset if recovering from a catastrophic error,
  2999. * or if stop_firmware fails for ISP-8xxx.
  3000. * This is the default case for ISP-4xxx */
  3001. if (is_qla40XX(ha) || reset_chip) {
  3002. if (is_qla40XX(ha))
  3003. goto chip_reset;
  3004. /* Check if 8XXX firmware is alive or not
  3005. * We may have arrived here from NEED_RESET
  3006. * detection only */
  3007. if (test_bit(AF_FW_RECOVERY, &ha->flags))
  3008. goto chip_reset;
  3009. wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
  3010. while (time_before(jiffies, wait)) {
  3011. if (qla4_8xxx_check_fw_alive(ha)) {
  3012. qla4xxx_mailbox_premature_completion(ha);
  3013. break;
  3014. }
  3015. set_current_state(TASK_UNINTERRUPTIBLE);
  3016. schedule_timeout(HZ);
  3017. }
  3018. chip_reset:
  3019. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  3020. qla4xxx_cmd_wait(ha);
  3021. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3022. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  3023. DEBUG2(ql4_printk(KERN_INFO, ha,
  3024. "scsi%ld: %s - Performing chip reset..\n",
  3025. ha->host_no, __func__));
  3026. status = ha->isp_ops->reset_chip(ha);
  3027. }
  3028. /* Flush any pending ddb changed AENs */
  3029. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3030. recover_ha_init_adapter:
  3031. /* Upon successful firmware/chip reset, re-initialize the adapter */
  3032. if (status == QLA_SUCCESS) {
  3033. /* For ISP-4xxx, force function 1 to always initialize
  3034. * before function 3 to prevent both funcions from
  3035. * stepping on top of the other */
  3036. if (is_qla40XX(ha) && (ha->mac_index == 3))
  3037. ssleep(6);
  3038. /* NOTE: AF_ONLINE flag set upon successful completion of
  3039. * qla4xxx_initialize_adapter */
  3040. status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  3041. }
  3042. /* Retry failed adapter initialization, if necessary
  3043. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  3044. * case to prevent ping-pong resets between functions */
  3045. if (!test_bit(AF_ONLINE, &ha->flags) &&
  3046. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  3047. /* Adapter initialization failed, see if we can retry
  3048. * resetting the ha.
  3049. * Since we don't want to block the DPC for too long
  3050. * with multiple resets in the same thread,
  3051. * utilize DPC to retry */
  3052. if (is_qla80XX(ha)) {
  3053. ha->isp_ops->idc_lock(ha);
  3054. dev_state = qla4_8xxx_rd_direct(ha,
  3055. QLA8XXX_CRB_DEV_STATE);
  3056. ha->isp_ops->idc_unlock(ha);
  3057. if (dev_state == QLA8XXX_DEV_FAILED) {
  3058. ql4_printk(KERN_INFO, ha, "%s: don't retry "
  3059. "recover adapter. H/W is in Failed "
  3060. "state\n", __func__);
  3061. qla4xxx_dead_adapter_cleanup(ha);
  3062. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3063. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3064. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  3065. &ha->dpc_flags);
  3066. status = QLA_ERROR;
  3067. goto exit_recover;
  3068. }
  3069. }
  3070. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  3071. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  3072. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  3073. "(%d) more times\n", ha->host_no,
  3074. ha->retry_reset_ha_cnt));
  3075. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3076. status = QLA_ERROR;
  3077. } else {
  3078. if (ha->retry_reset_ha_cnt > 0) {
  3079. /* Schedule another Reset HA--DPC will retry */
  3080. ha->retry_reset_ha_cnt--;
  3081. DEBUG2(printk("scsi%ld: recover adapter - "
  3082. "retry remaining %d\n",
  3083. ha->host_no,
  3084. ha->retry_reset_ha_cnt));
  3085. status = QLA_ERROR;
  3086. }
  3087. if (ha->retry_reset_ha_cnt == 0) {
  3088. /* Recover adapter retries have been exhausted.
  3089. * Adapter DEAD */
  3090. DEBUG2(printk("scsi%ld: recover adapter "
  3091. "failed - board disabled\n",
  3092. ha->host_no));
  3093. qla4xxx_dead_adapter_cleanup(ha);
  3094. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3095. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3096. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  3097. &ha->dpc_flags);
  3098. status = QLA_ERROR;
  3099. }
  3100. }
  3101. } else {
  3102. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3103. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  3104. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  3105. }
  3106. exit_recover:
  3107. ha->adapter_error_count++;
  3108. if (test_bit(AF_ONLINE, &ha->flags))
  3109. ha->isp_ops->enable_intrs(ha);
  3110. scsi_unblock_requests(ha->host);
  3111. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  3112. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  3113. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  3114. return status;
  3115. }
  3116. static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
  3117. {
  3118. struct iscsi_session *sess;
  3119. struct ddb_entry *ddb_entry;
  3120. struct scsi_qla_host *ha;
  3121. sess = cls_session->dd_data;
  3122. ddb_entry = sess->dd_data;
  3123. ha = ddb_entry->ha;
  3124. if (!iscsi_is_session_online(cls_session)) {
  3125. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
  3126. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3127. " unblock session\n", ha->host_no, __func__,
  3128. ddb_entry->fw_ddb_index);
  3129. iscsi_unblock_session(ddb_entry->sess);
  3130. } else {
  3131. /* Trigger relogin */
  3132. if (ddb_entry->ddb_type == FLASH_DDB) {
  3133. if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
  3134. test_bit(DF_DISABLE_RELOGIN,
  3135. &ddb_entry->flags)))
  3136. qla4xxx_arm_relogin_timer(ddb_entry);
  3137. } else
  3138. iscsi_session_failure(cls_session->dd_data,
  3139. ISCSI_ERR_CONN_FAILED);
  3140. }
  3141. }
  3142. }
  3143. int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
  3144. {
  3145. struct iscsi_session *sess;
  3146. struct ddb_entry *ddb_entry;
  3147. struct scsi_qla_host *ha;
  3148. sess = cls_session->dd_data;
  3149. ddb_entry = sess->dd_data;
  3150. ha = ddb_entry->ha;
  3151. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3152. " unblock session\n", ha->host_no, __func__,
  3153. ddb_entry->fw_ddb_index);
  3154. iscsi_unblock_session(ddb_entry->sess);
  3155. /* Start scan target */
  3156. if (test_bit(AF_ONLINE, &ha->flags)) {
  3157. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3158. " start scan\n", ha->host_no, __func__,
  3159. ddb_entry->fw_ddb_index);
  3160. scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
  3161. }
  3162. return QLA_SUCCESS;
  3163. }
  3164. int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
  3165. {
  3166. struct iscsi_session *sess;
  3167. struct ddb_entry *ddb_entry;
  3168. struct scsi_qla_host *ha;
  3169. int status = QLA_SUCCESS;
  3170. sess = cls_session->dd_data;
  3171. ddb_entry = sess->dd_data;
  3172. ha = ddb_entry->ha;
  3173. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  3174. " unblock user space session\n", ha->host_no, __func__,
  3175. ddb_entry->fw_ddb_index);
  3176. if (!iscsi_is_session_online(cls_session)) {
  3177. iscsi_conn_start(ddb_entry->conn);
  3178. iscsi_conn_login_event(ddb_entry->conn,
  3179. ISCSI_CONN_STATE_LOGGED_IN);
  3180. } else {
  3181. ql4_printk(KERN_INFO, ha,
  3182. "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
  3183. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  3184. cls_session->sid);
  3185. status = QLA_ERROR;
  3186. }
  3187. return status;
  3188. }
  3189. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  3190. {
  3191. iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
  3192. }
  3193. static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  3194. {
  3195. uint16_t relogin_timer;
  3196. struct iscsi_session *sess;
  3197. struct ddb_entry *ddb_entry;
  3198. struct scsi_qla_host *ha;
  3199. sess = cls_sess->dd_data;
  3200. ddb_entry = sess->dd_data;
  3201. ha = ddb_entry->ha;
  3202. relogin_timer = max(ddb_entry->default_relogin_timeout,
  3203. (uint16_t)RELOGIN_TOV);
  3204. atomic_set(&ddb_entry->relogin_timer, relogin_timer);
  3205. DEBUG2(ql4_printk(KERN_INFO, ha,
  3206. "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
  3207. ddb_entry->fw_ddb_index, relogin_timer));
  3208. qla4xxx_login_flash_ddb(cls_sess);
  3209. }
  3210. static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
  3211. {
  3212. struct iscsi_session *sess;
  3213. struct ddb_entry *ddb_entry;
  3214. struct scsi_qla_host *ha;
  3215. sess = cls_sess->dd_data;
  3216. ddb_entry = sess->dd_data;
  3217. ha = ddb_entry->ha;
  3218. if (!(ddb_entry->ddb_type == FLASH_DDB))
  3219. return;
  3220. if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  3221. return;
  3222. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  3223. !iscsi_is_session_online(cls_sess)) {
  3224. DEBUG2(ql4_printk(KERN_INFO, ha,
  3225. "relogin issued\n"));
  3226. qla4xxx_relogin_flash_ddb(cls_sess);
  3227. }
  3228. }
  3229. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  3230. {
  3231. if (ha->dpc_thread)
  3232. queue_work(ha->dpc_thread, &ha->dpc_work);
  3233. }
  3234. static struct qla4_work_evt *
  3235. qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
  3236. enum qla4_work_type type)
  3237. {
  3238. struct qla4_work_evt *e;
  3239. uint32_t size = sizeof(struct qla4_work_evt) + data_size;
  3240. e = kzalloc(size, GFP_ATOMIC);
  3241. if (!e)
  3242. return NULL;
  3243. INIT_LIST_HEAD(&e->list);
  3244. e->type = type;
  3245. return e;
  3246. }
  3247. static void qla4xxx_post_work(struct scsi_qla_host *ha,
  3248. struct qla4_work_evt *e)
  3249. {
  3250. unsigned long flags;
  3251. spin_lock_irqsave(&ha->work_lock, flags);
  3252. list_add_tail(&e->list, &ha->work_list);
  3253. spin_unlock_irqrestore(&ha->work_lock, flags);
  3254. qla4xxx_wake_dpc(ha);
  3255. }
  3256. int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
  3257. enum iscsi_host_event_code aen_code,
  3258. uint32_t data_size, uint8_t *data)
  3259. {
  3260. struct qla4_work_evt *e;
  3261. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
  3262. if (!e)
  3263. return QLA_ERROR;
  3264. e->u.aen.code = aen_code;
  3265. e->u.aen.data_size = data_size;
  3266. memcpy(e->u.aen.data, data, data_size);
  3267. qla4xxx_post_work(ha, e);
  3268. return QLA_SUCCESS;
  3269. }
  3270. int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
  3271. uint32_t status, uint32_t pid,
  3272. uint32_t data_size, uint8_t *data)
  3273. {
  3274. struct qla4_work_evt *e;
  3275. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
  3276. if (!e)
  3277. return QLA_ERROR;
  3278. e->u.ping.status = status;
  3279. e->u.ping.pid = pid;
  3280. e->u.ping.data_size = data_size;
  3281. memcpy(e->u.ping.data, data, data_size);
  3282. qla4xxx_post_work(ha, e);
  3283. return QLA_SUCCESS;
  3284. }
  3285. static void qla4xxx_do_work(struct scsi_qla_host *ha)
  3286. {
  3287. struct qla4_work_evt *e, *tmp;
  3288. unsigned long flags;
  3289. LIST_HEAD(work);
  3290. spin_lock_irqsave(&ha->work_lock, flags);
  3291. list_splice_init(&ha->work_list, &work);
  3292. spin_unlock_irqrestore(&ha->work_lock, flags);
  3293. list_for_each_entry_safe(e, tmp, &work, list) {
  3294. list_del_init(&e->list);
  3295. switch (e->type) {
  3296. case QLA4_EVENT_AEN:
  3297. iscsi_post_host_event(ha->host_no,
  3298. &qla4xxx_iscsi_transport,
  3299. e->u.aen.code,
  3300. e->u.aen.data_size,
  3301. e->u.aen.data);
  3302. break;
  3303. case QLA4_EVENT_PING_STATUS:
  3304. iscsi_ping_comp_event(ha->host_no,
  3305. &qla4xxx_iscsi_transport,
  3306. e->u.ping.status,
  3307. e->u.ping.pid,
  3308. e->u.ping.data_size,
  3309. e->u.ping.data);
  3310. break;
  3311. default:
  3312. ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
  3313. "supported", e->type);
  3314. }
  3315. kfree(e);
  3316. }
  3317. }
  3318. /**
  3319. * qla4xxx_do_dpc - dpc routine
  3320. * @data: in our case pointer to adapter structure
  3321. *
  3322. * This routine is a task that is schedule by the interrupt handler
  3323. * to perform the background processing for interrupts. We put it
  3324. * on a task queue that is consumed whenever the scheduler runs; that's
  3325. * so you can do anything (i.e. put the process to sleep etc). In fact,
  3326. * the mid-level tries to sleep when it reaches the driver threshold
  3327. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  3328. **/
  3329. static void qla4xxx_do_dpc(struct work_struct *work)
  3330. {
  3331. struct scsi_qla_host *ha =
  3332. container_of(work, struct scsi_qla_host, dpc_work);
  3333. int status = QLA_ERROR;
  3334. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  3335. "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  3336. ha->host_no, __func__, ha->flags, ha->dpc_flags))
  3337. /* Initialization not yet finished. Don't do anything yet. */
  3338. if (!test_bit(AF_INIT_DONE, &ha->flags))
  3339. return;
  3340. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  3341. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  3342. ha->host_no, __func__, ha->flags));
  3343. return;
  3344. }
  3345. /* post events to application */
  3346. qla4xxx_do_work(ha);
  3347. if (is_qla80XX(ha)) {
  3348. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  3349. if (is_qla8032(ha) || is_qla8042(ha)) {
  3350. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  3351. __func__);
  3352. /* disable pause frame for ISP83xx */
  3353. qla4_83xx_disable_pause(ha);
  3354. }
  3355. ha->isp_ops->idc_lock(ha);
  3356. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  3357. QLA8XXX_DEV_FAILED);
  3358. ha->isp_ops->idc_unlock(ha);
  3359. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  3360. qla4_8xxx_device_state_handler(ha);
  3361. }
  3362. if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
  3363. if (is_qla8042(ha)) {
  3364. if (ha->idc_info.info2 &
  3365. ENABLE_INTERNAL_LOOPBACK) {
  3366. ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
  3367. __func__);
  3368. status = qla4_84xx_config_acb(ha,
  3369. ACB_CONFIG_DISABLE);
  3370. if (status != QLA_SUCCESS) {
  3371. ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
  3372. __func__);
  3373. }
  3374. }
  3375. }
  3376. qla4_83xx_post_idc_ack(ha);
  3377. clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
  3378. }
  3379. if (is_qla8042(ha) &&
  3380. test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
  3381. ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
  3382. __func__);
  3383. if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
  3384. QLA_SUCCESS) {
  3385. ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
  3386. __func__);
  3387. }
  3388. clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
  3389. }
  3390. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  3391. qla4_8xxx_need_qsnt_handler(ha);
  3392. }
  3393. }
  3394. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  3395. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  3396. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  3397. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  3398. if ((is_qla8022(ha) && ql4xdontresethba) ||
  3399. ((is_qla8032(ha) || is_qla8042(ha)) &&
  3400. qla4_83xx_idc_dontreset(ha))) {
  3401. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  3402. ha->host_no, __func__));
  3403. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  3404. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  3405. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  3406. goto dpc_post_reset_ha;
  3407. }
  3408. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  3409. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  3410. qla4xxx_recover_adapter(ha);
  3411. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  3412. uint8_t wait_time = RESET_INTR_TOV;
  3413. while ((readw(&ha->reg->ctrl_status) &
  3414. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  3415. if (--wait_time == 0)
  3416. break;
  3417. msleep(1000);
  3418. }
  3419. if (wait_time == 0)
  3420. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  3421. "bit not cleared-- resetting\n",
  3422. ha->host_no, __func__));
  3423. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  3424. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  3425. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3426. status = qla4xxx_recover_adapter(ha);
  3427. }
  3428. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  3429. if (status == QLA_SUCCESS)
  3430. ha->isp_ops->enable_intrs(ha);
  3431. }
  3432. }
  3433. dpc_post_reset_ha:
  3434. /* ---- process AEN? --- */
  3435. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  3436. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  3437. /* ---- Get DHCP IP Address? --- */
  3438. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  3439. qla4xxx_get_dhcp_ip_address(ha);
  3440. /* ---- relogin device? --- */
  3441. if (adapter_up(ha) &&
  3442. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  3443. iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
  3444. }
  3445. /* ---- link change? --- */
  3446. if (!test_bit(AF_LOOPBACK, &ha->flags) &&
  3447. test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  3448. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  3449. /* ---- link down? --- */
  3450. qla4xxx_mark_all_devices_missing(ha);
  3451. } else {
  3452. /* ---- link up? --- *
  3453. * F/W will auto login to all devices ONLY ONCE after
  3454. * link up during driver initialization and runtime
  3455. * fatal error recovery. Therefore, the driver must
  3456. * manually relogin to devices when recovering from
  3457. * connection failures, logouts, expired KATO, etc. */
  3458. if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
  3459. qla4xxx_build_ddb_list(ha, ha->is_reset);
  3460. iscsi_host_for_each_session(ha->host,
  3461. qla4xxx_login_flash_ddb);
  3462. } else
  3463. qla4xxx_relogin_all_devices(ha);
  3464. }
  3465. }
  3466. }
  3467. /**
  3468. * qla4xxx_free_adapter - release the adapter
  3469. * @ha: pointer to adapter structure
  3470. **/
  3471. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  3472. {
  3473. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  3474. /* Turn-off interrupts on the card. */
  3475. ha->isp_ops->disable_intrs(ha);
  3476. if (is_qla40XX(ha)) {
  3477. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  3478. &ha->reg->ctrl_status);
  3479. readl(&ha->reg->ctrl_status);
  3480. } else if (is_qla8022(ha)) {
  3481. writel(0, &ha->qla4_82xx_reg->host_int);
  3482. readl(&ha->qla4_82xx_reg->host_int);
  3483. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  3484. writel(0, &ha->qla4_83xx_reg->risc_intr);
  3485. readl(&ha->qla4_83xx_reg->risc_intr);
  3486. }
  3487. /* Remove timer thread, if present */
  3488. if (ha->timer_active)
  3489. qla4xxx_stop_timer(ha);
  3490. /* Kill the kernel thread for this host */
  3491. if (ha->dpc_thread)
  3492. destroy_workqueue(ha->dpc_thread);
  3493. /* Kill the kernel thread for this host */
  3494. if (ha->task_wq)
  3495. destroy_workqueue(ha->task_wq);
  3496. /* Put firmware in known state */
  3497. ha->isp_ops->reset_firmware(ha);
  3498. if (is_qla80XX(ha)) {
  3499. ha->isp_ops->idc_lock(ha);
  3500. qla4_8xxx_clear_drv_active(ha);
  3501. ha->isp_ops->idc_unlock(ha);
  3502. }
  3503. /* Detach interrupts */
  3504. qla4xxx_free_irqs(ha);
  3505. /* free extra memory */
  3506. qla4xxx_mem_free(ha);
  3507. }
  3508. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  3509. {
  3510. int status = 0;
  3511. unsigned long mem_base, mem_len, db_base, db_len;
  3512. struct pci_dev *pdev = ha->pdev;
  3513. status = pci_request_regions(pdev, DRIVER_NAME);
  3514. if (status) {
  3515. printk(KERN_WARNING
  3516. "scsi(%ld) Failed to reserve PIO regions (%s) "
  3517. "status=%d\n", ha->host_no, pci_name(pdev), status);
  3518. goto iospace_error_exit;
  3519. }
  3520. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  3521. __func__, pdev->revision));
  3522. ha->revision_id = pdev->revision;
  3523. /* remap phys address */
  3524. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  3525. mem_len = pci_resource_len(pdev, 0);
  3526. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  3527. __func__, mem_base, mem_len));
  3528. /* mapping of pcibase pointer */
  3529. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  3530. if (!ha->nx_pcibase) {
  3531. printk(KERN_ERR
  3532. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  3533. pci_release_regions(ha->pdev);
  3534. goto iospace_error_exit;
  3535. }
  3536. /* Mapping of IO base pointer, door bell read and write pointer */
  3537. /* mapping of IO base pointer */
  3538. if (is_qla8022(ha)) {
  3539. ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
  3540. ((uint8_t *)ha->nx_pcibase + 0xbc000 +
  3541. (ha->pdev->devfn << 11));
  3542. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  3543. QLA82XX_CAM_RAM_DB2);
  3544. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  3545. ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
  3546. ((uint8_t *)ha->nx_pcibase);
  3547. }
  3548. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  3549. db_len = pci_resource_len(pdev, 4);
  3550. return 0;
  3551. iospace_error_exit:
  3552. return -ENOMEM;
  3553. }
  3554. /***
  3555. * qla4xxx_iospace_config - maps registers
  3556. * @ha: pointer to adapter structure
  3557. *
  3558. * This routines maps HBA's registers from the pci address space
  3559. * into the kernel virtual address space for memory mapped i/o.
  3560. **/
  3561. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  3562. {
  3563. unsigned long pio, pio_len, pio_flags;
  3564. unsigned long mmio, mmio_len, mmio_flags;
  3565. pio = pci_resource_start(ha->pdev, 0);
  3566. pio_len = pci_resource_len(ha->pdev, 0);
  3567. pio_flags = pci_resource_flags(ha->pdev, 0);
  3568. if (pio_flags & IORESOURCE_IO) {
  3569. if (pio_len < MIN_IOBASE_LEN) {
  3570. ql4_printk(KERN_WARNING, ha,
  3571. "Invalid PCI I/O region size\n");
  3572. pio = 0;
  3573. }
  3574. } else {
  3575. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  3576. pio = 0;
  3577. }
  3578. /* Use MMIO operations for all accesses. */
  3579. mmio = pci_resource_start(ha->pdev, 1);
  3580. mmio_len = pci_resource_len(ha->pdev, 1);
  3581. mmio_flags = pci_resource_flags(ha->pdev, 1);
  3582. if (!(mmio_flags & IORESOURCE_MEM)) {
  3583. ql4_printk(KERN_ERR, ha,
  3584. "region #0 not an MMIO resource, aborting\n");
  3585. goto iospace_error_exit;
  3586. }
  3587. if (mmio_len < MIN_IOBASE_LEN) {
  3588. ql4_printk(KERN_ERR, ha,
  3589. "Invalid PCI mem region size, aborting\n");
  3590. goto iospace_error_exit;
  3591. }
  3592. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  3593. ql4_printk(KERN_WARNING, ha,
  3594. "Failed to reserve PIO/MMIO regions\n");
  3595. goto iospace_error_exit;
  3596. }
  3597. ha->pio_address = pio;
  3598. ha->pio_length = pio_len;
  3599. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  3600. if (!ha->reg) {
  3601. ql4_printk(KERN_ERR, ha,
  3602. "cannot remap MMIO, aborting\n");
  3603. goto iospace_error_exit;
  3604. }
  3605. return 0;
  3606. iospace_error_exit:
  3607. return -ENOMEM;
  3608. }
  3609. static struct isp_operations qla4xxx_isp_ops = {
  3610. .iospace_config = qla4xxx_iospace_config,
  3611. .pci_config = qla4xxx_pci_config,
  3612. .disable_intrs = qla4xxx_disable_intrs,
  3613. .enable_intrs = qla4xxx_enable_intrs,
  3614. .start_firmware = qla4xxx_start_firmware,
  3615. .intr_handler = qla4xxx_intr_handler,
  3616. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  3617. .reset_chip = qla4xxx_soft_reset,
  3618. .reset_firmware = qla4xxx_hw_reset,
  3619. .queue_iocb = qla4xxx_queue_iocb,
  3620. .complete_iocb = qla4xxx_complete_iocb,
  3621. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3622. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3623. .get_sys_info = qla4xxx_get_sys_info,
  3624. .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
  3625. .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
  3626. };
  3627. static struct isp_operations qla4_82xx_isp_ops = {
  3628. .iospace_config = qla4_8xxx_iospace_config,
  3629. .pci_config = qla4_8xxx_pci_config,
  3630. .disable_intrs = qla4_82xx_disable_intrs,
  3631. .enable_intrs = qla4_82xx_enable_intrs,
  3632. .start_firmware = qla4_8xxx_load_risc,
  3633. .restart_firmware = qla4_82xx_try_start_fw,
  3634. .intr_handler = qla4_82xx_intr_handler,
  3635. .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
  3636. .need_reset = qla4_8xxx_need_reset,
  3637. .reset_chip = qla4_82xx_isp_reset,
  3638. .reset_firmware = qla4_8xxx_stop_firmware,
  3639. .queue_iocb = qla4_82xx_queue_iocb,
  3640. .complete_iocb = qla4_82xx_complete_iocb,
  3641. .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
  3642. .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
  3643. .get_sys_info = qla4_8xxx_get_sys_info,
  3644. .rd_reg_direct = qla4_82xx_rd_32,
  3645. .wr_reg_direct = qla4_82xx_wr_32,
  3646. .rd_reg_indirect = qla4_82xx_md_rd_32,
  3647. .wr_reg_indirect = qla4_82xx_md_wr_32,
  3648. .idc_lock = qla4_82xx_idc_lock,
  3649. .idc_unlock = qla4_82xx_idc_unlock,
  3650. .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
  3651. .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
  3652. .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
  3653. };
  3654. static struct isp_operations qla4_83xx_isp_ops = {
  3655. .iospace_config = qla4_8xxx_iospace_config,
  3656. .pci_config = qla4_8xxx_pci_config,
  3657. .disable_intrs = qla4_83xx_disable_intrs,
  3658. .enable_intrs = qla4_83xx_enable_intrs,
  3659. .start_firmware = qla4_8xxx_load_risc,
  3660. .restart_firmware = qla4_83xx_start_firmware,
  3661. .intr_handler = qla4_83xx_intr_handler,
  3662. .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
  3663. .need_reset = qla4_8xxx_need_reset,
  3664. .reset_chip = qla4_83xx_isp_reset,
  3665. .reset_firmware = qla4_8xxx_stop_firmware,
  3666. .queue_iocb = qla4_83xx_queue_iocb,
  3667. .complete_iocb = qla4_83xx_complete_iocb,
  3668. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  3669. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  3670. .get_sys_info = qla4_8xxx_get_sys_info,
  3671. .rd_reg_direct = qla4_83xx_rd_reg,
  3672. .wr_reg_direct = qla4_83xx_wr_reg,
  3673. .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
  3674. .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
  3675. .idc_lock = qla4_83xx_drv_lock,
  3676. .idc_unlock = qla4_83xx_drv_unlock,
  3677. .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
  3678. .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
  3679. .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
  3680. };
  3681. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3682. {
  3683. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  3684. }
  3685. uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  3686. {
  3687. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
  3688. }
  3689. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3690. {
  3691. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  3692. }
  3693. uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  3694. {
  3695. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
  3696. }
  3697. static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
  3698. {
  3699. struct scsi_qla_host *ha = data;
  3700. char *str = buf;
  3701. int rc;
  3702. switch (type) {
  3703. case ISCSI_BOOT_ETH_FLAGS:
  3704. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3705. break;
  3706. case ISCSI_BOOT_ETH_INDEX:
  3707. rc = sprintf(str, "0\n");
  3708. break;
  3709. case ISCSI_BOOT_ETH_MAC:
  3710. rc = sysfs_format_mac(str, ha->my_mac,
  3711. MAC_ADDR_LEN);
  3712. break;
  3713. default:
  3714. rc = -ENOSYS;
  3715. break;
  3716. }
  3717. return rc;
  3718. }
  3719. static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
  3720. {
  3721. int rc;
  3722. switch (type) {
  3723. case ISCSI_BOOT_ETH_FLAGS:
  3724. case ISCSI_BOOT_ETH_MAC:
  3725. case ISCSI_BOOT_ETH_INDEX:
  3726. rc = S_IRUGO;
  3727. break;
  3728. default:
  3729. rc = 0;
  3730. break;
  3731. }
  3732. return rc;
  3733. }
  3734. static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
  3735. {
  3736. struct scsi_qla_host *ha = data;
  3737. char *str = buf;
  3738. int rc;
  3739. switch (type) {
  3740. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3741. rc = sprintf(str, "%s\n", ha->name_string);
  3742. break;
  3743. default:
  3744. rc = -ENOSYS;
  3745. break;
  3746. }
  3747. return rc;
  3748. }
  3749. static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
  3750. {
  3751. int rc;
  3752. switch (type) {
  3753. case ISCSI_BOOT_INI_INITIATOR_NAME:
  3754. rc = S_IRUGO;
  3755. break;
  3756. default:
  3757. rc = 0;
  3758. break;
  3759. }
  3760. return rc;
  3761. }
  3762. static ssize_t
  3763. qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
  3764. char *buf)
  3765. {
  3766. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  3767. char *str = buf;
  3768. int rc;
  3769. switch (type) {
  3770. case ISCSI_BOOT_TGT_NAME:
  3771. rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
  3772. break;
  3773. case ISCSI_BOOT_TGT_IP_ADDR:
  3774. if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
  3775. rc = sprintf(buf, "%pI4\n",
  3776. &boot_conn->dest_ipaddr.ip_address);
  3777. else
  3778. rc = sprintf(str, "%pI6\n",
  3779. &boot_conn->dest_ipaddr.ip_address);
  3780. break;
  3781. case ISCSI_BOOT_TGT_PORT:
  3782. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  3783. break;
  3784. case ISCSI_BOOT_TGT_CHAP_NAME:
  3785. rc = sprintf(str, "%.*s\n",
  3786. boot_conn->chap.target_chap_name_length,
  3787. (char *)&boot_conn->chap.target_chap_name);
  3788. break;
  3789. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3790. rc = sprintf(str, "%.*s\n",
  3791. boot_conn->chap.target_secret_length,
  3792. (char *)&boot_conn->chap.target_secret);
  3793. break;
  3794. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3795. rc = sprintf(str, "%.*s\n",
  3796. boot_conn->chap.intr_chap_name_length,
  3797. (char *)&boot_conn->chap.intr_chap_name);
  3798. break;
  3799. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3800. rc = sprintf(str, "%.*s\n",
  3801. boot_conn->chap.intr_secret_length,
  3802. (char *)&boot_conn->chap.intr_secret);
  3803. break;
  3804. case ISCSI_BOOT_TGT_FLAGS:
  3805. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  3806. break;
  3807. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3808. rc = sprintf(str, "0\n");
  3809. break;
  3810. default:
  3811. rc = -ENOSYS;
  3812. break;
  3813. }
  3814. return rc;
  3815. }
  3816. static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
  3817. {
  3818. struct scsi_qla_host *ha = data;
  3819. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
  3820. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3821. }
  3822. static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
  3823. {
  3824. struct scsi_qla_host *ha = data;
  3825. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
  3826. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  3827. }
  3828. static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
  3829. {
  3830. int rc;
  3831. switch (type) {
  3832. case ISCSI_BOOT_TGT_NAME:
  3833. case ISCSI_BOOT_TGT_IP_ADDR:
  3834. case ISCSI_BOOT_TGT_PORT:
  3835. case ISCSI_BOOT_TGT_CHAP_NAME:
  3836. case ISCSI_BOOT_TGT_CHAP_SECRET:
  3837. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  3838. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  3839. case ISCSI_BOOT_TGT_NIC_ASSOC:
  3840. case ISCSI_BOOT_TGT_FLAGS:
  3841. rc = S_IRUGO;
  3842. break;
  3843. default:
  3844. rc = 0;
  3845. break;
  3846. }
  3847. return rc;
  3848. }
  3849. static void qla4xxx_boot_release(void *data)
  3850. {
  3851. struct scsi_qla_host *ha = data;
  3852. scsi_host_put(ha->host);
  3853. }
  3854. static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
  3855. {
  3856. dma_addr_t buf_dma;
  3857. uint32_t addr, pri_addr, sec_addr;
  3858. uint32_t offset;
  3859. uint16_t func_num;
  3860. uint8_t val;
  3861. uint8_t *buf = NULL;
  3862. size_t size = 13 * sizeof(uint8_t);
  3863. int ret = QLA_SUCCESS;
  3864. func_num = PCI_FUNC(ha->pdev->devfn);
  3865. ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
  3866. __func__, ha->pdev->device, func_num);
  3867. if (is_qla40XX(ha)) {
  3868. if (func_num == 1) {
  3869. addr = NVRAM_PORT0_BOOT_MODE;
  3870. pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
  3871. sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
  3872. } else if (func_num == 3) {
  3873. addr = NVRAM_PORT1_BOOT_MODE;
  3874. pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
  3875. sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
  3876. } else {
  3877. ret = QLA_ERROR;
  3878. goto exit_boot_info;
  3879. }
  3880. /* Check Boot Mode */
  3881. val = rd_nvram_byte(ha, addr);
  3882. if (!(val & 0x07)) {
  3883. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
  3884. "options : 0x%x\n", __func__, val));
  3885. ret = QLA_ERROR;
  3886. goto exit_boot_info;
  3887. }
  3888. /* get primary valid target index */
  3889. val = rd_nvram_byte(ha, pri_addr);
  3890. if (val & BIT_7)
  3891. ddb_index[0] = (val & 0x7f);
  3892. /* get secondary valid target index */
  3893. val = rd_nvram_byte(ha, sec_addr);
  3894. if (val & BIT_7)
  3895. ddb_index[1] = (val & 0x7f);
  3896. } else if (is_qla80XX(ha)) {
  3897. buf = dma_alloc_coherent(&ha->pdev->dev, size,
  3898. &buf_dma, GFP_KERNEL);
  3899. if (!buf) {
  3900. DEBUG2(ql4_printk(KERN_ERR, ha,
  3901. "%s: Unable to allocate dma buffer\n",
  3902. __func__));
  3903. ret = QLA_ERROR;
  3904. goto exit_boot_info;
  3905. }
  3906. if (ha->port_num == 0)
  3907. offset = BOOT_PARAM_OFFSET_PORT0;
  3908. else if (ha->port_num == 1)
  3909. offset = BOOT_PARAM_OFFSET_PORT1;
  3910. else {
  3911. ret = QLA_ERROR;
  3912. goto exit_boot_info_free;
  3913. }
  3914. addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
  3915. offset;
  3916. if (qla4xxx_get_flash(ha, buf_dma, addr,
  3917. 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
  3918. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  3919. " failed\n", ha->host_no, __func__));
  3920. ret = QLA_ERROR;
  3921. goto exit_boot_info_free;
  3922. }
  3923. /* Check Boot Mode */
  3924. if (!(buf[1] & 0x07)) {
  3925. DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
  3926. " : 0x%x\n", buf[1]));
  3927. ret = QLA_ERROR;
  3928. goto exit_boot_info_free;
  3929. }
  3930. /* get primary valid target index */
  3931. if (buf[2] & BIT_7)
  3932. ddb_index[0] = buf[2] & 0x7f;
  3933. /* get secondary valid target index */
  3934. if (buf[11] & BIT_7)
  3935. ddb_index[1] = buf[11] & 0x7f;
  3936. } else {
  3937. ret = QLA_ERROR;
  3938. goto exit_boot_info;
  3939. }
  3940. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
  3941. " target ID %d\n", __func__, ddb_index[0],
  3942. ddb_index[1]));
  3943. exit_boot_info_free:
  3944. dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
  3945. exit_boot_info:
  3946. ha->pri_ddb_idx = ddb_index[0];
  3947. ha->sec_ddb_idx = ddb_index[1];
  3948. return ret;
  3949. }
  3950. /**
  3951. * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  3952. * @ha: pointer to adapter structure
  3953. * @username: CHAP username to be returned
  3954. * @password: CHAP password to be returned
  3955. *
  3956. * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
  3957. * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
  3958. * So from the CHAP cache find the first BIDI CHAP entry and set it
  3959. * to the boot record in sysfs.
  3960. **/
  3961. static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
  3962. char *password)
  3963. {
  3964. int i, ret = -EINVAL;
  3965. int max_chap_entries = 0;
  3966. struct ql4_chap_table *chap_table;
  3967. if (is_qla80XX(ha))
  3968. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  3969. sizeof(struct ql4_chap_table);
  3970. else
  3971. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  3972. if (!ha->chap_list) {
  3973. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  3974. return ret;
  3975. }
  3976. mutex_lock(&ha->chap_sem);
  3977. for (i = 0; i < max_chap_entries; i++) {
  3978. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  3979. if (chap_table->cookie !=
  3980. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  3981. continue;
  3982. }
  3983. if (chap_table->flags & BIT_7) /* local */
  3984. continue;
  3985. if (!(chap_table->flags & BIT_6)) /* Not BIDI */
  3986. continue;
  3987. strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  3988. strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  3989. ret = 0;
  3990. break;
  3991. }
  3992. mutex_unlock(&ha->chap_sem);
  3993. return ret;
  3994. }
  3995. static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
  3996. struct ql4_boot_session_info *boot_sess,
  3997. uint16_t ddb_index)
  3998. {
  3999. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  4000. struct dev_db_entry *fw_ddb_entry;
  4001. dma_addr_t fw_ddb_entry_dma;
  4002. uint16_t idx;
  4003. uint16_t options;
  4004. int ret = QLA_SUCCESS;
  4005. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4006. &fw_ddb_entry_dma, GFP_KERNEL);
  4007. if (!fw_ddb_entry) {
  4008. DEBUG2(ql4_printk(KERN_ERR, ha,
  4009. "%s: Unable to allocate dma buffer.\n",
  4010. __func__));
  4011. ret = QLA_ERROR;
  4012. return ret;
  4013. }
  4014. if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
  4015. fw_ddb_entry_dma, ddb_index)) {
  4016. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
  4017. "index [%d]\n", __func__, ddb_index));
  4018. ret = QLA_ERROR;
  4019. goto exit_boot_target;
  4020. }
  4021. /* Update target name and IP from DDB */
  4022. memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
  4023. min(sizeof(boot_sess->target_name),
  4024. sizeof(fw_ddb_entry->iscsi_name)));
  4025. options = le16_to_cpu(fw_ddb_entry->options);
  4026. if (options & DDB_OPT_IPV6_DEVICE) {
  4027. memcpy(&boot_conn->dest_ipaddr.ip_address,
  4028. &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
  4029. } else {
  4030. boot_conn->dest_ipaddr.ip_type = 0x1;
  4031. memcpy(&boot_conn->dest_ipaddr.ip_address,
  4032. &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
  4033. }
  4034. boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
  4035. /* update chap information */
  4036. idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  4037. if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  4038. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
  4039. ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
  4040. target_chap_name,
  4041. (char *)&boot_conn->chap.target_secret,
  4042. idx);
  4043. if (ret) {
  4044. ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
  4045. ret = QLA_ERROR;
  4046. goto exit_boot_target;
  4047. }
  4048. boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  4049. boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  4050. }
  4051. if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  4052. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
  4053. ret = qla4xxx_get_bidi_chap(ha,
  4054. (char *)&boot_conn->chap.intr_chap_name,
  4055. (char *)&boot_conn->chap.intr_secret);
  4056. if (ret) {
  4057. ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
  4058. ret = QLA_ERROR;
  4059. goto exit_boot_target;
  4060. }
  4061. boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  4062. boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  4063. }
  4064. exit_boot_target:
  4065. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  4066. fw_ddb_entry, fw_ddb_entry_dma);
  4067. return ret;
  4068. }
  4069. static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
  4070. {
  4071. uint16_t ddb_index[2];
  4072. int ret = QLA_ERROR;
  4073. int rval;
  4074. memset(ddb_index, 0, sizeof(ddb_index));
  4075. ddb_index[0] = 0xffff;
  4076. ddb_index[1] = 0xffff;
  4077. ret = get_fw_boot_info(ha, ddb_index);
  4078. if (ret != QLA_SUCCESS) {
  4079. DEBUG2(ql4_printk(KERN_INFO, ha,
  4080. "%s: No boot target configured.\n", __func__));
  4081. return ret;
  4082. }
  4083. if (ql4xdisablesysfsboot)
  4084. return QLA_SUCCESS;
  4085. if (ddb_index[0] == 0xffff)
  4086. goto sec_target;
  4087. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
  4088. ddb_index[0]);
  4089. if (rval != QLA_SUCCESS) {
  4090. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
  4091. "configured\n", __func__));
  4092. } else
  4093. ret = QLA_SUCCESS;
  4094. sec_target:
  4095. if (ddb_index[1] == 0xffff)
  4096. goto exit_get_boot_info;
  4097. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
  4098. ddb_index[1]);
  4099. if (rval != QLA_SUCCESS) {
  4100. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
  4101. " configured\n", __func__));
  4102. } else
  4103. ret = QLA_SUCCESS;
  4104. exit_get_boot_info:
  4105. return ret;
  4106. }
  4107. static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
  4108. {
  4109. struct iscsi_boot_kobj *boot_kobj;
  4110. if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
  4111. return QLA_ERROR;
  4112. if (ql4xdisablesysfsboot) {
  4113. ql4_printk(KERN_INFO, ha,
  4114. "%s: syfsboot disabled - driver will trigger login "
  4115. "and publish session for discovery .\n", __func__);
  4116. return QLA_SUCCESS;
  4117. }
  4118. ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
  4119. if (!ha->boot_kset)
  4120. goto kset_free;
  4121. if (!scsi_host_get(ha->host))
  4122. goto kset_free;
  4123. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
  4124. qla4xxx_show_boot_tgt_pri_info,
  4125. qla4xxx_tgt_get_attr_visibility,
  4126. qla4xxx_boot_release);
  4127. if (!boot_kobj)
  4128. goto put_host;
  4129. if (!scsi_host_get(ha->host))
  4130. goto kset_free;
  4131. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
  4132. qla4xxx_show_boot_tgt_sec_info,
  4133. qla4xxx_tgt_get_attr_visibility,
  4134. qla4xxx_boot_release);
  4135. if (!boot_kobj)
  4136. goto put_host;
  4137. if (!scsi_host_get(ha->host))
  4138. goto kset_free;
  4139. boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
  4140. qla4xxx_show_boot_ini_info,
  4141. qla4xxx_ini_get_attr_visibility,
  4142. qla4xxx_boot_release);
  4143. if (!boot_kobj)
  4144. goto put_host;
  4145. if (!scsi_host_get(ha->host))
  4146. goto kset_free;
  4147. boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
  4148. qla4xxx_show_boot_eth_info,
  4149. qla4xxx_eth_get_attr_visibility,
  4150. qla4xxx_boot_release);
  4151. if (!boot_kobj)
  4152. goto put_host;
  4153. return QLA_SUCCESS;
  4154. put_host:
  4155. scsi_host_put(ha->host);
  4156. kset_free:
  4157. iscsi_boot_destroy_kset(ha->boot_kset);
  4158. return -ENOMEM;
  4159. }
  4160. /**
  4161. * qla4xxx_create chap_list - Create CHAP list from FLASH
  4162. * @ha: pointer to adapter structure
  4163. *
  4164. * Read flash and make a list of CHAP entries, during login when a CHAP entry
  4165. * is received, it will be checked in this list. If entry exist then the CHAP
  4166. * entry index is set in the DDB. If CHAP entry does not exist in this list
  4167. * then a new entry is added in FLASH in CHAP table and the index obtained is
  4168. * used in the DDB.
  4169. **/
  4170. static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
  4171. {
  4172. int rval = 0;
  4173. uint8_t *chap_flash_data = NULL;
  4174. uint32_t offset;
  4175. dma_addr_t chap_dma;
  4176. uint32_t chap_size = 0;
  4177. if (is_qla40XX(ha))
  4178. chap_size = MAX_CHAP_ENTRIES_40XX *
  4179. sizeof(struct ql4_chap_table);
  4180. else /* Single region contains CHAP info for both
  4181. * ports which is divided into half for each port.
  4182. */
  4183. chap_size = ha->hw.flt_chap_size / 2;
  4184. chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
  4185. &chap_dma, GFP_KERNEL);
  4186. if (!chap_flash_data) {
  4187. ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
  4188. return;
  4189. }
  4190. if (is_qla40XX(ha))
  4191. offset = FLASH_CHAP_OFFSET;
  4192. else {
  4193. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  4194. if (ha->port_num == 1)
  4195. offset += chap_size;
  4196. }
  4197. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  4198. if (rval != QLA_SUCCESS)
  4199. goto exit_chap_list;
  4200. if (ha->chap_list == NULL)
  4201. ha->chap_list = vmalloc(chap_size);
  4202. if (ha->chap_list == NULL) {
  4203. ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
  4204. goto exit_chap_list;
  4205. }
  4206. memcpy(ha->chap_list, chap_flash_data, chap_size);
  4207. exit_chap_list:
  4208. dma_free_coherent(&ha->pdev->dev, chap_size,
  4209. chap_flash_data, chap_dma);
  4210. }
  4211. static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
  4212. struct ql4_tuple_ddb *tddb)
  4213. {
  4214. struct scsi_qla_host *ha;
  4215. struct iscsi_cls_session *cls_sess;
  4216. struct iscsi_cls_conn *cls_conn;
  4217. struct iscsi_session *sess;
  4218. struct iscsi_conn *conn;
  4219. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  4220. ha = ddb_entry->ha;
  4221. cls_sess = ddb_entry->sess;
  4222. sess = cls_sess->dd_data;
  4223. cls_conn = ddb_entry->conn;
  4224. conn = cls_conn->dd_data;
  4225. tddb->tpgt = sess->tpgt;
  4226. tddb->port = conn->persistent_port;
  4227. strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
  4228. strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
  4229. }
  4230. static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
  4231. struct ql4_tuple_ddb *tddb,
  4232. uint8_t *flash_isid)
  4233. {
  4234. uint16_t options = 0;
  4235. tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  4236. memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
  4237. min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
  4238. options = le16_to_cpu(fw_ddb_entry->options);
  4239. if (options & DDB_OPT_IPV6_DEVICE)
  4240. sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  4241. else
  4242. sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  4243. tddb->port = le16_to_cpu(fw_ddb_entry->port);
  4244. if (flash_isid == NULL)
  4245. memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
  4246. sizeof(tddb->isid));
  4247. else
  4248. memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
  4249. }
  4250. static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
  4251. struct ql4_tuple_ddb *old_tddb,
  4252. struct ql4_tuple_ddb *new_tddb,
  4253. uint8_t is_isid_compare)
  4254. {
  4255. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  4256. return QLA_ERROR;
  4257. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
  4258. return QLA_ERROR;
  4259. if (old_tddb->port != new_tddb->port)
  4260. return QLA_ERROR;
  4261. /* For multi sessions, driver generates the ISID, so do not compare
  4262. * ISID in reset path since it would be a comparison between the
  4263. * driver generated ISID and firmware generated ISID. This could
  4264. * lead to adding duplicated DDBs in the list as driver generated
  4265. * ISID would not match firmware generated ISID.
  4266. */
  4267. if (is_isid_compare) {
  4268. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
  4269. "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
  4270. __func__, old_tddb->isid[5], old_tddb->isid[4],
  4271. old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
  4272. old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
  4273. new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
  4274. new_tddb->isid[0]));
  4275. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  4276. sizeof(old_tddb->isid)))
  4277. return QLA_ERROR;
  4278. }
  4279. DEBUG2(ql4_printk(KERN_INFO, ha,
  4280. "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
  4281. old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
  4282. old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
  4283. new_tddb->ip_addr, new_tddb->iscsi_name));
  4284. return QLA_SUCCESS;
  4285. }
  4286. static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
  4287. struct dev_db_entry *fw_ddb_entry,
  4288. uint32_t *index)
  4289. {
  4290. struct ddb_entry *ddb_entry;
  4291. struct ql4_tuple_ddb *fw_tddb = NULL;
  4292. struct ql4_tuple_ddb *tmp_tddb = NULL;
  4293. int idx;
  4294. int ret = QLA_ERROR;
  4295. fw_tddb = vzalloc(sizeof(*fw_tddb));
  4296. if (!fw_tddb) {
  4297. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4298. "Memory Allocation failed.\n"));
  4299. ret = QLA_SUCCESS;
  4300. goto exit_check;
  4301. }
  4302. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  4303. if (!tmp_tddb) {
  4304. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4305. "Memory Allocation failed.\n"));
  4306. ret = QLA_SUCCESS;
  4307. goto exit_check;
  4308. }
  4309. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  4310. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  4311. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  4312. if (ddb_entry == NULL)
  4313. continue;
  4314. qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
  4315. if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
  4316. ret = QLA_SUCCESS; /* found */
  4317. if (index != NULL)
  4318. *index = idx;
  4319. goto exit_check;
  4320. }
  4321. }
  4322. exit_check:
  4323. if (fw_tddb)
  4324. vfree(fw_tddb);
  4325. if (tmp_tddb)
  4326. vfree(tmp_tddb);
  4327. return ret;
  4328. }
  4329. /**
  4330. * qla4xxx_check_existing_isid - check if target with same isid exist
  4331. * in target list
  4332. * @list_nt: list of target
  4333. * @isid: isid to check
  4334. *
  4335. * This routine return QLA_SUCCESS if target with same isid exist
  4336. **/
  4337. static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
  4338. {
  4339. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  4340. struct dev_db_entry *fw_ddb_entry;
  4341. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4342. fw_ddb_entry = &nt_ddb_idx->fw_ddb;
  4343. if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
  4344. sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
  4345. return QLA_SUCCESS;
  4346. }
  4347. }
  4348. return QLA_ERROR;
  4349. }
  4350. /**
  4351. * qla4xxx_update_isid - compare ddbs and updated isid
  4352. * @ha: Pointer to host adapter structure.
  4353. * @list_nt: list of nt target
  4354. * @fw_ddb_entry: firmware ddb entry
  4355. *
  4356. * This routine update isid if ddbs have same iqn, same isid and
  4357. * different IP addr.
  4358. * Return QLA_SUCCESS if isid is updated.
  4359. **/
  4360. static int qla4xxx_update_isid(struct scsi_qla_host *ha,
  4361. struct list_head *list_nt,
  4362. struct dev_db_entry *fw_ddb_entry)
  4363. {
  4364. uint8_t base_value, i;
  4365. base_value = fw_ddb_entry->isid[1] & 0x1f;
  4366. for (i = 0; i < 8; i++) {
  4367. fw_ddb_entry->isid[1] = (base_value | (i << 5));
  4368. if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  4369. break;
  4370. }
  4371. if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  4372. return QLA_ERROR;
  4373. return QLA_SUCCESS;
  4374. }
  4375. /**
  4376. * qla4xxx_should_update_isid - check if isid need to update
  4377. * @ha: Pointer to host adapter structure.
  4378. * @old_tddb: ddb tuple
  4379. * @new_tddb: ddb tuple
  4380. *
  4381. * Return QLA_SUCCESS if different IP, different PORT, same iqn,
  4382. * same isid
  4383. **/
  4384. static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
  4385. struct ql4_tuple_ddb *old_tddb,
  4386. struct ql4_tuple_ddb *new_tddb)
  4387. {
  4388. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
  4389. /* Same ip */
  4390. if (old_tddb->port == new_tddb->port)
  4391. return QLA_ERROR;
  4392. }
  4393. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  4394. /* different iqn */
  4395. return QLA_ERROR;
  4396. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  4397. sizeof(old_tddb->isid)))
  4398. /* different isid */
  4399. return QLA_ERROR;
  4400. return QLA_SUCCESS;
  4401. }
  4402. /**
  4403. * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
  4404. * @ha: Pointer to host adapter structure.
  4405. * @list_nt: list of nt target.
  4406. * @fw_ddb_entry: firmware ddb entry.
  4407. *
  4408. * This routine check if fw_ddb_entry already exists in list_nt to avoid
  4409. * duplicate ddb in list_nt.
  4410. * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
  4411. * Note: This function also update isid of DDB if required.
  4412. **/
  4413. static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
  4414. struct list_head *list_nt,
  4415. struct dev_db_entry *fw_ddb_entry)
  4416. {
  4417. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  4418. struct ql4_tuple_ddb *fw_tddb = NULL;
  4419. struct ql4_tuple_ddb *tmp_tddb = NULL;
  4420. int rval, ret = QLA_ERROR;
  4421. fw_tddb = vzalloc(sizeof(*fw_tddb));
  4422. if (!fw_tddb) {
  4423. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4424. "Memory Allocation failed.\n"));
  4425. ret = QLA_SUCCESS;
  4426. goto exit_check;
  4427. }
  4428. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  4429. if (!tmp_tddb) {
  4430. DEBUG2(ql4_printk(KERN_WARNING, ha,
  4431. "Memory Allocation failed.\n"));
  4432. ret = QLA_SUCCESS;
  4433. goto exit_check;
  4434. }
  4435. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  4436. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4437. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
  4438. nt_ddb_idx->flash_isid);
  4439. ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
  4440. /* found duplicate ddb */
  4441. if (ret == QLA_SUCCESS)
  4442. goto exit_check;
  4443. }
  4444. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  4445. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
  4446. ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
  4447. if (ret == QLA_SUCCESS) {
  4448. rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
  4449. if (rval == QLA_SUCCESS)
  4450. ret = QLA_ERROR;
  4451. else
  4452. ret = QLA_SUCCESS;
  4453. goto exit_check;
  4454. }
  4455. }
  4456. exit_check:
  4457. if (fw_tddb)
  4458. vfree(fw_tddb);
  4459. if (tmp_tddb)
  4460. vfree(tmp_tddb);
  4461. return ret;
  4462. }
  4463. static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
  4464. {
  4465. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4466. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4467. list_del_init(&ddb_idx->list);
  4468. vfree(ddb_idx);
  4469. }
  4470. }
  4471. static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
  4472. struct dev_db_entry *fw_ddb_entry)
  4473. {
  4474. struct iscsi_endpoint *ep;
  4475. struct sockaddr_in *addr;
  4476. struct sockaddr_in6 *addr6;
  4477. struct sockaddr *t_addr;
  4478. struct sockaddr_storage *dst_addr;
  4479. char *ip;
  4480. /* TODO: need to destroy on unload iscsi_endpoint*/
  4481. dst_addr = vmalloc(sizeof(*dst_addr));
  4482. if (!dst_addr)
  4483. return NULL;
  4484. if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
  4485. t_addr = (struct sockaddr *)dst_addr;
  4486. t_addr->sa_family = AF_INET6;
  4487. addr6 = (struct sockaddr_in6 *)dst_addr;
  4488. ip = (char *)&addr6->sin6_addr;
  4489. memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  4490. addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4491. } else {
  4492. t_addr = (struct sockaddr *)dst_addr;
  4493. t_addr->sa_family = AF_INET;
  4494. addr = (struct sockaddr_in *)dst_addr;
  4495. ip = (char *)&addr->sin_addr;
  4496. memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
  4497. addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
  4498. }
  4499. ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
  4500. vfree(dst_addr);
  4501. return ep;
  4502. }
  4503. static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
  4504. {
  4505. if (ql4xdisablesysfsboot)
  4506. return QLA_SUCCESS;
  4507. if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
  4508. return QLA_ERROR;
  4509. return QLA_SUCCESS;
  4510. }
  4511. static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
  4512. struct ddb_entry *ddb_entry,
  4513. uint16_t idx)
  4514. {
  4515. uint16_t def_timeout;
  4516. ddb_entry->ddb_type = FLASH_DDB;
  4517. ddb_entry->fw_ddb_index = INVALID_ENTRY;
  4518. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  4519. ddb_entry->ha = ha;
  4520. ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
  4521. ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
  4522. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  4523. atomic_set(&ddb_entry->relogin_timer, 0);
  4524. atomic_set(&ddb_entry->relogin_retry_count, 0);
  4525. def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
  4526. ddb_entry->default_relogin_timeout =
  4527. (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
  4528. def_timeout : LOGIN_TOV;
  4529. ddb_entry->default_time2wait =
  4530. le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
  4531. if (ql4xdisablesysfsboot &&
  4532. (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
  4533. set_bit(DF_BOOT_TGT, &ddb_entry->flags);
  4534. }
  4535. static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
  4536. {
  4537. uint32_t idx = 0;
  4538. uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
  4539. uint32_t sts[MBOX_REG_COUNT];
  4540. uint32_t ip_state;
  4541. unsigned long wtime;
  4542. int ret;
  4543. wtime = jiffies + (HZ * IP_CONFIG_TOV);
  4544. do {
  4545. for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
  4546. if (ip_idx[idx] == -1)
  4547. continue;
  4548. ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
  4549. if (ret == QLA_ERROR) {
  4550. ip_idx[idx] = -1;
  4551. continue;
  4552. }
  4553. ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
  4554. DEBUG2(ql4_printk(KERN_INFO, ha,
  4555. "Waiting for IP state for idx = %d, state = 0x%x\n",
  4556. ip_idx[idx], ip_state));
  4557. if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
  4558. ip_state == IP_ADDRSTATE_INVALID ||
  4559. ip_state == IP_ADDRSTATE_PREFERRED ||
  4560. ip_state == IP_ADDRSTATE_DEPRICATED ||
  4561. ip_state == IP_ADDRSTATE_DISABLING)
  4562. ip_idx[idx] = -1;
  4563. }
  4564. /* Break if all IP states checked */
  4565. if ((ip_idx[0] == -1) &&
  4566. (ip_idx[1] == -1) &&
  4567. (ip_idx[2] == -1) &&
  4568. (ip_idx[3] == -1))
  4569. break;
  4570. schedule_timeout_uninterruptible(HZ);
  4571. } while (time_after(wtime, jiffies));
  4572. }
  4573. static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
  4574. struct dev_db_entry *flash_ddb_entry)
  4575. {
  4576. uint16_t options = 0;
  4577. size_t ip_len = IP_ADDR_LEN;
  4578. options = le16_to_cpu(fw_ddb_entry->options);
  4579. if (options & DDB_OPT_IPV6_DEVICE)
  4580. ip_len = IPv6_ADDR_LEN;
  4581. if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
  4582. return QLA_ERROR;
  4583. if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
  4584. sizeof(fw_ddb_entry->isid)))
  4585. return QLA_ERROR;
  4586. if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
  4587. sizeof(fw_ddb_entry->port)))
  4588. return QLA_ERROR;
  4589. return QLA_SUCCESS;
  4590. }
  4591. static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
  4592. struct dev_db_entry *fw_ddb_entry,
  4593. uint32_t fw_idx, uint32_t *flash_index)
  4594. {
  4595. struct dev_db_entry *flash_ddb_entry;
  4596. dma_addr_t flash_ddb_entry_dma;
  4597. uint32_t idx = 0;
  4598. int max_ddbs;
  4599. int ret = QLA_ERROR, status;
  4600. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4601. MAX_DEV_DB_ENTRIES;
  4602. flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4603. &flash_ddb_entry_dma);
  4604. if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
  4605. ql4_printk(KERN_ERR, ha, "Out of memory\n");
  4606. goto exit_find_st_idx;
  4607. }
  4608. status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
  4609. flash_ddb_entry_dma, fw_idx);
  4610. if (status == QLA_SUCCESS) {
  4611. status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
  4612. if (status == QLA_SUCCESS) {
  4613. *flash_index = fw_idx;
  4614. ret = QLA_SUCCESS;
  4615. goto exit_find_st_idx;
  4616. }
  4617. }
  4618. for (idx = 0; idx < max_ddbs; idx++) {
  4619. status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
  4620. flash_ddb_entry_dma, idx);
  4621. if (status == QLA_ERROR)
  4622. continue;
  4623. status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
  4624. if (status == QLA_SUCCESS) {
  4625. *flash_index = idx;
  4626. ret = QLA_SUCCESS;
  4627. goto exit_find_st_idx;
  4628. }
  4629. }
  4630. if (idx == max_ddbs)
  4631. ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
  4632. fw_idx);
  4633. exit_find_st_idx:
  4634. if (flash_ddb_entry)
  4635. dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
  4636. flash_ddb_entry_dma);
  4637. return ret;
  4638. }
  4639. static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
  4640. struct list_head *list_st)
  4641. {
  4642. struct qla_ddb_index *st_ddb_idx;
  4643. int max_ddbs;
  4644. int fw_idx_size;
  4645. struct dev_db_entry *fw_ddb_entry;
  4646. dma_addr_t fw_ddb_dma;
  4647. int ret;
  4648. uint32_t idx = 0, next_idx = 0;
  4649. uint32_t state = 0, conn_err = 0;
  4650. uint32_t flash_index = -1;
  4651. uint16_t conn_id = 0;
  4652. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4653. &fw_ddb_dma);
  4654. if (fw_ddb_entry == NULL) {
  4655. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4656. goto exit_st_list;
  4657. }
  4658. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4659. MAX_DEV_DB_ENTRIES;
  4660. fw_idx_size = sizeof(struct qla_ddb_index);
  4661. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4662. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4663. NULL, &next_idx, &state,
  4664. &conn_err, NULL, &conn_id);
  4665. if (ret == QLA_ERROR)
  4666. break;
  4667. /* Ignore DDB if invalid state (unassigned) */
  4668. if (state == DDB_DS_UNASSIGNED)
  4669. goto continue_next_st;
  4670. /* Check if ST, add to the list_st */
  4671. if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
  4672. goto continue_next_st;
  4673. st_ddb_idx = vzalloc(fw_idx_size);
  4674. if (!st_ddb_idx)
  4675. break;
  4676. ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
  4677. &flash_index);
  4678. if (ret == QLA_ERROR) {
  4679. ql4_printk(KERN_ERR, ha,
  4680. "No flash entry for ST at idx [%d]\n", idx);
  4681. st_ddb_idx->flash_ddb_idx = idx;
  4682. } else {
  4683. ql4_printk(KERN_INFO, ha,
  4684. "ST at idx [%d] is stored at flash [%d]\n",
  4685. idx, flash_index);
  4686. st_ddb_idx->flash_ddb_idx = flash_index;
  4687. }
  4688. st_ddb_idx->fw_ddb_idx = idx;
  4689. list_add_tail(&st_ddb_idx->list, list_st);
  4690. continue_next_st:
  4691. if (next_idx == 0)
  4692. break;
  4693. }
  4694. exit_st_list:
  4695. if (fw_ddb_entry)
  4696. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4697. }
  4698. /**
  4699. * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
  4700. * @ha: pointer to adapter structure
  4701. * @list_ddb: List from which failed ddb to be removed
  4702. *
  4703. * Iterate over the list of DDBs and find and remove DDBs that are either in
  4704. * no connection active state or failed state
  4705. **/
  4706. static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
  4707. struct list_head *list_ddb)
  4708. {
  4709. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4710. uint32_t next_idx = 0;
  4711. uint32_t state = 0, conn_err = 0;
  4712. int ret;
  4713. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4714. ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
  4715. NULL, 0, NULL, &next_idx, &state,
  4716. &conn_err, NULL, NULL);
  4717. if (ret == QLA_ERROR)
  4718. continue;
  4719. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4720. state == DDB_DS_SESSION_FAILED) {
  4721. list_del_init(&ddb_idx->list);
  4722. vfree(ddb_idx);
  4723. }
  4724. }
  4725. }
  4726. static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
  4727. struct ddb_entry *ddb_entry,
  4728. struct dev_db_entry *fw_ddb_entry)
  4729. {
  4730. struct iscsi_cls_session *cls_sess;
  4731. struct iscsi_session *sess;
  4732. uint32_t max_ddbs = 0;
  4733. uint16_t ddb_link = -1;
  4734. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4735. MAX_DEV_DB_ENTRIES;
  4736. cls_sess = ddb_entry->sess;
  4737. sess = cls_sess->dd_data;
  4738. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  4739. if (ddb_link < max_ddbs)
  4740. sess->discovery_parent_idx = ddb_link;
  4741. else
  4742. sess->discovery_parent_idx = DDB_NO_LINK;
  4743. }
  4744. static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
  4745. struct dev_db_entry *fw_ddb_entry,
  4746. int is_reset, uint16_t idx)
  4747. {
  4748. struct iscsi_cls_session *cls_sess;
  4749. struct iscsi_session *sess;
  4750. struct iscsi_cls_conn *cls_conn;
  4751. struct iscsi_endpoint *ep;
  4752. uint16_t cmds_max = 32;
  4753. uint16_t conn_id = 0;
  4754. uint32_t initial_cmdsn = 0;
  4755. int ret = QLA_SUCCESS;
  4756. struct ddb_entry *ddb_entry = NULL;
  4757. /* Create session object, with INVALID_ENTRY,
  4758. * the targer_id would get set when we issue the login
  4759. */
  4760. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
  4761. cmds_max, sizeof(struct ddb_entry),
  4762. sizeof(struct ql4_task_data),
  4763. initial_cmdsn, INVALID_ENTRY);
  4764. if (!cls_sess) {
  4765. ret = QLA_ERROR;
  4766. goto exit_setup;
  4767. }
  4768. /*
  4769. * so calling module_put function to decrement the
  4770. * reference count.
  4771. **/
  4772. module_put(qla4xxx_iscsi_transport.owner);
  4773. sess = cls_sess->dd_data;
  4774. ddb_entry = sess->dd_data;
  4775. ddb_entry->sess = cls_sess;
  4776. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  4777. memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
  4778. sizeof(struct dev_db_entry));
  4779. qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
  4780. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
  4781. if (!cls_conn) {
  4782. ret = QLA_ERROR;
  4783. goto exit_setup;
  4784. }
  4785. ddb_entry->conn = cls_conn;
  4786. /* Setup ep, for displaying attributes in sysfs */
  4787. ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
  4788. if (ep) {
  4789. ep->conn = cls_conn;
  4790. cls_conn->ep = ep;
  4791. } else {
  4792. DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
  4793. ret = QLA_ERROR;
  4794. goto exit_setup;
  4795. }
  4796. /* Update sess/conn params */
  4797. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  4798. qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
  4799. if (is_reset == RESET_ADAPTER) {
  4800. iscsi_block_session(cls_sess);
  4801. /* Use the relogin path to discover new devices
  4802. * by short-circuting the logic of setting
  4803. * timer to relogin - instead set the flags
  4804. * to initiate login right away.
  4805. */
  4806. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  4807. set_bit(DF_RELOGIN, &ddb_entry->flags);
  4808. }
  4809. exit_setup:
  4810. return ret;
  4811. }
  4812. static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
  4813. struct list_head *list_ddb,
  4814. struct dev_db_entry *fw_ddb_entry)
  4815. {
  4816. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  4817. uint16_t ddb_link;
  4818. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  4819. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  4820. if (ddb_idx->fw_ddb_idx == ddb_link) {
  4821. DEBUG2(ql4_printk(KERN_INFO, ha,
  4822. "Updating NT parent idx from [%d] to [%d]\n",
  4823. ddb_link, ddb_idx->flash_ddb_idx));
  4824. fw_ddb_entry->ddb_link =
  4825. cpu_to_le16(ddb_idx->flash_ddb_idx);
  4826. return;
  4827. }
  4828. }
  4829. }
  4830. static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
  4831. struct list_head *list_nt,
  4832. struct list_head *list_st,
  4833. int is_reset)
  4834. {
  4835. struct dev_db_entry *fw_ddb_entry;
  4836. struct ddb_entry *ddb_entry = NULL;
  4837. dma_addr_t fw_ddb_dma;
  4838. int max_ddbs;
  4839. int fw_idx_size;
  4840. int ret;
  4841. uint32_t idx = 0, next_idx = 0;
  4842. uint32_t state = 0, conn_err = 0;
  4843. uint32_t ddb_idx = -1;
  4844. uint16_t conn_id = 0;
  4845. uint16_t ddb_link = -1;
  4846. struct qla_ddb_index *nt_ddb_idx;
  4847. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4848. &fw_ddb_dma);
  4849. if (fw_ddb_entry == NULL) {
  4850. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4851. goto exit_nt_list;
  4852. }
  4853. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4854. MAX_DEV_DB_ENTRIES;
  4855. fw_idx_size = sizeof(struct qla_ddb_index);
  4856. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4857. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4858. NULL, &next_idx, &state,
  4859. &conn_err, NULL, &conn_id);
  4860. if (ret == QLA_ERROR)
  4861. break;
  4862. if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
  4863. goto continue_next_nt;
  4864. /* Check if NT, then add to list it */
  4865. if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
  4866. goto continue_next_nt;
  4867. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  4868. if (ddb_link < max_ddbs)
  4869. qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
  4870. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
  4871. state == DDB_DS_SESSION_FAILED) &&
  4872. (is_reset == INIT_ADAPTER))
  4873. goto continue_next_nt;
  4874. DEBUG2(ql4_printk(KERN_INFO, ha,
  4875. "Adding DDB to session = 0x%x\n", idx));
  4876. if (is_reset == INIT_ADAPTER) {
  4877. nt_ddb_idx = vmalloc(fw_idx_size);
  4878. if (!nt_ddb_idx)
  4879. break;
  4880. nt_ddb_idx->fw_ddb_idx = idx;
  4881. /* Copy original isid as it may get updated in function
  4882. * qla4xxx_update_isid(). We need original isid in
  4883. * function qla4xxx_compare_tuple_ddb to find duplicate
  4884. * target */
  4885. memcpy(&nt_ddb_idx->flash_isid[0],
  4886. &fw_ddb_entry->isid[0],
  4887. sizeof(nt_ddb_idx->flash_isid));
  4888. ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
  4889. fw_ddb_entry);
  4890. if (ret == QLA_SUCCESS) {
  4891. /* free nt_ddb_idx and do not add to list_nt */
  4892. vfree(nt_ddb_idx);
  4893. goto continue_next_nt;
  4894. }
  4895. /* Copy updated isid */
  4896. memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
  4897. sizeof(struct dev_db_entry));
  4898. list_add_tail(&nt_ddb_idx->list, list_nt);
  4899. } else if (is_reset == RESET_ADAPTER) {
  4900. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
  4901. &ddb_idx);
  4902. if (ret == QLA_SUCCESS) {
  4903. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
  4904. ddb_idx);
  4905. if (ddb_entry != NULL)
  4906. qla4xxx_update_sess_disc_idx(ha,
  4907. ddb_entry,
  4908. fw_ddb_entry);
  4909. goto continue_next_nt;
  4910. }
  4911. }
  4912. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
  4913. if (ret == QLA_ERROR)
  4914. goto exit_nt_list;
  4915. continue_next_nt:
  4916. if (next_idx == 0)
  4917. break;
  4918. }
  4919. exit_nt_list:
  4920. if (fw_ddb_entry)
  4921. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4922. }
  4923. static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
  4924. struct list_head *list_nt,
  4925. uint16_t target_id)
  4926. {
  4927. struct dev_db_entry *fw_ddb_entry;
  4928. dma_addr_t fw_ddb_dma;
  4929. int max_ddbs;
  4930. int fw_idx_size;
  4931. int ret;
  4932. uint32_t idx = 0, next_idx = 0;
  4933. uint32_t state = 0, conn_err = 0;
  4934. uint16_t conn_id = 0;
  4935. struct qla_ddb_index *nt_ddb_idx;
  4936. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  4937. &fw_ddb_dma);
  4938. if (fw_ddb_entry == NULL) {
  4939. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  4940. goto exit_new_nt_list;
  4941. }
  4942. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  4943. MAX_DEV_DB_ENTRIES;
  4944. fw_idx_size = sizeof(struct qla_ddb_index);
  4945. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  4946. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  4947. NULL, &next_idx, &state,
  4948. &conn_err, NULL, &conn_id);
  4949. if (ret == QLA_ERROR)
  4950. break;
  4951. /* Check if NT, then add it to list */
  4952. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  4953. goto continue_next_new_nt;
  4954. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
  4955. goto continue_next_new_nt;
  4956. DEBUG2(ql4_printk(KERN_INFO, ha,
  4957. "Adding DDB to session = 0x%x\n", idx));
  4958. nt_ddb_idx = vmalloc(fw_idx_size);
  4959. if (!nt_ddb_idx)
  4960. break;
  4961. nt_ddb_idx->fw_ddb_idx = idx;
  4962. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
  4963. if (ret == QLA_SUCCESS) {
  4964. /* free nt_ddb_idx and do not add to list_nt */
  4965. vfree(nt_ddb_idx);
  4966. goto continue_next_new_nt;
  4967. }
  4968. if (target_id < max_ddbs)
  4969. fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
  4970. list_add_tail(&nt_ddb_idx->list, list_nt);
  4971. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  4972. idx);
  4973. if (ret == QLA_ERROR)
  4974. goto exit_new_nt_list;
  4975. continue_next_new_nt:
  4976. if (next_idx == 0)
  4977. break;
  4978. }
  4979. exit_new_nt_list:
  4980. if (fw_ddb_entry)
  4981. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  4982. }
  4983. /**
  4984. * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
  4985. * @dev: dev associated with the sysfs entry
  4986. * @data: pointer to flashnode session object
  4987. *
  4988. * Returns:
  4989. * 1: if flashnode entry is non-persistent
  4990. * 0: if flashnode entry is persistent
  4991. **/
  4992. static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
  4993. {
  4994. struct iscsi_bus_flash_session *fnode_sess;
  4995. if (!iscsi_flashnode_bus_match(dev, NULL))
  4996. return 0;
  4997. fnode_sess = iscsi_dev_to_flash_session(dev);
  4998. return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
  4999. }
  5000. /**
  5001. * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
  5002. * @ha: pointer to host
  5003. * @fw_ddb_entry: flash ddb data
  5004. * @idx: target index
  5005. * @user: if set then this call is made from userland else from kernel
  5006. *
  5007. * Returns:
  5008. * On sucess: QLA_SUCCESS
  5009. * On failure: QLA_ERROR
  5010. *
  5011. * This create separate sysfs entries for session and connection attributes of
  5012. * the given fw ddb entry.
  5013. * If this is invoked as a result of a userspace call then the entry is marked
  5014. * as nonpersistent using flash_state field.
  5015. **/
  5016. static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
  5017. struct dev_db_entry *fw_ddb_entry,
  5018. uint16_t *idx, int user)
  5019. {
  5020. struct iscsi_bus_flash_session *fnode_sess = NULL;
  5021. struct iscsi_bus_flash_conn *fnode_conn = NULL;
  5022. int rc = QLA_ERROR;
  5023. fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
  5024. &qla4xxx_iscsi_transport, 0);
  5025. if (!fnode_sess) {
  5026. ql4_printk(KERN_ERR, ha,
  5027. "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
  5028. __func__, *idx, ha->host_no);
  5029. goto exit_tgt_create;
  5030. }
  5031. fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
  5032. &qla4xxx_iscsi_transport, 0);
  5033. if (!fnode_conn) {
  5034. ql4_printk(KERN_ERR, ha,
  5035. "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
  5036. __func__, *idx, ha->host_no);
  5037. goto free_sess;
  5038. }
  5039. if (user) {
  5040. fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
  5041. } else {
  5042. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  5043. if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
  5044. fnode_sess->is_boot_target = 1;
  5045. else
  5046. fnode_sess->is_boot_target = 0;
  5047. }
  5048. rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
  5049. fw_ddb_entry);
  5050. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  5051. __func__, fnode_sess->dev.kobj.name);
  5052. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  5053. __func__, fnode_conn->dev.kobj.name);
  5054. return QLA_SUCCESS;
  5055. free_sess:
  5056. iscsi_destroy_flashnode_sess(fnode_sess);
  5057. exit_tgt_create:
  5058. return QLA_ERROR;
  5059. }
  5060. /**
  5061. * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
  5062. * @shost: pointer to host
  5063. * @buf: type of ddb entry (ipv4/ipv6)
  5064. * @len: length of buf
  5065. *
  5066. * This creates new ddb entry in the flash by finding first free index and
  5067. * storing default ddb there. And then create sysfs entry for the new ddb entry.
  5068. **/
  5069. static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
  5070. int len)
  5071. {
  5072. struct scsi_qla_host *ha = to_qla_host(shost);
  5073. struct dev_db_entry *fw_ddb_entry = NULL;
  5074. dma_addr_t fw_ddb_entry_dma;
  5075. struct device *dev;
  5076. uint16_t idx = 0;
  5077. uint16_t max_ddbs = 0;
  5078. uint32_t options = 0;
  5079. uint32_t rval = QLA_ERROR;
  5080. if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
  5081. strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
  5082. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
  5083. __func__));
  5084. goto exit_ddb_add;
  5085. }
  5086. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  5087. MAX_DEV_DB_ENTRIES;
  5088. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5089. &fw_ddb_entry_dma, GFP_KERNEL);
  5090. if (!fw_ddb_entry) {
  5091. DEBUG2(ql4_printk(KERN_ERR, ha,
  5092. "%s: Unable to allocate dma buffer\n",
  5093. __func__));
  5094. goto exit_ddb_add;
  5095. }
  5096. dev = iscsi_find_flashnode_sess(ha->host, NULL,
  5097. qla4xxx_sysfs_ddb_is_non_persistent);
  5098. if (dev) {
  5099. ql4_printk(KERN_ERR, ha,
  5100. "%s: A non-persistent entry %s found\n",
  5101. __func__, dev->kobj.name);
  5102. put_device(dev);
  5103. goto exit_ddb_add;
  5104. }
  5105. /* Index 0 and 1 are reserved for boot target entries */
  5106. for (idx = 2; idx < max_ddbs; idx++) {
  5107. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
  5108. fw_ddb_entry_dma, idx))
  5109. break;
  5110. }
  5111. if (idx == max_ddbs)
  5112. goto exit_ddb_add;
  5113. if (!strncasecmp("ipv6", buf, 4))
  5114. options |= IPV6_DEFAULT_DDB_ENTRY;
  5115. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  5116. if (rval == QLA_ERROR)
  5117. goto exit_ddb_add;
  5118. rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
  5119. exit_ddb_add:
  5120. if (fw_ddb_entry)
  5121. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5122. fw_ddb_entry, fw_ddb_entry_dma);
  5123. if (rval == QLA_SUCCESS)
  5124. return idx;
  5125. else
  5126. return -EIO;
  5127. }
  5128. /**
  5129. * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
  5130. * @fnode_sess: pointer to session attrs of flash ddb entry
  5131. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5132. *
  5133. * This writes the contents of target ddb buffer to Flash with a valid cookie
  5134. * value in order to make the ddb entry persistent.
  5135. **/
  5136. static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
  5137. struct iscsi_bus_flash_conn *fnode_conn)
  5138. {
  5139. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5140. struct scsi_qla_host *ha = to_qla_host(shost);
  5141. uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  5142. struct dev_db_entry *fw_ddb_entry = NULL;
  5143. dma_addr_t fw_ddb_entry_dma;
  5144. uint32_t options = 0;
  5145. int rval = 0;
  5146. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5147. &fw_ddb_entry_dma, GFP_KERNEL);
  5148. if (!fw_ddb_entry) {
  5149. DEBUG2(ql4_printk(KERN_ERR, ha,
  5150. "%s: Unable to allocate dma buffer\n",
  5151. __func__));
  5152. rval = -ENOMEM;
  5153. goto exit_ddb_apply;
  5154. }
  5155. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5156. options |= IPV6_DEFAULT_DDB_ENTRY;
  5157. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  5158. if (rval == QLA_ERROR)
  5159. goto exit_ddb_apply;
  5160. dev_db_start_offset += (fnode_sess->target_id *
  5161. sizeof(*fw_ddb_entry));
  5162. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  5163. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  5164. rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  5165. sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
  5166. if (rval == QLA_SUCCESS) {
  5167. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  5168. ql4_printk(KERN_INFO, ha,
  5169. "%s: flash node %u of host %lu written to flash\n",
  5170. __func__, fnode_sess->target_id, ha->host_no);
  5171. } else {
  5172. rval = -EIO;
  5173. ql4_printk(KERN_ERR, ha,
  5174. "%s: Error while writing flash node %u of host %lu to flash\n",
  5175. __func__, fnode_sess->target_id, ha->host_no);
  5176. }
  5177. exit_ddb_apply:
  5178. if (fw_ddb_entry)
  5179. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5180. fw_ddb_entry, fw_ddb_entry_dma);
  5181. return rval;
  5182. }
  5183. static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
  5184. struct dev_db_entry *fw_ddb_entry,
  5185. uint16_t idx)
  5186. {
  5187. struct dev_db_entry *ddb_entry = NULL;
  5188. dma_addr_t ddb_entry_dma;
  5189. unsigned long wtime;
  5190. uint32_t mbx_sts = 0;
  5191. uint32_t state = 0, conn_err = 0;
  5192. uint16_t tmo = 0;
  5193. int ret = 0;
  5194. ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  5195. &ddb_entry_dma, GFP_KERNEL);
  5196. if (!ddb_entry) {
  5197. DEBUG2(ql4_printk(KERN_ERR, ha,
  5198. "%s: Unable to allocate dma buffer\n",
  5199. __func__));
  5200. return QLA_ERROR;
  5201. }
  5202. memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
  5203. ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
  5204. if (ret != QLA_SUCCESS) {
  5205. DEBUG2(ql4_printk(KERN_ERR, ha,
  5206. "%s: Unable to set ddb entry for index %d\n",
  5207. __func__, idx));
  5208. goto exit_ddb_conn_open;
  5209. }
  5210. qla4xxx_conn_open(ha, idx);
  5211. /* To ensure that sendtargets is done, wait for at least 12 secs */
  5212. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  5213. (ha->def_timeout < LOGIN_TOV * 10) ?
  5214. ha->def_timeout : LOGIN_TOV);
  5215. DEBUG2(ql4_printk(KERN_INFO, ha,
  5216. "Default time to wait for login to ddb %d\n", tmo));
  5217. wtime = jiffies + (HZ * tmo);
  5218. do {
  5219. ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
  5220. NULL, &state, &conn_err, NULL,
  5221. NULL);
  5222. if (ret == QLA_ERROR)
  5223. continue;
  5224. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  5225. state == DDB_DS_SESSION_FAILED)
  5226. break;
  5227. schedule_timeout_uninterruptible(HZ / 10);
  5228. } while (time_after(wtime, jiffies));
  5229. exit_ddb_conn_open:
  5230. if (ddb_entry)
  5231. dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  5232. ddb_entry, ddb_entry_dma);
  5233. return ret;
  5234. }
  5235. static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
  5236. struct dev_db_entry *fw_ddb_entry,
  5237. uint16_t target_id)
  5238. {
  5239. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  5240. struct list_head list_nt;
  5241. uint16_t ddb_index;
  5242. int ret = 0;
  5243. if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
  5244. ql4_printk(KERN_WARNING, ha,
  5245. "%s: A discovery already in progress!\n", __func__);
  5246. return QLA_ERROR;
  5247. }
  5248. INIT_LIST_HEAD(&list_nt);
  5249. set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  5250. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  5251. if (ret == QLA_ERROR)
  5252. goto exit_login_st_clr_bit;
  5253. ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
  5254. if (ret == QLA_ERROR)
  5255. goto exit_login_st;
  5256. qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
  5257. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
  5258. list_del_init(&ddb_idx->list);
  5259. qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
  5260. vfree(ddb_idx);
  5261. }
  5262. exit_login_st:
  5263. if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
  5264. ql4_printk(KERN_ERR, ha,
  5265. "Unable to clear DDB index = 0x%x\n", ddb_index);
  5266. }
  5267. clear_bit(ddb_index, ha->ddb_idx_map);
  5268. exit_login_st_clr_bit:
  5269. clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  5270. return ret;
  5271. }
  5272. static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
  5273. struct dev_db_entry *fw_ddb_entry,
  5274. uint16_t idx)
  5275. {
  5276. int ret = QLA_ERROR;
  5277. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
  5278. if (ret != QLA_SUCCESS)
  5279. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  5280. idx);
  5281. else
  5282. ret = -EPERM;
  5283. return ret;
  5284. }
  5285. /**
  5286. * qla4xxx_sysfs_ddb_login - Login to the specified target
  5287. * @fnode_sess: pointer to session attrs of flash ddb entry
  5288. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5289. *
  5290. * This logs in to the specified target
  5291. **/
  5292. static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
  5293. struct iscsi_bus_flash_conn *fnode_conn)
  5294. {
  5295. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5296. struct scsi_qla_host *ha = to_qla_host(shost);
  5297. struct dev_db_entry *fw_ddb_entry = NULL;
  5298. dma_addr_t fw_ddb_entry_dma;
  5299. uint32_t options = 0;
  5300. int ret = 0;
  5301. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
  5302. ql4_printk(KERN_ERR, ha,
  5303. "%s: Target info is not persistent\n", __func__);
  5304. ret = -EIO;
  5305. goto exit_ddb_login;
  5306. }
  5307. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5308. &fw_ddb_entry_dma, GFP_KERNEL);
  5309. if (!fw_ddb_entry) {
  5310. DEBUG2(ql4_printk(KERN_ERR, ha,
  5311. "%s: Unable to allocate dma buffer\n",
  5312. __func__));
  5313. ret = -ENOMEM;
  5314. goto exit_ddb_login;
  5315. }
  5316. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5317. options |= IPV6_DEFAULT_DDB_ENTRY;
  5318. ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  5319. if (ret == QLA_ERROR)
  5320. goto exit_ddb_login;
  5321. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  5322. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  5323. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  5324. ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
  5325. fnode_sess->target_id);
  5326. else
  5327. ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
  5328. fnode_sess->target_id);
  5329. if (ret > 0)
  5330. ret = -EIO;
  5331. exit_ddb_login:
  5332. if (fw_ddb_entry)
  5333. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5334. fw_ddb_entry, fw_ddb_entry_dma);
  5335. return ret;
  5336. }
  5337. /**
  5338. * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
  5339. * @cls_sess: pointer to session to be logged out
  5340. *
  5341. * This performs session log out from the specified target
  5342. **/
  5343. static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
  5344. {
  5345. struct iscsi_session *sess;
  5346. struct ddb_entry *ddb_entry = NULL;
  5347. struct scsi_qla_host *ha;
  5348. struct dev_db_entry *fw_ddb_entry = NULL;
  5349. dma_addr_t fw_ddb_entry_dma;
  5350. unsigned long flags;
  5351. unsigned long wtime;
  5352. uint32_t ddb_state;
  5353. int options;
  5354. int ret = 0;
  5355. sess = cls_sess->dd_data;
  5356. ddb_entry = sess->dd_data;
  5357. ha = ddb_entry->ha;
  5358. if (ddb_entry->ddb_type != FLASH_DDB) {
  5359. ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
  5360. __func__);
  5361. ret = -ENXIO;
  5362. goto exit_ddb_logout;
  5363. }
  5364. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  5365. ql4_printk(KERN_ERR, ha,
  5366. "%s: Logout from boot target entry is not permitted.\n",
  5367. __func__);
  5368. ret = -EPERM;
  5369. goto exit_ddb_logout;
  5370. }
  5371. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5372. &fw_ddb_entry_dma, GFP_KERNEL);
  5373. if (!fw_ddb_entry) {
  5374. ql4_printk(KERN_ERR, ha,
  5375. "%s: Unable to allocate dma buffer\n", __func__);
  5376. ret = -ENOMEM;
  5377. goto exit_ddb_logout;
  5378. }
  5379. if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  5380. goto ddb_logout_init;
  5381. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  5382. fw_ddb_entry, fw_ddb_entry_dma,
  5383. NULL, NULL, &ddb_state, NULL,
  5384. NULL, NULL);
  5385. if (ret == QLA_ERROR)
  5386. goto ddb_logout_init;
  5387. if (ddb_state == DDB_DS_SESSION_ACTIVE)
  5388. goto ddb_logout_init;
  5389. /* wait until next relogin is triggered using DF_RELOGIN and
  5390. * clear DF_RELOGIN to avoid invocation of further relogin
  5391. */
  5392. wtime = jiffies + (HZ * RELOGIN_TOV);
  5393. do {
  5394. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
  5395. goto ddb_logout_init;
  5396. schedule_timeout_uninterruptible(HZ);
  5397. } while ((time_after(wtime, jiffies)));
  5398. ddb_logout_init:
  5399. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  5400. atomic_set(&ddb_entry->relogin_timer, 0);
  5401. options = LOGOUT_OPTION_CLOSE_SESSION;
  5402. qla4xxx_session_logout_ddb(ha, ddb_entry, options);
  5403. memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
  5404. wtime = jiffies + (HZ * LOGOUT_TOV);
  5405. do {
  5406. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  5407. fw_ddb_entry, fw_ddb_entry_dma,
  5408. NULL, NULL, &ddb_state, NULL,
  5409. NULL, NULL);
  5410. if (ret == QLA_ERROR)
  5411. goto ddb_logout_clr_sess;
  5412. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  5413. (ddb_state == DDB_DS_SESSION_FAILED))
  5414. goto ddb_logout_clr_sess;
  5415. schedule_timeout_uninterruptible(HZ);
  5416. } while ((time_after(wtime, jiffies)));
  5417. ddb_logout_clr_sess:
  5418. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  5419. /*
  5420. * we have decremented the reference count of the driver
  5421. * when we setup the session to have the driver unload
  5422. * to be seamless without actually destroying the
  5423. * session
  5424. **/
  5425. try_module_get(qla4xxx_iscsi_transport.owner);
  5426. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  5427. spin_lock_irqsave(&ha->hardware_lock, flags);
  5428. qla4xxx_free_ddb(ha, ddb_entry);
  5429. clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
  5430. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  5431. iscsi_session_teardown(ddb_entry->sess);
  5432. clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
  5433. ret = QLA_SUCCESS;
  5434. exit_ddb_logout:
  5435. if (fw_ddb_entry)
  5436. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5437. fw_ddb_entry, fw_ddb_entry_dma);
  5438. return ret;
  5439. }
  5440. /**
  5441. * qla4xxx_sysfs_ddb_logout - Logout from the specified target
  5442. * @fnode_sess: pointer to session attrs of flash ddb entry
  5443. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5444. *
  5445. * This performs log out from the specified target
  5446. **/
  5447. static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
  5448. struct iscsi_bus_flash_conn *fnode_conn)
  5449. {
  5450. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5451. struct scsi_qla_host *ha = to_qla_host(shost);
  5452. struct ql4_tuple_ddb *flash_tddb = NULL;
  5453. struct ql4_tuple_ddb *tmp_tddb = NULL;
  5454. struct dev_db_entry *fw_ddb_entry = NULL;
  5455. struct ddb_entry *ddb_entry = NULL;
  5456. dma_addr_t fw_ddb_dma;
  5457. uint32_t next_idx = 0;
  5458. uint32_t state = 0, conn_err = 0;
  5459. uint16_t conn_id = 0;
  5460. int idx, index;
  5461. int status, ret = 0;
  5462. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  5463. &fw_ddb_dma);
  5464. if (fw_ddb_entry == NULL) {
  5465. ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
  5466. ret = -ENOMEM;
  5467. goto exit_ddb_logout;
  5468. }
  5469. flash_tddb = vzalloc(sizeof(*flash_tddb));
  5470. if (!flash_tddb) {
  5471. ql4_printk(KERN_WARNING, ha,
  5472. "%s:Memory Allocation failed.\n", __func__);
  5473. ret = -ENOMEM;
  5474. goto exit_ddb_logout;
  5475. }
  5476. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  5477. if (!tmp_tddb) {
  5478. ql4_printk(KERN_WARNING, ha,
  5479. "%s:Memory Allocation failed.\n", __func__);
  5480. ret = -ENOMEM;
  5481. goto exit_ddb_logout;
  5482. }
  5483. if (!fnode_sess->targetname) {
  5484. ql4_printk(KERN_ERR, ha,
  5485. "%s:Cannot logout from SendTarget entry\n",
  5486. __func__);
  5487. ret = -EPERM;
  5488. goto exit_ddb_logout;
  5489. }
  5490. if (fnode_sess->is_boot_target) {
  5491. ql4_printk(KERN_ERR, ha,
  5492. "%s: Logout from boot target entry is not permitted.\n",
  5493. __func__);
  5494. ret = -EPERM;
  5495. goto exit_ddb_logout;
  5496. }
  5497. strncpy(flash_tddb->iscsi_name, fnode_sess->targetname,
  5498. ISCSI_NAME_SIZE);
  5499. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5500. sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
  5501. else
  5502. sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
  5503. flash_tddb->tpgt = fnode_sess->tpgt;
  5504. flash_tddb->port = fnode_conn->port;
  5505. COPY_ISID(flash_tddb->isid, fnode_sess->isid);
  5506. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  5507. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  5508. if (ddb_entry == NULL)
  5509. continue;
  5510. if (ddb_entry->ddb_type != FLASH_DDB)
  5511. continue;
  5512. index = ddb_entry->sess->target_id;
  5513. status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
  5514. fw_ddb_dma, NULL, &next_idx,
  5515. &state, &conn_err, NULL,
  5516. &conn_id);
  5517. if (status == QLA_ERROR) {
  5518. ret = -ENOMEM;
  5519. break;
  5520. }
  5521. qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
  5522. status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
  5523. true);
  5524. if (status == QLA_SUCCESS) {
  5525. ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
  5526. break;
  5527. }
  5528. }
  5529. if (idx == MAX_DDB_ENTRIES)
  5530. ret = -ESRCH;
  5531. exit_ddb_logout:
  5532. if (flash_tddb)
  5533. vfree(flash_tddb);
  5534. if (tmp_tddb)
  5535. vfree(tmp_tddb);
  5536. if (fw_ddb_entry)
  5537. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  5538. return ret;
  5539. }
  5540. static int
  5541. qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
  5542. int param, char *buf)
  5543. {
  5544. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5545. struct scsi_qla_host *ha = to_qla_host(shost);
  5546. struct iscsi_bus_flash_conn *fnode_conn;
  5547. struct ql4_chap_table chap_tbl;
  5548. struct device *dev;
  5549. int parent_type;
  5550. int rc = 0;
  5551. dev = iscsi_find_flashnode_conn(fnode_sess);
  5552. if (!dev)
  5553. return -EIO;
  5554. fnode_conn = iscsi_dev_to_flash_conn(dev);
  5555. switch (param) {
  5556. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  5557. rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
  5558. break;
  5559. case ISCSI_FLASHNODE_PORTAL_TYPE:
  5560. rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
  5561. break;
  5562. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  5563. rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
  5564. break;
  5565. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  5566. rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
  5567. break;
  5568. case ISCSI_FLASHNODE_ENTRY_EN:
  5569. rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
  5570. break;
  5571. case ISCSI_FLASHNODE_HDR_DGST_EN:
  5572. rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
  5573. break;
  5574. case ISCSI_FLASHNODE_DATA_DGST_EN:
  5575. rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
  5576. break;
  5577. case ISCSI_FLASHNODE_IMM_DATA_EN:
  5578. rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
  5579. break;
  5580. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  5581. rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
  5582. break;
  5583. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  5584. rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
  5585. break;
  5586. case ISCSI_FLASHNODE_PDU_INORDER:
  5587. rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
  5588. break;
  5589. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  5590. rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
  5591. break;
  5592. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  5593. rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
  5594. break;
  5595. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  5596. rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
  5597. break;
  5598. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  5599. rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
  5600. break;
  5601. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  5602. rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
  5603. break;
  5604. case ISCSI_FLASHNODE_ERL:
  5605. rc = sprintf(buf, "%u\n", fnode_sess->erl);
  5606. break;
  5607. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  5608. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
  5609. break;
  5610. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  5611. rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
  5612. break;
  5613. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  5614. rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
  5615. break;
  5616. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  5617. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
  5618. break;
  5619. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  5620. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
  5621. break;
  5622. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  5623. rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
  5624. break;
  5625. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  5626. rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
  5627. break;
  5628. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  5629. rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
  5630. break;
  5631. case ISCSI_FLASHNODE_FIRST_BURST:
  5632. rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
  5633. break;
  5634. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  5635. rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
  5636. break;
  5637. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  5638. rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
  5639. break;
  5640. case ISCSI_FLASHNODE_MAX_R2T:
  5641. rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
  5642. break;
  5643. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  5644. rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
  5645. break;
  5646. case ISCSI_FLASHNODE_ISID:
  5647. rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
  5648. fnode_sess->isid[0], fnode_sess->isid[1],
  5649. fnode_sess->isid[2], fnode_sess->isid[3],
  5650. fnode_sess->isid[4], fnode_sess->isid[5]);
  5651. break;
  5652. case ISCSI_FLASHNODE_TSID:
  5653. rc = sprintf(buf, "%u\n", fnode_sess->tsid);
  5654. break;
  5655. case ISCSI_FLASHNODE_PORT:
  5656. rc = sprintf(buf, "%d\n", fnode_conn->port);
  5657. break;
  5658. case ISCSI_FLASHNODE_MAX_BURST:
  5659. rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
  5660. break;
  5661. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  5662. rc = sprintf(buf, "%u\n",
  5663. fnode_sess->default_taskmgmt_timeout);
  5664. break;
  5665. case ISCSI_FLASHNODE_IPADDR:
  5666. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5667. rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
  5668. else
  5669. rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
  5670. break;
  5671. case ISCSI_FLASHNODE_ALIAS:
  5672. if (fnode_sess->targetalias)
  5673. rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
  5674. else
  5675. rc = sprintf(buf, "\n");
  5676. break;
  5677. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  5678. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5679. rc = sprintf(buf, "%pI6\n",
  5680. fnode_conn->redirect_ipaddr);
  5681. else
  5682. rc = sprintf(buf, "%pI4\n",
  5683. fnode_conn->redirect_ipaddr);
  5684. break;
  5685. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  5686. rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
  5687. break;
  5688. case ISCSI_FLASHNODE_LOCAL_PORT:
  5689. rc = sprintf(buf, "%u\n", fnode_conn->local_port);
  5690. break;
  5691. case ISCSI_FLASHNODE_IPV4_TOS:
  5692. rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
  5693. break;
  5694. case ISCSI_FLASHNODE_IPV6_TC:
  5695. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5696. rc = sprintf(buf, "%u\n",
  5697. fnode_conn->ipv6_traffic_class);
  5698. else
  5699. rc = sprintf(buf, "\n");
  5700. break;
  5701. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  5702. rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
  5703. break;
  5704. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  5705. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  5706. rc = sprintf(buf, "%pI6\n",
  5707. fnode_conn->link_local_ipv6_addr);
  5708. else
  5709. rc = sprintf(buf, "\n");
  5710. break;
  5711. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  5712. rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
  5713. break;
  5714. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  5715. if (fnode_sess->discovery_parent_type == DDB_ISNS)
  5716. parent_type = ISCSI_DISC_PARENT_ISNS;
  5717. else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
  5718. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  5719. else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
  5720. parent_type = ISCSI_DISC_PARENT_SENDTGT;
  5721. else
  5722. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  5723. rc = sprintf(buf, "%s\n",
  5724. iscsi_get_discovery_parent_name(parent_type));
  5725. break;
  5726. case ISCSI_FLASHNODE_NAME:
  5727. if (fnode_sess->targetname)
  5728. rc = sprintf(buf, "%s\n", fnode_sess->targetname);
  5729. else
  5730. rc = sprintf(buf, "\n");
  5731. break;
  5732. case ISCSI_FLASHNODE_TPGT:
  5733. rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
  5734. break;
  5735. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  5736. rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
  5737. break;
  5738. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  5739. rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
  5740. break;
  5741. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  5742. rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
  5743. break;
  5744. case ISCSI_FLASHNODE_USERNAME:
  5745. if (fnode_sess->chap_auth_en) {
  5746. qla4xxx_get_uni_chap_at_index(ha,
  5747. chap_tbl.name,
  5748. chap_tbl.secret,
  5749. fnode_sess->chap_out_idx);
  5750. rc = sprintf(buf, "%s\n", chap_tbl.name);
  5751. } else {
  5752. rc = sprintf(buf, "\n");
  5753. }
  5754. break;
  5755. case ISCSI_FLASHNODE_PASSWORD:
  5756. if (fnode_sess->chap_auth_en) {
  5757. qla4xxx_get_uni_chap_at_index(ha,
  5758. chap_tbl.name,
  5759. chap_tbl.secret,
  5760. fnode_sess->chap_out_idx);
  5761. rc = sprintf(buf, "%s\n", chap_tbl.secret);
  5762. } else {
  5763. rc = sprintf(buf, "\n");
  5764. }
  5765. break;
  5766. case ISCSI_FLASHNODE_STATSN:
  5767. rc = sprintf(buf, "%u\n", fnode_conn->statsn);
  5768. break;
  5769. case ISCSI_FLASHNODE_EXP_STATSN:
  5770. rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
  5771. break;
  5772. case ISCSI_FLASHNODE_IS_BOOT_TGT:
  5773. rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
  5774. break;
  5775. default:
  5776. rc = -ENOSYS;
  5777. break;
  5778. }
  5779. put_device(dev);
  5780. return rc;
  5781. }
  5782. /**
  5783. * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
  5784. * @fnode_sess: pointer to session attrs of flash ddb entry
  5785. * @fnode_conn: pointer to connection attrs of flash ddb entry
  5786. * @data: Parameters and their values to update
  5787. * @len: len of data
  5788. *
  5789. * This sets the parameter of flash ddb entry and writes them to flash
  5790. **/
  5791. static int
  5792. qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
  5793. struct iscsi_bus_flash_conn *fnode_conn,
  5794. void *data, int len)
  5795. {
  5796. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  5797. struct scsi_qla_host *ha = to_qla_host(shost);
  5798. struct iscsi_flashnode_param_info *fnode_param;
  5799. struct ql4_chap_table chap_tbl;
  5800. struct nlattr *attr;
  5801. uint16_t chap_out_idx = INVALID_ENTRY;
  5802. int rc = QLA_ERROR;
  5803. uint32_t rem = len;
  5804. memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
  5805. nla_for_each_attr(attr, data, len, rem) {
  5806. fnode_param = nla_data(attr);
  5807. switch (fnode_param->param) {
  5808. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  5809. fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
  5810. break;
  5811. case ISCSI_FLASHNODE_PORTAL_TYPE:
  5812. memcpy(fnode_sess->portal_type, fnode_param->value,
  5813. strlen(fnode_sess->portal_type));
  5814. break;
  5815. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  5816. fnode_sess->auto_snd_tgt_disable =
  5817. fnode_param->value[0];
  5818. break;
  5819. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  5820. fnode_sess->discovery_sess = fnode_param->value[0];
  5821. break;
  5822. case ISCSI_FLASHNODE_ENTRY_EN:
  5823. fnode_sess->entry_state = fnode_param->value[0];
  5824. break;
  5825. case ISCSI_FLASHNODE_HDR_DGST_EN:
  5826. fnode_conn->hdrdgst_en = fnode_param->value[0];
  5827. break;
  5828. case ISCSI_FLASHNODE_DATA_DGST_EN:
  5829. fnode_conn->datadgst_en = fnode_param->value[0];
  5830. break;
  5831. case ISCSI_FLASHNODE_IMM_DATA_EN:
  5832. fnode_sess->imm_data_en = fnode_param->value[0];
  5833. break;
  5834. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  5835. fnode_sess->initial_r2t_en = fnode_param->value[0];
  5836. break;
  5837. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  5838. fnode_sess->dataseq_inorder_en = fnode_param->value[0];
  5839. break;
  5840. case ISCSI_FLASHNODE_PDU_INORDER:
  5841. fnode_sess->pdu_inorder_en = fnode_param->value[0];
  5842. break;
  5843. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  5844. fnode_sess->chap_auth_en = fnode_param->value[0];
  5845. /* Invalidate chap index if chap auth is disabled */
  5846. if (!fnode_sess->chap_auth_en)
  5847. fnode_sess->chap_out_idx = INVALID_ENTRY;
  5848. break;
  5849. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  5850. fnode_conn->snack_req_en = fnode_param->value[0];
  5851. break;
  5852. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  5853. fnode_sess->discovery_logout_en = fnode_param->value[0];
  5854. break;
  5855. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  5856. fnode_sess->bidi_chap_en = fnode_param->value[0];
  5857. break;
  5858. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  5859. fnode_sess->discovery_auth_optional =
  5860. fnode_param->value[0];
  5861. break;
  5862. case ISCSI_FLASHNODE_ERL:
  5863. fnode_sess->erl = fnode_param->value[0];
  5864. break;
  5865. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  5866. fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
  5867. break;
  5868. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  5869. fnode_conn->tcp_nagle_disable = fnode_param->value[0];
  5870. break;
  5871. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  5872. fnode_conn->tcp_wsf_disable = fnode_param->value[0];
  5873. break;
  5874. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  5875. fnode_conn->tcp_timer_scale = fnode_param->value[0];
  5876. break;
  5877. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  5878. fnode_conn->tcp_timestamp_en = fnode_param->value[0];
  5879. break;
  5880. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  5881. fnode_conn->fragment_disable = fnode_param->value[0];
  5882. break;
  5883. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  5884. fnode_conn->max_recv_dlength =
  5885. *(unsigned *)fnode_param->value;
  5886. break;
  5887. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  5888. fnode_conn->max_xmit_dlength =
  5889. *(unsigned *)fnode_param->value;
  5890. break;
  5891. case ISCSI_FLASHNODE_FIRST_BURST:
  5892. fnode_sess->first_burst =
  5893. *(unsigned *)fnode_param->value;
  5894. break;
  5895. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  5896. fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
  5897. break;
  5898. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  5899. fnode_sess->time2retain =
  5900. *(uint16_t *)fnode_param->value;
  5901. break;
  5902. case ISCSI_FLASHNODE_MAX_R2T:
  5903. fnode_sess->max_r2t =
  5904. *(uint16_t *)fnode_param->value;
  5905. break;
  5906. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  5907. fnode_conn->keepalive_timeout =
  5908. *(uint16_t *)fnode_param->value;
  5909. break;
  5910. case ISCSI_FLASHNODE_ISID:
  5911. memcpy(fnode_sess->isid, fnode_param->value,
  5912. sizeof(fnode_sess->isid));
  5913. break;
  5914. case ISCSI_FLASHNODE_TSID:
  5915. fnode_sess->tsid = *(uint16_t *)fnode_param->value;
  5916. break;
  5917. case ISCSI_FLASHNODE_PORT:
  5918. fnode_conn->port = *(uint16_t *)fnode_param->value;
  5919. break;
  5920. case ISCSI_FLASHNODE_MAX_BURST:
  5921. fnode_sess->max_burst = *(unsigned *)fnode_param->value;
  5922. break;
  5923. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  5924. fnode_sess->default_taskmgmt_timeout =
  5925. *(uint16_t *)fnode_param->value;
  5926. break;
  5927. case ISCSI_FLASHNODE_IPADDR:
  5928. memcpy(fnode_conn->ipaddress, fnode_param->value,
  5929. IPv6_ADDR_LEN);
  5930. break;
  5931. case ISCSI_FLASHNODE_ALIAS:
  5932. rc = iscsi_switch_str_param(&fnode_sess->targetalias,
  5933. (char *)fnode_param->value);
  5934. break;
  5935. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  5936. memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
  5937. IPv6_ADDR_LEN);
  5938. break;
  5939. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  5940. fnode_conn->max_segment_size =
  5941. *(unsigned *)fnode_param->value;
  5942. break;
  5943. case ISCSI_FLASHNODE_LOCAL_PORT:
  5944. fnode_conn->local_port =
  5945. *(uint16_t *)fnode_param->value;
  5946. break;
  5947. case ISCSI_FLASHNODE_IPV4_TOS:
  5948. fnode_conn->ipv4_tos = fnode_param->value[0];
  5949. break;
  5950. case ISCSI_FLASHNODE_IPV6_TC:
  5951. fnode_conn->ipv6_traffic_class = fnode_param->value[0];
  5952. break;
  5953. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  5954. fnode_conn->ipv6_flow_label = fnode_param->value[0];
  5955. break;
  5956. case ISCSI_FLASHNODE_NAME:
  5957. rc = iscsi_switch_str_param(&fnode_sess->targetname,
  5958. (char *)fnode_param->value);
  5959. break;
  5960. case ISCSI_FLASHNODE_TPGT:
  5961. fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
  5962. break;
  5963. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  5964. memcpy(fnode_conn->link_local_ipv6_addr,
  5965. fnode_param->value, IPv6_ADDR_LEN);
  5966. break;
  5967. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  5968. fnode_sess->discovery_parent_idx =
  5969. *(uint16_t *)fnode_param->value;
  5970. break;
  5971. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  5972. fnode_conn->tcp_xmit_wsf =
  5973. *(uint8_t *)fnode_param->value;
  5974. break;
  5975. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  5976. fnode_conn->tcp_recv_wsf =
  5977. *(uint8_t *)fnode_param->value;
  5978. break;
  5979. case ISCSI_FLASHNODE_STATSN:
  5980. fnode_conn->statsn = *(uint32_t *)fnode_param->value;
  5981. break;
  5982. case ISCSI_FLASHNODE_EXP_STATSN:
  5983. fnode_conn->exp_statsn =
  5984. *(uint32_t *)fnode_param->value;
  5985. break;
  5986. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  5987. chap_out_idx = *(uint16_t *)fnode_param->value;
  5988. if (!qla4xxx_get_uni_chap_at_index(ha,
  5989. chap_tbl.name,
  5990. chap_tbl.secret,
  5991. chap_out_idx)) {
  5992. fnode_sess->chap_out_idx = chap_out_idx;
  5993. /* Enable chap auth if chap index is valid */
  5994. fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
  5995. }
  5996. break;
  5997. default:
  5998. ql4_printk(KERN_ERR, ha,
  5999. "%s: No such sysfs attribute\n", __func__);
  6000. rc = -ENOSYS;
  6001. goto exit_set_param;
  6002. }
  6003. }
  6004. rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
  6005. exit_set_param:
  6006. return rc;
  6007. }
  6008. /**
  6009. * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
  6010. * @fnode_sess: pointer to session attrs of flash ddb entry
  6011. *
  6012. * This invalidates the flash ddb entry at the given index
  6013. **/
  6014. static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
  6015. {
  6016. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6017. struct scsi_qla_host *ha = to_qla_host(shost);
  6018. uint32_t dev_db_start_offset;
  6019. uint32_t dev_db_end_offset;
  6020. struct dev_db_entry *fw_ddb_entry = NULL;
  6021. dma_addr_t fw_ddb_entry_dma;
  6022. uint16_t *ddb_cookie = NULL;
  6023. size_t ddb_size = 0;
  6024. void *pddb = NULL;
  6025. int target_id;
  6026. int rc = 0;
  6027. if (fnode_sess->is_boot_target) {
  6028. rc = -EPERM;
  6029. DEBUG2(ql4_printk(KERN_ERR, ha,
  6030. "%s: Deletion of boot target entry is not permitted.\n",
  6031. __func__));
  6032. goto exit_ddb_del;
  6033. }
  6034. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
  6035. goto sysfs_ddb_del;
  6036. if (is_qla40XX(ha)) {
  6037. dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  6038. dev_db_end_offset = FLASH_OFFSET_DB_END;
  6039. dev_db_start_offset += (fnode_sess->target_id *
  6040. sizeof(*fw_ddb_entry));
  6041. ddb_size = sizeof(*fw_ddb_entry);
  6042. } else {
  6043. dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
  6044. (ha->hw.flt_region_ddb << 2);
  6045. /* flt_ddb_size is DDB table size for both ports
  6046. * so divide it by 2 to calculate the offset for second port
  6047. */
  6048. if (ha->port_num == 1)
  6049. dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
  6050. dev_db_end_offset = dev_db_start_offset +
  6051. (ha->hw.flt_ddb_size / 2);
  6052. dev_db_start_offset += (fnode_sess->target_id *
  6053. sizeof(*fw_ddb_entry));
  6054. dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
  6055. ddb_size = sizeof(*ddb_cookie);
  6056. }
  6057. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
  6058. __func__, dev_db_start_offset, dev_db_end_offset));
  6059. if (dev_db_start_offset > dev_db_end_offset) {
  6060. rc = -EIO;
  6061. DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
  6062. __func__, fnode_sess->target_id));
  6063. goto exit_ddb_del;
  6064. }
  6065. pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
  6066. &fw_ddb_entry_dma, GFP_KERNEL);
  6067. if (!pddb) {
  6068. rc = -ENOMEM;
  6069. DEBUG2(ql4_printk(KERN_ERR, ha,
  6070. "%s: Unable to allocate dma buffer\n",
  6071. __func__));
  6072. goto exit_ddb_del;
  6073. }
  6074. if (is_qla40XX(ha)) {
  6075. fw_ddb_entry = pddb;
  6076. memset(fw_ddb_entry, 0, ddb_size);
  6077. ddb_cookie = &fw_ddb_entry->cookie;
  6078. } else {
  6079. ddb_cookie = pddb;
  6080. }
  6081. /* invalidate the cookie */
  6082. *ddb_cookie = 0xFFEE;
  6083. qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  6084. ddb_size, FLASH_OPT_RMW_COMMIT);
  6085. sysfs_ddb_del:
  6086. target_id = fnode_sess->target_id;
  6087. iscsi_destroy_flashnode_sess(fnode_sess);
  6088. ql4_printk(KERN_INFO, ha,
  6089. "%s: session and conn entries for flashnode %u of host %lu deleted\n",
  6090. __func__, target_id, ha->host_no);
  6091. exit_ddb_del:
  6092. if (pddb)
  6093. dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
  6094. fw_ddb_entry_dma);
  6095. return rc;
  6096. }
  6097. /**
  6098. * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
  6099. * @ha: pointer to adapter structure
  6100. *
  6101. * Export the firmware DDB for all send targets and normal targets to sysfs.
  6102. **/
  6103. static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
  6104. {
  6105. struct dev_db_entry *fw_ddb_entry = NULL;
  6106. dma_addr_t fw_ddb_entry_dma;
  6107. uint16_t max_ddbs;
  6108. uint16_t idx = 0;
  6109. int ret = QLA_SUCCESS;
  6110. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
  6111. sizeof(*fw_ddb_entry),
  6112. &fw_ddb_entry_dma, GFP_KERNEL);
  6113. if (!fw_ddb_entry) {
  6114. DEBUG2(ql4_printk(KERN_ERR, ha,
  6115. "%s: Unable to allocate dma buffer\n",
  6116. __func__));
  6117. return -ENOMEM;
  6118. }
  6119. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  6120. MAX_DEV_DB_ENTRIES;
  6121. for (idx = 0; idx < max_ddbs; idx++) {
  6122. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
  6123. idx))
  6124. continue;
  6125. ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
  6126. if (ret) {
  6127. ret = -EIO;
  6128. break;
  6129. }
  6130. }
  6131. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
  6132. fw_ddb_entry_dma);
  6133. return ret;
  6134. }
  6135. static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
  6136. {
  6137. iscsi_destroy_all_flashnode(ha->host);
  6138. }
  6139. /**
  6140. * qla4xxx_build_ddb_list - Build ddb list and setup sessions
  6141. * @ha: pointer to adapter structure
  6142. * @is_reset: Is this init path or reset path
  6143. *
  6144. * Create a list of sendtargets (st) from firmware DDBs, issue send targets
  6145. * using connection open, then create the list of normal targets (nt)
  6146. * from firmware DDBs. Based on the list of nt setup session and connection
  6147. * objects.
  6148. **/
  6149. void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
  6150. {
  6151. uint16_t tmo = 0;
  6152. struct list_head list_st, list_nt;
  6153. struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
  6154. unsigned long wtime;
  6155. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  6156. set_bit(AF_BUILD_DDB_LIST, &ha->flags);
  6157. ha->is_reset = is_reset;
  6158. return;
  6159. }
  6160. INIT_LIST_HEAD(&list_st);
  6161. INIT_LIST_HEAD(&list_nt);
  6162. qla4xxx_build_st_list(ha, &list_st);
  6163. /* Before issuing conn open mbox, ensure all IPs states are configured
  6164. * Note, conn open fails if IPs are not configured
  6165. */
  6166. qla4xxx_wait_for_ip_configuration(ha);
  6167. /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
  6168. list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
  6169. qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
  6170. }
  6171. /* Wait to ensure all sendtargets are done for min 12 sec wait */
  6172. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  6173. (ha->def_timeout < LOGIN_TOV * 10) ?
  6174. ha->def_timeout : LOGIN_TOV);
  6175. DEBUG2(ql4_printk(KERN_INFO, ha,
  6176. "Default time to wait for build ddb %d\n", tmo));
  6177. wtime = jiffies + (HZ * tmo);
  6178. do {
  6179. if (list_empty(&list_st))
  6180. break;
  6181. qla4xxx_remove_failed_ddb(ha, &list_st);
  6182. schedule_timeout_uninterruptible(HZ / 10);
  6183. } while (time_after(wtime, jiffies));
  6184. qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
  6185. qla4xxx_free_ddb_list(&list_st);
  6186. qla4xxx_free_ddb_list(&list_nt);
  6187. qla4xxx_free_ddb_index(ha);
  6188. }
  6189. /**
  6190. * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
  6191. * response.
  6192. * @ha: pointer to adapter structure
  6193. *
  6194. * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
  6195. * set in DDB and we will wait for login response of boot targets during
  6196. * probe.
  6197. **/
  6198. static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
  6199. {
  6200. struct ddb_entry *ddb_entry;
  6201. struct dev_db_entry *fw_ddb_entry = NULL;
  6202. dma_addr_t fw_ddb_entry_dma;
  6203. unsigned long wtime;
  6204. uint32_t ddb_state;
  6205. int max_ddbs, idx, ret;
  6206. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6207. MAX_DEV_DB_ENTRIES;
  6208. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6209. &fw_ddb_entry_dma, GFP_KERNEL);
  6210. if (!fw_ddb_entry) {
  6211. ql4_printk(KERN_ERR, ha,
  6212. "%s: Unable to allocate dma buffer\n", __func__);
  6213. goto exit_login_resp;
  6214. }
  6215. wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
  6216. for (idx = 0; idx < max_ddbs; idx++) {
  6217. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  6218. if (ddb_entry == NULL)
  6219. continue;
  6220. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  6221. DEBUG2(ql4_printk(KERN_INFO, ha,
  6222. "%s: DDB index [%d]\n", __func__,
  6223. ddb_entry->fw_ddb_index));
  6224. do {
  6225. ret = qla4xxx_get_fwddb_entry(ha,
  6226. ddb_entry->fw_ddb_index,
  6227. fw_ddb_entry, fw_ddb_entry_dma,
  6228. NULL, NULL, &ddb_state, NULL,
  6229. NULL, NULL);
  6230. if (ret == QLA_ERROR)
  6231. goto exit_login_resp;
  6232. if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
  6233. (ddb_state == DDB_DS_SESSION_FAILED))
  6234. break;
  6235. schedule_timeout_uninterruptible(HZ);
  6236. } while ((time_after(wtime, jiffies)));
  6237. if (!time_after(wtime, jiffies)) {
  6238. DEBUG2(ql4_printk(KERN_INFO, ha,
  6239. "%s: Login response wait timer expired\n",
  6240. __func__));
  6241. goto exit_login_resp;
  6242. }
  6243. }
  6244. }
  6245. exit_login_resp:
  6246. if (fw_ddb_entry)
  6247. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6248. fw_ddb_entry, fw_ddb_entry_dma);
  6249. }
  6250. /**
  6251. * qla4xxx_probe_adapter - callback function to probe HBA
  6252. * @pdev: pointer to pci_dev structure
  6253. * @pci_device_id: pointer to pci_device entry
  6254. *
  6255. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  6256. * It returns zero if successful. It also initializes all data necessary for
  6257. * the driver.
  6258. **/
  6259. static int qla4xxx_probe_adapter(struct pci_dev *pdev,
  6260. const struct pci_device_id *ent)
  6261. {
  6262. int ret = -ENODEV, status;
  6263. struct Scsi_Host *host;
  6264. struct scsi_qla_host *ha;
  6265. uint8_t init_retry_count = 0;
  6266. char buf[34];
  6267. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  6268. uint32_t dev_state;
  6269. if (pci_enable_device(pdev))
  6270. return -1;
  6271. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  6272. if (host == NULL) {
  6273. printk(KERN_WARNING
  6274. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  6275. goto probe_disable_device;
  6276. }
  6277. /* Clear our data area */
  6278. ha = to_qla_host(host);
  6279. memset(ha, 0, sizeof(*ha));
  6280. /* Save the information from PCI BIOS. */
  6281. ha->pdev = pdev;
  6282. ha->host = host;
  6283. ha->host_no = host->host_no;
  6284. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  6285. pci_enable_pcie_error_reporting(pdev);
  6286. /* Setup Runtime configurable options */
  6287. if (is_qla8022(ha)) {
  6288. ha->isp_ops = &qla4_82xx_isp_ops;
  6289. ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
  6290. ha->qdr_sn_window = -1;
  6291. ha->ddr_mn_window = -1;
  6292. ha->curr_window = 255;
  6293. nx_legacy_intr = &legacy_intr[ha->func_num];
  6294. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  6295. ha->nx_legacy_intr.tgt_status_reg =
  6296. nx_legacy_intr->tgt_status_reg;
  6297. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  6298. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  6299. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  6300. ha->isp_ops = &qla4_83xx_isp_ops;
  6301. ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
  6302. } else {
  6303. ha->isp_ops = &qla4xxx_isp_ops;
  6304. }
  6305. if (is_qla80XX(ha)) {
  6306. rwlock_init(&ha->hw_lock);
  6307. ha->pf_bit = ha->func_num << 16;
  6308. /* Set EEH reset type to fundamental if required by hba */
  6309. pdev->needs_freset = 1;
  6310. }
  6311. /* Configure PCI I/O space. */
  6312. ret = ha->isp_ops->iospace_config(ha);
  6313. if (ret)
  6314. goto probe_failed_ioconfig;
  6315. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  6316. pdev->device, pdev->irq, ha->reg);
  6317. qla4xxx_config_dma_addressing(ha);
  6318. /* Initialize lists and spinlocks. */
  6319. INIT_LIST_HEAD(&ha->free_srb_q);
  6320. mutex_init(&ha->mbox_sem);
  6321. mutex_init(&ha->chap_sem);
  6322. init_completion(&ha->mbx_intr_comp);
  6323. init_completion(&ha->disable_acb_comp);
  6324. spin_lock_init(&ha->hardware_lock);
  6325. spin_lock_init(&ha->work_lock);
  6326. /* Initialize work list */
  6327. INIT_LIST_HEAD(&ha->work_list);
  6328. /* Allocate dma buffers */
  6329. if (qla4xxx_mem_alloc(ha)) {
  6330. ql4_printk(KERN_WARNING, ha,
  6331. "[ERROR] Failed to allocate memory for adapter\n");
  6332. ret = -ENOMEM;
  6333. goto probe_failed;
  6334. }
  6335. host->cmd_per_lun = 3;
  6336. host->max_channel = 0;
  6337. host->max_lun = MAX_LUNS - 1;
  6338. host->max_id = MAX_TARGETS;
  6339. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  6340. host->can_queue = MAX_SRBS ;
  6341. host->transportt = qla4xxx_scsi_transport;
  6342. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  6343. if (ret) {
  6344. ql4_printk(KERN_WARNING, ha,
  6345. "%s: scsi_init_shared_tag_map failed\n", __func__);
  6346. goto probe_failed;
  6347. }
  6348. pci_set_drvdata(pdev, ha);
  6349. ret = scsi_add_host(host, &pdev->dev);
  6350. if (ret)
  6351. goto probe_failed;
  6352. if (is_qla80XX(ha))
  6353. qla4_8xxx_get_flash_info(ha);
  6354. if (is_qla8032(ha) || is_qla8042(ha)) {
  6355. qla4_83xx_read_reset_template(ha);
  6356. /*
  6357. * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  6358. * If DONRESET_BIT0 is set, drivers should not set dev_state
  6359. * to NEED_RESET. But if NEED_RESET is set, drivers should
  6360. * should honor the reset.
  6361. */
  6362. if (ql4xdontresethba == 1)
  6363. qla4_83xx_set_idc_dontreset(ha);
  6364. }
  6365. /*
  6366. * Initialize the Host adapter request/response queues and
  6367. * firmware
  6368. * NOTE: interrupts enabled upon successful completion
  6369. */
  6370. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  6371. /* Dont retry adapter initialization if IRQ allocation failed */
  6372. if (is_qla80XX(ha) && !test_bit(AF_IRQ_ATTACHED, &ha->flags)) {
  6373. ql4_printk(KERN_WARNING, ha, "%s: Skipping retry of adapter initialization\n",
  6374. __func__);
  6375. goto skip_retry_init;
  6376. }
  6377. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  6378. init_retry_count++ < MAX_INIT_RETRIES) {
  6379. if (is_qla80XX(ha)) {
  6380. ha->isp_ops->idc_lock(ha);
  6381. dev_state = qla4_8xxx_rd_direct(ha,
  6382. QLA8XXX_CRB_DEV_STATE);
  6383. ha->isp_ops->idc_unlock(ha);
  6384. if (dev_state == QLA8XXX_DEV_FAILED) {
  6385. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  6386. "initialize adapter. H/W is in failed state\n",
  6387. __func__);
  6388. break;
  6389. }
  6390. }
  6391. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  6392. "(%d)\n", __func__, init_retry_count));
  6393. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  6394. continue;
  6395. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  6396. }
  6397. skip_retry_init:
  6398. if (!test_bit(AF_ONLINE, &ha->flags)) {
  6399. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  6400. if ((is_qla8022(ha) && ql4xdontresethba) ||
  6401. ((is_qla8032(ha) || is_qla8042(ha)) &&
  6402. qla4_83xx_idc_dontreset(ha))) {
  6403. /* Put the device in failed state. */
  6404. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  6405. ha->isp_ops->idc_lock(ha);
  6406. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  6407. QLA8XXX_DEV_FAILED);
  6408. ha->isp_ops->idc_unlock(ha);
  6409. }
  6410. ret = -ENODEV;
  6411. goto remove_host;
  6412. }
  6413. /* Startup the kernel thread for this host adapter. */
  6414. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  6415. "qla4xxx_dpc\n", __func__));
  6416. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  6417. ha->dpc_thread = create_singlethread_workqueue(buf);
  6418. if (!ha->dpc_thread) {
  6419. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  6420. ret = -ENODEV;
  6421. goto remove_host;
  6422. }
  6423. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  6424. ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
  6425. ha->host_no);
  6426. if (!ha->task_wq) {
  6427. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  6428. ret = -ENODEV;
  6429. goto remove_host;
  6430. }
  6431. /*
  6432. * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
  6433. * (which is called indirectly by qla4xxx_initialize_adapter),
  6434. * so that irqs will be registered after crbinit but before
  6435. * mbx_intr_enable.
  6436. */
  6437. if (is_qla40XX(ha)) {
  6438. ret = qla4xxx_request_irqs(ha);
  6439. if (ret) {
  6440. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  6441. "interrupt %d already in use.\n", pdev->irq);
  6442. goto remove_host;
  6443. }
  6444. }
  6445. pci_save_state(ha->pdev);
  6446. ha->isp_ops->enable_intrs(ha);
  6447. /* Start timer thread. */
  6448. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  6449. set_bit(AF_INIT_DONE, &ha->flags);
  6450. qla4_8xxx_alloc_sysfs_attr(ha);
  6451. printk(KERN_INFO
  6452. " QLogic iSCSI HBA Driver version: %s\n"
  6453. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  6454. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  6455. ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
  6456. ha->fw_info.fw_patch, ha->fw_info.fw_build);
  6457. /* Set the driver version */
  6458. if (is_qla80XX(ha))
  6459. qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
  6460. if (qla4xxx_setup_boot_info(ha))
  6461. ql4_printk(KERN_ERR, ha,
  6462. "%s: No iSCSI boot target configured\n", __func__);
  6463. if (qla4xxx_sysfs_ddb_export(ha))
  6464. ql4_printk(KERN_ERR, ha,
  6465. "%s: Error exporting ddb to sysfs\n", __func__);
  6466. /* Perform the build ddb list and login to each */
  6467. qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
  6468. iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
  6469. qla4xxx_wait_login_resp_boot_tgt(ha);
  6470. qla4xxx_create_chap_list(ha);
  6471. qla4xxx_create_ifaces(ha);
  6472. return 0;
  6473. remove_host:
  6474. scsi_remove_host(ha->host);
  6475. probe_failed:
  6476. qla4xxx_free_adapter(ha);
  6477. probe_failed_ioconfig:
  6478. pci_disable_pcie_error_reporting(pdev);
  6479. scsi_host_put(ha->host);
  6480. probe_disable_device:
  6481. pci_disable_device(pdev);
  6482. return ret;
  6483. }
  6484. /**
  6485. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  6486. * @ha: pointer to adapter structure
  6487. *
  6488. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  6489. * so that the other port will not re-initialize while in the process of
  6490. * removing the ha due to driver unload or hba hotplug.
  6491. **/
  6492. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  6493. {
  6494. struct scsi_qla_host *other_ha = NULL;
  6495. struct pci_dev *other_pdev = NULL;
  6496. int fn = ISP4XXX_PCI_FN_2;
  6497. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  6498. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  6499. fn = ISP4XXX_PCI_FN_1;
  6500. other_pdev =
  6501. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  6502. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  6503. fn));
  6504. /* Get other_ha if other_pdev is valid and state is enable*/
  6505. if (other_pdev) {
  6506. if (atomic_read(&other_pdev->enable_cnt)) {
  6507. other_ha = pci_get_drvdata(other_pdev);
  6508. if (other_ha) {
  6509. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  6510. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  6511. "Prevent %s reinit\n", __func__,
  6512. dev_name(&other_ha->pdev->dev)));
  6513. }
  6514. }
  6515. pci_dev_put(other_pdev);
  6516. }
  6517. }
  6518. static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
  6519. {
  6520. struct ddb_entry *ddb_entry;
  6521. int options;
  6522. int idx;
  6523. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  6524. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  6525. if ((ddb_entry != NULL) &&
  6526. (ddb_entry->ddb_type == FLASH_DDB)) {
  6527. options = LOGOUT_OPTION_CLOSE_SESSION;
  6528. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
  6529. == QLA_ERROR)
  6530. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
  6531. __func__);
  6532. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  6533. /*
  6534. * we have decremented the reference count of the driver
  6535. * when we setup the session to have the driver unload
  6536. * to be seamless without actually destroying the
  6537. * session
  6538. **/
  6539. try_module_get(qla4xxx_iscsi_transport.owner);
  6540. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  6541. qla4xxx_free_ddb(ha, ddb_entry);
  6542. iscsi_session_teardown(ddb_entry->sess);
  6543. }
  6544. }
  6545. }
  6546. /**
  6547. * qla4xxx_remove_adapter - callback function to remove adapter.
  6548. * @pci_dev: PCI device pointer
  6549. **/
  6550. static void qla4xxx_remove_adapter(struct pci_dev *pdev)
  6551. {
  6552. struct scsi_qla_host *ha;
  6553. /*
  6554. * If the PCI device is disabled then it means probe_adapter had
  6555. * failed and resources already cleaned up on probe_adapter exit.
  6556. */
  6557. if (!pci_is_enabled(pdev))
  6558. return;
  6559. ha = pci_get_drvdata(pdev);
  6560. if (is_qla40XX(ha))
  6561. qla4xxx_prevent_other_port_reinit(ha);
  6562. /* destroy iface from sysfs */
  6563. qla4xxx_destroy_ifaces(ha);
  6564. if ((!ql4xdisablesysfsboot) && ha->boot_kset)
  6565. iscsi_boot_destroy_kset(ha->boot_kset);
  6566. qla4xxx_destroy_fw_ddb_session(ha);
  6567. qla4_8xxx_free_sysfs_attr(ha);
  6568. qla4xxx_sysfs_ddb_remove(ha);
  6569. scsi_remove_host(ha->host);
  6570. qla4xxx_free_adapter(ha);
  6571. scsi_host_put(ha->host);
  6572. pci_disable_pcie_error_reporting(pdev);
  6573. pci_disable_device(pdev);
  6574. pci_set_drvdata(pdev, NULL);
  6575. }
  6576. /**
  6577. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  6578. * @ha: HA context
  6579. *
  6580. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  6581. * supported addressing method.
  6582. */
  6583. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  6584. {
  6585. int retval;
  6586. /* Update our PCI device dma_mask for full 64 bit mask */
  6587. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  6588. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  6589. dev_dbg(&ha->pdev->dev,
  6590. "Failed to set 64 bit PCI consistent mask; "
  6591. "using 32 bit.\n");
  6592. retval = pci_set_consistent_dma_mask(ha->pdev,
  6593. DMA_BIT_MASK(32));
  6594. }
  6595. } else
  6596. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  6597. }
  6598. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  6599. {
  6600. struct iscsi_cls_session *cls_sess;
  6601. struct iscsi_session *sess;
  6602. struct ddb_entry *ddb;
  6603. int queue_depth = QL4_DEF_QDEPTH;
  6604. cls_sess = starget_to_session(sdev->sdev_target);
  6605. sess = cls_sess->dd_data;
  6606. ddb = sess->dd_data;
  6607. sdev->hostdata = ddb;
  6608. sdev->tagged_supported = 1;
  6609. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  6610. queue_depth = ql4xmaxqdepth;
  6611. scsi_activate_tcq(sdev, queue_depth);
  6612. return 0;
  6613. }
  6614. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  6615. {
  6616. sdev->tagged_supported = 1;
  6617. return 0;
  6618. }
  6619. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  6620. {
  6621. scsi_deactivate_tcq(sdev, 1);
  6622. }
  6623. static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
  6624. int reason)
  6625. {
  6626. if (!ql4xqfulltracking)
  6627. return -EOPNOTSUPP;
  6628. return iscsi_change_queue_depth(sdev, qdepth, reason);
  6629. }
  6630. /**
  6631. * qla4xxx_del_from_active_array - returns an active srb
  6632. * @ha: Pointer to host adapter structure.
  6633. * @index: index into the active_array
  6634. *
  6635. * This routine removes and returns the srb at the specified index
  6636. **/
  6637. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  6638. uint32_t index)
  6639. {
  6640. struct srb *srb = NULL;
  6641. struct scsi_cmnd *cmd = NULL;
  6642. cmd = scsi_host_find_tag(ha->host, index);
  6643. if (!cmd)
  6644. return srb;
  6645. srb = (struct srb *)CMD_SP(cmd);
  6646. if (!srb)
  6647. return srb;
  6648. /* update counters */
  6649. if (srb->flags & SRB_DMA_VALID) {
  6650. ha->iocb_cnt -= srb->iocb_cnt;
  6651. if (srb->cmd)
  6652. srb->cmd->host_scribble =
  6653. (unsigned char *)(unsigned long) MAX_SRBS;
  6654. }
  6655. return srb;
  6656. }
  6657. /**
  6658. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  6659. * @ha: Pointer to host adapter structure.
  6660. * @cmd: Scsi Command to wait on.
  6661. *
  6662. * This routine waits for the command to be returned by the Firmware
  6663. * for some max time.
  6664. **/
  6665. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  6666. struct scsi_cmnd *cmd)
  6667. {
  6668. int done = 0;
  6669. struct srb *rp;
  6670. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  6671. int ret = SUCCESS;
  6672. /* Dont wait on command if PCI error is being handled
  6673. * by PCI AER driver
  6674. */
  6675. if (unlikely(pci_channel_offline(ha->pdev)) ||
  6676. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  6677. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  6678. ha->host_no, __func__);
  6679. return ret;
  6680. }
  6681. do {
  6682. /* Checking to see if its returned to OS */
  6683. rp = (struct srb *) CMD_SP(cmd);
  6684. if (rp == NULL) {
  6685. done++;
  6686. break;
  6687. }
  6688. msleep(2000);
  6689. } while (max_wait_time--);
  6690. return done;
  6691. }
  6692. /**
  6693. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  6694. * @ha: Pointer to host adapter structure
  6695. **/
  6696. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  6697. {
  6698. unsigned long wait_online;
  6699. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  6700. while (time_before(jiffies, wait_online)) {
  6701. if (adapter_up(ha))
  6702. return QLA_SUCCESS;
  6703. msleep(2000);
  6704. }
  6705. return QLA_ERROR;
  6706. }
  6707. /**
  6708. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  6709. * @ha: pointer to HBA
  6710. * @t: target id
  6711. * @l: lun id
  6712. *
  6713. * This function waits for all outstanding commands to a lun to complete. It
  6714. * returns 0 if all pending commands are returned and 1 otherwise.
  6715. **/
  6716. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  6717. struct scsi_target *stgt,
  6718. struct scsi_device *sdev)
  6719. {
  6720. int cnt;
  6721. int status = 0;
  6722. struct scsi_cmnd *cmd;
  6723. /*
  6724. * Waiting for all commands for the designated target or dev
  6725. * in the active array
  6726. */
  6727. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  6728. cmd = scsi_host_find_tag(ha->host, cnt);
  6729. if (cmd && stgt == scsi_target(cmd->device) &&
  6730. (!sdev || sdev == cmd->device)) {
  6731. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  6732. status++;
  6733. break;
  6734. }
  6735. }
  6736. }
  6737. return status;
  6738. }
  6739. /**
  6740. * qla4xxx_eh_abort - callback for abort task.
  6741. * @cmd: Pointer to Linux's SCSI command structure
  6742. *
  6743. * This routine is called by the Linux OS to abort the specified
  6744. * command.
  6745. **/
  6746. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  6747. {
  6748. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6749. unsigned int id = cmd->device->id;
  6750. unsigned int lun = cmd->device->lun;
  6751. unsigned long flags;
  6752. struct srb *srb = NULL;
  6753. int ret = SUCCESS;
  6754. int wait = 0;
  6755. ql4_printk(KERN_INFO, ha,
  6756. "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
  6757. ha->host_no, id, lun, cmd);
  6758. spin_lock_irqsave(&ha->hardware_lock, flags);
  6759. srb = (struct srb *) CMD_SP(cmd);
  6760. if (!srb) {
  6761. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6762. return SUCCESS;
  6763. }
  6764. kref_get(&srb->srb_ref);
  6765. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6766. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  6767. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
  6768. ha->host_no, id, lun));
  6769. ret = FAILED;
  6770. } else {
  6771. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
  6772. ha->host_no, id, lun));
  6773. wait = 1;
  6774. }
  6775. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  6776. /* Wait for command to complete */
  6777. if (wait) {
  6778. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  6779. DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
  6780. ha->host_no, id, lun));
  6781. ret = FAILED;
  6782. }
  6783. }
  6784. ql4_printk(KERN_INFO, ha,
  6785. "scsi%ld:%d:%d: Abort command - %s\n",
  6786. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  6787. return ret;
  6788. }
  6789. /**
  6790. * qla4xxx_eh_device_reset - callback for target reset.
  6791. * @cmd: Pointer to Linux's SCSI command structure
  6792. *
  6793. * This routine is called by the Linux OS to reset all luns on the
  6794. * specified target.
  6795. **/
  6796. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  6797. {
  6798. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6799. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  6800. int ret = FAILED, stat;
  6801. if (!ddb_entry)
  6802. return ret;
  6803. ret = iscsi_block_scsi_eh(cmd);
  6804. if (ret)
  6805. return ret;
  6806. ret = FAILED;
  6807. ql4_printk(KERN_INFO, ha,
  6808. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  6809. cmd->device->channel, cmd->device->id, cmd->device->lun);
  6810. DEBUG2(printk(KERN_INFO
  6811. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  6812. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  6813. cmd, jiffies, cmd->request->timeout / HZ,
  6814. ha->dpc_flags, cmd->result, cmd->allowed));
  6815. /* FIXME: wait for hba to go online */
  6816. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  6817. if (stat != QLA_SUCCESS) {
  6818. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  6819. goto eh_dev_reset_done;
  6820. }
  6821. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  6822. cmd->device)) {
  6823. ql4_printk(KERN_INFO, ha,
  6824. "DEVICE RESET FAILED - waiting for "
  6825. "commands.\n");
  6826. goto eh_dev_reset_done;
  6827. }
  6828. /* Send marker. */
  6829. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  6830. MM_LUN_RESET) != QLA_SUCCESS)
  6831. goto eh_dev_reset_done;
  6832. ql4_printk(KERN_INFO, ha,
  6833. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  6834. ha->host_no, cmd->device->channel, cmd->device->id,
  6835. cmd->device->lun);
  6836. ret = SUCCESS;
  6837. eh_dev_reset_done:
  6838. return ret;
  6839. }
  6840. /**
  6841. * qla4xxx_eh_target_reset - callback for target reset.
  6842. * @cmd: Pointer to Linux's SCSI command structure
  6843. *
  6844. * This routine is called by the Linux OS to reset the target.
  6845. **/
  6846. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  6847. {
  6848. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  6849. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  6850. int stat, ret;
  6851. if (!ddb_entry)
  6852. return FAILED;
  6853. ret = iscsi_block_scsi_eh(cmd);
  6854. if (ret)
  6855. return ret;
  6856. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6857. "WARM TARGET RESET ISSUED.\n");
  6858. DEBUG2(printk(KERN_INFO
  6859. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  6860. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  6861. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  6862. ha->dpc_flags, cmd->result, cmd->allowed));
  6863. stat = qla4xxx_reset_target(ha, ddb_entry);
  6864. if (stat != QLA_SUCCESS) {
  6865. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6866. "WARM TARGET RESET FAILED.\n");
  6867. return FAILED;
  6868. }
  6869. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  6870. NULL)) {
  6871. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6872. "WARM TARGET DEVICE RESET FAILED - "
  6873. "waiting for commands.\n");
  6874. return FAILED;
  6875. }
  6876. /* Send marker. */
  6877. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  6878. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  6879. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6880. "WARM TARGET DEVICE RESET FAILED - "
  6881. "marker iocb failed.\n");
  6882. return FAILED;
  6883. }
  6884. starget_printk(KERN_INFO, scsi_target(cmd->device),
  6885. "WARM TARGET RESET SUCCEEDED.\n");
  6886. return SUCCESS;
  6887. }
  6888. /**
  6889. * qla4xxx_is_eh_active - check if error handler is running
  6890. * @shost: Pointer to SCSI Host struct
  6891. *
  6892. * This routine finds that if reset host is called in EH
  6893. * scenario or from some application like sg_reset
  6894. **/
  6895. static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
  6896. {
  6897. if (shost->shost_state == SHOST_RECOVERY)
  6898. return 1;
  6899. return 0;
  6900. }
  6901. /**
  6902. * qla4xxx_eh_host_reset - kernel callback
  6903. * @cmd: Pointer to Linux's SCSI command structure
  6904. *
  6905. * This routine is invoked by the Linux kernel to perform fatal error
  6906. * recovery on the specified adapter.
  6907. **/
  6908. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  6909. {
  6910. int return_status = FAILED;
  6911. struct scsi_qla_host *ha;
  6912. ha = to_qla_host(cmd->device->host);
  6913. if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
  6914. qla4_83xx_set_idc_dontreset(ha);
  6915. /*
  6916. * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
  6917. * protocol drivers, we should not set device_state to NEED_RESET
  6918. */
  6919. if (ql4xdontresethba ||
  6920. ((is_qla8032(ha) || is_qla8042(ha)) &&
  6921. qla4_83xx_idc_dontreset(ha))) {
  6922. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  6923. ha->host_no, __func__));
  6924. /* Clear outstanding srb in queues */
  6925. if (qla4xxx_is_eh_active(cmd->device->host))
  6926. qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
  6927. return FAILED;
  6928. }
  6929. ql4_printk(KERN_INFO, ha,
  6930. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  6931. cmd->device->channel, cmd->device->id, cmd->device->lun);
  6932. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  6933. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  6934. "DEAD.\n", ha->host_no, cmd->device->channel,
  6935. __func__));
  6936. return FAILED;
  6937. }
  6938. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  6939. if (is_qla80XX(ha))
  6940. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  6941. else
  6942. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  6943. }
  6944. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  6945. return_status = SUCCESS;
  6946. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  6947. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  6948. return return_status;
  6949. }
  6950. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  6951. {
  6952. uint32_t mbox_cmd[MBOX_REG_COUNT];
  6953. uint32_t mbox_sts[MBOX_REG_COUNT];
  6954. struct addr_ctrl_blk_def *acb = NULL;
  6955. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  6956. int rval = QLA_SUCCESS;
  6957. dma_addr_t acb_dma;
  6958. acb = dma_alloc_coherent(&ha->pdev->dev,
  6959. sizeof(struct addr_ctrl_blk_def),
  6960. &acb_dma, GFP_KERNEL);
  6961. if (!acb) {
  6962. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  6963. __func__);
  6964. rval = -ENOMEM;
  6965. goto exit_port_reset;
  6966. }
  6967. memset(acb, 0, acb_len);
  6968. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  6969. if (rval != QLA_SUCCESS) {
  6970. rval = -EIO;
  6971. goto exit_free_acb;
  6972. }
  6973. rval = qla4xxx_disable_acb(ha);
  6974. if (rval != QLA_SUCCESS) {
  6975. rval = -EIO;
  6976. goto exit_free_acb;
  6977. }
  6978. wait_for_completion_timeout(&ha->disable_acb_comp,
  6979. DISABLE_ACB_TOV * HZ);
  6980. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  6981. if (rval != QLA_SUCCESS) {
  6982. rval = -EIO;
  6983. goto exit_free_acb;
  6984. }
  6985. exit_free_acb:
  6986. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  6987. acb, acb_dma);
  6988. exit_port_reset:
  6989. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  6990. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  6991. return rval;
  6992. }
  6993. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  6994. {
  6995. struct scsi_qla_host *ha = to_qla_host(shost);
  6996. int rval = QLA_SUCCESS;
  6997. uint32_t idc_ctrl;
  6998. if (ql4xdontresethba) {
  6999. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  7000. __func__));
  7001. rval = -EPERM;
  7002. goto exit_host_reset;
  7003. }
  7004. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  7005. goto recover_adapter;
  7006. switch (reset_type) {
  7007. case SCSI_ADAPTER_RESET:
  7008. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  7009. break;
  7010. case SCSI_FIRMWARE_RESET:
  7011. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  7012. if (is_qla80XX(ha))
  7013. /* set firmware context reset */
  7014. set_bit(DPC_RESET_HA_FW_CONTEXT,
  7015. &ha->dpc_flags);
  7016. else {
  7017. rval = qla4xxx_context_reset(ha);
  7018. goto exit_host_reset;
  7019. }
  7020. }
  7021. break;
  7022. }
  7023. recover_adapter:
  7024. /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
  7025. * reset is issued by application */
  7026. if ((is_qla8032(ha) || is_qla8042(ha)) &&
  7027. test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  7028. idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
  7029. qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
  7030. (idc_ctrl | GRACEFUL_RESET_BIT1));
  7031. }
  7032. rval = qla4xxx_recover_adapter(ha);
  7033. if (rval != QLA_SUCCESS) {
  7034. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  7035. __func__));
  7036. rval = -EIO;
  7037. }
  7038. exit_host_reset:
  7039. return rval;
  7040. }
  7041. /* PCI AER driver recovers from all correctable errors w/o
  7042. * driver intervention. For uncorrectable errors PCI AER
  7043. * driver calls the following device driver's callbacks
  7044. *
  7045. * - Fatal Errors - link_reset
  7046. * - Non-Fatal Errors - driver's pci_error_detected() which
  7047. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  7048. *
  7049. * PCI AER driver calls
  7050. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  7051. * returns RECOVERED or NEED_RESET if fw_hung
  7052. * NEED_RESET - driver's slot_reset()
  7053. * DISCONNECT - device is dead & cannot recover
  7054. * RECOVERED - driver's pci_resume()
  7055. */
  7056. static pci_ers_result_t
  7057. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  7058. {
  7059. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  7060. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  7061. ha->host_no, __func__, state);
  7062. if (!is_aer_supported(ha))
  7063. return PCI_ERS_RESULT_NONE;
  7064. switch (state) {
  7065. case pci_channel_io_normal:
  7066. clear_bit(AF_EEH_BUSY, &ha->flags);
  7067. return PCI_ERS_RESULT_CAN_RECOVER;
  7068. case pci_channel_io_frozen:
  7069. set_bit(AF_EEH_BUSY, &ha->flags);
  7070. qla4xxx_mailbox_premature_completion(ha);
  7071. qla4xxx_free_irqs(ha);
  7072. pci_disable_device(pdev);
  7073. /* Return back all IOs */
  7074. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  7075. return PCI_ERS_RESULT_NEED_RESET;
  7076. case pci_channel_io_perm_failure:
  7077. set_bit(AF_EEH_BUSY, &ha->flags);
  7078. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  7079. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  7080. return PCI_ERS_RESULT_DISCONNECT;
  7081. }
  7082. return PCI_ERS_RESULT_NEED_RESET;
  7083. }
  7084. /**
  7085. * qla4xxx_pci_mmio_enabled() gets called if
  7086. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  7087. * and read/write to the device still works.
  7088. **/
  7089. static pci_ers_result_t
  7090. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  7091. {
  7092. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  7093. if (!is_aer_supported(ha))
  7094. return PCI_ERS_RESULT_NONE;
  7095. return PCI_ERS_RESULT_RECOVERED;
  7096. }
  7097. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  7098. {
  7099. uint32_t rval = QLA_ERROR;
  7100. int fn;
  7101. struct pci_dev *other_pdev = NULL;
  7102. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  7103. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  7104. if (test_bit(AF_ONLINE, &ha->flags)) {
  7105. clear_bit(AF_ONLINE, &ha->flags);
  7106. clear_bit(AF_LINK_UP, &ha->flags);
  7107. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  7108. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  7109. }
  7110. fn = PCI_FUNC(ha->pdev->devfn);
  7111. while (fn > 0) {
  7112. fn--;
  7113. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
  7114. "func %x\n", ha->host_no, __func__, fn);
  7115. /* Get the pci device given the domain, bus,
  7116. * slot/function number */
  7117. other_pdev =
  7118. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  7119. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  7120. fn));
  7121. if (!other_pdev)
  7122. continue;
  7123. if (atomic_read(&other_pdev->enable_cnt)) {
  7124. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
  7125. "func in enabled state%x\n", ha->host_no,
  7126. __func__, fn);
  7127. pci_dev_put(other_pdev);
  7128. break;
  7129. }
  7130. pci_dev_put(other_pdev);
  7131. }
  7132. /* The first function on the card, the reset owner will
  7133. * start & initialize the firmware. The other functions
  7134. * on the card will reset the firmware context
  7135. */
  7136. if (!fn) {
  7137. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  7138. "0x%x is the owner\n", ha->host_no, __func__,
  7139. ha->pdev->devfn);
  7140. ha->isp_ops->idc_lock(ha);
  7141. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  7142. QLA8XXX_DEV_COLD);
  7143. ha->isp_ops->idc_unlock(ha);
  7144. rval = qla4_8xxx_update_idc_reg(ha);
  7145. if (rval == QLA_ERROR) {
  7146. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
  7147. ha->host_no, __func__);
  7148. ha->isp_ops->idc_lock(ha);
  7149. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  7150. QLA8XXX_DEV_FAILED);
  7151. ha->isp_ops->idc_unlock(ha);
  7152. goto exit_error_recovery;
  7153. }
  7154. clear_bit(AF_FW_RECOVERY, &ha->flags);
  7155. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  7156. if (rval != QLA_SUCCESS) {
  7157. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  7158. "FAILED\n", ha->host_no, __func__);
  7159. ha->isp_ops->idc_lock(ha);
  7160. qla4_8xxx_clear_drv_active(ha);
  7161. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  7162. QLA8XXX_DEV_FAILED);
  7163. ha->isp_ops->idc_unlock(ha);
  7164. } else {
  7165. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  7166. "READY\n", ha->host_no, __func__);
  7167. ha->isp_ops->idc_lock(ha);
  7168. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  7169. QLA8XXX_DEV_READY);
  7170. /* Clear driver state register */
  7171. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
  7172. qla4_8xxx_set_drv_active(ha);
  7173. ha->isp_ops->idc_unlock(ha);
  7174. ha->isp_ops->enable_intrs(ha);
  7175. }
  7176. } else {
  7177. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  7178. "the reset owner\n", ha->host_no, __func__,
  7179. ha->pdev->devfn);
  7180. if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
  7181. QLA8XXX_DEV_READY)) {
  7182. clear_bit(AF_FW_RECOVERY, &ha->flags);
  7183. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  7184. if (rval == QLA_SUCCESS)
  7185. ha->isp_ops->enable_intrs(ha);
  7186. ha->isp_ops->idc_lock(ha);
  7187. qla4_8xxx_set_drv_active(ha);
  7188. ha->isp_ops->idc_unlock(ha);
  7189. }
  7190. }
  7191. exit_error_recovery:
  7192. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  7193. return rval;
  7194. }
  7195. static pci_ers_result_t
  7196. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  7197. {
  7198. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  7199. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  7200. int rc;
  7201. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  7202. ha->host_no, __func__);
  7203. if (!is_aer_supported(ha))
  7204. return PCI_ERS_RESULT_NONE;
  7205. /* Restore the saved state of PCIe device -
  7206. * BAR registers, PCI Config space, PCIX, MSI,
  7207. * IOV states
  7208. */
  7209. pci_restore_state(pdev);
  7210. /* pci_restore_state() clears the saved_state flag of the device
  7211. * save restored state which resets saved_state flag
  7212. */
  7213. pci_save_state(pdev);
  7214. /* Initialize device or resume if in suspended state */
  7215. rc = pci_enable_device(pdev);
  7216. if (rc) {
  7217. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  7218. "device after reset\n", ha->host_no, __func__);
  7219. goto exit_slot_reset;
  7220. }
  7221. ha->isp_ops->disable_intrs(ha);
  7222. if (is_qla80XX(ha)) {
  7223. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  7224. ret = PCI_ERS_RESULT_RECOVERED;
  7225. goto exit_slot_reset;
  7226. } else
  7227. goto exit_slot_reset;
  7228. }
  7229. exit_slot_reset:
  7230. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  7231. "device after reset\n", ha->host_no, __func__, ret);
  7232. return ret;
  7233. }
  7234. static void
  7235. qla4xxx_pci_resume(struct pci_dev *pdev)
  7236. {
  7237. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  7238. int ret;
  7239. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  7240. ha->host_no, __func__);
  7241. ret = qla4xxx_wait_for_hba_online(ha);
  7242. if (ret != QLA_SUCCESS) {
  7243. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  7244. "resume I/O from slot/link_reset\n", ha->host_no,
  7245. __func__);
  7246. }
  7247. pci_cleanup_aer_uncorrect_error_status(pdev);
  7248. clear_bit(AF_EEH_BUSY, &ha->flags);
  7249. }
  7250. static const struct pci_error_handlers qla4xxx_err_handler = {
  7251. .error_detected = qla4xxx_pci_error_detected,
  7252. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  7253. .slot_reset = qla4xxx_pci_slot_reset,
  7254. .resume = qla4xxx_pci_resume,
  7255. };
  7256. static struct pci_device_id qla4xxx_pci_tbl[] = {
  7257. {
  7258. .vendor = PCI_VENDOR_ID_QLOGIC,
  7259. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  7260. .subvendor = PCI_ANY_ID,
  7261. .subdevice = PCI_ANY_ID,
  7262. },
  7263. {
  7264. .vendor = PCI_VENDOR_ID_QLOGIC,
  7265. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  7266. .subvendor = PCI_ANY_ID,
  7267. .subdevice = PCI_ANY_ID,
  7268. },
  7269. {
  7270. .vendor = PCI_VENDOR_ID_QLOGIC,
  7271. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  7272. .subvendor = PCI_ANY_ID,
  7273. .subdevice = PCI_ANY_ID,
  7274. },
  7275. {
  7276. .vendor = PCI_VENDOR_ID_QLOGIC,
  7277. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  7278. .subvendor = PCI_ANY_ID,
  7279. .subdevice = PCI_ANY_ID,
  7280. },
  7281. {
  7282. .vendor = PCI_VENDOR_ID_QLOGIC,
  7283. .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
  7284. .subvendor = PCI_ANY_ID,
  7285. .subdevice = PCI_ANY_ID,
  7286. },
  7287. {
  7288. .vendor = PCI_VENDOR_ID_QLOGIC,
  7289. .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
  7290. .subvendor = PCI_ANY_ID,
  7291. .subdevice = PCI_ANY_ID,
  7292. },
  7293. {0, 0},
  7294. };
  7295. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  7296. static struct pci_driver qla4xxx_pci_driver = {
  7297. .name = DRIVER_NAME,
  7298. .id_table = qla4xxx_pci_tbl,
  7299. .probe = qla4xxx_probe_adapter,
  7300. .remove = qla4xxx_remove_adapter,
  7301. .err_handler = &qla4xxx_err_handler,
  7302. };
  7303. static int __init qla4xxx_module_init(void)
  7304. {
  7305. int ret;
  7306. /* Allocate cache for SRBs. */
  7307. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  7308. SLAB_HWCACHE_ALIGN, NULL);
  7309. if (srb_cachep == NULL) {
  7310. printk(KERN_ERR
  7311. "%s: Unable to allocate SRB cache..."
  7312. "Failing load!\n", DRIVER_NAME);
  7313. ret = -ENOMEM;
  7314. goto no_srp_cache;
  7315. }
  7316. /* Derive version string. */
  7317. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  7318. if (ql4xextended_error_logging)
  7319. strcat(qla4xxx_version_str, "-debug");
  7320. qla4xxx_scsi_transport =
  7321. iscsi_register_transport(&qla4xxx_iscsi_transport);
  7322. if (!qla4xxx_scsi_transport){
  7323. ret = -ENODEV;
  7324. goto release_srb_cache;
  7325. }
  7326. ret = pci_register_driver(&qla4xxx_pci_driver);
  7327. if (ret)
  7328. goto unregister_transport;
  7329. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  7330. return 0;
  7331. unregister_transport:
  7332. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  7333. release_srb_cache:
  7334. kmem_cache_destroy(srb_cachep);
  7335. no_srp_cache:
  7336. return ret;
  7337. }
  7338. static void __exit qla4xxx_module_exit(void)
  7339. {
  7340. pci_unregister_driver(&qla4xxx_pci_driver);
  7341. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  7342. kmem_cache_destroy(srb_cachep);
  7343. }
  7344. module_init(qla4xxx_module_init);
  7345. module_exit(qla4xxx_module_exit);
  7346. MODULE_AUTHOR("QLogic Corporation");
  7347. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  7348. MODULE_LICENSE("GPL");
  7349. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);