ql4_os.c 172 KB

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